Skip to content

Session (Core)

A Swapped Connect session is one payment run identified by sessionId. Load it once, run Wallets, Exchange Pay, or Coinbase while it is active, then call restartSession() before another payment.

For UI, prefer client.getSessionView() (and the sessionView:changed event) over reading raw session.status. The view classifies API status, maintenance, and runtime rejection into screens you can switch on.

Status vs view

LayerTypeUse for
API statusSessionStatus on session.statusDebugging / logging
UI viewSessionView from getSessionView / client.getSessionView()Which screen to render

Only initiated sessions can start a new payment (isSessionActiveForPayments). After completion (or most other terminal views), call restartSession() or the next Wallets / Coinbase / Exchange Pay call hits SESSION_NOT_ACTIVE.

API statuses (SessionStatus)

StatusMeaning
initiatedReady for payment — maps to view active
awaitingConfirmationPayment in progress — waiting screen, or completed if transactionData is already present
awaitingEmailConfirmationUser must confirm email
completedPayment finished — success / restart
failedPayment failed
cancelledSession cancelled — treat as expired in UI
rejectedRegion / geo rejection (view.country, view.rejectReason)

UI views (SessionViewType)

ViewWhenSuggested UI
activeNo session yet, or status initiatedYour normal app (payment methods, Wallets, Coinbase, Exchange Pay)
completedStatus completed, or awaitingConfirmation with transactionDataSuccess summary + Start new session (restartSession)
awaitingConfirmationStatus awaitingConfirmation without transaction data yetWaiting / “payment processing”
awaitingEmailConfirmationStatus awaitingEmailConfirmationAsk the user to confirm email
expiredStatus cancelledSession expired + restart
failedStatus failedFailure message + restart
rejectedRegionStatus rejectedRegion not supported — prefer view.rejectReason (may contain \n; use white-space: pre-line), fall back to view.country
rejectedComplianceRuntime session:rejected (compliance)Compliance blocked — no restart of the same session
maintenanceMaintenance flag enabled (wins over status)Maintenance / try later

completed may include optional view.transaction when the SDK can show a completed-transaction screen. For success details, also use client.wallets.transfer.getCompletedTransactionSummary() (then ensure fees / rates), client.coinbase.getCompletedTransactionSummary(), or client.exchangePay.getCompletedTransactionSummary().

This is the Swapped session. Coinbase OAuth JWT expiry is separate (COINBASE_SESSION_EXPIRED / coinbase:sessionExpired) — reconnect Coinbase, do not confuse it with expired above.

Read the view

ts
import {
  SessionViewType,
  createSwappedConnectClient,
  isSessionActiveForPayments,
} from '@swapped/connect-sdk';

const client = createSwappedConnectClient({ sessionId: 'your-session-id' });
await client.loadSession();

const view = client.getSessionView();
const session = client.getSession();

console.log(view.type);
console.log(session?.session.status);
console.log(isSessionActiveForPayments(session)); // true only when status is initiated

Subscribe when the classified view changes:

ts
client.on('sessionView:changed', ({ view }) => {
  renderForView(view);
});

client.on('session:rejected', () => {
  // usually becomes REJECTED_COMPLIANCE
});

client.on('maintenance:changed', () => {
  // may become MAINTENANCE
});

Render by view

ts
import { SessionViewType, type SessionView } from '@swapped/connect-sdk';

function renderForView(view: SessionView) {
  switch (view.type) {
    case SessionViewType.Active:
      // payment methods → Wallets / Exchange Pay / Coinbase
      break;
    case SessionViewType.Completed: {
      const wallets = client.wallets.transfer.getCompletedTransactionSummary();
      const coinbase = client.coinbase.getCompletedTransactionSummary();
      const exchangePay = client.exchangePay.getCompletedTransactionSummary();
      // show provider summary if present, else generic completed + restart
      break;
    }
    case SessionViewType.RejectedRegion:
      // prefer view.rejectReason (may include \n); fall back to view.country
      break;
    case SessionViewType.RejectedCompliance:
      // compliance blocked
      break;
    case SessionViewType.Expired:
      // expired + restartSession()
      break;
    case SessionViewType.Failed:
      // failed + restartSession()
      break;
    case SessionViewType.AwaitingConfirmation:
      // waiting for confirmation
      break;
    case SessionViewType.AwaitingEmailConfirmation:
      // confirm email
      break;
    case SessionViewType.Maintenance:
      // try later
      break;
  }
}

Lifecycle

  1. createSwappedConnectClient({ sessionId })loadSession()
  2. While view is active, list payment methods and run Wallets, Exchange Pay, or Coinbase
  3. When the view leaves active, show the matching screen above
  4. restartSession() before another payment
  5. destroy() when tearing down
ts
await client.restartSession(); // new payment after completion / expiry / failure
client.destroy();

Errors

CodeWhenWhat to do
SESSION_NOT_ACTIVEStart payment when status ≠ initiatedShow completed / terminal UI; restartSession()
SESSION_REQUIREDAction needs a loaded session (connect, withdraw, create order, …)loadSession() first
SESSION_ID_REQUIREDMissing id on load / restartPass a valid sessionId