Skip to content

Commit

Permalink
fix: moved prepareTransaction before getting status (#7767)
Browse files Browse the repository at this point in the history
  • Loading branch information
CremaFR authored Sep 6, 2024
1 parent eb1c334 commit dbc0a9a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-garlics-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": minor
---

fix fee drawer issues by prepararing tx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,9 @@ const SwapWebView = ({
let finalTx = preparedTransaction;
let customFeeConfig = transaction && getCustomFeesPerFamily(finalTx);
const setTransaction = async (newTransaction: Transaction): Promise<Transaction> => {
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;
};

Expand Down

0 comments on commit dbc0a9a

Please sign in to comment.