Skip to content

Commit

Permalink
GIX-2183: Unnecessary error toast (#4087)
Browse files Browse the repository at this point in the history
# Motivation

In mainnet, when the user visits twice the Tokens page a toast error
might appear because of the background task to call update_balance on
the ckBTC minter.

In this PR, do not show the toast error if `uiIndicators` is set to
`false`.

# Changes

* In `updateBalance` ckbtc minter service, show error toast only when
`uiIndicators` is `true`.

# Tests

* Add a test for the new functionality.
* Tested manually that when the api endpoint raises this error the toast
is not shown.

# Todos

- [ ] Add entry to changelog (if necessary).

Not necessary.
  • Loading branch information
lmuntaner authored Dec 20, 2023
1 parent c5b4fa7 commit b5bea27
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
11 changes: 6 additions & 5 deletions frontend/src/lib/services/ckbtc-minter.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ export const updateBalance = async ({
return { success: true };
} catch (error: unknown) {
const err = mapUpdateBalanceError(error);

toastsError({
labelKey: "error__ckbtc.update_balance",
err,
});
if (uiIndicators) {
toastsError({
labelKey: "error__ckbtc.update_balance",
err,
});
}

return { success: false, err };
} finally {
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/tests/lib/services/ckbtc-minter.services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,30 @@ describe("ckbtc-minter-services", () => {
expect(spyOnToastsShow).not.toHaveBeenCalled();
});

it("should not toast error on error if no ui indicators", async () => {
const spyUpdateBalance = vi
.spyOn(minterApi, "updateBalance")
.mockImplementation(async () => {
throw new MinterAlreadyProcessingError();
});

const spyOnToastsError = vi.spyOn(toastsStore, "toastsError");

await services.updateBalance({
...params,
uiIndicators: false,
});

await waitFor(() =>
expect(spyUpdateBalance).toBeCalledWith({
identity: mockIdentity,
canisterId: CKBTC_MINTER_CANISTER_ID,
})
);

expect(spyOnToastsError).not.toHaveBeenCalled();
});

it("should not handle no new UTXOs success if no ui indicators", async () => {
vi.spyOn(minterApi, "updateBalance").mockImplementation(async () => {
throw new MinterNoNewUtxosError({
Expand Down

0 comments on commit b5bea27

Please sign in to comment.