Appearance
Expiry
Every Exchange Pay order has an expiresAt timestamp (ms since epoch). When it elapses, the SDK emits exchangePay:orderExpired and clears the active order.
When to use
Show a countdown on the checkout screen and handle expired UI (create a new order or go back).
Methods & helpers
| API | Purpose |
|---|---|
client.exchangePay.getActiveOrderExpiresAt() | Active order’s expiresAt, or null |
getExchangePayOrderTimeLeftMs(expiresAt) | Milliseconds remaining (exported helper) |
getExchangePayOrderTimeLeft(expiresAt) | { hours, minutes, seconds } |
isExchangePayOrderExpired(expiresAt) | Whether time is up |
Import helpers from @swapped/connect-sdk.
Example
ts
import {
getExchangePayOrderTimeLeft,
isExchangePayOrderExpired,
} from '@swapped/connect-sdk';
const expiresAt = client.exchangePay.getActiveOrderExpiresAt();
if (expiresAt !== null) {
const { hours, minutes, seconds } = getExchangePayOrderTimeLeft(expiresAt);
console.log(`Time left: ${hours}:${minutes}:${seconds}`);
console.log('expired?', isExchangePayOrderExpired(expiresAt));
}
client.exchangePay.onOrderExpired(({ order }) => {
// Show “order expired”; offer create again
console.log('expired', order.id);
});For a live ticking UI in vanilla JS, poll getExchangePayOrderTimeLeft on an interval, or subscribe to onOrderExpired for the end state. In React, prefer useExchangePayOrderCountdown.
Notes
- Expiry is per order, not a Coinbase-style submission cooldown.
- Provider APIs return expiry in different formats; the SDK normalizes to epoch ms (with a safe fallback if missing).
- After expiry, create a new order — do not reuse the old checkout links.
Errors
Expiry helpers do not throw. Order creation / status errors are covered in Orders and Errors.