Skip to content

Commit

Permalink
fixup! feat(wallet): the wallet now only fetches UTXOs on tx history …
Browse files Browse the repository at this point in the history
…change
  • Loading branch information
AngelCastilloB committed Nov 15, 2024
1 parent 6244a8e commit 721ebb6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/wallet/src/services/TransactionsTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const revertLastBlock = (
localTransactions: Cardano.HydratedTx[],
blockNo: Cardano.BlockNo,
rollback$: Subject<Cardano.HydratedTx>,
newTransactions: Cardano.HydratedTx[],
logger: Logger
) => {
const result = [...localTransactions];
Expand All @@ -135,9 +136,12 @@ export const revertLastBlock = (
const lastKnownTx = result[result.length - 1];

if (lastKnownTx.blockHeader.blockNo === blockNo) {
logger.debug(`Transaction ${lastKnownTx.id} was rolled back`);
// only emit if the tx is also not present in the new transactions to be added
if (newTransactions.findIndex((tx) => tx.id === lastKnownTx.id) === -1) {
logger.debug(`Transaction ${lastKnownTx.id} was rolled back`);
rollback$.next(lastKnownTx);
}

rollback$.next(lastKnownTx);
result.pop();
} else {
break;
Expand Down Expand Up @@ -200,7 +204,7 @@ const findIntersectionAndUpdateTxStore = ({

// If no transactions found from that block range, it means the last known block has been rolled back.
if (newTransactions.length === 0) {
localTransactions = revertLastBlock(localTransactions, lowerBound, rollback$, logger);
localTransactions = revertLastBlock(localTransactions, lowerBound, rollback$, newTransactions, logger);
continue;
}

Expand All @@ -214,7 +218,7 @@ const findIntersectionAndUpdateTxStore = ({
sameLength && localTxsFromSameBlock.every((tx, index) => tx.id === firstSegmentOfNewTransactions[index].id);

if (!sameLength || !sameOrder) {
localTransactions = revertLastBlock(localTransactions, lowerBound, rollback$, logger);
localTransactions = revertLastBlock(localTransactions, lowerBound, rollback$, newTransactions, logger);
localTransactions = [...localTransactions, ...newTransactions];
store.setAll(localTransactions);

Expand Down

0 comments on commit 721ebb6

Please sign in to comment.