feat: make bridging transactions work after sliding to confirm the transaction (#18986)

This commit is contained in:
Brian Sztamfater 2024-03-20 10:07:02 -03:00 committed by GitHub
parent 40e6c44b99
commit 463e8a5eec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 157 additions and 97 deletions

View File

@ -30,8 +30,12 @@
(defn networks (defn networks
[values theme] [values theme]
(let [{:keys [ethereum optimism arbitrum]} values (let [{:keys [ethereum optimism arbitrum]} values
show-optimism? (and optimism (pos? (:amount optimism))) show-optimism? (and optimism
show-arbitrum? (and arbitrum (pos? (:amount arbitrum)))] (or (pos? (:amount optimism))
(= (:amount optimism) "<0.01")))
show-arbitrum? (and arbitrum
(or (pos? (:amount arbitrum))
(= (:amount arbitrum) "<0.01")))]
[rn/view [rn/view
{:style style/networks-container {:style style/networks-container
:accessibility-label :networks} :accessibility-label :networks}

View File

@ -478,6 +478,7 @@
(def ^:const bridge-name-transfer "Transfer") (def ^:const bridge-name-transfer "Transfer")
(def ^:const bridge-name-erc-721-transfer "ERC721Transfer") (def ^:const bridge-name-erc-721-transfer "ERC721Transfer")
(def ^:const bridge-name-hop "Hop")
(def ^:const alert-banner-height 40) (def ^:const alert-banner-height 40)

View File

@ -31,7 +31,7 @@
:fiat-value fiat-formatted :fiat-value fiat-formatted
:on-press #(rf/dispatch [:wallet/select-bridge-network :on-press #(rf/dispatch [:wallet/select-bridge-network
{:network-chain-id chain-id {:network-chain-id chain-id
:stack-id :wallet-bridge}])}]))) :stack-id :screen/wallet.bridge-to}])}])))
(defn- view-internal (defn- view-internal
[] []

View File

@ -7,7 +7,6 @@
[status-im.contexts.wallet.account.tabs.view :as tabs] [status-im.contexts.wallet.account.tabs.view :as tabs]
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher] [status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
[status-im.contexts.wallet.common.temp :as temp] [status-im.contexts.wallet.common.temp :as temp]
[status-im.feature-flags :as ff]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -55,8 +54,7 @@
:receive-action #(rf/dispatch [:open-modal :screen/wallet.share-address {:status :receive}]) :receive-action #(rf/dispatch [:open-modal :screen/wallet.share-address {:status :receive}])
:buy-action #(rf/dispatch [:show-bottom-sheet :buy-action #(rf/dispatch [:show-bottom-sheet
{:content buy-drawer}]) {:content buy-drawer}])
:bridge-action #(ff/alert ::ff/wallet.bridge-token :bridge-action #(rf/dispatch [:wallet/start-bridge])}])
(fn [] (rf/dispatch [:wallet/start-bridge])))}])
[quo/tabs [quo/tabs
{:style style/tabs {:style style/tabs
:size 32 :size 32

View File

@ -244,7 +244,7 @@
(rf/reg-event-fx :wallet/start-bridge (rf/reg-event-fx :wallet/start-bridge
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:db (assoc-in db [:wallet :ui :send :type] :bridge) {:db (assoc-in db [:wallet :ui :send :tx-type] :bridge)
:fx [[:dispatch [:open-modal :screen/wallet.bridge]]]})) :fx [[:dispatch [:open-modal :screen/wallet.bridge]]]}))
(rf/reg-event-fx :wallet/select-bridge-network (rf/reg-event-fx :wallet/select-bridge-network

View File

@ -90,24 +90,24 @@
(rf/reg-event-fx :wallet/clean-selected-token (rf/reg-event-fx :wallet/clean-selected-token
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:db (assoc-in db [:wallet :ui :send :token] nil)})) {:db (update-in db [:wallet :ui :send] dissoc :token :tx-type)}))
(rf/reg-event-fx :wallet/clean-selected-collectible (rf/reg-event-fx :wallet/clean-selected-collectible
(fn [{:keys [db]}] (fn [{:keys [db]}]
(let [type (get-in db [:wallet :ui :send :type])] (let [transaction-type (get-in db [:wallet :ui :send :tx-type])]
{:db (update-in db {:db (update-in db
[:wallet :ui :send] [:wallet :ui :send]
dissoc dissoc
:collectible :collectible
:amount :amount
(when (= type :collecible) :type))}))) (when (= transaction-type :collecible) :tx-type))})))
(rf/reg-event-fx :wallet/send-select-collectible (rf/reg-event-fx :wallet/send-select-collectible
(fn [{:keys [db]} [{:keys [collectible stack-id]}]] (fn [{:keys [db]} [{:keys [collectible stack-id]}]]
{:db (-> db {:db (-> db
(update-in [:wallet :ui :send] dissoc :token) (update-in [:wallet :ui :send] dissoc :token)
(assoc-in [:wallet :ui :send :collectible] collectible) (assoc-in [:wallet :ui :send :collectible] collectible)
(assoc-in [:wallet :ui :send :type] :collectible) (assoc-in [:wallet :ui :send :tx-type] :collectible)
(assoc-in [:wallet :ui :send :amount] 1)) (assoc-in [:wallet :ui :send :amount] 1))
:fx [[:dispatch [:wallet/get-suggested-routes {:amount 1}]] :fx [[:dispatch [:wallet/get-suggested-routes {:amount 1}]]
[:navigate-to-within-stack [:screen/wallet.transaction-confirmation stack-id]]]})) [:navigate-to-within-stack [:screen/wallet.transaction-confirmation stack-id]]]}))
@ -121,7 +121,7 @@
(fn [{:keys [db now]} [{:keys [amount]}]] (fn [{:keys [db now]} [{:keys [amount]}]]
(let [wallet-address (get-in db [:wallet :current-viewing-account-address]) (let [wallet-address (get-in db [:wallet :current-viewing-account-address])
token (get-in db [:wallet :ui :send :token]) token (get-in db [:wallet :ui :send :token])
transaction-type (get-in db [:wallet :ui :send :type]) transaction-type (get-in db [:wallet :ui :send :tx-type])
collectible (get-in db [:wallet :ui :send :collectible]) collectible (get-in db [:wallet :ui :send :collectible])
to-address (get-in db [:wallet :ui :send :to-address]) to-address (get-in db [:wallet :ui :send :to-address])
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?]) test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
@ -191,21 +191,21 @@
(fn [_] (fn [_]
{:fx [[:dispatch [:dismiss-modal :screen/wallet.transaction-progress]]]})) {:fx [[:dispatch [:dismiss-modal :screen/wallet.transaction-progress]]]}))
(defn- transaction-bridge (defn- transaction-data
[{:keys [from-address from-chain-id to-address token-id token-address route data eth-transfer?]}] [{:keys [from-address to-address token-address route data eth-transfer?]}]
(let [{:keys [bridge-name amount-out gas-amount (let [{:keys [amount-in gas-amount gas-fees]} route
gas-fees]} route
eip-1559-enabled? (:eip-1559-enabled gas-fees) eip-1559-enabled? (:eip-1559-enabled gas-fees)
{:keys [gas-price max-fee-per-gas-medium {:keys [gas-price max-fee-per-gas-medium
max-priority-fee-per-gas]} gas-fees max-priority-fee-per-gas]} gas-fees]
transfer-tx (cond-> {:From from-address (cond-> {:From from-address
:To (or token-address to-address) :To (or token-address to-address)
:Gas (money/to-hex gas-amount) :Gas (money/to-hex gas-amount)
:Value (when eth-transfer? amount-out) :Value (when eth-transfer? amount-in)
:Nonce nil :Nonce nil
:Input "" :Input ""
:Data (or data "0x")} :Data (or data "0x")}
eip-1559-enabled? (assoc :TxType "0x02" eip-1559-enabled? (assoc
:TxType "0x02"
:MaxFeePerGas :MaxFeePerGas
(money/to-hex (money/to-hex
(money/->wei (money/->wei
@ -217,21 +217,55 @@
:gwei :gwei
max-priority-fee-per-gas))) max-priority-fee-per-gas)))
(not eip-1559-enabled?) (assoc :TxType "0x00" (not eip-1559-enabled?) (assoc :TxType "0x00"
:GasPrice (money/to-hex :GasPrice
(money/to-hex
(money/->wei (money/->wei
:gwei :gwei
gas-price))))] gas-price))))))
[(cond-> {:BridgeName bridge-name
(defn- transaction-path
[{:keys [from-address to-address token-id token-address route data eth-transfer?]}]
(let [{:keys [bridge-name amount-in bonder-fees from
to]} route
tx-data (transaction-data {:from-address from-address
:to-address to-address
:token-address token-address
:route route
:data data
:eth-transfer? eth-transfer?})
to-chain-id (:chain-id to)
from-chain-id (:chain-id from)]
(cond-> {:BridgeName bridge-name
:ChainID from-chain-id} :ChainID from-chain-id}
(= bridge-name constants/bridge-name-erc-721-transfer) (= bridge-name constants/bridge-name-erc-721-transfer)
(assoc :ERC721TransferTx (assoc :ERC721TransferTx
(assoc transfer-tx (assoc tx-data
:Recipient to-address :Recipient to-address
:TokenID token-id)) :TokenID token-id
:ChainID to-chain-id))
(= bridge-name constants/bridge-name-transfer) (= bridge-name constants/bridge-name-transfer)
(assoc :TransferTx transfer-tx))])) (assoc :TransferTx tx-data)
(= bridge-name constants/bridge-name-hop)
(assoc :HopTx
(assoc tx-data
:ChainID to-chain-id
:Symbol token-id
:Recipient to-address
:Amount amount-in
:BonderFee bonder-fees))
(not (or (= bridge-name constants/bridge-name-erc-721-transfer)
(= bridge-name constants/bridge-name-transfer)
(= bridge-name constants/bridge-name-hop)))
(assoc :CbridgeTx
(assoc tx-data
:ChainID to-chain-id
:Symbol token-id
:Recipient to-address
:Amount amount-in)))))
(defn- multi-transaction-command (defn- multi-transaction-command
[{:keys [from-address to-address from-asset to-asset amount-out transfer-type] [{:keys [from-address to-address from-asset to-asset amount-out transfer-type]
@ -245,11 +279,17 @@
(rf/reg-event-fx :wallet/send-transaction (rf/reg-event-fx :wallet/send-transaction
(fn [{:keys [db]} [sha3-pwd]] (fn [{:keys [db]} [sha3-pwd]]
(let [route (first (get-in db [:wallet :ui :send :route])) (let [routes (get-in db [:wallet :ui :send :route])
first-route (first routes)
from-address (get-in db [:wallet :current-viewing-account-address]) from-address (get-in db [:wallet :current-viewing-account-address])
transaction-type (get-in db [:wallet :ui :send :tx-type])
transaction-type-param (case transaction-type
:collectible constants/send-type-erc-721-transfer
:bridge constants/send-type-bridge
constants/send-type-transfer)
token (get-in db [:wallet :ui :send :token]) token (get-in db [:wallet :ui :send :token])
collectible (get-in db [:wallet :ui :send :collectible]) collectible (get-in db [:wallet :ui :send :collectible])
from-chain-id (get-in route [:from :chain-id]) first-route-from-chain-id (get-in first-route [:from :chain-id])
token-id (if token token-id (if token
(:symbol token) (:symbol token)
(get-in collectible [:id :token-id])) (get-in collectible [:id :token-id]))
@ -259,26 +299,33 @@
(get-in collectible (get-in collectible
[:id :contract-id :address]) [:id :contract-id :address])
erc20-transfer? erc20-transfer?
(get-in token [:balances-per-chain from-chain-id :address])) (get-in token [:balances-per-chain first-route-from-chain-id :address]))
to-address (get-in db [:wallet :ui :send :to-address]) to-address (get-in db [:wallet :ui :send :to-address])
data (when erc20-transfer? transaction-paths (mapv (fn [route]
(native-module/encode-transfer (address/normalized-hex to-address) (let [data (when erc20-transfer?
(:amount-out route))) (native-module/encode-transfer
request-params [(multi-transaction-command (address/normalized-hex to-address)
(:amount-in route)))]
(transaction-path {:to-address to-address
:from-address from-address
:route route
:token-address token-address
:token-id (if collectible
(money/to-hex (js/parseInt
token-id))
token-id)
:data data
:eth-transfer? eth-transfer?})))
routes)
request-params
[(multi-transaction-command
{:from-address from-address {:from-address from-address
:to-address to-address :to-address to-address
:from-asset token-id :from-asset token-id
:to-asset token-id :to-asset token-id
:amount-out (if eth-transfer? (:amount-out route) "0x0")}) :amount-out (if eth-transfer? (:amount-out first-route) "0x0")
(transaction-bridge {:to-address to-address :transfer-type transaction-type-param})
:from-address from-address transaction-paths
:route route
:from-chain-id from-chain-id
:token-address token-address
:token-id (when collectible
(money/to-hex (js/parseInt token-id)))
:data data
:eth-transfer? eth-transfer?})
sha3-pwd]] sha3-pwd]]
{:json-rpc/call [{:method "wallet_createMultiTransaction" {:json-rpc/call [{:method "wallet_createMultiTransaction"
:params request-params :params request-params
@ -293,4 +340,8 @@
(log/error "failed to send transaction" (log/error "failed to send transaction"
{:event :wallet/send-transaction {:event :wallet/send-transaction
:error error :error error
:params request-params}))}]}))) :params request-params})
(rf/dispatch [:toasts/upsert
{:id :send-transaction-error
:type :negative
:text (:message error)}]))}]})))

View File

@ -206,6 +206,7 @@
conversion-rate (-> token :market-values-per-currency :usd :price) conversion-rate (-> token :market-values-per-currency :usd :price)
loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?]) loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes]) suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
best-routes (when suggested-routes (or (:best suggested-routes) []))
route (rf/sub [:wallet/wallet-send-route]) route (rf/sub [:wallet/wallet-send-route])
to-address (rf/sub [:wallet/wallet-send-to-address]) to-address (rf/sub [:wallet/wallet-send-to-address])
on-confirm (or default-on-confirm handle-on-confirm) on-confirm (or default-on-confirm handle-on-confirm)
@ -280,7 +281,7 @@
:limit-crypto crypto-limit})}] :limit-crypto crypto-limit})}]
[routes/view [routes/view
{:amount amount-text {:amount amount-text
:routes suggested-routes :routes best-routes
:token token :token token
:input-value @input-value :input-value @input-value
:fetch-routes #(fetch-routes % (current-limit))}] :fetch-routes #(fetch-routes % (current-limit))}]

View File

@ -122,9 +122,8 @@
(let [selected-networks (rf/sub [:wallet/wallet-send-selected-networks]) (let [selected-networks (rf/sub [:wallet/wallet-send-selected-networks])
loading-networks (find-affordable-networks token input-value selected-networks) loading-networks (find-affordable-networks token input-value selected-networks)
loading-suggested-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?]) loading-suggested-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
best-routes (:best routes) data (if loading-suggested-routes? loading-networks routes)]
data (if loading-suggested-routes? loading-networks best-routes)] (if (or (and (not-empty loading-networks) loading-suggested-routes?) (not-empty routes))
(if (or (and (not-empty loading-networks) loading-suggested-routes?) (not-empty best-routes))
[rn/flat-list [rn/flat-list
{:data (if (and (< (count data) 3) (pos? (count data))) {:data (if (and (< (count data) 3) (pos? (count data)))
(concat data [{:status :add}]) (concat data [{:status :add}])
@ -154,7 +153,7 @@
(utils/id->network (get-in item (utils/id->network (get-in item
[:to :chain-id])))}])}] [:to :chain-id])))}])}]
[rn/view {:style style/empty-container} [rn/view {:style style/empty-container}
(when (and (not (nil? best-routes)) (not loading-suggested-routes?)) (when (and (not (nil? routes)) (not loading-suggested-routes?))
[quo/text (i18n/label :t/no-routes-found)])]))) [quo/text (i18n/label :t/no-routes-found)])])))
(def view (quo.theme/with-theme view-internal)) (def view (quo.theme/with-theme view-internal))

View File

@ -153,7 +153,14 @@
(reduce-kv (fn [acc k v] (reduce-kv (fn [acc k v]
(assoc acc k {:amount v :token-symbol token-symbol})) (assoc acc k {:amount v :token-symbol token-symbol}))
{} {}
network-amounts)] network-amounts)
network-values-sanitized (into {}
(map (fn [[k v]]
[k
(if (money/equal-to (v :amount) 0)
(assoc v :amount "<0.01")
v)])
network-values))]
[rn/view [rn/view
{:style {:padding-horizontal 20 {:style {:padding-horizontal 20
:padding-bottom 16}} :padding-bottom 16}}
@ -166,7 +173,7 @@
[quo/summary-info [quo/summary-info
{:type summary-type {:type summary-type
:networks? true :networks? true
:values network-values :values network-values-sanitized
:account-props account-props}]]))) :account-props account-props}]])))
(defn- transaction-details (defn- transaction-details
@ -258,7 +265,7 @@
image-url (when collectible (:image-url collectible-data)) image-url (when collectible (:image-url collectible-data))
amount (:amount send-transaction-data) amount (:amount send-transaction-data)
route (:route send-transaction-data) route (:route send-transaction-data)
transaction-type (:type send-transaction-data) transaction-type (:tx-type send-transaction-data)
estimated-time-min (reduce + (map :estimated-time route)) estimated-time-min (reduce + (map :estimated-time route))
max-fees "-" max-fees "-"
to-address (:to-address send-transaction-data) to-address (:to-address send-transaction-data)

View File

@ -11,7 +11,6 @@
(defonce ^:private feature-flags-config (defonce ^:private feature-flags-config
(reagent/atom (reagent/atom
{::wallet.edit-default-keypair (enabled-in-env? :FLAG_EDIT_DEFAULT_KEYPAIR) {::wallet.edit-default-keypair (enabled-in-env? :FLAG_EDIT_DEFAULT_KEYPAIR)
::wallet.bridge-token (enabled-in-env? :FLAG_BRIDGE_TOKEN_ENABLED)
::wallet.edit-derivation-path (enabled-in-env? :FLAG_EDIT_DERIVATION_PATH) ::wallet.edit-derivation-path (enabled-in-env? :FLAG_EDIT_DERIVATION_PATH)
::wallet.remove-account (enabled-in-env? :FLAG_REMOVE_ACCOUNT_ENABLED) ::wallet.remove-account (enabled-in-env? :FLAG_REMOVE_ACCOUNT_ENABLED)
::wallet.network-filter (enabled-in-env? :FLAG_NETWORK_FILTER_ENABLED) ::wallet.network-filter (enabled-in-env? :FLAG_NETWORK_FILTER_ENABLED)

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.176.9", "version": "v0.176.10",
"commit-sha1": "a3ad05db58b8af20bf6b7ab852f8603212abac4e", "commit-sha1": "f69ee07593e8e35bb029f62de670b5554d71c932",
"src-sha256": "10c05kgihczbams3i8fkfm1mh5m61bnsjh255c22m4awc073rg12" "src-sha256": "1icm7l1lhqdz5zbfvagxb051rw3hdm8zvwcxwaizyd1lhbx4v8h5"
} }