Skip to content

Commit

Permalink
more polishing and try to fix component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
briansztamfater committed Apr 2, 2024
1 parent 0c82517 commit 213c6fe
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[status-im.contexts.wallet.send.input-amount.view :as input-amount]
[test-helpers.component :as h]
[utils.debounce :as debounce]
[utils.money :as money]
[utils.re-frame :as rf]))

(set! rf/dispatch #())
Expand Down Expand Up @@ -41,7 +42,11 @@
:removed false}
:wallet/wallet-send-token {:symbol :eth
:total-balance 100
:market-values-per-currency {:usd {:price 10}}}
:market-values-per-currency {:usd {:price 10}}
:balances-per-chain {1 {:raw-balance
(money/bignumber
"2500")
:has-error false}}}
:wallet/wallet-send-loading-suggested-routes? false
:wallet/wallet-send-route [{:from {:chainid 1
:native-currency-symbol "ETH"}
Expand All @@ -52,13 +57,16 @@
:max-priority-fee-per-gas "0.011000001"
:eip1559-enabled true}}]
:wallet/wallet-send-suggested-routes {:candidates []}
:wallet/wallet-send-selected-networks []
:wallet/wallet-send-selected-networks [1]
:view-id :screen/wallet.send-input-amount
:wallet/wallet-send-to-address "0x04371e2d9d66b82f056bc128064"
:profile/currency-symbol "$"
:wallet/token-by-symbol {:symbol :eth
:total-balance 100
:market-values-per-currency {:usd {:price 10}}}})
:market-values-per-currency {:usd {:price 10}}}
:wallet/wallet-disabled-from-chain-ids []
:wallet/wallet-from-values-by-chain {1 (money/bignumber "1")}
:wallet/wallet-to-values-by-chain {1 (money/bignumber "1")}})

(h/describe "Send > input amount screen"
(h/setup-restorable-re-frame)
Expand Down
111 changes: 56 additions & 55 deletions src/status_im/contexts/wallet/send/input_amount/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -203,61 +203,62 @@
(reset! input-selection selection)
(reagent/flush))]
(fn []
(let [{fiat-currency :currency} (rf/sub [:profile/profile])
{token-balance :total-balance
token-symbol :symbol
token-networks :networks
:as token} (rf/sub [:wallet/wallet-send-token])
conversion-rate (-> token :market-values-per-currency :usd :price)
loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
best-routes (when suggested-routes (or (:best suggested-routes) []))
route (rf/sub [:wallet/wallet-send-route])
to-address (rf/sub [:wallet/wallet-send-to-address])
disabled-from-chain-ids (rf/sub [:wallet/wallet-disabled-from-chain-ids])
from-values-by-chain (rf/sub [:wallet/wallet-from-values-by-chain])
to-values-by-chain (rf/sub [:wallet/wallet-to-values-by-chain])
on-confirm (or default-on-confirm handle-on-confirm)
crypto-decimals (or default-crypto-decimals
(utils/get-crypto-decimals-count token))
crypto-limit (or default-limit-crypto
(utils/get-standard-crypto-format token token-balance))
fiat-limit (.toFixed (* token-balance conversion-rate) 2)
current-limit #(if @crypto-currency? crypto-limit fiat-limit)
current-currency (if @crypto-currency? token-symbol fiat-currency)
limit-label (make-limit-label {:amount (current-limit)
:currency current-currency})
input-num-value (parse-double @input-value)
confirm-disabled? (or (nil? route)
(empty? route)
(empty? @input-value)
(<= input-num-value 0)
(> input-num-value (current-limit)))
amount-text (str @input-value " " token-symbol)
native-currency-symbol (when-not confirm-disabled?
(get-in route [:from :native-currency-symbol]))
native-token (when native-currency-symbol
(rf/sub [:wallet/token-by-symbol native-currency-symbol]))
fee-in-native-token (when-not confirm-disabled?
(send-utils/calculate-full-route-gas-fee route))
fee-in-crypto-formatted (when fee-in-native-token
(utils/get-standard-crypto-format native-token
fee-in-native-token))
fee-in-fiat (when-not confirm-disabled?
(utils/token-fiat-value fiat-currency
fee-in-native-token
native-token))
currency-symbol (rf/sub [:profile/currency-symbol])
fee-formatted (when fee-in-fiat
(utils/get-standard-fiat-format fee-in-crypto-formatted
currency-symbol
fee-in-fiat))
selected-networks (rf/sub [:wallet/wallet-send-selected-networks])
affordable-networks (send-utils/find-affordable-networks
{:balances-per-chain (:balances-per-chain token)
:input-value @input-value
:selected-networks selected-networks
:disabled-chain-ids disabled-from-chain-ids})]
(let [{fiat-currency :currency} (rf/sub [:profile/profile])
{token-balance :total-balance
token-symbol :symbol
token-networks :networks
token-balances-per-chain :balances-per-chain
:as token} (rf/sub [:wallet/wallet-send-token])
conversion-rate (-> token :market-values-per-currency :usd :price)
loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
best-routes (when suggested-routes (or (:best suggested-routes) []))
route (rf/sub [:wallet/wallet-send-route])
to-address (rf/sub [:wallet/wallet-send-to-address])
disabled-from-chain-ids (rf/sub [:wallet/wallet-disabled-from-chain-ids])
from-values-by-chain (rf/sub [:wallet/wallet-from-values-by-chain])
to-values-by-chain (rf/sub [:wallet/wallet-to-values-by-chain])
on-confirm (or default-on-confirm handle-on-confirm)
crypto-decimals (or default-crypto-decimals
(utils/get-crypto-decimals-count token))
crypto-limit (or default-limit-crypto
(utils/get-standard-crypto-format token token-balance))
fiat-limit (.toFixed (* token-balance conversion-rate) 2)
current-limit #(if @crypto-currency? crypto-limit fiat-limit)
current-currency (if @crypto-currency? token-symbol fiat-currency)
limit-label (make-limit-label {:amount (current-limit)
:currency current-currency})
input-num-value (parse-double @input-value)
confirm-disabled? (or (nil? route)
(empty? route)
(empty? @input-value)
(<= input-num-value 0)
(> input-num-value (current-limit)))
amount-text (str @input-value " " token-symbol)
native-currency-symbol (when-not confirm-disabled?
(get-in route [:from :native-currency-symbol]))
native-token (when native-currency-symbol
(rf/sub [:wallet/token-by-symbol native-currency-symbol]))
fee-in-native-token (when-not confirm-disabled?
(send-utils/calculate-full-route-gas-fee route))
fee-in-crypto-formatted (when fee-in-native-token
(utils/get-standard-crypto-format native-token
fee-in-native-token))
fee-in-fiat (when-not confirm-disabled?
(utils/token-fiat-value fiat-currency
fee-in-native-token
native-token))
currency-symbol (rf/sub [:profile/currency-symbol])
fee-formatted (when fee-in-fiat
(utils/get-standard-fiat-format fee-in-crypto-formatted
currency-symbol
fee-in-fiat))
selected-networks (rf/sub [:wallet/wallet-send-selected-networks])
affordable-networks (send-utils/find-affordable-networks
{:balances-per-chain token-balances-per-chain
:input-value @input-value
:selected-networks selected-networks
:disabled-chain-ids disabled-from-chain-ids})]
(rn/use-mount
(fn []
(let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!))
Expand Down
14 changes: 8 additions & 6 deletions src/status_im/contexts/wallet/send/routes/style.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
{:flex-direction :row
:justify-content :space-between})

(def routes-inner-container
{:margin-top 11
(defn routes-inner-container
[first-item?]
{:margin-top (if first-item? 7.5 11)
:flex-direction :row
:align-items :center
:justify-content :space-between})

(defn section-label
[margin-left]
{:flex 0.5
:margin-left margin-left})
(def section-label-right
{:width 135})

(def section-label-left
{:width 136})

(def network-link
{:margin-horizontal -1.5
Expand Down
19 changes: 11 additions & 8 deletions src/status_im/contexts/wallet/send/routes/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@
:customization-color color}}]])))

(defn route-item
[{:keys [from-amount to-amount token-symbol from-chain-id to-chain-id from-network to-network
on-press-from-network on-press-to-network status theme fetch-routes disabled? loading?]}]
[{:keys [first-item? from-amount to-amount token-symbol from-chain-id to-chain-id from-network
to-network on-press-from-network on-press-to-network status theme fetch-routes disabled?
loading?]}]
(if (= status :add)
[quo/network-bridge
{:status :add
Expand All @@ -127,7 +128,7 @@
{:content (fn [] [networks-drawer
{:theme theme
:fetch-routes fetch-routes}])}])}]
[rn/view {:style style/routes-inner-container}
[rn/view {:style (style/routes-inner-container first-item?)}
[quo/network-bridge
{:amount (str from-amount " " token-symbol)
:network from-network
Expand Down Expand Up @@ -171,20 +172,22 @@
:header [rn/view {:style style/routes-header-container}
[quo/section-label
{:section (i18n/label :t/from-label)
:container-style (style/section-label 0)}]
:container-style style/section-label-left}]
[quo/section-label
{:section (i18n/label :t/to-label)
:container-style (style/section-label 64)}]]
:render-fn (fn [item]
(let [disabled-network? (= (:status item) :disabled)
:container-style style/section-label-right}]]
:render-fn (fn [item index]
(let [first-item? (= index 0)
disabled-network? (= (:status item) :disabled)
from-chain-id (get-in item [:from :chain-id])
to-chain-id (get-in item [:to :chain-id])
from-amount (when from-chain-id
(from-values-by-chain from-chain-id))
to-amount (when to-chain-id
(to-values-by-chain to-chain-id))]
[route-item
{:from-amount (if disabled-network? 0 from-amount)
{:first-item? first-item?
:from-amount (if disabled-network? 0 from-amount)
:to-amount (if disabled-network? 0 to-amount)
:token-symbol token-symbol
:disabled? disabled-network?
Expand Down

0 comments on commit 213c6fe

Please sign in to comment.