Skip to content

Errors

How wallet failures surface in React.

  1. Hook error stateuseAvailableWallets().error, useWalletBalances().error, useWalletTransferPlan().error, useWalletTransferQuote().error, useWalletTransfer().error, useWalletTransferMinAmount().error.
  2. Rejected promisesconnect(), disconnect(), submit() / retry() (also copied onto useWalletTransfer().error).
  3. useConnectWallet().errors — last message keyed by provider or walletId. useWallet(provider).error is the same map scoped to that provider.
  4. EventsuseOnWalletTransferStatus (failed / requires_retry); useClientEvent('wallets:error', …).

Branch on ConnectSdkError.code. Full code list: Errors (Core).

tsx
import {
  ConnectSdkError,
  ConnectSdkErrorCode,
} from '@swapped/connect-sdk'
import { useWallet } from '@swapped/connect-sdk/react'

function ConnectButton({ provider }: { provider: IntegrationProvider }) {
  const { connect } = useWallet(provider)

  return (
    <button
      type="button"
      onClick={() => {
        void connect().catch(error => {
          if (
            error instanceof ConnectSdkError &&
            (error.code === ConnectSdkErrorCode.WALLET_CONNECT_REJECTED ||
              error.code === ConnectSdkErrorCode.WALLET_PAIRING_CANCELLED)
          ) {
            return
          }
          // other codes
        })
      }}
    >
      Connect
    </button>
  )
}

WALLET_CONNECT_REJECTED / WALLET_TRANSACTION_REJECTED are user cancels. WALLET_PAIRING_CANCELLED is cancelPairing (or a force: true connect) aborting an in-flight pairing — the demo ignores that one when tearing down the WalletConnect tab.

REACT_WALLETS_PROVIDER_REQUIRED is thrown when a provider-bound hook is used outside WalletsProvider.

useDualAmountInput().error is an AmountValidationError ({ code, message, metadata }), not a ConnectSdkError. code includes below_min.

useDualAmountInput uses the min from useWalletTransferMinAmount.