@binopartner/pay-sdk 0.1.1 → 0.3.0
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 +33 -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,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import { safeImageUrl } from "../../core/appearance.js";
|
|
5
|
+
import * as ui from "../../ui/index.js";
|
|
6
|
+
import { useDepositFlowStore, useStoreValue } from "../context.js";
|
|
7
|
+
import { useStepFocus } from "./focus.js";
|
|
8
|
+
import { partProps } from "../part.js";
|
|
9
|
+
import { BackButton, Balance, Close, ErrorMessage, Loader, SubmitButton, } from "../components/basic.js";
|
|
10
|
+
import { Countdown, CryptoAddress, MethodNotice, Onramp, ReceiptUpload, RedirectButton, Requisites, RestartButton, } from "../components/deposit.js";
|
|
11
|
+
import { AmountInput, PhoneInput } from "../components/inputs.js";
|
|
12
|
+
import { CurrencyPicker, MethodPicker, NetworkPicker } from "../components/pickers.js";
|
|
13
|
+
import { Quote, Status } from "../components/status.js";
|
|
14
|
+
const DEFAULTS = {
|
|
15
|
+
Loader,
|
|
16
|
+
ErrorMessage,
|
|
17
|
+
Balance,
|
|
18
|
+
BackButton,
|
|
19
|
+
Close,
|
|
20
|
+
MethodPicker,
|
|
21
|
+
CurrencyPicker,
|
|
22
|
+
NetworkPicker,
|
|
23
|
+
AmountInput,
|
|
24
|
+
PhoneInput,
|
|
25
|
+
MethodNotice,
|
|
26
|
+
Quote,
|
|
27
|
+
SubmitButton,
|
|
28
|
+
CryptoAddress,
|
|
29
|
+
Requisites,
|
|
30
|
+
Countdown,
|
|
31
|
+
ReceiptUpload,
|
|
32
|
+
RedirectButton,
|
|
33
|
+
RestartButton,
|
|
34
|
+
Onramp,
|
|
35
|
+
Status,
|
|
36
|
+
};
|
|
37
|
+
const screenOf = (state, cryptoOpen) => {
|
|
38
|
+
const step = state?.step ?? "loading";
|
|
39
|
+
const method = state?.method ?? null;
|
|
40
|
+
if (step === "loading")
|
|
41
|
+
return "loading";
|
|
42
|
+
if (step === "error")
|
|
43
|
+
return "error";
|
|
44
|
+
if (step === "pick-method")
|
|
45
|
+
return cryptoOpen ? "crypto" : "entry";
|
|
46
|
+
if (step === "enter-amount")
|
|
47
|
+
return "entry";
|
|
48
|
+
if (step === "creating")
|
|
49
|
+
return method?.kind === "crypto" ? "crypto" : "entry";
|
|
50
|
+
if (step === "crypto-address")
|
|
51
|
+
return "crypto";
|
|
52
|
+
if (step === "onramp")
|
|
53
|
+
return "entry";
|
|
54
|
+
if (step === "done" && state?.deposit?.kind !== "fiat")
|
|
55
|
+
return "credited";
|
|
56
|
+
return "paying";
|
|
57
|
+
};
|
|
58
|
+
export const DepositForm = forwardRef(function DepositForm({ components, className, style, unstyled, ...rest }, ref) {
|
|
59
|
+
const { root, state } = useDepositFlowStore("<Pay.DepositForm>");
|
|
60
|
+
const picker = useStoreValue(root.picker);
|
|
61
|
+
const screen = screenOf(state, picker.cryptoOpen);
|
|
62
|
+
const setRef = useStepFocus(`${state?.step ?? "loading"}:${screen}`, ref);
|
|
63
|
+
if (root.mode !== "deposit") {
|
|
64
|
+
throw new Error("<Pay.DepositForm> needs <Pay.Root mode=\"deposit\">");
|
|
65
|
+
}
|
|
66
|
+
if (!root.open)
|
|
67
|
+
return null;
|
|
68
|
+
const c = { ...DEFAULTS, ...components };
|
|
69
|
+
const step = state?.step ?? "loading";
|
|
70
|
+
const isUnstyled = unstyled ?? root.unstyled;
|
|
71
|
+
const fiatSelected = state?.method?.kind === "fiat";
|
|
72
|
+
const onrampSelected = state?.method?.kind === "onramp";
|
|
73
|
+
const logoUrl = safeImageUrl(state?.context?.branding.logoUrl);
|
|
74
|
+
const withBack = screen === "crypto" || screen === "credited";
|
|
75
|
+
let body = null;
|
|
76
|
+
switch (screen) {
|
|
77
|
+
case "loading":
|
|
78
|
+
body = (_jsx(ui.PayBody, { unstyled: isUnstyled, children: _jsx(c.Loader, {}) }));
|
|
79
|
+
break;
|
|
80
|
+
case "error":
|
|
81
|
+
body = (_jsx(ui.PayBody, { unstyled: isUnstyled, children: _jsx(c.ErrorMessage, {}) }));
|
|
82
|
+
break;
|
|
83
|
+
case "entry":
|
|
84
|
+
body = (_jsxs(ui.PayBody, { unstyled: isUnstyled, children: [_jsx(c.MethodPicker, {}), fiatSelected ? (_jsxs("div", { className: isUnstyled ? undefined : "bp-rail-form", children: [_jsx(c.AmountInput, {}), _jsx(c.PhoneInput, {}), _jsx(c.MethodNotice, {}), _jsx(c.Quote, {}), _jsx(c.ErrorMessage, {}), _jsx(c.SubmitButton, {})] })) : onrampSelected ? (_jsxs("div", { className: isUnstyled ? undefined : "bp-onramp-tab", children: [_jsx(c.Onramp, {}), _jsx("p", { className: isUnstyled ? undefined : "bp-onramp-note", "data-binodex-pay": "onramp-note", children: root.t("onramp.disclosure") })] })) : (_jsx(c.ErrorMessage, {}))] }));
|
|
85
|
+
break;
|
|
86
|
+
case "crypto":
|
|
87
|
+
body = (_jsxs(ui.PayBody, { variant: "address", unstyled: isUnstyled, children: [_jsx(ui.Divider, { unstyled: isUnstyled }), _jsxs(ui.RouteGrid, { unstyled: isUnstyled, children: [_jsx(c.CurrencyPicker, {}), _jsx(c.NetworkPicker, {})] }), _jsx(c.ErrorMessage, {}), _jsx(c.CryptoAddress, {})] }));
|
|
88
|
+
break;
|
|
89
|
+
case "credited":
|
|
90
|
+
body = (_jsxs(ui.PayBody, { variant: "address", unstyled: isUnstyled, children: [_jsx(ui.Divider, { unstyled: isUnstyled }), _jsx(c.Status, {})] }));
|
|
91
|
+
break;
|
|
92
|
+
case "paying":
|
|
93
|
+
body = (_jsxs(ui.PayBody, { unstyled: isUnstyled, children: [_jsxs(ui.PayingPanel, { unstyled: isUnstyled, children: [_jsx(c.Status, {}), _jsx(c.Requisites, {}), _jsx(c.ReceiptUpload, {}), _jsx(c.Countdown, {}), _jsxs(ui.PayActions, { unstyled: isUnstyled, children: [_jsx(c.RedirectButton, {}), _jsx(c.RestartButton, {})] })] }), _jsx(c.ErrorMessage, {})] }));
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
return (_jsx("div", { tabIndex: -1, ...rest, ref: setRef, ...partProps("deposit-form", { className, style, unstyled }, root.unstyled), "data-step": step, "data-screen": screen, children: _jsx(ui.PayCard, { embedded: true, unstyled: isUnstyled, title: root.t(screen === "crypto" || screen === "credited" ? "header.depositAddress" : "header.deposit"), subtitle: _jsx(c.Balance, {}), back: withBack ? _jsx(c.BackButton, {}) : undefined, close: _jsx(c.Close, {}), logo: logoUrl ? _jsx("img", { src: logoUrl, alt: "", className: isUnstyled ? undefined : "bp-brand", referrerPolicy: "no-referrer" }) : undefined, children: body }) }));
|
|
97
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ComponentType, type HTMLAttributes } from "react";
|
|
2
|
+
import * as ui from "../../ui/index.js";
|
|
3
|
+
import { type PartStyleProps } from "../part.js";
|
|
4
|
+
export interface WithdrawFormComponents {
|
|
5
|
+
Loader: ComponentType;
|
|
6
|
+
ErrorMessage: ComponentType;
|
|
7
|
+
Balance: ComponentType;
|
|
8
|
+
Close: ComponentType;
|
|
9
|
+
CurrencyPicker: ComponentType;
|
|
10
|
+
NetworkPicker: ComponentType;
|
|
11
|
+
AddressInput: ComponentType;
|
|
12
|
+
AmountInput: ComponentType;
|
|
13
|
+
Quote: ComponentType;
|
|
14
|
+
SlippageWarning: ComponentType;
|
|
15
|
+
TwoFactorInput: ComponentType;
|
|
16
|
+
SubmitButton: ComponentType;
|
|
17
|
+
Status: ComponentType;
|
|
18
|
+
RestartButton: ComponentType;
|
|
19
|
+
}
|
|
20
|
+
export type WithdrawFormProps = Omit<HTMLAttributes<HTMLDivElement>, "className" | "style" | "children"> & PartStyleProps & {
|
|
21
|
+
components?: Partial<WithdrawFormComponents>;
|
|
22
|
+
};
|
|
23
|
+
export declare const WithdrawForm: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
24
|
+
components?: Partial<WithdrawFormComponents>;
|
|
25
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { safeImageUrl } from "../../core/appearance.js";
|
|
5
|
+
import * as ui from "../../ui/index.js";
|
|
6
|
+
import { useWithdrawFlowStore } from "../context.js";
|
|
7
|
+
import { useStepFocus } from "./focus.js";
|
|
8
|
+
import { partProps } from "../part.js";
|
|
9
|
+
import { Balance, Close, ErrorMessage, Loader, SubmitButton } from "../components/basic.js";
|
|
10
|
+
import { RestartButton } from "../components/deposit.js";
|
|
11
|
+
import { AddressInput, AmountInput, TwoFactorInput } from "../components/inputs.js";
|
|
12
|
+
import { CurrencyPicker, NetworkPicker } from "../components/pickers.js";
|
|
13
|
+
import { Quote, SlippageWarning, Status } from "../components/status.js";
|
|
14
|
+
const DEFAULTS = {
|
|
15
|
+
Loader,
|
|
16
|
+
ErrorMessage,
|
|
17
|
+
Balance,
|
|
18
|
+
Close,
|
|
19
|
+
CurrencyPicker,
|
|
20
|
+
NetworkPicker,
|
|
21
|
+
AddressInput,
|
|
22
|
+
AmountInput,
|
|
23
|
+
Quote,
|
|
24
|
+
SlippageWarning,
|
|
25
|
+
TwoFactorInput,
|
|
26
|
+
SubmitButton,
|
|
27
|
+
Status,
|
|
28
|
+
RestartButton,
|
|
29
|
+
};
|
|
30
|
+
export const WithdrawForm = forwardRef(function WithdrawForm({ components, className, style, unstyled, ...rest }, ref) {
|
|
31
|
+
const { root, state } = useWithdrawFlowStore("<Pay.WithdrawForm>");
|
|
32
|
+
const setRef = useStepFocus(state?.step ?? "loading", ref);
|
|
33
|
+
if (root.mode !== "withdraw") {
|
|
34
|
+
throw new Error("<Pay.WithdrawForm> needs <Pay.Root mode=\"withdraw\">");
|
|
35
|
+
}
|
|
36
|
+
if (!root.open)
|
|
37
|
+
return null;
|
|
38
|
+
const c = { ...DEFAULTS, ...components };
|
|
39
|
+
const step = state?.step ?? "loading";
|
|
40
|
+
const isUnstyled = unstyled ?? root.unstyled;
|
|
41
|
+
const logoUrl = safeImageUrl(state?.context?.branding.logoUrl);
|
|
42
|
+
const logo = logoUrl ? (_jsx("img", { src: logoUrl, alt: "", className: isUnstyled ? undefined : "bp-brand", referrerPolicy: "no-referrer" })) : undefined;
|
|
43
|
+
return (_jsx("div", { tabIndex: -1, ...rest, ref: setRef, ...partProps("withdraw-form", { className, style, unstyled }, root.unstyled), "data-step": step, children: step === "status" ? (_jsx(ui.PayCard, { embedded: true, variant: "withdraw", unstyled: isUnstyled, header: _jsx(c.Close, {}), children: _jsxs(ui.PayBody, { variant: "withdraw", unstyled: isUnstyled, children: [_jsx(c.Status, {}), _jsx(c.RestartButton, {}), _jsx(c.ErrorMessage, {})] }) })) : (_jsx(ui.PayCard, { embedded: true, variant: "withdraw", unstyled: isUnstyled, title: root.t("header.withdraw"), subtitle: _jsx(c.Balance, {}), close: _jsx(c.Close, {}), logo: logo, children: _jsxs(ui.PayBody, { variant: "withdraw", unstyled: isUnstyled, children: [_jsx(c.Loader, {}), step !== "loading" && step !== "error" && (_jsxs(_Fragment, { children: [_jsxs(ui.RouteGrid, { unstyled: isUnstyled, children: [_jsx(c.CurrencyPicker, {}), _jsx(c.NetworkPicker, {})] }), _jsx(c.AddressInput, {}), _jsx(c.AmountInput, {}), _jsx(c.Quote, {}), _jsx(c.SlippageWarning, {}), _jsx(c.TwoFactorInput, {})] })), _jsx(c.ErrorMessage, {}), step !== "loading" && step !== "error" && _jsx(c.SubmitButton, {})] }) })) }));
|
|
44
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
3
|
+
import { assignRef } from "../part.js";
|
|
4
|
+
export const useStepFocus = (step, forwarded) => {
|
|
5
|
+
const node = useRef(null);
|
|
6
|
+
const previous = useRef(step);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (previous.current === step)
|
|
9
|
+
return;
|
|
10
|
+
previous.current = step;
|
|
11
|
+
const element = node.current;
|
|
12
|
+
if (!element || typeof document === "undefined")
|
|
13
|
+
return;
|
|
14
|
+
const active = document.activeElement;
|
|
15
|
+
if (active && active !== document.body)
|
|
16
|
+
return;
|
|
17
|
+
const target = element.querySelector("input:not([disabled]), [role=alert], [role=status]") ?? element;
|
|
18
|
+
if (target !== element && !target.matches("input"))
|
|
19
|
+
target.setAttribute("tabindex", "-1");
|
|
20
|
+
target.focus({ preventScroll: true });
|
|
21
|
+
}, [step]);
|
|
22
|
+
return useCallback((element) => {
|
|
23
|
+
node.current = element;
|
|
24
|
+
assignRef(forwarded, element);
|
|
25
|
+
}, [forwarded]);
|
|
26
|
+
};
|