@binopartner/pay-sdk 0.1.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -2
- package/dist/core/api-base.d.ts +49 -0
- package/dist/core/api-base.js +196 -0
- package/dist/core/appearance.d.ts +17 -0
- package/dist/core/appearance.js +122 -0
- package/dist/core/auth.d.ts +32 -0
- package/dist/core/auth.js +233 -0
- package/dist/core/client.d.ts +71 -0
- package/dist/core/client.js +307 -0
- package/dist/core/clock.d.ts +7 -0
- package/dist/core/clock.js +17 -0
- package/dist/core/errors.d.ts +29 -0
- package/dist/core/errors.js +87 -0
- package/dist/core/events.d.ts +50 -0
- package/dist/core/events.js +1 -0
- package/dist/core/flows/deposit.d.ts +63 -0
- package/dist/core/flows/deposit.js +502 -0
- package/dist/core/flows/withdraw.d.ts +51 -0
- package/dist/core/flows/withdraw.js +413 -0
- package/dist/core/i18n/ar.d.ts +2 -0
- package/dist/core/i18n/ar.js +314 -0
- package/dist/core/i18n/base.d.ts +14 -0
- package/dist/core/i18n/base.js +86 -0
- package/dist/core/i18n/cs.d.ts +2 -0
- package/dist/core/i18n/cs.js +314 -0
- package/dist/core/i18n/de.d.ts +2 -0
- package/dist/core/i18n/de.js +314 -0
- package/dist/core/i18n/en-ui.d.ts +39 -0
- package/dist/core/i18n/en-ui.js +39 -0
- package/dist/core/i18n/en.d.ts +316 -0
- package/dist/core/i18n/en.js +280 -0
- package/dist/core/i18n/es.d.ts +2 -0
- package/dist/core/i18n/es.js +314 -0
- package/dist/core/i18n/fr.d.ts +2 -0
- package/dist/core/i18n/fr.js +314 -0
- package/dist/core/i18n/hi.d.ts +2 -0
- package/dist/core/i18n/hi.js +314 -0
- package/dist/core/i18n/index.d.ts +16 -0
- package/dist/core/i18n/index.js +39 -0
- package/dist/core/i18n/it.d.ts +2 -0
- package/dist/core/i18n/it.js +314 -0
- package/dist/core/i18n/ru.d.ts +2 -0
- package/dist/core/i18n/ru.js +314 -0
- package/dist/core/i18n/tr.d.ts +2 -0
- package/dist/core/i18n/tr.js +314 -0
- package/dist/core/i18n/ua.d.ts +2 -0
- package/dist/core/i18n/ua.js +314 -0
- package/dist/core/index.d.ts +37 -0
- package/dist/core/index.js +19 -0
- package/dist/core/intent.d.ts +13 -0
- package/dist/core/intent.js +45 -0
- package/dist/core/money.d.ts +22 -0
- package/dist/core/money.js +178 -0
- package/dist/core/poll.d.ts +16 -0
- package/dist/core/poll.js +100 -0
- package/dist/core/requisites-frame.d.ts +32 -0
- package/dist/core/requisites-frame.js +202 -0
- package/dist/core/rules/address.d.ts +3 -0
- package/dist/core/rules/address.js +29 -0
- package/dist/core/rules/limits.d.ts +17 -0
- package/dist/core/rules/limits.js +19 -0
- package/dist/core/rules/paying.d.ts +10 -0
- package/dist/core/rules/paying.js +32 -0
- package/dist/core/rules/receipt.d.ts +6 -0
- package/dist/core/rules/receipt.js +40 -0
- package/dist/core/rules/requisites.d.ts +42 -0
- package/dist/core/rules/requisites.js +68 -0
- package/dist/core/rules/slippage.d.ts +1 -0
- package/dist/core/rules/slippage.js +7 -0
- package/dist/core/store.d.ts +15 -0
- package/dist/core/store.js +53 -0
- package/dist/core/types.d.ts +244 -0
- package/dist/core/types.js +1 -0
- package/dist/core/wire.d.ts +178 -0
- package/dist/core/wire.js +602 -0
- package/dist/elements/Root.d.ts +37 -0
- package/dist/elements/Root.js +143 -0
- package/dist/elements/chains.d.ts +1 -0
- package/dist/elements/chains.js +1 -0
- package/dist/elements/components/Qr.d.ts +17 -0
- package/dist/elements/components/Qr.js +28 -0
- package/dist/elements/components/basic.d.ts +42 -0
- package/dist/elements/components/basic.js +129 -0
- package/dist/elements/components/deposit.d.ts +61 -0
- package/dist/elements/components/deposit.js +272 -0
- package/dist/elements/components/inputs.d.ts +24 -0
- package/dist/elements/components/inputs.js +92 -0
- package/dist/elements/components/pickers.d.ts +32 -0
- package/dist/elements/components/pickers.js +267 -0
- package/dist/elements/components/status.d.ts +25 -0
- package/dist/elements/components/status.js +221 -0
- package/dist/elements/context.d.ts +47 -0
- package/dist/elements/context.js +33 -0
- package/dist/elements/hooks/deposit.d.ts +52 -0
- package/dist/elements/hooks/deposit.js +215 -0
- package/dist/elements/hooks/root.d.ts +70 -0
- package/dist/elements/hooks/root.js +125 -0
- package/dist/elements/hooks/withdraw.d.ts +30 -0
- package/dist/elements/hooks/withdraw.js +145 -0
- package/dist/elements/index.d.ts +28 -0
- package/dist/elements/index.js +14 -0
- package/dist/elements/part.d.ts +2 -0
- package/dist/elements/part.js +1 -0
- package/dist/elements/presets/DepositForm.d.ts +32 -0
- package/dist/elements/presets/DepositForm.js +97 -0
- package/dist/elements/presets/WithdrawForm.d.ts +25 -0
- package/dist/elements/presets/WithdrawForm.js +44 -0
- package/dist/elements/presets/focus.d.ts +2 -0
- package/dist/elements/presets/focus.js +26 -0
- package/dist/elements.css +2777 -0
- package/dist/fonts.css +31 -0
- package/dist/frame.d.ts +1 -0
- package/dist/frame.js +37 -6
- package/dist/types.d.ts +1 -0
- package/dist/ui/chains.d.ts +3 -0
- package/dist/ui/chains.js +42 -0
- package/dist/ui/context.d.ts +51 -0
- package/dist/ui/context.js +63 -0
- package/dist/ui/crypto.d.ts +67 -0
- package/dist/ui/crypto.js +68 -0
- package/dist/ui/entry.d.ts +25 -0
- package/dist/ui/entry.js +26 -0
- package/dist/ui/fiat.d.ts +94 -0
- package/dist/ui/fiat.js +149 -0
- package/dist/ui/fields.d.ts +76 -0
- package/dist/ui/fields.js +71 -0
- package/dist/ui/fonts.d.ts +4 -0
- package/dist/ui/fonts.js +31 -0
- package/dist/ui/icons.d.ts +39 -0
- package/dist/ui/icons.js +116 -0
- package/dist/ui/index.d.ts +31 -0
- package/dist/ui/index.js +17 -0
- package/dist/ui/layout.d.ts +36 -0
- package/dist/ui/layout.js +44 -0
- package/dist/ui/logos.d.ts +14 -0
- package/dist/ui/logos.js +61 -0
- package/dist/ui/part.d.ts +32 -0
- package/dist/ui/part.js +33 -0
- package/dist/ui/pickers.d.ts +71 -0
- package/dist/ui/pickers.js +167 -0
- package/dist/ui/qr-encode.d.ts +30 -0
- package/dist/ui/qr-encode.js +340 -0
- package/dist/ui/summary.d.ts +31 -0
- package/dist/ui/summary.js +36 -0
- package/dist/ui/types.d.ts +67 -0
- package/dist/ui/types.js +1 -0
- package/dist/ui/urls.d.ts +4 -0
- package/dist/ui/urls.js +41 -0
- package/dist/ui/withdraw.d.ts +38 -0
- package/dist/ui/withdraw.js +30 -0
- package/dist/ui.css +2699 -0
- package/dist/widget-url.d.ts +1 -0
- package/dist/widget-url.js +16 -0
- package/package.json +46 -5
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
4
|
+
import * as Legacy from "../react.js";
|
|
5
|
+
import { resolveSkin, resolveTheme, themeVariables } from "../core/appearance.js";
|
|
6
|
+
import { createPayClient } from "../core/client.js";
|
|
7
|
+
import { FALLBACK_CODES } from "../core/errors.js";
|
|
8
|
+
import { createDepositFlow } from "../core/flows/deposit.js";
|
|
9
|
+
import { createWithdrawFlow } from "../core/flows/withdraw.js";
|
|
10
|
+
import { createTranslator, intlLocale, isRtlLocale, resolveLocale, } from "../core/i18n/index.js";
|
|
11
|
+
import { createStore } from "../core/store.js";
|
|
12
|
+
import { PayUiValueProvider, usePayUiValue } from "../ui/context.js";
|
|
13
|
+
import { registerFontFaces } from "../ui/fonts.js";
|
|
14
|
+
import { PayRootContext, useStoreValue } from "./context.js";
|
|
15
|
+
import { cx } from "./part.js";
|
|
16
|
+
const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
17
|
+
const legacyTheme = (theme) => theme === "light" || theme === "dark" ? theme : undefined;
|
|
18
|
+
export const Root = forwardRef(function Root(props, ref) {
|
|
19
|
+
const { mode, clientId, allowedApiOrigins, allowedWidgetOrigins, apiBase, locale: localeProp, messages, appearance, open: openProp, defaultOpen = true, onOpenChange, onEvent, fallback = "error", platformUrl, returnUrl, unstyled = false, assetBaseUrl, fontBaseUrl, fetch: fetchProp, sessionEndpoint, createSession: createSessionProp, children, className, style, ...rest } = props;
|
|
20
|
+
const latest = useRef(props);
|
|
21
|
+
useIsomorphicLayoutEffect(() => {
|
|
22
|
+
latest.current = props;
|
|
23
|
+
});
|
|
24
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
|
|
25
|
+
const open = openProp ?? uncontrolledOpen;
|
|
26
|
+
const [generation, setGeneration] = useState(0);
|
|
27
|
+
const hasCreateSession = typeof createSessionProp === "function";
|
|
28
|
+
const allowedApiKey = allowedApiOrigins?.join(" ") ?? null;
|
|
29
|
+
const allowedWidgetKey = allowedWidgetOrigins?.join(" ") ?? null;
|
|
30
|
+
const locale = useMemo(() => resolveLocale(localeProp), [localeProp]);
|
|
31
|
+
const setOpen = useCallback((next) => {
|
|
32
|
+
if (latest.current.open === undefined)
|
|
33
|
+
setUncontrolledOpen(next);
|
|
34
|
+
latest.current.onOpenChange?.(next);
|
|
35
|
+
}, []);
|
|
36
|
+
const createSession = useCallback((context) => {
|
|
37
|
+
const source = latest.current.createSession;
|
|
38
|
+
return source
|
|
39
|
+
? source(context)
|
|
40
|
+
: Promise.reject(new Error("createSession is no longer provided"));
|
|
41
|
+
}, []);
|
|
42
|
+
const client = useMemo(() => createPayClient({
|
|
43
|
+
mode,
|
|
44
|
+
...(hasCreateSession ? { createSession } : { sessionEndpoint }),
|
|
45
|
+
clientId,
|
|
46
|
+
allowedApiOrigins: allowedApiKey === null ? undefined : allowedApiKey.split(" ").filter(Boolean),
|
|
47
|
+
allowedWidgetOrigins: allowedWidgetKey === null ? undefined : allowedWidgetKey.split(" ").filter(Boolean),
|
|
48
|
+
apiBase,
|
|
49
|
+
locale,
|
|
50
|
+
fetch: fetchProp,
|
|
51
|
+
onEvent: (event) => latest.current.onEvent?.(event),
|
|
52
|
+
}), [
|
|
53
|
+
mode,
|
|
54
|
+
hasCreateSession,
|
|
55
|
+
createSession,
|
|
56
|
+
sessionEndpoint,
|
|
57
|
+
clientId,
|
|
58
|
+
allowedApiKey,
|
|
59
|
+
allowedWidgetKey,
|
|
60
|
+
apiBase,
|
|
61
|
+
locale,
|
|
62
|
+
fetchProp,
|
|
63
|
+
generation,
|
|
64
|
+
]);
|
|
65
|
+
const flow = useMemo(() => mode === "deposit"
|
|
66
|
+
? createDepositFlow(client, { returnUrl, onrampTheme: legacyTheme(appearance?.theme ?? "") })
|
|
67
|
+
: createWithdrawFlow(client), [client, mode]);
|
|
68
|
+
const picker = useMemo(() => createStore({ cryptoOpen: false, cryptoCurrency: null, tab: null, country: null, fiatMethodId: null }), [flow]);
|
|
69
|
+
const cryptoCache = useMemo(() => new Map(), [client]);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!open)
|
|
72
|
+
return;
|
|
73
|
+
const release = client.retain();
|
|
74
|
+
flow.actions.start();
|
|
75
|
+
return () => {
|
|
76
|
+
release();
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
if (client.destroyed)
|
|
79
|
+
flow.actions.destroy();
|
|
80
|
+
}, 0);
|
|
81
|
+
};
|
|
82
|
+
}, [client, flow, open]);
|
|
83
|
+
const wasOpen = useRef(open);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (wasOpen.current && !open)
|
|
86
|
+
setGeneration((value) => value + 1);
|
|
87
|
+
wasOpen.current = open;
|
|
88
|
+
}, [open]);
|
|
89
|
+
const restart = useCallback(() => setGeneration((value) => value + 1), []);
|
|
90
|
+
const clientState = useStoreValue(client.state);
|
|
91
|
+
const flowState = useStoreValue(flow);
|
|
92
|
+
const branding = flowState.context?.branding ?? null;
|
|
93
|
+
const theme = resolveTheme(appearance, branding);
|
|
94
|
+
const skin = resolveSkin(appearance);
|
|
95
|
+
const variables = useMemo(() => themeVariables(branding, appearance), [branding, appearance]);
|
|
96
|
+
const messagesKey = JSON.stringify(messages ?? {});
|
|
97
|
+
const t = useMemo(() => createTranslator(locale, JSON.parse(messagesKey)), [locale, messagesKey]);
|
|
98
|
+
const dir = isRtlLocale(locale) ? "rtl" : "ltr";
|
|
99
|
+
const lastReachable = useRef("");
|
|
100
|
+
if (clientState.status === "ready")
|
|
101
|
+
lastReachable.current = client.widgetOrigins().join(" ") || lastReachable.current;
|
|
102
|
+
const reachableKey = lastReachable.current;
|
|
103
|
+
const reachable = useMemo(() => reachableKey.split(" ").filter(Boolean), [reachableKey]);
|
|
104
|
+
const uiValue = usePayUiValue({ locale, t, dir, unstyled, assetBaseUrl: assetBaseUrl ?? reachable[0] });
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (fontBaseUrl === false)
|
|
107
|
+
return;
|
|
108
|
+
registerFontFaces(fontBaseUrl ? [fontBaseUrl] : reachable.map((origin) => `${origin}/fonts`));
|
|
109
|
+
}, [fontBaseUrl, reachable]);
|
|
110
|
+
const value = useMemo(() => ({
|
|
111
|
+
client,
|
|
112
|
+
mode,
|
|
113
|
+
flow,
|
|
114
|
+
open,
|
|
115
|
+
setOpen,
|
|
116
|
+
restart,
|
|
117
|
+
t,
|
|
118
|
+
locale,
|
|
119
|
+
intl: intlLocale(locale),
|
|
120
|
+
dir,
|
|
121
|
+
theme: theme === "auto" ? undefined : theme,
|
|
122
|
+
skin,
|
|
123
|
+
unstyled,
|
|
124
|
+
picker,
|
|
125
|
+
cryptoCache,
|
|
126
|
+
}), [client, mode, flow, open, setOpen, restart, t, locale, dir, theme, skin, unstyled, picker, cryptoCache]);
|
|
127
|
+
const fallbackActive = fallback === "iframe" &&
|
|
128
|
+
clientState.status === "error" &&
|
|
129
|
+
clientState.error !== null &&
|
|
130
|
+
FALLBACK_CODES.has(clientState.error.code);
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (fallbackActive)
|
|
133
|
+
flow.actions.destroy();
|
|
134
|
+
}, [fallbackActive, flow]);
|
|
135
|
+
const rootStyle = { ...variables, ...style };
|
|
136
|
+
return (_jsx("div", { ...rest, ref: ref, className: cx(!unstyled && "bp-root", className), style: rootStyle, "data-binodex-pay": "root", "data-theme": theme, "data-skin": skin, "data-mode": mode, "data-state": open ? "open" : "closed", "data-status": clientState.status, "data-fallback": fallbackActive ? "iframe" : undefined, dir: dir, lang: intlLocale(locale), children: fallbackActive ? (_jsx(LegacyFallback, { mode: mode, sessionEndpoint: sessionEndpoint, createSession: hasCreateSession ? createSession : undefined, clientId: clientId, platformUrl: platformUrl, allowedWidgetOrigins: allowedWidgetOrigins, lang: intlLocale(locale), theme: theme === "auto" ? undefined : theme, open: open, setOpen: setOpen, onEvent: (event) => latest.current.onEvent?.(event), loading: t("common.loading") })) : (_jsx(PayRootContext.Provider, { value: value, children: _jsx(PayUiValueProvider, { value: uiValue, children: children }) })) }));
|
|
137
|
+
});
|
|
138
|
+
function LegacyFallback(props) {
|
|
139
|
+
const source = props.createSession
|
|
140
|
+
? { createSession: props.createSession }
|
|
141
|
+
: { sessionEndpoint: props.sessionEndpoint ?? "" };
|
|
142
|
+
return (_jsxs(Legacy.Root, { ...source, mode: props.mode, clientId: props.clientId, platformUrl: props.platformUrl, allowedWidgetOrigins: props.allowedWidgetOrigins, lang: props.lang, theme: props.theme, open: props.open, onOpenChange: props.setOpen, onCredited: () => undefined, onError: (error) => props.onEvent({ type: "error", code: "SESSION_FAILED", scope: `fallback:${error.code}`, at: Date.now(), source: "client" }), children: [_jsx(Legacy.Loader, { className: "bp-loader", children: props.loading }), _jsx(Legacy.Status, { className: "bp-error" }), _jsx(Legacy.Frame, { title: props.mode === "withdraw" ? "Withdraw" : "Deposit" })] }));
|
|
143
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { chainName, explorerUrl, orderBy } from "../ui/chains.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { chainName, explorerUrl, orderBy } from "../ui/chains.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type SVGAttributes } from "react";
|
|
2
|
+
import type { QrEcc } from "../../ui/qr-encode.js";
|
|
3
|
+
import { type PartStyleProps } from "../part.js";
|
|
4
|
+
export type QrProps = Omit<SVGAttributes<SVGSVGElement>, "className" | "style" | "children"> & PartStyleProps & {
|
|
5
|
+
value: string;
|
|
6
|
+
fallbackUrl?: string | null;
|
|
7
|
+
size?: number;
|
|
8
|
+
ecc?: QrEcc;
|
|
9
|
+
label?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const Qr: import("react").ForwardRefExoticComponent<Omit<SVGAttributes<SVGSVGElement>, "style" | "children" | "className"> & PartStyleProps & {
|
|
12
|
+
value: string;
|
|
13
|
+
fallbackUrl?: string | null;
|
|
14
|
+
size?: number;
|
|
15
|
+
ecc?: QrEcc;
|
|
16
|
+
label?: string;
|
|
17
|
+
} & import("react").RefAttributes<SVGSVGElement>>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import { QrSvg, qrMatrixOf } from "../../ui/crypto.js";
|
|
5
|
+
import { usePayRoot } from "../context.js";
|
|
6
|
+
import { partProps } from "../part.js";
|
|
7
|
+
const safeHttps = (value) => {
|
|
8
|
+
if (!value)
|
|
9
|
+
return null;
|
|
10
|
+
try {
|
|
11
|
+
return new URL(value).protocol === "https:" ? value : null;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const Qr = forwardRef(function Qr({ value, fallbackUrl, size = 176, ecc = "M", label, className, style, unstyled, ...rest }, ref) {
|
|
18
|
+
const root = usePayRoot("<Pay.Qr>");
|
|
19
|
+
if (!qrMatrixOf(value, ecc, 4)) {
|
|
20
|
+
const part = partProps("qr", { className, style, unstyled }, root.unstyled, { sensitive: true });
|
|
21
|
+
const image = safeHttps(fallbackUrl);
|
|
22
|
+
if (image) {
|
|
23
|
+
return (_jsx("img", { ...part, src: image, alt: label ?? root.t("qr.label"), width: size, height: size, referrerPolicy: "no-referrer", "data-fallback": "" }));
|
|
24
|
+
}
|
|
25
|
+
return (_jsx("div", { ...part, role: "alert", "data-error": "QR_UNAVAILABLE", children: root.t("error.UNKNOWN") }));
|
|
26
|
+
}
|
|
27
|
+
return (_jsx(QrSvg, { ...rest, ref: ref, value: value, size: size, ecc: ecc, label: label, className: className, style: style, unstyled: unstyled ?? root.unstyled }));
|
|
28
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type HTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
import { type PayError } from "../../core/errors.js";
|
|
3
|
+
import type { DepositFlowState } from "../../core/flows/deposit.js";
|
|
4
|
+
import type { WithdrawFlowState } from "../../core/flows/withdraw.js";
|
|
5
|
+
import { type MessageKey } from "../../core/i18n/index.js";
|
|
6
|
+
import type { FiatRail } from "../../core/types.js";
|
|
7
|
+
import * as ui from "../../ui/index.js";
|
|
8
|
+
import { type PartStyleProps } from "../part.js";
|
|
9
|
+
type DivProps<C = ReactNode> = Omit<HTMLAttributes<HTMLDivElement>, "className" | "style" | "children"> & PartStyleProps & {
|
|
10
|
+
children?: C;
|
|
11
|
+
};
|
|
12
|
+
export declare const useFlowState: (owner: string) => {
|
|
13
|
+
root: import("../context.js").PayRootValue;
|
|
14
|
+
state: DepositFlowState | WithdrawFlowState;
|
|
15
|
+
};
|
|
16
|
+
export declare const railKey: (rail: FiatRail, key: string) => MessageKey;
|
|
17
|
+
export declare const Trigger: import("react").ForwardRefExoticComponent<Omit<ButtonHTMLAttributes<HTMLButtonElement>, "style" | "className"> & ui.PartStyleProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
18
|
+
export declare const Close: import("react").ForwardRefExoticComponent<Omit<ButtonHTMLAttributes<HTMLButtonElement>, "style" | "className"> & ui.PartStyleProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
19
|
+
export declare const Loader: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
22
|
+
export type ErrorMessageProps = DivProps<ReactNode | ((error: PayError) => ReactNode)> & {
|
|
23
|
+
retry?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare const ErrorMessage: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
26
|
+
children?: ReactNode | ((error: PayError) => ReactNode);
|
|
27
|
+
} & {
|
|
28
|
+
retry?: boolean;
|
|
29
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
30
|
+
export type BalanceProps = Omit<HTMLAttributes<HTMLSpanElement>, "className" | "style" | "children"> & PartStyleProps & {
|
|
31
|
+
children?: ReactNode | ((formatted: string, value: string | null) => ReactNode);
|
|
32
|
+
variant?: "available" | "withdrawable";
|
|
33
|
+
label?: ReactNode;
|
|
34
|
+
};
|
|
35
|
+
export declare const Balance: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLSpanElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
36
|
+
children?: ReactNode | ((formatted: string, value: string | null) => ReactNode);
|
|
37
|
+
variant?: "available" | "withdrawable";
|
|
38
|
+
label?: ReactNode;
|
|
39
|
+
} & import("react").RefAttributes<HTMLSpanElement>>;
|
|
40
|
+
export declare const BackButton: import("react").ForwardRefExoticComponent<Omit<ButtonHTMLAttributes<HTMLButtonElement>, "style" | "className"> & ui.PartStyleProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
41
|
+
export declare const SubmitButton: import("react").ForwardRefExoticComponent<Omit<ButtonHTMLAttributes<HTMLButtonElement>, "style" | "className"> & ui.PartStyleProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, } from "react";
|
|
4
|
+
import { isRetryable } from "../../core/errors.js";
|
|
5
|
+
import { errorMessage } from "../../core/i18n/index.js";
|
|
6
|
+
import { formatMoney } from "../../core/money.js";
|
|
7
|
+
import * as ui from "../../ui/index.js";
|
|
8
|
+
import { balanceText } from "../../ui/context.js";
|
|
9
|
+
import { usePayRoot, useStoreValue } from "../context.js";
|
|
10
|
+
import { partProps } from "../part.js";
|
|
11
|
+
export const useFlowState = (owner) => {
|
|
12
|
+
const root = usePayRoot(owner);
|
|
13
|
+
const state = useStoreValue(root.flow);
|
|
14
|
+
return { root, state };
|
|
15
|
+
};
|
|
16
|
+
export const railKey = (rail, key) => `fiat.${rail}.${key}`;
|
|
17
|
+
export const Trigger = forwardRef(function Trigger({ onClick, type = "button", children, className, style, unstyled, ...rest }, ref) {
|
|
18
|
+
const root = usePayRoot("<Pay.Trigger>");
|
|
19
|
+
return (_jsx("button", { type: type, "aria-expanded": root.open, ...rest, ref: ref, ...partProps("trigger", { className, style, unstyled }, root.unstyled), "data-state": root.open ? "open" : "closed", onClick: (event) => {
|
|
20
|
+
onClick?.(event);
|
|
21
|
+
if (!event.defaultPrevented)
|
|
22
|
+
root.setOpen(true);
|
|
23
|
+
}, children: children ?? root.t(root.mode === "withdraw" ? "trigger.withdraw" : "trigger.deposit") }));
|
|
24
|
+
});
|
|
25
|
+
export const Close = forwardRef(function Close({ onClick, children, ...rest }, ref) {
|
|
26
|
+
const root = usePayRoot("<Pay.Close>");
|
|
27
|
+
if (!root.open)
|
|
28
|
+
return null;
|
|
29
|
+
return (_jsx(ui.CloseButton, { ...rest, ref: ref, label: children ? undefined : root.t("common.close"), "data-state": "open", onClick: (event) => {
|
|
30
|
+
onClick?.(event);
|
|
31
|
+
if (event.defaultPrevented)
|
|
32
|
+
return;
|
|
33
|
+
root.client.emit({ type: "close.requested" });
|
|
34
|
+
root.setOpen(false);
|
|
35
|
+
}, children: children }));
|
|
36
|
+
});
|
|
37
|
+
const LOADING_STEPS = new Set(["loading", "creating"]);
|
|
38
|
+
export const Loader = forwardRef(function Loader({ children, className, style, unstyled, ...rest }, ref) {
|
|
39
|
+
const { root, state } = useFlowState("<Pay.Loader>");
|
|
40
|
+
const client = useStoreValue(root.client.state);
|
|
41
|
+
const busy = root.open &&
|
|
42
|
+
client.status !== "error" &&
|
|
43
|
+
(client.status === "idle" || client.status === "session" || LOADING_STEPS.has(state.step));
|
|
44
|
+
if (!busy)
|
|
45
|
+
return null;
|
|
46
|
+
if (children !== undefined) {
|
|
47
|
+
return (_jsx("div", { role: "status", "aria-live": "polite", ...rest, ref: ref, ...partProps("loader", { className, style, unstyled }, root.unstyled), "data-status": client.status, "data-step": state.step, children: children }));
|
|
48
|
+
}
|
|
49
|
+
return (_jsx(ui.Loader, { ...rest, ref: ref, className: className, style: style, unstyled: unstyled, "data-status": client.status, "data-step": state.step }));
|
|
50
|
+
});
|
|
51
|
+
export const ErrorMessage = forwardRef(function ErrorMessage({ children, retry = true, className, style, unstyled, ...rest }, ref) {
|
|
52
|
+
const { root, state } = useFlowState("<Pay.ErrorMessage>");
|
|
53
|
+
const client = useStoreValue(root.client.state);
|
|
54
|
+
const submitError = state.submitError && !state.submitError.code.startsWith("TWO_FA_") ? state.submitError : null;
|
|
55
|
+
const error = client.error ?? state.error ?? submitError;
|
|
56
|
+
if (!root.open || !error)
|
|
57
|
+
return null;
|
|
58
|
+
const sessionLevel = client.error !== null;
|
|
59
|
+
const canRetry = retry && (sessionLevel || state.error !== null) && isRetryable(error);
|
|
60
|
+
return (_jsxs(ui.ErrorBox, { ...rest, ref: ref, part: "error", variant: root.mode === "withdraw" ? "withdraw" : "deposit", className: className, style: style, unstyled: unstyled, "data-error": error.code, children: [typeof children === "function"
|
|
61
|
+
? children(error)
|
|
62
|
+
: (children ?? _jsx("div", { children: errorMessage(root.t, error, root.locale) })), canRetry && typeof children !== "function" && (_jsx("button", { type: "button", className: (unstyled ?? root.unstyled) ? undefined : "bp-max-button", "data-binodex-pay": "retry", onClick: () => (sessionLevel ? root.restart() : root.flow.actions.retry()), children: root.t("withdraw.retry") }))] }));
|
|
63
|
+
});
|
|
64
|
+
export const Balance = forwardRef(function Balance({ variant, label, children, className, style, unstyled, ...rest }, ref) {
|
|
65
|
+
const { root, state } = useFlowState("<Pay.Balance>");
|
|
66
|
+
const balance = state.context?.balance;
|
|
67
|
+
if (!balance)
|
|
68
|
+
return null;
|
|
69
|
+
const kind = variant ?? (root.mode === "withdraw" ? "withdrawable" : "available");
|
|
70
|
+
const value = kind === "withdrawable" ? (balance.withdrawable ?? balance.available) : balance.available;
|
|
71
|
+
const formatted = balance.currency.toUpperCase() === "USD" ? balanceText(value) : formatMoney(value, balance.currency, root.intl);
|
|
72
|
+
return (_jsx("span", { ...rest, ref: ref, ...partProps("balance", { className, style, unstyled }, root.unstyled), "data-variant": kind, children: typeof children === "function" ? (children(formatted, value)) : (_jsxs(_Fragment, { children: [_jsx("span", { "data-binodex-pay": "balance-label", children: label ?? root.t("header.balance") }), ": ", _jsx("span", { "data-binodex-pay": "balance-value", children: formatted })] })) }));
|
|
73
|
+
});
|
|
74
|
+
export const BackButton = forwardRef(function BackButton({ onClick, children, ...rest }, ref) {
|
|
75
|
+
const { root, state } = useFlowState("<Pay.BackButton>");
|
|
76
|
+
const picker = useStoreValue(root.picker);
|
|
77
|
+
if (root.mode !== "deposit")
|
|
78
|
+
return null;
|
|
79
|
+
const step = state.step;
|
|
80
|
+
const cryptoScreen = step === "pick-method" && picker.cryptoOpen;
|
|
81
|
+
if (!cryptoScreen && (step === "loading" || step === "pick-method" || step === "error" || step === "creating")) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return (_jsx(ui.BackButton, { ...rest, ref: ref, label: children ? undefined : root.t("common.back"), onClick: (event) => {
|
|
85
|
+
onClick?.(event);
|
|
86
|
+
if (event.defaultPrevented)
|
|
87
|
+
return;
|
|
88
|
+
if (cryptoScreen) {
|
|
89
|
+
root.picker.set({ cryptoOpen: false });
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
root.flow.actions.back();
|
|
93
|
+
if (state.method?.kind === "crypto")
|
|
94
|
+
root.picker.set({ cryptoOpen: false });
|
|
95
|
+
}, children: children }));
|
|
96
|
+
});
|
|
97
|
+
export const SubmitButton = forwardRef(function SubmitButton({ onClick, type = "button", children, disabled, ...rest }, ref) {
|
|
98
|
+
const { root, state } = useFlowState("<Pay.SubmitButton>");
|
|
99
|
+
let pending = false;
|
|
100
|
+
let ready = false;
|
|
101
|
+
let label;
|
|
102
|
+
if (root.mode === "deposit") {
|
|
103
|
+
const deposit = state;
|
|
104
|
+
if (deposit.step !== "enter-amount" && deposit.step !== "creating")
|
|
105
|
+
return null;
|
|
106
|
+
if (deposit.method?.kind !== "fiat")
|
|
107
|
+
return null;
|
|
108
|
+
pending = deposit.step === "creating";
|
|
109
|
+
ready = !!deposit.amount && !deposit.amountError;
|
|
110
|
+
label = root.t(railKey(deposit.method.rail, pending ? "submitting" : "submit"));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const withdraw = state;
|
|
114
|
+
if (withdraw.step === "status" || withdraw.step === "loading" || withdraw.step === "error")
|
|
115
|
+
return null;
|
|
116
|
+
pending = withdraw.step === "submitting" || withdraw.step === "quoting";
|
|
117
|
+
ready =
|
|
118
|
+
!!withdraw.quote &&
|
|
119
|
+
!withdraw.addressError &&
|
|
120
|
+
!withdraw.amountError &&
|
|
121
|
+
(withdraw.step !== "two-factor" || withdraw.twoFactorCode.length === 6);
|
|
122
|
+
label = root.t(withdraw.step === "submitting" ? "withdraw.submitting" : "withdraw.submit");
|
|
123
|
+
}
|
|
124
|
+
return (_jsx(ui.SubmitButton, { type: type, ...rest, ref: ref, variant: root.mode === "withdraw" ? "withdraw" : "pay", disabled: disabled || pending || !ready, pending: pending, onClick: (event) => {
|
|
125
|
+
onClick?.(event);
|
|
126
|
+
if (!event.defaultPrevented)
|
|
127
|
+
void root.flow.actions.submit();
|
|
128
|
+
}, children: children ?? label }));
|
|
129
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type AnchorHTMLAttributes, type ButtonHTMLAttributes, type HTMLAttributes, type IframeHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
import * as ui from "../../ui/index.js";
|
|
3
|
+
import { type PartStyleProps } from "../part.js";
|
|
4
|
+
type DivProps = Omit<HTMLAttributes<HTMLDivElement>, "className" | "style" | "children"> & PartStyleProps & {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
export declare const CryptoAddress: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
} & {
|
|
10
|
+
showQr?: boolean;
|
|
11
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
12
|
+
export type RequisitesProps = DivProps & {
|
|
13
|
+
frameTitle?: string;
|
|
14
|
+
readyTimeoutMs?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const Requisites: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
} & {
|
|
19
|
+
frameTitle?: string;
|
|
20
|
+
readyTimeoutMs?: number;
|
|
21
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
22
|
+
export type RequisitesFrameProps = DivProps & {
|
|
23
|
+
depositId: string;
|
|
24
|
+
origins?: readonly string[];
|
|
25
|
+
path?: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
readyTimeoutMs?: number;
|
|
28
|
+
};
|
|
29
|
+
export declare const RequisitesFrame: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
30
|
+
children?: ReactNode;
|
|
31
|
+
} & {
|
|
32
|
+
depositId: string;
|
|
33
|
+
origins?: readonly string[];
|
|
34
|
+
path?: string;
|
|
35
|
+
title?: string;
|
|
36
|
+
readyTimeoutMs?: number;
|
|
37
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
38
|
+
export declare const ReceiptUpload: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
} & {
|
|
41
|
+
accept?: string;
|
|
42
|
+
} & import("react").RefAttributes<HTMLInputElement>>;
|
|
43
|
+
export declare const Countdown: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
44
|
+
children?: ReactNode;
|
|
45
|
+
} & {
|
|
46
|
+
expiresAt?: number | null;
|
|
47
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
48
|
+
export declare const RedirectButton: import("react").ForwardRefExoticComponent<Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "style" | "className" | "rel" | "href" | "target"> & ui.PartStyleProps & import("react").RefAttributes<HTMLAnchorElement>>;
|
|
49
|
+
export declare const RestartButton: import("react").ForwardRefExoticComponent<Omit<ButtonHTMLAttributes<HTMLButtonElement>, "style" | "className"> & ui.PartStyleProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
50
|
+
export declare const MethodNotice: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
51
|
+
children?: ReactNode;
|
|
52
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
53
|
+
export type OnrampProps = Omit<IframeHTMLAttributes<HTMLIFrameElement>, "className" | "style" | "src"> & PartStyleProps & {
|
|
54
|
+
display?: "embed" | "tab";
|
|
55
|
+
height?: number;
|
|
56
|
+
};
|
|
57
|
+
export declare const Onramp: import("react").ForwardRefExoticComponent<Omit<IframeHTMLAttributes<HTMLIFrameElement>, "style" | "src" | "className"> & ui.PartStyleProps & {
|
|
58
|
+
display?: "embed" | "tab";
|
|
59
|
+
height?: number;
|
|
60
|
+
} & import("react").RefAttributes<HTMLIFrameElement>>;
|
|
61
|
+
export {};
|