UNPKG

@coin-voyage/paykit

Version:

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

41 lines 1.78 kB
import { PayOrderStatus } from "@coin-voyage/shared/common"; import usePayContext from "../components/contexts/pay"; /** Returns the current payment, or undefined if there is none. * * Status values: * - `payment_pending` - the user has not paid yet * - `payment_started` - the user has paid & payment is in progress. This status * typically lasts a few seconds. * - `payment_completed` - the final call or transfer succeeded * - `payment_bounced` - the final call or transfer reverted. Funds were sent * - `payment_expired` - the payment expired before the user paid * - `payment_failed` - the payment failed for some reason * to the payment's configured refund address on the destination chain. */ export function usePayStatus() { const { paymentState } = usePayContext(); if (!paymentState || !paymentState.payOrder) { return undefined; } const order = paymentState.payOrder; const paymentId = order.id; if ([PayOrderStatus.EXECUTING_ORDER, PayOrderStatus.COMPLETED].includes(order.status)) { return { paymentId, status: "payment_completed" }; } if (order.status === PayOrderStatus.FAILED) { return { paymentId, status: "payment_failed" }; } if (order.status === PayOrderStatus.REFUNDED) { return { paymentId, status: "payment_bounced" }; } if (order.status === PayOrderStatus.AWAITING_CONFIRMATION) { return { paymentId, status: "payment_started" }; } if (order.status === PayOrderStatus.EXPIRED) { return { paymentId, status: "payment_expired" }; } if ([PayOrderStatus.AWAITING_PAYMENT, PayOrderStatus.PENDING].includes(order.status)) { return { paymentId, status: "payment_pending" }; } } //# sourceMappingURL=usePayStatus.js.map