Skip to content

Commit 9311b75

Browse files
sbpublicclaude
andcommitted
chore(frontend): DO NOT MERGE — add allowance mode to signer failure simulator
Adds the 'allowance' mode (exhausted per-user ICRC-2 allowance) so the new sign.error.limit_reached message can be reproduced alongside payment/internal/ signing. Merged latest PR #13145 so the limit_reached path is present. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 794ddad commit 9311b75

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/frontend/src/lib/utils/signer-failure-simulator.utils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { browser } from '$app/environment';
2+
import type { PaymentError } from '$declarations/signer/signer.did';
23
import { CanisterInternalError } from '$lib/canisters/errors';
34
import { SignerCanisterPaymentError } from '$lib/canisters/signer.errors';
45
import { LOCAL, STAGING } from '$lib/constants/app.constants';
6+
import { Principal } from '@dfinity/principal';
57
import { isNullish } from '@dfinity/utils';
68

79
/**
@@ -19,11 +21,16 @@ import { isNullish } from '@dfinity/utils';
1921
* - or localStorage: `localStorage.setItem('OISY_SIMULATE_SIGNER_FAILURE', 'payment')`
2022
*
2123
* The query param wins over localStorage. Set the value to `off` (or clear it) to disable.
24+
*
25+
* Modes: `payment` (backend out of cycles → "signer unavailable"), `allowance` (exhausted
26+
* per-user allowance → "signing limit reached"), `internal` / `signing` (generic non-payment
27+
* signer errors → fallback toast).
2228
*/
23-
export type SimulatedSignerFailureMode = 'payment' | 'internal' | 'signing';
29+
export type SimulatedSignerFailureMode = 'payment' | 'allowance' | 'internal' | 'signing';
2430

2531
const SIMULATED_SIGNER_FAILURE_MODES: SimulatedSignerFailureMode[] = [
2632
'payment',
33+
'allowance',
2734
'internal',
2835
'signing'
2936
];
@@ -63,6 +70,16 @@ export const simulateSignerFailureIfEnabled = () => {
6370
});
6471
}
6572

73+
if (mode === 'allowance') {
74+
// Exhausted per-user ICRC-2 allowance → the "signing limit reached" toast.
75+
throw new SignerCanisterPaymentError({
76+
LedgerWithdrawFromError: {
77+
error: { InsufficientAllowance: { allowance: 1_000n } },
78+
ledger: Principal.anonymous()
79+
}
80+
} as unknown as PaymentError);
81+
}
82+
6683
if (mode === 'signing') {
6784
// A non-payment signer error (e.g. a threshold-signing failure) → fallback toast.
6885
throw new CanisterInternalError('Simulated signer SigningError (demo)');

0 commit comments

Comments
 (0)