Skip to content

Commit b440689

Browse files
authored
refactor: add base types for WalletStatus (#1322)
1 parent 695df0b commit b440689

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

src/shared/helpers/i18n.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export type ErrorKeys = Extract<
88
`${string}_${'error' | 'warn'}_${string}`
99
>;
1010

11+
export interface I18nInfo {
12+
key: TranslationKeys;
13+
// Could be empty, but required for checking if an object follows this interface
14+
substitutions: string[];
15+
}
16+
1117
/**
1218
* Error object with key and substitutions based on `_locales/[lang]/messages.json`
1319
*/
@@ -66,7 +72,7 @@ export function tFactory(browser: Pick<Browser, 'i18n'>) {
6672
*/
6773
function t<T extends TranslationKeys>(
6874
key: T,
69-
substitutions?: string[],
75+
substitutions?: string[] | readonly string[],
7076
): string;
7177
function t<T extends ErrorKeys>(err: ErrorWithKeyLike<T>): string;
7278
function t(key: string | ErrorWithKeyLike, substitutions?: string[]): string {

src/shared/types.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { WalletAddress } from '@interledger/open-payments';
22
import type { Tabs } from 'webextension-polyfill';
3-
import type { ErrorWithKeyLike } from './helpers';
3+
import type { ErrorWithKeyLike, I18nInfo } from './helpers';
44
import type { components as RSComponents } from '@interledger/open-payments/dist/openapi/generated/resource-server-types';
55

66
export type AmountType = RSComponents['schemas']['amount'];
@@ -145,6 +145,50 @@ export type PopupTabInfo = {
145145
| never; // just added for code formatting
146146
};
147147

148+
interface WalletStatusBase {
149+
intent: 'connect' | 'reconnect' | 'add_funds' | 'update_budget';
150+
type: 'success' | 'failure' | 'cancel' | 'progress';
151+
}
152+
153+
interface WalletStatusSuccess extends WalletStatusBase {
154+
type: 'success';
155+
}
156+
157+
interface WalletStatusProgress extends WalletStatusBase {
158+
type: 'progress';
159+
currentStep: string | I18nInfo;
160+
}
161+
162+
export interface WalletStatusFailure extends WalletStatusBase {
163+
type: 'failure';
164+
code:
165+
| 'grant_continuation_failed'
166+
| 'grant_hash_failed'
167+
| 'grant_invalid'
168+
| 'key_add_failed'
169+
| 'timeout'
170+
| 'unknown';
171+
/**
172+
* - `auto`: can try to connect automatically (like timeout, bad login, server errors etc.)
173+
* - `manual`: ask user to connect manually, might need some edit to params (budget too high etc.)
174+
* - `false`/`undefined`: cannot retry
175+
*/
176+
retryPossible: 'auto' | 'manual' | false;
177+
details?: ErrorWithKeyLike | { message: string };
178+
}
179+
180+
interface WalletStatusCancel extends WalletStatusBase {
181+
type: 'cancel';
182+
code: 'tab_closed' | 'grant_rejected';
183+
retryPossible: 'auto';
184+
}
185+
186+
export type WalletStatus =
187+
| WalletStatusSuccess
188+
| WalletStatusFailure
189+
| WalletStatusCancel
190+
| WalletStatusProgress;
191+
148192
export type TransientState = Partial<{
149193
connect:
150194
| null

0 commit comments

Comments
 (0)