UNPKG

@daimo/pay

Version:

Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.

95 lines (94 loc) 3.37 kB
import { DaimoPayOrderID, SolanaPublicKey } from "@daimo/pay-common"; import { Address, Hex } from "viem"; import { PaymentState, PayParams } from "../payment/paymentFsm"; type DaimoPayFunctions = { /** * Create a new Daimo Pay order preview with the given parameters. * Call this to start a new payment flow. * * @param params - Parameters describing the payment to be created. */ createPreviewOrder: (params: PayParams) => Promise<Extract<PaymentState, { type: "preview"; }>>; /** * Set the order ID to fetch and manage an existing Daimo Pay order. * Useful for resuming or referencing a previously created order. * * @param id - The Daimo Pay order ID to set. */ setPayId: (id: DaimoPayOrderID) => Promise<Extract<PaymentState, { type: "unhydrated" | "payment_unpaid" | "payment_started" | "payment_completed" | "payment_bounced"; }>>; /** * Hydrate the current order, locking in the payment intent details and * token swap prices. */ hydrateOrder: (refundAddress?: Address) => Promise<Extract<PaymentState, { type: "payment_unpaid"; }>>; /** Trigger search for payment on the current order. */ paySource: () => void; /** * Register an Ethereum payment source for the current order. * Call this after the user has submitted an Ethereum payment transaction. * * @param args - Details about the Ethereum payment transaction. */ payEthSource: (args: { paymentTxHash: Hex; sourceChainId: number; payerAddress: Address; sourceToken: Address; sourceAmount: bigint; }) => Promise<Extract<PaymentState, { type: "payment_started" | "payment_completed" | "payment_bounced"; }>>; /** * Register a Solana payment source for the current order. * Call this after the user has submitted a Solana payment transaction. * * @param args - Details about the Solana payment transaction. */ paySolanaSource: (args: { paymentTxHash: string; sourceToken: SolanaPublicKey; }) => Promise<Extract<PaymentState, { type: "payment_started" | "payment_completed" | "payment_bounced"; }>>; /** * Reset the current payment state and clear the active order. * Call this to start a new payment flow. */ reset: () => void; /** * Update the user's chosen amount in USD. Applies only to deposit flow. * * @deprecated */ setChosenUsd: (usd: number) => void; }; type DaimoPayState = { [S in PaymentState as S["type"]]: { paymentState: S["type"]; order: S extends { order: infer O; } ? O : null; paymentErrorMessage: S extends { message: infer M; } ? M : null; }; }[PaymentState["type"]]; export type UseDaimoPay = DaimoPayFunctions & DaimoPayState; /** * React hook for interacting with Daimo Pay orders and payments. Use this hook * to manage the lifecycle of a Daimo Pay payment in your application. * * This hook provides a simple interface to create, hydrate, pay, and reset * Daimo Pay orders. * * @returns {UseDaimoPay} An object with current payment state and methods to * manage Daimo Pay orders and payments. */ export declare function useDaimoPay(): UseDaimoPay; export {};