fix(wallet): some router ui adjustments (#20209)
Signed-off-by: Brian Sztamfater <brian@status.im>
This commit is contained in:
parent
039ad8d162
commit
24194fb34e
|
@ -1,7 +1,7 @@
|
||||||
(ns quo.components.wallet.network-bridge.schema)
|
(ns quo.components.wallet.network-bridge.schema)
|
||||||
|
|
||||||
(def ^:private ?network-bridge-status
|
(def ^:private ?network-bridge-status
|
||||||
[:enum :add :loading :locked :disabled :default])
|
[:enum :edit :loading :locked :disabled :default])
|
||||||
|
|
||||||
(def ?schema
|
(def ?schema
|
||||||
[:=>
|
[:=>
|
||||||
|
|
|
@ -18,7 +18,11 @@
|
||||||
(style/add-container theme)
|
(style/add-container theme)
|
||||||
container-style)
|
container-style)
|
||||||
:on-press on-press}
|
:on-press on-press}
|
||||||
[icon/icon :i/add-circle {:size 12 :no-color true}]])
|
[icon/icon :i/edit
|
||||||
|
{:size 12
|
||||||
|
:color (colors/theme-colors colors/neutral-50
|
||||||
|
colors/neutral-60
|
||||||
|
theme)}]])
|
||||||
|
|
||||||
(defn- network->text
|
(defn- network->text
|
||||||
[network]
|
[network]
|
||||||
|
@ -29,7 +33,7 @@
|
||||||
(defn view-internal
|
(defn view-internal
|
||||||
[{:keys [network status amount container-style on-press] :as args}]
|
[{:keys [network status amount container-style on-press] :as args}]
|
||||||
(let [theme (quo.theme/use-theme)]
|
(let [theme (quo.theme/use-theme)]
|
||||||
(if (= status :add)
|
(if (= status :edit)
|
||||||
[network-bridge-add (assoc args :theme theme)]
|
[network-bridge-add (assoc args :theme theme)]
|
||||||
[rn/pressable
|
[rn/pressable
|
||||||
{:style (merge (style/container network status theme) container-style)
|
{:style (merge (style/container network status theme) container-style)
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
{:key :locked :value :locked}
|
{:key :locked :value :locked}
|
||||||
{:key :loading :value :loading}
|
{:key :loading :value :loading}
|
||||||
{:key :disabled :value :disabled}
|
{:key :disabled :value :disabled}
|
||||||
{:key :add :value :add}]}])
|
{:key :edit :value :edit}]}])
|
||||||
|
|
||||||
(defn view
|
(defn view
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -111,7 +111,7 @@
|
||||||
:else type)
|
:else type)
|
||||||
:on-press #(when (not loading-routes?)
|
:on-press #(when (not loading-routes?)
|
||||||
(cond
|
(cond
|
||||||
(= type :add)
|
(= type :edit)
|
||||||
(open-preferences)
|
(open-preferences)
|
||||||
on-press (on-press chain-id total-amount)))}]])
|
on-press (on-press chain-id total-amount)))}]])
|
||||||
network-values)])
|
network-values)])
|
||||||
|
|
|
@ -93,8 +93,6 @@
|
||||||
:optimism 2
|
:optimism 2
|
||||||
:arbitrum 3})
|
:arbitrum 3})
|
||||||
|
|
||||||
(def ^:private available-networks-count
|
|
||||||
(count (set (keys network-priority-score))))
|
|
||||||
|
|
||||||
(defn reset-loading-network-amounts-to-zero
|
(defn reset-loading-network-amounts-to-zero
|
||||||
[network-amounts]
|
[network-amounts]
|
||||||
|
@ -114,7 +112,7 @@
|
||||||
disabled? (contains? disabled-chain-ids-set
|
disabled? (contains? disabled-chain-ids-set
|
||||||
(:chain-id network-amount))]
|
(:chain-id network-amount))]
|
||||||
(cond-> network-amount
|
(cond-> network-amount
|
||||||
(and (not= (:type network-amount) :add)
|
(and (not= (:type network-amount) :edit)
|
||||||
(not= (:type network-amount) :not-available))
|
(not= (:type network-amount) :not-available))
|
||||||
(assoc :total-amount (money/bignumber "0")
|
(assoc :total-amount (money/bignumber "0")
|
||||||
:type (if disabled? :disabled :default)))))
|
:type (if disabled? :disabled :default)))))
|
||||||
|
@ -136,9 +134,7 @@
|
||||||
(reduce
|
(reduce
|
||||||
(fn [acc k]
|
(fn [acc k]
|
||||||
(if (or (contains? network-values-keys k)
|
(if (or (contains? network-values-keys k)
|
||||||
(and receiver?
|
receiver?)
|
||||||
(not (contains? receiver-networks-set
|
|
||||||
k))))
|
|
||||||
acc
|
acc
|
||||||
(assoc acc k (money/bignumber "0"))))
|
(assoc acc k (money/bignumber "0"))))
|
||||||
network-values
|
network-values
|
||||||
|
@ -177,15 +173,13 @@
|
||||||
(vec))
|
(vec))
|
||||||
(and receiver?
|
(and receiver?
|
||||||
routes-found?
|
routes-found?
|
||||||
(< (count network-values-with-not-available-chains) available-networks-count)
|
|
||||||
(not= tx-type :tx/bridge))
|
(not= tx-type :tx/bridge))
|
||||||
(conj {:type :add}))))
|
(conj {:type :edit}))))
|
||||||
|
|
||||||
(defn loading-network-amounts
|
(defn loading-network-amounts
|
||||||
[{:keys [valid-networks disabled-chain-ids receiver-networks token-networks-ids tx-type receiver?]}]
|
[{:keys [valid-networks disabled-chain-ids receiver-networks token-networks-ids tx-type receiver?]}]
|
||||||
(let [disabled-set (set disabled-chain-ids)
|
(let [disabled-set (set disabled-chain-ids)
|
||||||
receiver-networks-set (set receiver-networks)
|
receiver-networks-set (set receiver-networks)
|
||||||
receiver-networks-count (count receiver-networks)
|
|
||||||
token-networks-ids-set (set token-networks-ids)
|
token-networks-ids-set (set token-networks-ids)
|
||||||
valid-networks-set (set valid-networks)
|
valid-networks-set (set valid-networks)
|
||||||
not-available-networks (if receiver?
|
not-available-networks (if receiver?
|
||||||
|
@ -199,7 +193,7 @@
|
||||||
(filter #(not (valid-networks-set %))
|
(filter #(not (valid-networks-set %))
|
||||||
not-available-networks)))
|
not-available-networks)))
|
||||||
(distinct))]
|
(distinct))]
|
||||||
(cond-> (->> valid-networks
|
(->> valid-networks
|
||||||
(map
|
(map
|
||||||
(fn [chain-id]
|
(fn [chain-id]
|
||||||
(cond->
|
(cond->
|
||||||
|
@ -220,9 +214,7 @@
|
||||||
(sort-by (fn [network-amount]
|
(sort-by (fn [network-amount]
|
||||||
(get network-priority-score
|
(get network-priority-score
|
||||||
(network-utils/id->network (:chain-id network-amount)))))
|
(network-utils/id->network (:chain-id network-amount)))))
|
||||||
(vec))
|
(vec))))
|
||||||
(and receiver? (< receiver-networks-count available-networks-count) (not= tx-type :tx/bridge))
|
|
||||||
(conj {:type :add}))))
|
|
||||||
|
|
||||||
(defn network-links
|
(defn network-links
|
||||||
[route from-values-by-chain to-values-by-chain]
|
[route from-values-by-chain to-values-by-chain]
|
||||||
|
|
|
@ -269,20 +269,16 @@
|
||||||
|
|
||||||
(deftest test-network-amounts
|
(deftest test-network-amounts
|
||||||
(testing "Handles disabled and receiver networks correctly when receiver? is true"
|
(testing "Handles disabled and receiver networks correctly when receiver? is true"
|
||||||
(let [network-values {1 (money/bignumber "100")
|
(let [network-values {10 (money/bignumber "200")}
|
||||||
10 (money/bignumber "200")}
|
|
||||||
disabled-chain-ids [1]
|
disabled-chain-ids [1]
|
||||||
receiver-networks [10]
|
receiver-networks [10]
|
||||||
token-networks-ids [1 10 42161]
|
token-networks-ids [1 10 42161]
|
||||||
receiver? true
|
receiver? true
|
||||||
expected [{:chain-id 1
|
expected [{:chain-id 10
|
||||||
:total-amount (money/bignumber "100")
|
|
||||||
:type :default}
|
|
||||||
{:chain-id 10
|
|
||||||
:total-amount (money/bignumber "200")
|
:total-amount (money/bignumber "200")
|
||||||
:type :default}
|
:type :default}
|
||||||
{:type :add}]
|
{:type :edit}]
|
||||||
tx-type :send
|
tx-type :tx/send
|
||||||
result (utils/network-amounts {:network-values network-values
|
result (utils/network-amounts {:network-values network-values
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -303,7 +299,7 @@
|
||||||
{:chain-id 10
|
{:chain-id 10
|
||||||
:total-amount (money/bignumber "0")
|
:total-amount (money/bignumber "0")
|
||||||
:type :disabled}]
|
:type :disabled}]
|
||||||
tx-type :send
|
tx-type :tx/send
|
||||||
result (utils/network-amounts {:network-values network-values
|
result (utils/network-amounts {:network-values network-values
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -319,7 +315,7 @@
|
||||||
token-networks-ids []
|
token-networks-ids []
|
||||||
receiver? true
|
receiver? true
|
||||||
expected []
|
expected []
|
||||||
tx-type :send
|
tx-type :tx/send
|
||||||
result (utils/network-amounts {:network-values network-values
|
result (utils/network-amounts {:network-values network-values
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -344,8 +340,9 @@
|
||||||
:type :default}
|
:type :default}
|
||||||
{:chain-id 42161
|
{:chain-id 42161
|
||||||
:total-amount (money/bignumber "500")
|
:total-amount (money/bignumber "500")
|
||||||
:type :default}]
|
:type :default}
|
||||||
tx-type :send
|
{:type :edit}]
|
||||||
|
tx-type :tx/send
|
||||||
result (utils/network-amounts {:network-values network-values
|
result (utils/network-amounts {:network-values network-values
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -366,7 +363,7 @@
|
||||||
{:chain-id 10
|
{:chain-id 10
|
||||||
:total-amount (money/bignumber "0")
|
:total-amount (money/bignumber "0")
|
||||||
:type :disabled}]
|
:type :disabled}]
|
||||||
tx-type :send
|
tx-type :tx/send
|
||||||
result (utils/network-amounts {:network-values network-values
|
result (utils/network-amounts {:network-values network-values
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -388,7 +385,7 @@
|
||||||
{:chain-id 10
|
{:chain-id 10
|
||||||
:total-amount nil
|
:total-amount nil
|
||||||
:type :not-available}]
|
:type :not-available}]
|
||||||
tx-type :send
|
tx-type :tx/send
|
||||||
result (utils/network-amounts {:network-values network-values
|
result (utils/network-amounts {:network-values network-values
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -397,7 +394,8 @@
|
||||||
:receiver? receiver?})]
|
:receiver? receiver?})]
|
||||||
(is (every? identity (map #(map/deep-compare %1 %2) expected result)))))
|
(is (every? identity (map #(map/deep-compare %1 %2) expected result)))))
|
||||||
|
|
||||||
(testing "Handles disabled and receiver networks correctly when to? is false and tx-type is :tx/bridge"
|
(testing
|
||||||
|
"Handles disabled and receiver networks correctly when receiver? is false and tx-type is :tx/bridge"
|
||||||
(let [network-values {10 (money/bignumber "200")}
|
(let [network-values {10 (money/bignumber "200")}
|
||||||
disabled-chain-ids [1]
|
disabled-chain-ids [1]
|
||||||
receiver-networks [10]
|
receiver-networks [10]
|
||||||
|
@ -418,7 +416,8 @@
|
||||||
:receiver? receiver?})]
|
:receiver? receiver?})]
|
||||||
(is (every? identity (map #(map/deep-compare %1 %2) expected result)))))
|
(is (every? identity (map #(map/deep-compare %1 %2) expected result)))))
|
||||||
|
|
||||||
(testing "Handles disabled and receiver networks correctly when to? is true and tx-type is :tx/bridge"
|
(testing
|
||||||
|
"Handles disabled and receiver networks correctly when receiver? is true and tx-type is :tx/bridge"
|
||||||
(let [network-values {10 (money/bignumber "200")}
|
(let [network-values {10 (money/bignumber "200")}
|
||||||
disabled-chain-ids [1]
|
disabled-chain-ids [1]
|
||||||
receiver-networks [10]
|
receiver-networks [10]
|
||||||
|
@ -444,9 +443,8 @@
|
||||||
token-networks-ids [1 10 42161]
|
token-networks-ids [1 10 42161]
|
||||||
receiver? true
|
receiver? true
|
||||||
expected [{:chain-id 1 :type :loading}
|
expected [{:chain-id 1 :type :loading}
|
||||||
{:chain-id 10 :type :loading}
|
{:chain-id 10 :type :loading}]
|
||||||
{:type :add}]
|
tx-type :tx/send
|
||||||
tx-type :send
|
|
||||||
result (utils/loading-network-amounts {:valid-networks valid-networks
|
result (utils/loading-network-amounts {:valid-networks valid-networks
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -467,7 +465,7 @@
|
||||||
expected [{:chain-id 1 :type :loading}
|
expected [{:chain-id 1 :type :loading}
|
||||||
{:chain-id 10 :type :disabled :total-amount (money/bignumber "0")}
|
{:chain-id 10 :type :disabled :total-amount (money/bignumber "0")}
|
||||||
{:chain-id 42161 :type :disabled :total-amount (money/bignumber "0")}]
|
{:chain-id 42161 :type :disabled :total-amount (money/bignumber "0")}]
|
||||||
tx-type :send
|
tx-type :tx/send
|
||||||
result (utils/loading-network-amounts {:valid-networks valid-networks
|
result (utils/loading-network-amounts {:valid-networks valid-networks
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -487,7 +485,7 @@
|
||||||
receiver? true
|
receiver? true
|
||||||
expected [{:chain-id 1 :type :loading}
|
expected [{:chain-id 1 :type :loading}
|
||||||
{:chain-id 42161 :type :loading}]
|
{:chain-id 42161 :type :loading}]
|
||||||
tx-type :send
|
tx-type :tx/send
|
||||||
result (utils/loading-network-amounts {:valid-networks valid-networks
|
result (utils/loading-network-amounts {:valid-networks valid-networks
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -500,15 +498,14 @@
|
||||||
(is (every? identity comparisons))))
|
(is (every? identity comparisons))))
|
||||||
|
|
||||||
(testing
|
(testing
|
||||||
"Appends :add type if receiver network count is less than available networks and receiver? is true"
|
"Appends :edit type if receiver network count is less than available networks and receiver? is true"
|
||||||
(let [valid-networks [1 10 42161]
|
(let [valid-networks [1 10 42161]
|
||||||
disabled-chain-ids [10]
|
disabled-chain-ids [10]
|
||||||
receiver-networks [1]
|
receiver-networks [1]
|
||||||
token-networks-ids [1 10 42161]
|
token-networks-ids [1 10 42161]
|
||||||
receiver? true
|
receiver? true
|
||||||
expected [{:chain-id 1 :type :loading}
|
expected [{:chain-id 1 :type :loading}]
|
||||||
{:type :add}]
|
tx-type :tx/send
|
||||||
tx-type :send
|
|
||||||
result (utils/loading-network-amounts {:valid-networks valid-networks
|
result (utils/loading-network-amounts {:valid-networks valid-networks
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -528,7 +525,7 @@
|
||||||
token-networks-ids [42161]
|
token-networks-ids [42161]
|
||||||
receiver? false
|
receiver? false
|
||||||
expected [{:chain-id 42161 :type :loading}]
|
expected [{:chain-id 42161 :type :loading}]
|
||||||
tx-type :send
|
tx-type :tx/send
|
||||||
result (utils/loading-network-amounts {:valid-networks valid-networks
|
result (utils/loading-network-amounts {:valid-networks valid-networks
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -547,9 +544,8 @@
|
||||||
receiver-networks [1]
|
receiver-networks [1]
|
||||||
token-networks-ids [42161]
|
token-networks-ids [42161]
|
||||||
receiver? true
|
receiver? true
|
||||||
expected [{:chain-id 1 :type :not-available}
|
expected [{:chain-id 1 :type :not-available}]
|
||||||
{:type :add}]
|
tx-type :tx/send
|
||||||
tx-type :send
|
|
||||||
result (utils/loading-network-amounts {:valid-networks valid-networks
|
result (utils/loading-network-amounts {:valid-networks valid-networks
|
||||||
:disabled-chain-ids disabled-chain-ids
|
:disabled-chain-ids disabled-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
|
@ -562,7 +558,7 @@
|
||||||
(is (every? identity comparisons))))
|
(is (every? identity comparisons))))
|
||||||
|
|
||||||
(testing
|
(testing
|
||||||
"Assigns :loading type to valid networks and :disabled for disabled ones when tx-type is :tx/bridge and to? false"
|
"Assigns :loading type to valid networks and :disabled for disabled ones when tx-type is :tx/bridge and receiver? false"
|
||||||
(let [valid-networks [1 10]
|
(let [valid-networks [1 10]
|
||||||
disabled-chain-ids [10]
|
disabled-chain-ids [10]
|
||||||
receiver-networks []
|
receiver-networks []
|
||||||
|
@ -583,7 +579,7 @@
|
||||||
(is (every? identity comparisons))))
|
(is (every? identity comparisons))))
|
||||||
|
|
||||||
(testing
|
(testing
|
||||||
"Assigns :loading type to valid networks, ignore disabled ones and do not add {:type :add} when tx-type is :tx/bridge and to? true"
|
"Assigns :loading type to valid networks, ignore disabled ones and do not add {:type :edit} when tx-type is :tx/bridge and receiver? true"
|
||||||
(let [valid-networks [1]
|
(let [valid-networks [1]
|
||||||
disabled-chain-ids [10]
|
disabled-chain-ids [10]
|
||||||
receiver-networks []
|
receiver-networks []
|
||||||
|
|
Loading…
Reference in New Issue