@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,267 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useEffect } from "react";
|
|
4
|
+
import { methodCopy } from "../../core/i18n/index.js";
|
|
5
|
+
import { formatAmount, formatPercentValue } from "../../core/money.js";
|
|
6
|
+
import { formatMinLimit } from "../../core/rules/limits.js";
|
|
7
|
+
import * as ui from "../../ui/index.js";
|
|
8
|
+
import { chainName, orderBy } from "../chains.js";
|
|
9
|
+
import { useStoreValue } from "../context.js";
|
|
10
|
+
import { partProps } from "../part.js";
|
|
11
|
+
import { railKey, useFlowState } from "./basic.js";
|
|
12
|
+
const RAIL_COUNTRY = { ru: "RU", kz: "KZ", ua: "UA", in: "IN" };
|
|
13
|
+
const LOCALE_COUNTRY = {
|
|
14
|
+
ru: "RU",
|
|
15
|
+
ua: "UA",
|
|
16
|
+
tr: "TR",
|
|
17
|
+
hi: "IN",
|
|
18
|
+
ar: "AE",
|
|
19
|
+
es: "ES",
|
|
20
|
+
fr: "FR",
|
|
21
|
+
de: "DE",
|
|
22
|
+
cs: "CZ",
|
|
23
|
+
it: "IT",
|
|
24
|
+
en: "US",
|
|
25
|
+
};
|
|
26
|
+
const defaultRailMethod = (methods, previousId) => methods.find((method) => method.id === previousId) ??
|
|
27
|
+
methods.find((method) => method.isDefault) ??
|
|
28
|
+
methods[0] ??
|
|
29
|
+
null;
|
|
30
|
+
const cardTabDefault = (root, state, picker, filter) => {
|
|
31
|
+
if (root.mode !== "deposit" || !state.methods || state.step !== "pick-method" || picker.cryptoOpen)
|
|
32
|
+
return null;
|
|
33
|
+
if (state.method?.kind === "fiat" || state.method?.kind === "onramp")
|
|
34
|
+
return null;
|
|
35
|
+
const methods = state.methods.methods.filter((method) => (filter ? filter(method) : true));
|
|
36
|
+
const hasCrypto = methods.some((method) => method.kind === "crypto");
|
|
37
|
+
const fiat = methods.filter((method) => method.kind === "fiat");
|
|
38
|
+
const onramp = methods.find((method) => method.kind === "onramp") ?? null;
|
|
39
|
+
if (fiat.length === 0 && !onramp)
|
|
40
|
+
return null;
|
|
41
|
+
const tab = picker.tab ?? (hasCrypto ? "crypto" : "card");
|
|
42
|
+
if (tab !== "card")
|
|
43
|
+
return null;
|
|
44
|
+
const country = cardCountry(root.locale, state.methods, fiat, onramp !== null, null, picker.country);
|
|
45
|
+
const railMethods = fiat.filter((method) => RAIL_COUNTRY[method.rail] === country);
|
|
46
|
+
if (railMethods.length === 0)
|
|
47
|
+
return onramp?.id ?? null;
|
|
48
|
+
return defaultRailMethod(railMethods, picker.fiatMethodId)?.id ?? null;
|
|
49
|
+
};
|
|
50
|
+
const cardCountries = (fiat, onramp) => {
|
|
51
|
+
const railCountries = Array.from(new Set(fiat.map((method) => RAIL_COUNTRY[method.rail])));
|
|
52
|
+
const countries = onramp ? Array.from(new Set([...railCountries, ...ui.COUNTRY_CODES])) : railCountries;
|
|
53
|
+
return { railCountries, countries };
|
|
54
|
+
};
|
|
55
|
+
const cardCountry = (locale, methods, fiat, onramp, selected, picked) => {
|
|
56
|
+
const { railCountries, countries } = cardCountries(fiat, onramp);
|
|
57
|
+
const pick = (code) => (code && countries.includes(code) ? code : null);
|
|
58
|
+
return (pick(selected ? RAIL_COUNTRY[selected.rail] : null) ??
|
|
59
|
+
pick(picked) ??
|
|
60
|
+
pick(methods.suggestedCountry?.toUpperCase()) ??
|
|
61
|
+
pick(LOCALE_COUNTRY[locale]) ??
|
|
62
|
+
railCountries[0] ??
|
|
63
|
+
countries[0] ??
|
|
64
|
+
"US");
|
|
65
|
+
};
|
|
66
|
+
export const MethodPicker = forwardRef(function MethodPicker({ filter, renderItem, className, style, unstyled, ...rest }, ref) {
|
|
67
|
+
const { root, state } = useFlowState("<Pay.MethodPicker>");
|
|
68
|
+
const picker = useStoreValue(root.picker);
|
|
69
|
+
const autoMethodId = renderItem ? null : cardTabDefault(root, state, picker, filter);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (autoMethodId)
|
|
72
|
+
root.flow.actions.selectMethod(autoMethodId);
|
|
73
|
+
}, [autoMethodId, root.flow]);
|
|
74
|
+
if (root.mode !== "deposit" || !state.methods)
|
|
75
|
+
return null;
|
|
76
|
+
const s = state;
|
|
77
|
+
const fiatSelected = s.method?.kind === "fiat";
|
|
78
|
+
const onrampSelected = s.method?.kind === "onramp";
|
|
79
|
+
const visible = (s.step === "pick-method" && !picker.cryptoOpen) ||
|
|
80
|
+
((s.step === "enter-amount" || s.step === "creating") && fiatSelected) ||
|
|
81
|
+
(s.step === "onramp" && onrampSelected);
|
|
82
|
+
if (!visible)
|
|
83
|
+
return null;
|
|
84
|
+
const isUnstyled = unstyled ?? root.unstyled;
|
|
85
|
+
const methods = s.methods.methods.filter((method) => (filter ? filter(method) : true));
|
|
86
|
+
const crypto = methods.filter((method) => method.kind === "crypto");
|
|
87
|
+
const fiat = methods.filter((method) => method.kind === "fiat");
|
|
88
|
+
const onramp = methods.find((method) => method.kind === "onramp") ?? null;
|
|
89
|
+
const actions = root.flow.actions;
|
|
90
|
+
const openCrypto = () => {
|
|
91
|
+
const available = orderBy(crypto.filter((method) => method.available), (method) => method.currency, s.methods.ordering.currencies);
|
|
92
|
+
const preferred = available.find((method) => method.chainId === "base" && method.currency === "USDC") ?? available[0] ?? crypto[0];
|
|
93
|
+
root.picker.set({ cryptoOpen: true, cryptoCurrency: preferred?.currency ?? null });
|
|
94
|
+
};
|
|
95
|
+
const fiatLabel = (method) => {
|
|
96
|
+
const copy = methodCopy(root.t, method);
|
|
97
|
+
return {
|
|
98
|
+
label: copy.label ?? root.t("method.card"),
|
|
99
|
+
subtitle: copy.subtitle ??
|
|
100
|
+
(method.displayedCommissionPct
|
|
101
|
+
? root.t("method.commission", { pct: formatPercentValue(method.displayedCommissionPct, root.intl) })
|
|
102
|
+
: null),
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
if (crypto.length + fiat.length + (onramp ? 1 : 0) === 0) {
|
|
106
|
+
return (_jsx("div", { ...rest, ref: ref, ...partProps("method-picker", { className, style, unstyled }, root.unstyled), "data-empty": "", children: _jsx(ui.MethodsNotice, { variant: "empty", unstyled: unstyled, children: root.t("method.empty") }) }));
|
|
107
|
+
}
|
|
108
|
+
if (renderItem) {
|
|
109
|
+
const options = [];
|
|
110
|
+
if (crypto.length > 0)
|
|
111
|
+
options.push({ kind: "crypto", id: "crypto", methods: crypto });
|
|
112
|
+
methods.forEach((method) => {
|
|
113
|
+
if (method.kind !== "crypto")
|
|
114
|
+
options.push(method);
|
|
115
|
+
});
|
|
116
|
+
return (_jsx("div", { role: "group", "aria-label": root.t("method.title"), ...rest, ref: ref, ...partProps("method-picker", { className, style, unstyled }, root.unstyled), children: options.map((option) => {
|
|
117
|
+
const selected = option.kind === "crypto" ? picker.cryptoOpen : s.method?.id === option.id;
|
|
118
|
+
const select = () => {
|
|
119
|
+
if (option.kind === "crypto") {
|
|
120
|
+
openCrypto();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
root.picker.set({ cryptoOpen: false });
|
|
124
|
+
actions.selectMethod(option.id);
|
|
125
|
+
};
|
|
126
|
+
return _jsx("div", { children: renderItem(option, { selected, select }) }, option.id);
|
|
127
|
+
}) }));
|
|
128
|
+
}
|
|
129
|
+
const hasCrypto = crypto.length > 0;
|
|
130
|
+
const hasCard = fiat.length > 0 || onramp !== null;
|
|
131
|
+
const tab = picker.tab ?? (fiatSelected || onrampSelected || !hasCrypto ? "card" : "crypto");
|
|
132
|
+
const { countries } = cardCountries(fiat, onramp !== null);
|
|
133
|
+
const country = cardCountry(root.locale, s.methods, fiat, onramp !== null, fiatSelected ? s.method : null, picker.country);
|
|
134
|
+
const railMethods = fiat.filter((method) => RAIL_COUNTRY[method.rail] === country);
|
|
135
|
+
const leaveAmount = () => {
|
|
136
|
+
if (s.step !== "pick-method")
|
|
137
|
+
actions.back();
|
|
138
|
+
};
|
|
139
|
+
return (_jsxs("div", { role: "group", "aria-label": root.t("method.title"), ...rest, ref: ref, ...partProps("method-picker", { className, style, unstyled }, root.unstyled), "data-tab": tab, children: [hasCrypto && hasCard && (_jsx(ui.EntryTabs, { unstyled: isUnstyled, ariaLabel: root.t("method.title"), value: tab, onChange: (next) => {
|
|
140
|
+
leaveAmount();
|
|
141
|
+
root.picker.set({ tab: next, cryptoOpen: false });
|
|
142
|
+
}, tabs: [
|
|
143
|
+
{ id: "crypto", label: root.t("entry.tabCrypto") },
|
|
144
|
+
{ id: "card", label: root.t("entry.tabCard") },
|
|
145
|
+
] })), tab === "crypto" && hasCrypto && (_jsx(ui.EntryOptions, { unstyled: isUnstyled, onSelect: openCrypto, options: [
|
|
146
|
+
{
|
|
147
|
+
id: "crypto",
|
|
148
|
+
title: root.t("entry.transferTitle"),
|
|
149
|
+
subtitle: root.t("entry.transferSubtitle"),
|
|
150
|
+
icons: ui.cryptoStackIcons(),
|
|
151
|
+
attrs: {
|
|
152
|
+
"data-binodex-pay": "method-option",
|
|
153
|
+
"data-kind": "crypto",
|
|
154
|
+
"data-method": "crypto",
|
|
155
|
+
"data-selected": picker.cryptoOpen ? "" : undefined,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
] })), tab === "card" && hasCard && (_jsxs("div", { className: isUnstyled ? undefined : "bp-card-tab", children: [countries.length > 1 && (_jsx(ui.CountrySelect, { unstyled: isUnstyled, value: country, countries: countries, onChange: (code) => {
|
|
159
|
+
if (code === country)
|
|
160
|
+
return;
|
|
161
|
+
leaveAmount();
|
|
162
|
+
root.picker.set({ country: code });
|
|
163
|
+
} })), railMethods.length > 0 ? (_jsx(ui.Field, { label: root.t("fiat.methodLabel"), unstyled: isUnstyled, children: _jsx(ui.MethodGrid, { unstyled: isUnstyled, ariaLabel: root.t("fiat.methodLabel"), selectedId: s.method?.id ?? null, disabled: s.step === "creating", badgeTitles: { qr: root.t("fiat.qrHint"), pdf: root.t("fiat.pdfHint") }, onSelect: (id) => {
|
|
164
|
+
root.picker.set({ cryptoOpen: false, tab: "card", country, fiatMethodId: id });
|
|
165
|
+
if (s.method?.id !== id)
|
|
166
|
+
actions.selectMethod(id);
|
|
167
|
+
}, methods: railMethods.map((method) => {
|
|
168
|
+
const copy = fiatLabel(method);
|
|
169
|
+
return {
|
|
170
|
+
id: method.id,
|
|
171
|
+
label: copy.label,
|
|
172
|
+
subtitle: copy.subtitle,
|
|
173
|
+
minLabel: method.minAmount
|
|
174
|
+
? root.t(railKey(method.rail, "methodMin"), { min: formatAmount(method.minAmount, method.currency) })
|
|
175
|
+
: null,
|
|
176
|
+
logoKey: method.methodId,
|
|
177
|
+
attrs: {
|
|
178
|
+
"data-binodex-pay": "method-option",
|
|
179
|
+
"data-kind": "fiat",
|
|
180
|
+
"data-method": method.id,
|
|
181
|
+
"data-rail": method.rail,
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}) }) })) : onramp ? null : (_jsx(ui.MethodsNotice, { variant: "empty", unstyled: isUnstyled, children: root.t("fiat.methodsEmpty") }))] }))] }));
|
|
185
|
+
});
|
|
186
|
+
const useCryptoMethods = (owner) => {
|
|
187
|
+
const { root, state } = useFlowState(owner);
|
|
188
|
+
const picker = useStoreValue(root.picker);
|
|
189
|
+
const ordering = state.methods?.ordering ?? { currencies: [], chains: [] };
|
|
190
|
+
const crypto = (state.methods?.methods ?? []).filter((method) => method.kind === "crypto");
|
|
191
|
+
const selectedMethod = state.method?.kind === "crypto" ? state.method : null;
|
|
192
|
+
const currency = picker.cryptoCurrency ?? selectedMethod?.currency ?? null;
|
|
193
|
+
const visible = root.mode === "withdraw"
|
|
194
|
+
? state.step !== "loading" && state.step !== "status" && state.step !== "error"
|
|
195
|
+
: (state.step === "pick-method" && picker.cryptoOpen) ||
|
|
196
|
+
(selectedMethod !== null && (state.step === "creating" || state.step === "crypto-address"));
|
|
197
|
+
return { root, state, crypto, ordering, currency, selectedMethod, visible };
|
|
198
|
+
};
|
|
199
|
+
export const CurrencyPicker = forwardRef(function CurrencyPicker({ renderItem, className, style, unstyled, ...rest }, ref) {
|
|
200
|
+
const { root, crypto, ordering, currency, selectedMethod, visible } = useCryptoMethods("<Pay.CurrencyPicker>");
|
|
201
|
+
if (!visible || crypto.length === 0)
|
|
202
|
+
return null;
|
|
203
|
+
const isUnstyled = unstyled ?? root.unstyled;
|
|
204
|
+
const currencies = orderBy(Array.from(new Set(crypto.map((method) => method.currency))), (value) => value, ordering.currencies);
|
|
205
|
+
const select = (value) => {
|
|
206
|
+
root.picker.set({ cryptoCurrency: value });
|
|
207
|
+
const routes = orderBy(crypto.filter((method) => method.currency === value), (method) => method.chainId, ordering.chains);
|
|
208
|
+
if (root.mode === "withdraw") {
|
|
209
|
+
const preferred = routes.find((method) => method.chainId === selectedMethod?.chainId) ?? routes[0] ?? null;
|
|
210
|
+
if (preferred)
|
|
211
|
+
root.flow.actions.selectMethod(preferred.id);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const sameChain = routes.find((method) => method.chainId === selectedMethod?.chainId && method.available);
|
|
215
|
+
const target = sameChain ?? (routes.length === 1 ? routes[0] : null);
|
|
216
|
+
if (target)
|
|
217
|
+
root.flow.actions.selectMethod(target.id);
|
|
218
|
+
else if (selectedMethod)
|
|
219
|
+
root.flow.actions.back();
|
|
220
|
+
};
|
|
221
|
+
if (renderItem) {
|
|
222
|
+
return (_jsx("div", { role: "group", "aria-label": root.t("currency.label"), ...rest, ref: ref, ...partProps("currency-picker", { className, style, unstyled }, root.unstyled), children: currencies.map((value) => (_jsx("div", { children: renderItem(value, { selected: value === currency, select: () => select(value) }) }, value))) }));
|
|
223
|
+
}
|
|
224
|
+
const options = currencies.map((value) => ({
|
|
225
|
+
value,
|
|
226
|
+
label: value,
|
|
227
|
+
icon: _jsx(ui.TokenIcon, { symbol: value, size: 24 }),
|
|
228
|
+
attrs: { "data-currency": value },
|
|
229
|
+
}));
|
|
230
|
+
return (_jsx(ui.RouteColumn, { ...rest, ref: ref, className: className, style: style, unstyled: isUnstyled, part: "currency-picker", optionPart: "currency-option", label: root.t("route.token"), listLabel: root.t("currency.label"), value: options.find((option) => option.value === currency) ?? null, options: options, onSelect: select }));
|
|
231
|
+
});
|
|
232
|
+
export const NetworkPicker = forwardRef(function NetworkPicker({ renderItem, className, style, unstyled, ...rest }, ref) {
|
|
233
|
+
const { root, crypto, ordering, currency, selectedMethod, visible } = useCryptoMethods("<Pay.NetworkPicker>");
|
|
234
|
+
if (!visible || crypto.length === 0)
|
|
235
|
+
return null;
|
|
236
|
+
const isUnstyled = unstyled ?? root.unstyled;
|
|
237
|
+
const routes = currency
|
|
238
|
+
? orderBy(crypto.filter((method) => method.currency === currency), (method) => method.chainId, ordering.chains)
|
|
239
|
+
: [];
|
|
240
|
+
const select = (id) => root.flow.actions.selectMethod(id);
|
|
241
|
+
if (renderItem) {
|
|
242
|
+
if (routes.length === 0)
|
|
243
|
+
return null;
|
|
244
|
+
return (_jsx("div", { role: "group", "aria-label": root.t("network.label"), ...rest, ref: ref, ...partProps("network-picker", { className, style, unstyled }, root.unstyled), children: routes.map((method) => (_jsx("div", { children: renderItem(method, { selected: selectedMethod?.id === method.id, select: () => select(method.id) }) }, method.id))) }));
|
|
245
|
+
}
|
|
246
|
+
const limits = selectedMethod && selectedMethod.currency === currency
|
|
247
|
+
? root.mode === "withdraw"
|
|
248
|
+
? selectedMethod.withdrawal
|
|
249
|
+
: selectedMethod.minUsd
|
|
250
|
+
? { minUsd: selectedMethod.minUsd, minNative: selectedMethod.minNative, maxNative: selectedMethod.maxNative }
|
|
251
|
+
: null
|
|
252
|
+
: null;
|
|
253
|
+
const options = routes.map((method) => {
|
|
254
|
+
const unavailable = root.mode === "deposit" && !method.available;
|
|
255
|
+
return {
|
|
256
|
+
value: method.id,
|
|
257
|
+
label: chainName(method.chainId),
|
|
258
|
+
icon: _jsx(ui.ChainIcon, { chainId: method.chainId, size: 24 }),
|
|
259
|
+
disabled: unavailable,
|
|
260
|
+
hint: unavailable ? root.t("method.unavailable") : null,
|
|
261
|
+
attrs: { "data-chain": method.chainId },
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
return (_jsx(ui.RouteColumn, { ...rest, ref: ref, className: className, style: style, unstyled: isUnstyled, part: "network-picker", optionPart: "network-option", label: root.t("route.network"), listLabel: root.t("network.label"), labelRight: limits
|
|
265
|
+
? `${root.t("route.min")}: ${formatMinLimit({ minUsd: limits.minUsd, minNative: limits.minNative, maxNative: limits.maxNative }, selectedMethod.currency)}`
|
|
266
|
+
: undefined, value: options.find((option) => option.value === selectedMethod?.id) ?? null, options: options, onSelect: select }));
|
|
267
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type HTMLAttributes, 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 Quote: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
10
|
+
export declare const SlippageWarning: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & {
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
13
|
+
export type StatusProps = Omit<DivProps, "children"> & {
|
|
14
|
+
children?: ReactNode | ((status: {
|
|
15
|
+
status: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}) => ReactNode);
|
|
18
|
+
};
|
|
19
|
+
export declare const Status: import("react").ForwardRefExoticComponent<Omit<DivProps, "children"> & {
|
|
20
|
+
children?: ReactNode | ((status: {
|
|
21
|
+
status: string;
|
|
22
|
+
label: string;
|
|
23
|
+
}) => ReactNode);
|
|
24
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useState } from "react";
|
|
4
|
+
import { errorMessage } from "../../core/i18n/index.js";
|
|
5
|
+
import { formatPayingAmount, formatPercentValue, formatTokenAmount, formatUsd } from "../../core/money.js";
|
|
6
|
+
import * as ui from "../../ui/index.js";
|
|
7
|
+
import { balanceText } from "../../ui/context.js";
|
|
8
|
+
import { explorerUrl } from "../chains.js";
|
|
9
|
+
import { railKey, useFlowState } from "./basic.js";
|
|
10
|
+
export const Quote = forwardRef(function Quote({ className, style, unstyled, children, ...rest }, ref) {
|
|
11
|
+
const { root, state } = useFlowState("<Pay.Quote>");
|
|
12
|
+
if (root.mode === "deposit") {
|
|
13
|
+
const s = state;
|
|
14
|
+
if (s.step !== "enter-amount" || s.method?.kind !== "fiat")
|
|
15
|
+
return null;
|
|
16
|
+
const rail = s.method.rail;
|
|
17
|
+
if (s.quoteError) {
|
|
18
|
+
return (_jsx(ui.ErrorBox, { ...rest, ref: ref, part: "quote", variant: "rail", className: className, style: style, unstyled: unstyled, "data-error": s.quoteError.code, children: errorMessage(root.t, s.quoteError, root.locale) }));
|
|
19
|
+
}
|
|
20
|
+
const quote = s.quote;
|
|
21
|
+
if (!quote && !s.quoteLoading)
|
|
22
|
+
return null;
|
|
23
|
+
const loading = s.quoteLoading;
|
|
24
|
+
const commission = quote?.displayedCommissionPct ?? s.method.displayedCommissionPct;
|
|
25
|
+
const rows = [
|
|
26
|
+
...(commission
|
|
27
|
+
? [
|
|
28
|
+
{
|
|
29
|
+
key: "commission",
|
|
30
|
+
label: root.t(railKey(rail, "commissionLabel")),
|
|
31
|
+
value: loading ? "…" : root.t("common.percent", { value: formatPercentValue(commission, root.intl) }),
|
|
32
|
+
},
|
|
33
|
+
]
|
|
34
|
+
: []),
|
|
35
|
+
{
|
|
36
|
+
key: "estimated",
|
|
37
|
+
label: root.t(railKey(rail, "estimatedLabel")),
|
|
38
|
+
value: loading || !quote?.estimatedUsd ? "≈ …" : `≈ ${formatUsd(quote.estimatedUsd)}`,
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
return (_jsx(ui.Summary, { ...rest, ref: ref, part: "quote", className: className, style: style, unstyled: unstyled, "data-loading": loading ? "" : undefined, rows: rows, children: children }));
|
|
42
|
+
}
|
|
43
|
+
const s = state;
|
|
44
|
+
if (s.step === "loading" || s.step === "status" || s.step === "error")
|
|
45
|
+
return null;
|
|
46
|
+
if (s.step === "quoting") {
|
|
47
|
+
return (_jsx(ui.QuoteRows, { ...rest, ref: ref, part: "quote", className: className, style: style, unstyled: unstyled, rows: [], loading: true, loadingRows: s.method?.etaSeconds || s.method?.withdrawal?.etaSeconds ? 3 : 2, loadingLabel: root.t("withdraw.quoteLoading") }));
|
|
48
|
+
}
|
|
49
|
+
if (s.quoteError) {
|
|
50
|
+
return (_jsxs(ui.ErrorBox, { ...rest, ref: ref, part: "quote", variant: "withdraw", className: className, style: style, unstyled: unstyled, "data-error": s.quoteError.code, children: [_jsx("div", { children: errorMessage(root.t, s.quoteError, root.locale) }), _jsx("button", { type: "button", className: (unstyled ?? root.unstyled) ? undefined : "bp-max-button", "data-binodex-pay": "retry", onClick: () => root.flow.actions.requote(), children: root.t("withdraw.retry") })] }));
|
|
51
|
+
}
|
|
52
|
+
if (!s.quote || !s.method)
|
|
53
|
+
return null;
|
|
54
|
+
const currency = s.method.currency;
|
|
55
|
+
const eta = s.quote.etaSeconds ?? s.method.withdrawal?.etaSeconds ?? null;
|
|
56
|
+
const rows = [
|
|
57
|
+
{
|
|
58
|
+
key: "receive",
|
|
59
|
+
label: root.t("withdraw.receive"),
|
|
60
|
+
icon: _jsx(ui.TokenIcon, { symbol: currency, size: 18 }),
|
|
61
|
+
value: `~${formatTokenAmount(s.quote.receiveAmount, currency)} ${currency}`,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
key: "fee",
|
|
65
|
+
label: root.t("withdraw.networkFee"),
|
|
66
|
+
value: `~${balanceText(s.quote.feeUsd)}`,
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
if (s.acceptedSlippagePct !== null && s.quote.slippagePct) {
|
|
70
|
+
rows.push({ key: "slippage", label: root.t("withdraw.slippage"), value: `~${s.quote.slippagePct}%`, tone: "warning" });
|
|
71
|
+
}
|
|
72
|
+
if (eta) {
|
|
73
|
+
rows.push({ key: "eta", label: root.t("withdraw.time"), value: `~${Math.ceil(eta / 60)} ${root.t("withdraw.minutes")}` });
|
|
74
|
+
}
|
|
75
|
+
return (_jsx(ui.QuoteRows, { ...rest, ref: ref, part: "quote", className: className, style: style, unstyled: unstyled, rows: rows, children: children }));
|
|
76
|
+
});
|
|
77
|
+
export const SlippageWarning = forwardRef(function SlippageWarning({ className, style, unstyled, children, ...rest }, ref) {
|
|
78
|
+
const { root, state } = useFlowState("<Pay.SlippageWarning>");
|
|
79
|
+
if (root.mode !== "withdraw")
|
|
80
|
+
return null;
|
|
81
|
+
const s = state;
|
|
82
|
+
if (s.step !== "slippage-confirm" || !s.slippageWarning || !s.method)
|
|
83
|
+
return null;
|
|
84
|
+
const warning = s.slippageWarning;
|
|
85
|
+
const currency = s.method.currency;
|
|
86
|
+
const pct = warning.slippagePct ? formatPercentValue(warning.slippagePct, root.intl) : "?";
|
|
87
|
+
const amount = [
|
|
88
|
+
warning.receiveAmount ? `${formatTokenAmount(warning.receiveAmount, currency)} ${currency}` : null,
|
|
89
|
+
warning.receiveAmountUsd ? `(~${balanceText(warning.receiveAmountUsd)})` : null,
|
|
90
|
+
]
|
|
91
|
+
.filter(Boolean)
|
|
92
|
+
.join(" ");
|
|
93
|
+
return (_jsx(ui.SlippageWarning, { ...rest, ref: ref, part: "slippage", className: className, style: style, unstyled: unstyled, title: `${root.t("withdraw.slippageTitle")}: ~${pct}%`, body: `${root.t("withdraw.slippageBody", { amount, pct })} ${root.t("withdraw.slippageHint")}`, actionLabel: root.t("withdraw.slippageAccept"), onAccept: () => root.flow.actions.acceptSlippage(), children: children }));
|
|
94
|
+
});
|
|
95
|
+
const fiatStatusKey = (rail, status) => {
|
|
96
|
+
switch (status) {
|
|
97
|
+
case "completed":
|
|
98
|
+
return railKey(rail, "statusCompleted");
|
|
99
|
+
case "failed":
|
|
100
|
+
return railKey(rail, "statusFailed");
|
|
101
|
+
case "expired":
|
|
102
|
+
return railKey(rail, "statusExpired");
|
|
103
|
+
case "disputed":
|
|
104
|
+
return "fiat.statusInCheck";
|
|
105
|
+
default:
|
|
106
|
+
return railKey(rail, "statusPending");
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const toneOf = (status) => status === "completed"
|
|
110
|
+
? { tone: "completed", status: "success" }
|
|
111
|
+
: status === "pending" || status === "disputed"
|
|
112
|
+
? { tone: "pending", status: "pending" }
|
|
113
|
+
: { tone: "failed", status: "failed" };
|
|
114
|
+
const formatDateTime = (at, intl) => {
|
|
115
|
+
try {
|
|
116
|
+
return new Date(at).toLocaleString(intl, {
|
|
117
|
+
day: "numeric",
|
|
118
|
+
month: "long",
|
|
119
|
+
hour: "2-digit",
|
|
120
|
+
minute: "2-digit",
|
|
121
|
+
second: "2-digit",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return new Date(at).toISOString();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
function WithdrawDetails({ withdrawal, t, intl, unstyled }) {
|
|
129
|
+
const [open, setOpen] = useState(false);
|
|
130
|
+
const hash = withdrawal.destinationTxHash;
|
|
131
|
+
const link = withdrawal.chainId ? explorerUrl(withdrawal.chainId, hash) : null;
|
|
132
|
+
const cls = unstyled ? () => undefined : (name) => `bp-${name}`;
|
|
133
|
+
return (_jsx(ui.DetailsAccordion, { variant: "withdraw", unstyled: unstyled, open: open, onOpenChange: setOpen, label: t("withdraw.details"), rows: [
|
|
134
|
+
{
|
|
135
|
+
key: "tx",
|
|
136
|
+
label: t("withdraw.txHash"),
|
|
137
|
+
value: hash ? (_jsxs("span", { className: cls("hash"), children: [_jsx("span", { className: cls("short-hash"), "data-binodex-pay": "tx-hash", children: `${hash.slice(0, 6)}…${hash.slice(-4)}` }), _jsx(ui.CopyButton, { value: hash, unstyled: true, className: cls("hash-button") }), link && (_jsx("a", { href: link, target: "_blank", rel: "noopener noreferrer", className: cls("hash-button"), "data-binodex-pay": "tx-link", title: t("status.tx"), "aria-label": t("status.tx"), children: _jsx(ui.icons.ExplorerIcon, {}) }))] })) : (_jsx("span", { children: t("withdraw.txPending") })),
|
|
138
|
+
},
|
|
139
|
+
{ key: "created", label: t("withdraw.orderSent"), value: formatDateTime(withdrawal.createdAt, intl) },
|
|
140
|
+
] }));
|
|
141
|
+
}
|
|
142
|
+
export const Status = forwardRef(function Status({ className, style, unstyled, children, ...rest }, ref) {
|
|
143
|
+
const { root, state } = useFlowState("<Pay.Status>");
|
|
144
|
+
const isUnstyled = unstyled ?? root.unstyled;
|
|
145
|
+
if (root.mode === "deposit") {
|
|
146
|
+
const s = state;
|
|
147
|
+
const fiat = s.deposit?.kind === "fiat" ? s.deposit : null;
|
|
148
|
+
if (s.step === "done" && !fiat) {
|
|
149
|
+
if (s.outcome !== "credited")
|
|
150
|
+
return null;
|
|
151
|
+
const total = s.credited.reduce((sum, entry) => sum + Number(entry.amountUsd ?? 0), 0);
|
|
152
|
+
const label = root.t("credit.title");
|
|
153
|
+
if (typeof children === "function")
|
|
154
|
+
return _jsx(_Fragment, { children: children({ status: "success", label }) });
|
|
155
|
+
return (_jsx(ui.CreditBanner, { ...rest, ref: ref, part: "status", className: className, style: style, unstyled: unstyled, "data-status": "success", title: label, subtitle: total > 0 ? root.t("credit.subtitle", { amount: `+${balanceText(total)}` }) : undefined, children: children }));
|
|
156
|
+
}
|
|
157
|
+
const paying = (s.step === "requisites" || s.step === "redirect") && fiat;
|
|
158
|
+
if (!fiat || (!paying && s.step !== "done"))
|
|
159
|
+
return null;
|
|
160
|
+
// The requisites frame draws its own status and timer; a second pill here would contradict it.
|
|
161
|
+
if (s.view?.kind === "frame" && s.step !== "done")
|
|
162
|
+
return null;
|
|
163
|
+
const shown = s.step === "done" ? fiat.status : (s.shownStatus ?? fiat.status);
|
|
164
|
+
const attachedPending = shown === "pending" && fiat.receipt.attachedAt !== null && fiat.receipt.required;
|
|
165
|
+
const tone = toneOf(shown);
|
|
166
|
+
const label = root.t(attachedPending ? "fiat.statusInCheck" : fiatStatusKey(fiat.rail, shown));
|
|
167
|
+
if (typeof children === "function")
|
|
168
|
+
return _jsx(_Fragment, { children: children({ status: tone.status, label }) });
|
|
169
|
+
const requisitesAmount = s.view?.kind === "requisites" ? s.view.requisites.amount : null;
|
|
170
|
+
const amount = requisitesAmount ?? fiat.amount;
|
|
171
|
+
const hint = shown !== "pending" || attachedPending
|
|
172
|
+
? null
|
|
173
|
+
: s.view?.kind === "requisites"
|
|
174
|
+
? root.t("fiat.requisitesHint")
|
|
175
|
+
: s.view?.kind === "redirect"
|
|
176
|
+
? root.t(railKey(fiat.rail, "openedInNewTab"))
|
|
177
|
+
: s.view?.kind === "qr"
|
|
178
|
+
? root.t(railKey(fiat.rail, "scanQr"))
|
|
179
|
+
: null;
|
|
180
|
+
return (_jsxs(_Fragment, { children: [_jsx(ui.StatusPill, { ...rest, ref: ref, part: "status", role: "status", "aria-live": "polite", className: className, style: style, unstyled: unstyled, tone: tone.tone, "data-status": tone.status, label: label }), amount && _jsx(ui.PanelAmount, { unstyled: isUnstyled, children: formatPayingAmount(amount, fiat.currency) }), hint && _jsx(ui.PanelHint, { unstyled: isUnstyled, children: hint }), children] }));
|
|
181
|
+
}
|
|
182
|
+
const s = state;
|
|
183
|
+
if (s.step !== "status")
|
|
184
|
+
return null;
|
|
185
|
+
const withdrawal = s.withdrawal;
|
|
186
|
+
const status = withdrawal?.displayStatus ?? "pending";
|
|
187
|
+
const label = root.t(status === "success" ? "withdraw.successTitle" : status === "failed" ? "withdraw.failedTitle" : "withdraw.pendingTitle");
|
|
188
|
+
if (typeof children === "function")
|
|
189
|
+
return _jsx(_Fragment, { children: children({ status, label }) });
|
|
190
|
+
const currency = withdrawal?.currency?.toUpperCase() ?? null;
|
|
191
|
+
const receiveAmount = withdrawal?.receiveAmount ?? null;
|
|
192
|
+
const rows = [
|
|
193
|
+
{
|
|
194
|
+
key: "status",
|
|
195
|
+
label: root.t("withdraw.statusLabel"),
|
|
196
|
+
value: (_jsx(ui.StatusText, { tone: status, unstyled: isUnstyled, children: root.t(status === "success" ? "withdraw.statusSuccess" : status === "failed" ? "withdraw.statusFailed" : "withdraw.statusPending") })),
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
if (currency) {
|
|
200
|
+
rows.push({
|
|
201
|
+
key: "receive",
|
|
202
|
+
label: root.t("withdraw.receive"),
|
|
203
|
+
value: (_jsxs("span", { className: isUnstyled ? undefined : "bp-receive-value", children: [_jsx(ui.TokenIcon, { symbol: currency, size: 18 }), _jsx("span", { className: isUnstyled ? undefined : "bp-mono", children: receiveAmount !== null ? (_jsxs(_Fragment, { children: [`~${formatTokenAmount(receiveAmount, currency)} ${currency}`, withdrawal?.receiveAmountUsd && (_jsx("span", { className: isUnstyled ? undefined : "bp-muted", style: { marginLeft: 6 }, children: `(~${balanceText(withdrawal.receiveAmountUsd)})` }))] })) : ("—") })] })),
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (status === "success" && withdrawal) {
|
|
207
|
+
const seconds = Math.max(1, Math.round((withdrawal.updatedAt - withdrawal.createdAt) / 1000));
|
|
208
|
+
rows.push({
|
|
209
|
+
key: "time",
|
|
210
|
+
label: root.t("withdraw.time"),
|
|
211
|
+
value: seconds < 60
|
|
212
|
+
? `${seconds} ${root.t("withdraw.seconds")}`
|
|
213
|
+
: `${Math.round(seconds / 60)} ${root.t("withdraw.minutes")}`,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return (_jsx(ui.WithdrawResult, { ...rest, ref: ref, part: "status", role: "status", "aria-live": "polite", className: className, style: style, unstyled: unstyled, "data-status": status, state: status, title: label, subtitle: root.t(status === "success"
|
|
217
|
+
? "withdraw.successSubtitle"
|
|
218
|
+
: status === "failed"
|
|
219
|
+
? "withdraw.failedSubtitle"
|
|
220
|
+
: "withdraw.pendingSubtitle"), rows: rows, details: withdrawal ? _jsx(WithdrawDetails, { withdrawal: withdrawal, t: root.t, intl: root.intl, unstyled: isUnstyled }) : null, children: children }));
|
|
221
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AppearanceSkin } from "../core/appearance.js";
|
|
2
|
+
import type { PayClient } from "../core/client.js";
|
|
3
|
+
import type { PayError } from "../core/errors.js";
|
|
4
|
+
import type { DepositFlow } from "../core/flows/deposit.js";
|
|
5
|
+
import type { WithdrawFlow } from "../core/flows/withdraw.js";
|
|
6
|
+
import type { PayLocale, Translate } from "../core/i18n/index.js";
|
|
7
|
+
import type { ReadableStore, Store } from "../core/store.js";
|
|
8
|
+
import type { CryptoDeposit, PayMode, PayTheme } from "../core/types.js";
|
|
9
|
+
export type EntryTab = "crypto" | "card";
|
|
10
|
+
export interface PickerState {
|
|
11
|
+
cryptoOpen: boolean;
|
|
12
|
+
cryptoCurrency: string | null;
|
|
13
|
+
tab: EntryTab | null;
|
|
14
|
+
country: string | null;
|
|
15
|
+
fiatMethodId: string | null;
|
|
16
|
+
}
|
|
17
|
+
export interface PayRootValue {
|
|
18
|
+
client: PayClient;
|
|
19
|
+
mode: PayMode;
|
|
20
|
+
flow: DepositFlow | WithdrawFlow;
|
|
21
|
+
open: boolean;
|
|
22
|
+
setOpen: (open: boolean) => void;
|
|
23
|
+
restart: () => void;
|
|
24
|
+
t: Translate;
|
|
25
|
+
locale: PayLocale;
|
|
26
|
+
intl: string;
|
|
27
|
+
dir: "ltr" | "rtl";
|
|
28
|
+
theme: PayTheme | undefined;
|
|
29
|
+
skin: AppearanceSkin;
|
|
30
|
+
unstyled: boolean;
|
|
31
|
+
picker: Store<PickerState>;
|
|
32
|
+
cryptoCache: Map<string, CryptoDeposit>;
|
|
33
|
+
}
|
|
34
|
+
export declare const PayRootContext: import("react").Context<PayRootValue | null>;
|
|
35
|
+
export declare const usePayRoot: (owner: string) => PayRootValue;
|
|
36
|
+
export declare const useStoreValue: <T>(store: ReadableStore<T>) => T;
|
|
37
|
+
export declare const useDepositFlowStore: (owner: string) => {
|
|
38
|
+
root: PayRootValue;
|
|
39
|
+
flow: DepositFlow | null;
|
|
40
|
+
state: import("../core/flows/deposit.js").DepositFlowState | null;
|
|
41
|
+
};
|
|
42
|
+
export declare const useWithdrawFlowStore: (owner: string) => {
|
|
43
|
+
root: PayRootValue;
|
|
44
|
+
flow: WithdrawFlow | null;
|
|
45
|
+
state: import("../core/flows/withdraw.js").WithdrawFlowState | null;
|
|
46
|
+
};
|
|
47
|
+
export declare const useFlowError: (owner: string) => PayError | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext, useSyncExternalStore } from "react";
|
|
3
|
+
export const PayRootContext = createContext(null);
|
|
4
|
+
export const usePayRoot = (owner) => {
|
|
5
|
+
const value = useContext(PayRootContext);
|
|
6
|
+
if (!value) {
|
|
7
|
+
throw new Error(`${owner} must be used inside <Pay.Root> from @binopartner/pay-sdk/elements`);
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
export const useStoreValue = (store) => useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
12
|
+
const IDLE_STORE = {
|
|
13
|
+
getSnapshot: () => null,
|
|
14
|
+
subscribe: () => () => undefined,
|
|
15
|
+
};
|
|
16
|
+
export const useDepositFlowStore = (owner) => {
|
|
17
|
+
const root = usePayRoot(owner);
|
|
18
|
+
const flow = root.mode === "deposit" ? root.flow : null;
|
|
19
|
+
const state = useStoreValue(flow ?? IDLE_STORE);
|
|
20
|
+
return { root, flow, state };
|
|
21
|
+
};
|
|
22
|
+
export const useWithdrawFlowStore = (owner) => {
|
|
23
|
+
const root = usePayRoot(owner);
|
|
24
|
+
const flow = root.mode === "withdraw" ? root.flow : null;
|
|
25
|
+
const state = useStoreValue(flow ?? IDLE_STORE);
|
|
26
|
+
return { root, flow, state };
|
|
27
|
+
};
|
|
28
|
+
export const useFlowError = (owner) => {
|
|
29
|
+
const root = usePayRoot(owner);
|
|
30
|
+
const client = useStoreValue(root.client.state);
|
|
31
|
+
const flow = useStoreValue(root.flow);
|
|
32
|
+
return client.error ?? flow.error;
|
|
33
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type PayError } from "../../core/errors.js";
|
|
2
|
+
import { type PayView } from "../../core/rules/requisites.js";
|
|
3
|
+
import type { CreateDepositInput, CryptoDeposit, Deposit, DepositQuote, FiatDeposit, FiatDepositStatus } from "../../core/types.js";
|
|
4
|
+
export declare const QUOTE_DEBOUNCE_MS = 400;
|
|
5
|
+
export interface UseDepositQuoteResult {
|
|
6
|
+
quote: DepositQuote | null;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
error: PayError | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function useDepositQuote(methodId: string | null | undefined, amount: string | null | undefined): UseDepositQuoteResult;
|
|
11
|
+
export interface UseCryptoDepositResult {
|
|
12
|
+
deposit: CryptoDeposit | null;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
error: PayError | null;
|
|
15
|
+
request: () => Promise<CryptoDeposit | null>;
|
|
16
|
+
}
|
|
17
|
+
export declare function useCryptoDeposit(input: {
|
|
18
|
+
chainId: string | null | undefined;
|
|
19
|
+
currency: string | null | undefined;
|
|
20
|
+
methodId?: string;
|
|
21
|
+
}): UseCryptoDepositResult;
|
|
22
|
+
export interface UseCreateDepositResult {
|
|
23
|
+
create: (input: CreateDepositInput) => Promise<FiatDeposit | null>;
|
|
24
|
+
pending: boolean;
|
|
25
|
+
error: PayError | null;
|
|
26
|
+
deposit: FiatDeposit | null;
|
|
27
|
+
}
|
|
28
|
+
export declare function useCreateDeposit(): UseCreateDepositResult;
|
|
29
|
+
export interface UseDepositResult {
|
|
30
|
+
deposit: Deposit | null;
|
|
31
|
+
view: PayView | null;
|
|
32
|
+
shownStatus: FiatDepositStatus | null;
|
|
33
|
+
error: PayError | null;
|
|
34
|
+
loading: boolean;
|
|
35
|
+
refresh: () => void;
|
|
36
|
+
}
|
|
37
|
+
export declare function useDeposit(id: string | null | undefined): UseDepositResult;
|
|
38
|
+
export interface UseAttachReceiptResult {
|
|
39
|
+
attach: (file: Blob) => Promise<boolean>;
|
|
40
|
+
pending: boolean;
|
|
41
|
+
error: PayError | null;
|
|
42
|
+
attached: boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare function useAttachReceipt(id: string | null | undefined): UseAttachReceiptResult;
|
|
45
|
+
export interface UseOnrampResult {
|
|
46
|
+
url: string | null;
|
|
47
|
+
loading: boolean;
|
|
48
|
+
error: PayError | null;
|
|
49
|
+
load: () => Promise<string | null>;
|
|
50
|
+
retry: () => Promise<string | null>;
|
|
51
|
+
}
|
|
52
|
+
export declare function useOnramp(): UseOnrampResult;
|