wallet

Read the customer's wallet balance and a page of their wallet transactions.

Use wallet for an account wallet page: the balance plus a page of transactions. It has no queries, only the plain function.

app/components/WalletBalance.tsx
import { useQuery } from '@tanstack/react-query';
import { useUser } from '@salla.sa/twilight-theme-engine/hooks/useUser';
import { wallet } from '@salla.sa/twilight-theme-engine/api/wallet';

export function WalletBalance() {
  const { isLoggedIn } = useUser();
  const { data } = useQuery({
    queryKey: ['wallet', 'list', { page: 1 }],
    queryFn: () => wallet.list(),
    enabled: isLoggedIn,
  });

  return <p>{data?.balance}</p>;
}

Methods

MethodParametersReturnsRequestLogin needed
listparams?: { page?: number; perPage?: number; signal?: AbortSignal }Promise<{ items: TransactionItem[]; next: string | null; balance: number }>GET balance/wallet?page=1&per_page=10Yes

Defaults: page 1, perPage 10. A TransactionItem has id, order_id, transaction_type, action_type, type, title, description, amount, created_at and expired_at.

Queries

There is no queries object. If you want caching, write your own options with a key that includes the page (and the locale or scope if they matter), as in the example above.

Gotchas

  • Guests have no token and the call fails. Gate it with useUser().isLoggedIn.
  • The balance comes back on every page, next to that page's transactions.
  • next is the API's next_page_url (a URL or null), not a cursor. Request the next page by number.
  • A missing transactions.data becomes []; a missing transactions object throws.
  • Errors are not caught. Handle 401 and 403 yourself, for example with orUnauthorized (Errors).

See also

On this page