UNPKG

@ledgerhq/live-common

Version:
129 lines 4.06 kB
"use strict"; /** * Simplified Swap Error System * Base error class and specific error types for swap transaction flows */ Object.defineProperty(exports, "__esModule", { value: true }); exports.PayinExtraIdError = exports.UnknownAccountError = exports.ListCurrencyError = exports.ListAccountError = exports.NotEnoughFunds = exports.IgnoredSignatureStepError = exports.SignatureStepError = exports.PayloadStepError = exports.NonceStepError = exports.SwapError = void 0; /** * Base error class for all swap-related errors * Contains error code and nested error information */ class SwapError extends Error { cause; message; constructor(code = "swap000", nestedError) { super(); this.name = "SwapError"; // Preserve nested error information this.cause = { swapCode: code, ...(nestedError?.constructor !== Object && nestedError?.constructor !== Array ? { message: `${nestedError}` } : {}), ...nestedError, }; this.message = nestedError?.message ? nestedError.message : `${nestedError}`; } } exports.SwapError = SwapError; /** * Error during nonce/deviceTransactionId generation step * Typically occurs when calling startSwap() */ class NonceStepError extends SwapError { constructor(nestedError) { super("swap001", nestedError); this.name = "NonceStepError"; } } exports.NonceStepError = NonceStepError; /** * Error during payload retrieval step * Occurs when communicating with backend to get transaction payload */ class PayloadStepError extends SwapError { constructor(nestedError) { super("swap002", nestedError); this.name = "PayloadStepError"; } } exports.PayloadStepError = PayloadStepError; /** * Error during transaction signature step * Occurs when user rejects or device fails during completeSwap() */ class SignatureStepError extends SwapError { constructor(nestedError) { super("swap003", nestedError); this.name = "SignatureStepError"; } } exports.SignatureStepError = SignatureStepError; /** * Special case: signature error that should be ignored/handled silently * Used for expected user cancellations */ class IgnoredSignatureStepError extends SwapError { constructor(nestedError) { super("swap003Ignored", nestedError); this.name = "SignatureStepError"; } } exports.IgnoredSignatureStepError = IgnoredSignatureStepError; /** * Error when user doesn't have sufficient funds * Thrown during balance validation */ class NotEnoughFunds extends SwapError { constructor() { super("swap004"); this.name = "NotEnoughFunds"; } } exports.NotEnoughFunds = NotEnoughFunds; /** * Error when unable to retrieve account list * Occurs during account lookup phase */ class ListAccountError extends SwapError { constructor(nestedError) { super("swap005", nestedError); this.name = "ListAccountError"; } } exports.ListAccountError = ListAccountError; /** * Error when unable to retrieve currency information * Occurs during currency lookup phase */ class ListCurrencyError extends SwapError { constructor(nestedError) { super("swap006", nestedError); this.name = "ListCurrencyError"; } } exports.ListCurrencyError = ListCurrencyError; /** * Error when specified account ID cannot be found * Thrown when fromAccountId or toAccountId is invalid */ class UnknownAccountError extends SwapError { constructor(nestedError) { super("swap007", nestedError); this.name = "UnknownAccountError"; } } exports.UnknownAccountError = UnknownAccountError; /** * Error when extra identifier is required but missing * Some chains require payinExtraId (e.g., XLM memo, XRP tag) */ class PayinExtraIdError extends SwapError { constructor(nestedError) { super("swap010", nestedError); this.name = "PayinExtraIdError"; } } exports.PayinExtraIdError = PayinExtraIdError; //# sourceMappingURL=SwapError.js.map