Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/shared/helpers/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
*/
Expand Down Expand Up @@ -66,7 +72,7 @@ export function tFactory(browser: Pick<Browser, 'i18n'>) {
*/
function t<T extends TranslationKeys>(
key: T,
substitutions?: string[],
substitutions?: string[] | readonly string[],
): string;
function t<T extends ErrorKeys>(err: ErrorWithKeyLike<T>): string;
function t(key: string | ErrorWithKeyLike, substitutions?: string[]): string {
Expand Down
46 changes: 45 additions & 1 deletion src/shared/types.ts
Original file line number Diff line number Diff line change
@@ -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'];
Expand Down Expand Up @@ -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
Expand Down
Loading