feat: support sending multi collectibles (#20045)
This commit is contained in:
parent
ea58e52dc1
commit
d558c565b0
|
@ -6,7 +6,8 @@
|
|||
[:props
|
||||
[:map {:closed true}
|
||||
[:status {:optional true} [:maybe [:enum :default :error]]]
|
||||
[:on-change-text {:optional true} [:maybe fn?]]
|
||||
[:on-inc-press {:optional true} [:maybe fn?]]
|
||||
[:on-dec-press {:optional true} [:maybe fn?]]
|
||||
[:container-style {:optional true} [:maybe :map]]
|
||||
[:min-value {:optional true} [:maybe :int]]
|
||||
[:max-value {:optional true} [:maybe :int]]
|
||||
|
|
|
@ -506,11 +506,18 @@
|
|||
(def ^:const send-type-stickers-buy 4)
|
||||
(def ^:const send-type-bridge 5)
|
||||
(def ^:const send-type-erc-721-transfer 6)
|
||||
(def ^:const send-type-erc-1155-transfer 7)
|
||||
|
||||
(def ^:const bridge-name-transfer "Transfer")
|
||||
(def ^:const bridge-name-erc-721-transfer "ERC721Transfer")
|
||||
(def ^:const bridge-name-erc-1155-transfer "ERC1155Transfer")
|
||||
(def ^:const bridge-name-hop "Hop")
|
||||
|
||||
(def ^:const wallet-contract-type-uknown 0)
|
||||
(def ^:const wallet-contract-type-erc-20 1)
|
||||
(def ^:const wallet-contract-type-erc-721 2)
|
||||
(def ^:const wallet-contract-type-erc-1155 3)
|
||||
|
||||
(def ^:const alert-banner-height 40)
|
||||
|
||||
(def ^:const status-hostname "status.app")
|
||||
|
|
|
@ -250,7 +250,7 @@
|
|||
{:db (-> db
|
||||
(assoc-in [:wallet :ui :send :token] token)
|
||||
(assoc-in [:wallet :ui :send :to-address] to-address)
|
||||
(assoc-in [:wallet :ui :send :tx-type] :bridge))
|
||||
(assoc-in [:wallet :ui :send :tx-type] :tx/bridge))
|
||||
:fx [[:dispatch
|
||||
[:wallet/wizard-navigate-forward
|
||||
{:current-screen stack-id
|
||||
|
@ -259,7 +259,7 @@
|
|||
|
||||
(rf/reg-event-fx :wallet/start-bridge
|
||||
(fn [{:keys [db]}]
|
||||
{:db (assoc-in db [:wallet :ui :send :tx-type] :bridge)
|
||||
{:db (assoc-in db [:wallet :ui :send :tx-type] :tx/bridge)
|
||||
:fx [[:dispatch [:open-modal :screen/wallet.bridge-select-asset]]]}))
|
||||
|
||||
(rf/reg-event-fx :wallet/select-bridge-network
|
||||
|
|
|
@ -144,7 +144,8 @@
|
|||
{:prefix prefix
|
||||
:testnet-enabled? testnet-enabled?
|
||||
:goerli-enabled? goerli-enabled?})
|
||||
collectible-tx? (= (-> db :wallet :ui :send :tx-type) :collectible)
|
||||
collectible-tx? (send-utils/tx-type-collectible?
|
||||
(-> db :wallet :ui :send :tx-type))
|
||||
collectible (when collectible-tx?
|
||||
(-> db :wallet :ui :send :collectible))
|
||||
one-collectible? (when collectible-tx?
|
||||
|
@ -235,13 +236,19 @@
|
|||
:collectible
|
||||
:token-display-name
|
||||
:amount
|
||||
(when (= transaction-type :collectible) :tx-type))})))
|
||||
(when (send-utils/tx-type-collectible?
|
||||
transaction-type)
|
||||
:tx-type))})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:wallet/set-collectible-to-send
|
||||
(fn [{db :db} [{:keys [collectible current-screen]}]]
|
||||
(let [collection-data (:collection-data collectible)
|
||||
collectible-data (:collectible-data collectible)
|
||||
contract-type (:contract-type collectible)
|
||||
tx-type (if (= contract-type constants/wallet-contract-type-erc-1155)
|
||||
:tx/collectible-erc-1155
|
||||
:tx/collectible-erc-721)
|
||||
collectible-id (get-in collectible [:id :token-id])
|
||||
one-collectible? (= (collectible.utils/collectible-balance collectible) 1)
|
||||
token-display-name (cond
|
||||
|
@ -255,7 +262,7 @@
|
|||
(update-in [:wallet :ui :send] dissoc :token)
|
||||
(assoc-in [:wallet :ui :send :collectible] collectible)
|
||||
(assoc-in [:wallet :ui :send :token-display-name] token-display-name)
|
||||
(assoc-in [:wallet :ui :send :tx-type] :collectible))
|
||||
(assoc-in [:wallet :ui :send :tx-type] tx-type))
|
||||
recipient-set? (-> db :wallet :ui :send :recipient)]
|
||||
{:db (cond-> collectible-tx
|
||||
one-collectible? (assoc-in [:wallet :ui :send :amount] 1))
|
||||
|
@ -314,7 +321,7 @@
|
|||
amount-in (send-utils/amount-in-hex amount (if token token-decimal 0))
|
||||
from-address wallet-address
|
||||
disabled-from-chain-ids disabled-from-chain-ids
|
||||
disabled-to-chain-ids (if (= transaction-type :bridge)
|
||||
disabled-to-chain-ids (if (= transaction-type :tx/bridge)
|
||||
(filter #(not= % bridge-to-chain-id) network-chain-ids)
|
||||
(filter (fn [chain-id]
|
||||
(not (some #(= chain-id %)
|
||||
|
@ -322,8 +329,9 @@
|
|||
network-chain-ids))
|
||||
from-locked-amount {}
|
||||
transaction-type-param (case transaction-type
|
||||
:collectible constants/send-type-erc-721-transfer
|
||||
:bridge constants/send-type-bridge
|
||||
:tx/collectible-erc-721 constants/send-type-erc-721-transfer
|
||||
:tx/collectible-erc-1155 constants/send-type-erc-1155-transfer
|
||||
:tx/bridge constants/send-type-bridge
|
||||
constants/send-type-transfer)
|
||||
balances-per-chain (when token (:balances-per-chain token))
|
||||
token-available-networks-for-suggested-routes
|
||||
|
@ -455,6 +463,14 @@
|
|||
:TokenID token-id
|
||||
:ChainID to-chain-id))
|
||||
|
||||
(= bridge-name constants/bridge-name-erc-1155-transfer)
|
||||
(assoc :ERC1155TransferTx
|
||||
(assoc tx-data
|
||||
:Recipient to-address
|
||||
:TokenID token-id
|
||||
:ChainID to-chain-id
|
||||
:Amount amount-in))
|
||||
|
||||
(= bridge-name constants/bridge-name-transfer)
|
||||
(assoc :TransferTx tx-data)
|
||||
|
||||
|
@ -494,8 +510,9 @@
|
|||
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
|
||||
:tx/collectible-erc-721 constants/send-type-erc-721-transfer
|
||||
:tx/collectible-erc-1155 constants/send-type-erc-1155-transfer
|
||||
:tx/bridge constants/send-type-bridge
|
||||
constants/send-type-transfer)
|
||||
token (get-in db [:wallet :ui :send :token])
|
||||
collectible (get-in db [:wallet :ui :send :collectible])
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
(ns status-im.contexts.wallet.send.flow-config)
|
||||
(ns status-im.contexts.wallet.send.flow-config
|
||||
(:require
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]))
|
||||
|
||||
(defn- collectible-selected?
|
||||
[db]
|
||||
(let [collectible-stored (-> db :wallet :ui :send :collectible)
|
||||
tx-type (-> db :wallet :ui :send :tx-type)]
|
||||
(and (some? collectible-stored)
|
||||
(= tx-type :collectible))))
|
||||
(send-utils/tx-type-collectible? tx-type))))
|
||||
|
||||
(defn- token-selected?
|
||||
[db]
|
||||
|
@ -19,7 +21,8 @@
|
|||
{:screen-id :screen/wallet.select-asset
|
||||
:skip-step? (fn [db] (or (token-selected? db) (collectible-selected? db)))}
|
||||
{:screen-id :screen/wallet.send-input-amount
|
||||
:skip-step? (fn [db] (= (get-in db [:wallet :ui :send :tx-type]) :collectible))}
|
||||
:skip-step? (fn [db]
|
||||
(send-utils/tx-type-collectible? (get-in db [:wallet :ui :send :tx-type])))}
|
||||
{:screen-id :screen/wallet.select-collectible-amount
|
||||
:skip-step? (fn [db]
|
||||
(or (not (collectible-selected? db))
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
:weight :semi-bold
|
||||
:style style/title-container
|
||||
:accessibility-label :send-label}
|
||||
(if (= transaction-type :bridge)
|
||||
(if (= transaction-type :tx/bridge)
|
||||
(i18n/label :t/bridge)
|
||||
(i18n/label :t/send))]
|
||||
[quo/summary-tag
|
||||
|
@ -34,7 +34,7 @@
|
|||
:label (str amount " " token-display-name)
|
||||
:type (if collectible? :collectible :token)
|
||||
:image-source (if collectible? image-url :eth)}]]
|
||||
(if (= transaction-type :bridge)
|
||||
(if (= transaction-type :tx/bridge)
|
||||
(map-indexed
|
||||
(fn [idx path]
|
||||
(let [from-network (:from path)
|
||||
|
@ -98,7 +98,7 @@
|
|||
:style style/title-container
|
||||
:accessibility-label :send-label}
|
||||
(i18n/label :t/to)]
|
||||
(if (= transaction-type :bridge)
|
||||
(if (= transaction-type :tx/bridge)
|
||||
[quo/summary-tag
|
||||
{:type :network
|
||||
:image-source (:source to-network)
|
||||
|
@ -107,7 +107,7 @@
|
|||
[quo/summary-tag
|
||||
{:type :address
|
||||
:label (utils/get-shortened-address to-address)}])]
|
||||
(when (= transaction-type :bridge)
|
||||
(when (= transaction-type :tx/bridge)
|
||||
[rn/view
|
||||
{:style {:flex-direction :row
|
||||
:margin-top 4}}
|
||||
|
@ -198,7 +198,7 @@
|
|||
{:amount (str max-fees)
|
||||
:symbol currency-symbol})}]
|
||||
[data-item
|
||||
{:title (if (= transaction-type :bridge)
|
||||
{:title (if (= transaction-type :tx/bridge)
|
||||
(i18n/label :t/bridged-to
|
||||
{:network (:abbreviated-name to-network)})
|
||||
(i18n/label :t/user-gets {:name (utils/get-shortened-address to-address)}))
|
||||
|
@ -249,7 +249,7 @@
|
|||
:footer (when (and route (seq route))
|
||||
[standard-auth/slide-button
|
||||
{:size :size-48
|
||||
:track-text (if (= transaction-type :bridge)
|
||||
:track-text (if (= transaction-type :tx/bridge)
|
||||
(i18n/label :t/slide-to-bridge)
|
||||
(i18n/label :t/slide-to-send))
|
||||
:container-style {:z-index 2}
|
||||
|
@ -282,12 +282,12 @@
|
|||
:theme theme}]
|
||||
[user-summary
|
||||
{:token-display-name token-display-name
|
||||
:summary-type (if (= transaction-type :bridge)
|
||||
:summary-type (if (= transaction-type :tx/bridge)
|
||||
:status-account
|
||||
:account)
|
||||
:accessibility-label :summary-to-label
|
||||
:label (i18n/label :t/to-capitalized)
|
||||
:account-props (if (= transaction-type :bridge)
|
||||
:account-props (if (= transaction-type :tx/bridge)
|
||||
from-account-props
|
||||
user-props)
|
||||
:network-values to-values-by-chain
|
||||
|
|
|
@ -208,3 +208,11 @@
|
|||
:position-diff position-diff})))
|
||||
[]
|
||||
route))
|
||||
|
||||
(def ^:private collectible-tx-set
|
||||
#{:tx/collectible-erc-721
|
||||
:tx/collectible-erc-1155})
|
||||
|
||||
(defn tx-type-collectible?
|
||||
[tx-type]
|
||||
(contains? collectible-tx-set tx-type))
|
||||
|
|
Loading…
Reference in New Issue