diff --git a/src/status_im/contexts/wallet/send/transaction_confirmation/view.cljs b/src/status_im/contexts/wallet/send/transaction_confirmation/view.cljs index ebd1753ec6..9788005357 100644 --- a/src/status_im/contexts/wallet/send/transaction_confirmation/view.cljs +++ b/src/status_im/contexts/wallet/send/transaction_confirmation/view.cljs @@ -125,56 +125,96 @@ :emoji (:emoji 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 - [{:keys [token-symbol token-decimals account-props route to? theme label accessibility-label - summary-type]}] - (letfn [(merge-sum [a b] - (merge-with money/add a b))] - (let [network-amounts - (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-details (rf/sub [:wallet/network-details-by-chain-id chain-id]) - network-name (:network-name network-details) - network-name (if (= network-name :mainnet) :ethereum network-name)] - (merge-sum acc {network-name amount}))) - {} - route) - network-values - (reduce-kv (fn [acc k v] - (assoc acc k {:amount v :token-symbol token-symbol})) - {} - 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 - {: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}]]))) + [{:keys [account-props theme label accessibility-label + summary-type network-values] + :as _props}] + [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 + :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 [{: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}}] route-loaded? [:<> - [quo/data-item - {:container-style style/detail-item - :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)})}] - [quo/data-item - {:container-style style/detail-item - :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 - {: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)}]] + [data-item + {:title (i18n/label :t/est-time) + :subtitle (i18n/label :t/time-in-mins {:minutes (str estimated-time-min)})}] + [data-item + {:title (i18n/label :t/max-fees) + :subtitle (i18n/label :t/amount-with-currency-symbol + {:amount (str max-fees) + :symbol currency-symbol})}] + [data-item + {: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 [quo/text {:style {:align-self :center}} (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 [_] (let [on-close (fn [] (rf/dispatch [:wallet/clean-suggested-routes]) - (rf/dispatch [:wallet/clean-selected-collectible]) (rf/dispatch [:navigate-back]))] (fn [{:keys [theme]}] - (let [send-transaction-data (rf/sub [:wallet/wallet-send]) - token (:token send-transaction-data) - collectible (:collectible send-transaction-data) - collection-data (:collection-data collectible) - collectible-data (:collectible-data collectible) - collectible-id (get-in collectible [:id :token-id]) - token-symbol (if collectible - (first (remove - string/blank? - [(:name collectible-data) - (str (:name collection-data) " #" collectible-id)])) - (:symbol token)) - token-decimals (if collectible 0 (:decimals token)) - image-url (when collectible (:image-url collectible-data)) - amount (:amount send-transaction-data) - route (:route send-transaction-data) - transaction-type (:tx-type send-transaction-data) - estimated-time-min (reduce + (map :estimated-time route)) - max-fees "-" - to-address (:to-address send-transaction-data) - account (rf/sub [:wallet/current-viewing-account]) - account-color (:color account) - bridge-to-chain-id (:bridge-to-chain-id send-transaction-data) - bridge-to-network (when bridge-to-chain-id - (rf/sub [:wallet/network-details-by-chain-id bridge-to-chain-id])) - from-account-props {:customization-color account-color - :size 32 - :emoji (:emoji account) - :type :default - :name (:name account) - :address (utils/get-shortened-address (:address - account))} - user-props {:full-name to-address - :address (utils/get-shortened-address to-address)}] + (let [send-transaction-data (rf/sub [:wallet/wallet-send]) + {:keys [token collectible amount route + to-address bridge-to-chain-id]} send-transaction-data + collectible? (some? collectible) + token-symbol (if collectible + (collectible-token-symbol collectible) + (:symbol token)) + token-decimals (if collectible 0 (:decimals token)) + image-url (when collectible + (get-in collectible [:preview-url :uri])) + transaction-type (:tx-type send-transaction-data) + estimated-time-min (reduce + (map :estimated-time route)) + max-fees "-" + account (rf/sub [:wallet/current-viewing-account]) + account-color (:color account) + bridge-to-network (when bridge-to-chain-id + (rf/sub [:wallet/network-details-by-chain-id + bridge-to-chain-id])) + from-account-props {:customization-color account-color + :size 32 + :emoji (:emoji account) + :type :default + :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}} [floating-button-page/view {:footer-container-padding 0 @@ -317,21 +337,21 @@ :to-network bridge-to-network :image-url image-url :transaction-type transaction-type - :collectible? (some? collectible)}] + :collectible? collectible?}] [user-summary - {:token-symbol token-symbol - :token-decimals token-decimals - :summary-type :status-account + {:summary-type :status-account :accessibility-label :summary-from-label :label (i18n/label :t/from-capitalized) - :route route - :to? false :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 - {:token-symbol token-symbol - :token-decimals token-decimals - :summary-type (if (= transaction-type :bridge) + {:summary-type (if (= transaction-type :bridge) :status-account :account) :accessibility-label :summary-to-label @@ -339,9 +359,13 @@ :account-props (if (= transaction-type :bridge) from-account-props user-props) - :route route - :to? true - :theme theme}] + :theme theme + :network-values (values-by-network {:collectible collectible + :amount amount + :token-symbol token-symbol + :route route + :token-decimals token-decimals + :to? true})}] [transaction-details {:estimated-time-min estimated-time-min :max-fees max-fees