@coin-voyage/paykit
Version:
Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.
75 lines • 3.45 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useCallback } from "react";
import { ROUTES } from "../../types/routes";
import usePayContext from "../contexts/pay";
import Modal from "../ui/Modal";
import About from "../Pages/About";
import Connectors from "../Pages/Connectors";
import DownloadApp from "../Pages/DownloadApp";
import MobileConnectors from "../Pages/MobileConnectors";
import Onboarding from "../Pages/Onboarding";
import SwitchNetworks from "../Pages/SwitchNetworks";
import ConnectUsing from "./ConnectUsing";
import { useAccount } from "@coin-voyage/crypto/hooks";
import { ThemeProvider } from "../../providers/theme/provider";
import Confirmation from "../Pages/Confirmation";
import PayWithToken from "../Pages/PayWithToken";
import SelectMethod from "../Pages/SelectMethod";
import SelectToken from "../Pages/SelectToken";
import { useChainIsSupported } from "../../hooks/useChainIsSupported";
const pages = {
[ROUTES.SELECT_METHOD]: _jsx(SelectMethod, {}),
[ROUTES.SELECT_TOKEN]: _jsx(SelectToken, {}),
[ROUTES.CONFIRMATION]: _jsx(Confirmation, {}),
[ROUTES.PAY_WITH_TOKEN]: _jsx(PayWithToken, {}),
[ROUTES.ONBOARDING]: _jsx(Onboarding, {}),
[ROUTES.ABOUT]: _jsx(About, {}),
[ROUTES.DOWNLOAD]: _jsx(DownloadApp, {}),
[ROUTES.CONNECTORS]: _jsx(Connectors, {}),
[ROUTES.MOBILECONNECTORS]: _jsx(MobileConnectors, {}),
[ROUTES.CONNECT]: _jsx(ConnectUsing, {}),
[ROUTES.SWITCHNETWORKS]: _jsx(SwitchNetworks, {}),
};
export function PayModal() {
const { route, setOpen, setRoute, paymentState, options, mode, theme, customTheme, } = usePayContext();
const { setConnectorChainType, resetPayOrder, setSelectedTokenOption } = paymentState;
const { account } = useAccount({
selectedWallet: paymentState.selectedWallet,
chainType: paymentState.connectorChainType,
});
const chainIsSupported = useChainIsSupported(account.chainType, account.chainId);
//if chain is unsupported we enforce a "switch chain" prompt
const closeable = !(options?.enforceSupportedChains &&
account.isConnected &&
!chainIsSupported);
const showBackButton = closeable && ![ROUTES.SELECT_METHOD, ROUTES.CONFIRMATION].includes(route);
const showInfoButton = closeable && ![ROUTES.CONFIRMATION].includes(route);
const onBack = useCallback(() => {
if (route === ROUTES.DOWNLOAD) {
setRoute(ROUTES.CONNECT);
}
else if (route === ROUTES.CONNECTORS) {
setConnectorChainType(undefined);
setRoute(ROUTES.SELECT_METHOD);
}
else if (route === ROUTES.SELECT_TOKEN) {
setConnectorChainType(undefined);
setRoute(ROUTES.SELECT_METHOD);
}
else if (route === ROUTES.PAY_WITH_TOKEN) {
setSelectedTokenOption(undefined);
setRoute(ROUTES.SELECT_TOKEN);
}
else if (route === ROUTES.ONBOARDING) {
setRoute(ROUTES.CONNECTORS);
}
else {
resetPayOrder();
}
}, []);
function hide() {
setOpen(false);
}
return (_jsx(ThemeProvider, { theme: theme, customTheme: customTheme, mode: mode, children: _jsx(Modal, { pages: pages, pageId: route, onClose: closeable ? hide : undefined, onInfo: showInfoButton ? () => setRoute(ROUTES.ABOUT) : undefined, onBack: showBackButton ? onBack : undefined }) }));
}
//# sourceMappingURL=index.js.map