@swype-org/deposit 0.3.31 → 0.3.34
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 +24 -0
- package/dist/{chunk-HBW7IVRJ.js → chunk-24WCJE4H.js} +84 -5
- package/dist/chunk-24WCJE4H.js.map +1 -0
- package/dist/index.cjs +83 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -3
- package/dist/index.d.ts +28 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +82 -3
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +2 -2
- package/dist/{types-NMNL3Jut.d.cts → types-Bwy_1TQT.d.cts} +33 -0
- package/dist/{types-NMNL3Jut.d.ts → types-Bwy_1TQT.d.ts} +33 -0
- package/package.json +1 -1
- package/dist/chunk-HBW7IVRJ.js.map +0 -1
package/README.md
CHANGED
|
@@ -257,6 +257,30 @@ overflow.
|
|
|
257
257
|
|
|
258
258
|
Your CSP needs `frame-src https://pay.blink.cash`.
|
|
259
259
|
|
|
260
|
+
### Merchant balance
|
|
261
|
+
|
|
262
|
+
If your users hold a balance on your platform, pass it on the request and the
|
|
263
|
+
flow shows it under the deposit header — "Acme balance: $20.70" — so the user
|
|
264
|
+
tops up with their number in view:
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
await deposit.requestDeposit({
|
|
268
|
+
amount: null,
|
|
269
|
+
chainId: 8453,
|
|
270
|
+
address: userWalletAddress,
|
|
271
|
+
token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
272
|
+
balance: 20.7, // USD — display only
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Display-only by design: the value is never part of the signed payload and never
|
|
277
|
+
reaches your signer, so no signer changes are needed — and it cannot affect the
|
|
278
|
+
transfer amount or destination. It must be a finite number, `>= 0` and below
|
|
279
|
+
`1e12`; the SDK floors it to whole cents (`20.789` shows as `$20.78`). Anything
|
|
280
|
+
else is dropped with a console error naming the field, and the deposit proceeds
|
|
281
|
+
without the subtitle. When you don't pass it, Blink may fall back to showing
|
|
282
|
+
the destination wallet's on-chain balance instead.
|
|
283
|
+
|
|
260
284
|
## Error Handling
|
|
261
285
|
|
|
262
286
|
Every error is a `DepositError` with a machine-readable `code`:
|
|
@@ -548,12 +548,14 @@ function parseWidthHint(key, value) {
|
|
|
548
548
|
function buildRevealMessage() {
|
|
549
549
|
return { type: "blink:reveal" };
|
|
550
550
|
}
|
|
551
|
-
function buildSignedPayloadMessage(merchantId, payload, signature) {
|
|
551
|
+
function buildSignedPayloadMessage(merchantId, payload, signature, balance, minimumDeposit) {
|
|
552
552
|
return {
|
|
553
553
|
type: "blink:signed-payload",
|
|
554
554
|
merchantId,
|
|
555
555
|
payload,
|
|
556
|
-
signature
|
|
556
|
+
signature,
|
|
557
|
+
...balance === void 0 ? {} : { balance },
|
|
558
|
+
...minimumDeposit === void 0 ? {} : { minimumDeposit }
|
|
557
559
|
};
|
|
558
560
|
}
|
|
559
561
|
|
|
@@ -574,6 +576,26 @@ function normalizeBrandHex(value) {
|
|
|
574
576
|
return `#${digits[0]}${digits[0]}${digits[1]}${digits[1]}${digits[2]}${digits[2]}`;
|
|
575
577
|
}
|
|
576
578
|
|
|
579
|
+
// src/balanceParam.ts
|
|
580
|
+
var MAX_BALANCE_USD = 1e12;
|
|
581
|
+
function normalizeDisplayBalance(value) {
|
|
582
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return null;
|
|
583
|
+
if (value < 0 || value >= MAX_BALANCE_USD) return null;
|
|
584
|
+
const cents = Math.floor(Number((value * 100).toPrecision(15)));
|
|
585
|
+
if (cents < 0 || cents >= MAX_BALANCE_USD * 100) return null;
|
|
586
|
+
return (cents / 100).toFixed(2);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// src/minimumDepositParam.ts
|
|
590
|
+
var MAX_MINIMUM_DEPOSIT_USD = 1e6;
|
|
591
|
+
function normalizeMinimumDeposit(value) {
|
|
592
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return null;
|
|
593
|
+
if (value <= 0 || value >= MAX_MINIMUM_DEPOSIT_USD) return null;
|
|
594
|
+
const cents = Math.ceil(Number((value * 100).toPrecision(15)));
|
|
595
|
+
if (cents <= 0 || cents >= MAX_MINIMUM_DEPOSIT_USD * 100) return null;
|
|
596
|
+
return (cents / 100).toFixed(2);
|
|
597
|
+
}
|
|
598
|
+
|
|
577
599
|
// src/viewportMetrics.ts
|
|
578
600
|
function measureViewportMetrics() {
|
|
579
601
|
const unavailable = { viewportLvh: 0, safeAreaBottom: 0 };
|
|
@@ -1571,6 +1593,53 @@ var Deposit = class {
|
|
|
1571
1593
|
const encoded = Object.keys(BRAND_COLOR_PARAM_KEYS).filter((key) => accepted[key] !== void 0).map((key) => `${BRAND_COLOR_PARAM_KEYS[key]}-${accepted[key].slice(1)}`).join(".");
|
|
1572
1594
|
if (encoded) url.searchParams.set("brand", encoded);
|
|
1573
1595
|
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Normalizes the display-only {@link DepositRequest.balance} for the wire,
|
|
1598
|
+
* or returns `undefined` to omit it everywhere — the `blink:signed-payload`
|
|
1599
|
+
* sibling field and the legacy fallback URL param alike. Additive wire
|
|
1600
|
+
* discipline: an unset or rejected balance leaves both channels
|
|
1601
|
+
* byte-for-byte what they always were, and old webviews ignore the field
|
|
1602
|
+
* by construction.
|
|
1603
|
+
*
|
|
1604
|
+
* Validated here purely so the merchant sees the complaint in their OWN
|
|
1605
|
+
* console (same rationale as {@link applyBrandParam}); the hosted flow
|
|
1606
|
+
* re-validates whatever arrives, since both channels are host-controlled
|
|
1607
|
+
* input. A rejected balance never blocks the deposit — the flow proceeds
|
|
1608
|
+
* without the subtitle.
|
|
1609
|
+
*/
|
|
1610
|
+
normalizeRequestBalance(balance) {
|
|
1611
|
+
if (balance === void 0 || balance === null) return void 0;
|
|
1612
|
+
const normalized = normalizeDisplayBalance(balance);
|
|
1613
|
+
if (normalized === null) {
|
|
1614
|
+
const received = typeof balance === "number" ? String(balance) : JSON.stringify(balance) ?? String(balance);
|
|
1615
|
+
console.error(
|
|
1616
|
+
`[blink] balance must be a finite number >= 0 and < 1e12 (USD, display only); received ${received}. Ignoring it.`
|
|
1617
|
+
);
|
|
1618
|
+
return void 0;
|
|
1619
|
+
}
|
|
1620
|
+
return normalized;
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Normalizes {@link DepositRequest.minimumDeposit} for the wire, or returns
|
|
1624
|
+
* `undefined` to omit it everywhere. Same additive discipline and same
|
|
1625
|
+
* console-complaint rationale as {@link normalizeRequestBalance}.
|
|
1626
|
+
*
|
|
1627
|
+
* A rejected minimum never blocks the deposit — the flow proceeds on
|
|
1628
|
+
* Blink's own per-route floor, which is the safe direction to fail: the
|
|
1629
|
+
* merchant loses their higher floor, nobody is locked out of depositing.
|
|
1630
|
+
*/
|
|
1631
|
+
normalizeRequestMinimumDeposit(minimumDeposit) {
|
|
1632
|
+
if (minimumDeposit === void 0 || minimumDeposit === null) return void 0;
|
|
1633
|
+
const normalized = normalizeMinimumDeposit(minimumDeposit);
|
|
1634
|
+
if (normalized === null) {
|
|
1635
|
+
const received = typeof minimumDeposit === "number" ? String(minimumDeposit) : JSON.stringify(minimumDeposit) ?? String(minimumDeposit);
|
|
1636
|
+
console.error(
|
|
1637
|
+
`[blink] minimumDeposit must be a finite number > 0 and < 1e6 (USD); received ${received}. Ignoring it.`
|
|
1638
|
+
);
|
|
1639
|
+
return void 0;
|
|
1640
|
+
}
|
|
1641
|
+
return normalized;
|
|
1642
|
+
}
|
|
1574
1643
|
/**
|
|
1575
1644
|
* Fluid is the default; `layout: 'fixed'` opts back into the legacy
|
|
1576
1645
|
* container. Embedded is a separate presentation and never fluid — the
|
|
@@ -1629,6 +1698,8 @@ var Deposit = class {
|
|
|
1629
1698
|
signer: typeof this.config.signer === "string" ? this.config.signer : "<function>"
|
|
1630
1699
|
});
|
|
1631
1700
|
const signerRequest = buildSignerRequest(request, webviewBaseUrl);
|
|
1701
|
+
const displayBalance = this.normalizeRequestBalance(request.balance);
|
|
1702
|
+
const minimumDeposit = this.normalizeRequestMinimumDeposit(request.minimumDeposit);
|
|
1632
1703
|
let preloadIframe;
|
|
1633
1704
|
let iframeReadyPromise;
|
|
1634
1705
|
const warm = this.takeWarmIframe();
|
|
@@ -1681,7 +1752,9 @@ var Deposit = class {
|
|
|
1681
1752
|
buildSignedPayloadMessage(
|
|
1682
1753
|
signerResponse.merchantId,
|
|
1683
1754
|
signerResponse.payload,
|
|
1684
|
-
signerResponse.signature
|
|
1755
|
+
signerResponse.signature,
|
|
1756
|
+
displayBalance,
|
|
1757
|
+
minimumDeposit
|
|
1685
1758
|
),
|
|
1686
1759
|
this.hostedOrigin
|
|
1687
1760
|
);
|
|
@@ -1695,6 +1768,12 @@ var Deposit = class {
|
|
|
1695
1768
|
hostedUrl.searchParams.set("merchantId", signerResponse.merchantId);
|
|
1696
1769
|
hostedUrl.searchParams.set("payload", signerResponse.payload);
|
|
1697
1770
|
hostedUrl.searchParams.set("signature", signerResponse.signature);
|
|
1771
|
+
if (displayBalance !== void 0) {
|
|
1772
|
+
hostedUrl.searchParams.set("balance", displayBalance);
|
|
1773
|
+
}
|
|
1774
|
+
if (minimumDeposit !== void 0) {
|
|
1775
|
+
hostedUrl.searchParams.set("minDeposit", minimumDeposit);
|
|
1776
|
+
}
|
|
1698
1777
|
this.applyFullWidgetParam(hostedUrl);
|
|
1699
1778
|
if (this.isEmbedded()) {
|
|
1700
1779
|
this.applyLayoutParam(hostedUrl);
|
|
@@ -1867,5 +1946,5 @@ function detectMerchantColorScheme() {
|
|
|
1867
1946
|
var Checkout = Deposit;
|
|
1868
1947
|
|
|
1869
1948
|
export { ALLOWED_RPC_METHODS, BRIDGE_PROTOCOL_VERSION, Checkout, CheckoutError, DEFAULT_WEBVIEW_BASE_URL, Deposit, DepositError, SANDBOX_WEBVIEW_BASE_URL, attachRpcHost, createWalletDiscoverer, getDisplayMessage, parseBridgeMessage };
|
|
1870
|
-
//# sourceMappingURL=chunk-
|
|
1871
|
-
//# sourceMappingURL=chunk-
|
|
1949
|
+
//# sourceMappingURL=chunk-24WCJE4H.js.map
|
|
1950
|
+
//# sourceMappingURL=chunk-24WCJE4H.js.map
|