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,56 +125,96 @@
:emoji (:emoji account) :emoji (:emoji account)
:customization-color (:color account)}]])])) :customization-color (:color account)}]])]))
(defn network-name-from-chain-id
[chain-id]
(let [network-name (-> (rf/sub [:wallet/network-details-by-chain-id chain-id])
:network-name)]
(if (= network-name :mainnet) :ethereum network-name)))
(defn- network-amounts-from-route
[{:keys [route token-symbol token-decimals to?]}]
(reduce (fn [acc path]
(let [network (if to? (:to path) (:from path))
chain-id (:chain-id network)
amount-hex (if to? (:amount-in path) (:amount-out path))
amount-units (native-module/hex-to-number
(utils.hex/normalize-hex amount-hex))
amount (money/with-precision
(if (= token-symbol "ETH")
(money/wei->ether amount-units)
(money/token->unit amount-units
token-decimals))
6)
network-name (network-name-from-chain-id chain-id)]
(merge-with money/add acc {network-name amount})))
{}
route))
(defn- network-values-from-amounts
[network-amounts token-symbol]
(reduce-kv (fn [acc k v]
(assoc acc
k
{:amount v
:token-symbol token-symbol}))
{}
network-amounts))
(defn- sanitize-network-values
[network-values]
(into {}
(map (fn [[k v]]
[k
(if (money/equal-to (v :amount) 0)
(assoc v :amount "<0.01")
v)])
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 (defn- user-summary
[{:keys [token-symbol token-decimals account-props route to? theme label accessibility-label [{:keys [account-props theme label accessibility-label
summary-type]}] summary-type network-values]
(letfn [(merge-sum [a b] :as _props}]
(merge-with money/add a b))] [rn/view
(let [network-amounts {:style {:padding-horizontal 20
(reduce (fn [acc path] :padding-bottom 16}}
(let [network (if to? (:to path) (:from path)) [quo/text
chain-id (:chain-id network) {:size :paragraph-2
amount-hex (if to? (:amount-in path) (:amount-out path)) :weight :medium
amount-units (native-module/hex-to-number :style (style/section-label theme)
(utils.hex/normalize-hex amount-hex)) :accessibility-label accessibility-label}
amount (money/with-precision label]
(if (= token-symbol "ETH") [quo/summary-info
(money/wei->ether amount-units) {:type summary-type
(money/token->unit amount-units :networks? true
token-decimals)) :values network-values
6) :account-props account-props}]])
network-details (rf/sub [:wallet/network-details-by-chain-id chain-id])
network-name (:network-name network-details) (defn data-item
network-name (if (= network-name :mainnet) :ethereum network-name)] [{:keys [title subtitle]}]
(merge-sum acc {network-name amount}))) [quo/data-item
{} {:container-style style/detail-item
route) :blur? false
network-values :description :default
(reduce-kv (fn [acc k v] :icon-right? false
(assoc acc k {:amount v :token-symbol token-symbol})) :card? false
{} :label :none
network-amounts) :status :default
network-values-sanitized (into {} :size :small
(map (fn [[k v]] :title title
[k :subtitle subtitle}])
(if (money/equal-to (v :amount) 0)
(assoc v :amount "<0.01")
v)])
network-values))]
[rn/view
{:style {:padding-horizontal 20
:padding-bottom 16}}
[quo/text
{:size :paragraph-2
:weight :medium
:style (style/section-label theme)
:accessibility-label accessibility-label}
label]
[quo/summary-info
{:type summary-type
:networks? true
:values network-values-sanitized
:account-props account-props}]])))
(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,89 +240,69 @@
[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 :subtitle (i18n/label :t/time-in-mins {:minutes (str estimated-time-min)})}]
:description :default [data-item
:icon-right? false {:title (i18n/label :t/max-fees)
:card? false :subtitle (i18n/label :t/amount-with-currency-symbol
:label :none {:amount (str max-fees)
:status :default :symbol currency-symbol})}]
:size :small [data-item
:title (i18n/label :t/est-time) {:title (if (= transaction-type :bridge)
:subtitle (i18n/label :t/time-in-mins {:minutes (str estimated-time-min)})}] (i18n/label :t/bridged-to
[quo/data-item {:network (:abbreviated-name to-network)})
{:container-style style/detail-item (i18n/label :t/user-gets {:name (utils/get-shortened-address to-address)}))
:blur? false :subtitle (str amount " " token-symbol)}]]
: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
{:amount (str max-fees)
:symbol currency-symbol})}]
[quo/data-item
{:container-style style/detail-item
: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
{:network (:abbreviated-name to-network)})
(i18n/label :t/user-gets {:name (utils/get-shortened-address to-address)}))
:subtitle (str amount " " token-symbol)}]]
:else :else
[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) token-symbol (if collectible
collectible-id (get-in collectible [:id :token-id]) (collectible-token-symbol collectible)
token-symbol (if collectible (:symbol token))
(first (remove token-decimals (if collectible 0 (:decimals token))
string/blank? image-url (when collectible
[(:name collectible-data) (get-in collectible [:preview-url :uri]))
(str (:name collection-data) " #" collectible-id)])) transaction-type (:tx-type send-transaction-data)
(:symbol token)) estimated-time-min (reduce + (map :estimated-time route))
token-decimals (if collectible 0 (:decimals token)) max-fees "-"
image-url (when collectible (:image-url collectible-data)) account (rf/sub [:wallet/current-viewing-account])
amount (:amount send-transaction-data) account-color (:color account)
route (:route send-transaction-data) bridge-to-network (when bridge-to-chain-id
transaction-type (:tx-type send-transaction-data) (rf/sub [:wallet/network-details-by-chain-id
estimated-time-min (reduce + (map :estimated-time route)) bridge-to-chain-id]))
max-fees "-" from-account-props {:customization-color account-color
to-address (:to-address send-transaction-data) :size 32
account (rf/sub [:wallet/current-viewing-account]) :emoji (:emoji account)
account-color (:color account) :type :default
bridge-to-chain-id (:bridge-to-chain-id send-transaction-data) :name (:name account)
bridge-to-network (when bridge-to-chain-id :address (utils/get-shortened-address
(rf/sub [:wallet/network-details-by-chain-id bridge-to-chain-id])) (:address
from-account-props {:customization-color account-color account))}
:size 32 user-props {:full-name to-address
:emoji (:emoji account) :address (utils/get-shortened-address
:type :default to-address)}]
:name (:name account)
:address (utils/get-shortened-address (:address
account))}
user-props {:full-name 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
:network-values (values-by-network {:collectible collectible
:amount amount
:token-symbol token-symbol
:route route
:token-decimals token-decimals
:to? false})}]
[user-summary [user-summary
{:token-symbol token-symbol {:summary-type (if (= transaction-type :bridge)
:token-decimals token-decimals
: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)
:route route :theme theme
:to? true :network-values (values-by-network {:collectible collectible
:theme theme}] :amount amount
:token-symbol token-symbol
:route route
:token-decimals token-decimals
: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