Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21ebd4d930 | ||
|
|
40c36c30e6 |
+15
-12
@@ -23,15 +23,18 @@ PODS:
|
||||
- secp256k1
|
||||
- SSZipArchive
|
||||
- libevent (2.1.12)
|
||||
- libwebp (1.2.4):
|
||||
- libwebp/demux (= 1.2.4)
|
||||
- libwebp/mux (= 1.2.4)
|
||||
- libwebp/webp (= 1.2.4)
|
||||
- libwebp/demux (1.2.4):
|
||||
- libwebp (1.3.2):
|
||||
- libwebp/demux (= 1.3.2)
|
||||
- libwebp/mux (= 1.3.2)
|
||||
- libwebp/sharpyuv (= 1.3.2)
|
||||
- libwebp/webp (= 1.3.2)
|
||||
- libwebp/demux (1.3.2):
|
||||
- libwebp/webp
|
||||
- libwebp/mux (1.2.4):
|
||||
- libwebp/mux (1.3.2):
|
||||
- libwebp/demux
|
||||
- libwebp/webp (1.2.4)
|
||||
- libwebp/sharpyuv (1.3.2)
|
||||
- libwebp/webp (1.3.2):
|
||||
- libwebp/sharpyuv
|
||||
- RCT-Folly (2022.05.16.00):
|
||||
- boost
|
||||
- DoubleConversion
|
||||
@@ -1189,7 +1192,7 @@ PODS:
|
||||
- secp256k1 (0.1.6)
|
||||
- SocketRocket (0.6.1)
|
||||
- SSZipArchive (2.4.3)
|
||||
- TOCropViewController (2.6.1)
|
||||
- TOCropViewController (2.7.4)
|
||||
- Yoga (1.14.0)
|
||||
|
||||
DEPENDENCIES:
|
||||
@@ -1489,7 +1492,7 @@ CHECKOUT OPTIONS:
|
||||
:git: https://github.com/status-im/Keycard.swift.git
|
||||
:tag: 3.1.1
|
||||
secp256k1:
|
||||
:commit: 46a1fa30d9b8babeae85ff519050f42394ab5fcc
|
||||
:commit: 4ab977cc2b2d7319be858bcb30a5d189bb149884
|
||||
:git: https://github.com/status-im/secp256k1.swift.git
|
||||
:submodules: true
|
||||
|
||||
@@ -1506,7 +1509,7 @@ SPEC CHECKSUMS:
|
||||
HMSegmentedControl: 34c1f54d822d8308e7b24f5d901ec674dfa31352
|
||||
Keycard: 3bd24405b9a875b3b3cf1ab1be69b5c30c5f28bc
|
||||
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
|
||||
libwebp: f62cb61d0a484ba548448a4bd52aabf150ff6eef
|
||||
libwebp: 1786c9f4ff8a279e4dac1e8f385004d5fc253009
|
||||
RCT-Folly: 7169b2b1c44399c76a47b5deaaba715eeeb476c0
|
||||
RCTRequired: 2544c0f1081a5fa12e108bb8cb40e5f4581ccd87
|
||||
RCTTypeSafety: 50efabe2b115c11ed03fbf3fd79e2f163ddb5d7c
|
||||
@@ -1590,9 +1593,9 @@ SPEC CHECKSUMS:
|
||||
secp256k1: f61d67e6fdcb85fd727acf1bf35ace6036db540c
|
||||
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
|
||||
SSZipArchive: fe6a26b2a54d5a0890f2567b5cc6de5caa600aef
|
||||
TOCropViewController: edfd4f25713d56905ad1e0b9f5be3fbe0f59c863
|
||||
TOCropViewController: 80b8985ad794298fb69d3341de183f33d1853654
|
||||
Yoga: a716eea57d0d3430219c0a5a233e1e93ee931eb7
|
||||
|
||||
PODFILE CHECKSUM: 81a66b45adddb083171ade882c343deb4faf2a8b
|
||||
PODFILE CHECKSUM: 56d9f695324306d6db368d1172d211dfab55b7cb
|
||||
|
||||
COCOAPODS: 1.15.2
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ in {
|
||||
yarn = super.yarn.override { nodejs = super.nodejs_20; };
|
||||
openjdk = super.openjdk17_headless;
|
||||
xcodeWrapper = callPackage ./pkgs/xcodeenv/compose-xcodewrapper.nix { } {
|
||||
versions = ["15.1" "15.2" "15.3" "15.4"];
|
||||
versions = ["15.1" "15.2" "15.3" "15.4" "16.0" "16.1"];
|
||||
};
|
||||
go = super.go_1_21;
|
||||
clang = super.clang_15;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(ns status-im.contexts.wallet.bridge.bridge-to.view
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[quo.core :as quo]
|
||||
[quo.foundations.resources :as quo.resources]
|
||||
[quo.theme]
|
||||
@@ -15,28 +14,34 @@
|
||||
|
||||
(defn- bridge-token-component
|
||||
[]
|
||||
(fn [{:keys [chain-id network-name]} {:keys [supported-networks] :as token}]
|
||||
(let [network (rf/sub [:wallet/network-details-by-chain-id chain-id])
|
||||
currency (rf/sub [:profile/currency])
|
||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||
prices-per-token (rf/sub [:wallet/prices-per-token])
|
||||
balance (utils/calculate-total-token-balance token [chain-id])
|
||||
crypto-value (utils/get-standard-crypto-format token balance prices-per-token)
|
||||
fiat-value (utils/calculate-token-fiat-value
|
||||
{:currency currency
|
||||
:balance balance
|
||||
:token token
|
||||
:prices-per-token prices-per-token})
|
||||
fiat-formatted (utils/fiat-formatted-for-ui currency-symbol
|
||||
fiat-value)
|
||||
token-available-on-network? (network-utils/token-available-on-network? supported-networks
|
||||
chain-id)]
|
||||
(fn [{:keys [chain-id network-name]} {:keys [supported-networks] :as token} selected-network]
|
||||
(let [network (rf/sub [:wallet/network-details-by-chain-id chain-id])
|
||||
currency (rf/sub [:profile/currency])
|
||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||
prices-per-token (rf/sub [:wallet/prices-per-token])
|
||||
{selected-network-chain-id :chain-id} selected-network
|
||||
balance (utils/calculate-total-token-balance token [chain-id])
|
||||
crypto-value (utils/get-standard-crypto-format token
|
||||
balance
|
||||
prices-per-token)
|
||||
fiat-value (utils/calculate-token-fiat-value
|
||||
{:currency currency
|
||||
:balance balance
|
||||
:token token
|
||||
:prices-per-token prices-per-token})
|
||||
fiat-formatted (utils/fiat-formatted-for-ui currency-symbol
|
||||
fiat-value)
|
||||
token-available-on-network? (network-utils/token-available-on-network?
|
||||
supported-networks
|
||||
chain-id)]
|
||||
[quo/network-list
|
||||
{:label (name network-name)
|
||||
:network-image (quo.resources/get-network (:network-name network))
|
||||
:token-value (str crypto-value " " (:symbol token))
|
||||
:fiat-value fiat-formatted
|
||||
:state (if token-available-on-network? :default :disabled)
|
||||
:state (if (and token-available-on-network? (not= chain-id selected-network-chain-id))
|
||||
:default
|
||||
:disabled)
|
||||
:on-press #(rf/dispatch [:wallet/select-bridge-network
|
||||
{:network-chain-id chain-id
|
||||
:stack-id :screen/wallet.bridge-to}])}])))
|
||||
@@ -46,6 +51,7 @@
|
||||
(let [network-details (rf/sub [:wallet/network-details])
|
||||
account (rf/sub [:wallet/current-viewing-account])
|
||||
token (rf/sub [:wallet/wallet-send-token])
|
||||
selected-network (rf/sub [:wallet/send-network])
|
||||
token-symbol (:symbol token)
|
||||
tokens (:tokens account)
|
||||
mainnet (first network-details)
|
||||
@@ -55,8 +61,7 @@
|
||||
(assoc account-token
|
||||
:networks (:networks token)
|
||||
:supported-networks (:supported-networks token)))
|
||||
bridge-to-title (i18n/label :t/bridge-to
|
||||
{:name (string/upper-case (str token-symbol))})]
|
||||
bridge-to-title (i18n/label :t/select-network-to-receive)]
|
||||
|
||||
(hot-reload/use-safe-unmount #(rf/dispatch [:wallet/clean-bridge-to-selection]))
|
||||
|
||||
@@ -68,11 +73,11 @@
|
||||
:switcher-type :select-account}]
|
||||
[quo/page-top {:title bridge-to-title}]
|
||||
[rn/view style/content-container
|
||||
[bridge-token-component (assoc mainnet :network-name :t/mainnet) account-token]]
|
||||
[bridge-token-component (assoc mainnet :network-name :t/mainnet) account-token selected-network]]
|
||||
|
||||
[quo/divider-label (i18n/label :t/layer-2)]
|
||||
[rn/flat-list
|
||||
{:data layer-2-networks
|
||||
:render-fn (fn [network]
|
||||
[bridge-token-component network account-token])
|
||||
[bridge-token-component network account-token selected-network])
|
||||
:content-container-style style/content-container}]]))
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
(ns status-im.contexts.wallet.bridge.flow-config)
|
||||
|
||||
(def steps
|
||||
[{:screen-id :screen/wallet.select-from
|
||||
:skip-step? (fn [db] (some? (get-in db [:wallet :current-viewing-account-address])))}
|
||||
{:screen-id :screen/wallet.bridge-select-asset
|
||||
[{:screen-id :screen/wallet.bridge-select-asset
|
||||
:skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :token])))}
|
||||
{:screen-id :screen/wallet.bridge-to
|
||||
:skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :bridge-to-chain-id])))}
|
||||
|
||||
@@ -82,13 +82,13 @@
|
||||
token-owners (rf/sub [:wallet/operable-addresses-with-token-symbol token-symbol])
|
||||
testnet-mode? (rf/sub [:profile/test-networks-enabled?])
|
||||
account-owns-token? (rf/sub [:wallet/current-account-owns-token token-symbol])
|
||||
network-details (rf/sub [:wallet/network-details])
|
||||
receive-token-symbol (if (= token-symbol "SNT") "ETH" "SNT")
|
||||
token-owned? (if selected-account account-owns-token? (seq token-owners))
|
||||
asset-to-receive (rf/sub [:wallet/token-by-symbol receive-token-symbol])
|
||||
params (cond-> {:start-flow? true
|
||||
:owners token-owners
|
||||
:testnet-mode? testnet-mode?
|
||||
:asset-to-receive asset-to-receive}
|
||||
params (cond-> {:start-flow? true
|
||||
:owners token-owners
|
||||
:testnet-mode? testnet-mode?}
|
||||
selected-account
|
||||
(assoc :token token-data
|
||||
:stack-id :screen/wallet.accounts
|
||||
@@ -108,9 +108,13 @@
|
||||
(action-send params entry-point))
|
||||
(action-receive selected-account)
|
||||
(when token-owned?
|
||||
(action-swap params))
|
||||
(action-swap (assoc params
|
||||
:asset-to-receive
|
||||
asset-to-receive)))
|
||||
(when token-owned?
|
||||
(action-bridge (assoc params
|
||||
:network-details
|
||||
network-details
|
||||
:bridge-disabled?
|
||||
(send-utils/bridge-disabled? token-symbol))))]))]]))
|
||||
|
||||
|
||||
@@ -1,23 +1,11 @@
|
||||
(ns status-im.contexts.wallet.common.wizard.events
|
||||
(:require [status-im.contexts.wallet.bridge.flow-config :as wallet-bridge-flow]
|
||||
[status-im.contexts.wallet.send.flow-config :as wallet-send-flow]
|
||||
(:require [status-im.contexts.wallet.common.wizard.utils :as wizard-utils]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn- wizard-find-next-screen
|
||||
[db flow-id current-screen]
|
||||
(let [flow-config (case flow-id
|
||||
:wallet-send-flow wallet-send-flow/steps
|
||||
:wallet-bridge-flow wallet-bridge-flow/steps
|
||||
nil)]
|
||||
(first (filter (fn [{:keys [skip-step? screen-id]}]
|
||||
(and (not= screen-id current-screen)
|
||||
(not (and (fn? skip-step?) (skip-step? db)))))
|
||||
flow-config))))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/wizard-navigate-forward
|
||||
(fn [{:keys [db]} [{:keys [current-screen flow-id start-flow?]}]]
|
||||
(let [next-screen (wizard-find-next-screen db flow-id current-screen)]
|
||||
(let [next-screen (wizard-utils/wizard-find-next-screen db flow-id current-screen)]
|
||||
{:fx [[:dispatch
|
||||
(if start-flow?
|
||||
[:open-modal (:screen-id next-screen)]
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
(ns status-im.contexts.wallet.common.wizard.utils
|
||||
(:require [status-im.contexts.wallet.bridge.flow-config :as wallet-bridge-flow]
|
||||
[status-im.contexts.wallet.send.flow-config :as wallet-send-flow]))
|
||||
|
||||
(defn wizard-find-next-screen
|
||||
[db flow-id current-screen]
|
||||
(let [flow-config (case flow-id
|
||||
:wallet-send-flow wallet-send-flow/steps
|
||||
:wallet-bridge-flow wallet-bridge-flow/steps
|
||||
nil)]
|
||||
(first (filter (fn [{:keys [skip-step? screen-id]}]
|
||||
(and (not= screen-id current-screen)
|
||||
(not (and (fn? skip-step?) (skip-step? db)))))
|
||||
flow-config))))
|
||||
@@ -10,11 +10,13 @@
|
||||
[status-im.contexts.settings.wallet.effects]
|
||||
[status-im.contexts.settings.wallet.events]
|
||||
[status-im.contexts.wallet.common.activity-tab.events]
|
||||
[status-im.contexts.wallet.common.utils :as utils]
|
||||
[status-im.contexts.wallet.common.utils.external-links :as external-links]
|
||||
[status-im.contexts.wallet.common.utils.networks :as network-utils]
|
||||
[status-im.contexts.wallet.data-store :as data-store]
|
||||
[status-im.contexts.wallet.db :as db]
|
||||
[status-im.contexts.wallet.item-types :as item-types]
|
||||
[status-im.contexts.wallet.sheets.network-selection.view :as network-selection]
|
||||
[status-im.contexts.wallet.tokens.events]
|
||||
[status-im.feature-flags :as ff]
|
||||
[taoensso.timbre :as log]
|
||||
@@ -343,19 +345,61 @@
|
||||
(rf/reg-event-fx :wallet/get-keypairs get-keypairs)
|
||||
|
||||
(rf/reg-event-fx :wallet/bridge-select-token
|
||||
(fn [{:keys [db]} [{:keys [token token-symbol stack-id start-flow?]}]]
|
||||
(let [missing-recipient? (-> db :wallet :ui :send :to-address nil?)
|
||||
to-address (-> db :wallet :current-viewing-account-address)]
|
||||
(fn [{:keys [db]}
|
||||
[{:keys [token token-symbol stack-id network owners network-details start-flow?] :as params}]]
|
||||
(let [{:keys [wallet]} db
|
||||
unique-owner (when (= (count owners) 1)
|
||||
(first owners))
|
||||
token (if (and unique-owner (nil? token))
|
||||
(let [token (utils/get-token-from-account db
|
||||
token-symbol
|
||||
unique-owner)]
|
||||
(assoc token
|
||||
:networks (network-utils/network-list-with-positive-balance
|
||||
token
|
||||
network-details)
|
||||
:supported-networks (network-utils/network-list
|
||||
token
|
||||
network-details)
|
||||
:total-balance (utils/calculate-total-token-balance token)))
|
||||
token)
|
||||
missing-recipient? (-> db :wallet :ui :send :to-address nil?)
|
||||
to-address (or unique-owner
|
||||
(-> db :wallet :current-viewing-account-address)
|
||||
(utils/get-default-account (-> db :wallet :accounts)))
|
||||
view-id (:view-id db)
|
||||
root-screen? (or (= view-id :wallet-stack) (nil? view-id))
|
||||
multi-account-balance? (-> (utils/get-accounts-with-token-balance (:accounts wallet)
|
||||
token)
|
||||
(count)
|
||||
(> 1))]
|
||||
{:db (cond-> db
|
||||
:always (assoc-in [:wallet :ui :send :tx-type] :tx/bridge)
|
||||
token (assoc-in [:wallet :ui :send :token] token)
|
||||
token-symbol (assoc-in [:wallet :ui :send :token-symbol] token-symbol)
|
||||
network (assoc-in [:wallet :ui :send :network] network)
|
||||
missing-recipient? (assoc-in [:wallet :ui :send :to-address] to-address))
|
||||
:fx [[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-bridge-flow}]]]})))
|
||||
:fx (if (and (not unique-owner) multi-account-balance? root-screen?)
|
||||
[[:dispatch [:open-modal :screen/wallet.select-from]]]
|
||||
(if (some? network)
|
||||
[[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-bridge-flow}]]]
|
||||
[[:dispatch [:wallet/switch-current-viewing-account to-address]]
|
||||
[:dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[network-selection/view
|
||||
{:title (i18n/label :t/select-network-to-bridge-from)
|
||||
:token-symbol (or token-symbol (:symbol token))
|
||||
:source :bridge
|
||||
:on-select-network (fn [network]
|
||||
(rf/dispatch [:hide-bottom-sheet])
|
||||
(rf/dispatch
|
||||
[:wallet/bridge-select-token
|
||||
(assoc params :network network)]))}])}]]]))})))
|
||||
|
||||
(rf/reg-event-fx :wallet/start-bridge
|
||||
(fn [{:keys [db]}]
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
[status-im.contexts.wallet.collectible.utils :as collectible.utils]
|
||||
[status-im.contexts.wallet.common.utils :as utils]
|
||||
[status-im.contexts.wallet.common.utils.networks :as network-utils]
|
||||
[status-im.contexts.wallet.common.wizard.utils :as wizard-utils]
|
||||
[status-im.contexts.wallet.data-store :as data-store]
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||
[status-im.contexts.wallet.sheets.network-selection.view :as network-selection]
|
||||
[taoensso.timbre :as log]
|
||||
[utils.money :as utils.money]
|
||||
[utils.number]
|
||||
@@ -148,23 +150,16 @@
|
||||
(rf/reg-event-fx
|
||||
:wallet/select-send-address
|
||||
(fn [{:keys [db]} [{:keys [address recipient stack-id start-flow?]}]]
|
||||
(let [[prefix to-address] (utils/split-prefix-and-address address)
|
||||
testnet-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||
receiver-networks (network-utils/resolve-receiver-networks
|
||||
{:prefix prefix
|
||||
:testnet-enabled? testnet-enabled?})
|
||||
collectible-tx? (send-utils/tx-type-collectible?
|
||||
(-> db :wallet :ui :send :tx-type))
|
||||
collectible (when collectible-tx?
|
||||
(-> db :wallet :ui :send :collectible))
|
||||
one-collectible? (when collectible-tx?
|
||||
(= (collectible.utils/collectible-balance collectible) 1))]
|
||||
(let [[_ to-address] (utils/split-prefix-and-address address)
|
||||
collectible-tx? (send-utils/tx-type-collectible?
|
||||
(-> db :wallet :ui :send :tx-type))
|
||||
collectible (when collectible-tx?
|
||||
(-> db :wallet :ui :send :collectible))
|
||||
one-collectible? (when collectible-tx?
|
||||
(= (collectible.utils/collectible-balance collectible) 1))]
|
||||
{:db (-> db
|
||||
(assoc-in [:wallet :ui :send :recipient] (or recipient address))
|
||||
(assoc-in [:wallet :ui :send :to-address] to-address)
|
||||
(assoc-in [:wallet :ui :send :address-prefix] prefix)
|
||||
(assoc-in [:wallet :ui :send :receiver-preferred-networks] receiver-networks)
|
||||
(assoc-in [:wallet :ui :send :receiver-networks] receiver-networks))
|
||||
(assoc-in [:wallet :ui :send :to-address] to-address))
|
||||
:fx [(when (and collectible-tx? one-collectible?)
|
||||
[:dispatch [:wallet/start-get-suggested-routes {:amount 1}]])
|
||||
[:dispatch
|
||||
@@ -182,14 +177,12 @@
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/set-token-to-send
|
||||
(fn [{:keys [db]} [{:keys [token-symbol token stack-id start-flow? owners]} entry-point]]
|
||||
(fn [{:keys [db]}
|
||||
[{:keys [token-symbol token network stack-id start-flow? owners] :as params} entry-point]]
|
||||
;; `token` is a map extracted from the sender, but in the wallet home page we don't know the
|
||||
;; sender yet, so we only provide the `token-symbol`, later in
|
||||
;; `:wallet/select-from-account` the `token` key will be set.
|
||||
(let [{:keys [networks]} token
|
||||
receiver-networks (get-in db [:wallet :ui :send :receiver-networks])
|
||||
token-networks-ids (map :chain-id networks)
|
||||
unsupported-token? (not-any? (set receiver-networks) token-networks-ids)
|
||||
(let [{:keys [wallet]} db
|
||||
unique-owner (when (= (count owners) 1)
|
||||
(first owners))
|
||||
unique-owner-tokens (get-in db [:wallet :accounts unique-owner :tokens])
|
||||
@@ -197,17 +190,25 @@
|
||||
(when (and token-symbol unique-owner)
|
||||
(some #(when (= (:symbol %) token-symbol) %)
|
||||
unique-owner-tokens)))
|
||||
view-id (:view-id db)
|
||||
root-screen? (or (= view-id :wallet-stack) (nil? view-id))
|
||||
multi-account-balance? (-> (utils/get-accounts-with-token-balance (:accounts wallet)
|
||||
token)
|
||||
(count)
|
||||
(> 1))
|
||||
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||
network-details (-> (get-in db
|
||||
[:wallet :networks (if test-networks-enabled? :test :prod)])
|
||||
(network-utils/sorted-networks-with-details))]
|
||||
(network-utils/sorted-networks-with-details))
|
||||
next-screen (:screen-id (wizard-utils/wizard-find-next-screen db
|
||||
:wallet-send-flow
|
||||
stack-id))]
|
||||
(when (or token-data token-symbol)
|
||||
{:db (cond-> db
|
||||
:always (update-in [:wallet :ui :send]
|
||||
network (update-in [:wallet :ui :send]
|
||||
#(-> %
|
||||
(dissoc :collectible :tx-type)
|
||||
(assoc :token-not-supported-in-receiver-networks?
|
||||
unsupported-token?)))
|
||||
(assoc :network network)))
|
||||
token-symbol (assoc-in [:wallet :ui :send :token-symbol] token-symbol)
|
||||
token-data (update-in [:wallet :ui :send]
|
||||
#(assoc %
|
||||
@@ -216,20 +217,35 @@
|
||||
(network-utils/network-list
|
||||
token-data
|
||||
network-details))
|
||||
:token-display-name (:symbol token-data)))
|
||||
:token-display-name (:symbol token-data)
|
||||
:token-symbol (:symbol token-data)))
|
||||
unique-owner (assoc-in [:wallet :current-viewing-account-address] unique-owner)
|
||||
entry-point (assoc-in [:wallet :ui :send :entry-point] entry-point))
|
||||
:fx [[:dispatch [:wallet/stop-and-clean-suggested-routes]]
|
||||
[:dispatch
|
||||
;; ^:flush-dom allows us to make sure the re-frame DB state is always synced
|
||||
;; before the navigation occurs, so the new screen is always rendered with
|
||||
;; the DB state set by this event. By adding the metadata we are omitting
|
||||
;; a 1-frame blink when the screen is mounted.
|
||||
^:flush-dom
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-send-flow}]]]}))))
|
||||
:fx (if (and (not unique-owner) multi-account-balance? root-screen?)
|
||||
[[:dispatch [:open-modal :screen/wallet.select-from]]]
|
||||
(if (or (= next-screen :screen/wallet.select-from) (some? network))
|
||||
[[:dispatch [:wallet/stop-and-clean-suggested-routes]]
|
||||
[:dispatch
|
||||
;; ^:flush-dom allows us to make sure the re-frame DB state is always synced
|
||||
;; before the navigation occurs, so the new screen is always rendered with
|
||||
;; the DB state set by this event. By adding the metadata we are omitting
|
||||
;; a 1-frame blink when the screen is mounted.
|
||||
^:flush-dom
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id :wallet-send-flow}]]]
|
||||
[[:dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[network-selection/view
|
||||
{:token-symbol (or token-symbol (:symbol token-data))
|
||||
:source :send
|
||||
:on-select-network (fn [network]
|
||||
(rf/dispatch [:hide-bottom-sheet])
|
||||
(rf/dispatch
|
||||
[:wallet/set-token-to-send
|
||||
(assoc params :network network)]))}])}]]]))}))))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/edit-token-to-send
|
||||
@@ -288,7 +304,7 @@
|
||||
|
||||
collectible
|
||||
(str (:name collection-data) " #" collectible-id))
|
||||
owner-address (-> db :wallet :current-viewing-account-address)
|
||||
owner-address (-> collectible :ownership first :address)
|
||||
collectible-tx (-> db
|
||||
(update-in [:wallet :ui :send] dissoc :token)
|
||||
(assoc-in [:wallet :ui :send :collectible] collectible)
|
||||
@@ -404,89 +420,62 @@
|
||||
|
||||
(rf/reg-event-fx :wallet/start-get-suggested-routes
|
||||
(fn [{:keys [db]} [{:keys [amount amount-out updated-token] :as args :or {amount-out "0"}}]]
|
||||
(let [wallet-address (get-in db [:wallet :current-viewing-account-address])
|
||||
(let [wallet-address (get-in db [:wallet :current-viewing-account-address])
|
||||
{:keys [token tx-type collectible to-address
|
||||
receiver-networks disabled-from-chain-ids
|
||||
from-locked-amounts bridge-to-chain-id]
|
||||
network bridge-to-chain-id]
|
||||
:or {token updated-token}} (get-in db [:wallet :ui :send])
|
||||
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||
networks (get-in db [:wallet :networks (if test-networks-enabled? :test :prod)])
|
||||
network-chain-ids (map :chain-id networks)
|
||||
token-decimal (when token (:decimals token))
|
||||
token-id (utils/format-token-id token collectible)
|
||||
to-token-id ""
|
||||
gas-rates constants/gas-rate-medium
|
||||
to-hex (fn [v] (send-utils/amount-in-hex v (if token token-decimal 0)))
|
||||
amount-in (to-hex amount)
|
||||
amount-out (to-hex amount-out)
|
||||
from-address wallet-address
|
||||
disabled-to-chain-ids (if (= tx-type :tx/bridge)
|
||||
(filter #(not= % bridge-to-chain-id) network-chain-ids)
|
||||
(filter (fn [chain-id]
|
||||
(not (some #(= chain-id %)
|
||||
receiver-networks)))
|
||||
network-chain-ids))
|
||||
from-locked-amount (update-vals from-locked-amounts to-hex)
|
||||
send-type (case tx-type
|
||||
:tx/collectible-erc-721 constants/send-type-erc-721-transfer
|
||||
:tx/collectible-erc-1155 constants/send-type-erc-1155-transfer
|
||||
:tx/bridge constants/send-type-bridge
|
||||
constants/send-type-transfer)
|
||||
balances-per-chain (when token (:balances-per-chain token))
|
||||
sender-token-available-networks-for-suggested-routes
|
||||
(when token
|
||||
(send-utils/token-available-networks-for-suggested-routes
|
||||
{:balances-per-chain balances-per-chain
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:only-with-balance? true}))
|
||||
receiver-token-available-networks-for-suggested-routes
|
||||
(when token
|
||||
(send-utils/token-available-networks-for-suggested-routes
|
||||
{:balances-per-chain balances-per-chain
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:only-with-balance? false}))
|
||||
token-networks-ids (when token (map #(:chain-id %) (:supported-networks token)))
|
||||
sender-network-values (when sender-token-available-networks-for-suggested-routes
|
||||
(send-utils/loading-network-amounts
|
||||
{:valid-networks
|
||||
(if (= tx-type :tx/bridge)
|
||||
(remove #(= bridge-to-chain-id %)
|
||||
sender-token-available-networks-for-suggested-routes)
|
||||
sender-token-available-networks-for-suggested-routes)
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? false}))
|
||||
receiver-network-values (when receiver-token-available-networks-for-suggested-routes
|
||||
(send-utils/loading-network-amounts
|
||||
{:valid-networks
|
||||
(if (= tx-type :tx/bridge)
|
||||
(filter
|
||||
#(= bridge-to-chain-id %)
|
||||
receiver-token-available-networks-for-suggested-routes)
|
||||
receiver-token-available-networks-for-suggested-routes)
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
:tx-type tx-type
|
||||
:receiver? true}))
|
||||
request-uuid (str (random-uuid))
|
||||
params [{:uuid request-uuid
|
||||
:sendType send-type
|
||||
:addrFrom from-address
|
||||
:addrTo to-address
|
||||
:amountIn amount-in
|
||||
:amountOut amount-out
|
||||
:tokenID token-id
|
||||
:toTokenID to-token-id
|
||||
:disabledFromChainIDs disabled-from-chain-ids
|
||||
:disabledToChainIDs disabled-to-chain-ids
|
||||
:gasFeeMode gas-rates
|
||||
:fromLockedAmount from-locked-amount
|
||||
:username (:username args)
|
||||
:publicKey (:publicKey args)
|
||||
:packID (:packID args)}]]
|
||||
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||
networks (get-in db
|
||||
[:wallet :networks
|
||||
(if test-networks-enabled? :test :prod)])
|
||||
network-chain-ids (map :chain-id networks)
|
||||
token-decimal (when token (:decimals token))
|
||||
token-id (utils/format-token-id token collectible)
|
||||
to-token-id ""
|
||||
gas-rates constants/gas-rate-medium
|
||||
to-hex (fn [v] (send-utils/amount-in-hex v (if token token-decimal 0)))
|
||||
amount-in (to-hex amount)
|
||||
amount-out (to-hex amount-out)
|
||||
from-address wallet-address
|
||||
network-chain-id (if collectible
|
||||
(get-in collectible [:id :contract-id :chain-id])
|
||||
(:chain-id network))
|
||||
disabled-from-chain-ids (filter #(not= % network-chain-id) network-chain-ids)
|
||||
disabled-to-chain-ids (filter #(not= %
|
||||
(if (= tx-type :tx/bridge)
|
||||
bridge-to-chain-id
|
||||
network-chain-id))
|
||||
network-chain-ids)
|
||||
send-type (case tx-type
|
||||
:tx/collectible-erc-721 constants/send-type-erc-721-transfer
|
||||
:tx/collectible-erc-1155 constants/send-type-erc-1155-transfer
|
||||
:tx/bridge constants/send-type-bridge
|
||||
constants/send-type-transfer)
|
||||
sender-network-values (when (= tx-type :tx/bridge)
|
||||
(send-utils/loading-network-amounts
|
||||
{:networks [network-chain-id]
|
||||
:values {network-chain-id amount}
|
||||
:receiver? false}))
|
||||
receiver-network-values (when (= tx-type :tx/bridge)
|
||||
(send-utils/loading-network-amounts
|
||||
{:networks [bridge-to-chain-id]
|
||||
:receiver? true}))
|
||||
request-uuid (str (random-uuid))
|
||||
params [{:uuid request-uuid
|
||||
:sendType send-type
|
||||
:addrFrom from-address
|
||||
:addrTo to-address
|
||||
:amountIn amount-in
|
||||
:amountOut amount-out
|
||||
:tokenID token-id
|
||||
:toTokenID to-token-id
|
||||
:disabledFromChainIDs disabled-from-chain-ids
|
||||
:disabledToChainIDs disabled-to-chain-ids
|
||||
:gasFeeMode gas-rates
|
||||
:fromLockedAmount {}
|
||||
:username (:username args)
|
||||
:publicKey (:publicKey args)
|
||||
:packID (:packID args)}]]
|
||||
(when (and to-address from-address amount-in token-id)
|
||||
{:db (update-in db
|
||||
[:wallet :ui :send]
|
||||
@@ -712,7 +701,7 @@
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/select-from-account
|
||||
(fn [{db :db} [{:keys [address stack-id network-details start-flow?]}]]
|
||||
(fn [{db :db} [{:keys [address stack-id network-details network start-flow?] :as params}]]
|
||||
(let [{:keys [token-symbol
|
||||
tx-type]} (-> db :wallet :ui :send)
|
||||
token (when token-symbol
|
||||
@@ -724,22 +713,38 @@
|
||||
:networks (network-utils/network-list-with-positive-balance
|
||||
token
|
||||
network-details)
|
||||
:supported-networks (network-utils/network-list token
|
||||
network-details)
|
||||
:supported-networks (network-utils/network-list
|
||||
token
|
||||
network-details)
|
||||
:total-balance (utils/calculate-total-token-balance token))))
|
||||
bridge-tx? (= tx-type :tx/bridge)
|
||||
flow-id (if bridge-tx?
|
||||
:wallet-bridge-flow
|
||||
:wallet-send-flow)]
|
||||
{:db (cond-> db
|
||||
network (assoc-in [:wallet :ui :send :network] network)
|
||||
token-symbol (assoc-in [:wallet :ui :send :token] token)
|
||||
bridge-tx? (assoc-in [:wallet :ui :send :to-address] address))
|
||||
:fx [[:dispatch [:wallet/switch-current-viewing-account address]]
|
||||
[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id flow-id}]]]})))
|
||||
:fx (if (some? network)
|
||||
[[:dispatch [:wallet/switch-current-viewing-account address]]
|
||||
[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
:start-flow? start-flow?
|
||||
:flow-id flow-id}]]]
|
||||
[[:dispatch [:dismiss-modal :screen/wallet.select-from]]
|
||||
[:dispatch [:wallet/switch-current-viewing-account address]]
|
||||
[:dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[network-selection/view
|
||||
{:token-symbol (or token-symbol (:symbol token))
|
||||
:source :send
|
||||
:on-select-network (fn [network]
|
||||
(rf/dispatch [:hide-bottom-sheet])
|
||||
(rf/dispatch
|
||||
[:wallet/select-from-account
|
||||
(assoc params :network network)]))}])}]]])})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/transaction-confirmation-navigate-back
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns status-im.contexts.wallet.send.events-test
|
||||
(:require
|
||||
[cljs.test :refer-macros [is testing]]
|
||||
[matcher-combinators.matchers :as m]
|
||||
matcher-combinators.test
|
||||
[re-frame.db :as rf-db]
|
||||
[status-im.contexts.wallet.common.utils.networks :as network-utils]
|
||||
@@ -579,8 +580,23 @@
|
||||
[event-id dispatch]
|
||||
(let [stack-id :screen/stack
|
||||
start-flow? false
|
||||
address "0x01"]
|
||||
address "0x01"
|
||||
network {:chain-id 1}]
|
||||
(testing "when tx-type is :tx/bridge and token-symbol is nil"
|
||||
(let [flow-id :wallet-bridge-flow
|
||||
tx-type :tx/bridge
|
||||
expected-result {:db {:wallet {:ui {:send {:to-address address
|
||||
:tx-type tx-type}}}}
|
||||
:fx [[:dispatch [:dismiss-modal :screen/wallet.select-from]]
|
||||
[:dispatch [:wallet/switch-current-viewing-account address]]
|
||||
[:dispatch [:show-bottom-sheet {:content (m/pred fn?)}]]]}]
|
||||
(reset! rf-db/app-db {:wallet {:ui {:send {:tx-type tx-type}}}})
|
||||
(is (match? expected-result
|
||||
(dispatch [event-id
|
||||
{:address address
|
||||
:stack-id stack-id
|
||||
:start-flow? start-flow?}])))))
|
||||
(testing "when tx-type is :tx/bridge, network is selected and token-symbol is nil"
|
||||
(let [flow-id :wallet-bridge-flow
|
||||
tx-type :tx/bridge
|
||||
expected-result {:db {:wallet {:ui {:send {:to-address address
|
||||
@@ -596,6 +612,7 @@
|
||||
(dispatch [event-id
|
||||
{:address address
|
||||
:stack-id stack-id
|
||||
:network network
|
||||
:start-flow? start-flow?}])))))
|
||||
(testing "when tx-type is not :tx/bridge and token-symbol is nil"
|
||||
(let [flow-id :wallet-send-flow
|
||||
@@ -612,6 +629,7 @@
|
||||
(dispatch [event-id
|
||||
{:address address
|
||||
:stack-id stack-id
|
||||
:network network
|
||||
:start-flow? start-flow?}])))))
|
||||
(testing "when tx-type is :tx/bridge and token-symbol is not nil"
|
||||
(let [flow-id :wallet-bridge-flow
|
||||
@@ -680,5 +698,6 @@
|
||||
(dispatch [event-id
|
||||
{:address address
|
||||
:stack-id stack-id
|
||||
:network network
|
||||
:start-flow? start-flow?
|
||||
:netork-details network-details}])))))))
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
(-> db :wallet :ui :send :token some?))
|
||||
|
||||
(def steps
|
||||
[{:screen-id :screen/wallet.select-from
|
||||
:skip-step? (fn [db] (some? (get-in db [:wallet :current-viewing-account-address])))}
|
||||
{:screen-id :screen/wallet.select-address
|
||||
[{:screen-id :screen/wallet.select-address
|
||||
:skip-step? (fn [db] (some? (get-in db [:wallet :ui :send :recipient])))}
|
||||
{:screen-id :screen/wallet.select-asset
|
||||
:skip-step? (fn [db] (or (token-selected? db) (collectible-selected? db)))}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
[status-im.common.floating-button-page.view :as floating-button-page]
|
||||
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
|
||||
[status-im.contexts.wallet.send.from.style :as style]
|
||||
[status-im.setup.hot-reload :as hot-reload]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.money :as money]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn- on-account-press
|
||||
@@ -15,27 +15,28 @@
|
||||
(rf/dispatch [:wallet/select-from-account
|
||||
{:address address
|
||||
:network-details network-details
|
||||
:stack-id :screen/wallet.select-from}]))
|
||||
|
||||
(defn- on-close
|
||||
[]
|
||||
(rf/dispatch [:wallet/clean-current-viewing-account]))
|
||||
:stack-id :screen/wallet.select-from
|
||||
:start-flow? true}]))
|
||||
|
||||
(defn- render-fn
|
||||
[item _ _ {:keys [network-details]}]
|
||||
(let [transformed-address (rf/sub [:wallet/account-address (:address item)
|
||||
(:network-preferences-names item)])]
|
||||
(let [has-balance (money/above-zero? (:asset-pay-balance item))]
|
||||
[quo/account-item
|
||||
{:on-press #(on-account-press (:address item) network-details)
|
||||
{:type (if has-balance :tag :default)
|
||||
:on-press #(on-account-press (:address item) network-details)
|
||||
:state (if has-balance :default :disabled)
|
||||
:token-props {:symbol (:asset-pay-symbol item)
|
||||
:value (:asset-pay-balance item)}
|
||||
:account-props (assoc item
|
||||
:address transformed-address
|
||||
:address (:formatted-address item)
|
||||
:full-address? true)}]))
|
||||
|
||||
(defn view
|
||||
[]
|
||||
(let [accounts (rf/sub [:wallet/accounts-with-current-asset])
|
||||
(let [token-symbol (rf/sub [:wallet/send-token-symbol])
|
||||
token (rf/sub [:wallet/token-by-symbol token-symbol])
|
||||
accounts (rf/sub [:wallet/accounts-with-balances token])
|
||||
network-details (rf/sub [:wallet/network-details])]
|
||||
(hot-reload/use-safe-unmount on-close)
|
||||
[floating-button-page/view
|
||||
{:footer-container-padding 0
|
||||
:header [account-switcher/view
|
||||
|
||||
@@ -30,19 +30,16 @@
|
||||
(let [amount (rf/sub [:wallet/send-total-amount-formatted])
|
||||
tx-type (rf/sub [:wallet/wallet-send-tx-type])
|
||||
{:keys [full-name]} (rf/sub [:wallet/bridge-to-network-details])]
|
||||
[quo/data-item
|
||||
(cond-> {:container-style style/amount-data-item
|
||||
:status (if loading-routes? :loading :default)
|
||||
:size :small
|
||||
:title (i18n/label :t/recipient-gets)
|
||||
:subtitle amount}
|
||||
|
||||
(= tx-type :tx/bridge)
|
||||
(assoc
|
||||
:title-icon :i/info
|
||||
:title (i18n/label :t/bridged-to
|
||||
{:network full-name})
|
||||
:on-press show-bonder-fee-info))]))
|
||||
(when (= tx-type :tx/bridge)
|
||||
[quo/data-item
|
||||
{:container-style style/amount-data-item
|
||||
:status (if loading-routes? :loading :default)
|
||||
:size :small
|
||||
:title-icon :i/info
|
||||
:title (i18n/label :t/bridged-to
|
||||
{:network full-name})
|
||||
:subtitle amount
|
||||
:on-press show-bonder-fee-info}])))
|
||||
|
||||
(defn view
|
||||
[{:keys [loading-routes? fees]}]
|
||||
@@ -62,6 +59,6 @@
|
||||
{:container-style style/fees-data-item
|
||||
:status (if loading-routes? :loading :default)
|
||||
:size :small
|
||||
:title (i18n/label :t/fees)
|
||||
:title (i18n/label :t/max-fees)
|
||||
:subtitle fees}]
|
||||
[received-amount {:loading-routes? loading-routes?}]])
|
||||
|
||||
@@ -25,10 +25,9 @@
|
||||
:height 40})
|
||||
|
||||
(def fees-data-item
|
||||
{:flex 1
|
||||
:height 40
|
||||
:margin-horizontal 16
|
||||
:background-color :transparent})
|
||||
{:flex 1
|
||||
:height 40
|
||||
:background-color :transparent})
|
||||
|
||||
(def amount-data-item
|
||||
{:flex 1
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[quo.core :as quo]
|
||||
[quo.foundations.colors :as colors]
|
||||
[quo.theme]
|
||||
[react-native.core :as rn]
|
||||
[react-native.safe-area :as safe-area]
|
||||
@@ -15,29 +14,18 @@
|
||||
[status-im.contexts.wallet.send.input-amount.style :as style]
|
||||
[status-im.contexts.wallet.send.routes.view :as routes]
|
||||
[status-im.contexts.wallet.sheets.buy-token.view :as buy-token]
|
||||
[status-im.contexts.wallet.sheets.unpreferred-networks-alert.view :as unpreferred-networks-alert]
|
||||
[status-im.setup.hot-reload :as hot-reload]
|
||||
[utils.debounce :as debounce]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.money :as money]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn- every-network-value-is-zero?
|
||||
[sender-network-values]
|
||||
(every? (fn [{:keys [total-amount]}]
|
||||
(and
|
||||
total-amount
|
||||
(money/bignumber? total-amount)
|
||||
(money/equal-to total-amount
|
||||
(money/bignumber "0"))))
|
||||
sender-network-values))
|
||||
|
||||
(defn select-asset-bottom-sheet
|
||||
[clear-input!]
|
||||
(let [{preselected-token-symbol :symbol} (rf/sub [:wallet/wallet-send-token])]
|
||||
[:<> ;; Need to be a `:<>` to keep `asset-list` scrollable.
|
||||
[quo/drawer-top
|
||||
{:title (i18n/label :t/select-asset)
|
||||
{:title (i18n/label :t/select-token)
|
||||
:container-style {:padding-bottom 8}}]
|
||||
[asset-list/view
|
||||
{:content-container-style {:padding-horizontal 8
|
||||
@@ -47,37 +35,6 @@
|
||||
(rf/dispatch [:wallet/edit-token-to-send token])
|
||||
(clear-input!))}]]))
|
||||
|
||||
(defn- token-not-available
|
||||
[token-symbol receiver-networks token-networks]
|
||||
(let [theme (quo.theme/use-theme)
|
||||
add-token-networks (fn []
|
||||
(let [chain-ids (concat receiver-networks
|
||||
(mapv #(:chain-id %) token-networks))]
|
||||
(rf/dispatch [:wallet/update-receiver-networks chain-ids])))]
|
||||
[rn/view {:style (style/token-not-available-container theme)}
|
||||
[rn/view
|
||||
[quo/icon :i/alert
|
||||
{:size 16
|
||||
:color (colors/resolve-color :danger theme)}]]
|
||||
[rn/view {:style style/token-not-available-content-container}
|
||||
[quo/text
|
||||
{:style (style/token-not-available-text theme)
|
||||
:size :paragraph-2}
|
||||
(i18n/label :t/token-not-available-on-receiver-networks {:token-symbol token-symbol})]
|
||||
[quo/button
|
||||
{:size 24
|
||||
:customization-color (colors/resolve-color :danger theme)
|
||||
:on-press add-token-networks}
|
||||
(i18n/label :t/add-networks-token-can-be-sent-to {:token-symbol token-symbol})]]]))
|
||||
|
||||
(defn- show-unpreferred-networks-alert
|
||||
[on-confirm]
|
||||
(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[unpreferred-networks-alert/view
|
||||
{:on-confirm on-confirm}])}]))
|
||||
|
||||
(defn- no-routes-found
|
||||
[]
|
||||
[rn/view {:style style/no-routes-found-container}
|
||||
@@ -119,7 +76,7 @@
|
||||
|
||||
(defn- insufficient-asset-amount?
|
||||
[{:keys [token-symbol owned-eth-token input-state no-routes-found? limit-exceeded?
|
||||
sender-network-values enough-assets?]}]
|
||||
enough-assets?]}]
|
||||
(let [eth-selected? (= token-symbol (string/upper-case constants/mainnet-short-name))
|
||||
zero-owned-eth? (money/equal-to (:total-balance owned-eth-token) 0)
|
||||
input-at-max-owned-amount? (money/equal-to
|
||||
@@ -129,7 +86,6 @@
|
||||
input-at-max-owned-amount?
|
||||
zero-owned-eth?)]
|
||||
(and (or no-routes-found? limit-exceeded?)
|
||||
(seq sender-network-values)
|
||||
(or exceeded-input? (not enough-assets?)))))
|
||||
|
||||
(defn view
|
||||
@@ -142,122 +98,104 @@
|
||||
button-one-props :button-one-props
|
||||
current-screen-id :current-screen-id
|
||||
initial-crypto-currency? :initial-crypto-currency?
|
||||
enabled-from-chain-ids :enabled-from-chain-ids
|
||||
from-enabled-networks :from-enabled-networks
|
||||
:or {initial-crypto-currency? true}}]
|
||||
(let [view-id (rf/sub [:view-id])
|
||||
active-screen? (= view-id current-screen-id)
|
||||
bottom (safe-area/get-bottom)
|
||||
[crypto-currency?
|
||||
set-crypto-currency] (rn/use-state initial-crypto-currency?)
|
||||
handle-on-confirm (fn [amount]
|
||||
(rf/dispatch [:wallet/set-token-amount-to-send
|
||||
{:amount amount
|
||||
:stack-id current-screen-id}]))
|
||||
{fiat-currency :currency} (rf/sub [:profile/profile])
|
||||
{token-symbol :symbol
|
||||
token-networks :networks
|
||||
:as token} (rf/sub [:wallet/wallet-send-token])
|
||||
send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts])
|
||||
(let [view-id (rf/sub [:view-id])
|
||||
{fiat-currency :currency} (rf/sub [:profile/profile])
|
||||
currency (rf/sub [:profile/currency])
|
||||
{token-symbol :symbol
|
||||
:as token} (rf/sub [:wallet/wallet-send-token])
|
||||
network (rf/sub [:wallet/send-network])
|
||||
{:keys [total-balance]
|
||||
:as token-by-symbol} (rf/sub [:wallet/token-by-symbol
|
||||
(str token-symbol)
|
||||
enabled-from-chain-ids])
|
||||
token-balance (or default-limit-crypto total-balance)
|
||||
prices-per-token (rf/sub [:wallet/prices-per-token])
|
||||
usd-conversion-rate (utils/token-usd-price token prices-per-token)
|
||||
currency (rf/sub [:profile/currency])
|
||||
token-decimals (rf/sub [:wallet/send-display-token-decimals])
|
||||
|
||||
conversion-rate (utils/token-price-by-symbol prices-per-token
|
||||
token-symbol
|
||||
currency)
|
||||
[input-state set-input-state] (rn/use-state controlled-input/init-state)
|
||||
clear-input! #(set-input-state controlled-input/delete-all)
|
||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||
loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
|
||||
route (rf/sub [:wallet/wallet-send-route])
|
||||
on-confirm (or default-on-confirm handle-on-confirm)
|
||||
max-limit (if crypto-currency?
|
||||
(utils/cut-crypto-decimals-to-fit-usd-cents
|
||||
token-balance
|
||||
usd-conversion-rate)
|
||||
(utils/cut-fiat-balance-to-two-decimals
|
||||
(money/crypto->fiat token-balance conversion-rate)))
|
||||
input-value (controlled-input/input-value input-state)
|
||||
valid-input? (not (or (controlled-input/empty-value? input-state)
|
||||
(controlled-input/input-error input-state)))
|
||||
amount-in-crypto (if crypto-currency?
|
||||
input-value
|
||||
(rf/sub [:wallet/send-amount-fixed
|
||||
(/ input-value conversion-rate)]))
|
||||
show-select-asset-sheet #(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[select-asset-bottom-sheet
|
||||
clear-input!])}])
|
||||
sender-network-values (rf/sub [:wallet/wallet-send-sender-network-values])
|
||||
receiver-network-values (rf/sub [:wallet/wallet-send-receiver-network-values])
|
||||
tx-type (rf/sub [:wallet/wallet-send-tx-type])
|
||||
unsupported-token-in-receiver? (and (not= tx-type :tx/bridge)
|
||||
(->> receiver-network-values
|
||||
(remove #(= (:type %) :add))
|
||||
(every? #(= (:type %) :not-available))))
|
||||
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
|
||||
routes (when suggested-routes
|
||||
(or (:best suggested-routes) []))
|
||||
no-routes-found? (and
|
||||
(every-network-value-is-zero? sender-network-values)
|
||||
(some? routes)
|
||||
(not loading-routes?)
|
||||
(not unsupported-token-in-receiver?))
|
||||
receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
|
||||
receiver-preferred-networks (rf/sub [:wallet/wallet-send-receiver-preferred-networks])
|
||||
receiver-preferred-network? (set receiver-preferred-networks)
|
||||
sending-to-unpreferred-networks? (some (comp not receiver-preferred-network?)
|
||||
receiver-networks)
|
||||
input-error (controlled-input/input-error input-state)
|
||||
limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
|
||||
current-address (rf/sub [:wallet/current-viewing-account-address])
|
||||
current-color (rf/sub [:wallet/current-viewing-account-color])
|
||||
enough-assets? (rf/sub [:wallet/wallet-send-enough-assets?])
|
||||
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
||||
(string/upper-case constants/mainnet-short-name)
|
||||
enabled-from-chain-ids])
|
||||
not-enough-asset? (insufficient-asset-amount?
|
||||
{:enough-assets? enough-assets?
|
||||
:token-symbol token-symbol
|
||||
:owned-eth-token owned-eth-token
|
||||
:input-state input-state
|
||||
:no-routes-found? no-routes-found?
|
||||
:limit-exceeded? limit-exceeded?
|
||||
:sender-network-values sender-network-values})
|
||||
should-try-again? (and (not limit-exceeded?)
|
||||
no-routes-found?
|
||||
(not not-enough-asset?))
|
||||
show-no-routes? (and (or no-routes-found? limit-exceeded?)
|
||||
(not-empty sender-network-values)
|
||||
(not not-enough-asset?))
|
||||
confirm-disabled? (or (nil? route)
|
||||
(empty? route)
|
||||
(not valid-input?))
|
||||
fee-formatted (when (or (not confirm-disabled?) not-enough-asset?)
|
||||
(get-fee-formatted route))
|
||||
request-fetch-routes (fn [bounce-duration-ms]
|
||||
(fetch-routes
|
||||
{:amount amount-in-crypto
|
||||
:valid-input? valid-input?
|
||||
:bounce-duration-ms bounce-duration-ms
|
||||
:token token
|
||||
:reset-amounts-to-zero? (and limit-exceeded?
|
||||
(some? routes))}))
|
||||
swap-between-fiat-and-crypto (fn []
|
||||
(if crypto-currency?
|
||||
(set-input-state
|
||||
#(controlled-input/->fiat % conversion-rate))
|
||||
(set-input-state
|
||||
#(controlled-input/->crypto % conversion-rate)))
|
||||
(set-crypto-currency (not crypto-currency?)))]
|
||||
:as token-by-symbol} (rf/sub [:wallet/token-by-symbol
|
||||
(str token-symbol)
|
||||
[(:chain-id network)]])
|
||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||
loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
|
||||
route (rf/sub [:wallet/wallet-send-route])
|
||||
current-address (rf/sub [:wallet/current-viewing-account-address])
|
||||
current-color (rf/sub [:wallet/current-viewing-account-color])
|
||||
enough-assets? (rf/sub [:wallet/wallet-send-enough-assets?])
|
||||
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
||||
(string/upper-case constants/mainnet-short-name)
|
||||
[(:chain-id network)]])
|
||||
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
|
||||
tx-type (rf/sub [:wallet/wallet-send-tx-type])
|
||||
[crypto-currency?
|
||||
set-crypto-currency] (rn/use-state initial-crypto-currency?)
|
||||
[input-state set-input-state] (rn/use-state controlled-input/init-state)
|
||||
active-screen? (= view-id current-screen-id)
|
||||
bottom (safe-area/get-bottom)
|
||||
token-balance (or default-limit-crypto total-balance)
|
||||
prices-per-token (rf/sub [:wallet/prices-per-token])
|
||||
usd-conversion-rate (utils/token-usd-price token prices-per-token)
|
||||
conversion-rate (utils/token-price-by-symbol prices-per-token
|
||||
token-symbol
|
||||
currency)
|
||||
token-decimals (rf/sub [:wallet/send-display-token-decimals])
|
||||
clear-input! #(set-input-state controlled-input/delete-all)
|
||||
max-limit (if crypto-currency?
|
||||
(utils/cut-crypto-decimals-to-fit-usd-cents
|
||||
token-balance
|
||||
usd-conversion-rate)
|
||||
(utils/cut-fiat-balance-to-two-decimals
|
||||
(money/crypto->fiat token-balance conversion-rate)))
|
||||
input-value (controlled-input/input-value input-state)
|
||||
valid-input? (not (or (controlled-input/empty-value? input-state)
|
||||
(controlled-input/input-error input-state)))
|
||||
amount-in-crypto (if crypto-currency?
|
||||
input-value
|
||||
(rf/sub [:wallet/send-amount-fixed
|
||||
(/ input-value conversion-rate)]))
|
||||
routes-request-uuid (when suggested-routes
|
||||
(:uuid suggested-routes))
|
||||
no-routes-found? (and
|
||||
routes-request-uuid
|
||||
(empty? route)
|
||||
(not loading-routes?))
|
||||
input-error (controlled-input/input-error input-state)
|
||||
limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
|
||||
not-enough-asset? (insufficient-asset-amount?
|
||||
{:enough-assets? enough-assets?
|
||||
:token-symbol token-symbol
|
||||
:owned-eth-token owned-eth-token
|
||||
:input-state input-state
|
||||
:no-routes-found? no-routes-found?
|
||||
:limit-exceeded? limit-exceeded?})
|
||||
should-try-again? (and (not limit-exceeded?)
|
||||
no-routes-found?
|
||||
(not not-enough-asset?))
|
||||
show-no-routes? (and (or no-routes-found? limit-exceeded?)
|
||||
(not not-enough-asset?))
|
||||
confirm-disabled? (or (nil? route)
|
||||
(empty? route)
|
||||
(not valid-input?))
|
||||
fee-formatted (when (or (not confirm-disabled?) not-enough-asset?)
|
||||
(get-fee-formatted route))
|
||||
handle-on-confirm (fn [amount]
|
||||
(rf/dispatch [:wallet/set-token-amount-to-send
|
||||
{:amount amount
|
||||
:stack-id current-screen-id}]))
|
||||
on-confirm (or default-on-confirm handle-on-confirm)
|
||||
show-select-asset-sheet #(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content (fn []
|
||||
[select-asset-bottom-sheet
|
||||
clear-input!])}])
|
||||
request-fetch-routes (fn [bounce-duration-ms]
|
||||
(fetch-routes
|
||||
{:amount amount-in-crypto
|
||||
:valid-input? valid-input?
|
||||
:bounce-duration-ms bounce-duration-ms
|
||||
:token token
|
||||
:reset-amounts-to-zero? (and limit-exceeded?
|
||||
(some? route))}))
|
||||
swap-between-fiat-and-crypto (fn []
|
||||
(if crypto-currency?
|
||||
(set-input-state
|
||||
#(controlled-input/->fiat % conversion-rate))
|
||||
(set-input-state
|
||||
#(controlled-input/->crypto % conversion-rate)))
|
||||
(set-crypto-currency (not crypto-currency?)))]
|
||||
(rn/use-effect
|
||||
(fn []
|
||||
(when active-screen?
|
||||
@@ -287,8 +225,9 @@
|
||||
[current-address])
|
||||
(rn/use-effect
|
||||
(fn []
|
||||
(request-fetch-routes 0))
|
||||
[send-from-locked-amounts])
|
||||
(when active-screen?
|
||||
(request-fetch-routes 2000)))
|
||||
[amount-in-crypto valid-input?])
|
||||
[rn/view
|
||||
{:style style/screen
|
||||
:accessibility-label (str "container"
|
||||
@@ -316,7 +255,7 @@
|
||||
conversion-rate)
|
||||
conversion-rate))
|
||||
:hint-component [quo/network-tags
|
||||
{:networks (seq from-enabled-networks)
|
||||
{:networks (seq [network])
|
||||
:title (i18n/label
|
||||
:t/send-limit
|
||||
{:limit (if crypto-currency?
|
||||
@@ -328,17 +267,9 @@
|
||||
(controlled-input/upper-limit-bn
|
||||
input-state)))})
|
||||
:status (when (controlled-input/input-error input-state) :error)}]}]
|
||||
[routes/view
|
||||
{:token token-by-symbol
|
||||
:input-value input-value
|
||||
:valid-input? valid-input?
|
||||
:token-not-supported-in-receiver-networks? unsupported-token-in-receiver?
|
||||
:current-screen-id current-screen-id
|
||||
:request-fetch-routes request-fetch-routes}]
|
||||
(when (and (not loading-routes?)
|
||||
sender-network-values
|
||||
unsupported-token-in-receiver?)
|
||||
[token-not-available token-symbol receiver-networks token-networks])
|
||||
(if (= tx-type :tx/bridge)
|
||||
[routes/view {:token token-by-symbol}]
|
||||
[rn/view {:style {:flex 1}}])
|
||||
(when not-enough-asset?
|
||||
[not-enough-asset])
|
||||
(when (or (and (not no-routes-found?) (or loading-routes? route))
|
||||
@@ -359,14 +290,10 @@
|
||||
loading-routes?
|
||||
(and (not should-try-again?)
|
||||
confirm-disabled?))
|
||||
:on-press (cond
|
||||
should-try-again?
|
||||
:on-press (if should-try-again?
|
||||
#(rf/dispatch [:wallet/start-get-suggested-routes
|
||||
{:amount amount-in-crypto
|
||||
:updated-token token-by-symbol}])
|
||||
sending-to-unpreferred-networks?
|
||||
#(show-unpreferred-networks-alert on-confirm)
|
||||
:else
|
||||
#(on-confirm amount-in-crypto))
|
||||
:customization-color current-color}
|
||||
(when should-try-again?
|
||||
|
||||
@@ -34,19 +34,3 @@
|
||||
:top margin-top}
|
||||
inverted?
|
||||
(assoc :transform [{:scaleY -1}])))
|
||||
|
||||
(def disclaimer
|
||||
{:margin-horizontal 20
|
||||
:margin-top 20
|
||||
:margin-bottom 8})
|
||||
|
||||
(def input-container
|
||||
{:margin-top 8
|
||||
:margin-bottom 12})
|
||||
|
||||
(defn keyboard-container
|
||||
[bottom]
|
||||
{:padding-bottom bottom})
|
||||
|
||||
(def error-box
|
||||
{:margin-horizontal 20})
|
||||
|
||||
@@ -1,87 +1,23 @@
|
||||
(ns status-im.contexts.wallet.send.routes.view
|
||||
(:require
|
||||
[quo.core :as quo]
|
||||
[quo.theme]
|
||||
[react-native.core :as rn]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contexts.wallet.common.utils :as common-utils]
|
||||
[status-im.contexts.wallet.common.utils.networks :as network-utils]
|
||||
[status-im.contexts.wallet.send.routes.style :as style]
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||
[status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
|
||||
(def row-height 44)
|
||||
(def space-between-rows 11)
|
||||
(def network-link-linear-height 10)
|
||||
(def network-link-1x-height 56)
|
||||
(def network-link-2x-height 111)
|
||||
|
||||
|
||||
(defn- open-preferences
|
||||
[]
|
||||
(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content
|
||||
(fn []
|
||||
(let [receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
|
||||
receiver-preferred-networks (rf/sub
|
||||
[:wallet/wallet-send-receiver-preferred-networks])
|
||||
{token-symbol :symbol
|
||||
token-networks :supported-networks} (rf/sub [:wallet/wallet-send-token])
|
||||
token-chain-ids-set (set (mapv #(:chain-id %) token-networks))
|
||||
[selected-receiver-networks
|
||||
set-selected-receiver-networks] (rn/use-state receiver-networks)
|
||||
receiver-preferred-networks-set (set receiver-preferred-networks)
|
||||
receiver-selected-preferred-networks (filter #(contains?
|
||||
receiver-preferred-networks-set
|
||||
%)
|
||||
selected-receiver-networks)
|
||||
receiver-selected-non-preferred-networks (filter #(not (contains?
|
||||
receiver-preferred-networks-set
|
||||
%))
|
||||
selected-receiver-networks)
|
||||
not-available-preferred-networks (filter (fn [preferred-chain-id]
|
||||
(not (contains? token-chain-ids-set
|
||||
preferred-chain-id)))
|
||||
receiver-selected-preferred-networks)
|
||||
not-available-non-preferred-networks (filter (fn [preferred-chain-id]
|
||||
(not (contains?
|
||||
token-chain-ids-set
|
||||
preferred-chain-id)))
|
||||
receiver-selected-non-preferred-networks)
|
||||
first-section-warning-label (when (not-empty not-available-preferred-networks)
|
||||
(i18n/label
|
||||
:t/token-not-available-on-networks
|
||||
{:token-symbol token-symbol
|
||||
:networks
|
||||
(network-utils/network-ids->formatted-text
|
||||
not-available-preferred-networks)}))
|
||||
second-section-warning-label (when (not-empty
|
||||
not-available-non-preferred-networks)
|
||||
(i18n/label
|
||||
:t/token-not-available-on-networks
|
||||
{:token-symbol token-symbol
|
||||
:networks
|
||||
(network-utils/network-ids->formatted-text
|
||||
not-available-non-preferred-networks)}))]
|
||||
[network-preferences/view
|
||||
{:title (i18n/label :t/edit-receiver-networks)
|
||||
:first-section-label (i18n/label :t/preferred-by-receiver)
|
||||
:second-section-label (i18n/label :t/not-preferred-by-receiver)
|
||||
:selected-networks (set (map network-utils/id->network
|
||||
receiver-networks))
|
||||
:receiver-preferred-networks receiver-preferred-networks
|
||||
:button-label (i18n/label :t/apply-changes)
|
||||
:first-section-warning-label first-section-warning-label
|
||||
:second-section-warning-label second-section-warning-label
|
||||
:on-change #(set-selected-receiver-networks %)
|
||||
:on-save (fn [chain-ids]
|
||||
(rf/dispatch [:hide-bottom-sheet])
|
||||
(rf/dispatch [:wallet/update-receiver-networks
|
||||
chain-ids]))}]))}]))
|
||||
|
||||
(defn render-network-values
|
||||
[{:keys [network-values token-symbol on-press on-long-press receiver? loading-routes?
|
||||
[{:keys [network-values token-symbol receiver? loading-routes?
|
||||
token-not-supported-in-receiver-networks?]}]
|
||||
[rn/view
|
||||
(doall
|
||||
@@ -96,27 +32,19 @@
|
||||
(= network-value-type :not-available)
|
||||
:disabled
|
||||
:else network-value-type)
|
||||
amount-formatted (-> (rf/sub [:wallet/send-amount-fixed total-amount])
|
||||
amount-formatted (-> total-amount
|
||||
(common-utils/sanitized-token-amount-to-display
|
||||
constants/min-token-decimals-to-display)
|
||||
(str " " token-symbol))]
|
||||
[rn/view
|
||||
{:key (str (if receiver? "to" "from") "-" chain-id)
|
||||
:style {:margin-top (if (pos? index) 11 7.5)}}
|
||||
[quo/network-bridge
|
||||
{:amount (if (= network-value-type :not-available)
|
||||
(i18n/label :t/not-available)
|
||||
amount-formatted)
|
||||
:network (network-utils/id->network chain-id)
|
||||
:status status
|
||||
:on-press #(when (not loading-routes?)
|
||||
(cond
|
||||
(= network-value-type :edit)
|
||||
(open-preferences)
|
||||
on-press (on-press chain-id total-amount)))
|
||||
:on-long-press #(when (and (not loading-routes?) (not= status :disabled))
|
||||
(cond
|
||||
(= network-value-type :add)
|
||||
(open-preferences)
|
||||
on-long-press (on-long-press chain-id total-amount)))}]]))
|
||||
{:amount (if (= network-value-type :not-available)
|
||||
(i18n/label :t/not-available)
|
||||
amount-formatted)
|
||||
:network (network-utils/id->network chain-id)
|
||||
:status status}]]))
|
||||
network-values))])
|
||||
|
||||
(defn render-network-links
|
||||
@@ -156,59 +84,15 @@
|
||||
:destination destination}]]]))
|
||||
network-links)])
|
||||
|
||||
(defn disable-chain
|
||||
[chain-id disabled-from-chain-ids token-available-networks-for-suggested-routes]
|
||||
(let [disabled-chain-ids
|
||||
(if (contains? (set
|
||||
disabled-from-chain-ids)
|
||||
chain-id)
|
||||
(vec (remove #(= % chain-id)
|
||||
disabled-from-chain-ids))
|
||||
(conj disabled-from-chain-ids
|
||||
chain-id))
|
||||
re-enabling-chain?
|
||||
(< (count disabled-chain-ids)
|
||||
(count disabled-from-chain-ids))]
|
||||
(if (or re-enabling-chain?
|
||||
(> (count token-available-networks-for-suggested-routes) 1))
|
||||
(rf/dispatch [:wallet/disable-from-networks
|
||||
disabled-chain-ids])
|
||||
(rf/dispatch [:toasts/upsert
|
||||
{:id :disable-chain-error
|
||||
:type :negative
|
||||
:text (i18n/label :t/at-least-one-network-must-be-activated)}]))))
|
||||
|
||||
(defn view
|
||||
[{:keys [token theme valid-input? request-fetch-routes on-press-to-network current-screen-id
|
||||
token-not-supported-in-receiver-networks? input-value]}]
|
||||
(let [token-symbol (:symbol token)
|
||||
nav-current-screen-id (rf/sub [:view-id])
|
||||
active-screen? (= nav-current-screen-id current-screen-id)
|
||||
loading-routes? (rf/sub
|
||||
[:wallet/wallet-send-loading-suggested-routes?])
|
||||
sender-network-values (rf/sub
|
||||
[:wallet/wallet-send-sender-network-values])
|
||||
receiver-network-values (rf/sub
|
||||
[:wallet/wallet-send-receiver-network-values])
|
||||
network-links (rf/sub [:wallet/wallet-send-network-links])
|
||||
disabled-from-chain-ids (rf/sub
|
||||
[:wallet/wallet-send-disabled-from-chain-ids])
|
||||
{token-balances-per-chain :balances-per-chain} (rf/sub [:wallet/wallet-send-token])
|
||||
token-available-networks-for-suggested-routes
|
||||
(send-utils/token-available-networks-for-suggested-routes
|
||||
{:balances-per-chain token-balances-per-chain
|
||||
:disabled-chain-ids disabled-from-chain-ids})
|
||||
show-routes? (not-empty sender-network-values)]
|
||||
(rn/use-effect
|
||||
(fn []
|
||||
(when (and active-screen?
|
||||
(> (count token-available-networks-for-suggested-routes) 0))
|
||||
(request-fetch-routes 2000)))
|
||||
[input-value valid-input?])
|
||||
(rn/use-effect
|
||||
#(when (and active-screen? (> (count token-available-networks-for-suggested-routes) 0))
|
||||
(request-fetch-routes 0))
|
||||
[disabled-from-chain-ids])
|
||||
[{:keys [token]}]
|
||||
(let [theme (quo.theme/use-theme)
|
||||
token-symbol (:symbol token)
|
||||
loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
|
||||
sender-network-values (rf/sub [:wallet/wallet-send-sender-network-values])
|
||||
receiver-network-values (rf/sub [:wallet/wallet-send-receiver-network-values])
|
||||
network-links (rf/sub [:wallet/wallet-send-network-links])
|
||||
show-routes? (not-empty sender-network-values)]
|
||||
[rn/scroll-view {:content-container-style style/routes-container}
|
||||
(when show-routes?
|
||||
[rn/view {:style style/routes-header-container}
|
||||
@@ -220,27 +104,18 @@
|
||||
:container-style style/section-label-right}]])
|
||||
[rn/view {:style style/routes-inner-container}
|
||||
[render-network-values
|
||||
{:token-symbol token-symbol
|
||||
:network-values sender-network-values
|
||||
:on-press (fn [chain-id-to-disable]
|
||||
(disable-chain
|
||||
chain-id-to-disable
|
||||
disabled-from-chain-ids
|
||||
token-available-networks-for-suggested-routes))
|
||||
:receiver? false
|
||||
:theme theme
|
||||
:loading-routes? loading-routes?
|
||||
:token-not-supported-in-receiver-networks? false}]
|
||||
{:token-symbol token-symbol
|
||||
:network-values sender-network-values
|
||||
:receiver? false
|
||||
:theme theme
|
||||
:loading-routes? loading-routes?}]
|
||||
[render-network-links
|
||||
{:network-links network-links
|
||||
:sender-network-values sender-network-values}]
|
||||
[render-network-values
|
||||
{:token-symbol token-symbol
|
||||
:network-values receiver-network-values
|
||||
:on-press on-press-to-network
|
||||
:receiver? true
|
||||
:loading-routes? loading-routes?
|
||||
:theme theme
|
||||
:token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks?
|
||||
:on-save #(request-fetch-routes 0)}]]]))
|
||||
{:token-symbol token-symbol
|
||||
:network-values receiver-network-values
|
||||
:receiver? true
|
||||
:loading-routes? loading-routes?
|
||||
:theme theme}]]]))
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
:on-press on-close
|
||||
:switcher-type :select-account}]
|
||||
[quo/page-top
|
||||
{:title (i18n/label :t/select-asset)
|
||||
{:title (i18n/label :t/select-token)
|
||||
:title-accessibility-label :title-label}]
|
||||
[quo/segmented-control
|
||||
{:size 32
|
||||
|
||||
@@ -229,44 +229,17 @@
|
||||
safe-add-type-edit)))
|
||||
|
||||
(defn loading-network-amounts
|
||||
[{:keys [valid-networks disabled-chain-ids receiver-networks token-networks-ids tx-type receiver?]}]
|
||||
(let [disabled-set (set disabled-chain-ids)
|
||||
receiver-networks-set (set receiver-networks)
|
||||
token-networks-ids-set (set token-networks-ids)
|
||||
valid-networks-set (set valid-networks)
|
||||
not-available-networks (if receiver?
|
||||
(filter #(not (token-networks-ids-set %)) receiver-networks)
|
||||
[])
|
||||
not-available-networks-set (set not-available-networks)
|
||||
valid-networks (-> (concat valid-networks
|
||||
(when (not (and receiver? (= tx-type :tx/bridge)))
|
||||
disabled-chain-ids)
|
||||
(when receiver?
|
||||
(filter #(not (valid-networks-set %))
|
||||
not-available-networks)))
|
||||
(distinct))]
|
||||
(->> valid-networks
|
||||
(map
|
||||
(fn [chain-id]
|
||||
(cond->
|
||||
{:chain-id chain-id
|
||||
:type (cond
|
||||
(contains? not-available-networks-set chain-id) :not-available
|
||||
(or receiver?
|
||||
(not (contains? disabled-set chain-id))) :loading
|
||||
(and (not receiver?) (contains? disabled-set chain-id)) :disabled)}
|
||||
(and (not receiver?) (contains? disabled-set chain-id))
|
||||
(assoc :total-amount (money/bignumber "0")))))
|
||||
(filter
|
||||
(fn [network-amount]
|
||||
(or (and receiver?
|
||||
(or (= tx-type :tx/bridge)
|
||||
(contains? receiver-networks-set (:chain-id network-amount))))
|
||||
(not receiver?))))
|
||||
(sort-by (fn [network-amount]
|
||||
(get network-priority-score
|
||||
(network-utils/id->network (:chain-id network-amount)))))
|
||||
(vec))))
|
||||
[{:keys [networks values receiver?]}]
|
||||
(->> networks
|
||||
(map
|
||||
(fn [chain-id]
|
||||
(let [network-value (when values (get values chain-id))]
|
||||
(cond-> {:chain-id chain-id
|
||||
:type (if network-value :default :loading)}
|
||||
network-value (assoc :total-amount
|
||||
(money/bignumber network-value))
|
||||
(and (not network-value) (not receiver?)) (assoc :total-amount (money/bignumber "0"))))))
|
||||
(vec)))
|
||||
|
||||
(defn network-links
|
||||
[route from-values-by-chain to-values-by-chain]
|
||||
|
||||
@@ -8,12 +8,16 @@
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn- network-item
|
||||
[{:keys [network on-select-network]}]
|
||||
[{:keys [network on-select-network source]}]
|
||||
(let [{:keys [network-name
|
||||
chain-id]} network
|
||||
chain-id]} network
|
||||
{balance-in-crypto :crypto
|
||||
balance-in-fiat :fiat} (rf/sub [:wallet/swap-asset-to-pay-network-balance chain-id])
|
||||
mainnet? (= network-name constants/mainnet-network-name)]
|
||||
balance-in-fiat :fiat} (case source
|
||||
:swap
|
||||
(rf/sub [:wallet/swap-asset-to-pay-network-balance chain-id])
|
||||
(rf/sub [:wallet/send-token-network-balance chain-id]))
|
||||
mainnet?
|
||||
(= network-name constants/mainnet-network-name)]
|
||||
[quo/network-list
|
||||
{:label (name network-name)
|
||||
:network-image (quo.resources/get-network network-name)
|
||||
@@ -23,21 +27,28 @@
|
||||
:container-style (style/network-list-container mainnet?)}]))
|
||||
|
||||
(defn view
|
||||
[{:keys [on-select-network]}]
|
||||
(let [token-symbol (rf/sub [:wallet/swap-asset-to-pay-token-symbol])
|
||||
{mainnet-network :mainnet-network
|
||||
layer-2-networks :layer-2-networks} (rf/sub [:wallet/swap-asset-to-pay-networks])
|
||||
[{:keys [token-symbol on-select-network source title]
|
||||
:or {source :swap
|
||||
title (i18n/label :t/select-network)}}]
|
||||
(let [{mainnet-network :mainnet-network
|
||||
layer-2-networks :layer-2-networks} (case source
|
||||
:swap
|
||||
(rf/sub [:wallet/swap-asset-to-pay-networks])
|
||||
:send
|
||||
(rf/sub [:wallet/send-token-grouped-networks])
|
||||
:bridge
|
||||
(rf/sub [:wallet/send-token-grouped-networks]))
|
||||
render-fn (rn/use-callback (fn [network]
|
||||
[network-item
|
||||
{:network network
|
||||
:on-select-network
|
||||
on-select-network}]))]
|
||||
{:network network
|
||||
:on-select-network on-select-network
|
||||
:source source}]))]
|
||||
[:<>
|
||||
[rn/view {:style style/header-container}
|
||||
[quo/text
|
||||
{:size :heading-2
|
||||
:weight :semi-bold}
|
||||
(i18n/label :t/select-network)]
|
||||
title]
|
||||
[quo/context-tag
|
||||
{:type :token
|
||||
:size 24
|
||||
@@ -46,7 +57,8 @@
|
||||
(when mainnet-network
|
||||
[network-item
|
||||
{:network mainnet-network
|
||||
:on-select-network on-select-network}])
|
||||
:on-select-network on-select-network
|
||||
:source source}])
|
||||
[quo/divider-label {:container-style style/divider-label}
|
||||
(i18n/label :t/layer-2)]
|
||||
[rn/flat-list
|
||||
|
||||
@@ -34,7 +34,8 @@
|
||||
|
||||
(defn view
|
||||
[]
|
||||
(let [accounts (rf/sub [:wallet/accounts-with-balances])]
|
||||
(let [asset-to-pay (rf/sub [:wallet/swap-asset-to-pay])
|
||||
accounts (rf/sub [:wallet/accounts-with-balances asset-to-pay])]
|
||||
[floating-button-page/view
|
||||
{:footer-container-padding 0
|
||||
:header [quo/page-nav
|
||||
|
||||
@@ -56,12 +56,12 @@
|
||||
(re-frame/reg-sub
|
||||
:wallet/network-values
|
||||
:<- [:wallet/wallet-send]
|
||||
:<- [:wallet/send-display-token-decimals]
|
||||
(fn [[{:keys [from-values-by-chain to-values-by-chain token-display-name] :as send-data} token-decimals]
|
||||
(fn [{:keys [from-values-by-chain to-values-by-chain token-display-name token] :as send-data}
|
||||
[_ to-values?]]
|
||||
(let [network-values (if to-values? to-values-by-chain from-values-by-chain)
|
||||
token-symbol (or token-display-name
|
||||
(-> send-data :token :symbol))]
|
||||
(-> send-data :token :symbol))
|
||||
token-decimals (:decimals token)]
|
||||
(reduce-kv
|
||||
(fn [acc chain-id amount]
|
||||
(let [network-name (network-utils/id->network chain-id)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
(:require
|
||||
[re-frame.core :as rf]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contexts.wallet.common.activity-tab.constants :as activity-constants]
|
||||
[status-im.contexts.wallet.common.activity-tab.constants :as activity-tab-constants]
|
||||
[status-im.contexts.wallet.common.utils :as common-utils]
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||
[utils.money :as money]
|
||||
@@ -34,6 +34,11 @@
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :token)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/send-token-symbol
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :token-symbol)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/send-transaction-ids
|
||||
:<- [:wallet/wallet-send]
|
||||
@@ -54,6 +59,11 @@
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :tx-type)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/send-network
|
||||
:<- [:wallet/wallet-send]
|
||||
:-> :network)
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/sending-collectible?
|
||||
:<- [:wallet/send-tx-type]
|
||||
@@ -77,7 +87,7 @@
|
||||
(->> address-activity
|
||||
(sort :timestamp)
|
||||
(keep (fn [{:keys [activity-type recipient]}]
|
||||
(when (= activity-constants/wallet-activity-type-send activity-type)
|
||||
(when (= activity-tab-constants/wallet-activity-type-send activity-type)
|
||||
recipient)))
|
||||
(distinct)))))
|
||||
|
||||
@@ -173,3 +183,39 @@
|
||||
(= (:chain-id network) bridge-to-chain-id)
|
||||
network))
|
||||
networks))))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/send-token-grouped-networks
|
||||
:<- [:wallet/wallet-send-token]
|
||||
(fn [token]
|
||||
(let [{token-networks :networks} token
|
||||
grouped-networks (group-by :layer
|
||||
token-networks)
|
||||
mainnet-network (first (get grouped-networks constants/layer-1-network))
|
||||
layer-2-networks (get grouped-networks constants/layer-2-network)]
|
||||
{:mainnet-network mainnet-network
|
||||
:layer-2-networks layer-2-networks})))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/send-token-network-balance
|
||||
:<- [:wallet/wallet-send-token]
|
||||
:<- [:profile/currency]
|
||||
:<- [:profile/currency-symbol]
|
||||
:<- [:wallet/prices-per-token]
|
||||
(fn [[token currency currency-symbol prices-per-token] [_ chain-id]]
|
||||
(let [{:keys [balances-per-chain
|
||||
decimals]} token
|
||||
balance-for-chain (get balances-per-chain chain-id)
|
||||
total-balance (money/token->unit (:raw-balance balance-for-chain) decimals)
|
||||
fiat-value (common-utils/calculate-token-fiat-value
|
||||
{:currency currency
|
||||
:balance total-balance
|
||||
:token token
|
||||
:prices-per-token prices-per-token})
|
||||
crypto-formatted (common-utils/get-standard-crypto-format token
|
||||
total-balance
|
||||
prices-per-token)
|
||||
fiat-formatted (common-utils/fiat-formatted-for-ui currency-symbol
|
||||
fiat-value)]
|
||||
{:crypto (str crypto-formatted " " (:symbol token))
|
||||
:fiat fiat-formatted})))
|
||||
|
||||
@@ -334,24 +334,3 @@
|
||||
:token token-for-fees
|
||||
:prices-per-token prices-per-token})]
|
||||
fee-in-fiat)))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/accounts-with-balances
|
||||
:<- [:wallet/operable-accounts]
|
||||
:<- [:wallet/swap-asset-to-pay]
|
||||
(fn [[accounts asset-to-pay]]
|
||||
(let [token-symbol (:symbol asset-to-pay)]
|
||||
(map
|
||||
(fn [account]
|
||||
(let [tokens (:tokens account)
|
||||
filtered-tokens (filter #(= (:symbol %) token-symbol) tokens)
|
||||
asset-pay-balance (utils/calculate-total-token-balance filtered-tokens)
|
||||
formatted-address (network-utils/format-address (:address account)
|
||||
(:network-preferences-names account))]
|
||||
(assoc account
|
||||
:formatted-address formatted-address
|
||||
:asset-pay-balance (utils/sanitized-token-amount-to-display
|
||||
asset-pay-balance
|
||||
constants/min-token-decimals-to-display)
|
||||
:asset-pay-symbol token-symbol)))
|
||||
accounts))))
|
||||
|
||||
@@ -901,3 +901,23 @@
|
||||
:<- [:wallet/accounts-without-current-viewing-account]
|
||||
(fn [accounts]
|
||||
(get-emoji-and-colors-from-accounts accounts)))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/accounts-with-balances
|
||||
:<- [:wallet/operable-accounts]
|
||||
(fn [accounts [_ token]]
|
||||
(let [token-symbol (:symbol token)]
|
||||
(map
|
||||
(fn [account]
|
||||
(let [tokens (:tokens account)
|
||||
filtered-tokens (filter #(= (:symbol %) token-symbol) tokens)
|
||||
asset-pay-balance (utils/calculate-total-token-balance filtered-tokens)
|
||||
formatted-address (network-utils/format-address (:address account)
|
||||
(:network-preferences-names account))]
|
||||
(assoc account
|
||||
:formatted-address formatted-address
|
||||
:asset-pay-balance (utils/sanitized-token-amount-to-display
|
||||
asset-pay-balance
|
||||
constants/min-token-decimals-to-display)
|
||||
:asset-pay-symbol token-symbol)))
|
||||
accounts))))
|
||||
|
||||
@@ -799,7 +799,6 @@
|
||||
"do-not-cheat": "Don't try to cheat",
|
||||
"do-not-cheat-description": "These 12 words give access to all of your funds so it is important that you write them in the correct order, take it seriously.",
|
||||
"do-not-quit": "Do not quit the application or turn off your device. Doing so will lead to data corruption, loss of your Status profile and the inability to use Status.",
|
||||
|
||||
"do-not-share": "Do not share",
|
||||
"done": "Done",
|
||||
"dont-ask": "Don't ask me again",
|
||||
@@ -1215,7 +1214,10 @@
|
||||
"include": "Include",
|
||||
"incoming": "Incoming",
|
||||
"incoming-transaction": "Incoming transaction",
|
||||
"incorrect-code": ["str", "Sorry the code was incorrect, please enter it again"],
|
||||
"incorrect-code": [
|
||||
"str",
|
||||
"Sorry the code was incorrect, please enter it again"
|
||||
],
|
||||
"incorrect-private-key": "This is not the private key for this key pair",
|
||||
"increase-gas": "Increase Gas",
|
||||
"information-you-input-and-send": "Information you input and send",
|
||||
@@ -2280,8 +2282,11 @@
|
||||
"select-chat": "Select chat to start messaging",
|
||||
"select-network": "Select network",
|
||||
"select-network-for-buying": "Select network for buying",
|
||||
"select-network-to-bridge-from": "Select network to bridge from",
|
||||
"select-network-to-receive": "Select network to receive",
|
||||
"select-networks": "Select networks",
|
||||
"select-new-location-for-keys": "Select a new location to save your private key(s)",
|
||||
"select-token": "Select token",
|
||||
"select-token-to-receive": "Select token to receive",
|
||||
"select-token-to-swap": "Select token to Swap",
|
||||
"selected": "Selected",
|
||||
|
||||
Reference in New Issue
Block a user