From dbc0a9ab83f30c225950bdd5189216f7d4735c8e Mon Sep 17 00:00:00 2001 From: Thomas Brillard Date: Fri, 6 Sep 2024 11:38:46 +0200 Subject: [PATCH] fix: moved prepareTransaction before getting status (#7767) --- .changeset/sharp-garlics-cover.md | 5 +++ .../Swap2/Form/FeesDrawerLiveApp/index.tsx | 36 ++++++++++++------- .../exchange/Swap2/Form/SwapWebView.tsx | 7 ++-- 3 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 .changeset/sharp-garlics-cover.md diff --git a/.changeset/sharp-garlics-cover.md b/.changeset/sharp-garlics-cover.md new file mode 100644 index 000000000000..c903d11fe9c7 --- /dev/null +++ b/.changeset/sharp-garlics-cover.md @@ -0,0 +1,5 @@ +--- +"ledger-live-desktop": minor +--- + +fix fee drawer issues by prepararing tx diff --git a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/FeesDrawerLiveApp/index.tsx b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/FeesDrawerLiveApp/index.tsx index 9935edb29e61..1301efcecc60 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/FeesDrawerLiveApp/index.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/FeesDrawerLiveApp/index.tsx @@ -40,29 +40,41 @@ export default function FeesDrawerLiveApp({ const handleSetTransaction = useCallback( (transaction: Transaction) => { - setTransactionState(transaction); - setTransaction(transaction); + const account = mainAccount.type === "TokenAccount" ? parentAccount : mainAccount; bridge - .getTransactionStatus( - mainAccount.type === "TokenAccount" ? parentAccount : mainAccount, - transaction, + .prepareTransaction(account, transaction) + .then(preparedTransaction => + bridge.getTransactionStatus(account, preparedTransaction).then(status => { + setTransactionStatus(status); + setTransactionState(preparedTransaction); + setTransaction(preparedTransaction); + }), ) - .then(setTransactionStatus); + .catch(error => { + console.error("Error preparing transaction:", error); + }); }, [setTransaction, bridge, mainAccount, parentAccount], ); const handleUpdateTransaction = useCallback( (updater: (arg0: Transaction) => Transaction) => { + const account = mainAccount.type === "TokenAccount" ? parentAccount : mainAccount; setTransactionState(prevTransaction => { - const updatedTransaction = updater(prevTransaction); + let updatedTransaction = updater(prevTransaction); bridge - .getTransactionStatus( - mainAccount.type === "TokenAccount" ? parentAccount : mainAccount, - updatedTransaction, + .prepareTransaction(account, updatedTransaction) + .then(preparedTransaction => + bridge.getTransactionStatus(account, preparedTransaction).then(status => { + setTransactionStatus(status); + setTransaction(preparedTransaction); + updatedTransaction = preparedTransaction; + }), ) - .then(setTransactionStatus) - .then(_ => setTransaction(updatedTransaction)); + .catch(error => { + console.error("Error updating transaction:", error); + return prevTransaction; + }); return updatedTransaction; }); diff --git a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/SwapWebView.tsx b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/SwapWebView.tsx index 0d7b7c754714..24ab57b66fa2 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/SwapWebView.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/SwapWebView.tsx @@ -353,10 +353,9 @@ const SwapWebView = ({ let finalTx = preparedTransaction; let customFeeConfig = transaction && getCustomFeesPerFamily(finalTx); const setTransaction = async (newTransaction: Transaction): Promise => { - const preparedTransaction = await bridge.prepareTransaction(mainAccount, newTransaction); - status = await bridge.getTransactionStatus(mainAccount, preparedTransaction); - customFeeConfig = transaction && getCustomFeesPerFamily(preparedTransaction); - finalTx = preparedTransaction; + status = await bridge.getTransactionStatus(mainAccount, newTransaction); + customFeeConfig = transaction && getCustomFeesPerFamily(newTransaction); + finalTx = newTransaction; return newTransaction; };