diff --git a/src/quo/components/wallet/token_input/component_spec.cljs b/src/quo/components/wallet/token_input/component_spec.cljs index deeaf92ee9e0..6e76ce46c2d9 100644 --- a/src/quo/components/wallet/token_input/component_spec.cljs +++ b/src/quo/components/wallet/token_input/component_spec.cljs @@ -6,14 +6,14 @@ (h/describe "Wallet: Token Input" (h/test "Token label renders" (h/render [token-input/view - {:token {:symbol "snt"} + {:token :snt :currency :eur :conversion 1}]) (h/is-truthy (h/get-by-text "SNT"))) (h/test "Amount renders" (h/render [token-input/view - {:token {:symbol "snt"} + {:token :snt :currency :eur :conversion 1}]) (h/is-truthy (h/get-by-text "€0.00")))) diff --git a/src/status_im2/contexts/wallet/common/utils.cljs b/src/status_im2/contexts/wallet/common/utils.cljs index 9d93a34bd7d7..e814018b9edc 100644 --- a/src/status_im2/contexts/wallet/common/utils.cljs +++ b/src/status_im2/contexts/wallet/common/utils.cljs @@ -69,8 +69,9 @@ (defn calculate-balance-for-token [token] - (* (total-token-units-in-all-chains token) - (-> token :market-values-per-currency :usd :price))) + (money/bignumber + (money/mul (total-token-units-in-all-chains token) + (-> token :market-values-per-currency :usd :price)))) (defn calculate-balance [tokens-in-account] diff --git a/src/status_im2/contexts/wallet/events.cljs b/src/status_im2/contexts/wallet/events.cljs index f0480715f455..901d68fcdef1 100644 --- a/src/status_im2/contexts/wallet/events.cljs +++ b/src/status_im2/contexts/wallet/events.cljs @@ -141,7 +141,9 @@ (rf/defn clean-scanned-address {:events [:wallet/clean-scanned-address]} [{:keys [db]}] - {:db (dissoc db :wallet/scanned-address :wallet/send-address)}) + {:db (-> db + (dissoc :wallet/scanned-address :wallet/send-address) + (update-in [:wallet :ui :send] dissoc :to-address))}) (rf/reg-event-fx :wallet/create-derived-addresses (fn [{:keys [db]} [{:keys [sha3-pwd path]} on-success]] @@ -426,10 +428,6 @@ (background-timer/clear-timeout current-timeout) {:db (assoc db :wallet/local-suggestions [] :wallet/valid-ens-or-address? false)}))) -(rf/reg-event-fx :wallet/select-send-address - (fn [{:keys [db]} [address]] - {:db (assoc db :wallet/send-address address)})) - (rf/reg-event-fx :wallet/get-address-details-success (fn [{:keys [db]} [{:keys [hasActivity]}]] {:db (assoc-in db diff --git a/src/status_im2/contexts/wallet/send/events.cljs b/src/status_im2/contexts/wallet/send/events.cljs index 1b9524aab59b..22be1936dec1 100644 --- a/src/status_im2/contexts/wallet/send/events.cljs +++ b/src/status_im2/contexts/wallet/send/events.cljs @@ -30,46 +30,49 @@ (update-in [:wallet :ui :send] dissoc :loading-suggested-routes?))})) (rf/reg-event-fx :wallet/select-send-address - (fn [{:keys [db]} [address]] - {:db (assoc-in db [:wallet :ui :send :to-address] address)})) + (fn [{:keys [db]} [{:keys [address stack-id]}]] + (println "dsadadasd" address stack-id) + {:db (assoc-in db [:wallet :ui :send :to-address] address) + :fx [[:navigate-to-within-stack [:wallet-select-asset stack-id]]]})) (rf/reg-event-fx :wallet/send-select-token - (fn [{:keys [db]} [token stack-id]] + (fn [{:keys [db]} [{:keys [token stack-id]}]] {:db (assoc-in db [:wallet :ui :send :token] token) :fx [[:navigate-to-within-stack [:wallet-send-input-amount stack-id]]]})) (rf/reg-event-fx :wallet/get-suggested-routes - (fn [{:keys [db]} [amount]] - (let [wallet-address (get-in db [:wallet :current-viewing-account-address]) - token (get-in db [:wallet :ui :send :token]) - to-address (get-in db [:wallet :ui :send :to-address]) - token-decimal (:decimals token) - token-id (:symbol token) - network-preferences [constants/mainnet-chain-id] ; TODO: don't hardcode network preferences - gas-rates constants/gas-rate-low - amount-in (money/mul (money/bignumber amount) - (money/from-decimal token-decimal)) - from-address wallet-address - request-params [constants/send-type-transfer - from-address - to-address - (money/to-hex amount-in) - token-id - [] - [] - network-preferences - gas-rates - {}] - timestamp (datetime/timestamp)] + (fn [{:keys [db now]} [amount]] + (let [wallet-address (get-in db [:wallet :current-viewing-account-address]) + token (get-in db [:wallet :ui :send :token]) + to-address (get-in db [:wallet :ui :send :to-address]) + token-decimal (:decimals token) + token-id (:symbol token) + network-preferences [constants/mainnet-chain-id] ; TODO: don't hardcode network + ; preferences + gas-rates constants/gas-rate-low + amount-in (money/amount-in-hex amount token-decimal) + from-address wallet-address + disabled-from-chain-ids [] + disabled-to-chain-ids [] + from-locked-amount {} + request-params [constants/send-type-transfer + from-address + to-address + amount-in + token-id + disabled-from-chain-ids + disabled-to-chain-ids + network-preferences + gas-rates + from-locked-amount]] {:db (-> db (assoc-in [:wallet :ui :send :loading-suggested-routes?] true) - (assoc-in [:wallet :ui :send :suggested-routes-call-timestamp] - timestamp)) + (assoc-in [:wallet :ui :send :suggested-routes-call-timestamp] now)) :json-rpc/call [{:method "wallet_getSuggestedRoutes" :params request-params :on-success (fn [suggested-routes] (rf/dispatch [:wallet/suggested-routes-success suggested-routes - timestamp])) + now])) :on-error (fn [error] (rf/dispatch [:wallet/suggested-routes-error error]) (log/error "failed to get suggested routes" diff --git a/src/status_im2/contexts/wallet/send/input_amount/view.cljs b/src/status_im2/contexts/wallet/send/input_amount/view.cljs index e960c5e7caca..5a81cfeacac2 100644 --- a/src/status_im2/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im2/contexts/wallet/send/input_amount/view.cljs @@ -52,8 +52,8 @@ (let [bottom (safe-area/get-bottom) {:keys [currency]} (rf/sub [:profile/profile]) networks (rf/sub [:wallet/network-details]) - wallet-send (get-in (rf/sub [:wallet]) [:ui :send]) - token (:token wallet-send) + token (rf/sub [:wallet/wallet-send-token]) + loading-suggested-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?]) token-symbol (:symbol token) limit-crypto (:total-balance token) limit-fiat (:total-balance-fiat token) @@ -61,7 +61,6 @@ input-value (reagent/atom "") current-limit (reagent/atom {:amount limit-crypto :currency token-symbol}) - loading-suggested-routes? (:loading-suggested-routes? wallet-send) handle-swap (fn [crypto?] (let [num-value (parse-double @input-value)] (reset! current-limit (if crypto? @@ -96,8 +95,8 @@ :wallet-send-input-amount])}}] (let [limit-label (make-limit-label @current-limit) input-num-value (parse-double @input-value) - route (get-in (rf/sub [:wallet]) [:ui :send :route]) - loading-suggested-routes? (get-in (rf/sub [:wallet]) [:ui :send :loading-suggested-routes?]) + route (rf/sub [:wallet/wallet-send-route]) + loading-suggested-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?]) confirm-disabled? (or (nil? route) (empty? @input-value) diff --git a/src/status_im2/contexts/wallet/send/select_address/view.cljs b/src/status_im2/contexts/wallet/send/select_address/view.cljs index c8b4d9f85c49..bc30568e710e 100644 --- a/src/status_im2/contexts/wallet/send/select_address/view.cljs +++ b/src/status_im2/contexts/wallet/send/select_address/view.cljs @@ -47,7 +47,7 @@ [input-value input-focused?] (fn [] (let [scanned-address (rf/sub [:wallet/scanned-address]) - send-address (get-in (rf/sub [:wallet]) [:ui :send :to-address]) + send-address (rf/sub [:wallet/wallet-send-to-address]) valid-ens-or-address? (rf/sub [:wallet/valid-ens-or-address?]) chain-id (rf/sub [:chain-id]) contacts (rf/sub [:contacts/active])] @@ -100,7 +100,10 @@ _ _] (let [props {:on-press (fn [] (let [address (if accounts (:address (first accounts)) address)] - (when-not ens (rf/dispatch [:wallet/select-send-address address])))) + (when-not ens + (rf/dispatch [:wallet/select-send-address + {:address address + :stack-id :wallet-select-address}])))) :active-state? false}] (cond (= type types/saved-address) @@ -172,7 +175,9 @@ :type :primary :disabled? (not valid-ens-or-address?) :container-style style/button - :on-press #(js/alert "Not implemented yet")} + :on-press #(rf/dispatch [:wallet/select-send-address + {:address @input-value + :stack-id :wallet-select-address}])} (i18n/label :t/continue)])] [:<> [quo/tabs diff --git a/src/status_im2/contexts/wallet/send/select_asset/view.cljs b/src/status_im2/contexts/wallet/send/select_asset/view.cljs index 1a76e4f7ff39..fe48dcede3ca 100644 --- a/src/status_im2/contexts/wallet/send/select_asset/view.cljs +++ b/src/status_im2/contexts/wallet/send/select_asset/view.cljs @@ -18,9 +18,9 @@ [] (fn [token _ _ _] (let [on-press - #(if (= (:symbol token) "ETH") - (rf/dispatch [:wallet/send-select-token token :wallet-select-asset]) - (js/alert "Only ETH transfers are allowed.")) + #(rf/dispatch [:wallet/send-select-token + {:token token + :stack-id :wallet-select-asset}]) total-balance-formatted (.toFixed (:total-balance token) 2) balance-fiat-formatted (.toFixed (:total-balance-fiat token) 2) currency-symbol "$"] diff --git a/src/status_im2/subs/wallet/wallet.cljs b/src/status_im2/subs/wallet/wallet.cljs index 8eddc46ab310..bf605df2de38 100644 --- a/src/status_im2/subs/wallet/wallet.cljs +++ b/src/status_im2/subs/wallet/wallet.cljs @@ -9,11 +9,41 @@ :<- [:wallet] :-> :ui) +(rf/reg-sub + :wallet/wallet-send + :<- [:wallet/ui] + :-> :send) + (rf/reg-sub :wallet/tokens-loading? :<- [:wallet/ui] :-> :tokens-loading?) +(rf/reg-sub + :wallet/wallet-send-to-address + :<- [:wallet/wallet-send] + :-> :to-address) + +(rf/reg-sub + :wallet/wallet-send-route + :<- [:wallet/wallet-send] + :-> :route) + +(rf/reg-sub + :wallet/wallet-send-token + :<- [:wallet/wallet-send] + :-> :token) + +(rf/reg-sub + :wallet/wallet-send-amount + :<- [:wallet/wallet-send] + :-> :amount) + +(rf/reg-sub + :wallet/wallet-send-loading-suggested-routes? + :<- [:wallet/wallet-send] + :-> :loading-suggested-routes?) + (rf/reg-sub :wallet/watch-address-activity-state :<- [:wallet/ui] @@ -48,7 +78,7 @@ :<- [:wallet/balances] :<- [:wallet/tokens-loading?] (fn [[accounts balances tokens-loading?]] - (mapv (fn [{:keys [color address] :as account}] + (mapv (fn [{:keys [color address type] :as account}] (assoc account :customization-color color :type (if (= type :watch) :watch-only :empty) diff --git a/src/utils/money.cljs b/src/utils/money.cljs index e70bb4eb1450..b874c9f64d92 100644 --- a/src/utils/money.cljs +++ b/src/utils/money.cljs @@ -246,3 +246,7 @@ (schema/=> format-amount [:=> [:cat [:maybe :int]] [:maybe :string]]) + +(defn amount-in-hex + [amount token-decimal] + (to-hex (mul (bignumber amount) (from-decimal token-decimal))))