Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): add resetAll to initTransactionsStore #3606

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/frontend/src/lib/stores/transactions.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface TransactionsStore<T> extends CertifiedStore<TransactionsData<T>
append: (params: { tokenId: TokenId; transactions: CertifiedTransaction<T>[] }) => void;
cleanUp: (params: { tokenId: TokenId; transactionIds: string[] }) => void;
nullify: (tokenId: TokenId) => void;
resetAll: () => void;
}

export const initTransactionsStore = <
Expand Down Expand Up @@ -64,6 +65,7 @@ export const initTransactionsStore = <
[tokenId]: null
})),
reset,
resetAll: () => update(() => ({})),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally use null for reset because it explicitly indicates a decision to reset, such as when an error occurs. However, in this case, you are setting to the initial value, which creates a slight discrepancy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to replicate what is happening for the ETH transactions store too. But for sure I can set null on this, and then, in another PR, I adjust that store too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say so, makes sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to clarify, that means setting null in all keys, like {tokenId1: null, tokenId2: null, ...}, and NOT that the entire store is null instead of {}

correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does not reset?

subscribe
};
};
17 changes: 17 additions & 0 deletions src/frontend/src/tests/lib/stores/transactions.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,21 @@ describe('transactions.store', () => {
})();
}));
});

describe('resetAll', () => {
it('should clear all transactions and keys', () =>
new Promise<void>((done) => {
const store = initTransactionsStore<IcTransactionUi>();

const transactions = [createCertifiedIcTransactionUiMock('tx1')];
store.append({ tokenId, transactions });
store.resetAll();

store.subscribe((state) => {
expect(state).toEqual({});

done();
})();
}));
});
});