Skip to content

Commit

Permalink
web-wallet: The sync promise should be set to null after aborting a…
Browse files Browse the repository at this point in the history
… sync

Resolves #2118
  • Loading branch information
ascartabelli committed Aug 19, 2024
1 parent b34d758 commit ec4bcac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions web-wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix Receive tab content overflows [#1901]
- Add missing "Soehne Mono" and its `@font-face` definition [#2071]
- The sync promise should be set to `null` after aborting a sync [#2118]

## [0.5.0] - 2024-03-27

Expand Down Expand Up @@ -235,6 +236,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2026]: https://github.com/dusk-network/rusk/issues/2026
[#2000]: https://github.com/dusk-network/rusk/issues/2000
[#2071]: https://github.com/dusk-network/rusk/issues/2071
[#2118]: https://github.com/dusk-network/rusk/issues/2118

<!-- VERSIONS -->

Expand Down
20 changes: 17 additions & 3 deletions web-wallet/src/lib/stores/__tests__/walletStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,25 +226,39 @@ describe("walletStore", async () => {
it("should expose a method to abort a sync that is in progress", async () => {
await walletStore.init(wallet);

expect(syncSpy).toHaveBeenCalledTimes(1);
expect(syncSpy).toHaveBeenCalledWith({ signal: expect.any(AbortSignal) });

walletStore.abortSync();

await vi.advanceTimersToNextTimerAsync();
expect(abortControllerSpy).toHaveBeenCalledTimes(1);
});

it("should set to `null` the current sync promise so that a new call to `sync` will start a new synchronization", async () => {
await walletStore.init(wallet);

expect(syncSpy).toHaveBeenCalledTimes(1);
expect(syncSpy).toHaveBeenCalledWith({ signal: expect.any(AbortSignal) });

walletStore.abortSync();

expect(abortControllerSpy).toHaveBeenCalledTimes(1);

walletStore.sync();

expect(syncSpy).toHaveBeenCalledTimes(2);
expect(syncSpy).toHaveBeenCalledWith({ signal: expect.any(AbortSignal) });
});

it("should do nothing if there is no sync in progress", async () => {
walletStore.reset();

await walletStore.init(wallet);
await vi.advanceTimersToNextTimerAsync();

expect(syncSpy).toHaveBeenCalledTimes(1);
expect(syncSpy).toHaveBeenCalledWith({ signal: expect.any(AbortSignal) });

syncSpy.mockClear();
await vi.advanceTimersToNextTimerAsync();

walletStore.abortSync();

Expand Down
5 changes: 4 additions & 1 deletion web-wallet/src/lib/stores/walletStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ const getCurrentAddress = () => get(walletStore).currentAddress;
/** @type {(action: (...args: any[]) => Promise<any>) => Promise<void>} */
const syncedAction = (action) => sync().then(action).finally(sync);

const abortSync = () => syncPromise && syncController?.abort();
const abortSync = () => {
syncPromise && syncController?.abort();
syncPromise = null;
};

/** @type {() => Promise<void>} */
const clearLocalData = async () => walletInstance?.reset();
Expand Down

0 comments on commit ec4bcac

Please sign in to comment.