UNPKG

@coin-voyage/paykit

Version:

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

30 lines (29 loc) 1.39 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { useMemo } from "react"; import usePayContext from "../components/contexts/pay"; import { SquircleIcon } from "../components/ui/Icon"; import { BTC_MIN_USD_AMOUNT } from "../lib/constants"; import { ChainId } from "../server"; import { ROUTE } from "../types/routes"; import { useTokenList } from "./useTokenList"; export function usePayToAddressChainOptions() { const { setRoute, paymentState } = usePayContext(); const { setPayToAddressChainId, payOrder } = paymentState; const fiatAmount = payOrder?.fulfillment.amount.value_usd; const { chains, isLoading } = useTokenList(); const options = useMemo(() => chains.map((chain) => { const disabled = chain.chainId === ChainId.BTC && typeof fiatAmount === "number" && fiatAmount < BTC_MIN_USD_AMOUNT; return { id: chain.chainId.toString(), title: chain.name, icons: [_jsx(SquircleIcon, { icon: chain.logoURI, alt: chain.name }, chain.chainId)], onClick: () => { setPayToAddressChainId(chain.chainId); setRoute(ROUTE.ADDRESS_TOKEN_SELECT); }, disabled, subtitle: disabled ? `Minimum $${BTC_MIN_USD_AMOUNT}` : undefined, }; }), [chains, setPayToAddressChainId, setRoute, fiatAmount]); return { options, isLoading }; }