Skip to content

Commit

Permalink
fix: max value is incorrect for some tokens (#20096)
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Sztamfater <brian@status.im>
  • Loading branch information
briansztamfater authored May 21, 2024
1 parent a480df4 commit 32123d2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 32 deletions.
7 changes: 5 additions & 2 deletions src/status_im/contexts/wallet/send/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,16 @@

(rf/reg-event-fx
:wallet/select-from-account
(fn [{db :db} [{:keys [address stack-id start-flow?]}]]
(fn [{db :db} [{:keys [address stack-id network-details start-flow?]}]]
(let [token-symbol (-> db :wallet :ui :send :token-symbol)
token (when token-symbol
;; When this flow has started in the wallet home page, we know the
;; token or collectible to send, but we don't know from which
;; account, so we extract the token data from the picked account.
(utils/get-token-from-account db token-symbol address))]
(let [token (utils/get-token-from-account db token-symbol address)]
(assoc token
:networks (network-utils/network-list token network-details)
:total-balance (utils/calculate-total-token-balance token))))]
{:db (if token-symbol
(-> db
(assoc-in [:wallet :ui :send :token] token)
Expand Down
14 changes: 8 additions & 6 deletions src/status_im/contexts/wallet/send/from/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
[utils.re-frame :as rf]))

(defn- on-press
[address]
[address network-details]
(rf/dispatch [:wallet/select-from-account
{:address address
:stack-id :screen/wallet.select-from}]))
{:address address
:network-details network-details
:stack-id :screen/wallet.select-from}]))

(defn- on-close
[]
Expand All @@ -22,9 +23,10 @@

(defn- render-fn
[item]
[quo/account-item
{:on-press #(on-press (:address item))
:account-props item}])
(let [network-details (rf/sub [:wallet/network-details])]
[quo/account-item
{:on-press #(on-press (:address item) network-details)
:account-props item}]))

(defn view
[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@
:mixedcase-address "0x7bcDfc75c431"
:public-key "0x04371e2d9d66b82f056bc128064"
:removed false}
:wallet/wallet-send-token {:symbol :eth
:networks [{:source 879
:short-name "eth"
:network-name :mainnet
:abbreviated-name "Eth."
:chain-id 1
:related-chain-id 1
:layer 1}]}
:wallet/current-viewing-account-tokens-filtered {:balances-per-chain {1 {:raw-balance
:wallet/wallet-send-token {:symbol :eth
:networks [{:source 879
:short-name "eth"
:network-name :mainnet
:abbreviated-name
"Eth."
:chain-id 1
:related-chain-id 1
:layer 1}]
:balances-per-chain {1 {:raw-balance
(money/bignumber
"2500")
:has-error false}}
Expand All @@ -72,6 +73,11 @@
:profile/currency :usd
:wallet/token-by-symbol {:symbol :eth
:total-balance 100
:available-balance 100
:balances-per-chain {1 {:raw-balance
(money/bignumber
"2500")
:has-error false}}
:market-values-per-currency {:usd {:price 10}}}
:wallet/wallet-send-disabled-from-chain-ids []
:wallet/wallet-send-from-values-by-chain {1 (money/bignumber "250")}
Expand Down
16 changes: 8 additions & 8 deletions src/status_im/contexts/wallet/send/input_amount/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@
input-state)
:stack-id current-screen-id}]))
{fiat-currency :currency} (rf/sub [:profile/profile])
{token-symbol :symbol
{token-symbol :symbol
token-networks :networks
token-decimals :decimals} (rf/sub [:wallet/wallet-send-token])
token-decimals :decimals
:as
token} (rf/sub [:wallet/wallet-send-token])
send-enabled-networks (rf/sub [:wallet/wallet-send-enabled-networks])
enabled-from-chain-ids (rf/sub
[:wallet/wallet-send-enabled-from-chain-ids])
{token-balance :total-balance
available-balance :available-balance
:as
token} (rf/sub
[:wallet/current-viewing-account-tokens-filtered
(str token-symbol) enabled-from-chain-ids])
{token-balance :total-balance
available-balance :available-balance} (rf/sub [:wallet/token-by-symbol
(str token-symbol)
enabled-from-chain-ids])
currency-symbol (rf/sub [:profile/currency-symbol])
currency (rf/sub [:profile/currency])
conversion-rate (-> token :market-values-per-currency currency :price)
Expand Down
4 changes: 1 addition & 3 deletions src/status_im/contexts/wallet/send/routes/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@
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/current-viewing-account-tokens-filtered
(str token-symbol)])
{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
Expand Down
22 changes: 18 additions & 4 deletions src/status_im/subs/wallet/wallet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,19 @@
(rf/reg-sub
:wallet/wallet-send-token
:<- [:wallet/wallet-send]
:-> :token)
:<- [:wallet/network-details]
:<- [:wallet/wallet-send-disabled-from-chain-ids]
(fn [[wallet-send networks disabled-from-chain-ids]]
(let [token (:token wallet-send)
enabled-from-chain-ids (->> networks
(filter #(not (contains? (set disabled-from-chain-ids)
(:chain-id %))))
(map :chain-id)
set)]
(assoc token
:networks (network-utils/network-list token networks)
:available-balance (utils/calculate-total-token-balance token)
:total-balance (utils/calculate-total-token-balance token enabled-from-chain-ids)))))

(rf/reg-sub
:wallet/wallet-send-disabled-from-chain-ids
Expand Down Expand Up @@ -310,11 +322,13 @@
:wallet/token-by-symbol
:<- [:wallet/current-viewing-account]
:<- [:wallet/network-details]
(fn [[account networks] [_ token-symbol]]
(fn [[account networks] [_ token-symbol chain-ids]]
(let [tokens (map (fn [token]
(assoc token
:networks (network-utils/network-list token networks)
:total-balance (utils/calculate-total-token-balance token)))
:networks (network-utils/network-list token networks)
:available-balance (utils/calculate-total-token-balance token)
:total-balance (utils/calculate-total-token-balance token
chain-ids)))
(:tokens account))
token (first (filter #(= (string/lower-case (:symbol %))
(string/lower-case token-symbol))
Expand Down

0 comments on commit 32123d2

Please sign in to comment.