mirror of
https://github.com/status-im/status-react.git
synced 2025-02-08 17:15:52 +00:00
fix: reintroduce changes for sending erc20 token and collectibles (#18679)
Signed-off-by: Brian Sztamfater <brian@status.im>
This commit is contained in:
parent
a95f2a0f52
commit
e54932057d
@ -3,10 +3,12 @@
|
|||||||
[camel-snake-kebab.core :as csk]
|
[camel-snake-kebab.core :as csk]
|
||||||
[camel-snake-kebab.extras :as cske]
|
[camel-snake-kebab.extras :as cske]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
|
[native-module.core :as native-module]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
[status-im.contexts.wallet.common.utils :as utils]
|
[status-im.contexts.wallet.common.utils :as utils]
|
||||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
|
[utils.address :as address]
|
||||||
[utils.money :as money]
|
[utils.money :as money]
|
||||||
[utils.number]
|
[utils.number]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
@ -79,7 +81,9 @@
|
|||||||
|
|
||||||
(rf/reg-event-fx :wallet/send-select-token
|
(rf/reg-event-fx :wallet/send-select-token
|
||||||
(fn [{:keys [db]} [{:keys [token stack-id]}]]
|
(fn [{:keys [db]} [{:keys [token stack-id]}]]
|
||||||
{:db (assoc-in db [:wallet :ui :send :token] token)
|
{:db (-> db
|
||||||
|
(update-in [:wallet :ui :send] dissoc :collectible)
|
||||||
|
(assoc-in [:wallet :ui :send :token] token))
|
||||||
:fx [[:dispatch-later
|
:fx [[:dispatch-later
|
||||||
{:ms 1
|
{:ms 1
|
||||||
:dispatch [:navigate-to-within-stack [:wallet-send-input-amount stack-id]]}]]}))
|
:dispatch [:navigate-to-within-stack [:wallet-send-input-amount stack-id]]}]]}))
|
||||||
@ -92,6 +96,15 @@
|
|||||||
(fn [{:keys [db]}]
|
(fn [{:keys [db]}]
|
||||||
{:db (assoc-in db [:wallet :ui :send :token] nil)}))
|
{:db (assoc-in db [:wallet :ui :send :token] nil)}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx :wallet/send-select-collectible
|
||||||
|
(fn [{:keys [db]} [{:keys [collectible stack-id]}]]
|
||||||
|
{:db (-> db
|
||||||
|
(update-in [:wallet :ui :send] dissoc :token)
|
||||||
|
(assoc-in [:wallet :ui :send :collectible] collectible)
|
||||||
|
(assoc-in [:wallet :ui :send :amount] 1))
|
||||||
|
:fx [[:dispatch [:wallet/get-suggested-routes 1]]
|
||||||
|
[:navigate-to-within-stack [:wallet-transaction-confirmation stack-id]]]}))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/send-select-amount
|
(rf/reg-event-fx :wallet/send-select-amount
|
||||||
(fn [{:keys [db]} [{:keys [amount stack-id]}]]
|
(fn [{:keys [db]} [{:keys [amount stack-id]}]]
|
||||||
{:db (assoc-in db [:wallet :ui :send :amount] amount)
|
{:db (assoc-in db [:wallet :ui :send :amount] amount)
|
||||||
@ -101,19 +114,25 @@
|
|||||||
(fn [{:keys [db now]} [amount]]
|
(fn [{:keys [db now]} [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])
|
||||||
account-address (get-in db [:wallet :ui :send :send-account-address])
|
collectible (get-in db [:wallet :ui :send :collectible])
|
||||||
selected-networks (get-in db [:wallet :ui :send :selected-networks])
|
to-address (get-in db [:wallet :ui :send :to-address])
|
||||||
to-address (or account-address (get-in db [:wallet :ui :send :to-address]))
|
token-decimal (when token (:decimals token))
|
||||||
token-decimal (:decimals token)
|
token-id (if token
|
||||||
token-id (:symbol token)
|
(:symbol token)
|
||||||
network-preferences selected-networks
|
(str (get-in collectible [:id :contract-id :address])
|
||||||
|
":"
|
||||||
|
(get-in collectible [:id :token-id])))
|
||||||
|
network-preferences (if token [] [(get-in collectible [:id :contract-id :chain-id])])
|
||||||
gas-rates constants/gas-rate-medium
|
gas-rates constants/gas-rate-medium
|
||||||
amount-in (send-utils/amount-in-hex amount token-decimal)
|
amount-in (send-utils/amount-in-hex amount (if token token-decimal 0))
|
||||||
from-address wallet-address
|
from-address wallet-address
|
||||||
disabled-from-chain-ids []
|
disabled-from-chain-ids []
|
||||||
disabled-to-chain-ids []
|
disabled-to-chain-ids []
|
||||||
from-locked-amount {}
|
from-locked-amount {}
|
||||||
request-params [constants/send-type-transfer
|
transaction-type (if token
|
||||||
|
constants/send-type-transfer
|
||||||
|
constants/send-type-erc-721-transfer)
|
||||||
|
request-params [transaction-type
|
||||||
from-address
|
from-address
|
||||||
to-address
|
to-address
|
||||||
amount-in
|
amount-in
|
||||||
@ -157,21 +176,46 @@
|
|||||||
{:fx [[:dispatch [:dismiss-modal :wallet-transaction-progress]]]}))
|
{:fx [[:dispatch [:dismiss-modal :wallet-transaction-progress]]]}))
|
||||||
|
|
||||||
(defn- transaction-bridge
|
(defn- transaction-bridge
|
||||||
[{:keys [from-address to-address route]}]
|
[{:keys [from-address from-chain-id to-address token-id token-address route data eth-transfer?]}]
|
||||||
(let [{:keys [from bridge-name amount-out gas-amount gas-fees]} route
|
(let [{:keys [bridge-name amount-out gas-amount
|
||||||
{:keys [gas-price max-fee-per-gas-medium max-priority-fee-per-gas]} gas-fees]
|
gas-fees]} route
|
||||||
[{:BridgeName bridge-name
|
eip-1559-enabled? (:eip-1559-enabled gas-fees)
|
||||||
:ChainID (:chain-id from)
|
{:keys [gas-price max-fee-per-gas-medium
|
||||||
:TransferTx {:From from-address
|
max-priority-fee-per-gas]} gas-fees
|
||||||
:To to-address
|
transfer-tx (cond-> {:From from-address
|
||||||
|
:To (or token-address to-address)
|
||||||
:Gas (money/to-hex gas-amount)
|
:Gas (money/to-hex gas-amount)
|
||||||
:GasPrice (money/to-hex (money/->wei :gwei gas-price))
|
:Value (when eth-transfer? amount-out)
|
||||||
:Value amount-out
|
|
||||||
:Nonce nil
|
:Nonce nil
|
||||||
:MaxFeePerGas (money/to-hex (money/->wei :gwei max-fee-per-gas-medium))
|
|
||||||
:MaxPriorityFeePerGas (money/to-hex (money/->wei :gwei max-priority-fee-per-gas))
|
|
||||||
:Input ""
|
:Input ""
|
||||||
:Data "0x"}}]))
|
:Data (or data "0x")}
|
||||||
|
eip-1559-enabled? (assoc :TxType "0x02"
|
||||||
|
:MaxFeePerGas
|
||||||
|
(money/to-hex
|
||||||
|
(money/->wei
|
||||||
|
:gwei
|
||||||
|
max-fee-per-gas-medium))
|
||||||
|
:MaxPriorityFeePerGas
|
||||||
|
(money/to-hex
|
||||||
|
(money/->wei
|
||||||
|
:gwei
|
||||||
|
max-priority-fee-per-gas)))
|
||||||
|
(not eip-1559-enabled?) (assoc :TxType "0x00"
|
||||||
|
:GasPrice (money/to-hex
|
||||||
|
(money/->wei
|
||||||
|
:gwei
|
||||||
|
gas-price))))]
|
||||||
|
[(cond-> {:BridgeName bridge-name
|
||||||
|
:ChainID from-chain-id}
|
||||||
|
|
||||||
|
(= bridge-name constants/bridge-name-erc-721-transfer)
|
||||||
|
(assoc :ERC721TransferTx
|
||||||
|
(assoc transfer-tx
|
||||||
|
:Recipient to-address
|
||||||
|
:TokenID token-id))
|
||||||
|
|
||||||
|
(= bridge-name constants/bridge-name-transfer)
|
||||||
|
(assoc :TransferTx transfer-tx))]))
|
||||||
|
|
||||||
(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]
|
||||||
@ -187,23 +231,48 @@
|
|||||||
(fn [{:keys [db]} [sha3-pwd]]
|
(fn [{:keys [db]} [sha3-pwd]]
|
||||||
(let [route (get-in db [:wallet :ui :send :route])
|
(let [route (get-in db [:wallet :ui :send :route])
|
||||||
from-address (get-in db [:wallet :current-viewing-account-address])
|
from-address (get-in db [:wallet :current-viewing-account-address])
|
||||||
to-address (get-in db [:wallet :ui :send :to-address])
|
|
||||||
token (get-in db [:wallet :ui :send :token])
|
token (get-in db [:wallet :ui :send :token])
|
||||||
token-id (:symbol token)
|
collectible (get-in db [:wallet :ui :send :collectible])
|
||||||
request-params [(multi-transaction-command {:from-address from-address
|
from-chain-id (get-in route [:from :chain-id])
|
||||||
|
token-id (if token
|
||||||
|
(:symbol token)
|
||||||
|
(get-in collectible [:id :token-id]))
|
||||||
|
erc20-transfer? (and token (not= token-id "ETH"))
|
||||||
|
eth-transfer? (and token (not erc20-transfer?))
|
||||||
|
token-address (cond collectible
|
||||||
|
(get-in collectible
|
||||||
|
[:id :contract-id :address])
|
||||||
|
erc20-transfer?
|
||||||
|
(get-in token [:balances-per-chain from-chain-id :address]))
|
||||||
|
to-address (get-in db [:wallet :ui :send :to-address])
|
||||||
|
data (when erc20-transfer?
|
||||||
|
(native-module/encode-transfer (address/normalized-hex to-address)
|
||||||
|
(:amount-out route)))
|
||||||
|
request-params [(multi-transaction-command
|
||||||
|
{: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 (:amount-out route)})
|
:amount-out (if eth-transfer? (:amount-out route) "0x0")})
|
||||||
(transaction-bridge {:to-address to-address
|
(transaction-bridge {:to-address to-address
|
||||||
:from-address from-address
|
:from-address from-address
|
||||||
:route route})
|
: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
|
||||||
:on-success (fn [result]
|
:on-success (fn [result]
|
||||||
(rf/dispatch [:hide-bottom-sheet])
|
(rf/dispatch [:hide-bottom-sheet])
|
||||||
(rf/dispatch [:wallet/add-authorized-transaction result]))
|
(rf/dispatch [:wallet/add-authorized-transaction result])
|
||||||
|
(rf/dispatch [:wallet/clean-scanned-address])
|
||||||
|
(rf/dispatch [:wallet/clean-local-suggestions])
|
||||||
|
(rf/dispatch [:wallet/clean-send-address])
|
||||||
|
(rf/dispatch [:wallet/select-address-tab nil]))
|
||||||
:on-error (fn [error]
|
:on-error (fn [error]
|
||||||
(log/error "failed to send transaction"
|
(log/error "failed to send transaction"
|
||||||
{:event :wallet/send-transaction
|
{:event :wallet/send-transaction
|
||||||
|
@ -14,16 +14,18 @@
|
|||||||
{:margin-right 4})
|
{:margin-right 4})
|
||||||
|
|
||||||
(defn details-container
|
(defn details-container
|
||||||
[route? theme]
|
[{:keys [loading-suggested-routes? route-loaded? theme]}]
|
||||||
{:flex-direction :row
|
{:flex-direction :row
|
||||||
:justify-content (if route? :space-between :center)
|
:justify-content (if route-loaded? :space-between :center)
|
||||||
:height 52
|
:height (when (or loading-suggested-routes? route-loaded?) 52)
|
||||||
:padding-horizontal 12
|
:padding-horizontal 12
|
||||||
:padding-top 7
|
:padding-top 7
|
||||||
:padding-bottom 8
|
:padding-bottom 8
|
||||||
:border-radius 16
|
:border-radius 16
|
||||||
:border-width 1
|
:border-width 1
|
||||||
:border-color (colors/theme-colors colors/neutral-10 colors/neutral-90 theme)})
|
:border-color (if (or loading-suggested-routes? route-loaded?)
|
||||||
|
(colors/theme-colors colors/neutral-10 colors/neutral-90 theme)
|
||||||
|
:transparent)})
|
||||||
|
|
||||||
(def details-title-container
|
(def details-title-container
|
||||||
{:padding-horizontal 20
|
{:padding-horizontal 20
|
||||||
|
@ -74,9 +74,10 @@
|
|||||||
:account-props account-props}]])
|
:account-props account-props}]])
|
||||||
|
|
||||||
(defn- transaction-details
|
(defn- transaction-details
|
||||||
[{:keys [estimated-time-min max-fees token amount to-address route theme]}]
|
[{:keys [estimated-time-min max-fees token-symbol amount to-address route theme]}]
|
||||||
(let [currency-symbol (rf/sub [:profile/currency-symbol])
|
(let [currency-symbol (rf/sub [:profile/currency-symbol])
|
||||||
route-loaded? (some? route)]
|
route-loaded? (some? route)
|
||||||
|
loading-suggested-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])]
|
||||||
[rn/view
|
[rn/view
|
||||||
{:style style/details-title-container}
|
{:style style/details-title-container}
|
||||||
[quo/text
|
[quo/text
|
||||||
@ -86,8 +87,14 @@
|
|||||||
:accessibility-label :summary-from-label}
|
:accessibility-label :summary-from-label}
|
||||||
(i18n/label :t/details)]
|
(i18n/label :t/details)]
|
||||||
[rn/view
|
[rn/view
|
||||||
{:style (style/details-container route-loaded? theme)}
|
{:style (style/details-container
|
||||||
(if route-loaded?
|
{:loading-suggested-routes? loading-suggested-routes?
|
||||||
|
:route-loaded? route-loaded?
|
||||||
|
:theme theme})}
|
||||||
|
(cond
|
||||||
|
loading-suggested-routes?
|
||||||
|
[rn/activity-indicator {:style {:align-self :center}}]
|
||||||
|
route-loaded?
|
||||||
[:<>
|
[:<>
|
||||||
[quo/data-item
|
[quo/data-item
|
||||||
{:container-style style/detail-item
|
{:container-style style/detail-item
|
||||||
@ -123,8 +130,10 @@
|
|||||||
:status :default
|
:status :default
|
||||||
:size :small
|
:size :small
|
||||||
:title (i18n/label :t/user-gets {:name (utils/get-shortened-address to-address)})
|
:title (i18n/label :t/user-gets {:name (utils/get-shortened-address to-address)})
|
||||||
:subtitle (str amount " " (:symbol token))}]]
|
:subtitle (str amount " " token-symbol)}]]
|
||||||
[rn/activity-indicator {:style {:align-self :center}}])]]))
|
:else
|
||||||
|
[quo/text {:style {:align-self :center}}
|
||||||
|
(i18n/label :t/no-routes-found-confirmation)])]]))
|
||||||
|
|
||||||
(defn- view-internal
|
(defn- view-internal
|
||||||
[_]
|
[_]
|
||||||
@ -140,7 +149,8 @@
|
|||||||
collectible-data (:collectible-data collectible)
|
collectible-data (:collectible-data collectible)
|
||||||
collectible-id (get-in collectible [:id :token-id])
|
collectible-id (get-in collectible [:id :token-id])
|
||||||
token-symbol (if collectible
|
token-symbol (if collectible
|
||||||
(first (remove string/blank?
|
(first (remove
|
||||||
|
string/blank?
|
||||||
[(:name collectible-data)
|
[(:name collectible-data)
|
||||||
(str (:name collection-data) " #" collectible-id)]))
|
(str (:name collection-data) " #" collectible-id)]))
|
||||||
(:symbol token))
|
(:symbol token))
|
||||||
@ -157,7 +167,8 @@
|
|||||||
:emoji (:emoji account)
|
:emoji (:emoji account)
|
||||||
:type :default
|
:type :default
|
||||||
:name (:name account)
|
:name (:name account)
|
||||||
:address (utils/get-shortened-address (:address account))}
|
:address (utils/get-shortened-address (:address
|
||||||
|
account))}
|
||||||
user-props {:full-name to-address
|
user-props {:full-name to-address
|
||||||
:address (utils/get-shortened-address to-address)}]
|
:address (utils/get-shortened-address to-address)}]
|
||||||
[rn/view {:style {:flex 1}}
|
[rn/view {:style {:flex 1}}
|
||||||
@ -173,17 +184,17 @@
|
|||||||
:on-press #(js/alert
|
:on-press #(js/alert
|
||||||
"to be implemented")
|
"to be implemented")
|
||||||
:accessibility-label :advanced-options}]}]
|
:accessibility-label :advanced-options}]}]
|
||||||
:footer (if route
|
:footer (when route
|
||||||
[standard-auth/slide-button
|
[standard-auth/slide-button
|
||||||
{:size :size-48
|
{:size :size-48
|
||||||
:track-text (i18n/label :t/slide-to-send)
|
:track-text (i18n/label :t/slide-to-send)
|
||||||
:container-style {:z-index 2}
|
:container-style {:z-index 2}
|
||||||
:customization-color account-color
|
:customization-color account-color
|
||||||
:on-auth-success #(rf/dispatch [:wallet/send-transaction
|
:on-auth-success #(rf/dispatch
|
||||||
|
[:wallet/send-transaction
|
||||||
(security/safe-unmask-data
|
(security/safe-unmask-data
|
||||||
%)])
|
%)])
|
||||||
:auth-button-label (i18n/label :t/confirm)}]
|
:auth-button-label (i18n/label :t/confirm)}])
|
||||||
[rn/activity-indicator])
|
|
||||||
:gradient-cover? true
|
:gradient-cover? true
|
||||||
:customization-color (:color account)}
|
:customization-color (:color account)}
|
||||||
[rn/view
|
[rn/view
|
||||||
@ -213,7 +224,7 @@
|
|||||||
[transaction-details
|
[transaction-details
|
||||||
{:estimated-time-min estimated-time-min
|
{:estimated-time-min estimated-time-min
|
||||||
:max-fees max-fees
|
:max-fees max-fees
|
||||||
:token token
|
:token-symbol token-symbol
|
||||||
:amount amount
|
:amount amount
|
||||||
:to-address to-address
|
:to-address to-address
|
||||||
:theme theme
|
:theme theme
|
||||||
|
@ -2480,5 +2480,6 @@
|
|||||||
"preferred-by-receiver": "Preferred by receiver",
|
"preferred-by-receiver": "Preferred by receiver",
|
||||||
"not-preferred-by-receiver": "Not preferred by receiver",
|
"not-preferred-by-receiver": "Not preferred by receiver",
|
||||||
"apply-changes": "Apply changes",
|
"apply-changes": "Apply changes",
|
||||||
"receiver-networks-warning": "Changing these settings may result in sending tokens to networks the recipient doesn't use"
|
"receiver-networks-warning": "Changing these settings may result in sending tokens to networks the recipient doesn't use",
|
||||||
|
"no-routes-found-confirmation": "No routes found. Token type may not be supported or you may don't have enough ETH to cover gas."
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user