diff --git a/src/shared/helpers/i18n.ts b/src/shared/helpers/i18n.ts index 82282762..b312d735 100644 --- a/src/shared/helpers/i18n.ts +++ b/src/shared/helpers/i18n.ts @@ -8,6 +8,12 @@ export type ErrorKeys = Extract< `${string}_${'error' | 'warn'}_${string}` >; +export interface I18nInfo { + key: TranslationKeys; + // Could be empty, but required for checking if an object follows this interface + substitutions: string[]; +} + /** * Error object with key and substitutions based on `_locales/[lang]/messages.json` */ @@ -66,7 +72,7 @@ export function tFactory(browser: Pick) { */ function t( key: T, - substitutions?: string[], + substitutions?: string[] | readonly string[], ): string; function t(err: ErrorWithKeyLike): string; function t(key: string | ErrorWithKeyLike, substitutions?: string[]): string { diff --git a/src/shared/types.ts b/src/shared/types.ts index bde5324f..6bbb5d64 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -1,6 +1,6 @@ import type { WalletAddress } from '@interledger/open-payments'; import type { Tabs } from 'webextension-polyfill'; -import type { ErrorWithKeyLike } from './helpers'; +import type { ErrorWithKeyLike, I18nInfo } from './helpers'; import type { components as RSComponents } from '@interledger/open-payments/dist/openapi/generated/resource-server-types'; export type AmountType = RSComponents['schemas']['amount']; @@ -145,6 +145,50 @@ export type PopupTabInfo = { | never; // just added for code formatting }; +interface WalletStatusBase { + intent: 'connect' | 'reconnect' | 'add_funds' | 'update_budget'; + type: 'success' | 'failure' | 'cancel' | 'progress'; +} + +interface WalletStatusSuccess extends WalletStatusBase { + type: 'success'; +} + +interface WalletStatusProgress extends WalletStatusBase { + type: 'progress'; + currentStep: string | I18nInfo; +} + +export interface WalletStatusFailure extends WalletStatusBase { + type: 'failure'; + code: + | 'grant_continuation_failed' + | 'grant_hash_failed' + | 'grant_invalid' + | 'key_add_failed' + | 'timeout' + | 'unknown'; + /** + * - `auto`: can try to connect automatically (like timeout, bad login, server errors etc.) + * - `manual`: ask user to connect manually, might need some edit to params (budget too high etc.) + * - `false`/`undefined`: cannot retry + */ + retryPossible: 'auto' | 'manual' | false; + details?: ErrorWithKeyLike | { message: string }; +} + +interface WalletStatusCancel extends WalletStatusBase { + type: 'cancel'; + code: 'tab_closed' | 'grant_rejected'; + retryPossible: 'auto'; +} + +export type WalletStatus = + | WalletStatusSuccess + | WalletStatusFailure + | WalletStatusCancel + | WalletStatusProgress; + export type TransientState = Partial<{ connect: | null