@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.
- package/README.md +19 -3
- package/dist/core/client.d.ts +9 -1
- package/dist/core/client.js +16 -1
- package/dist/core/errors.d.ts +7 -1
- package/dist/core/errors.js +6 -0
- package/dist/core/flows/promo.d.ts +49 -0
- package/dist/core/flows/promo.js +155 -0
- package/dist/core/flows/withdraw.d.ts +7 -1
- package/dist/core/flows/withdraw.js +56 -3
- package/dist/core/i18n/ar.js +55 -0
- package/dist/core/i18n/base.js +12 -0
- package/dist/core/i18n/cs.js +55 -0
- package/dist/core/i18n/de.js +55 -0
- package/dist/core/i18n/en.d.ts +55 -0
- package/dist/core/i18n/en.js +55 -0
- package/dist/core/i18n/es.js +55 -0
- package/dist/core/i18n/fr.js +55 -0
- package/dist/core/i18n/hi.js +55 -0
- package/dist/core/i18n/it.js +55 -0
- package/dist/core/i18n/ru.js +55 -0
- package/dist/core/i18n/tr.js +55 -0
- package/dist/core/i18n/ua.js +55 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +2 -0
- package/dist/core/rules/bonus.d.ts +27 -0
- package/dist/core/rules/bonus.js +60 -0
- package/dist/core/types.d.ts +69 -0
- package/dist/core/wire.d.ts +18 -1
- package/dist/core/wire.js +79 -0
- package/dist/elements/Root.js +14 -7
- package/dist/elements/components/basic.js +4 -1
- package/dist/elements/components/bonus.d.ts +19 -0
- package/dist/elements/components/bonus.js +177 -0
- package/dist/elements/context.d.ts +3 -0
- package/dist/elements/hooks/promo.d.ts +37 -0
- package/dist/elements/hooks/promo.js +66 -0
- package/dist/elements/index.d.ts +7 -0
- package/dist/elements/index.js +2 -0
- package/dist/elements/presets/DepositForm.d.ts +2 -0
- package/dist/elements/presets/DepositForm.js +4 -2
- package/dist/elements/presets/WithdrawForm.d.ts +2 -0
- package/dist/elements/presets/WithdrawForm.js +3 -1
- package/dist/elements.css +394 -0
- package/package.json +1 -1
package/dist/core/i18n/ua.js
CHANGED
|
@@ -311,4 +311,59 @@ export const ua = {
|
|
|
311
311
|
"fiat.in.statusFailed": "Платіж не пройшов",
|
|
312
312
|
"fiat.in.statusExpired": "Час оплати минув",
|
|
313
313
|
"fiat.in.scanQr": "Відскануйте код у застосунку банку, щоб оплатити.",
|
|
314
|
+
"promo.toggle": "Маєте промокод?",
|
|
315
|
+
"promo.label": "Промокод",
|
|
316
|
+
"promo.placeholder": "Введіть код",
|
|
317
|
+
"promo.apply": "Застосувати",
|
|
318
|
+
"promo.checking": "Перевіряємо…",
|
|
319
|
+
"promo.hide": "Сховати промокод",
|
|
320
|
+
"promo.applied": "Застосовано",
|
|
321
|
+
"promo.remove": "Прибрати код",
|
|
322
|
+
"promo.headlinePercent": "+{pct}% до депозиту",
|
|
323
|
+
"promo.headlinePercentCap": "+{pct}% до депозиту, до {max}",
|
|
324
|
+
"promo.headlineFixed": "+{amount} до депозиту",
|
|
325
|
+
"promo.minDeposit": "Мінімальний депозит",
|
|
326
|
+
"promo.maxDeposit": "Бонус рахується з депозиту до",
|
|
327
|
+
"promo.expiresIn": "Код діє ще",
|
|
328
|
+
"promo.wager": "Наторгуйте оборот у {multiplier}× від бонусу за {duration} після зарахування.",
|
|
329
|
+
"promo.wagerNoDeadline": "Наторгуйте оборот у {multiplier}× від бонусу після зарахування.",
|
|
330
|
+
"promo.unlockAnytime": "Виводити можна будь-коли.",
|
|
331
|
+
"promo.unlockPartial": "Виведення відкриється після {pct}% цього обороту.",
|
|
332
|
+
"promo.unlockFull": "Виведення відкриється після всього обороту.",
|
|
333
|
+
"promo.burn": "Виведення спалює залишок бонусу на цей момент.",
|
|
334
|
+
"promo.firstDepositOnly": "Лише для першого депозиту.",
|
|
335
|
+
"promo.activeTitle": "Бонус {code}",
|
|
336
|
+
"promo.activeProgress": "Оборот {wagered} з {goal}",
|
|
337
|
+
"promo.activeLeft": "залишилось {duration}",
|
|
338
|
+
"promo.activeBurnPending": "Бонус закриється, коли закриються відкриті позиції.",
|
|
339
|
+
"promo.reason.BONUS_CODE_NOT_FOUND": "Такого коду немає.",
|
|
340
|
+
"promo.reason.BONUS_INACTIVE": "Цей код не активний.",
|
|
341
|
+
"promo.reason.BONUS_EXPIRED": "Термін дії коду минув.",
|
|
342
|
+
"promo.reason.USAGE_LIMIT_REACHED": "Ліміт використань коду вичерпано.",
|
|
343
|
+
"promo.reason.USER_LIMIT_REACHED": "Ви вже використали цей код.",
|
|
344
|
+
"promo.reason.FIRST_DEPOSIT_ONLY": "Код діє лише на перший депозит.",
|
|
345
|
+
"promo.reason.MIN_DEPOSIT_NOT_MET": "Депозит менший за мінімум для цього коду.",
|
|
346
|
+
"promo.reason.ACTIVE_BONUS_EXISTS": "У вас уже є активний бонус.",
|
|
347
|
+
"promo.reason.SYSTEM_DISABLED": "Промокоди зараз недоступні.",
|
|
348
|
+
"promo.reason.UNKNOWN": "Цей код не можна застосувати.",
|
|
349
|
+
"duration.days": "{count} д",
|
|
350
|
+
"duration.hours": "{count} год",
|
|
351
|
+
"duration.minutes": "{count} хв",
|
|
352
|
+
"withdrawBonus.lockedTitle": "Виведення закрите бонусом",
|
|
353
|
+
"withdrawBonus.lockedPartial": "Виведення відкриється, коли ви наторгуєте {unlock}% обороту за бонусом.",
|
|
354
|
+
"withdrawBonus.lockedFull": "Виведення відкриється, коли ви наторгуєте весь оборот за бонусом.",
|
|
355
|
+
"withdrawBonus.progress": "Наторговано {progress}% з потрібних {unlock}%",
|
|
356
|
+
"withdrawBonus.pendingTitle": "Бонус закривається",
|
|
357
|
+
"withdrawBonus.pendingBody": "Закрийте відкриті позиції. Бонус згорить після їх закриття, і виведення стане доступним.",
|
|
358
|
+
"withdrawBonus.burnTitle": "Виведення спалить бонус",
|
|
359
|
+
"withdrawBonus.burnBody": "Залишок бонусу на балансі, до {amount}, згорить разом із цим виведенням.",
|
|
360
|
+
"withdrawBonus.burnBodyGeneric": "Залишок бонусу на балансі згорить разом із цим виведенням.",
|
|
361
|
+
"withdrawBonus.consent": "Розумію, що залишок бонусу згорить",
|
|
362
|
+
"error.PROMO_CODE_REJECTED": "Цей промокод не можна застосувати.",
|
|
363
|
+
"error.BONUS_WITHDRAWAL_LOCKED": "Виведення закрите, доки не наторговано оборот за бонусом.",
|
|
364
|
+
"error.BONUS_WITHDRAWAL_LOCKED_PCT": "Виведення відкриється на {unlock}% обороту за бонусом. Зараз {progress}%.",
|
|
365
|
+
"error.BONUS_BURN_CONFIRM_REQUIRED": "Підтвердьте, що виведення спалить залишок бонусу.",
|
|
366
|
+
"error.BONUS_BURN_PENDING": "Бонус ще закривається. Спершу закрийте відкриті позиції.",
|
|
367
|
+
"error.BONUS_CHANGED": "Бонус змінився. Перевірте умови й спробуйте знову.",
|
|
368
|
+
"error.OPEN_POSITIONS": "Закрийте відкриті позиції перед виведенням.",
|
|
314
369
|
};
|
package/dist/core/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { createDepositFlow, fiatAmountHint } from "./flows/deposit.js";
|
|
|
4
4
|
export type { DepositFlow, DepositFlowActions, DepositFlowOptions, DepositFlowState, DepositOutcome, DepositStep, FlowStore, } from "./flows/deposit.js";
|
|
5
5
|
export { createWithdrawFlow, isTerminalWithdrawal, withdrawAmountHint, withdrawableOf, } from "./flows/withdraw.js";
|
|
6
6
|
export type { WithdrawFlow, WithdrawFlowActions, WithdrawFlowOptions, WithdrawFlowState, WithdrawStep, } from "./flows/withdraw.js";
|
|
7
|
+
export { createPromoFlow, promoViewOf } from "./flows/promo.js";
|
|
8
|
+
export type { PromoFlow, PromoFlowActions, PromoFlowState, PromoPending, PromoStatus, PromoView, } from "./flows/promo.js";
|
|
7
9
|
export { PROBE_TIMEOUT_MS, resolveHosts, selectApiBase, validateApiBase, validateWidgetOrigin, } from "./api-base.js";
|
|
8
10
|
export type { ResolvedHosts, Timers } from "./api-base.js";
|
|
9
11
|
export { RENEW_LEAD_MS } from "./auth.js";
|
|
@@ -24,6 +26,8 @@ export type { NativeBounds, NativeRange } from "./rules/limits.js";
|
|
|
24
26
|
export { addressFamily, isValidWithdrawAddress } from "./rules/address.js";
|
|
25
27
|
export type { AddressFamily } from "./rules/address.js";
|
|
26
28
|
export { acceptSlippagePct } from "./rules/slippage.js";
|
|
29
|
+
export { BONUS_REJECT_REASONS, PROMO_CODE_MAX_LENGTH, formatDuration, isBonusRejectReason, maxCountedDepositUsd, normalizePromoCode, promoReasonKey, wholePercent, withdrawBonusGate, withdrawalUnlockRule, } from "./rules/bonus.js";
|
|
30
|
+
export type { BonusRejectReason, WithdrawBonusGate, WithdrawalUnlockRule } from "./rules/bonus.js";
|
|
27
31
|
export { getRuReceiptRule, getRuReceiptRuleForMethod, requiresRuReceipt } from "./rules/receipt.js";
|
|
28
32
|
export type { ReceiptRule } from "./rules/receipt.js";
|
|
29
33
|
export { COUNTDOWN_MAX_MS, FINAL_STATES, SUCCESS_STATES, formatExpires, payToLabelKey, showsCountdown, statusTone, } from "./rules/paying.js";
|
package/dist/core/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { createPayClient, createIdempotencyKey, MAX_RECEIPT_BYTES } from "./client.js";
|
|
2
2
|
export { createDepositFlow, fiatAmountHint } from "./flows/deposit.js";
|
|
3
3
|
export { createWithdrawFlow, isTerminalWithdrawal, withdrawAmountHint, withdrawableOf, } from "./flows/withdraw.js";
|
|
4
|
+
export { createPromoFlow, promoViewOf } from "./flows/promo.js";
|
|
4
5
|
export { PROBE_TIMEOUT_MS, resolveHosts, selectApiBase, validateApiBase, validateWidgetOrigin, } from "./api-base.js";
|
|
5
6
|
export { RENEW_LEAD_MS } from "./auth.js";
|
|
6
7
|
export { createServerClock, serverClockOffsetMs } from "./clock.js";
|
|
@@ -12,6 +13,7 @@ export { amountForCopy, getPayView, groupCardNumber, isTerminalDepositStatus, re
|
|
|
12
13
|
export { formatMinLimit, formatNativeRange } from "./rules/limits.js";
|
|
13
14
|
export { addressFamily, isValidWithdrawAddress } from "./rules/address.js";
|
|
14
15
|
export { acceptSlippagePct } from "./rules/slippage.js";
|
|
16
|
+
export { BONUS_REJECT_REASONS, PROMO_CODE_MAX_LENGTH, formatDuration, isBonusRejectReason, maxCountedDepositUsd, normalizePromoCode, promoReasonKey, wholePercent, withdrawBonusGate, withdrawalUnlockRule, } from "./rules/bonus.js";
|
|
15
17
|
export { getRuReceiptRule, getRuReceiptRuleForMethod, requiresRuReceipt } from "./rules/receipt.js";
|
|
16
18
|
export { COUNTDOWN_MAX_MS, FINAL_STATES, SUCCESS_STATES, formatExpires, payToLabelKey, showsCountdown, statusTone, } from "./rules/paying.js";
|
|
17
19
|
export { TOKEN_NAMES, readableOn, resolveSkin, resolveTheme, safeBackground, safeColor, safeImageUrl, themeVariables, } from "./appearance.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MessageKey, Translate } from "../i18n/base.js";
|
|
2
|
+
import type { BonusTerms, WithdrawalBonus } from "../types.js";
|
|
3
|
+
export declare const PROMO_CODE_MAX_LENGTH = 64;
|
|
4
|
+
/** Why the server refuses a promo code (`BonusPreview.reason`, `PROMO_CODE_REJECTED` `details.reason`). */
|
|
5
|
+
export declare const BONUS_REJECT_REASONS: readonly ["BONUS_CODE_NOT_FOUND", "BONUS_INACTIVE", "BONUS_EXPIRED", "USAGE_LIMIT_REACHED", "USER_LIMIT_REACHED", "FIRST_DEPOSIT_ONLY", "MIN_DEPOSIT_NOT_MET", "ACTIVE_BONUS_EXISTS", "SYSTEM_DISABLED"];
|
|
6
|
+
export type BonusRejectReason = (typeof BONUS_REJECT_REASONS)[number];
|
|
7
|
+
export declare const isBonusRejectReason: (value: unknown) => value is BonusRejectReason;
|
|
8
|
+
/** The message for a refused code. A reason this SDK does not know reads as a plain refusal. */
|
|
9
|
+
export declare const promoReasonKey: (reason: string | null | undefined) => MessageKey;
|
|
10
|
+
/** Codes are typed in capitals and without spaces, as the server stores them. */
|
|
11
|
+
export declare const normalizePromoCode: (raw: string) => string;
|
|
12
|
+
/** The deposit past which a capped `PERCENT` bonus stops growing: `maxBonusUsd / (value / 100)`. */
|
|
13
|
+
export declare const maxCountedDepositUsd: (terms: Pick<BonusTerms, "type" | "value" | "maxBonusUsd">) => string | null;
|
|
14
|
+
/** A whole percent for progress: floored, so it never reads 100 before the server says done. */
|
|
15
|
+
export declare const wholePercent: (value: number) => number;
|
|
16
|
+
/** When a withdrawal opens: at once, after the code's share of the trading volume, or after all of it. */
|
|
17
|
+
export type WithdrawalUnlockRule = "anytime" | "partial" | "full";
|
|
18
|
+
export declare const withdrawalUnlockRule: (pct: number) => WithdrawalUnlockRule;
|
|
19
|
+
/**
|
|
20
|
+
* What a live bonus lets a withdrawal do: `burn-pending` waits for open positions to close,
|
|
21
|
+
* `locked` waits for the trading volume, `consent` is open once the user agrees that the
|
|
22
|
+
* withdrawal burns the rest of the bonus, `ready` has that consent.
|
|
23
|
+
*/
|
|
24
|
+
export type WithdrawBonusGate = "none" | "burn-pending" | "locked" | "consent" | "ready";
|
|
25
|
+
export declare const withdrawBonusGate: (bonus: WithdrawalBonus | null | undefined, consent: boolean) => WithdrawBonusGate;
|
|
26
|
+
/** `3 d 4 h`, `5 h 12 min`, `12 min`. */
|
|
27
|
+
export declare const formatDuration: (t: Translate, ms: number) => string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const PROMO_CODE_MAX_LENGTH = 64;
|
|
2
|
+
/** Why the server refuses a promo code (`BonusPreview.reason`, `PROMO_CODE_REJECTED` `details.reason`). */
|
|
3
|
+
export const BONUS_REJECT_REASONS = [
|
|
4
|
+
"BONUS_CODE_NOT_FOUND",
|
|
5
|
+
"BONUS_INACTIVE",
|
|
6
|
+
"BONUS_EXPIRED",
|
|
7
|
+
"USAGE_LIMIT_REACHED",
|
|
8
|
+
"USER_LIMIT_REACHED",
|
|
9
|
+
"FIRST_DEPOSIT_ONLY",
|
|
10
|
+
"MIN_DEPOSIT_NOT_MET",
|
|
11
|
+
"ACTIVE_BONUS_EXISTS",
|
|
12
|
+
"SYSTEM_DISABLED",
|
|
13
|
+
];
|
|
14
|
+
const REASONS = new Set(BONUS_REJECT_REASONS);
|
|
15
|
+
export const isBonusRejectReason = (value) => typeof value === "string" && REASONS.has(value);
|
|
16
|
+
/** The message for a refused code. A reason this SDK does not know reads as a plain refusal. */
|
|
17
|
+
export const promoReasonKey = (reason) => isBonusRejectReason(reason) ? `promo.reason.${reason}` : "promo.reason.UNKNOWN";
|
|
18
|
+
/** Codes are typed in capitals and without spaces, as the server stores them. */
|
|
19
|
+
export const normalizePromoCode = (raw) => raw.toUpperCase().replace(/\s+/g, "").slice(0, PROMO_CODE_MAX_LENGTH);
|
|
20
|
+
const positive = (value) => {
|
|
21
|
+
const num = value === null || value === undefined ? Number.NaN : Number(value);
|
|
22
|
+
return Number.isFinite(num) && num > 0 ? num : null;
|
|
23
|
+
};
|
|
24
|
+
/** The deposit past which a capped `PERCENT` bonus stops growing: `maxBonusUsd / (value / 100)`. */
|
|
25
|
+
export const maxCountedDepositUsd = (terms) => {
|
|
26
|
+
if (terms.type !== "PERCENT")
|
|
27
|
+
return null;
|
|
28
|
+
const pct = positive(terms.value);
|
|
29
|
+
const cap = positive(terms.maxBonusUsd);
|
|
30
|
+
return pct !== null && cap !== null ? ((cap * 100) / pct).toFixed(2) : null;
|
|
31
|
+
};
|
|
32
|
+
/** A whole percent for progress: floored, so it never reads 100 before the server says done. */
|
|
33
|
+
export const wholePercent = (value) => {
|
|
34
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
35
|
+
return 0;
|
|
36
|
+
return value >= 100 ? 100 : Math.floor(value);
|
|
37
|
+
};
|
|
38
|
+
export const withdrawalUnlockRule = (pct) => pct <= 0 ? "anytime" : pct >= 100 ? "full" : "partial";
|
|
39
|
+
export const withdrawBonusGate = (bonus, consent) => {
|
|
40
|
+
if (!bonus)
|
|
41
|
+
return "none";
|
|
42
|
+
if (bonus.status === "BURN_PENDING")
|
|
43
|
+
return "burn-pending";
|
|
44
|
+
if (!bonus.unlocked)
|
|
45
|
+
return "locked";
|
|
46
|
+
return consent ? "ready" : "consent";
|
|
47
|
+
};
|
|
48
|
+
/** `3 d 4 h`, `5 h 12 min`, `12 min`. */
|
|
49
|
+
export const formatDuration = (t, ms) => {
|
|
50
|
+
const total = Math.max(1, Math.ceil(ms / 60000));
|
|
51
|
+
const days = Math.floor(total / 1440);
|
|
52
|
+
const hours = Math.floor((total % 1440) / 60);
|
|
53
|
+
const minutes = total % 60;
|
|
54
|
+
const parts = days > 0
|
|
55
|
+
? [t("duration.days", { count: days }), hours > 0 ? t("duration.hours", { count: hours }) : null]
|
|
56
|
+
: hours > 0
|
|
57
|
+
? [t("duration.hours", { count: hours }), minutes > 0 ? t("duration.minutes", { count: minutes }) : null]
|
|
58
|
+
: [t("duration.minutes", { count: minutes })];
|
|
59
|
+
return parts.filter((part) => part !== null).join(" ");
|
|
60
|
+
};
|
package/dist/core/types.d.ts
CHANGED
|
@@ -16,6 +16,20 @@ export interface Branding {
|
|
|
16
16
|
logoUrl: string | null;
|
|
17
17
|
}
|
|
18
18
|
export type RequisitesDelivery = "raw" | "frame";
|
|
19
|
+
/** A bonus credited and being traded through: `BURN_PENDING` ended while positions were open and burns once they close. */
|
|
20
|
+
export type LiveBonusStatus = "ACTIVE" | "BURN_PENDING";
|
|
21
|
+
/** The promo bonus a withdrawal meets (`GET /pay/context` in withdraw mode). */
|
|
22
|
+
export interface WithdrawalBonus {
|
|
23
|
+
status: LiveBonusStatus;
|
|
24
|
+
/** What a withdrawal burns: what is left of the bonus. */
|
|
25
|
+
bonusLeftUsd: string | null;
|
|
26
|
+
/** How much of the bonus trading volume is done, 0-100. */
|
|
27
|
+
progressPct: number;
|
|
28
|
+
/** The share of the trading volume (0-100) that opens a withdrawal. */
|
|
29
|
+
unlockPct: number;
|
|
30
|
+
/** A withdrawal is open now; it burns what is left of the bonus. */
|
|
31
|
+
unlocked: boolean;
|
|
32
|
+
}
|
|
19
33
|
export interface PayContext {
|
|
20
34
|
mode: PayMode;
|
|
21
35
|
serverTime: number;
|
|
@@ -24,6 +38,8 @@ export interface PayContext {
|
|
|
24
38
|
withdrawal: {
|
|
25
39
|
twoFactorRequired: boolean;
|
|
26
40
|
inFlightId: string | null;
|
|
41
|
+
/** The live promo bonus, or null. An older backend never sends one. */
|
|
42
|
+
bonus: WithdrawalBonus | null;
|
|
27
43
|
} | null;
|
|
28
44
|
requisitesDelivery: RequisitesDelivery;
|
|
29
45
|
branding: Branding;
|
|
@@ -221,6 +237,59 @@ export interface QuoteWithdrawalInput {
|
|
|
221
237
|
export interface CreateWithdrawalInput extends QuoteWithdrawalInput {
|
|
222
238
|
quote?: WithdrawalQuote;
|
|
223
239
|
twoFactorCode?: string;
|
|
240
|
+
/** The user agreed that the withdrawal burns what is left of the promo bonus. */
|
|
241
|
+
confirmBurnBonus?: boolean;
|
|
242
|
+
}
|
|
243
|
+
export type BonusType = "FIXED" | "PERCENT";
|
|
244
|
+
/** What a promo code gives and asks. */
|
|
245
|
+
export interface BonusTerms {
|
|
246
|
+
type: BonusType;
|
|
247
|
+
/** USD for `FIXED`, percent of the deposit for `PERCENT`. */
|
|
248
|
+
value: string | null;
|
|
249
|
+
minDepositUsd: string | null;
|
|
250
|
+
/** The cap of a `PERCENT` bonus. */
|
|
251
|
+
maxBonusUsd: string | null;
|
|
252
|
+
/** Trading volume asked: this many times the bonus. */
|
|
253
|
+
wagerMultiplier: string | null;
|
|
254
|
+
/** Hours to reach the trading volume once the bonus is credited; null: until the code expires. */
|
|
255
|
+
durationHours: number | null;
|
|
256
|
+
/** ISO time until which the code takes deposits. */
|
|
257
|
+
codeExpiresAt: string | null;
|
|
258
|
+
/** The share of the trading volume (0, 10 or 100) that opens a withdrawal. */
|
|
259
|
+
withdrawalUnlockPct: number;
|
|
260
|
+
}
|
|
261
|
+
export interface AttachedBonus extends BonusTerms {
|
|
262
|
+
code: string;
|
|
263
|
+
title: string;
|
|
264
|
+
}
|
|
265
|
+
export interface ActiveBonus extends AttachedBonus {
|
|
266
|
+
status: LiveBonusStatus;
|
|
267
|
+
bonusUsd: string | null;
|
|
268
|
+
bonusLeftUsd: string | null;
|
|
269
|
+
wageredUsd: string | null;
|
|
270
|
+
goalUsd: string | null;
|
|
271
|
+
/** 0-100. */
|
|
272
|
+
progressPct: number;
|
|
273
|
+
expiresAt: string | null;
|
|
274
|
+
activatedAt: string | null;
|
|
275
|
+
}
|
|
276
|
+
export interface PayBonuses {
|
|
277
|
+
/** Promo codes are on for this user. */
|
|
278
|
+
enabled: boolean;
|
|
279
|
+
/** The code waiting for the next deposit. */
|
|
280
|
+
attached: AttachedBonus | null;
|
|
281
|
+
/** The bonus credited and being traded through. */
|
|
282
|
+
active: ActiveBonus | null;
|
|
283
|
+
}
|
|
284
|
+
export interface BonusPreview {
|
|
285
|
+
valid: boolean;
|
|
286
|
+
code: string;
|
|
287
|
+
/** Why the code does not apply (see `BONUS_REJECT_REASONS`); null when it does. */
|
|
288
|
+
reason: string | null;
|
|
289
|
+
estimatedBonusUsd: string | null;
|
|
290
|
+
bonus: (AttachedBonus & {
|
|
291
|
+
firstDepositOnly: boolean;
|
|
292
|
+
}) | null;
|
|
224
293
|
}
|
|
225
294
|
export interface FrameTicket {
|
|
226
295
|
ticket: string;
|
package/dist/core/wire.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AppearanceSkin } from "./appearance.js";
|
|
2
2
|
import { PayError } from "./errors.js";
|
|
3
|
-
import type { CreateDepositInput, CreateWithdrawalInput, CryptoDeposit, Deposit, DepositQuote, FiatDeposit, FrameTicket, PayActivity, PayContext, PayMethods, PayMode, PayRegion, PayTheme, QuoteWithdrawalInput, Withdrawal, WithdrawalQuoteResult } from "./types.js";
|
|
3
|
+
import type { BonusPreview, CreateDepositInput, CreateWithdrawalInput, CryptoDeposit, Deposit, DepositQuote, FiatDeposit, FrameTicket, PayActivity, PayBonuses, PayContext, PayMethods, PayMode, PayRegion, PayTheme, QuoteWithdrawalInput, Withdrawal, WithdrawalQuoteResult } from "./types.js";
|
|
4
4
|
export declare const PATHS: {
|
|
5
5
|
readonly redeem: "/broker/widget-sessions/redeem";
|
|
6
6
|
readonly ping: "/broker/pay/ping";
|
|
@@ -17,6 +17,9 @@ export declare const PATHS: {
|
|
|
17
17
|
readonly withdrawals: "/broker/pay/withdrawals";
|
|
18
18
|
readonly withdrawal: (id: string) => string;
|
|
19
19
|
readonly activity: "/broker/pay/activity";
|
|
20
|
+
readonly bonuses: "/broker/pay/bonuses";
|
|
21
|
+
readonly bonusPreview: "/broker/pay/bonuses/preview";
|
|
22
|
+
readonly bonusAttach: "/broker/pay/bonuses/attach";
|
|
20
23
|
};
|
|
21
24
|
export declare const IDEMPOTENCY_HEADER = "Idempotency-Key";
|
|
22
25
|
export declare const REQUISITES_FRAME_PATH = "/embed/pay/requisites";
|
|
@@ -66,6 +69,9 @@ export interface WireErrorEnvelope {
|
|
|
66
69
|
currency?: string;
|
|
67
70
|
retry_after_seconds?: number;
|
|
68
71
|
withdrawal_id?: string;
|
|
72
|
+
reason?: string;
|
|
73
|
+
unlock_pct?: number;
|
|
74
|
+
progress_pct?: number;
|
|
69
75
|
};
|
|
70
76
|
};
|
|
71
77
|
}
|
|
@@ -91,6 +97,11 @@ export interface WireCreateWithdrawalBody extends WireQuoteWithdrawalBody {
|
|
|
91
97
|
slippage_pct: string | null;
|
|
92
98
|
};
|
|
93
99
|
two_factor_code?: string;
|
|
100
|
+
confirm_burn_bonus?: boolean;
|
|
101
|
+
}
|
|
102
|
+
export interface WireBonusPreviewBody {
|
|
103
|
+
code: string;
|
|
104
|
+
amount_usd?: string;
|
|
94
105
|
}
|
|
95
106
|
export declare const readSessionExtras: (data: WireSessionResponse) => {
|
|
96
107
|
apiBases: string[];
|
|
@@ -150,6 +161,12 @@ export declare const readWithdrawalQuote: (value: unknown) => WithdrawalQuoteRes
|
|
|
150
161
|
export declare const readWithdrawal: (value: unknown) => Withdrawal;
|
|
151
162
|
export declare const toActivityQuery: (since: number) => Record<string, string>;
|
|
152
163
|
export declare const readActivity: (value: unknown) => PayActivity;
|
|
164
|
+
export declare const readBonuses: (value: unknown) => PayBonuses;
|
|
165
|
+
export declare const toBonusPreviewBody: (code: string, amountUsd?: string | number) => WireBonusPreviewBody;
|
|
166
|
+
export declare const toBonusAttachBody: (code: string) => {
|
|
167
|
+
code: string;
|
|
168
|
+
};
|
|
169
|
+
export declare const readBonusPreview: (value: unknown) => BonusPreview;
|
|
153
170
|
export declare const REQUISITES_FRAME_MESSAGES: {
|
|
154
171
|
readonly ready: "binodex-embed:ready";
|
|
155
172
|
readonly resize: "binodex-embed:resize";
|
package/dist/core/wire.js
CHANGED
|
@@ -15,6 +15,9 @@ export const PATHS = {
|
|
|
15
15
|
withdrawals: "/broker/pay/withdrawals",
|
|
16
16
|
withdrawal: (id) => `/broker/pay/withdrawals/${encodeURIComponent(id)}`,
|
|
17
17
|
activity: "/broker/pay/activity",
|
|
18
|
+
bonuses: "/broker/pay/bonuses",
|
|
19
|
+
bonusPreview: "/broker/pay/bonuses/preview",
|
|
20
|
+
bonusAttach: "/broker/pay/bonuses/attach",
|
|
18
21
|
};
|
|
19
22
|
export const IDEMPOTENCY_HEADER = "Idempotency-Key";
|
|
20
23
|
export const REQUISITES_FRAME_PATH = "/embed/pay/requisites";
|
|
@@ -90,6 +93,9 @@ const WITHDRAWAL_STATUSES = [
|
|
|
90
93
|
];
|
|
91
94
|
const DISPLAY_STATUSES = ["pending", "success", "failed"];
|
|
92
95
|
const DEPOSIT_SOURCES = ["crypto", "card", "onramp"];
|
|
96
|
+
const BONUS_TYPES = ["FIXED", "PERCENT"];
|
|
97
|
+
const LIVE_BONUS_STATUSES = ["ACTIVE", "BURN_PENDING"];
|
|
98
|
+
const percentOf = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? Math.min(100, Math.max(0, value)) : fallback;
|
|
93
99
|
export const readSessionExtras = (data) => {
|
|
94
100
|
const apiBases = strList(data.api_bases);
|
|
95
101
|
if (apiBases.length === 0 && typeof data.api_base === "string") {
|
|
@@ -156,6 +162,8 @@ export const readError = (status, value) => {
|
|
|
156
162
|
? envelope.message.slice(0, 300)
|
|
157
163
|
: `HTTP ${status}`;
|
|
158
164
|
const retry = details.retry_after_seconds;
|
|
165
|
+
const unlockPct = details.unlock_pct;
|
|
166
|
+
const progressPct = details.progress_pct;
|
|
159
167
|
return new PayError(code, message, {
|
|
160
168
|
status,
|
|
161
169
|
details: {
|
|
@@ -169,6 +177,9 @@ export const readError = (status, value) => {
|
|
|
169
177
|
...(typeof details.withdrawal_id === "string"
|
|
170
178
|
? { withdrawalId: details.withdrawal_id }
|
|
171
179
|
: {}),
|
|
180
|
+
...(typeof details.reason === "string" ? { reason: details.reason.slice(0, 64) } : {}),
|
|
181
|
+
...(typeof unlockPct === "number" && Number.isFinite(unlockPct) ? { unlockPct } : {}),
|
|
182
|
+
...(typeof progressPct === "number" && Number.isFinite(progressPct) ? { progressPct } : {}),
|
|
172
183
|
},
|
|
173
184
|
});
|
|
174
185
|
};
|
|
@@ -182,6 +193,19 @@ const readBalance = (value) => {
|
|
|
182
193
|
currency: optStr(data, "currency") ?? "USD",
|
|
183
194
|
};
|
|
184
195
|
};
|
|
196
|
+
// Lenient on purpose: a bonus the SDK cannot read must not take the whole withdrawal form down.
|
|
197
|
+
const readWithdrawalBonus = (value) => {
|
|
198
|
+
if (!isObject(value))
|
|
199
|
+
return null;
|
|
200
|
+
const status = oneOf(value.status, LIVE_BONUS_STATUSES, "ACTIVE");
|
|
201
|
+
return {
|
|
202
|
+
status,
|
|
203
|
+
bonusLeftUsd: optStr(value, "bonus_left_usd"),
|
|
204
|
+
progressPct: percentOf(value.progress_pct, 0),
|
|
205
|
+
unlockPct: percentOf(value.unlock_pct, 100),
|
|
206
|
+
unlocked: status === "ACTIVE" && value.unlocked === true,
|
|
207
|
+
};
|
|
208
|
+
};
|
|
185
209
|
export const readContext = (value) => {
|
|
186
210
|
const data = asObject(value, "context");
|
|
187
211
|
const withdrawal = isObject(data.withdrawal) ? data.withdrawal : null;
|
|
@@ -195,6 +219,7 @@ export const readContext = (value) => {
|
|
|
195
219
|
? {
|
|
196
220
|
twoFactorRequired: withdrawal.two_factor_required === true,
|
|
197
221
|
inFlightId: optStr(withdrawal, "in_flight_id"),
|
|
222
|
+
bonus: readWithdrawalBonus(withdrawal.bonus),
|
|
198
223
|
}
|
|
199
224
|
: null,
|
|
200
225
|
requisitesDelivery: data.requisites_delivery === "raw" ? "raw" : "frame",
|
|
@@ -486,6 +511,7 @@ export const toCreateWithdrawalBody = (input) => ({
|
|
|
486
511
|
}
|
|
487
512
|
: {}),
|
|
488
513
|
...(input.twoFactorCode ? { two_factor_code: input.twoFactorCode } : {}),
|
|
514
|
+
...(input.confirmBurnBonus === true ? { confirm_burn_bonus: true } : {}),
|
|
489
515
|
});
|
|
490
516
|
export const readWithdrawalQuote = (value) => {
|
|
491
517
|
const data = asObject(value, "withdrawal quote");
|
|
@@ -575,6 +601,59 @@ export const readActivity = (value) => {
|
|
|
575
601
|
}
|
|
576
602
|
return { serverTime: num(data, "server_time"), deposits, withdrawals };
|
|
577
603
|
};
|
|
604
|
+
const readBonusTerms = (data) => ({
|
|
605
|
+
type: strictOneOf(data.type, BONUS_TYPES, "type"),
|
|
606
|
+
value: optStr(data, "value"),
|
|
607
|
+
minDepositUsd: optStr(data, "min_deposit_usd"),
|
|
608
|
+
maxBonusUsd: optStr(data, "max_bonus_usd"),
|
|
609
|
+
wagerMultiplier: optStr(data, "wager_multiplier"),
|
|
610
|
+
durationHours: optNum(data, "duration_hours"),
|
|
611
|
+
codeExpiresAt: optStr(data, "code_expires_at"),
|
|
612
|
+
withdrawalUnlockPct: percentOf(data.withdrawal_unlock_pct, 100),
|
|
613
|
+
});
|
|
614
|
+
const readAttachedBonus = (data) => {
|
|
615
|
+
const code = str(data, "code");
|
|
616
|
+
return { code, title: optStr(data, "title") ?? code, ...readBonusTerms(data) };
|
|
617
|
+
};
|
|
618
|
+
const readActiveBonus = (data) => ({
|
|
619
|
+
...readAttachedBonus(data),
|
|
620
|
+
status: oneOf(data.status, LIVE_BONUS_STATUSES, "ACTIVE"),
|
|
621
|
+
bonusUsd: optStr(data, "bonus_usd"),
|
|
622
|
+
bonusLeftUsd: optStr(data, "bonus_left_usd"),
|
|
623
|
+
wageredUsd: optStr(data, "wagered_usd"),
|
|
624
|
+
goalUsd: optStr(data, "goal_usd"),
|
|
625
|
+
progressPct: percentOf(data.progress_pct, 0),
|
|
626
|
+
expiresAt: optStr(data, "expires_at"),
|
|
627
|
+
activatedAt: optStr(data, "activated_at"),
|
|
628
|
+
});
|
|
629
|
+
export const readBonuses = (value) => {
|
|
630
|
+
const data = asObject(value, "bonuses");
|
|
631
|
+
if (typeof data.enabled !== "boolean")
|
|
632
|
+
throw invalid("enabled");
|
|
633
|
+
return {
|
|
634
|
+
enabled: data.enabled,
|
|
635
|
+
attached: isObject(data.attached) ? readAttachedBonus(data.attached) : null,
|
|
636
|
+
active: isObject(data.active) ? readActiveBonus(data.active) : null,
|
|
637
|
+
};
|
|
638
|
+
};
|
|
639
|
+
export const toBonusPreviewBody = (code, amountUsd) => ({
|
|
640
|
+
code,
|
|
641
|
+
...(amountUsd !== undefined && amountUsd !== "" ? { amount_usd: String(amountUsd) } : {}),
|
|
642
|
+
});
|
|
643
|
+
export const toBonusAttachBody = (code) => ({ code });
|
|
644
|
+
export const readBonusPreview = (value) => {
|
|
645
|
+
const data = asObject(value, "bonus preview");
|
|
646
|
+
if (typeof data.valid !== "boolean")
|
|
647
|
+
throw invalid("valid");
|
|
648
|
+
const bonus = isObject(data.bonus) ? data.bonus : null;
|
|
649
|
+
return {
|
|
650
|
+
valid: data.valid,
|
|
651
|
+
code: optStr(data, "code") ?? "",
|
|
652
|
+
reason: data.valid ? null : (optStr(data, "reason") ?? "BONUS_CODE_NOT_FOUND"),
|
|
653
|
+
estimatedBonusUsd: optStr(data, "estimated_bonus_usd"),
|
|
654
|
+
bonus: bonus ? { ...readAttachedBonus(bonus), firstDepositOnly: bonus.first_deposit_only === true } : null,
|
|
655
|
+
};
|
|
656
|
+
};
|
|
578
657
|
export const REQUISITES_FRAME_MESSAGES = {
|
|
579
658
|
ready: "binodex-embed:ready",
|
|
580
659
|
resize: "binodex-embed:resize",
|
package/dist/elements/Root.js
CHANGED
|
@@ -6,6 +6,7 @@ import { resolveSkin, resolveTheme, themeVariables } from "../core/appearance.js
|
|
|
6
6
|
import { createPayClient } from "../core/client.js";
|
|
7
7
|
import { FALLBACK_CODES } from "../core/errors.js";
|
|
8
8
|
import { createDepositFlow } from "../core/flows/deposit.js";
|
|
9
|
+
import { createPromoFlow } from "../core/flows/promo.js";
|
|
9
10
|
import { createWithdrawFlow } from "../core/flows/withdraw.js";
|
|
10
11
|
import { createTranslator, intlLocale, isRtlLocale, resolveLocale, } from "../core/i18n/index.js";
|
|
11
12
|
import { createStore } from "../core/store.js";
|
|
@@ -65,6 +66,7 @@ export const Root = forwardRef(function Root(props, ref) {
|
|
|
65
66
|
const flow = useMemo(() => mode === "deposit"
|
|
66
67
|
? createDepositFlow(client, { returnUrl, onrampTheme: legacyTheme(appearance?.theme ?? "") })
|
|
67
68
|
: createWithdrawFlow(client), [client, mode]);
|
|
69
|
+
const promo = useMemo(() => (mode === "deposit" ? createPromoFlow(client) : null), [client, mode]);
|
|
68
70
|
const picker = useMemo(() => createStore({ cryptoOpen: false, cryptoCurrency: null, tab: null, country: null, fiatMethodId: null }), [flow]);
|
|
69
71
|
const cryptoCache = useMemo(() => new Map(), [client]);
|
|
70
72
|
useEffect(() => {
|
|
@@ -75,11 +77,13 @@ export const Root = forwardRef(function Root(props, ref) {
|
|
|
75
77
|
return () => {
|
|
76
78
|
release();
|
|
77
79
|
setTimeout(() => {
|
|
78
|
-
if (client.destroyed)
|
|
79
|
-
|
|
80
|
+
if (!client.destroyed)
|
|
81
|
+
return;
|
|
82
|
+
flow.actions.destroy();
|
|
83
|
+
promo?.actions.destroy();
|
|
80
84
|
}, 0);
|
|
81
85
|
};
|
|
82
|
-
}, [client, flow, open]);
|
|
86
|
+
}, [client, flow, promo, open]);
|
|
83
87
|
const wasOpen = useRef(open);
|
|
84
88
|
useEffect(() => {
|
|
85
89
|
if (wasOpen.current && !open)
|
|
@@ -111,6 +115,7 @@ export const Root = forwardRef(function Root(props, ref) {
|
|
|
111
115
|
client,
|
|
112
116
|
mode,
|
|
113
117
|
flow,
|
|
118
|
+
promo,
|
|
114
119
|
open,
|
|
115
120
|
setOpen,
|
|
116
121
|
restart,
|
|
@@ -123,15 +128,17 @@ export const Root = forwardRef(function Root(props, ref) {
|
|
|
123
128
|
unstyled,
|
|
124
129
|
picker,
|
|
125
130
|
cryptoCache,
|
|
126
|
-
}), [client, mode, flow, open, setOpen, restart, t, locale, dir, theme, skin, unstyled, picker, cryptoCache]);
|
|
131
|
+
}), [client, mode, flow, promo, open, setOpen, restart, t, locale, dir, theme, skin, unstyled, picker, cryptoCache]);
|
|
127
132
|
const fallbackActive = fallback === "iframe" &&
|
|
128
133
|
clientState.status === "error" &&
|
|
129
134
|
clientState.error !== null &&
|
|
130
135
|
FALLBACK_CODES.has(clientState.error.code);
|
|
131
136
|
useEffect(() => {
|
|
132
|
-
if (fallbackActive)
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
if (!fallbackActive)
|
|
138
|
+
return;
|
|
139
|
+
flow.actions.destroy();
|
|
140
|
+
promo?.actions.destroy();
|
|
141
|
+
}, [fallbackActive, flow, promo]);
|
|
135
142
|
const rootStyle = { ...variables, ...style };
|
|
136
143
|
return (_jsx("div", { ...rest, ref: ref, className: cx(!unstyled && "bp-root", className), style: rootStyle, "data-binodex-pay": "root", "data-theme": theme, "data-skin": skin, "data-mode": mode, "data-state": open ? "open" : "closed", "data-status": clientState.status, "data-fallback": fallbackActive ? "iframe" : undefined, dir: dir, lang: intlLocale(locale), children: fallbackActive ? (_jsx(LegacyFallback, { mode: mode, sessionEndpoint: sessionEndpoint, createSession: hasCreateSession ? createSession : undefined, clientId: clientId, platformUrl: platformUrl, allowedWidgetOrigins: allowedWidgetOrigins, lang: intlLocale(locale), theme: theme === "auto" ? undefined : theme, open: open, setOpen: setOpen, onEvent: (event) => latest.current.onEvent?.(event), loading: t("common.loading") })) : (_jsx(PayRootContext.Provider, { value: value, children: _jsx(PayUiValueProvider, { value: uiValue, children: children }) })) }));
|
|
137
144
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef, } from "react";
|
|
4
4
|
import { isRetryable } from "../../core/errors.js";
|
|
5
|
+
import { withdrawBonusGate } from "../../core/rules/bonus.js";
|
|
5
6
|
import { errorMessage } from "../../core/i18n/index.js";
|
|
6
7
|
import { formatMoney } from "../../core/money.js";
|
|
7
8
|
import * as ui from "../../ui/index.js";
|
|
@@ -114,8 +115,10 @@ export const SubmitButton = forwardRef(function SubmitButton({ onClick, type = "
|
|
|
114
115
|
if (withdraw.step === "status" || withdraw.step === "loading" || withdraw.step === "error")
|
|
115
116
|
return null;
|
|
116
117
|
pending = withdraw.step === "submitting" || withdraw.step === "quoting";
|
|
118
|
+
const gate = withdrawBonusGate(withdraw.bonus, withdraw.burnConsent);
|
|
117
119
|
ready =
|
|
118
|
-
|
|
120
|
+
(gate === "none" || gate === "ready") &&
|
|
121
|
+
!!withdraw.quote &&
|
|
119
122
|
!withdraw.addressError &&
|
|
120
123
|
!withdraw.amountError &&
|
|
121
124
|
(withdraw.step !== "two-factor" || withdraw.twoFactorCode.length === 6);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type HTMLAttributes } 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
|
+
export type PromoCodeProps = DivProps;
|
|
6
|
+
/**
|
|
7
|
+
* The promo code of a deposit: a collapsed «Have a promo code?» row, the code field,
|
|
8
|
+
* the attached code with its terms, or the progress of the bonus already credited.
|
|
9
|
+
* Renders nothing when promo codes are off or the backend does not know them.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PromoCode: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
12
|
+
export type WithdrawBonusProps = DivProps;
|
|
13
|
+
/**
|
|
14
|
+
* What a live promo bonus means for this withdrawal: locked until the trading volume is
|
|
15
|
+
* reached, waiting for open positions to close, or open once the user agrees that it burns
|
|
16
|
+
* the rest of the bonus (a required checkbox; the submit button waits for it).
|
|
17
|
+
*/
|
|
18
|
+
export declare const WithdrawBonus: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, "style" | "children" | "className"> & ui.PartStyleProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
19
|
+
export {};
|