Skip to content

Commit

Permalink
feat: update transaction confirmation page to support bridging transa…
Browse files Browse the repository at this point in the history
…ctions (#18887)
  • Loading branch information
briansztamfater authored Mar 1, 2024
1 parent 0e9847f commit 7d55c98
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 143 deletions.
4 changes: 2 additions & 2 deletions src/quo/components/wallet/summary_info/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
(defn networks
[values theme]
(let [{:keys [ethereum optimism arbitrum]} values
show-optimism? (pos? optimism)
show-arbitrum? (pos? arbitrum)]
show-optimism? (and optimism (pos? (:amount optimism)))
show-arbitrum? (and arbitrum (pos? (:amount arbitrum)))]
[rn/view
{:style style/networks-container
:accessibility-label :networks}
Expand Down
1 change: 1 addition & 0 deletions src/quo/foundations/resources.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
(def ^:private networks
{:arbitrum (js/require "../resources/images/networks/Arbitrum.png")
:ethereum (js/require "../resources/images/networks/Ethereum.png")
:mainnet (js/require "../resources/images/networks/Ethereum.png")
:gnosis (js/require "../resources/images/networks/Gnosis.png")
:hermez (js/require "../resources/images/networks/Hermez.png")
:optimism (js/require "../resources/images/networks/Optimism.png")
Expand Down
6 changes: 5 additions & 1 deletion src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@
(def ^:const optimism-short-name "opt")
(def ^:const arbitrum-short-name "arb1")

(def ^:const mainnet-network-name :ethereum)
(def ^:const mainnet-abbreviated-name "Eth.")
(def ^:const optimism-abbreviated-name "Opt.")
(def ^:const arbitrum-abbreviated-name "Arb1.")

(def ^:const mainnet-network-name :mainnet)
(def ^:const optimism-network-name :optimism)
(def ^:const arbitrum-network-name :arbitrum)

Expand Down
9 changes: 5 additions & 4 deletions src/status_im/contexts/wallet/account/bridge_send/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
[]
[rn/view {:style style/bridge-send-wrapper}
[input-amount/view
{:button-one-label (i18n/label :t/confirm-bridge)
:button-one-props {:icon-left :i/bridge}
:on-navigate-back (fn []
(rf/dispatch [:navigate-back-within-stack :wallet-bridge-send]))}]])
{:current-screen-id :wallet-bridge-send
:button-one-label (i18n/label :t/confirm-bridge)
:button-one-props {:icon-left :i/bridge}
:on-navigate-back (fn []
(rf/dispatch [:navigate-back-within-stack :wallet-bridge-send]))}]])

(def view (quo.theme/with-theme view-internal))
4 changes: 4 additions & 0 deletions src/status_im/contexts/wallet/common/utils/send.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
(let [gas-price (money/bignumber (get gas-fees :gas-price))
total-gas-fee (money/mul gas-amount gas-price)]
(money/with-precision (money/div total-gas-fee billion) 10)))))

(defn calculate-full-route-gas-fee
[route]
(reduce money/add (map calculate-gas-fee route)))
18 changes: 13 additions & 5 deletions src/status_im/contexts/wallet/send/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
(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 csk/->kebab-case suggested-routes)
chosen-route (->> suggested-routes-data
:best
first)]
chosen-route (:best suggested-routes-data)]
{:db (-> db
(assoc-in [:wallet :ui :send :suggested-routes] suggested-routes-data)
(assoc-in [:wallet :ui :send :route] chosen-route)
Expand Down Expand Up @@ -99,7 +97,17 @@

(rf/reg-event-fx :wallet/clean-selected-token
(fn [{:keys [db]}]
{:db (assoc-in db [:wallet :ui :send :token] nil)}))
{:db (update-in db [:wallet :ui :send] dissoc :token :type)}))

(rf/reg-event-fx :wallet/clean-selected-collectible
(fn [{:keys [db]}]
(let [type (get-in db [:wallet :ui :send :type])]
{:db (update-in db
[:wallet :ui :send]
dissoc
:collectible
:amount
(when (= type :collecible) :type))})))

(rf/reg-event-fx :wallet/send-select-collectible
(fn [{:keys [db]} [{:keys [collectible stack-id]}]]
Expand Down Expand Up @@ -244,7 +252,7 @@

(rf/reg-event-fx :wallet/send-transaction
(fn [{:keys [db]} [sha3-pwd]]
(let [route (get-in db [:wallet :ui :send :route])
(let [route (first (get-in db [:wallet :ui :send :route]))
from-address (get-in db [:wallet :current-viewing-account-address])
token (get-in db [:wallet :ui :send :token])
collectible (get-in db [:wallet :ui :send :collectible])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
:total-balance 100
:market-values-per-currency {:usd {:price 10}}}
:wallet/wallet-send-loading-suggested-routes? false
:wallet/wallet-send-route {:from {:chainid 1
:native-currency-symbol "ETH"}
:to {:chain-id 1
:native-currency-symbol "ETH"}
:gas-amount "23487"
:gas-fees {:base-fee "32.325296406"
:max-priority-fee-per-gas "0.011000001"
:eip1559-enabled true}}
:wallet/wallet-send-route [{:from {:chainid 1
:native-currency-symbol "ETH"}
:to {:chain-id 1
:native-currency-symbol "ETH"}
:gas-amount "23487"
:gas-fees {:base-fee "32.325296406"
:max-priority-fee-per-gas "0.011000001"
:eip1559-enabled true}}]
:wallet/wallet-send-suggested-routes {:candidates []}
:wallet/wallet-send-selected-networks []
:navigation/current-screen-id :wallet-send-input-amount
Expand Down
13 changes: 8 additions & 5 deletions src/status_im/contexts/wallet/send/input_amount/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
on-navigate-back :on-navigate-back
button-one-label :button-one-label
button-one-props :button-one-props
current-screen-id :current-screen-id
initial-crypto-currency? :initial-crypto-currency?
:or {initial-crypto-currency? true}}]
(let [_ (rn/dismiss-keyboard!)
Expand Down Expand Up @@ -172,11 +173,11 @@
(reagent/flush))))
on-navigate-back on-navigate-back
fetch-routes (fn [input-num-value current-limit-amount]
(let [current-screen-id (rf/sub [:navigation/current-screen-id])]
(let [nav-current-screen-id (rf/sub [:navigation/current-screen-id])]
; this check is to prevent effect being triggered when screen is
; loaded but not being shown to the user (deep in the navigation
; stack) and avoid undesired behaviors
(when (= current-screen-id :wallet-send-input-amount)
(when (= nav-current-screen-id current-screen-id)
(if-not (or (empty? @input-value)
(<= input-num-value 0)
(> input-num-value current-limit-amount))
Expand All @@ -187,7 +188,7 @@
handle-on-confirm (fn []
(rf/dispatch [:wallet/send-select-amount
{:amount @input-value
:stack-id :wallet-send-input-amount}]))
:stack-id current-screen-id}]))
selection-change (fn [selection]
;; `reagent/flush` is needed to properly propagate the
;; input cursor state. Since this is a controlled
Expand Down Expand Up @@ -218,6 +219,7 @@
: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))
Expand All @@ -226,7 +228,8 @@
(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-gas-fee route))
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))
Expand Down Expand Up @@ -280,7 +283,7 @@
:token token
:input-value @input-value
:fetch-routes #(fetch-routes % current-limit)}]
(when (or loading-routes? route)
(when (or loading-routes? (seq route))
[estimated-fees
{:loading-suggested-routes? loading-routes?
:fees fee-formatted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
(rf/dispatch [:wallet/clean-scanned-address])
(rf/dispatch [:wallet/clean-local-suggestions])
(rf/dispatch [:wallet/clean-selected-token])
(rf/dispatch [:wallet/clean-selected-collectible])
(rf/dispatch [:wallet/clean-send-address])
(rf/dispatch [:wallet/select-address-tab nil])
(rf/dispatch [:navigate-back]))
Expand Down
10 changes: 6 additions & 4 deletions src/status_im/contexts/wallet/send/send_amount/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
(defn- view-internal
[]
[input-amount/view
{:button-one-label (i18n/label :t/confirm)
:on-navigate-back (fn []
(rf/dispatch [:wallet/clean-selected-token])
(rf/dispatch [:navigate-back-within-stack :wallet-send-input-amount]))}])
{:current-screen-id :wallet-send-input-amount
:button-one-label (i18n/label :t/confirm)
:on-navigate-back (fn []
(rf/dispatch [:wallet/clean-selected-token])
(rf/dispatch [:wallet/clean-selected-collectible])
(rf/dispatch [:navigate-back-within-stack :wallet-send-input-amount]))}])

(def view (quo.theme/with-theme view-internal))
Loading

0 comments on commit 7d55c98

Please sign in to comment.