fix(wallet): some router ui adjustments (#20209)

Signed-off-by: Brian Sztamfater <brian@status.im>
This commit is contained in:
Brian Sztamfater 2024-05-31 10:03:53 -03:00 committed by GitHub
parent 039ad8d162
commit 24194fb34e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 61 additions and 69 deletions

View File

@ -1,7 +1,7 @@
(ns quo.components.wallet.network-bridge.schema)
(def ^:private ?network-bridge-status
[:enum :add :loading :locked :disabled :default])
[:enum :edit :loading :locked :disabled :default])
(def ?schema
[:=>

View File

@ -18,7 +18,11 @@
(style/add-container theme)
container-style)
: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
[network]
@ -29,7 +33,7 @@
(defn view-internal
[{:keys [network status amount container-style on-press] :as args}]
(let [theme (quo.theme/use-theme)]
(if (= status :add)
(if (= status :edit)
[network-bridge-add (assoc args :theme theme)]
[rn/pressable
{:style (merge (style/container network status theme) container-style)

View File

@ -17,7 +17,7 @@
{:key :locked :value :locked}
{:key :loading :value :loading}
{:key :disabled :value :disabled}
{:key :add :value :add}]}])
{:key :edit :value :edit}]}])
(defn view
[]

View File

@ -111,7 +111,7 @@
:else type)
:on-press #(when (not loading-routes?)
(cond
(= type :add)
(= type :edit)
(open-preferences)
on-press (on-press chain-id total-amount)))}]])
network-values)])

View File

@ -93,8 +93,6 @@
:optimism 2
:arbitrum 3})
(def ^:private available-networks-count
(count (set (keys network-priority-score))))
(defn reset-loading-network-amounts-to-zero
[network-amounts]
@ -114,7 +112,7 @@
disabled? (contains? disabled-chain-ids-set
(:chain-id network-amount))]
(cond-> network-amount
(and (not= (:type network-amount) :add)
(and (not= (:type network-amount) :edit)
(not= (:type network-amount) :not-available))
(assoc :total-amount (money/bignumber "0")
:type (if disabled? :disabled :default)))))
@ -136,9 +134,7 @@
(reduce
(fn [acc k]
(if (or (contains? network-values-keys k)
(and receiver?
(not (contains? receiver-networks-set
k))))
receiver?)
acc
(assoc acc k (money/bignumber "0"))))
network-values
@ -177,15 +173,13 @@
(vec))
(and receiver?
routes-found?
(< (count network-values-with-not-available-chains) available-networks-count)
(not= tx-type :tx/bridge))
(conj {:type :add}))))
(conj {: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)
receiver-networks-count (count receiver-networks)
token-networks-ids-set (set token-networks-ids)
valid-networks-set (set valid-networks)
not-available-networks (if receiver?
@ -199,30 +193,28 @@
(filter #(not (valid-networks-set %))
not-available-networks)))
(distinct))]
(cond-> (->> 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))
(and receiver? (< receiver-networks-count available-networks-count) (not= tx-type :tx/bridge))
(conj {:type :add}))))
(->> 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))))
(defn network-links
[route from-values-by-chain to-values-by-chain]

View File

@ -269,20 +269,16 @@
(deftest test-network-amounts
(testing "Handles disabled and receiver networks correctly when receiver? is true"
(let [network-values {1 (money/bignumber "100")
10 (money/bignumber "200")}
(let [network-values {10 (money/bignumber "200")}
disabled-chain-ids [1]
receiver-networks [10]
token-networks-ids [1 10 42161]
receiver? true
expected [{:chain-id 1
:total-amount (money/bignumber "100")
:type :default}
{:chain-id 10
expected [{:chain-id 10
:total-amount (money/bignumber "200")
:type :default}
{:type :add}]
tx-type :send
{:type :edit}]
tx-type :tx/send
result (utils/network-amounts {:network-values network-values
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -303,7 +299,7 @@
{:chain-id 10
:total-amount (money/bignumber "0")
:type :disabled}]
tx-type :send
tx-type :tx/send
result (utils/network-amounts {:network-values network-values
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -319,7 +315,7 @@
token-networks-ids []
receiver? true
expected []
tx-type :send
tx-type :tx/send
result (utils/network-amounts {:network-values network-values
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -344,8 +340,9 @@
:type :default}
{:chain-id 42161
:total-amount (money/bignumber "500")
:type :default}]
tx-type :send
:type :default}
{:type :edit}]
tx-type :tx/send
result (utils/network-amounts {:network-values network-values
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -366,7 +363,7 @@
{:chain-id 10
:total-amount (money/bignumber "0")
:type :disabled}]
tx-type :send
tx-type :tx/send
result (utils/network-amounts {:network-values network-values
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -388,7 +385,7 @@
{:chain-id 10
:total-amount nil
:type :not-available}]
tx-type :send
tx-type :tx/send
result (utils/network-amounts {:network-values network-values
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -397,7 +394,8 @@
:receiver? receiver?})]
(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")}
disabled-chain-ids [1]
receiver-networks [10]
@ -418,7 +416,8 @@
:receiver? receiver?})]
(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")}
disabled-chain-ids [1]
receiver-networks [10]
@ -444,9 +443,8 @@
token-networks-ids [1 10 42161]
receiver? true
expected [{:chain-id 1 :type :loading}
{:chain-id 10 :type :loading}
{:type :add}]
tx-type :send
{:chain-id 10 :type :loading}]
tx-type :tx/send
result (utils/loading-network-amounts {:valid-networks valid-networks
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -467,7 +465,7 @@
expected [{:chain-id 1 :type :loading}
{:chain-id 10 :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
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -487,7 +485,7 @@
receiver? true
expected [{:chain-id 1 :type :loading}
{:chain-id 42161 :type :loading}]
tx-type :send
tx-type :tx/send
result (utils/loading-network-amounts {:valid-networks valid-networks
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -500,15 +498,14 @@
(is (every? identity comparisons))))
(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]
disabled-chain-ids [10]
receiver-networks [1]
token-networks-ids [1 10 42161]
receiver? true
expected [{:chain-id 1 :type :loading}
{:type :add}]
tx-type :send
expected [{:chain-id 1 :type :loading}]
tx-type :tx/send
result (utils/loading-network-amounts {:valid-networks valid-networks
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -528,7 +525,7 @@
token-networks-ids [42161]
receiver? false
expected [{:chain-id 42161 :type :loading}]
tx-type :send
tx-type :tx/send
result (utils/loading-network-amounts {:valid-networks valid-networks
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -547,9 +544,8 @@
receiver-networks [1]
token-networks-ids [42161]
receiver? true
expected [{:chain-id 1 :type :not-available}
{:type :add}]
tx-type :send
expected [{:chain-id 1 :type :not-available}]
tx-type :tx/send
result (utils/loading-network-amounts {:valid-networks valid-networks
:disabled-chain-ids disabled-chain-ids
:receiver-networks receiver-networks
@ -562,7 +558,7 @@
(is (every? identity comparisons))))
(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]
disabled-chain-ids [10]
receiver-networks []
@ -583,7 +579,7 @@
(is (every? identity comparisons))))
(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]
disabled-chain-ids [10]
receiver-networks []