@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.
Files changed (154) hide show
  1. package/README.md +145 -2
  2. package/dist/core/api-base.d.ts +49 -0
  3. package/dist/core/api-base.js +196 -0
  4. package/dist/core/appearance.d.ts +17 -0
  5. package/dist/core/appearance.js +122 -0
  6. package/dist/core/auth.d.ts +32 -0
  7. package/dist/core/auth.js +233 -0
  8. package/dist/core/client.d.ts +71 -0
  9. package/dist/core/client.js +307 -0
  10. package/dist/core/clock.d.ts +7 -0
  11. package/dist/core/clock.js +17 -0
  12. package/dist/core/errors.d.ts +29 -0
  13. package/dist/core/errors.js +87 -0
  14. package/dist/core/events.d.ts +50 -0
  15. package/dist/core/events.js +1 -0
  16. package/dist/core/flows/deposit.d.ts +63 -0
  17. package/dist/core/flows/deposit.js +502 -0
  18. package/dist/core/flows/withdraw.d.ts +51 -0
  19. package/dist/core/flows/withdraw.js +413 -0
  20. package/dist/core/i18n/ar.d.ts +2 -0
  21. package/dist/core/i18n/ar.js +314 -0
  22. package/dist/core/i18n/base.d.ts +14 -0
  23. package/dist/core/i18n/base.js +86 -0
  24. package/dist/core/i18n/cs.d.ts +2 -0
  25. package/dist/core/i18n/cs.js +314 -0
  26. package/dist/core/i18n/de.d.ts +2 -0
  27. package/dist/core/i18n/de.js +314 -0
  28. package/dist/core/i18n/en-ui.d.ts +39 -0
  29. package/dist/core/i18n/en-ui.js +39 -0
  30. package/dist/core/i18n/en.d.ts +316 -0
  31. package/dist/core/i18n/en.js +280 -0
  32. package/dist/core/i18n/es.d.ts +2 -0
  33. package/dist/core/i18n/es.js +314 -0
  34. package/dist/core/i18n/fr.d.ts +2 -0
  35. package/dist/core/i18n/fr.js +314 -0
  36. package/dist/core/i18n/hi.d.ts +2 -0
  37. package/dist/core/i18n/hi.js +314 -0
  38. package/dist/core/i18n/index.d.ts +16 -0
  39. package/dist/core/i18n/index.js +39 -0
  40. package/dist/core/i18n/it.d.ts +2 -0
  41. package/dist/core/i18n/it.js +314 -0
  42. package/dist/core/i18n/ru.d.ts +2 -0
  43. package/dist/core/i18n/ru.js +314 -0
  44. package/dist/core/i18n/tr.d.ts +2 -0
  45. package/dist/core/i18n/tr.js +314 -0
  46. package/dist/core/i18n/ua.d.ts +2 -0
  47. package/dist/core/i18n/ua.js +314 -0
  48. package/dist/core/index.d.ts +37 -0
  49. package/dist/core/index.js +19 -0
  50. package/dist/core/intent.d.ts +13 -0
  51. package/dist/core/intent.js +45 -0
  52. package/dist/core/money.d.ts +22 -0
  53. package/dist/core/money.js +178 -0
  54. package/dist/core/poll.d.ts +16 -0
  55. package/dist/core/poll.js +100 -0
  56. package/dist/core/requisites-frame.d.ts +32 -0
  57. package/dist/core/requisites-frame.js +202 -0
  58. package/dist/core/rules/address.d.ts +3 -0
  59. package/dist/core/rules/address.js +29 -0
  60. package/dist/core/rules/limits.d.ts +17 -0
  61. package/dist/core/rules/limits.js +19 -0
  62. package/dist/core/rules/paying.d.ts +10 -0
  63. package/dist/core/rules/paying.js +32 -0
  64. package/dist/core/rules/receipt.d.ts +6 -0
  65. package/dist/core/rules/receipt.js +33 -0
  66. package/dist/core/rules/requisites.d.ts +42 -0
  67. package/dist/core/rules/requisites.js +68 -0
  68. package/dist/core/rules/slippage.d.ts +1 -0
  69. package/dist/core/rules/slippage.js +7 -0
  70. package/dist/core/store.d.ts +15 -0
  71. package/dist/core/store.js +53 -0
  72. package/dist/core/types.d.ts +244 -0
  73. package/dist/core/types.js +1 -0
  74. package/dist/core/wire.d.ts +178 -0
  75. package/dist/core/wire.js +602 -0
  76. package/dist/elements/Root.d.ts +37 -0
  77. package/dist/elements/Root.js +143 -0
  78. package/dist/elements/chains.d.ts +1 -0
  79. package/dist/elements/chains.js +1 -0
  80. package/dist/elements/components/Qr.d.ts +17 -0
  81. package/dist/elements/components/Qr.js +28 -0
  82. package/dist/elements/components/basic.d.ts +42 -0
  83. package/dist/elements/components/basic.js +129 -0
  84. package/dist/elements/components/deposit.d.ts +61 -0
  85. package/dist/elements/components/deposit.js +272 -0
  86. package/dist/elements/components/inputs.d.ts +24 -0
  87. package/dist/elements/components/inputs.js +92 -0
  88. package/dist/elements/components/pickers.d.ts +32 -0
  89. package/dist/elements/components/pickers.js +267 -0
  90. package/dist/elements/components/status.d.ts +25 -0
  91. package/dist/elements/components/status.js +221 -0
  92. package/dist/elements/context.d.ts +47 -0
  93. package/dist/elements/context.js +33 -0
  94. package/dist/elements/hooks/deposit.d.ts +52 -0
  95. package/dist/elements/hooks/deposit.js +215 -0
  96. package/dist/elements/hooks/root.d.ts +70 -0
  97. package/dist/elements/hooks/root.js +125 -0
  98. package/dist/elements/hooks/withdraw.d.ts +30 -0
  99. package/dist/elements/hooks/withdraw.js +145 -0
  100. package/dist/elements/index.d.ts +28 -0
  101. package/dist/elements/index.js +14 -0
  102. package/dist/elements/part.d.ts +2 -0
  103. package/dist/elements/part.js +1 -0
  104. package/dist/elements/presets/DepositForm.d.ts +32 -0
  105. package/dist/elements/presets/DepositForm.js +97 -0
  106. package/dist/elements/presets/WithdrawForm.d.ts +25 -0
  107. package/dist/elements/presets/WithdrawForm.js +44 -0
  108. package/dist/elements/presets/focus.d.ts +2 -0
  109. package/dist/elements/presets/focus.js +26 -0
  110. package/dist/elements.css +2777 -0
  111. package/dist/fonts.css +31 -0
  112. package/dist/frame.d.ts +1 -0
  113. package/dist/frame.js +37 -6
  114. package/dist/types.d.ts +1 -0
  115. package/dist/ui/chains.d.ts +3 -0
  116. package/dist/ui/chains.js +42 -0
  117. package/dist/ui/context.d.ts +51 -0
  118. package/dist/ui/context.js +63 -0
  119. package/dist/ui/crypto.d.ts +67 -0
  120. package/dist/ui/crypto.js +68 -0
  121. package/dist/ui/entry.d.ts +25 -0
  122. package/dist/ui/entry.js +26 -0
  123. package/dist/ui/fiat.d.ts +94 -0
  124. package/dist/ui/fiat.js +149 -0
  125. package/dist/ui/fields.d.ts +76 -0
  126. package/dist/ui/fields.js +71 -0
  127. package/dist/ui/fonts.d.ts +4 -0
  128. package/dist/ui/fonts.js +31 -0
  129. package/dist/ui/icons.d.ts +39 -0
  130. package/dist/ui/icons.js +116 -0
  131. package/dist/ui/index.d.ts +31 -0
  132. package/dist/ui/index.js +17 -0
  133. package/dist/ui/layout.d.ts +36 -0
  134. package/dist/ui/layout.js +44 -0
  135. package/dist/ui/logos.d.ts +14 -0
  136. package/dist/ui/logos.js +61 -0
  137. package/dist/ui/part.d.ts +32 -0
  138. package/dist/ui/part.js +33 -0
  139. package/dist/ui/pickers.d.ts +71 -0
  140. package/dist/ui/pickers.js +167 -0
  141. package/dist/ui/qr-encode.d.ts +30 -0
  142. package/dist/ui/qr-encode.js +340 -0
  143. package/dist/ui/summary.d.ts +31 -0
  144. package/dist/ui/summary.js +36 -0
  145. package/dist/ui/types.d.ts +67 -0
  146. package/dist/ui/types.js +1 -0
  147. package/dist/ui/urls.d.ts +4 -0
  148. package/dist/ui/urls.js +41 -0
  149. package/dist/ui/withdraw.d.ts +38 -0
  150. package/dist/ui/withdraw.js +30 -0
  151. package/dist/ui.css +2699 -0
  152. package/dist/widget-url.d.ts +1 -0
  153. package/dist/widget-url.js +16 -0
  154. package/package.json +46 -5
@@ -0,0 +1,272 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { forwardRef, useCallback, useEffect, useRef, useState, } from "react";
4
+ import { errorMessage } from "../../core/i18n/index.js";
5
+ import { formatPayingAmount } from "../../core/money.js";
6
+ import { runRequisitesFrame, } from "../../core/requisites-frame.js";
7
+ import { payToLabelKey } from "../../core/rules/paying.js";
8
+ import { getRuReceiptRule } from "../../core/rules/receipt.js";
9
+ import { getPayView, isTerminalDepositStatus } from "../../core/rules/requisites.js";
10
+ import * as ui from "../../ui/index.js";
11
+ import { getMethodLogo } from "../../ui/logos.js";
12
+ import { chainName } from "../chains.js";
13
+ import { useDepositFlowStore, usePayRoot, useStoreValue } from "../context.js";
14
+ import { useCountdown } from "../hooks/root.js";
15
+ import { assignRef, partProps } from "../part.js";
16
+ import { railKey } from "./basic.js";
17
+ import { Qr } from "./Qr.js";
18
+ const useDeposit = (owner) => {
19
+ const { root, flow, state } = useDepositFlowStore(owner);
20
+ return { root, actions: flow?.actions ?? null, state };
21
+ };
22
+ const HIGH_FEE_USD = 1;
23
+ const minutes = (seconds) => Math.max(1, Math.round(seconds / 60));
24
+ export const CryptoAddress = forwardRef(function CryptoAddress({ showQr = true, children, className, style, unstyled, ...rest }, ref) {
25
+ const { root, state } = useDeposit("<Pay.CryptoAddress>");
26
+ if (!state)
27
+ return null;
28
+ const method = state.method?.kind === "crypto" ? state.method : null;
29
+ const creating = state.step === "creating" && method !== null;
30
+ if (!creating && (state.step !== "crypto-address" || state.deposit?.kind !== "crypto"))
31
+ return null;
32
+ const deposit = state.deposit?.kind === "crypto" ? state.deposit : null;
33
+ const chainId = deposit?.chainId ?? method?.chainId ?? "";
34
+ const currency = deposit?.currency ?? method?.currency ?? "";
35
+ const fee = method?.feeUsd ? Number(method.feeUsd) : 0;
36
+ const network = chainName(chainId);
37
+ const active = deposit?.status === "active";
38
+ const slippage = method?.withdrawal?.maxSlippagePct ?? null;
39
+ const detailRows = [];
40
+ if (slippage) {
41
+ detailRows.push({ key: "slippage", label: `${root.t("address.maxSlippage")}:`, value: `${root.t("address.auto")} • ${slippage}%` });
42
+ }
43
+ if (method?.feeUsd) {
44
+ detailRows.push({ key: "fee", label: `${root.t("address.feeEstimate")}:`, value: `~$${fee.toFixed(2)}` });
45
+ }
46
+ if (method?.etaSeconds) {
47
+ detailRows.push({ key: "eta", label: `${root.t("address.eta")}:`, value: `< ${minutes(method.etaSeconds)} min` });
48
+ }
49
+ const details = detailRows.length > 0 ? (_jsx(ui.DetailsAccordion, { variant: "deposit", unstyled: unstyled ?? root.unstyled, label: `${slippage ? root.t("address.priceImpact") : root.t("address.feeEstimate")}:`, value: slippage ? `< ${slippage}%` : method?.feeUsd ? `~$${fee.toFixed(2)}` : null, rows: slippage ? detailRows : detailRows.filter((row) => row.key !== "fee") })) : null;
50
+ return (_jsxs(ui.CryptoAddressCard, { ...rest, ref: ref, part: "crypto-address", className: className, style: style, unstyled: unstyled, "data-status": deposit?.status ?? "creating", "data-chain": chainId, address: deposit?.address ?? null, loading: creating, showQr: showQr && (creating || active), overlay: currency ? _jsx(ui.TokenIcon, { symbol: currency, size: 48 }) : null, badge: chainId && currency && ui.needsChainBadge(chainId, currency) ? _jsx(ui.ChainIcon, { chainId: chainId, size: 24 }) : null, warning: currency ? root.t("address.warning", { currency: currency.toUpperCase(), network }) : null, highFee: fee > HIGH_FEE_USD ? root.t("address.highFee", { network, fee: fee.toFixed(2) }) : null, details: details, children: [deposit?.status === "expired" && (_jsx(ui.Notice, { variant: "hint", part: "warning", "data-variant": "expired", unstyled: unstyled, children: root.t("crypto.expired") })), children] }));
51
+ });
52
+ const useLiveView = (state, deposit) => {
53
+ const root = usePayRoot("<Pay.Requisites>");
54
+ const countdown = useCountdown(deposit?.expiresAt ?? null);
55
+ if (!state || !deposit)
56
+ return null;
57
+ const view = countdown.expired && state.view?.kind === "requisites"
58
+ ? getPayView(deposit, state.knownRequisites, root.client.clock.now())
59
+ : (state.view ?? getPayView(deposit, state.knownRequisites, root.client.clock.now()));
60
+ return view;
61
+ };
62
+ export const Requisites = forwardRef(function Requisites({ frameTitle, readyTimeoutMs, children, className, style, unstyled, ...rest }, ref) {
63
+ const { root, state } = useDeposit("<Pay.Requisites>");
64
+ const deposit = state?.deposit?.kind === "fiat" ? state.deposit : null;
65
+ const view = useLiveView(state, deposit);
66
+ if (!state || !deposit || !view || (state.step !== "requisites" && state.step !== "done"))
67
+ return null;
68
+ if (state.step === "done" && view.kind !== "closed")
69
+ return null;
70
+ const isUnstyled = unstyled ?? root.unstyled;
71
+ const delivery = view.kind === "frame" ? "frame" : "raw";
72
+ let body = null;
73
+ if (view.kind === "requisites") {
74
+ const r = view.requisites;
75
+ const amountLabel = formatPayingAmount(r.amount, deposit.currency);
76
+ const rows = [];
77
+ if (r.bank)
78
+ rows.push({ key: "bank", label: root.t("fiat.recipientBank"), value: r.bank });
79
+ if (r.recipient)
80
+ rows.push({ key: "recipient", label: root.t("fiat.recipientName"), value: r.recipient });
81
+ if (r.country)
82
+ rows.push({ key: "country", label: root.t("fiat.recipientCountry"), value: r.country });
83
+ rows.push({ key: r.kind, label: root.t(payToLabelKey(r.kind)), value: r.display, copy: r.copyValue, mono: true });
84
+ rows.push({ key: "amount", label: root.t("fiat.payAmount"), value: amountLabel, copy: r.amountCopy, accent: true });
85
+ body = (_jsx(ui.Requisites, { unstyled: isUnstyled, sensitive: false, rows: rows, note: root.t("fiat.payExactAmount", { amount: amountLabel }) }));
86
+ }
87
+ else if (view.kind === "frame") {
88
+ body = (_jsx(RequisitesFrame, { depositId: deposit.id, origins: view.frame?.origins, path: view.frame?.path, title: frameTitle, readyTimeoutMs: readyTimeoutMs, unstyled: unstyled }));
89
+ }
90
+ else if (view.kind === "qr") {
91
+ body = (_jsx(ui.QrImageCard, { unstyled: isUnstyled, children: _jsx(Qr, { value: view.payload ?? "", fallbackUrl: view.imageUrl, size: 208, unstyled: true }) }));
92
+ }
93
+ else if (view.kind === "closed") {
94
+ body = (_jsx(ui.Notice, { variant: "hint", part: "warning", "data-variant": "closed", unstyled: isUnstyled, children: root.t("requisites.closed") }));
95
+ }
96
+ return (_jsxs("div", { ...rest, ref: ref, ...partProps("requisites", { className, style, unstyled }, root.unstyled, {
97
+ sensitive: view.kind === "requisites",
98
+ }), ...(view.kind === "requisites" ? ui.SENSITIVE_PROPS : {}), "data-delivery": delivery, "data-view": view.kind, children: [body, children] }));
99
+ });
100
+ const systemTheme = () => {
101
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function")
102
+ return undefined;
103
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
104
+ };
105
+ export const RequisitesFrame = forwardRef(function RequisitesFrame({ depositId, origins, path, title, readyTimeoutMs, className, style, unstyled, children, ...rest }, ref) {
106
+ const root = usePayRoot("<Pay.RequisitesFrame>");
107
+ const container = useRef(null);
108
+ const handle = useRef(null);
109
+ const [status, setStatus] = useState({
110
+ status: "loading",
111
+ error: null,
112
+ });
113
+ const flow = root.mode === "deposit" ? root.flow.actions : null;
114
+ const originsKey = origins?.join(" ") ?? "";
115
+ const latest = useRef({ root, flow, title, readyTimeoutMs });
116
+ useEffect(() => {
117
+ latest.current = { root, flow, title, readyTimeoutMs };
118
+ });
119
+ const client = root.client;
120
+ useEffect(() => {
121
+ const element = container.current;
122
+ if (!element)
123
+ return;
124
+ const initial = latest.current;
125
+ const run = runRequisitesFrame(element, {
126
+ depositId,
127
+ origins: client.frameOrigins(originsKey ? originsKey.split(" ") : []),
128
+ path,
129
+ getTicket: (signal) => client.getRequisitesFrameTicket(depositId, signal),
130
+ lang: initial.root.intl,
131
+ theme: initial.root.theme ?? systemTheme(),
132
+ skin: initial.root.skin,
133
+ title: initial.title ?? initial.root.t("requisites.title"),
134
+ readyTimeoutMs: initial.readyTimeoutMs,
135
+ onStatus: (next, error) => {
136
+ setStatus({ status: next, error });
137
+ if (next === "unavailable" && error) {
138
+ client.emit({ type: "error", code: error.code, scope: "requisites.frame" });
139
+ }
140
+ },
141
+ onReceiptAttached: () => void latest.current.flow?.refreshContext(),
142
+ isActive: () => {
143
+ const current = latest.current.root;
144
+ if (current.mode !== "deposit")
145
+ return true;
146
+ const deposit = current.flow.getSnapshot().deposit;
147
+ return !(deposit?.kind === "fiat" && deposit.id === depositId && isTerminalDepositStatus(deposit.status));
148
+ },
149
+ });
150
+ handle.current = run;
151
+ return () => {
152
+ run.destroy();
153
+ handle.current = null;
154
+ };
155
+ }, [depositId, originsKey, path, client]);
156
+ const setRef = useCallback((element) => {
157
+ assignRef(ref, element);
158
+ }, [ref]);
159
+ return (_jsxs("div", { ...rest, ref: setRef, ...partProps("requisites-frame", { className, style, unstyled }, root.unstyled), "data-status": status.status, children: [status.status === "loading" && _jsx(ui.Loader, { label: root.t("requisites.loading"), unstyled: unstyled }), status.status === "unavailable" && (_jsxs(ui.ErrorBox, { part: "error", variant: "rail", unstyled: unstyled, "data-error": status.error?.code ?? "REQUISITES_FRAME_UNAVAILABLE", children: [_jsx("div", { children: errorMessage(root.t, status.error?.code === "REQUISITES_FRAME_UNAVAILABLE" || !status.error
160
+ ? { code: "REQUISITES_FRAME_UNAVAILABLE", details: {} }
161
+ : status.error, root.locale) }), _jsx("button", { type: "button", "data-binodex-pay": "retry", className: (unstyled ?? root.unstyled) ? undefined : "bp-max-button", onClick: () => handle.current?.retry(), children: root.t("common.retry") })] })), _jsx("div", { ref: container, "data-binodex-pay": "frame-slot", hidden: status.status === "unavailable" }), children] }));
162
+ });
163
+ export const ReceiptUpload = forwardRef(function ReceiptUpload({ accept, className, style, unstyled, children, ...rest }, ref) {
164
+ const { root, actions, state } = useDeposit("<Pay.ReceiptUpload>");
165
+ if (!state || !actions || state.step !== "requisites")
166
+ return null;
167
+ const deposit = state.deposit?.kind === "fiat" ? state.deposit : null;
168
+ if (!deposit ||
169
+ deposit.rail !== "ru" ||
170
+ !deposit.receipt.required ||
171
+ state.view?.kind !== "requisites") {
172
+ return null;
173
+ }
174
+ const isUnstyled = unstyled ?? root.unstyled;
175
+ const attached = deposit.receipt.attachedAt !== null;
176
+ const pdfOnly = getRuReceiptRule("paylee", deposit.methodId.split(":").pop())?.pdfOnly ?? false;
177
+ return (_jsxs("div", { ...rest, ...partProps("receipt", { className: [isUnstyled ? null : "bp-receipt-block", className].filter(Boolean).join(" ") || undefined, style, unstyled }, root.unstyled), "data-attached": attached ? "" : undefined, "data-pending": state.receiptPending ? "" : undefined, children: [attached ? (_jsx(ui.ReceiptAttached, { unstyled: isUnstyled })) : (_jsxs(_Fragment, { children: [pdfOnly ? (_jsx(ui.PdfReceiptWarning, { unstyled: isUnstyled })) : (_jsx(ui.Notice, { variant: "receipt", unstyled: isUnstyled, children: root.t("receipt.hintPaayzen") })), _jsx(ui.ReceiptForm, { unstyled: isUnstyled, inputRef: ref, accept: accept, pdfOnly: pdfOnly, sending: state.receiptPending, error: state.receiptError ? errorMessage(root.t, state.receiptError, root.locale) : null, onSubmit: (file) => actions.attachReceipt(file) })] })), children] }));
178
+ });
179
+ export const Countdown = forwardRef(function Countdown({ expiresAt, className, style, unstyled, children, ...rest }, ref) {
180
+ const { root, state } = useDeposit("<Pay.Countdown>");
181
+ const fiat = state?.deposit?.kind === "fiat" && state.step === "requisites" ? state.deposit : null;
182
+ const target = expiresAt !== undefined
183
+ ? expiresAt
184
+ : fiat
185
+ ? fiat.expiresAt
186
+ : state?.deposit?.kind === "crypto" && state.step === "crypto-address"
187
+ ? state.deposit.expiresAt
188
+ : null;
189
+ const framed = expiresAt === undefined && state?.step === "requisites" && state.view?.kind === "frame";
190
+ const attached = fiat !== null && fiat.receipt.required && fiat.receipt.attachedAt !== null;
191
+ const countdown = useCountdown(framed ? null : (target ?? null));
192
+ if (framed || attached || target === null || target === undefined || countdown.text === null)
193
+ return null;
194
+ const text = expiresAt === undefined && fiat
195
+ ? `${root.t(railKey(fiat.rail, "expiresIn"))}: ${countdown.expired ? "00:00" : countdown.text}`
196
+ : countdown.expired
197
+ ? root.t("countdown.expired")
198
+ : root.t("countdown.left", { time: countdown.text });
199
+ return (_jsx(ui.ExpiresLine, { role: "timer", "aria-live": "off", ...rest, ref: ref, part: "countdown", className: className, style: style, unstyled: unstyled, "data-expired": countdown.expired ? "" : undefined, children: children ?? text }));
200
+ });
201
+ export const RedirectButton = forwardRef(function RedirectButton({ children, ...rest }, ref) {
202
+ const { root, state } = useDeposit("<Pay.RedirectButton>");
203
+ if (!state || state.step !== "redirect" || state.view?.kind !== "redirect")
204
+ return null;
205
+ const url = state.view.url;
206
+ if (!/^https:\/\//i.test(url))
207
+ return null;
208
+ const rail = state.deposit?.kind === "fiat" ? state.deposit.rail : "ru";
209
+ return (_jsx(ui.SubmitLink, { ...rest, ref: ref, part: "redirect", href: url, children: children ?? root.t(railKey(rail, "openPaywall")) }));
210
+ });
211
+ export const RestartButton = forwardRef(function RestartButton({ onClick, children, ...rest }, ref) {
212
+ const root = usePayRoot("<Pay.RestartButton>");
213
+ const state = useStoreValue(root.flow);
214
+ let label = null;
215
+ let restart = null;
216
+ if (root.mode === "deposit") {
217
+ const s = state;
218
+ const fiat = s.deposit?.kind === "fiat" ? s.deposit : null;
219
+ if (!fiat || (s.step !== "requisites" && s.step !== "redirect" && s.step !== "done"))
220
+ return null;
221
+ const attached = fiat.receipt.required && fiat.receipt.attachedAt !== null;
222
+ const terminal = s.step === "done" || isTerminalDepositStatus(fiat.status) || attached;
223
+ label = root.t(railKey(fiat.rail, terminal ? "newPayment" : "cancel"));
224
+ restart = () => root.flow.actions.back();
225
+ }
226
+ else {
227
+ const s = state;
228
+ const terminal = s.step === "status" &&
229
+ s.withdrawal &&
230
+ (s.withdrawal.displayStatus === "failed" ||
231
+ ["completed", "failed", "cancelled", "refunded"].includes(s.withdrawal.status));
232
+ if (!terminal)
233
+ return null;
234
+ label = root.t("trigger.withdraw");
235
+ restart = () => root.flow.actions.reset();
236
+ }
237
+ return (_jsx(ui.LinkButton, { ...rest, ref: ref, part: "restart", onClick: (event) => {
238
+ onClick?.(event);
239
+ if (!event.defaultPrevented)
240
+ restart?.();
241
+ }, children: children ?? label }));
242
+ });
243
+ export const MethodNotice = forwardRef(function MethodNotice({ className, style, unstyled, children, ...rest }, ref) {
244
+ const { root, state } = useDeposit("<Pay.MethodNotice>");
245
+ if (!state || (state.step !== "enter-amount" && state.step !== "creating"))
246
+ return null;
247
+ const method = state.method?.kind === "fiat" ? state.method : null;
248
+ if (!method || getMethodLogo(method.methodId).badge !== "pdf")
249
+ return null;
250
+ return (_jsx(ui.Notice, { ...rest, ref: ref, part: "method-notice", variant: "receipt", className: className, style: style, unstyled: unstyled, children: children ?? root.t("fiat.receiptMayBeNeeded") }));
251
+ });
252
+ export const Onramp = forwardRef(function Onramp({ display = "embed", height = 560, className, style, unstyled, title, ...rest }, ref) {
253
+ const { root, actions, state } = useDeposit("<Pay.Onramp>");
254
+ const active = state?.step === "onramp";
255
+ useEffect(() => {
256
+ if (active && actions)
257
+ void actions.loadOnramp();
258
+ }, [active, actions]);
259
+ if (!state || !actions || !active)
260
+ return null;
261
+ if (state.onrampError) {
262
+ return (_jsxs(ui.ErrorBox, { part: "error", variant: "rail", unstyled: unstyled, "data-error": state.onrampError.code, children: [_jsx("div", { children: errorMessage(root.t, state.onrampError, root.locale) }), _jsx("button", { type: "button", "data-binodex-pay": "retry", className: (unstyled ?? root.unstyled) ? undefined : "bp-max-button", onClick: () => void actions.retryOnramp(), children: root.t("common.retry") })] }));
263
+ }
264
+ const url = state.onrampUrl;
265
+ if (!url || !/^https:\/\//i.test(url)) {
266
+ return state.onrampLoading ? _jsx(ui.Loader, { unstyled: unstyled }) : null;
267
+ }
268
+ if (display === "tab") {
269
+ return (_jsx(ui.SubmitLink, { part: "onramp", href: url, className: className, style: style, unstyled: unstyled, "data-display": "tab", children: root.t("onramp.open") }));
270
+ }
271
+ return (_jsx("iframe", { title: title ?? root.t("onramp.title"), allow: "accelerometer; autoplay; camera; gyroscope; payment; clipboard-write", referrerPolicy: "no-referrer", height: height, ...rest, ref: ref, src: url, ...partProps("onramp", { className, style: { width: "100%", border: 0, ...style }, unstyled }, root.unstyled), "data-display": "embed" }));
272
+ });
@@ -0,0 +1,24 @@
1
+ import { type InputHTMLAttributes, type ReactNode } from "react";
2
+ import * as ui from "../../ui/index.js";
3
+ export declare const AmountInput: import("react").ForwardRefExoticComponent<Omit<InputHTMLAttributes<HTMLInputElement>, "style" | "children" | "className" | "onChange" | "value" | "size"> & ui.PartStyleProps & {
4
+ label?: ReactNode;
5
+ hint?: ReactNode;
6
+ } & {
7
+ showMax?: boolean;
8
+ } & import("react").RefAttributes<HTMLInputElement>>;
9
+ export declare const PhoneInput: import("react").ForwardRefExoticComponent<Omit<InputHTMLAttributes<HTMLInputElement>, "style" | "children" | "className" | "onChange" | "value" | "size"> & ui.PartStyleProps & {
10
+ label?: ReactNode;
11
+ hint?: ReactNode;
12
+ } & {
13
+ always?: boolean;
14
+ } & import("react").RefAttributes<HTMLInputElement>>;
15
+ export declare const AddressInput: import("react").ForwardRefExoticComponent<Omit<InputHTMLAttributes<HTMLInputElement>, "style" | "children" | "className" | "onChange" | "value" | "size"> & ui.PartStyleProps & {
16
+ label?: ReactNode;
17
+ hint?: ReactNode;
18
+ } & import("react").RefAttributes<HTMLInputElement>>;
19
+ export declare const TwoFactorInput: import("react").ForwardRefExoticComponent<Omit<InputHTMLAttributes<HTMLInputElement>, "style" | "children" | "className" | "onChange" | "value" | "size"> & ui.PartStyleProps & {
20
+ label?: ReactNode;
21
+ hint?: ReactNode;
22
+ } & {
23
+ always?: boolean;
24
+ } & import("react").RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,92 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { forwardRef } from "react";
4
+ import { errorMessage } from "../../core/i18n/index.js";
5
+ import { formatAmountMax2, formatMoney } from "../../core/money.js";
6
+ import { addressFamily } from "../../core/rules/address.js";
7
+ import * as ui from "../../ui/index.js";
8
+ import { SENSITIVE_PROPS } from "../part.js";
9
+ import { railKey, useFlowState } from "./basic.js";
10
+ const ADDRESS_PLACEHOLDER = {
11
+ solana: "Sol...",
12
+ bitcoin: "bc1...",
13
+ tron: "T...",
14
+ };
15
+ export const AmountInput = forwardRef(function AmountInput({ label, hint, showMax = true, className, style, unstyled, id, placeholder, ...rest }, ref) {
16
+ const { root, state } = useFlowState("<Pay.AmountInput>");
17
+ if (root.mode === "deposit") {
18
+ const s = state;
19
+ if (s.step !== "enter-amount" && s.step !== "creating")
20
+ return null;
21
+ if (s.method?.kind !== "fiat")
22
+ return null;
23
+ const method = s.method;
24
+ let defaultHint = null;
25
+ if (method.minAmount && method.maxAmount) {
26
+ defaultHint = root.t("amount.range", {
27
+ min: formatMoney(method.minAmount, method.currency, root.intl),
28
+ max: formatMoney(method.maxAmount, method.currency, root.intl),
29
+ });
30
+ }
31
+ else if (method.minAmount) {
32
+ defaultHint = root.t("amount.min", { amount: formatMoney(method.minAmount, method.currency, root.intl) });
33
+ }
34
+ const error = s.amountError;
35
+ return (_jsx(ui.AmountField, { ref: ref, id: id, part: "amount", variant: "pay", className: className, style: style, unstyled: unstyled, label: label ?? root.t(railKey(method.rail, "amountLabel")), suffix: method.currency, value: s.amount, placeholder: placeholder, disabled: s.step === "creating" || rest.disabled, hint: hint ?? defaultHint, error: error ? errorMessage(root.t, error, root.locale) : null, sanitize: false, inputProps: rest, onChange: (value) => root.flow.actions.setAmount(value) }));
36
+ }
37
+ const s = state;
38
+ if (s.step === "loading" || s.step === "status" || s.step === "error")
39
+ return null;
40
+ const actions = root.flow.actions;
41
+ const balance = s.context?.balance;
42
+ const available = balance ? (balance.withdrawable ?? balance.available) : null;
43
+ const error = s.amountError ? errorMessage(root.t, s.amountError, root.locale) : null;
44
+ return (_jsx(ui.AmountField, { ref: ref, id: id, part: "amount", variant: "withdraw", className: className, style: style, unstyled: unstyled, label: label ?? root.t("withdraw.amount"), suffix: root.t("withdraw.usd"), value: s.amount, placeholder: placeholder, disabled: s.step === "submitting" || rest.disabled, hint: hint, error: error, sanitize: false, inputProps: rest, onMax: showMax ? actions.setMax : undefined, maxLabel: root.t("withdraw.max"), footer: [
45
+ `$${formatAmountMax2(s.amount || 0)}`,
46
+ `${root.t("header.balance")}: $${formatAmountMax2(available ?? 0)}`,
47
+ ], onChange: actions.setAmount }));
48
+ });
49
+ export const PhoneInput = forwardRef(function PhoneInput({ label, hint, always = false, className, style, unstyled, id, ...rest }, ref) {
50
+ const { root, state } = useFlowState("<Pay.PhoneInput>");
51
+ if (root.mode !== "deposit")
52
+ return null;
53
+ const s = state;
54
+ if (s.step !== "enter-amount" && s.step !== "creating")
55
+ return null;
56
+ if (s.method?.kind !== "fiat" || !always)
57
+ return null;
58
+ return (_jsx(ui.TextField, { ref: ref, id: id, part: "phone", variant: "pay", type: "tel", className: className, style: style, unstyled: unstyled, label: label ?? root.t("phone.label"), hint: hint, value: s.customerPhone, inputProps: { inputMode: "tel", autoComplete: "tel", ...rest }, onChange: (value) => root.flow.actions.setCustomerPhone(value) }));
59
+ });
60
+ export const AddressInput = forwardRef(function AddressInput({ label, hint, className, style, unstyled, id, placeholder, ...rest }, ref) {
61
+ const { root, state } = useFlowState("<Pay.AddressInput>");
62
+ if (root.mode !== "withdraw")
63
+ return null;
64
+ const s = state;
65
+ if (s.step === "loading" || s.step === "status" || s.step === "error")
66
+ return null;
67
+ const chainId = s.method?.chainId ?? "";
68
+ const family = s.method ? addressFamily(chainId) : "evm";
69
+ const errorText = s.addressError ? root.t(`address.invalid.${family}`) : null;
70
+ return (_jsx(ui.TextField, { ref: ref, id: id, part: "address", variant: "withdraw", className: className, style: style, unstyled: unstyled, label: label ?? root.t("withdraw.address"), hint: hint, error: errorText, value: s.address, placeholder: placeholder ?? ADDRESS_PLACEHOLDER[chainId] ?? "0x...", disabled: s.step === "submitting" || rest.disabled, inputProps: {
71
+ autoComplete: "off",
72
+ autoCapitalize: "none",
73
+ autoCorrect: "off",
74
+ spellCheck: false,
75
+ ...SENSITIVE_PROPS,
76
+ ...rest,
77
+ }, onChange: (value) => root.flow.actions.setAddress(value) }));
78
+ });
79
+ export const TwoFactorInput = forwardRef(function TwoFactorInput({ label, hint, always = false, className, style, unstyled, id, ...rest }, ref) {
80
+ const { root, state } = useFlowState("<Pay.TwoFactorInput>");
81
+ if (root.mode !== "withdraw")
82
+ return null;
83
+ const s = state;
84
+ if (s.step === "loading" || s.step === "status" || s.step === "error")
85
+ return null;
86
+ if (!always && s.step !== "two-factor" && !s.twoFactorRequired)
87
+ return null;
88
+ const error = s.submitError && s.submitError.code.startsWith("TWO_FA_")
89
+ ? errorMessage(root.t, s.submitError, root.locale)
90
+ : null;
91
+ return (_jsx(ui.TwoFactorField, { ref: ref, id: id, part: "two-factor", className: className, style: style, unstyled: unstyled, label: label ?? root.t("withdraw.twoFactor"), hint: hint ?? root.t("withdraw.twoFactorHint"), error: error, value: s.twoFactorCode, disabled: s.step === "submitting" || rest.disabled, inputProps: rest, onChange: (value) => root.flow.actions.setTwoFactorCode(value) }));
92
+ });
@@ -0,0 +1,32 @@
1
+ import { type HTMLAttributes, type ReactNode } from "react";
2
+ import type { CryptoMethod, FiatMethod, OnrampMethod, PayMethod } from "../../core/types.js";
3
+ import { type PartStyleProps } from "../part.js";
4
+ type ListProps = Omit<HTMLAttributes<HTMLDivElement>, "className" | "style" | "children"> & PartStyleProps;
5
+ export type MethodOption = {
6
+ kind: "crypto";
7
+ id: "crypto";
8
+ methods: CryptoMethod[];
9
+ } | FiatMethod | OnrampMethod;
10
+ export interface MethodPickerProps extends ListProps {
11
+ filter?: (method: PayMethod) => boolean;
12
+ renderItem?: (option: MethodOption, state: {
13
+ selected: boolean;
14
+ select: () => void;
15
+ }) => ReactNode;
16
+ }
17
+ export declare const MethodPicker: import("react").ForwardRefExoticComponent<MethodPickerProps & import("react").RefAttributes<HTMLDivElement>>;
18
+ export interface CurrencyPickerProps extends ListProps {
19
+ renderItem?: (currency: string, state: {
20
+ selected: boolean;
21
+ select: () => void;
22
+ }) => ReactNode;
23
+ }
24
+ export declare const CurrencyPicker: import("react").ForwardRefExoticComponent<CurrencyPickerProps & import("react").RefAttributes<HTMLDivElement>>;
25
+ export interface NetworkPickerProps extends ListProps {
26
+ renderItem?: (method: CryptoMethod, state: {
27
+ selected: boolean;
28
+ select: () => void;
29
+ }) => ReactNode;
30
+ }
31
+ export declare const NetworkPicker: import("react").ForwardRefExoticComponent<NetworkPickerProps & import("react").RefAttributes<HTMLDivElement>>;
32
+ export {};