Skip to content

Commit

Permalink
fixes based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
briansztamfater committed Apr 8, 2024
1 parent 4555caa commit a768091
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@
(def ^:const optimism-short-name "opt")
(def ^:const arbitrum-short-name "arb1")

(def ^:const default-address-prefix "eth:opt:arb1:")
(def ^:const default-multichain-address-prefix "eth:opt:arb1:")

(def ^:const mainnet-abbreviated-name "Eth.")
(def ^:const optimism-abbreviated-name "Opt.")
Expand Down
14 changes: 14 additions & 0 deletions src/status_im/contexts/wallet/common/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,17 @@
{}
tokens)
(update-vals #(prettify-balance currency-symbol %))))

(defn resolve-receiver-networks
[{:keys [prefix testnet-enabled? goerli-enabled?]}]
(let [prefix (if (string/blank? prefix)
constants/default-multichain-address-prefix
prefix)
prefix-seq (string/split prefix #":")]
(->> prefix-seq
(remove string/blank?)
(mapv
#(network->chain-id
{:network %
:testnet-enabled? testnet-enabled?
:goerli-enabled? goerli-enabled?})))))
21 changes: 13 additions & 8 deletions src/status_im/contexts/wallet/common/utils/send.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns status-im.contexts.wallet.common.utils.send
(:require [utils.money :as money]))
(:require [utils.money :as money]
[clojure.string :as string]))

(defn calculate-gas-fee
[data]
Expand All @@ -23,10 +24,14 @@

(defn find-affordable-networks
[{:keys [balances-per-chain input-value selected-networks disabled-chain-ids]}]
(->> balances-per-chain
(filter (fn [[_ {:keys [balance chain-id]}]]
(and
(>= (js/parseFloat balance) input-value)
(some #(= % chain-id) selected-networks)
(not-any? #(= % chain-id) disabled-chain-ids))))
(map first)))
(let [input-value (if (string/blank? input-value) 0 input-value)]
(->> balances-per-chain
(filter (fn [[_
{:keys [balance chain-id]
:or {balance 0}}]]
(and
(money/greater-than-or-equals (money/bignumber balance)
(money/bignumber input-value))
(some #(= % chain-id) selected-networks)
(not-any? #(= % chain-id) disabled-chain-ids))))
(map first))))
77 changes: 38 additions & 39 deletions src/status_im/contexts/wallet/send/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,43 @@
(rf/reg-event-fx :wallet/suggested-routes-success
(fn [{:keys [db]} [suggested-routes timestamp]]
(when (= (get-in db [:wallet :ui :send :suggested-routes-call-timestamp]) timestamp)
(let [suggested-routes-data (cske/transform-keys transforms/->kebab-case-keyword
suggested-routes)
chosen-route (:best suggested-routes-data)
token (get-in db [:wallet :ui :send :token])
collectible (get-in db [:wallet :ui :send :collectible])
collection-data (:collection-data collectible)
collectible-data (:collectible-data collectible)
collectible-id (get-in collectible [:id :token-id])
token-symbol (if collectible
(first (remove
string/blank?
[(:name collectible-data)
(str (:name collection-data) " #" collectible-id)]))
(:symbol token))
token-decimals (if collectible 0 (:decimals token))
native-token? (and token (= token-symbol "ETH"))
from-network-amounts (send-utils/network-amounts {:route chosen-route
:token-decimals token-decimals
:native-token? native-token?
:to? false})
from-network-values (send-utils/network-values from-network-amounts)
from-network-values-sanitized (send-utils/network-values-sanitized from-network-values)
to-network-amounts (send-utils/network-amounts {:route chosen-route
:token-decimals token-decimals
:native-token? native-token?
:to? true})
to-network-values (send-utils/network-values to-network-amounts)
to-network-values-sanitized (send-utils/network-values-sanitized to-network-values)]
(let [suggested-routes-data (cske/transform-keys transforms/->kebab-case-keyword
suggested-routes)
chosen-route (:best suggested-routes-data)
token (get-in db [:wallet :ui :send :token])
collectible (get-in db [:wallet :ui :send :collectible])
collection-data (:collection-data collectible)
collectible-data (:collectible-data collectible)
collectible-id (get-in collectible [:id :token-id])
token-symbol (cond
(and collectible
(not (string/blank? (:name collectible-data))))
(:name collectible-data)

collectible
(str (:name collection-data) " #" collectible-id)

:else
(:symbol token))
token-decimals (if collectible 0 (:decimals token))
native-token? (and token (= token-symbol "ETH"))
from-network-amounts (send-utils/network-amounts {:route chosen-route
:token-decimals token-decimals
:native-token? native-token?
:to? false})
from-network-values (send-utils/network-values from-network-amounts)
from-network-values-for-ui (send-utils/network-values-for-ui from-network-values)
to-network-amounts (send-utils/network-amounts {:route chosen-route
:token-decimals token-decimals
:native-token? native-token?
:to? true})
to-network-values (send-utils/network-values to-network-amounts)
to-network-values-for-ui (send-utils/network-values-for-ui to-network-values)]
{:db (-> db
(assoc-in [:wallet :ui :send :suggested-routes] suggested-routes-data)
(assoc-in [:wallet :ui :send :route] chosen-route)
(assoc-in [:wallet :ui :send :from-values-by-chain] from-network-values-sanitized)
(assoc-in [:wallet :ui :send :to-values-by-chain] to-network-values-sanitized)
(assoc-in [:wallet :ui :send :from-values-by-chain] from-network-values-for-ui)
(assoc-in [:wallet :ui :send :to-values-by-chain] to-network-values-for-ui)
(assoc-in [:wallet :ui :send :loading-suggested-routes?] false))}))))

(rf/reg-event-fx :wallet/suggested-routes-error
Expand Down Expand Up @@ -91,15 +95,10 @@
(let [[prefix to-address] (utils/split-prefix-and-address address)
testnet-enabled? (get-in db [:profile/profile :test-networks-enabled?])
goerli-enabled? (get-in db [:profile/profile :is-goerli-enabled?])
prefix (if (string/blank? prefix) constants/default-address-prefix prefix)
prefix-seq (string/split prefix #":")
selected-networks (->> prefix-seq
(remove string/blank?)
(mapv
#(utils/network->chain-id
{:network %
:testnet-enabled? testnet-enabled?
:goerli-enabled? goerli-enabled?})))]
selected-networks (utils/resolve-receiver-networks
{:prefix prefix
:testnet-enabled? testnet-enabled?
:goerli-enabled? goerli-enabled?})]
{:db (-> db
(assoc-in [:wallet :ui :send :recipient] (or recipient address))
(assoc-in [:wallet :ui :send :to-address] to-address)
Expand Down
9 changes: 3 additions & 6 deletions src/status_im/contexts/wallet/send/input_amount/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,9 @@
(if-not (or (empty? @input-value)
(<= input-num-value 0)
(> input-num-value current-limit-amount))
(if (= bounce-duration-ms 0)
(rf/dispatch [:wallet/get-suggested-routes
{:amount @input-value}])
(debounce/debounce-and-dispatch
[:wallet/get-suggested-routes {:amount @input-value}]
bounce-duration-ms))
(debounce/debounce-and-dispatch
[:wallet/get-suggested-routes {:amount @input-value}]
bounce-duration-ms)
(rf/dispatch [:wallet/clean-suggested-routes])))))
handle-on-confirm (fn []
(rf/dispatch [:wallet/send-select-amount
Expand Down
Loading

0 comments on commit a768091

Please sign in to comment.