-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(wallet): mercuryo on-ramp (#20962)
Signed-off-by: Brian Sztamfater <[email protected]>
- Loading branch information
1 parent
4b93c8f
commit 00b0d75
Showing
16 changed files
with
303 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
(ns status-im.contexts.wallet.buy-crypto.events | ||
(:require [re-frame.core :as rf] | ||
[react-native.core :as rn] | ||
[status-im.contexts.wallet.sheets.buy-network-selection.view :as buy-network-selection] | ||
[status-im.contexts.wallet.sheets.select-asset.view :as select-asset] | ||
[utils.i18n :as i18n])) | ||
|
||
(rf/reg-event-fx :wallet.buy-crypto/select-provider | ||
(fn [{:keys [db]} [{:keys [account provider recurrent?]}]] | ||
(let [swap-network (get-in db [:wallet :ui :swap :network])] | ||
{:db (-> db | ||
(assoc-in [:wallet :ui :buy-crypto :account] account) | ||
(assoc-in [:wallet :ui :buy-crypto :provider] provider) | ||
(assoc-in [:wallet :ui :buy-crypto :recurrent?] recurrent?)) | ||
:fx [(if swap-network | ||
[:dispatch [:wallet.buy-crypto/select-network swap-network]] | ||
[:dispatch | ||
[:show-bottom-sheet | ||
{:content | ||
(fn [] | ||
[buy-network-selection/view | ||
{:provider provider | ||
:account account}])}]])]}))) | ||
|
||
(rf/reg-event-fx :wallet.buy-crypto/select-network | ||
(fn [{:keys [db]} [network]] | ||
(let [provider (get-in db [:wallet :ui :buy-crypto :provider]) | ||
network-chain-id (:chain-id network) | ||
supported-tokens (:supported-tokens provider) | ||
supported-tokens-on-network (set (map :symbol | ||
(filter (fn [token] | ||
(= (:chain-id token) network-chain-id)) | ||
supported-tokens)))] | ||
{:db (assoc-in db [:wallet :ui :buy-crypto :network] network) | ||
:fx [[:dispatch | ||
[:show-bottom-sheet | ||
{:content | ||
(fn [] | ||
[select-asset/view | ||
{:title (i18n/label :t/select-asset-to-buy) | ||
:network network | ||
:provider provider | ||
:on-select (fn [token] | ||
(rf/dispatch [:wallet/get-crypto-on-ramp-url {:token token}])) | ||
:hide-token-fn (fn [_ token] | ||
(not (contains? supported-tokens-on-network | ||
(:symbol token))))}])}]]]}))) | ||
|
||
(rf/reg-event-fx | ||
:wallet/get-crypto-on-ramp-url | ||
(fn [{:keys [db]} [{:keys [token]}]] | ||
(let [account (get-in db [:wallet :ui :buy-crypto :account]) | ||
provider (get-in db [:wallet :ui :buy-crypto :provider]) | ||
network (get-in db [:wallet :ui :buy-crypto :network]) | ||
recurrent? (get-in db [:wallet :ui :buy-crypto :recurrent?]) | ||
provider-id (:id provider) | ||
parameters {:symbol (:symbol token) | ||
:destAddress (:address account) | ||
:chainID (:chain-id network) | ||
:isRecurrent recurrent?}] | ||
{:fx [[:json-rpc/call | ||
[{:method "wallet_getCryptoOnRampURL" | ||
:params [provider-id parameters] | ||
:on-success (fn [url] | ||
(rf/dispatch [:navigate-back]) | ||
(rf/dispatch [:wallet.buy-crypto/clean-all]) | ||
(rn/open-url url)) | ||
:on-error [:wallet/log-rpc-error {:event :wallet/get-crypto-on-ramps}]}]]]}))) | ||
|
||
(rf/reg-event-fx :wallet.buy-crypto/clean-all | ||
(fn [{:keys [db]}] | ||
{:db (update-in db [:wallet :ui] dissoc :buy-crypto)})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/status_im/contexts/wallet/sheets/buy_network_selection/style.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(ns status-im.contexts.wallet.sheets.buy-network-selection.style) | ||
|
||
(defn network-list-container | ||
[mainnet?] | ||
{:margin-horizontal 8 | ||
:padding-vertical (when mainnet? 8)}) | ||
|
||
(def header-container | ||
{:height 62 | ||
:padding-horizontal 20}) | ||
|
||
(def context-tag | ||
{:margin-top 0}) | ||
|
||
(def divider-label | ||
{:padding-top 0 | ||
:padding-bottom 0}) | ||
|
||
(def subheader-container | ||
{:flex-direction :row | ||
:align-items :center | ||
:margin-top 4}) | ||
|
||
(def on | ||
{:margin-right 4}) | ||
|
||
(def to | ||
{:margin-horizontal 4}) |
78 changes: 78 additions & 0 deletions
78
src/status_im/contexts/wallet/sheets/buy_network_selection/view.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
(ns status-im.contexts.wallet.sheets.buy-network-selection.view | ||
(:require [quo.core :as quo] | ||
[quo.foundations.resources :as quo.resources] | ||
[react-native.core :as rn] | ||
[status-im.constants :as constants] | ||
[status-im.contexts.wallet.sheets.buy-network-selection.style :as style] | ||
[utils.i18n :as i18n] | ||
[utils.re-frame :as rf])) | ||
|
||
(defn- network-item | ||
[{:keys [network on-select-network]}] | ||
(let [{:keys [network-name]} network | ||
mainnet? (= network-name constants/mainnet-network-name)] | ||
[quo/network-list | ||
{:label (name network-name) | ||
:network-image (quo.resources/get-network network-name) | ||
:on-press #(on-select-network network) | ||
:container-style (style/network-list-container mainnet?)}])) | ||
|
||
(defn- subheader | ||
[{:keys [provider account]}] | ||
[rn/view {:style style/subheader-container} | ||
[quo/text | ||
{:size :paragraph-2 | ||
:weight :medium | ||
:style style/on} | ||
(i18n/label :t/on-uppercase)] | ||
[quo/context-tag | ||
{:type :network | ||
:network-logo (:logo-url provider) | ||
:network-name (:name provider) | ||
:size 24 | ||
:container-style style/context-tag}] | ||
[quo/text | ||
{:size :paragraph-2 | ||
:weight :medium | ||
:style style/to} | ||
(i18n/label :t/to)] | ||
[quo/context-tag | ||
{:type :account | ||
:account-name (:name account) | ||
:emoji (:emoji account) | ||
:size 24 | ||
:container-style style/context-tag}]]) | ||
|
||
(defn view | ||
[] | ||
(let [provider (rf/sub [:wallet/wallet-buy-crypto-provider]) | ||
account (rf/sub [:wallet/wallet-buy-crypto-account]) | ||
network-details (rf/sub [:wallet/network-details]) | ||
mainnet-network (first network-details) | ||
layer-2-networks (rest network-details) | ||
render-fn (rn/use-callback (fn [network] | ||
[network-item | ||
{:network network | ||
:on-select-network | ||
(fn [network] | ||
(rf/dispatch [:wallet.buy-crypto/select-network | ||
network]))}]))] | ||
[:<> | ||
[rn/view {:style style/header-container} | ||
[quo/text | ||
{:size :heading-2 | ||
:weight :semi-bold} | ||
(i18n/label :t/select-network-for-buying)] | ||
[subheader | ||
{:provider provider | ||
:account account}]] | ||
(when mainnet-network | ||
[network-item | ||
{:network mainnet-network | ||
:on-select-network #(rf/dispatch [:wallet.buy-crypto/select-network mainnet-network])}]) | ||
[quo/divider-label {:container-style style/divider-label} | ||
(i18n/label :t/layer-2)] | ||
[rn/flat-list | ||
{:data (vec layer-2-networks) | ||
:render-fn render-fn | ||
:scroll-enabled false}]])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.