diff --git a/.changeset/proud-results-cheat.md b/.changeset/proud-results-cheat.md new file mode 100644 index 000000000..e010d837c --- /dev/null +++ b/.changeset/proud-results-cheat.md @@ -0,0 +1,5 @@ +--- +'@solana/errors': minor +--- + +Add `SOLANA_ERROR__WALLET__NOT_CONNECTED` error code for when a wallet operation is attempted without a connected wallet. diff --git a/packages/errors/src/codes.ts b/packages/errors/src/codes.ts index 8131b5981..54c03b4f0 100644 --- a/packages/errors/src/codes.ts +++ b/packages/errors/src/codes.ts @@ -362,6 +362,10 @@ export const SOLANA_ERROR__PROGRAM_CLIENTS__RESOLVED_INSTRUCTION_INPUT_MUST_BE_N export const SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_ACCOUNT_TYPE = 8500005; export const SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT = 8500006; +// Wallet-related errors. +// Reserve error codes in the range [8900000-8900999]. +export const SOLANA_ERROR__WALLET__NOT_CONNECTED = 8900000; + // Invariant violation errors. // Reserve error codes in the range [9900000-9900999]. // These errors should only be thrown when there is a bug with the @@ -678,7 +682,8 @@ export type SolanaErrorCode = | typeof SOLANA_ERROR__TRANSACTION_ERROR__WOULD_EXCEED_ACCOUNT_DATA_TOTAL_LIMIT | typeof SOLANA_ERROR__TRANSACTION_ERROR__WOULD_EXCEED_MAX_ACCOUNT_COST_LIMIT | typeof SOLANA_ERROR__TRANSACTION_ERROR__WOULD_EXCEED_MAX_BLOCK_COST_LIMIT - | typeof SOLANA_ERROR__TRANSACTION_ERROR__WOULD_EXCEED_MAX_VOTE_COST_LIMIT; + | typeof SOLANA_ERROR__TRANSACTION_ERROR__WOULD_EXCEED_MAX_VOTE_COST_LIMIT + | typeof SOLANA_ERROR__WALLET__NOT_CONNECTED; /** * Errors of this type are understood to have an optional {@link SolanaError} nested inside as diff --git a/packages/errors/src/context.ts b/packages/errors/src/context.ts index 2917b3134..0ba9d8f0d 100644 --- a/packages/errors/src/context.ts +++ b/packages/errors/src/context.ts @@ -209,6 +209,7 @@ import { SOLANA_ERROR__TRANSACTION_ERROR__INSUFFICIENT_FUNDS_FOR_RENT, SOLANA_ERROR__TRANSACTION_ERROR__PROGRAM_EXECUTION_TEMPORARILY_RESTRICTED, SOLANA_ERROR__TRANSACTION_ERROR__UNKNOWN, + SOLANA_ERROR__WALLET__NOT_CONNECTED, SolanaErrorCode, } from './codes'; import { RpcSimulateTransactionResult } from './json-rpc-error'; @@ -861,6 +862,9 @@ export type SolanaErrorContext = ReadonlyContextValue< firstByte: number; transactionBytes: ReadonlyUint8Array; }; + [SOLANA_ERROR__WALLET__NOT_CONNECTED]: { + operation: string; + }; } > >; diff --git a/packages/errors/src/messages.ts b/packages/errors/src/messages.ts index 425d3ad70..3e9676327 100644 --- a/packages/errors/src/messages.ts +++ b/packages/errors/src/messages.ts @@ -295,6 +295,7 @@ import { SOLANA_ERROR__TRANSACTION_ERROR__WOULD_EXCEED_MAX_ACCOUNT_COST_LIMIT, SOLANA_ERROR__TRANSACTION_ERROR__WOULD_EXCEED_MAX_BLOCK_COST_LIMIT, SOLANA_ERROR__TRANSACTION_ERROR__WOULD_EXCEED_MAX_VOTE_COST_LIMIT, + SOLANA_ERROR__WALLET__NOT_CONNECTED, SolanaErrorCode, } from './codes'; @@ -812,4 +813,5 @@ export const SolanaErrorMessages: Readonly<{ 'Transaction has $actualCount instructions but the maximum allowed is $maxAllowed', [SOLANA_ERROR__TRANSACTION__TOO_MANY_ACCOUNTS_IN_INSTRUCTION]: 'The instruction at index $instructionIndex has $actualCount account references but the maximum allowed is $maxAllowed', + [SOLANA_ERROR__WALLET__NOT_CONNECTED]: 'Cannot $operation: no wallet connected', };