From 0c25b77e540168904974bb4ac6dce43bea7ea47f Mon Sep 17 00:00:00 2001 From: Lungu Cristian Date: Tue, 3 Dec 2024 10:28:23 +0200 Subject: [PATCH] fix: show accurate approval fee for swaps (#21718) --- src/status_im/contexts/wallet/data_store.cljs | 15 ++++++--------- src/status_im/subs/wallet/swap.cljs | 15 +++++++++++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/status_im/contexts/wallet/data_store.cljs b/src/status_im/contexts/wallet/data_store.cljs index db82a249a7..1ff6d923ae 100644 --- a/src/status_im/contexts/wallet/data_store.cljs +++ b/src/status_im/contexts/wallet/data_store.cljs @@ -233,9 +233,12 @@ (defn new->old-route-path [new-path] - (let [bonder-fees (-> new-path :tx-bonder-fees money/bignumber) - token-fees (-> new-path :tx-token-fees money/bignumber)] - {:from (:from-chain new-path) + (let [to-bignumber (fn [k] (-> new-path k money/bignumber))] + {:approval-fee (to-bignumber :approval-fee) + :approval-l-1-fee (to-bignumber :approval-l-1-fee) + :bonder-fees (to-bignumber :tx-bonder-fees) + :token-fees (to-bignumber :tx-token-fees) + :from (:from-chain new-path) :amount-in-locked (:amount-in-locked new-path) :amount-in (:amount-in new-path) :max-amount-in (:max-amount-in new-path) @@ -273,15 +276,9 @@ :approval-contract-address (:approval-contract-address new-path) :approval-required (:approval-required new-path) :estimated-time (:estimated-time new-path) - :approval-gas-fees (* (money/wei->ether (get-in new-path - [:suggested-levels-for-max-fees-per-gas - :medium])) - (:approval-gas-amount new-path)) :to (:to-chain new-path) - :bonder-fees bonder-fees :approval-amount-required (:approval-amount-required new-path) ;; :cost () ;; tbd not used on desktop - :token-fees token-fees :gas-amount (:tx-gas-amount new-path)})) (defn tokens-never-loaded? diff --git a/src/status_im/subs/wallet/swap.cljs b/src/status_im/subs/wallet/swap.cljs index 8930c34094..7695f2c42d 100644 --- a/src/status_im/subs/wallet/swap.cljs +++ b/src/status_im/subs/wallet/swap.cljs @@ -126,7 +126,7 @@ (let [swap-proposal (:swap-proposal swap)] (reduce dissoc swap-proposal - [:gas-fees :gas-amount :token-fees :bonder-fees :approval-gas-fees])))) + [:gas-fees :gas-amount :token-fees :bonder-fees :approval-fee :approval-l-1-fee])))) (rf/reg-sub :wallet/swap-amount @@ -310,20 +310,27 @@ :token asset-to-pay-with-current-account-balance :prices-per-token prices-per-token}))) +(rf/reg-sub + :wallet/swap-approval-fee + :<- [:wallet/swap-proposal] + (fn [{:keys [approval-fee approval-l-1-fee]}] + (money/add (money/wei->ether approval-fee) + (money/wei->ether approval-l-1-fee)))) + (rf/reg-sub :wallet/approval-gas-fees :<- [:wallet/current-viewing-account] - :<- [:wallet/swap-proposal] + :<- [:wallet/swap-approval-fee] :<- [:profile/currency] :<- [:wallet/prices-per-token] - (fn [[account {:keys [approval-gas-fees]} currency prices-per-token]] + (fn [[account approval-fee currency prices-per-token]] (let [tokens (:tokens account) token-for-fees (first (filter #(= (string/lower-case (:symbol %)) (string/lower-case constants/token-for-fees-symbol)) tokens)) fee-in-fiat (utils/calculate-token-fiat-value {:currency currency - :balance approval-gas-fees + :balance approval-fee :token token-for-fees :prices-per-token prices-per-token})] fee-in-fiat)))