@swype-org/deposit 0.3.31 → 0.3.32

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/dist/index.cjs CHANGED
@@ -147,12 +147,13 @@ function parseWidthHint(key, value) {
147
147
  function buildRevealMessage() {
148
148
  return { type: "blink:reveal" };
149
149
  }
150
- function buildSignedPayloadMessage(merchantId, payload, signature) {
150
+ function buildSignedPayloadMessage(merchantId, payload, signature, balance) {
151
151
  return {
152
152
  type: "blink:signed-payload",
153
153
  merchantId,
154
154
  payload,
155
- signature
155
+ signature,
156
+ ...balance === void 0 ? {} : { balance }
156
157
  };
157
158
  }
158
159
 
@@ -173,6 +174,16 @@ function normalizeBrandHex(value) {
173
174
  return `#${digits[0]}${digits[0]}${digits[1]}${digits[1]}${digits[2]}${digits[2]}`;
174
175
  }
175
176
 
177
+ // src/balanceParam.ts
178
+ var MAX_BALANCE_USD = 1e12;
179
+ function normalizeDisplayBalance(value) {
180
+ if (typeof value !== "number" || !Number.isFinite(value)) return null;
181
+ if (value < 0 || value >= MAX_BALANCE_USD) return null;
182
+ const cents = Math.floor(Number((value * 100).toPrecision(15)));
183
+ if (cents < 0 || cents >= MAX_BALANCE_USD * 100) return null;
184
+ return (cents / 100).toFixed(2);
185
+ }
186
+
176
187
  // src/walletBridge/discover.ts
177
188
  function createWalletDiscoverer() {
178
189
  if (typeof window === "undefined") {
@@ -1573,6 +1584,32 @@ var Deposit = class {
1573
1584
  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(".");
1574
1585
  if (encoded) url.searchParams.set("brand", encoded);
1575
1586
  }
1587
+ /**
1588
+ * Normalizes the display-only {@link DepositRequest.balance} for the wire,
1589
+ * or returns `undefined` to omit it everywhere — the `blink:signed-payload`
1590
+ * sibling field and the legacy fallback URL param alike. Additive wire
1591
+ * discipline: an unset or rejected balance leaves both channels
1592
+ * byte-for-byte what they always were, and old webviews ignore the field
1593
+ * by construction.
1594
+ *
1595
+ * Validated here purely so the merchant sees the complaint in their OWN
1596
+ * console (same rationale as {@link applyBrandParam}); the hosted flow
1597
+ * re-validates whatever arrives, since both channels are host-controlled
1598
+ * input. A rejected balance never blocks the deposit — the flow proceeds
1599
+ * without the subtitle.
1600
+ */
1601
+ normalizeRequestBalance(balance) {
1602
+ if (balance === void 0 || balance === null) return void 0;
1603
+ const normalized = normalizeDisplayBalance(balance);
1604
+ if (normalized === null) {
1605
+ const received = typeof balance === "number" ? String(balance) : JSON.stringify(balance) ?? String(balance);
1606
+ console.error(
1607
+ `[blink] balance must be a finite number >= 0 and < 1e12 (USD, display only); received ${received}. Ignoring it.`
1608
+ );
1609
+ return void 0;
1610
+ }
1611
+ return normalized;
1612
+ }
1576
1613
  /**
1577
1614
  * Fluid is the default; `layout: 'fixed'` opts back into the legacy
1578
1615
  * container. Embedded is a separate presentation and never fluid — the
@@ -1631,6 +1668,7 @@ var Deposit = class {
1631
1668
  signer: typeof this.config.signer === "string" ? this.config.signer : "<function>"
1632
1669
  });
1633
1670
  const signerRequest = buildSignerRequest(request, webviewBaseUrl);
1671
+ const displayBalance = this.normalizeRequestBalance(request.balance);
1634
1672
  let preloadIframe;
1635
1673
  let iframeReadyPromise;
1636
1674
  const warm = this.takeWarmIframe();
@@ -1683,7 +1721,8 @@ var Deposit = class {
1683
1721
  buildSignedPayloadMessage(
1684
1722
  signerResponse.merchantId,
1685
1723
  signerResponse.payload,
1686
- signerResponse.signature
1724
+ signerResponse.signature,
1725
+ displayBalance
1687
1726
  ),
1688
1727
  this.hostedOrigin
1689
1728
  );
@@ -1697,6 +1736,9 @@ var Deposit = class {
1697
1736
  hostedUrl.searchParams.set("merchantId", signerResponse.merchantId);
1698
1737
  hostedUrl.searchParams.set("payload", signerResponse.payload);
1699
1738
  hostedUrl.searchParams.set("signature", signerResponse.signature);
1739
+ if (displayBalance !== void 0) {
1740
+ hostedUrl.searchParams.set("balance", displayBalance);
1741
+ }
1700
1742
  this.applyFullWidgetParam(hostedUrl);
1701
1743
  if (this.isEmbedded()) {
1702
1744
  this.applyLayoutParam(hostedUrl);
@@ -1869,7 +1911,7 @@ function detectMerchantColorScheme() {
1869
1911
  var Checkout = Deposit;
1870
1912
 
1871
1913
  // src/index.ts
1872
- var VERSION = "0.3.27";
1914
+ var VERSION = "0.3.32";
1873
1915
 
1874
1916
  exports.ALLOWED_RPC_METHODS = ALLOWED_RPC_METHODS;
1875
1917
  exports.BRIDGE_PROTOCOL_VERSION = BRIDGE_PROTOCOL_VERSION;