Support for multiple collectibles transaction on confirmation page (#19502)

This commit is contained in:
Volodymyr Kozieiev 2024-04-08 20:43:23 +01:00 committed by GitHub
parent 55a182f430
commit 5aca098aa2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 159 additions and 135 deletions

View File

@ -125,12 +125,14 @@
:emoji (:emoji account) :emoji (:emoji account)
:customization-color (:color account)}]])])) :customization-color (:color account)}]])]))
(defn- user-summary (defn network-name-from-chain-id
[{:keys [token-symbol token-decimals account-props route to? theme label accessibility-label [chain-id]
summary-type]}] (let [network-name (-> (rf/sub [:wallet/network-details-by-chain-id chain-id])
(letfn [(merge-sum [a b] :network-name)]
(merge-with money/add a b))] (if (= network-name :mainnet) :ethereum network-name)))
(let [network-amounts
(defn- network-amounts-from-route
[{:keys [route token-symbol token-decimals to?]}]
(reduce (fn [acc path] (reduce (fn [acc path]
(let [network (if to? (:to path) (:from path)) (let [network (if to? (:to path) (:from path))
chain-id (:chain-id network) chain-id (:chain-id network)
@ -143,24 +145,48 @@
(money/token->unit amount-units (money/token->unit amount-units
token-decimals)) token-decimals))
6) 6)
network-details (rf/sub [:wallet/network-details-by-chain-id chain-id]) network-name (network-name-from-chain-id chain-id)]
network-name (:network-name network-details) (merge-with money/add acc {network-name amount})))
network-name (if (= network-name :mainnet) :ethereum network-name)]
(merge-sum acc {network-name amount})))
{} {}
route) route))
network-values
(defn- network-values-from-amounts
[network-amounts token-symbol]
(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 {}
(defn- sanitize-network-values
[network-values]
(into {}
(map (fn [[k v]] (map (fn [[k v]]
[k [k
(if (money/equal-to (v :amount) 0) (if (money/equal-to (v :amount) 0)
(assoc v :amount "<0.01") (assoc v :amount "<0.01")
v)]) v)])
network-values))] network-values)))
(defn- values-by-network
[{:keys [collectible amount token-symbol route token-decimals to?]}]
(if collectible
(let [collectible-chain-id (get-in collectible [:id :contract-id :chain-id])
network-name (network-name-from-chain-id collectible-chain-id)]
{network-name {:amount amount :token-symbol token-symbol}})
(let [network-amounts (network-amounts-from-route {:route route
:token-symbol token-symbol
:token-decimals token-decimals
:to? to?})
network-values (network-values-from-amounts network-amounts token-symbol)]
(sanitize-network-values network-values))))
(defn- user-summary
[{:keys [account-props theme label accessibility-label
summary-type network-values]
:as _props}]
[rn/view [rn/view
{:style {:padding-horizontal 20 {:style {:padding-horizontal 20
:padding-bottom 16}} :padding-bottom 16}}
@ -173,8 +199,22 @@
[quo/summary-info [quo/summary-info
{:type summary-type {:type summary-type
:networks? true :networks? true
:values network-values-sanitized :values network-values
:account-props account-props}]]))) :account-props account-props}]])
(defn data-item
[{:keys [title subtitle]}]
[quo/data-item
{:container-style style/detail-item
:blur? false
:description :default
:icon-right? false
:card? false
:label :none
:status :default
:size :small
:title title
:subtitle subtitle}])
(defn- transaction-details (defn- transaction-details
[{:keys [estimated-time-min max-fees token-symbol amount to-address to-network route transaction-type [{:keys [estimated-time-min max-fees token-symbol amount to-address to-network route transaction-type
@ -200,40 +240,16 @@
[rn/activity-indicator {:style {:align-self :center}}] [rn/activity-indicator {:style {:align-self :center}}]
route-loaded? route-loaded?
[:<> [:<>
[quo/data-item [data-item
{:container-style style/detail-item {:title (i18n/label :t/est-time)
:blur? false
:description :default
:icon-right? false
:card? false
:label :none
:status :default
:size :small
:title (i18n/label :t/est-time)
:subtitle (i18n/label :t/time-in-mins {:minutes (str estimated-time-min)})}] :subtitle (i18n/label :t/time-in-mins {:minutes (str estimated-time-min)})}]
[quo/data-item [data-item
{:container-style style/detail-item {:title (i18n/label :t/max-fees)
:blur? false
:description :default
:icon-right? false
:card? false
:label :none
:status :default
:size :small
:title (i18n/label :t/max-fees)
:subtitle (i18n/label :t/amount-with-currency-symbol :subtitle (i18n/label :t/amount-with-currency-symbol
{:amount (str max-fees) {:amount (str max-fees)
:symbol currency-symbol})}] :symbol currency-symbol})}]
[quo/data-item [data-item
{:container-style style/detail-item {:title (if (= transaction-type :bridge)
:blur? false
:description :default
:icon-right? false
:card? false
:label :none
:status :default
:size :small
:title (if (= transaction-type :bridge)
(i18n/label :t/bridged-to (i18n/label :t/bridged-to
{:network (:abbreviated-name to-network)}) {:network (:abbreviated-name to-network)})
(i18n/label :t/user-gets {:name (utils/get-shortened-address to-address)})) (i18n/label :t/user-gets {:name (utils/get-shortened-address to-address)}))
@ -242,47 +258,51 @@
[quo/text {:style {:align-self :center}} [quo/text {:style {:align-self :center}}
(i18n/label :t/no-routes-found-confirmation)])]])) (i18n/label :t/no-routes-found-confirmation)])]]))
(defn collectible-token-symbol
[collectible]
(let [collection-data (:collection-data collectible)
collectible-data (:collectible-data collectible)
collectible-id (get-in collectible [:id :token-id])]
(first (remove
string/blank?
[(:name collectible-data)
(str (:name collection-data) " #" collectible-id)]))))
(defn- view-internal (defn- view-internal
[_] [_]
(let [on-close (fn [] (let [on-close (fn []
(rf/dispatch [:wallet/clean-suggested-routes]) (rf/dispatch [:wallet/clean-suggested-routes])
(rf/dispatch [:wallet/clean-selected-collectible])
(rf/dispatch [:navigate-back]))] (rf/dispatch [:navigate-back]))]
(fn [{:keys [theme]}] (fn [{:keys [theme]}]
(let [send-transaction-data (rf/sub [:wallet/wallet-send]) (let [send-transaction-data (rf/sub [:wallet/wallet-send])
token (:token send-transaction-data) {:keys [token collectible amount route
collectible (:collectible send-transaction-data) to-address bridge-to-chain-id]} send-transaction-data
collection-data (:collection-data collectible) collectible? (some? collectible)
collectible-data (:collectible-data collectible)
collectible-id (get-in collectible [:id :token-id])
token-symbol (if collectible token-symbol (if collectible
(first (remove (collectible-token-symbol collectible)
string/blank?
[(:name collectible-data)
(str (:name collection-data) " #" collectible-id)]))
(:symbol token)) (:symbol token))
token-decimals (if collectible 0 (:decimals token)) token-decimals (if collectible 0 (:decimals token))
image-url (when collectible (:image-url collectible-data)) image-url (when collectible
amount (:amount send-transaction-data) (get-in collectible [:preview-url :uri]))
route (:route send-transaction-data)
transaction-type (:tx-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)
account (rf/sub [:wallet/current-viewing-account]) account (rf/sub [:wallet/current-viewing-account])
account-color (:color account) account-color (:color account)
bridge-to-chain-id (:bridge-to-chain-id send-transaction-data)
bridge-to-network (when bridge-to-chain-id bridge-to-network (when bridge-to-chain-id
(rf/sub [:wallet/network-details-by-chain-id bridge-to-chain-id])) (rf/sub [:wallet/network-details-by-chain-id
bridge-to-chain-id]))
from-account-props {:customization-color account-color from-account-props {:customization-color account-color
:size 32 :size 32
:emoji (:emoji account) :emoji (:emoji account)
:type :default :type :default
:name (:name account) :name (:name account)
:address (utils/get-shortened-address (:address :address (utils/get-shortened-address
(:address
account))} 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}}
[floating-button-page/view [floating-button-page/view
{:footer-container-padding 0 {:footer-container-padding 0
@ -317,21 +337,21 @@
:to-network bridge-to-network :to-network bridge-to-network
:image-url image-url :image-url image-url
:transaction-type transaction-type :transaction-type transaction-type
:collectible? (some? collectible)}] :collectible? collectible?}]
[user-summary [user-summary
{:token-symbol token-symbol {:summary-type :status-account
:token-decimals token-decimals
:summary-type :status-account
:accessibility-label :summary-from-label :accessibility-label :summary-from-label
:label (i18n/label :t/from-capitalized) :label (i18n/label :t/from-capitalized)
:route route
:to? false
:account-props from-account-props :account-props from-account-props
:theme theme}] :theme theme
[user-summary :network-values (values-by-network {:collectible collectible
{:token-symbol token-symbol :amount amount
:token-symbol token-symbol
:route route
:token-decimals token-decimals :token-decimals token-decimals
:summary-type (if (= transaction-type :bridge) :to? false})}]
[user-summary
{:summary-type (if (= transaction-type :bridge)
:status-account :status-account
:account) :account)
:accessibility-label :summary-to-label :accessibility-label :summary-to-label
@ -339,9 +359,13 @@
:account-props (if (= transaction-type :bridge) :account-props (if (= transaction-type :bridge)
from-account-props from-account-props
user-props) user-props)
:theme theme
:network-values (values-by-network {:collectible collectible
:amount amount
:token-symbol token-symbol
:route route :route route
:to? true :token-decimals token-decimals
:theme theme}] :to? true})}]
[transaction-details [transaction-details
{:estimated-time-min estimated-time-min {:estimated-time-min estimated-time-min
:max-fees max-fees :max-fees max-fees