@phala/pay 0.8.2 → 0.9.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 (104) hide show
  1. package/README.md +33 -58
  2. package/THIRD_PARTY_NOTICES +25 -0
  3. package/dist/chains.d.ts +2 -0
  4. package/dist/chains.d.ts.map +1 -1
  5. package/dist/chains.js +11 -2
  6. package/dist/chains.js.map +1 -1
  7. package/dist/checkout.d.ts +4 -2
  8. package/dist/checkout.d.ts.map +1 -1
  9. package/dist/checkout.js +18 -3
  10. package/dist/checkout.js.map +1 -1
  11. package/dist/deposit-address.js +2 -2
  12. package/dist/deposit-address.js.map +1 -1
  13. package/dist/icon-names.d.ts +7 -0
  14. package/dist/icon-names.d.ts.map +1 -0
  15. package/dist/icon-names.js +15 -0
  16. package/dist/icon-names.js.map +1 -0
  17. package/dist/icon-svg.d.ts +6 -0
  18. package/dist/icon-svg.d.ts.map +1 -0
  19. package/dist/icon-svg.js +13 -0
  20. package/dist/icon-svg.js.map +1 -0
  21. package/dist/icons.d.ts +5 -0
  22. package/dist/icons.d.ts.map +1 -0
  23. package/dist/icons.js +27 -0
  24. package/dist/icons.js.map +1 -0
  25. package/dist/index.d.ts +6 -3
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +5 -3
  28. package/dist/index.js.map +1 -1
  29. package/dist/request.d.ts +2 -0
  30. package/dist/request.d.ts.map +1 -1
  31. package/dist/request.js +7 -0
  32. package/dist/request.js.map +1 -1
  33. package/dist/shared/checkout-params.d.ts +7 -0
  34. package/dist/shared/checkout-params.d.ts.map +1 -0
  35. package/dist/shared/checkout-params.js +2 -0
  36. package/dist/shared/checkout-params.js.map +1 -0
  37. package/package.json +18 -31
  38. package/src/chains.ts +12 -2
  39. package/src/checkout.ts +21 -4
  40. package/src/deposit-address.ts +2 -2
  41. package/src/generated/openapi.d.ts +9482 -0
  42. package/src/icon-names.ts +20 -0
  43. package/src/icon-svg.ts +13 -0
  44. package/src/icons.ts +30 -0
  45. package/src/index.ts +6 -2
  46. package/src/request.ts +7 -0
  47. package/src/shared/checkout-params.ts +6 -0
  48. package/dist/react/Checkout.d.ts +0 -43
  49. package/dist/react/Checkout.d.ts.map +0 -1
  50. package/dist/react/Checkout.js +0 -193
  51. package/dist/react/Checkout.js.map +0 -1
  52. package/dist/react/DepositAddress.d.ts +0 -32
  53. package/dist/react/DepositAddress.d.ts.map +0 -1
  54. package/dist/react/DepositAddress.js +0 -131
  55. package/dist/react/DepositAddress.js.map +0 -1
  56. package/dist/react/Field.d.ts +0 -7
  57. package/dist/react/Field.d.ts.map +0 -1
  58. package/dist/react/Field.js +0 -21
  59. package/dist/react/Field.js.map +0 -1
  60. package/dist/react/QrCode.d.ts +0 -8
  61. package/dist/react/QrCode.d.ts.map +0 -1
  62. package/dist/react/QrCode.js +0 -20
  63. package/dist/react/QrCode.js.map +0 -1
  64. package/dist/react/appearance.d.ts +0 -5
  65. package/dist/react/appearance.d.ts.map +0 -1
  66. package/dist/react/appearance.js +0 -2
  67. package/dist/react/appearance.js.map +0 -1
  68. package/dist/react/index.d.ts +0 -5
  69. package/dist/react/index.d.ts.map +0 -1
  70. package/dist/react/index.js +0 -5
  71. package/dist/react/index.js.map +0 -1
  72. package/dist/react/useCheckout.d.ts +0 -9
  73. package/dist/react/useCheckout.d.ts.map +0 -1
  74. package/dist/react/useCheckout.js +0 -32
  75. package/dist/react/useCheckout.js.map +0 -1
  76. package/dist/server/addresses.d.ts +0 -78
  77. package/dist/server/addresses.d.ts.map +0 -1
  78. package/dist/server/addresses.js +0 -118
  79. package/dist/server/addresses.js.map +0 -1
  80. package/dist/server/index.d.ts +0 -12
  81. package/dist/server/index.d.ts.map +0 -1
  82. package/dist/server/index.js +0 -12
  83. package/dist/server/index.js.map +0 -1
  84. package/dist/server/sweeps.d.ts +0 -78
  85. package/dist/server/sweeps.d.ts.map +0 -1
  86. package/dist/server/sweeps.js +0 -117
  87. package/dist/server/sweeps.js.map +0 -1
  88. package/dist/server/webhook.d.ts +0 -61
  89. package/dist/server/webhook.d.ts.map +0 -1
  90. package/dist/server/webhook.js +0 -154
  91. package/dist/server/webhook.js.map +0 -1
  92. package/src/css.d.ts +0 -1
  93. package/src/react/Checkout.tsx +0 -469
  94. package/src/react/DepositAddress.tsx +0 -239
  95. package/src/react/Field.tsx +0 -46
  96. package/src/react/QrCode.tsx +0 -39
  97. package/src/react/appearance.ts +0 -4
  98. package/src/react/index.ts +0 -6
  99. package/src/react/useCheckout.ts +0 -58
  100. package/src/server/addresses.ts +0 -223
  101. package/src/server/index.ts +0 -38
  102. package/src/server/sweeps.ts +0 -197
  103. package/src/server/webhook.ts +0 -208
  104. package/src/styles.css +0 -76
@@ -0,0 +1,20 @@
1
+ import type { ICON_SVG } from "./icon-svg.js";
2
+
3
+ export type IconName = keyof typeof ICON_SVG;
4
+
5
+ /** Case-insensitive token symbol; unrecognized symbols use a neutral monogram. */
6
+ export function assetIconName(asset: string): IconName | undefined {
7
+ switch (asset.trim().toLowerCase()) {
8
+ case "usdc": return "usdc";
9
+ case "usdt": return "usdt";
10
+ case "pha": return "pha";
11
+ case "eth": return "eth";
12
+ default: return undefined;
13
+ }
14
+ }
15
+
16
+ /** First character for a neutral fallback, including an empty-symbol placeholder. */
17
+ export function iconMonogram(label: string): string {
18
+ return Array.from(label.trim())[0]?.toUpperCase() ?? "?";
19
+ }
20
+
@@ -0,0 +1,13 @@
1
+ /** Generated from @web3icons/core@4.0.57 by scripts/generate-icons.mjs.
2
+ * SPDX-License-Identifier: MIT; Copyright (c) 2024 0xa3k5.
3
+ * See THIRD_PARTY_NOTICES for the full license. Do not edit.
4
+ */
5
+
6
+ export const ICON_SVG: Record<"usdc" | "usdt" | "pha" | "eth" | "ethereum" | "base", string> = {
7
+ usdc: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" fill=\"none\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"#0B53BF\" d=\"M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18\"/><path fill=\"#fff\" d=\"M13.62 5.45v1.159a5.64 5.64 0 0 1 4.005 5.394 5.64 5.64 0 0 1-4.005 5.394v1.16a6.74 6.74 0 0 0 5.13-6.554 6.74 6.74 0 0 0-5.13-6.553m-7.245 6.553a5.64 5.64 0 0 1 4.005-5.394V5.45a6.74 6.74 0 0 0-5.13 6.553 6.74 6.74 0 0 0 5.13 6.553v-1.159a5.63 5.63 0 0 1-4.005-5.394\"/><path fill=\"#fff\" d=\"M14.419 13.258c0-2.301-3.606-1.356-3.606-2.627 0-.456.366-.748 1.063-.748.833 0 1.12.405 1.21.95h1.147c-.102-1.024-.69-1.67-1.67-1.863v-.904h-1.125v.872c-1.075.137-1.75.762-1.75 1.693 0 2.312 3.611 1.445 3.611 2.694 0 .472-.455.787-1.226.787-1.007 0-1.339-.444-1.462-1.057H9.49c.073 1.122.764 1.823 1.947 1.999v.886h1.125v-.875c1.153-.149 1.856-.82 1.856-1.807\"/></svg>",
8
+ usdt: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" fill=\"none\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"#009393\" d=\"m12 19.2-9-8.88L6.433 4.8h11.134L21 10.32zm.9-8.1v-1.098c1.62.08 3.132.396 3.6.805-.544.477-2.493.824-4.5.824s-3.956-.347-4.5-.824c.463-.41 1.98-.72 3.6-.81V11.1zm-5.4-.297v.661c.463.41 1.975.72 3.6.81V14.7h1.8v-2.43c1.62-.081 3.136-.396 3.6-.806v-1.318c-.464-.41-1.98-.725-3.6-.81V8.4h2.7V7.05H8.4V8.4h2.7v.936c-1.625.085-3.137.4-3.6.81z\"/></svg>",
9
+ pha: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" fill=\"none\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><circle cx=\"12\" cy=\"12\" r=\"12\" fill=\"#252525\"/><path fill=\"#D1FF52\" fill-rule=\"evenodd\" d=\"M3 3h14.143v3.857H21V12h-3.857V6.857H6.857V12H3zm3.857 12.857h10.286V12H6.857zm0 0V21H3v-5.143z\" clip-rule=\"evenodd\"/></svg>",
10
+ eth: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" fill=\"none\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"#8FFCF3\" d=\"M12 3v6.65l5.625 2.516z\"/><path fill=\"#CABCF8\" d=\"m12 3-5.625 9.166L12 9.651z\"/><path fill=\"#CBA7F5\" d=\"M12 16.477v4.522l5.625-7.784z\"/><path fill=\"#74A0F3\" d=\"M12 21v-4.523l-5.625-3.262z\"/><path fill=\"#CBA7F5\" d=\"m12 15.43 5.625-3.263L12 9.65z\"/><path fill=\"#74A0F3\" d=\"M6.375 12.167 12 15.429V9.651z\"/><path fill=\"#202699\" fill-rule=\"evenodd\" d=\"m12 15.429-5.625-3.263L12 3l5.625 9.166zM6.749 11.9l5.16-8.41v6.115zm-.077.23 5.238-2.327v5.364zm5.418-2.327v5.364l5.233-3.038zm0-.198 5.16 2.295-5.16-8.41z\" clip-rule=\"evenodd\"/><path fill=\"#202699\" fill-rule=\"evenodd\" d=\"M12 16.406 6.375 13.21 12 21l5.625-7.79zm-4.995-2.633 4.905 2.79v4.005zm5.085 2.79v4.005l4.905-6.795z\" clip-rule=\"evenodd\"/></svg>",
11
+ ethereum: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" fill=\"none\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"#8FFCF3\" d=\"M12 3v6.651l5.625 2.516z\"/><path fill=\"#CABCF8\" d=\"m12 3-5.625 9.166L12 9.653z\"/><path fill=\"#CBA7F5\" d=\"M12 16.478V21l5.625-7.784z\"/><path fill=\"#74A0F3\" d=\"M12 21v-4.522l-5.625-3.262z\"/><path fill=\"#CBA7F5\" d=\"m12 15.43 5.625-3.263L12 9.652z\"/><path fill=\"#74A0F3\" d=\"M6.375 12.167 12 15.43V9.652z\"/><path fill=\"#202699\" fill-rule=\"evenodd\" d=\"m12 15.43-5.625-3.263L12 3l5.624 9.166zm-5.252-3.528 5.161-8.41v6.114zm-.077.229 5.238-2.327v5.364zm5.418-2.327v5.364l5.234-3.037zm0-.198 5.161 2.296-5.161-8.41z\" clip-rule=\"evenodd\"/><path fill=\"#202699\" fill-rule=\"evenodd\" d=\"m12 16.406-5.625-3.195L12 21l5.624-7.79zm-4.995-2.633 4.904 2.79v4.005zm5.084 2.79v4.005l4.905-6.795z\" clip-rule=\"evenodd\"/></svg>",
12
+ base: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" fill=\"none\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"#00F\" d=\"M3 4.706c0-.585 0-.877.11-1.101.106-.215.28-.39.496-.495C3.83 3 4.122 3 4.706 3h14.588c.585 0 .876 0 1.101.11.215.105.389.28.494.495.111.225.111.517.111 1.101v14.588c0 .585 0 .876-.11 1.101-.106.215-.28.389-.495.494-.225.111-.517.111-1.101.111H4.706c-.585 0-.876 0-1.101-.11a1.08 1.08 0 0 1-.494-.495C3 20.17 3 19.878 3 19.294z\"/></svg>",
13
+ };
package/src/icons.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { networkName, networkIconName } from "./chains.js";
2
+ import { ICON_SVG } from "./icon-svg.js";
3
+
4
+ import { assetIconName, iconMonogram } from "./icon-names.js";
5
+
6
+ function fallback(label: string): string {
7
+ const letter = iconMonogram(label).replace(/[&<>"']/g, (character) => {
8
+ switch (character) {
9
+ case "&": return "&amp;";
10
+ case "<": return "&lt;";
11
+ case ">": return "&gt;";
12
+ case '"': return "&quot;";
13
+ default: return "&#39;";
14
+ }
15
+ });
16
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="11" fill="currentColor" opacity="0.12"/><text x="12" y="16" text-anchor="middle" font-family="sans-serif" font-size="12" fill="currentColor">${letter}</text></svg>`;
17
+ }
18
+
19
+ /** Decorative inline SVG markup; testnets reuse their mainnet family artwork. */
20
+ export function networkIcon(chainId: number): string {
21
+ const name = networkIconName(chainId);
22
+ const svg = name === undefined ? fallback(networkName(chainId)) : ICON_SVG[name];
23
+ return svg;
24
+ }
25
+
26
+ /** Decorative inline SVG markup; keep the asset name visible beside it. */
27
+ export function assetIcon(asset: string): string {
28
+ const name = assetIconName(asset);
29
+ return name === undefined ? fallback(asset) : ICON_SVG[name];
30
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export {
2
2
  CheckoutError,
3
3
  checkoutStatus,
4
+ pollDelay,
4
5
  createCheckout,
5
6
  retrieveQuote,
6
7
  type CheckoutErrorCode,
@@ -21,8 +22,8 @@ export {
21
22
  type DepositAddressPayment,
22
23
  type RetrieveDepositAddressOptions,
23
24
  } from "./deposit-address.js";
24
- export { knownChain, networkName, transactionUrl } from "./chains.js";
25
- export { formatAmount, formatCountdown, formatTokenAmount, tokenAmount } from "./format.js";
25
+ export { knownChain, networkName, transactionUrl, networkIconName } from "./chains.js";
26
+ export { formatAmount, formatCountdown, formatMinorAmount, formatTokenAmount, formatWait, tokenAmount } from "./format.js";
26
27
  export {
27
28
  depositAddressTransfer,
28
29
  parseTransferUri,
@@ -34,6 +35,7 @@ export {
34
35
  type TransferRequest,
35
36
  } from "./payment.js";
36
37
  export { parseClientQuote, quoteIdFromClientSecret, type ClientQuote } from "./quote.js";
38
+ export { assetIconName, iconMonogram, type IconName } from "./icon-names.js";
37
39
  export {
38
40
  INJECTED_WALLET_UUID,
39
41
  WalletError,
@@ -44,3 +46,5 @@ export {
44
46
  type WalletErrorCode,
45
47
  type WalletInfo,
46
48
  } from "./wallet.js";
49
+ export { networkIcon, assetIcon } from "./icons.js";
50
+ export type { CheckoutParams } from "./shared/checkout-params.js";
package/src/request.ts CHANGED
@@ -6,3 +6,10 @@ export function requestSignal(options: {
6
6
  const deadline = AbortSignal.timeout(options.requestTimeout ?? 10_000);
7
7
  return options.signal === undefined ? deadline : AbortSignal.any([options.signal, deadline]);
8
8
  }
9
+
10
+ /** `apiBase` without trailing slashes, in linear time (a `/\/+$/` regex is quadratic). */
11
+ export function trimTrailingSlashes(apiBase: string): string {
12
+ let end = apiBase.length;
13
+ while (end > 0 && apiBase[end - 1] === "/") end -= 1;
14
+ return apiBase.slice(0, end);
15
+ }
@@ -0,0 +1,6 @@
1
+ /** The only server-to-browser checkout handoff; contains no merchant credentials or pins. */
2
+ export interface CheckoutParams {
3
+ clientSecret: string;
4
+ expectedAddress: string;
5
+ apiBase: string;
6
+ }
@@ -1,43 +0,0 @@
1
- import type { WalletClient } from "viem";
2
- import type { CheckoutState } from "../checkout.js";
3
- import type { ClientQuote } from "../quote.js";
4
- import { WalletError, type EthereumProvider } from "../wallet.js";
5
- import type { Appearance } from "./appearance.js";
6
- export interface CheckoutProps {
7
- /** The quote's `client_secret`, from your backend's `POST /v1/quotes`. */
8
- clientSecret: string;
9
- /**
10
- * The quote's `address` as your backend's SDK recomputed it from the pinned forwarder
11
- * (`PhalaPay(forwarder=…)` in Python). Required: when the service's quote names another
12
- * address, the checkout fails closed and shows nothing to pay.
13
- */
14
- expectedAddress: string;
15
- /** The service origin, for example `https://topup.example.com`. */
16
- apiBase: string;
17
- /** Called once when the payment is credited, with the quote: its `amount_credited` is what was
18
- * credited, which differs from `amount` for a payment of another amount or a late one. Fulfil
19
- * from the `deposit.credited` webhook, not here. */
20
- onSuccess?: (quote: ClientQuote) => void;
21
- /** Called once when the quote expires or is canceled without a payment. */
22
- onExpire?: (quote: ClientQuote) => void;
23
- /** Called whenever the checkout's status changes, like Stripe Elements' `onChange`: for example,
24
- * to hide your own "new payment" control while a payment is `seen` or `confirming`. */
25
- onChange?: (state: CheckoutState) => void;
26
- /** Called when the wallet tab could not send the payment, with the `WalletError` and the wallet
27
- * it tried (the chosen browser wallet's provider, or `walletClient`): for example on
28
- * `insufficient_balance` (nothing was sent), to offer your own way to fund that wallet. The
29
- * checkout shows the error's message itself. */
30
- onWalletError?: (error: WalletError, wallet: WalletClient | EthereumProvider) => void;
31
- appearance?: Appearance;
32
- /** Milliseconds between status reads; default 3000. */
33
- pollInterval?: number;
34
- className?: string;
35
- /** The wallet button's label; default "Pay with crypto". */
36
- buttonText?: string;
37
- /** Your page's connected wallet, for example wagmi's `useWalletClient().data`. When set, the
38
- * wallet tab pays with it and its account instead of listing the browser's wallets. */
39
- walletClient?: WalletClient | undefined;
40
- }
41
- /** A checkout for one quote: pay from a browser wallet, by QR code, or manually, with live status. */
42
- export declare function Checkout({ clientSecret, expectedAddress, apiBase, onSuccess, onExpire, onChange, onWalletError, appearance, pollInterval, className, buttonText, walletClient, }: CheckoutProps): import("react").JSX.Element;
43
- //# sourceMappingURL=Checkout.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Checkout.d.ts","sourceRoot":"","sources":["../../src/react/Checkout.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAQ,YAAY,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,KAAK,EAAqB,aAAa,EAAkB,MAAM,gBAAgB,CAAC;AAWvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,WAAW,EAGX,KAAK,gBAAgB,EAEtB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKlD,MAAM,WAAW,aAAa;IAC5B,0EAA0E;IAC1E,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB;;wDAEoD;IACpD,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACzC,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACxC;2FACuF;IACvF,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC1C;;;oDAGgD;IAChD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,GAAG,gBAAgB,KAAK,IAAI,CAAC;IACtF,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;2FACuF;IACvF,YAAY,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;CACzC;AAUD,sGAAsG;AACtG,wBAAgB,QAAQ,CAAC,EACvB,YAAY,EACZ,eAAe,EACf,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAA8B,EAC9B,YAAY,GACb,EAAE,aAAa,+BAyEf"}
@@ -1,193 +0,0 @@
1
- "use client";
2
- import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { useEffect, useId, useRef, useState } from "react";
4
- import { networkName, transactionUrl } from "../chains.js";
5
- import { formatAmount, formatCountdown, formatMinorAmount, formatTokenAmount, formatWait, tokenAmount, } from "../format.js";
6
- import { quoteTransfer } from "../payment.js";
7
- import { WalletError, payWithWallet, watchWallets, } from "../wallet.js";
8
- import { Field } from "./Field.js";
9
- import { QrCode } from "./QrCode.js";
10
- import { useCheckout } from "./useCheckout.js";
11
- const METHODS = [
12
- { id: "wallet", label: "Browser wallet" },
13
- { id: "qr", label: "QR code" },
14
- { id: "manual", label: "Send manually" },
15
- ];
16
- /** A checkout for one quote: pay from a browser wallet, by QR code, or manually, with live status. */
17
- export function Checkout({ clientSecret, expectedAddress, apiBase, onSuccess, onExpire, onChange, onWalletError, appearance, pollInterval, className, buttonText = "Pay with crypto", walletClient, }) {
18
- const { status, quote, error, refresh } = useCheckout({
19
- clientSecret,
20
- expectedAddress,
21
- apiBase,
22
- ...(pollInterval === undefined ? {} : { pollInterval }),
23
- });
24
- const [txHash, setTxHash] = useState(null);
25
- const now = useNow(status === "waiting");
26
- const callbacks = useRef({ onSuccess, onExpire, onChange });
27
- const state = useRef({ status, quote, error });
28
- useEffect(() => {
29
- callbacks.current = { onSuccess, onExpire, onChange };
30
- state.current = { status, quote, error };
31
- });
32
- // Once per status change, not on every poll.
33
- useEffect(() => {
34
- callbacks.current.onChange?.(state.current);
35
- }, [status]);
36
- const notified = useRef(new Set());
37
- useEffect(() => {
38
- if (quote === null) {
39
- return;
40
- }
41
- if (status === "credited") {
42
- const key = `${quote.id}:success`;
43
- if (!notified.current.has(key)) {
44
- notified.current.add(key);
45
- callbacks.current.onSuccess?.(quote);
46
- }
47
- }
48
- else if (status === "expired" || status === "canceled") {
49
- const key = `${quote.id}:expire`;
50
- if (!notified.current.has(key)) {
51
- notified.current.add(key);
52
- callbacks.current.onExpire?.(quote);
53
- }
54
- }
55
- }, [status, quote]);
56
- return (_jsxs("div", { className: className === undefined ? "pp-root" : `pp-root ${className}`, "data-theme": appearance?.theme ?? "light", children: [quote !== null && (_jsxs(_Fragment, { children: [_jsxs("p", { className: "pp-amount", children: [formatTokenAmount(quote), " ", quote.asset.toUpperCase()] }), _jsxs("p", { className: "pp-subtitle", children: [formatAmount(quote), " top-up \u00B7 ", networkName(quote.chain_id), !quote.livemode && _jsx("span", { className: "pp-badge", children: " \u00B7 Test mode" })] })] })), _jsx(StatusLine, { status: status, quote: quote, now: now, error: error }), txHash !== null && quote !== null && _jsx(Transaction, { hash: txHash, chainId: quote.chain_id }), status === "waiting" && quote !== null && (_jsx(PaymentOptions, { quote: quote, buttonText: buttonText, walletClient: walletClient, now: now, onSent: (hash) => {
57
- setTxHash(hash);
58
- refresh();
59
- }, onWalletError: onWalletError }))] }));
60
- }
61
- function StatusLine({ status, quote, now, error, }) {
62
- const tone = status === "credited"
63
- ? "success"
64
- : ["rejected", "reversed", "expired", "canceled", "error"].includes(status)
65
- ? "danger"
66
- : "neutral";
67
- return (_jsxs("div", { className: "pp-status", "data-tone": tone, children: [_jsxs("span", { role: "status", "aria-live": "polite", children: [statusMessage(status, quote, error?.code), error !== null && status !== "error" ? " (reconnecting…)" : ""] }), status === "waiting" && quote !== null && (_jsx("span", { className: "pp-countdown", "aria-label": "Time left to pay", children: formatCountdown(quote.expires_at, now) }))] }));
68
- }
69
- function statusMessage(status, quote, code) {
70
- switch (status) {
71
- case "loading":
72
- return "Loading payment details…";
73
- case "waiting":
74
- return "Waiting for your payment";
75
- case "seen":
76
- return seenMessage(quote);
77
- case "confirming":
78
- return "Payment confirmed on chain, crediting…";
79
- case "credited":
80
- return creditedMessage(quote);
81
- case "rejected":
82
- return "This payment cannot be credited. Contact support with your transaction.";
83
- case "reversed":
84
- return "This payment was reversed: its transaction is no longer on the blockchain, so it did not happen and its credit was taken back. Check your wallet, then start a new top-up.";
85
- case "expired":
86
- return "This quote has expired. Do not send funds to this address; start a new top-up.";
87
- case "canceled":
88
- return "This quote was canceled. Do not send funds to this address.";
89
- case "error":
90
- return code === "address_mismatch"
91
- ? "This payment address could not be verified. Do not send funds; contact support."
92
- : "This payment link is not valid. Start a new top-up.";
93
- }
94
- }
95
- function seenMessage(quote) {
96
- if (quote === null) {
97
- return "Payment received, crediting once it is confirmed";
98
- }
99
- const wait = formatWait(quote.typical_credit_seconds);
100
- return quote.confirmations === null
101
- ? `Payment received, crediting in ${wait}`
102
- : `Payment received, ${quote.confirmations} confirmation${quote.confirmations === 1 ? "" : "s"}. Crediting in ${wait}`;
103
- }
104
- /** What was credited and, when the payment was valued at the market price, the quote it missed. */
105
- function creditedMessage(quote) {
106
- if (quote?.amount_credited == null) {
107
- return "Payment credited";
108
- }
109
- const credited = formatMinorAmount(quote, quote.amount_credited);
110
- if (quote.amount_credited < quote.amount) {
111
- return `Payment credited: ${credited} of ${formatAmount(quote)}`;
112
- }
113
- if (quote.amount_credited > quote.amount) {
114
- return `Payment credited: ${credited}, more than the ${formatAmount(quote)} quoted`;
115
- }
116
- return `Payment credited: ${credited}`;
117
- }
118
- function Transaction({ hash, chainId }) {
119
- const url = transactionUrl(chainId, hash);
120
- return (_jsxs("p", { className: "pp-tx", children: ["Transaction sent:", " ", url === undefined ? (_jsx("span", { className: "pp-value", children: hash })) : (_jsx("a", { className: "pp-value", href: url, target: "_blank", rel: "noreferrer", children: hash }))] }));
121
- }
122
- function PaymentOptions({ quote, now, buttonText, walletClient, onSent, onWalletError, }) {
123
- const [method, setMethod] = useState("wallet");
124
- const id = useId();
125
- const tabs = useRef([]);
126
- const amount = `${formatTokenAmount(quote)} ${quote.asset.toUpperCase()}`;
127
- const onKeyDown = (event) => {
128
- const index = METHODS.findIndex((m) => m.id === method);
129
- const next = event.key === "ArrowRight"
130
- ? (index + 1) % METHODS.length
131
- : event.key === "ArrowLeft"
132
- ? (index - 1 + METHODS.length) % METHODS.length
133
- : event.key === "Home"
134
- ? 0
135
- : event.key === "End"
136
- ? METHODS.length - 1
137
- : null;
138
- const target = next === null ? undefined : METHODS[next];
139
- if (next !== null && target !== undefined) {
140
- event.preventDefault();
141
- setMethod(target.id);
142
- tabs.current[next]?.focus();
143
- }
144
- };
145
- return (_jsxs(_Fragment, { children: [_jsxs("p", { className: "pp-notice", children: ["Send ", _jsxs("strong", { children: ["exactly ", amount] }), " on ", networkName(quote.chain_id), " in one transfer before the timer ends. A different amount, or a payment after expiry, is credited at the market price instead of this quote. Exchanges may deduct a withdrawal fee, so the amount that arrives must be exact."] }), _jsx("div", { className: "pp-tabs", role: "tablist", "aria-label": "Payment method", onKeyDown: onKeyDown, children: METHODS.map((m, index) => (_jsx("button", { ref: (element) => {
146
- tabs.current[index] = element;
147
- }, type: "button", role: "tab", className: "pp-tab", id: `${id}-tab-${m.id}`, "aria-selected": method === m.id, "aria-controls": `${id}-panel-${m.id}`, tabIndex: method === m.id ? 0 : -1, onClick: () => setMethod(m.id), children: m.label }, m.id))) }), _jsxs("div", { role: "tabpanel", id: `${id}-panel-${method}`, "aria-labelledby": `${id}-tab-${method}`, tabIndex: 0, children: [method === "wallet" && (_jsx(WalletPanel, { quote: quote, buttonText: buttonText, walletClient: walletClient, onSent: onSent, onWalletError: onWalletError })), method === "qr" && (_jsxs("div", { className: "pp-qr-panel", children: [_jsx(QrCode, { value: quote.payment_uri, label: `Payment request for ${amount}` }), _jsxs("p", { className: "pp-message", children: ["Scan with a wallet app that reads payment links, and check that it shows ", amount, " on", " ", networkName(quote.chain_id), " before you confirm."] })] })), method === "manual" && _jsx(ManualPanel, { quote: quote, now: now })] })] }));
148
- }
149
- function WalletPanel({ quote, buttonText, walletClient, onSent, onWalletError, }) {
150
- const [discovered, setDiscovered] = useState([]);
151
- const [step, setStep] = useState({ kind: "idle" });
152
- useEffect(() => (walletClient === undefined ? watchWallets(setDiscovered) : undefined), [walletClient]);
153
- const wallets = walletClient === undefined
154
- ? discovered.map(({ info: { uuid, name, icon }, provider }) => ({ id: uuid, name, icon, wallet: provider }))
155
- : [{ id: "client", name: "your wallet", icon: "", wallet: walletClient }];
156
- const pay = async ({ name, wallet }) => {
157
- setStep({ kind: "pending", wallet: name });
158
- try {
159
- onSent(await payWithWallet(wallet, quote));
160
- setStep({ kind: "idle" });
161
- }
162
- catch (error) {
163
- setStep({
164
- kind: "failed",
165
- message: error instanceof WalletError ? error.message : "The payment could not be sent",
166
- });
167
- if (error instanceof WalletError) {
168
- onWalletError?.(error, wallet);
169
- }
170
- }
171
- };
172
- if (wallets.length === 0) {
173
- return (_jsx("p", { className: "pp-message", children: "No browser wallet found. Scan the QR code with a mobile wallet, or send the payment manually." }));
174
- }
175
- return (_jsxs("div", { className: "pp-wallets", children: [wallets.map((choice) => (_jsxs("button", { type: "button", className: "pp-button", disabled: step.kind === "pending", onClick: () => void pay(choice), "aria-label": walletClient === undefined ? `${buttonText} (${choice.name})` : buttonText, children: [choice.icon !== "" && _jsx("img", { src: choice.icon, alt: "" }), _jsx("span", { children: buttonText }), walletClient === undefined && _jsx("span", { className: "pp-wallet-name", children: choice.name })] }, choice.id))), _jsxs("p", { className: "pp-message", "data-tone": step.kind === "failed" ? "danger" : undefined, "aria-live": "polite", children: [step.kind === "pending" && `Confirm the payment in ${step.wallet}…`, step.kind === "failed" && step.message] })] }));
176
- }
177
- function ManualPanel({ quote, now }) {
178
- const token = quoteTransfer(quote).token;
179
- return (_jsxs("dl", { className: "pp-fields", children: [_jsx(Field, { label: "Network", value: `${networkName(quote.chain_id)} (chain ID ${quote.chain_id})` }), _jsx(Field, { label: `Token (${quote.asset.toUpperCase()}) contract`, value: token, copy: true }), _jsx(Field, { label: "Send to address", value: quote.address, copy: true }), _jsx(Field, { label: "Exact amount", value: formatTokenAmount(quote), copy: tokenAmount(quote) }), _jsx(Field, { label: "Time left", value: formatCountdown(quote.expires_at, now) })] }));
180
- }
181
- /** The current time in milliseconds, updated every second while `active`. */
182
- function useNow(active) {
183
- const [now, setNow] = useState(() => Date.now());
184
- useEffect(() => {
185
- if (!active) {
186
- return;
187
- }
188
- const timer = setInterval(() => setNow(Date.now()), 1000);
189
- return () => clearInterval(timer);
190
- }, [active]);
191
- return now;
192
- }
193
- //# sourceMappingURL=Checkout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Checkout.js","sourceRoot":"","sources":["../../src/react/Checkout.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAsB,MAAM,OAAO,CAAC;AAG/E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EACL,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,WAAW,GACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,E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CAAC,QAAQ,GAAG,GAAI,EAC/F,KAAC,KAAK,IAAC,KAAK,EAAE,UAAU,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,SAAG,EACpF,KAAC,KAAK,IAAC,KAAK,EAAC,iBAAiB,EAAC,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,SAAG,EAC5D,KAAC,KAAK,IAAC,KAAK,EAAC,cAAc,EAAC,KAAK,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,GAAI,EACzF,KAAC,KAAK,IAAC,KAAK,EAAC,WAAW,EAAC,KAAK,EAAE,eAAe,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,GAAI,IACvE,CACN,CAAC;AACJ,CAAC;AAED,6EAA6E;AAC7E,SAAS,MAAM,CAAC,MAAe;IAC7B,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IACjD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;QACD,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QAC1D,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IACb,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,32 +0,0 @@
1
- import { type DepositAddressDetails } from "../payment.js";
2
- import type { Appearance } from "./appearance.js";
3
- export interface DepositAddressProps {
4
- /** `address` and `networks` from your backend's `POST /v1/deposit_addresses`. */
5
- depositAddress: DepositAddressDetails;
6
- /** The network shown first; the first of `networks` by default. */
7
- chainId?: number;
8
- /** The token shown first, for example `pha`; the network's first token by default. */
9
- asset?: string;
10
- /**
11
- * The `client_secret` of the same response. With `apiBase`, the component follows the
12
- * address's payments and shows each one within about a block of arriving: received with its
13
- * confirmations, then credited, and states each network's typical credit time. Display only;
14
- * credit from your `deposit.credited` webhook.
15
- */
16
- clientSecret?: string;
17
- /** The service origin, for example `https://pay.example.com`; needed with `clientSecret`. */
18
- apiBase?: string;
19
- /** Milliseconds between payment reads; default 3000. */
20
- pollInterval?: number;
21
- appearance?: Appearance;
22
- className?: string;
23
- }
24
- /**
25
- * A customer's persistent deposit address: one address for every supported token on every
26
- * supported network. The payer picks a network and a token; the component shows a QR code of that
27
- * EIP-681 transfer request and the address and token contract to copy. Any amount of a supported
28
- * token sent is credited at the market rate when it arrives; follow it from your backend's
29
- * `deposit.credited` webhook.
30
- */
31
- export declare function DepositAddress({ depositAddress, chainId, asset, clientSecret, apiBase, pollInterval, appearance, className, }: DepositAddressProps): import("react").JSX.Element;
32
- //# sourceMappingURL=DepositAddress.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DepositAddress.d.ts","sourceRoot":"","sources":["../../src/react/DepositAddress.tsx"],"names":[],"mappings":"AAYA,OAAO,EAA0B,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIlD,MAAM,WAAW,mBAAmB;IAClC,iFAAiF;IACjF,cAAc,EAAE,qBAAqB,CAAC;IACtC,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sFAAsF;IACtF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6FAA6F;IAC7F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,EAC7B,cAAc,EACd,OAAO,EACP,KAAK,EACL,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,GACV,EAAE,mBAAmB,+BAsFrB"}
@@ -1,131 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEffect, useId, useState } from "react";
4
- import { formatUnits } from "viem";
5
- import { networkName } from "../chains.js";
6
- import { retrieveDepositAddress, } from "../deposit-address.js";
7
- import { CheckoutError, pollDelay } from "../checkout.js";
8
- import { formatWait } from "../format.js";
9
- import { depositAddressTransfer } from "../payment.js";
10
- import { Field } from "./Field.js";
11
- import { QrCode } from "./QrCode.js";
12
- /**
13
- * A customer's persistent deposit address: one address for every supported token on every
14
- * supported network. The payer picks a network and a token; the component shows a QR code of that
15
- * EIP-681 transfer request and the address and token contract to copy. Any amount of a supported
16
- * token sent is credited at the market rate when it arrives; follow it from your backend's
17
- * `deposit.credited` webhook.
18
- */
19
- export function DepositAddress({ depositAddress, chainId, asset, clientSecret, apiBase, pollInterval, appearance, className, }) {
20
- const { networks } = depositAddress;
21
- const id = useId();
22
- const view = useClientView(clientSecret, apiBase, pollInterval ?? 3000);
23
- const payments = view?.payments ?? [];
24
- const [selectedChain, setSelectedChain] = useState(chainId ?? networks[0]?.chain_id);
25
- const [selectedAsset, setSelectedAsset] = useState(asset);
26
- const network = networks.find((candidate) => candidate.chain_id === selectedChain) ?? networks[0];
27
- if (network === undefined) {
28
- throw new TypeError("the deposit address has no network");
29
- }
30
- const token = network.assets.find((candidate) => candidate.asset === selectedAsset) ?? network.assets[0];
31
- if (token === undefined) {
32
- throw new TypeError(`the deposit address takes no token on chain ${network.chain_id}`);
33
- }
34
- const { token: contract, to } = depositAddressTransfer(network, token);
35
- const symbol = token.asset.toUpperCase();
36
- const name = networkName(network.chain_id);
37
- const tokens = [...new Set(networks.flatMap((each) => each.assets.map((a) => a.asset.toUpperCase())))];
38
- return (_jsxs("div", { className: className === undefined ? "pp-root" : `pp-root ${className}`, "data-theme": appearance?.theme ?? "light", children: [_jsx("p", { className: "pp-subtitle", children: depositAddress.address === null
39
- ? "Your deposit address for every supported token; it differs on some networks"
40
- : "One address for all supported tokens and networks" }), networks.length > 1 && (_jsxs("fieldset", { className: "pp-choices", children: [_jsx("legend", { children: "Network" }), networks.map((each) => (_jsxs("label", { children: [_jsx("input", { type: "radio", name: `${id}-network`, checked: each.chain_id === network.chain_id, onChange: () => setSelectedChain(each.chain_id) }), networkName(each.chain_id)] }, each.chain_id)))] })), network.assets.length > 1 && (_jsxs("fieldset", { className: "pp-choices", children: [_jsx("legend", { children: "Token" }), network.assets.map((each) => (_jsxs("label", { children: [_jsx("input", { type: "radio", name: `${id}-token`, checked: each.asset === token.asset, onChange: () => setSelectedAsset(each.asset) }), each.asset.toUpperCase()] }, each.asset)))] })), _jsx("div", { className: "pp-qr-panel", children: _jsx(QrCode, { value: token.payment_uri, label: `Deposit address for ${symbol} on ${name}` }) }), _jsxs("dl", { className: "pp-fields", children: [_jsx(Field, { label: "Network", value: `${name} (chain ID ${network.chain_id})` }), _jsx(Field, { label: `Token (${symbol}) contract`, value: contract, copy: true }), _jsx(Field, { label: "Deposit address", value: to, copy: true })] }), payments.length > 0 && (_jsx("ul", { className: "pp-payments", "aria-live": "polite", "aria-label": "Payments", children: payments.map((payment) => (_jsx("li", { children: paymentMessage(payment) }, `${payment.chain_id}:${payment.tx_hash}:${payment.created}`))) })), _jsxs("p", { className: "pp-message", children: ["Send only ", tokens.join(", "), " on ", networks.map((each) => networkName(each.chain_id)).join(", "), ". ", creditMessage(networks.map((each) => each.chain_id), view), " Other tokens and networks are not credited. You can reuse this address."] })] }));
41
- }
42
- /** The address's public view, read every `interval` while mounted; `null` without a secret. */
43
- function useClientView(clientSecret, apiBase, interval) {
44
- const key = clientSecret === undefined || apiBase === undefined ? "" : `${apiBase} ${clientSecret}`;
45
- const [current, setCurrent] = useState({
46
- key: "",
47
- view: null,
48
- });
49
- useEffect(() => {
50
- if (clientSecret === undefined || apiBase === undefined) {
51
- return;
52
- }
53
- const controller = new AbortController();
54
- let stopped = false;
55
- let timer;
56
- let failures = 0;
57
- const load = async () => {
58
- let failure = null;
59
- try {
60
- const view = await retrieveDepositAddress({ clientSecret, apiBase, signal: controller.signal });
61
- failures = 0;
62
- if (!stopped) {
63
- setCurrent({ key, view });
64
- }
65
- }
66
- catch (error) {
67
- failures += 1;
68
- // A secret that is not valid will not become valid: stop, keep showing the address.
69
- if (error instanceof CheckoutError && error.code === "invalid_client_secret") {
70
- return;
71
- }
72
- failure = error instanceof CheckoutError ? error : null;
73
- }
74
- if (!stopped) {
75
- timer = setTimeout(() => void load(), pollDelay(interval, failures, failure));
76
- }
77
- };
78
- void load();
79
- return () => {
80
- stopped = true;
81
- controller.abort();
82
- clearTimeout(timer);
83
- };
84
- }, [key, clientSecret, apiBase, interval]);
85
- // Another address starts without the previous one's view.
86
- return current.key === key && key !== "" ? current.view : null;
87
- }
88
- /**
89
- * When a payment on each of `chainIds` is credited, from `view`'s typical credit times, for
90
- * example "usually in about 30 seconds on Ethereum and about 7 seconds on Base". Before the view
91
- * is loaded it names no time.
92
- */
93
- function creditMessage(chainIds, view) {
94
- const names = new Map();
95
- for (const network of view?.networks ?? []) {
96
- if (chainIds.includes(network.chain_id)) {
97
- const seconds = network.typical_credit_seconds;
98
- names.set(seconds, [...(names.get(seconds) ?? []), networkName(network.chain_id)]);
99
- }
100
- }
101
- if (names.size === 0) {
102
- return "Any amount is credited at the market rate once it is confirmed on its network.";
103
- }
104
- const list = new Intl.ListFormat("en", { type: "conjunction" });
105
- const [only, ...others] = names.keys();
106
- const usually = only !== undefined && others.length === 0
107
- ? formatWait(only)
108
- : list.format([...names].map(([seconds, on]) => `${formatWait(seconds)} on ${list.format(on)}`));
109
- return `Any amount is credited at the market rate when it arrives, usually in ${usually}.`;
110
- }
111
- function paymentMessage(payment) {
112
- const amount = payment.asset === null || payment.decimals === null
113
- ? "A payment"
114
- : `${formatUnits(BigInt(payment.amount_atomic), payment.decimals)} ${payment.asset.toUpperCase()}`;
115
- const on = `on ${networkName(payment.chain_id)}`;
116
- switch (payment.status) {
117
- case "seen":
118
- return payment.confirmations === null
119
- ? `${amount} received ${on}, crediting shortly`
120
- : `${amount} received ${on}, ${payment.confirmations} confirmation${payment.confirmations === 1 ? "" : "s"}`;
121
- case "confirming":
122
- return `${amount} confirmed ${on}, crediting…`;
123
- case "credited":
124
- return `${amount} ${on} credited`;
125
- case "rejected":
126
- return `${amount} ${on} cannot be credited. Contact support with your transaction.`;
127
- case "reversed":
128
- return `${amount} ${on} was reversed: its transaction is no longer on the blockchain.`;
129
- }
130
- }
131
- //# sourceMappingURL=DepositAddress.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DepositAddress.js","sourceRoot":"","sources":["../../src/react/DepositAddress.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACL,sBAAsB,GAGvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAA8B,MAAM,eAAe,CAAC;AAEnF,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAwBrC;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,cAAc,EACd,OAAO,EACP,KAAK,EACL,YAAY,EACZ,OAAO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AAQ,OAAO,CAAC,MAAM,EAAE,CAAC;QACvB,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,aAAa,KAAK,IAAI;gBACnC,CAAC,CAAC,GAAG,MAAM,aAAa,EAAE,qBAAqB;gBAC/C,CAAC,CAAC,GAAG,MAAM,aAAa,EAAE,KAAK,OAAO,CAAC,aAAa,gBAAgB,OAAO,CAAC,aAAa,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QACjH,KAAK,YAAY;YACf,OAAO,GAAG,MAAM,cAAc,EAAE,cAAc,CAAC;QACjD,KAAK,UAAU;YACb,OAAO,GAAG,MAAM,IAAI,EAAE,WAAW,CAAC;QACpC,KAAK,UAAU;YACb,OAAO,GAAG,MAAM,IAAI,EAAE,6DAA6D,CAAC;QACtF,KAAK,UAAU;YACb,OAAO,GAAG,MAAM,IAAI,EAAE,gEAAgE,CAAC;IAC3F,CAAC;AACH,CAAC"}
@@ -1,7 +0,0 @@
1
- /** `copy` adds a copy button, copying `value`, or the given string when it differs from it. */
2
- export declare function Field({ label, value, copy, }: {
3
- label: string;
4
- value: string;
5
- copy?: boolean | string;
6
- }): import("react").JSX.Element;
7
- //# sourceMappingURL=Field.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/react/Field.tsx"],"names":[],"mappings":"AAEA,+FAA+F;AAC/F,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,KAAK,EACL,IAAY,GACb,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACzB,+BAYA"}
@@ -1,21 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useState } from "react";
3
- /** `copy` adds a copy button, copying `value`, or the given string when it differs from it. */
4
- export function Field({ label, value, copy = false, }) {
5
- return (_jsxs("div", { className: "pp-field", children: [_jsx("dt", { children: label }), _jsxs("dd", { children: [_jsx("span", { className: copy === false ? undefined : "pp-value", children: value }), copy !== false && (_jsx(CopyButton, { value: typeof copy === "string" ? copy : value, label: label }))] })] }));
6
- }
7
- function CopyButton({ value, label }) {
8
- const [copied, setCopied] = useState(null);
9
- useEffect(() => {
10
- if (copied === null) {
11
- return;
12
- }
13
- const timer = setTimeout(() => setCopied(null), 2000);
14
- return () => clearTimeout(timer);
15
- }, [copied]);
16
- const onClick = () => {
17
- navigator.clipboard.writeText(value).then(() => setCopied(true), () => setCopied(false));
18
- };
19
- return (_jsx("button", { type: "button", className: "pp-copy", onClick: onClick, "aria-label": `Copy ${label}`, children: _jsx("span", { "aria-live": "polite", children: copied === null ? "Copy" : copied ? "Copied" : "Copy failed" }) }));
20
- }
21
- //# sourceMappingURL=Field.js.map