diff --git a/src/app/components/Delegations/Delegations.tsx b/src/app/components/Delegations/Delegations.tsx index aae948a4..a76685b2 100644 --- a/src/app/components/Delegations/Delegations.tsx +++ b/src/app/components/Delegations/Delegations.tsx @@ -77,18 +77,33 @@ export const Delegations: React.FC = ({ delegation: DelegationInterface, newState: string, ) => { - setIntermediateDelegationsLocalStorage((delegations) => [ - toLocalStorageIntermediateDelegation( - delegation.stakingTxHashHex, - publicKeyNoCoord, - delegation.finalityProviderPkHex, - delegation.stakingValueSat, - delegation.stakingTx.txHex, - delegation.stakingTx.timelock, - newState, - ), - ...delegations, - ]); + const newTxId = delegation.stakingTxHashHex; + + setIntermediateDelegationsLocalStorage((delegations) => { + // Check if an intermediate delegation with the same transaction ID already exists + const exists = delegations.some( + (existingDelegation) => existingDelegation.stakingTxHashHex === newTxId, + ); + + // If it doesn't exist, add the new intermediate delegation + if (!exists) { + return [ + toLocalStorageIntermediateDelegation( + newTxId, + publicKeyNoCoord, + delegation.finalityProviderPkHex, + delegation.stakingValueSat, + delegation.stakingTx.txHex, + delegation.stakingTx.timelock, + newState, + ), + ...delegations, + ]; + } + + // If it exists, return the existing delegations unchanged + return delegations; + }); }; // Handles unbonding requests for Active delegations that want to be withdrawn early diff --git a/src/app/components/Staking/Staking.tsx b/src/app/components/Staking/Staking.tsx index 4e3c709b..50e2e09a 100644 --- a/src/app/components/Staking/Staking.tsx +++ b/src/app/components/Staking/Staking.tsx @@ -296,17 +296,33 @@ export const Staking: React.FC = ({ signedTxHex: string, stakingTerm: number, ) => { - setDelegationsLocalStorage((delegations) => [ - toLocalStorageDelegation( - Transaction.fromHex(signedTxHex).getId(), - publicKeyNoCoord, - finalityProvider!.btcPk, - stakingAmountSat, - signedTxHex, - stakingTerm, - ), - ...delegations, - ]); + // Get the transaction ID + const newTxId = Transaction.fromHex(signedTxHex).getId(); + + setDelegationsLocalStorage((delegations) => { + // Check if the delegation with the same transaction ID already exists + const exists = delegations.some( + (delegation) => delegation.stakingTxHashHex === newTxId, + ); + + // If it doesn't exist, add the new delegation + if (!exists) { + return [ + toLocalStorageDelegation( + newTxId, + publicKeyNoCoord, + finalityProvider!.btcPk, + stakingAmountSat, + signedTxHex, + stakingTerm, + ), + ...delegations, + ]; + } + + // If it exists, return the existing delegations unchanged + return delegations; + }); }; // Memoize the staking fee calculation