@binopartner/pay-sdk 0.3.4 → 0.4.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 (44) hide show
  1. package/README.md +19 -3
  2. package/dist/core/client.d.ts +9 -1
  3. package/dist/core/client.js +16 -1
  4. package/dist/core/errors.d.ts +7 -1
  5. package/dist/core/errors.js +6 -0
  6. package/dist/core/flows/promo.d.ts +49 -0
  7. package/dist/core/flows/promo.js +155 -0
  8. package/dist/core/flows/withdraw.d.ts +7 -1
  9. package/dist/core/flows/withdraw.js +56 -3
  10. package/dist/core/i18n/ar.js +55 -0
  11. package/dist/core/i18n/base.js +12 -0
  12. package/dist/core/i18n/cs.js +55 -0
  13. package/dist/core/i18n/de.js +55 -0
  14. package/dist/core/i18n/en.d.ts +55 -0
  15. package/dist/core/i18n/en.js +55 -0
  16. package/dist/core/i18n/es.js +55 -0
  17. package/dist/core/i18n/fr.js +55 -0
  18. package/dist/core/i18n/hi.js +55 -0
  19. package/dist/core/i18n/it.js +55 -0
  20. package/dist/core/i18n/ru.js +55 -0
  21. package/dist/core/i18n/tr.js +55 -0
  22. package/dist/core/i18n/ua.js +55 -0
  23. package/dist/core/index.d.ts +4 -0
  24. package/dist/core/index.js +2 -0
  25. package/dist/core/rules/bonus.d.ts +27 -0
  26. package/dist/core/rules/bonus.js +60 -0
  27. package/dist/core/types.d.ts +69 -0
  28. package/dist/core/wire.d.ts +18 -1
  29. package/dist/core/wire.js +79 -0
  30. package/dist/elements/Root.js +14 -7
  31. package/dist/elements/components/basic.js +4 -1
  32. package/dist/elements/components/bonus.d.ts +19 -0
  33. package/dist/elements/components/bonus.js +177 -0
  34. package/dist/elements/context.d.ts +3 -0
  35. package/dist/elements/hooks/promo.d.ts +37 -0
  36. package/dist/elements/hooks/promo.js +66 -0
  37. package/dist/elements/index.d.ts +7 -0
  38. package/dist/elements/index.js +2 -0
  39. package/dist/elements/presets/DepositForm.d.ts +2 -0
  40. package/dist/elements/presets/DepositForm.js +4 -2
  41. package/dist/elements/presets/WithdrawForm.d.ts +2 -0
  42. package/dist/elements/presets/WithdrawForm.js +3 -1
  43. package/dist/elements.css +394 -0
  44. package/package.json +1 -1
@@ -0,0 +1,177 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { forwardRef, useCallback, useId, useRef, } from "react";
4
+ import { formatDecimal, formatPercentValue, formatUsd } from "../../core/money.js";
5
+ import { PROMO_CODE_MAX_LENGTH, formatDuration, maxCountedDepositUsd, wholePercent, withdrawBonusGate, withdrawalUnlockRule, } from "../../core/rules/bonus.js";
6
+ import * as ui from "../../ui/index.js";
7
+ import { usePayRoot, useWithdrawFlowStore } from "../context.js";
8
+ import { usePromoCode } from "../hooks/promo.js";
9
+ import { partProps } from "../part.js";
10
+ import { classes } from "../../ui/part.js";
11
+ const GiftIcon = ({ className }) => (_jsx("svg", { width: 16, height: 16, viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", className: className, children: _jsx("path", { d: "M2.5 7.5h11v6a1 1 0 0 1-1 1h-9a1 1 0 0 1-1-1v-6ZM1.5 5a1 1 0 0 1 1-1h11a1 1 0 0 1 1 1v2.5h-13V5ZM8 4v10.5M8 4S7 1.5 5.25 1.5a1.25 1.25 0 0 0 0 2.5H8Zm0 0s1-2.5 2.75-2.5a1.25 1.25 0 0 1 0 2.5H8Z", stroke: "currentColor", strokeWidth: "1.3", strokeLinejoin: "round" }) }));
12
+ const positive = (value) => value !== null && value !== undefined && Number(value) > 0;
13
+ const remainingMs = (iso, now) => {
14
+ if (!iso)
15
+ return null;
16
+ const at = /^\d+$/.test(iso) ? Number(iso) : Date.parse(iso);
17
+ return Number.isFinite(at) && at > now ? at - now : null;
18
+ };
19
+ const Progress = ({ c, value, max = 100, label }) => {
20
+ const share = max > 0 ? Math.min(100, Math.max(0, (value / max) * 100)) : 0;
21
+ return (_jsx("div", { className: c("bonus-progress"), "data-binodex-pay": "bonus-progress", role: "progressbar", "aria-label": label, "aria-valuemin": 0, "aria-valuemax": max, "aria-valuenow": Math.min(value, max), children: _jsx("span", { className: c("bonus-progress-bar"), style: { width: `${share}%` } }) }));
22
+ };
23
+ const headlineOf = (t, bonus, intl) => {
24
+ if (!positive(bonus.value))
25
+ return null;
26
+ if (bonus.type === "FIXED")
27
+ return t("promo.headlineFixed", { amount: formatUsd(bonus.value) });
28
+ const pct = formatPercentValue(bonus.value, intl);
29
+ return positive(bonus.maxBonusUsd)
30
+ ? t("promo.headlinePercentCap", { pct, max: formatUsd(bonus.maxBonusUsd) })
31
+ : t("promo.headlinePercent", { pct });
32
+ };
33
+ const rulesOf = (t, bonus, preview, intl) => {
34
+ const rules = [];
35
+ const wager = positive(bonus.wagerMultiplier);
36
+ if (wager) {
37
+ const multiplier = formatDecimal(bonus.wagerMultiplier, intl, { maximumFractionDigits: 2 });
38
+ rules.push(bonus.durationHours !== null && bonus.durationHours > 0
39
+ ? t("promo.wager", { multiplier, duration: formatDuration(t, bonus.durationHours * 3600000) })
40
+ : t("promo.wagerNoDeadline", { multiplier }));
41
+ }
42
+ const unlock = withdrawalUnlockRule(bonus.withdrawalUnlockPct);
43
+ if (unlock === "anytime" || !wager)
44
+ rules.push(t("promo.unlockAnytime"));
45
+ else if (unlock === "partial")
46
+ rules.push(t("promo.unlockPartial", { pct: wholePercent(bonus.withdrawalUnlockPct) }));
47
+ else
48
+ rules.push(t("promo.unlockFull"));
49
+ rules.push(t("promo.burn"));
50
+ if (preview?.bonus?.firstDepositOnly && preview.code === bonus.code)
51
+ rules.push(t("promo.firstDepositOnly"));
52
+ return rules;
53
+ };
54
+ const AppliedCard = ({ c, promo, now }) => {
55
+ const root = usePayRoot("<Pay.PromoCode>");
56
+ const { t, intl } = root;
57
+ const bonus = promo.attached;
58
+ if (!bonus)
59
+ return null;
60
+ const headline = headlineOf(t, bonus, intl);
61
+ const maxCounted = maxCountedDepositUsd(bonus);
62
+ const left = remainingMs(bonus.codeExpiresAt, now);
63
+ const terms = [];
64
+ if (positive(bonus.minDepositUsd))
65
+ terms.push(["min", t("promo.minDeposit"), formatUsd(bonus.minDepositUsd)]);
66
+ if (maxCounted !== null)
67
+ terms.push(["max", t("promo.maxDeposit"), formatUsd(maxCounted)]);
68
+ if (left !== null)
69
+ terms.push(["expires", t("promo.expiresIn"), formatDuration(t, left)]);
70
+ const busy = promo.pending !== null;
71
+ return (_jsxs("div", { className: c("promo-card"), "data-binodex-pay": "promo-card", children: [_jsxs("div", { className: c("promo-card-head"), children: [_jsx("span", { className: c("promo-code"), "data-binodex-pay": "promo-code", dir: "ltr", children: bonus.code }), _jsxs("span", { className: c("promo-badge"), "data-binodex-pay": "promo-badge", children: [_jsx(ui.icons.CheckIcon, { size: 10 }), t("promo.applied")] })] }), bonus.title && bonus.title !== bonus.code ? _jsx("p", { className: c("promo-title"), children: bonus.title }) : null, headline ? (_jsx("p", { className: c("promo-headline"), "data-binodex-pay": "promo-headline", children: headline })) : null, terms.length > 0 ? (_jsx("dl", { className: c("promo-terms"), "data-binodex-pay": "promo-terms", children: terms.map(([key, label, value]) => (_jsxs("div", { className: c("promo-term"), "data-term": key, children: [_jsx("dt", { children: label }), _jsx("dd", { children: value })] }, key))) })) : null, _jsx("ul", { className: c("promo-rules"), "data-binodex-pay": "promo-rules", children: rulesOf(t, bonus, promo.preview, intl).map((rule) => (_jsx("li", { children: rule }, rule))) }), _jsx("button", { type: "button", className: c("promo-remove"), "data-binodex-pay": "promo-remove", disabled: busy, "aria-busy": promo.pending === "detach" || undefined, onClick: () => void promo.remove(), children: t("promo.remove") }), promo.errorText ? (_jsx("p", { role: "alert", className: c("promo-message"), "data-binodex-pay": "promo-message", "data-error": promo.error?.code, children: promo.errorText })) : null] }));
72
+ };
73
+ const ActiveLine = ({ c, bonus, now }) => {
74
+ const { t } = usePayRoot("<Pay.PromoCode>");
75
+ const pct = wholePercent(bonus.progressPct);
76
+ const burning = bonus.status === "BURN_PENDING";
77
+ const left = burning ? null : remainingMs(bonus.expiresAt, now);
78
+ const notes = burning
79
+ ? [t("promo.activeBurnPending")]
80
+ : [
81
+ bonus.wageredUsd !== null && bonus.goalUsd !== null
82
+ ? t("promo.activeProgress", { wagered: formatUsd(bonus.wageredUsd), goal: formatUsd(bonus.goalUsd) })
83
+ : null,
84
+ left !== null ? t("promo.activeLeft", { duration: formatDuration(t, left) }) : null,
85
+ ].filter((note) => note !== null);
86
+ const title = t("promo.activeTitle", { code: bonus.code });
87
+ return (_jsxs("div", { className: c("promo-active"), "data-binodex-pay": "promo-active", "data-status": bonus.status, children: [_jsxs("div", { className: c("promo-active-head"), children: [_jsx(GiftIcon, { className: c("promo-icon") }), _jsx("span", { className: c("promo-active-title"), children: title }), _jsxs("span", { className: c("promo-active-pct"), children: [pct, "%"] })] }), _jsx(Progress, { c: c, value: pct, label: title }), notes.length > 0 ? _jsx("p", { className: c("promo-active-note"), children: notes.join(" · ") }) : null] }));
88
+ };
89
+ /**
90
+ * The promo code of a deposit: a collapsed «Have a promo code?» row, the code field,
91
+ * the attached code with its terms, or the progress of the bonus already credited.
92
+ * Renders nothing when promo codes are off or the backend does not know them.
93
+ */
94
+ export const PromoCode = forwardRef(function PromoCode({ className, style, unstyled, ...rest }, ref) {
95
+ const root = usePayRoot("<Pay.PromoCode>");
96
+ const promo = usePromoCode();
97
+ const inputId = useId();
98
+ const messageId = useId();
99
+ const focusInput = useRef(false);
100
+ const inputRef = useCallback((node) => {
101
+ if (node && focusInput.current) {
102
+ focusInput.current = false;
103
+ node.focus();
104
+ }
105
+ }, []);
106
+ if (!root.open || promo.view === "hidden")
107
+ return null;
108
+ const c = classes(unstyled ?? root.unstyled);
109
+ const { t } = root;
110
+ const now = root.client.clock.now();
111
+ const busy = promo.pending !== null;
112
+ let body = null;
113
+ switch (promo.view) {
114
+ case "collapsed":
115
+ body = (_jsxs("button", { type: "button", className: c("promo-toggle"), "data-binodex-pay": "promo-toggle", "aria-expanded": false, onClick: () => {
116
+ focusInput.current = true;
117
+ promo.open();
118
+ }, children: [_jsx(GiftIcon, { className: c("promo-icon") }), _jsx("span", { children: t("promo.toggle") })] }));
119
+ break;
120
+ case "editing": {
121
+ const message = promo.reasonText ?? promo.errorText;
122
+ const submit = () => {
123
+ if (promo.code && !busy)
124
+ void promo.apply();
125
+ };
126
+ body = (_jsxs("div", { className: c("promo-form"), "data-binodex-pay": "promo-form", children: [_jsxs("div", { className: c("promo-form-head"), children: [_jsx("label", { className: c("promo-label"), htmlFor: inputId, children: t("promo.label") }), _jsx("button", { type: "button", className: c("promo-hide"), "data-binodex-pay": "promo-hide", "aria-label": t("promo.hide"), disabled: busy, onClick: promo.close, children: _jsx(ui.icons.CloseIcon, { size: 10 }) })] }), _jsxs("div", { className: c("promo-row"), children: [_jsx("input", { ref: inputRef, id: inputId, type: "text", className: c("promo-input"), "data-binodex-pay": "promo-input", dir: "ltr", value: promo.code, placeholder: t("promo.placeholder"), maxLength: PROMO_CODE_MAX_LENGTH, autoComplete: "off", autoCapitalize: "characters", spellCheck: false, enterKeyHint: "go", readOnly: busy, "aria-invalid": promo.reason !== null || undefined, "aria-describedby": message ? messageId : undefined, onChange: (event) => promo.setCode(event.target.value), onKeyDown: (event) => {
127
+ if (event.key !== "Enter")
128
+ return;
129
+ event.preventDefault();
130
+ submit();
131
+ } }), _jsx("button", { type: "button", className: c("promo-apply"), "data-binodex-pay": "promo-apply", disabled: !promo.code || busy, "aria-busy": busy || undefined, onClick: submit, children: busy ? t("promo.checking") : t("promo.apply") })] }), message ? (_jsx("p", { id: messageId, role: "alert", className: c("promo-message"), "data-binodex-pay": "promo-message", "data-reason": promo.reason ?? undefined, "data-error": promo.reason === null ? promo.error?.code : undefined, children: message })) : null] }));
132
+ break;
133
+ }
134
+ case "applied":
135
+ body = _jsx(AppliedCard, { c: c, promo: promo, now: now });
136
+ break;
137
+ case "active":
138
+ body = promo.active ? _jsx(ActiveLine, { c: c, bonus: promo.active, now: now }) : null;
139
+ break;
140
+ }
141
+ return (_jsx("div", { ...rest, ref: ref, ...partProps("promo", { className, style, unstyled }, root.unstyled), "data-view": promo.view, "data-pending": promo.pending ?? undefined, children: body }));
142
+ });
143
+ /**
144
+ * What a live promo bonus means for this withdrawal: locked until the trading volume is
145
+ * reached, waiting for open positions to close, or open once the user agrees that it burns
146
+ * the rest of the bonus (a required checkbox; the submit button waits for it).
147
+ */
148
+ export const WithdrawBonus = forwardRef(function WithdrawBonus({ className, style, unstyled, ...rest }, ref) {
149
+ const { root, flow, state } = useWithdrawFlowStore("<Pay.WithdrawBonus>");
150
+ if (!root.open || !flow || !state)
151
+ return null;
152
+ if (state.step === "loading" || state.step === "error" || state.step === "status")
153
+ return null;
154
+ const bonus = state.bonus;
155
+ const gate = withdrawBonusGate(bonus, state.burnConsent);
156
+ if (!bonus || gate === "none")
157
+ return null;
158
+ const c = classes(unstyled ?? root.unstyled);
159
+ const { t } = root;
160
+ let body;
161
+ if (gate === "burn-pending") {
162
+ body = (_jsxs(_Fragment, { children: [_jsx("p", { className: c("withdraw-bonus-title"), children: t("withdrawBonus.pendingTitle") }), _jsx("p", { className: c("withdraw-bonus-text"), children: t("withdrawBonus.pendingBody") })] }));
163
+ }
164
+ else if (gate === "locked") {
165
+ const unlock = wholePercent(bonus.unlockPct);
166
+ const progress = wholePercent(bonus.progressPct);
167
+ const partial = withdrawalUnlockRule(bonus.unlockPct) === "partial";
168
+ const meta = t("withdrawBonus.progress", { progress, unlock: partial ? unlock : 100 });
169
+ body = (_jsxs(_Fragment, { children: [_jsx("p", { className: c("withdraw-bonus-title"), children: t("withdrawBonus.lockedTitle") }), _jsx("p", { className: c("withdraw-bonus-text"), children: partial ? t("withdrawBonus.lockedPartial", { unlock }) : t("withdrawBonus.lockedFull") }), _jsx(Progress, { c: c, value: progress, max: partial ? unlock : 100, label: meta }), _jsx("p", { className: c("withdraw-bonus-meta"), children: meta })] }));
170
+ }
171
+ else {
172
+ body = (_jsxs(_Fragment, { children: [_jsx("p", { className: c("withdraw-bonus-title"), children: t("withdrawBonus.burnTitle") }), _jsx("p", { className: c("withdraw-bonus-text"), children: positive(bonus.bonusLeftUsd)
173
+ ? t("withdrawBonus.burnBody", { amount: formatUsd(bonus.bonusLeftUsd) })
174
+ : t("withdrawBonus.burnBodyGeneric") }), _jsxs("label", { className: c("withdraw-bonus-consent"), children: [_jsx("input", { type: "checkbox", className: c("checkbox"), "data-binodex-pay": "burn-consent", checked: state.burnConsent, disabled: state.step === "submitting", required: true, onChange: (event) => flow.actions.setBurnConsent(event.target.checked) }), _jsx("span", { children: t("withdrawBonus.consent") })] })] }));
175
+ }
176
+ return (_jsx("div", { role: gate === "locked" || gate === "burn-pending" ? "note" : undefined, ...rest, ref: ref, ...partProps("withdraw-bonus", { className, style, unstyled }, root.unstyled), "data-gate": gate, "data-status": bonus.status, children: body }));
177
+ });
@@ -2,6 +2,7 @@ import type { AppearanceSkin } from "../core/appearance.js";
2
2
  import type { PayClient } from "../core/client.js";
3
3
  import type { PayError } from "../core/errors.js";
4
4
  import type { DepositFlow } from "../core/flows/deposit.js";
5
+ import type { PromoFlow } from "../core/flows/promo.js";
5
6
  import type { WithdrawFlow } from "../core/flows/withdraw.js";
6
7
  import type { PayLocale, Translate } from "../core/i18n/index.js";
7
8
  import type { ReadableStore, Store } from "../core/store.js";
@@ -18,6 +19,8 @@ export interface PayRootValue {
18
19
  client: PayClient;
19
20
  mode: PayMode;
20
21
  flow: DepositFlow | WithdrawFlow;
22
+ /** Promo codes of a deposit root; null in withdraw mode. Loaded by the first promo part mounted. */
23
+ promo: PromoFlow | null;
21
24
  open: boolean;
22
25
  setOpen: (open: boolean) => void;
23
26
  restart: () => void;
@@ -0,0 +1,37 @@
1
+ import type { PayError } from "../../core/errors.js";
2
+ import { type PromoPending, type PromoView } from "../../core/flows/promo.js";
3
+ import type { ActiveBonus, AttachedBonus, BonusPreview } from "../../core/types.js";
4
+ export interface UsePromoCodeResult {
5
+ /** What to show; `hidden` while loading, on a backend without promo codes, when they are off, or in withdraw mode. */
6
+ view: PromoView;
7
+ /** Promo codes are on for this user. */
8
+ enabled: boolean;
9
+ /** The code waiting for the next deposit. */
10
+ attached: AttachedBonus | null;
11
+ /** The bonus credited and being traded through. */
12
+ active: ActiveBonus | null;
13
+ /** The terms of the code checked last, with `firstDepositOnly`. */
14
+ preview: BonusPreview | null;
15
+ /** The typed code, in capitals. */
16
+ code: string;
17
+ pending: PromoPending | null;
18
+ /** Why the code was refused (`BONUS_REJECT_REASONS`, or a reason this SDK does not know). */
19
+ reason: string | null;
20
+ reasonText: string | null;
21
+ /** A request that failed for another cause. */
22
+ error: PayError | null;
23
+ errorText: string | null;
24
+ open: () => void;
25
+ close: () => void;
26
+ setCode: (raw: string) => void;
27
+ /** Checks the typed code, then attaches it to the next deposit. */
28
+ apply: () => Promise<void>;
29
+ /** Takes the attached code off. */
30
+ remove: () => Promise<void>;
31
+ refresh: () => Promise<void>;
32
+ }
33
+ /**
34
+ * Promo codes of the deposit form: the state of `<Pay.PromoCode>` for a layout of your own.
35
+ * Mounting it loads the user's bonuses once per opened form.
36
+ */
37
+ export declare function usePromoCode(): UsePromoCodeResult;
@@ -0,0 +1,66 @@
1
+ "use client";
2
+ import { useEffect, useMemo } from "react";
3
+ import { promoViewOf, } from "../../core/flows/promo.js";
4
+ import { errorMessage } from "../../core/i18n/index.js";
5
+ import { promoReasonKey } from "../../core/rules/bonus.js";
6
+ import { usePayRoot, useStoreValue } from "../context.js";
7
+ const IDLE_STATE = {
8
+ status: "idle",
9
+ bonuses: null,
10
+ open: false,
11
+ code: "",
12
+ pending: null,
13
+ preview: null,
14
+ reason: null,
15
+ error: null,
16
+ };
17
+ const IDLE_STORE = {
18
+ getSnapshot: () => IDLE_STATE,
19
+ subscribe: () => () => undefined,
20
+ };
21
+ const done = () => Promise.resolve();
22
+ const IDLE_ACTIONS = {
23
+ open: () => undefined,
24
+ close: () => undefined,
25
+ setCode: () => undefined,
26
+ apply: done,
27
+ remove: done,
28
+ refresh: done,
29
+ };
30
+ /**
31
+ * Promo codes of the deposit form: the state of `<Pay.PromoCode>` for a layout of your own.
32
+ * Mounting it loads the user's bonuses once per opened form.
33
+ */
34
+ export function usePromoCode() {
35
+ const root = usePayRoot("usePromoCode()");
36
+ const promo = root.promo;
37
+ const state = useStoreValue(promo ?? IDLE_STORE);
38
+ useEffect(() => {
39
+ if (root.open)
40
+ promo?.actions.start();
41
+ }, [promo, root.open]);
42
+ const actions = promo?.actions ?? IDLE_ACTIONS;
43
+ const { t, locale } = root;
44
+ const { reason, error } = state;
45
+ const reasonText = useMemo(() => (reason === null ? null : t(promoReasonKey(reason))), [t, reason]);
46
+ const errorText = useMemo(() => (error === null ? null : errorMessage(t, error, locale)), [t, locale, error]);
47
+ return {
48
+ view: promoViewOf(state),
49
+ enabled: state.bonuses?.enabled ?? false,
50
+ attached: state.bonuses?.attached ?? null,
51
+ active: state.bonuses?.active ?? null,
52
+ preview: state.preview,
53
+ code: state.code,
54
+ pending: state.pending,
55
+ reason,
56
+ reasonText,
57
+ error,
58
+ errorText,
59
+ open: actions.open,
60
+ close: actions.close,
61
+ setCode: actions.setCode,
62
+ apply: actions.apply,
63
+ remove: actions.remove,
64
+ refresh: actions.refresh,
65
+ };
66
+ }
@@ -9,6 +9,8 @@ export { Countdown, CryptoAddress, MethodNotice, Onramp, ReceiptUpload, Redirect
9
9
  export type { OnrampDisplay, OnrampProps, RequisitesFrameProps, RequisitesProps } from "./components/deposit.js";
10
10
  export { Quote, SlippageWarning, Status } from "./components/status.js";
11
11
  export type { StatusProps } from "./components/status.js";
12
+ export { PromoCode, WithdrawBonus } from "./components/bonus.js";
13
+ export type { PromoCodeProps, WithdrawBonusProps } from "./components/bonus.js";
12
14
  export { Qr } from "./components/Qr.js";
13
15
  export type { QrProps } from "./components/Qr.js";
14
16
  export { DepositForm } from "./presets/DepositForm.js";
@@ -19,10 +21,15 @@ export { useBalance, useCountdown, useDepositFlow, usePay, usePayContext, usePay
19
21
  export type { UseBalanceResult, UseCountdownResult, UsePayContextResult, UsePayMessagesResult, UsePaymentMethodsResult, UsePayResult, } from "./hooks/root.js";
20
22
  export { useAttachReceipt, useCreateDeposit, useCryptoDeposit, useDeposit, useDepositQuote, useOnramp, } from "./hooks/deposit.js";
21
23
  export type { UseAttachReceiptResult, UseCreateDepositResult, UseCryptoDepositResult, UseDepositQuoteResult, UseDepositResult, UseOnrampResult, } from "./hooks/deposit.js";
24
+ export { usePromoCode } from "./hooks/promo.js";
25
+ export type { UsePromoCodeResult } from "./hooks/promo.js";
22
26
  export { useCreateWithdrawal, useWithdrawQuote, useWithdrawal } from "./hooks/withdraw.js";
23
27
  export type { UseCreateWithdrawalResult, UseWithdrawQuoteResult, UseWithdrawalResult, } from "./hooks/withdraw.js";
24
28
  export type { Appearance, AppearanceSkin, AppearanceTheme, TokenName } from "../core/appearance.js";
25
29
  export type { PayErrorCode } from "../core/errors.js";
26
30
  export { PayError } from "../core/errors.js";
27
31
  export type { PayEvent, PayEventType } from "../core/events.js";
32
+ export type { PromoPending, PromoView } from "../core/flows/promo.js";
33
+ export type { WithdrawBonusGate } from "../core/rules/bonus.js";
34
+ export type { ActiveBonus, AttachedBonus, BonusPreview, BonusTerms, BonusType, PayBonuses, WithdrawalBonus, } from "../core/types.js";
28
35
  export type { MessageKey, PayLocale } from "../core/i18n/index.js";
@@ -5,10 +5,12 @@ export { CurrencyPicker, MethodPicker, NetworkPicker } from "./components/picker
5
5
  export { AddressInput, AmountInput, PhoneInput, TwoFactorInput } from "./components/inputs.js";
6
6
  export { Countdown, CryptoAddress, MethodNotice, Onramp, ReceiptUpload, RedirectButton, Requisites, RequisitesFrame, RestartButton, } from "./components/deposit.js";
7
7
  export { Quote, SlippageWarning, Status } from "./components/status.js";
8
+ export { PromoCode, WithdrawBonus } from "./components/bonus.js";
8
9
  export { Qr } from "./components/Qr.js";
9
10
  export { DepositForm } from "./presets/DepositForm.js";
10
11
  export { WithdrawForm } from "./presets/WithdrawForm.js";
11
12
  export { useBalance, useCountdown, useDepositFlow, usePay, usePayContext, usePayError, usePayEvents, usePayMessages, usePaymentMethods, useWithdrawFlow, } from "./hooks/root.js";
12
13
  export { useAttachReceipt, useCreateDeposit, useCryptoDeposit, useDeposit, useDepositQuote, useOnramp, } from "./hooks/deposit.js";
14
+ export { usePromoCode } from "./hooks/promo.js";
13
15
  export { useCreateWithdrawal, useWithdrawQuote, useWithdrawal } from "./hooks/withdraw.js";
14
16
  export { PayError } from "../core/errors.js";
@@ -27,6 +27,8 @@ export interface DepositFormComponents {
27
27
  display?: OnrampDisplay;
28
28
  }>;
29
29
  Status: ComponentType;
30
+ /** Under the methods and under the deposit address; renders nothing without promo codes. */
31
+ PromoCode: ComponentType;
30
32
  }
31
33
  export type DepositFormProps = Omit<HTMLAttributes<HTMLDivElement>, "className" | "style" | "children"> & PartStyleProps & {
32
34
  components?: Partial<DepositFormComponents>;
@@ -8,6 +8,7 @@ import { useStepFocus } from "./focus.js";
8
8
  import { partProps } from "../part.js";
9
9
  import { BackButton, Balance, Close, ErrorMessage, Loader, SubmitButton, } from "../components/basic.js";
10
10
  import { Countdown, CryptoAddress, MethodNotice, Onramp, ReceiptUpload, RedirectButton, Requisites, RestartButton, } from "../components/deposit.js";
11
+ import { PromoCode } from "../components/bonus.js";
11
12
  import { AmountInput, PhoneInput } from "../components/inputs.js";
12
13
  import { CurrencyPicker, MethodPicker, NetworkPicker } from "../components/pickers.js";
13
14
  import { Quote, Status } from "../components/status.js";
@@ -33,6 +34,7 @@ const DEFAULTS = {
33
34
  RestartButton,
34
35
  Onramp,
35
36
  Status,
37
+ PromoCode,
36
38
  };
37
39
  const screenOf = (state, cryptoOpen) => {
38
40
  const step = state?.step ?? "loading";
@@ -81,10 +83,10 @@ export const DepositForm = forwardRef(function DepositForm({ components, onrampD
81
83
  body = (_jsx(ui.PayBody, { unstyled: isUnstyled, children: _jsx(c.ErrorMessage, {}) }));
82
84
  break;
83
85
  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, { display: onrampDisplay }), state?.onrampUrl ? (_jsx("p", { className: isUnstyled ? undefined : "bp-onramp-note", "data-binodex-pay": "onramp-note", children: root.t("onramp.disclosure") })) : null] })) : (_jsx(c.ErrorMessage, {}))] }));
86
+ 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, { display: onrampDisplay }), state?.onrampUrl ? (_jsx("p", { className: isUnstyled ? undefined : "bp-onramp-note", "data-binodex-pay": "onramp-note", children: root.t("onramp.disclosure") })) : null] })) : (_jsx(c.ErrorMessage, {})), _jsx(c.PromoCode, {})] }));
85
87
  break;
86
88
  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, {})] }));
89
+ 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, {}), _jsx(c.PromoCode, {})] }));
88
90
  break;
89
91
  case "credited":
90
92
  body = (_jsxs(ui.PayBody, { variant: "address", unstyled: isUnstyled, children: [_jsx(ui.Divider, { unstyled: isUnstyled }), _jsx(c.Status, {})] }));
@@ -16,6 +16,8 @@ export interface WithdrawFormComponents {
16
16
  SubmitButton: ComponentType;
17
17
  Status: ComponentType;
18
18
  RestartButton: ComponentType;
19
+ /** The live promo bonus: a lock, a wait for open positions, or the burn consent. */
20
+ WithdrawBonus: ComponentType;
19
21
  }
20
22
  export type WithdrawFormProps = Omit<HTMLAttributes<HTMLDivElement>, "className" | "style" | "children"> & PartStyleProps & {
21
23
  components?: Partial<WithdrawFormComponents>;
@@ -7,6 +7,7 @@ import { useWithdrawFlowStore } from "../context.js";
7
7
  import { useStepFocus } from "./focus.js";
8
8
  import { partProps } from "../part.js";
9
9
  import { Balance, Close, ErrorMessage, Loader, SubmitButton } from "../components/basic.js";
10
+ import { WithdrawBonus } from "../components/bonus.js";
10
11
  import { RestartButton } from "../components/deposit.js";
11
12
  import { AddressInput, AmountInput, TwoFactorInput } from "../components/inputs.js";
12
13
  import { CurrencyPicker, NetworkPicker } from "../components/pickers.js";
@@ -26,6 +27,7 @@ const DEFAULTS = {
26
27
  SubmitButton,
27
28
  Status,
28
29
  RestartButton,
30
+ WithdrawBonus,
29
31
  };
30
32
  export const WithdrawForm = forwardRef(function WithdrawForm({ components, className, style, unstyled, ...rest }, ref) {
31
33
  const { root, state } = useWithdrawFlowStore("<Pay.WithdrawForm>");
@@ -40,5 +42,5 @@ export const WithdrawForm = forwardRef(function WithdrawForm({ components, class
40
42
  const isUnstyled = unstyled ?? root.unstyled;
41
43
  const logoUrl = safeImageUrl(state?.context?.branding.logoUrl);
42
44
  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, {})] }) })) }));
45
+ 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.WithdrawBonus, {})] })), _jsx(c.ErrorMessage, {}), step !== "loading" && step !== "error" && _jsx(c.SubmitButton, {})] }) })) }));
44
46
  });