fixes on network selection flow and not enough assets to cover fees error message logic

Signed-off-by: Brian Sztamfater <brian@status.im>
This commit is contained in:
Brian Sztamfater 2024-12-20 12:54:05 -03:00
parent 61c6ba13b4
commit 9648e36488
No known key found for this signature in database
GPG Key ID: 59EB921E0706B48F
5 changed files with 41 additions and 25 deletions

View File

@ -77,7 +77,7 @@
(defn token-value-drawer
[token watch-only? entry-point]
(let [token-symbol (:token token)
token-data (rf/sub [:wallet/token-by-symbol token-symbol])
token-data (rf/sub [:wallet/token-by-symbol-from-first-available-account token-symbol])
selected-account (rf/sub [:wallet/current-viewing-account-address])
token-owners (rf/sub [:wallet/operable-addresses-with-token-symbol token-symbol])
testnet-mode? (rf/sub [:profile/test-networks-enabled?])
@ -86,6 +86,7 @@
receive-token-symbol (if (= token-symbol "SNT") "ETH" "SNT")
token-owned? (if selected-account account-owns-token? (seq token-owners))
asset-to-receive (rf/sub [:wallet/token-by-symbol receive-token-symbol])
unique-owner? (= (count token-owners) 1)
params (cond-> {:start-flow? true
:owners token-owners
:testnet-mode? testnet-mode?}
@ -94,7 +95,12 @@
:stack-id :screen/wallet.accounts
:has-balance? (-> (get-in token [:values :fiat-unformatted-value])
money/above-zero?))
(not selected-account)
(and (not selected-account) unique-owner?)
(assoc :token-symbol token-symbol
:token token-data
:stack-id :wallet-stack)
(and (not selected-account) (not unique-owner?))
(assoc :token-symbol token-symbol
:stack-id :wallet-stack))]
[quo/action-drawer
@ -124,7 +130,11 @@
(cond-> item
(or (not watch-only?) (ff/enabled? ::ff/wallet.long-press-watch-only-asset))
(assoc :on-long-press
#(rf/dispatch
(fn []
(when (= entry-point :wallet-stack)
(rf/dispatch [:wallet/close-account-page])
(rf/dispatch [:wallet/clean-current-viewing-account]))
(rf/dispatch
[:show-bottom-sheet
{:content (fn [] [token-value-drawer item watch-only? entry-point])
:selected-item (fn [] [quo/token-value item])}])))])
:selected-item (fn [] [quo/token-value item])}]))))])

View File

@ -708,7 +708,7 @@
[:dispatch
[:wallet/wizard-navigate-forward
{:current-screen stack-id
:start-flow? start-flow?
:start-flow? (and start-flow? (not balance-in-only-one-network?))
:flow-id flow-id}]]]
[[:dispatch [:dismiss-modal :screen/wallet.select-from]]
[:dispatch [:wallet/switch-current-viewing-account address]]

View File

@ -1,5 +1,6 @@
(ns status-im.contexts.wallet.send.from.view
(:require
[clojure.string :as string]
[quo.core :as quo]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
@ -20,7 +21,7 @@
(defn- render-fn
[item _ _ {:keys [network-details]}]
(let [has-balance (money/above-zero? (:asset-pay-balance item))]
(let [has-balance (money/above-zero? (string/replace-first (:asset-pay-balance item) "<" ""))]
[quo/account-item
{:type (if has-balance :tag :default)
:on-press #(on-account-press (:address item) network-details)

View File

@ -75,8 +75,7 @@
(rf/sub [:wallet/wallet-send-fee-fiat-formatted native-currency-symbol])))
(defn- insufficient-asset-amount?
[{:keys [token-symbol owned-eth-token input-state no-routes-found? limit-exceeded?
enough-assets?]}]
[{:keys [token-symbol owned-eth-token input-state limit-exceeded? enough-assets?]}]
(let [eth-selected? (= token-symbol (string/upper-case constants/mainnet-short-name))
zero-owned-eth? (money/equal-to (:total-balance owned-eth-token) 0)
input-at-max-owned-amount? (money/equal-to
@ -85,8 +84,9 @@
exceeded-input? (if eth-selected?
input-at-max-owned-amount?
zero-owned-eth?)]
(and (or no-routes-found? limit-exceeded? (false? enough-assets?))
exceeded-input?)))
(or exceeded-input?
limit-exceeded?
(false? enough-assets?))))
(defn view
;; crypto-decimals, limit-crypto and initial-crypto-currency? args are needed
@ -159,7 +159,6 @@
:token-symbol token-symbol
:owned-eth-token owned-eth-token
:input-state input-state
:no-routes-found? no-routes-found?
:limit-exceeded? limit-exceeded?})
should-try-again? (and (not limit-exceeded?)
no-routes-found?
@ -271,8 +270,7 @@
[rn/view {:style {:flex 1}}])
(when not-enough-asset?
[not-enough-asset])
(when (or (and (not no-routes-found?) (or loading-routes? route))
(and not-enough-asset? (not limit-exceeded?)))
(when (or loading-routes? route)
[estimated-fees/view
{:not-enough-asset? not-enough-asset?
:loading-routes? loading-routes?

View File

@ -558,15 +558,22 @@
(rf/reg-sub
:wallet/token-by-symbol-from-first-available-account
:<- [:wallet/accounts]
:<- [:wallet/current-viewing-account-or-default]
:<- [:wallet/network-details]
(fn [[accounts networks] [_ token-symbol chain-ids]]
(fn [[accounts {:keys [tokens]} networks] [_ token-symbol chain-ids]]
(when token-symbol
(or
(->> (utils/tokens-with-balance tokens networks chain-ids)
(filter #(= (string/lower-case (:symbol %))
(string/lower-case token-symbol)))
first)
(some
(fn [{:keys [tokens]}]
(->> (utils/tokens-with-balance tokens networks chain-ids)
(filter #(= (string/lower-case (:symbol %))
(string/lower-case token-symbol)))
first))
accounts)))
accounts)))))
(rf/reg-sub
:wallet/accounts-without-current-viewing-account