@rio-pay/sdk 0.0.1-alpha.1 → 0.0.1-alpha.3
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 +10 -9
- package/dist/checkout/react.d.ts +2 -2
- package/dist/checkout/react.js +5 -5
- package/dist/client.d.ts +2 -0
- package/dist/client.js +1 -0
- package/dist/components/payments-checkout.d.ts +8 -8
- package/dist/components/payments-modal.d.ts +8 -8
- package/dist/index.d.ts +1 -1
- package/dist/lib/payments-options.d.ts +3 -3
- package/dist/lib/payments-pay.d.ts +2 -2
- package/dist/lib/payments.d.ts +9 -9
- package/dist/lib/rio-client.d.ts +73 -0
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -8,9 +8,10 @@ The SDK for Rio USDC payments: the checkout widget, shared types and the utiliti
|
|
|
8
8
|
|
|
9
9
|
| Import | What it is | Runs in |
|
|
10
10
|
|---|---|---|
|
|
11
|
-
| `@rio-pay/sdk` | Types only: `CreatedCharge`, `ChargeCreateResult`, `ChargeStatus`, `Confirmation`, `
|
|
11
|
+
| `@rio-pay/sdk` | Types only: `CreatedCharge`, `ChargeCreateResult`, `ChargeStatus`, `Confirmation`, `CheckoutCopy`, `PlatformChargeStatus`, `PostCreateChargeOptions`, `WebhookEvent`, `WebhookEventType`. No runtime code. | anywhere |
|
|
12
|
+
| `@rio-pay/sdk/client` | `createRioClient({ apiKey, serviceUrl })` (the alpha has no default API URL yet: pass yours, or set `RIO_SERVICE_URL`): `charges.create` returns the charge as the widget takes it, `charges.get` the status its poll takes; failures are `RioError`. Server-side only. | Node 18+, Bun, edge runtimes |
|
|
12
13
|
| `@rio-pay/sdk/server` | `verifyWebhook`, `signWebhook` (for your own tests), `SIGNATURE_HEADER`, `DEFAULT_TOLERANCE_SECONDS`. Web Crypto only, no React. | Node 18+, Bun, edge runtimes |
|
|
13
|
-
| `@rio-pay/sdk/checkout/react` | The widget: `
|
|
14
|
+
| `@rio-pay/sdk/checkout/react` | The widget: `CheckoutWidget` (a client module, `"use client"`), the optional `postCreateCharge` fetch adapter, and the prop types (`CheckoutWidgetProps`, `PostCreateChargeOptions`, `CheckoutCopy`, `CheckoutState`, `CheckoutError`). React is an optional peer dependency (`^18.2 \|\| ^19`); you only need it for this entry. | browsers, React |
|
|
14
15
|
|
|
15
16
|
## Verify a webhook
|
|
16
17
|
|
|
@@ -38,22 +39,22 @@ export async function POST(req: Request) {
|
|
|
38
39
|
## Checkout widget
|
|
39
40
|
|
|
40
41
|
```tsx
|
|
41
|
-
import {
|
|
42
|
+
import { CheckoutWidget, postCreateCharge } from "@rio-pay/sdk/checkout/react";
|
|
42
43
|
|
|
43
|
-
<
|
|
44
|
+
<CheckoutWidget
|
|
44
45
|
orderId={order.id}
|
|
45
46
|
merchantName="Moon Lantern"
|
|
46
47
|
// Calls YOUR route. The route decides the amount and creates the charge with your API key.
|
|
47
48
|
createCharge={() => postCreateCharge("/api/checkout", { orderId: order.id })}
|
|
48
49
|
// Your route that returns the authoritative status for a charge (a PlatformChargeStatus), or null to turn polling off.
|
|
49
|
-
statusUrl={(chargeId) => `/api/checkout/status?chargeId=${encodeURIComponent(chargeId)}`}
|
|
50
|
+
statusUrl={(chargeId) => `/api/checkout/status?chargeId=${encodeURIComponent(chargeId)}&orderId=${encodeURIComponent(order.id)}`}
|
|
50
51
|
onPaid={(status) => { /* status.confirmation is "provisional", then "final" */ }}
|
|
51
52
|
/>
|
|
52
53
|
```
|
|
53
54
|
|
|
54
55
|
It shows a "Pay with USDC" button, opens a modal, connects the buyer's wallet (EVM and Solana) and walks them through paying a charge. It has no styles to import (the CSS ships inside the component).
|
|
55
56
|
|
|
56
|
-
`createCharge` and `statusUrl` are required: the widget has no default routes. The `statusUrl` route may return the service charge from `GET /v1/charges/:id` as is (`id`, `status`, `confirmed`, `confirmation`, `collected_amount`) or the same fields in camelCase (`chargeId`, `collectedAmount`).
|
|
57
|
+
`createCharge` and `statusUrl` are required: the widget has no default routes. The `statusUrl` route may return the service charge from `GET /v1/charges/:id` as is (`id`, `status`, `confirmed`, `confirmation`, `collected_amount`) or the same fields in camelCase (`chargeId`, `collectedAmount`). **Scope the status route to the buyer's own order.** It reads the charge with your API key, so it must not answer for a charge that is not theirs: send the order id along (as above), have the create route record which charge belongs to the order, and in the status route load the signed-in buyer's order and return 404 unless its charge id matches, before calling the client or `fetch`.
|
|
57
58
|
|
|
58
59
|
### The create route and `postCreateCharge`
|
|
59
60
|
|
|
@@ -85,7 +86,7 @@ You can also write your own `createCharge` that resolves to a `ChargeCreateResul
|
|
|
85
86
|
|
|
86
87
|
The widget never sends an amount and never holds your API key. Your server route calls `POST /v1/charges` (see `internal/docs/API.md`) and returns the charge as JSON with `chargeId`, `clientSecret`, `serviceUrl`, `amount`, `chain`, `chargeAddress`, `status`, `confirmed`, `confirmation` and `expiresAt`. The client secret stays in component state only. `serviceUrl` must be `https` (plain `http` is accepted only for `localhost`, `127.0.0.1` and `[::1]`), because the secret is sent there. After that the browser talks to the service directly, with per-charge CORS.
|
|
87
88
|
|
|
88
|
-
Props worth knowing: `presentation` (`"modal"` or `"inline"`), `appearance` (`"auto" | "light" | "dark"`), `copy` (a `Partial<
|
|
89
|
+
Props worth knowing: `presentation` (`"modal"` or `"inline"`), `appearance` (`"auto" | "light" | "dark"`), `copy` (a `Partial<CheckoutCopy>` that overrides any string), `manualPayment`, `defaultOpen`, `successSlot`, `onStatusChange`, `onError`. Theme with the CSS variables `--sc-accent`, `--sc-radius`, `--sc-bg`, `--sc-fg`, `--sc-muted`, `--sc-border`, `--sc-success`, `--sc-danger`.
|
|
89
90
|
|
|
90
91
|
## Design rules
|
|
91
92
|
|
|
@@ -107,14 +108,14 @@ bun install
|
|
|
107
108
|
bun run dev # dev host on :3030: a stand-in storefront that mounts the widget from src (hot reload); needs the service, so prefer `bun dev` at the repo root
|
|
108
109
|
bun run typecheck
|
|
109
110
|
bun test # unit tests, server-rendered component tests, and happy-dom interaction tests
|
|
110
|
-
bun run build # dist/: one ESM file per entry (index, server, checkout/react with the "use client" banner and react external) + .d.ts
|
|
111
|
+
bun run build # dist/: one ESM file per entry (index, server, client, checkout/react with the "use client" banner and react external) + .d.ts
|
|
111
112
|
bun run test:dist # checks the built package: every exports path exists and each subpath imports (needs a build first)
|
|
112
113
|
bun pm pack --dry-run # exactly dist/, README.md and package.json ship
|
|
113
114
|
```
|
|
114
115
|
|
|
115
116
|
`dev/` is the dev host (page, server routes and the pure logic in `dev/host.ts`); it is not part of the package (`files` ships `dist` only) and is typechecked with the rest. `bun run dev` reads `PAYMENTS_SERVICE_URL`, `PAYMENTS_API_KEY`, `PAYMENTS_MERCHANT_ID`, `PAYMENTS_WEBHOOK_SECRET` and `PORT`; `bun dev` at the repo root supplies them.
|
|
116
117
|
|
|
117
|
-
Layout: `src/index.ts` (types), `src/server.ts` (webhook utilities) and `src/checkout/react.ts` (the widget) are the
|
|
118
|
+
Layout: `src/index.ts` (types), `src/server.ts` (webhook utilities), `src/client.ts` (the API client) and `src/checkout/react.ts` (the widget) are the four entries; `src/entries.test.ts` enforces that none but the last reaches React or a component, that the server entry imports no `node:` module, and that no entry exports the copy table or a parser (`postCreateCharge` is exported from the client entry only). Everything else is internal. `src/lib/` holds the framework-free logic (options, pay plans, wallets, Solana, client, webhook signatures); `src/components/` holds the React components.
|
|
118
119
|
|
|
119
120
|
## Releasing
|
|
120
121
|
|
package/dist/checkout/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type {
|
|
1
|
+
export { CheckoutWidget } from "../components/payments-checkout";
|
|
2
|
+
export type { CheckoutWidgetProps, CheckoutCopy, CheckoutState, CheckoutError, } from "../components/payments-checkout";
|
|
3
3
|
export { postCreateCharge } from "../lib/create-charge";
|
|
4
4
|
export type { PostCreateChargeOptions } from "../lib/create-charge";
|
|
5
5
|
export type { ChargeCreateResult, CreatedCharge, PlatformChargeStatus, Confirmation } from "../lib/payments";
|
package/dist/checkout/react.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{useCallback as W,useEffect as I,useId as Nr,useMemo as xt,useReducer as Rr,useRef as
|
|
3
|
-
`)[0].slice(0,240);function
|
|
2
|
+
import{useCallback as W,useEffect as I,useId as Nr,useMemo as xt,useReducer as Rr,useRef as P,useState as N}from"react";import{useEffect as Z,useLayoutEffect as Eo,useRef as ae,useState as me}from"react";function ho(e){let t=typeof e==="bigint"?e:BigInt(e),n=t<0n,a=n?-t:t,r=a/1000000n,o=(a%1000000n).toString().padStart(6,"0").replace(/0+$/,"");if(o.length<2)o=o.padEnd(2,"0");let s=r.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");return`${n?"-":""}${s}.${o}`}function Zt(e){return e.length>12?`${e.slice(0,6)}…${e.slice(-4)}`:e}function ya(e){return`0x${e.toString(16)}`}function ba(e){return`0x${BigInt(e||"0").toString(16)}`}var yo=[["name","string"],["version","string"],["chainId","uint256"],["verifyingContract","address"],["salt","bytes32"]];function wa(e){let t={...e.domain};if(typeof t.chainId==="string")t.chainId=Number(t.chainId);let n=yo.filter(([a])=>t[a]!==void 0).map(([a,r])=>({name:a,type:r}));return JSON.stringify({domain:t,types:{...e.types,EIP712Domain:e.types.EIP712Domain??n},primaryType:e.primaryType,message:e.message})}function va(e,t,n){let a=e.message;return{from:typeof a.from==="string"?a.from:t,value:String(a.value),validAfter:String(a.validAfter),validBefore:String(a.validBefore),nonce:String(a.nonce),signature:n}}function Ue(e){return!!e&&typeof e==="object"}var bo=(e)=>e==="pending"||e==="provisional"||e==="final";function en(e){return{confirmed:e.confirmed===!0,confirmation:bo(e.confirmation)?e.confirmation:"pending"}}var wo=["created","payment_pending","funded","settled","underpaid","expired"];function xa(e){if(!Ue(e)||!wo.includes(e.status))return null;return{status:e.status,...en(e),funded_amount:typeof e.funded_amount==="string"?e.funded_amount:null}}var vo=["localhost","127.0.0.1","[::1]"];function xo(e){try{let t=new URL(e);if(t.username||t.password)return null;if(t.protocol!=="https:"&&!(t.protocol==="http:"&&vo.includes(t.hostname)))return null;return e.replace(/\/+$/,"")}catch{return null}}var ko=(e)=>typeof e==="string"?/^[1-9]\d{0,18}$/.test(e)?e:null:typeof e==="number"&&Number.isSafeInteger(e)&&e>0?String(e):null;function ka(e){if(!Ue(e))return null;let t=e.chain,n=ko(e.amount);if(typeof e.chargeId!=="string"||typeof e.clientSecret!=="string"||!e.clientSecret||typeof e.serviceUrl!=="string"||typeof e.chargeAddress!=="string"||n===null||!Ue(t)||typeof t.id!=="number")return null;let a=xo(e.serviceUrl);if(!a)return null;return{chargeId:e.chargeId,clientSecret:e.clientSecret,serviceUrl:a,amount:n,chain:{id:t.id,name:typeof t.name==="string"?t.name:"sei",usdc:typeof t.usdc==="string"?t.usdc:"",add_chain:Ue(t.add_chain)?t.add_chain:null},chargeAddress:e.chargeAddress,status:typeof e.status==="string"?e.status:"created",...en(e),expiresAt:typeof e.expiresAt==="string"?e.expiresAt:null}}function Ca(e){if(!Ue(e))return null;let t=typeof e.chargeId==="string"?e.chargeId:typeof e.id==="string"?e.id:null;if(t===null||typeof e.status!=="string")return null;let{confirmed:n,confirmation:a}=en(e),r=e.collectedAmount??e.collected_amount;return{chargeId:t,orderId:typeof e.orderId==="string"?e.orderId:null,status:e.status,confirmed:n,confirmation:a,collectedAmount:typeof r==="string"||typeof r==="number"?String(r):null,...Array.isArray(e.tags)?{tags:e.tags.filter((o)=>typeof o==="string")}:{}}}function Sa(e,t){return t?t(e):null}function Pa(e,t){if(typeof e!=="string"||!e)return null;try{let n=new URL(t),a=new URL(e,n);if(a.protocol!=="https:"&&a.protocol!=="http:")return null;return a.origin===n.origin?a.toString():null}catch{return null}}var je={trigger:"Pay with USDC",title:"Pay",titleFor:"Pay {merchant}",close:"Close",done:"Done",amountDue:"Amount due",payWith:"Pay with",chooseUsdc:"Choose how to pay",connectWallet:"Connect wallet",connectingWallet:"Connecting…",pay:"Pay {amount}",opening:"Opening your wallet…",confirm:"Confirm in your wallet",confirmTx:"Confirm in your wallet ({n} of {total})",confirming:"Confirming payment…",paid:"Paid",preparing:"Preparing your payment",walletName:"Wallet",balanceLabel:"USDC balance",gasLabel:"Gas",lowGas:"Low gas",notEnough:"Not enough",checking:"Checking balances…",noUsdc:"No USDC found in this wallet.",insufficientAll:"There isn't enough USDC in this wallet for this payment.",checkAgain:"Check again",payAnotherWay:"Pay another way",back:"Back",tryAgain:"Try again",startNew:"Start a new payment",details:"Show details",rejected:"No problem, tap Pay when you're ready.",rejectedConnect:"No problem, tap Connect wallet when you're ready.",rejectedPick:"No problem, pick a wallet when you're ready.",noWallet:"We couldn't find a wallet in this browser. Install one like MetaMask, or pay another way.",noWalletMobile:"We couldn't find a wallet in this browser. Open this page in your wallet app, or pay another way.",noWalletForOption:"That option needs a different wallet than the one in this browser. Pick another option, or pay another way.",openInWalletApp:"Open in your wallet app",wrongNetwork:"Your wallet didn't switch. Approve the switch in your wallet and try again.",insufficient:"You have {balance}, you need {needed}.",noGas:"This wallet needs a little gas to send the payment. Add some and try again.",walletBusy:"Your wallet already has a request waiting. Open it to continue.",txFailed:"That payment didn't go through. Please try again.",network:"We can't reach the payment service. Check your connection and try again.",service:"Something went wrong on our side. Please try again in a moment.",unknown:"Something went wrong. Please try again.",expired:"This payment expired. Start a new one to continue.",createFailed:"Checkout is temporarily unavailable. Please try again.",conflict:"This order changed. Start a new payment to continue.",slow:"This is taking a little longer than usual. You can keep this page open.",received:"Payment confirmed",receivedProvisional:"Payment received",finalizing:"We'll finish confirming in the background. You can leave this page.",receiptLabel:"Receipt",returnToStore:"Back to the store",stagesLabel:"Payment progress",stageWallet:"Confirm in wallet",stageSent:"Payment sent",stageConfirmed:"Payment confirmed",manualIntro:"Send USDC on the network shown to the address below. Make sure {amount} arrives: exchanges deduct their fee.",manualWarning:"Choose {network} as the network when you withdraw or send. Only USDC sent on {network} reaches this payment: anything else sent to this address is lost and can't be recovered.",manualConfirm:"I'll send USDC on {network}",manualWaiting:"This page updates by itself when it arrives.",manualOwnWallet:"Exchange can't send on {network}? Withdraw USDC to your own browser wallet, then connect it and pay here.",copyAddress:"Copy address",copied:"Copied",openInWallet:"Open in wallet app",partial:"We've received {received} so far. {remaining} to go.",confirmNamed:"Confirm in {wallet}",confirmTxNamed:"Confirm in {wallet} ({n} of {total})",openingNamed:"Opening {wallet}…",sending:"Sending payment…",notEnoughUsdc:"Not enough USDC",needsGas:"Needs gas",needsGasReason:"Add a little gas to this wallet to continue.",needsOtherWallet:"Needs a different wallet",couldntCheck:"Couldn't check",balanceUpdated:"Balance updated",walletMenu:"Wallet options",copyWalletAddress:"Copy address",switchWallet:"Switch wallet",disconnect:"Disconnect",chooseWallet:"Choose a wallet",lastUsed:"Last used",closeConfirm:"Your payment is still going through. You can close this and it will keep going.",closeAnyway:"Close",stay:"Stay",pauseBalances:"Pause balance updates",openInPhantom:"Open in Phantom",balanceLabelFor:"{symbol} balance",youPay:"You pay {amount}",youPayChecking:"Checking the price…",youPayUpdating:"Updating the price…",youPayTakes:"Usually takes about {minutes} min",optionUnavailable:"Not available right now",optionUnavailableReason:"This way of paying isn't available right now. Pick another, or try again in a moment.",notEnoughToken:"Not enough {symbol}",priceChanged:"The price just updated. Check the amount and tap Pay again."};function B(e,t={}){return e.replace(/\{(\w+)\}/g,(n,a)=>(a in t)?String(t[a]):n)}function Aa(e){if(!e)return je;let t={...je};for(let n of Object.keys(e)){let a=e[n];if(typeof a==="string")t[n]=a}return t}function we(e){let t=typeof e==="bigint"?e:BigInt(e);return`${t<0n?"-":""}$${ho(t<0n?-t:t)}`}function Ra(e){return e.split(/[-_\s]+/).filter(Boolean).map((t)=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function Ea(e){return`#${e.replace(/^[a-z]+_/i,"").replace(/[^a-z0-9]/gi,"").slice(-8).toUpperCase()}`}var Co=/^0x[0-9a-fA-F]{40}$/;function So(e){return typeof e==="string"&&Co.test(e)}function st(e){try{let t=new URL(e);if(t.protocol!=="https:"&&t.protocol!=="http:")return null;return`https://metamask.app.link/dapp/${t.host}${t.pathname}${t.search}`}catch{return null}}function it(e){try{let t=new URL(e);if(t.protocol!=="https:"&&t.protocol!=="http:")return null;return`https://phantom.com/ul/browse/${encodeURIComponent(t.toString())}?ref=${encodeURIComponent(t.origin)}`}catch{return null}}function tn(e){return/Android|iPhone|iPad|iPod|Mobile/i.test(e)}function nn(e){if(!So(e))throw Error("Invalid address");return`0x70a08231${e.slice(2).toLowerCase().padStart(64,"0")}`}function ze(e){if(typeof e!=="string"||!/^0x[0-9a-fA-F]*$/.test(e))throw Error("Unexpected balance response");return e==="0x"?0n:BigInt(e)}function Na(e,t){let n=BigInt(e)-BigInt(t||"0");return n>0n?n:0n}class ne extends Error{problem;constructor(e){super(e.message);this.problem=e}}var Po=new Set(["amount_mismatch","charge_expired","error","expired","forbidden","invalid_request","network","not_found","rate_limited","recreate_failed","unauthorized"]),fa=(e,t)=>typeof e==="number"&&Number.isInteger(e)&&Math.abs(e)<t;function La(e){let t=[fa(e.status,1000)&&e.status>=0?`status ${e.status}`:null,typeof e.code==="string"&&Po.has(e.code)?`code ${e.code}`:null,fa(e.code,1e5)?`code ${e.code}`:null].filter((n)=>n!==null);return t.length?t.join(", "):void 0}var Ta=(e)=>e.split(`
|
|
3
|
+
`)[0].slice(0,240);function Ao(e){let t=e&&typeof e==="object"?e:{};return Ta(typeof t.message==="string"?t.message:String(e))}function Ia(e,t=je){let n=La({status:e.status,code:e.code}),a=(r,o)=>({kind:r,message:o,...n?{detail:n}:{},...e.error?{cause:Ta(e.error)}:{}});if(/expired/i.test(e.code??"")||e.status===410)return a("expired",t.expired);if(e.status===409)return a("conflict",t.conflict);if(e.status===0||e.status===408)return a("network",t.network);if(e.status===429||e.status>=500)return a("service",t.createFailed);return a("unknown",t.createFailed)}var Ro=/user (rejected|denied|declined|cancell?ed)|rejected the request|request rejected|declined/i;function He(e,t={}){if(e instanceof ne)return e.problem;let n=t.copy??je,a=e&&typeof e==="object"?e:{},r=La({status:a.status,code:a.code}),o=Ao(e),s=(u,g)=>({kind:u,message:g,...r?{detail:r}:{},cause:o}),i=typeof a.message==="string"?a.message:"";if(typeof a.status==="number"){let u=typeof a.code==="string"?a.code:"";if(/expired/i.test(u)||a.status===410)return s("expired",n.expired);if(a.status===409)return s("conflict",n.conflict);if(a.status===0||a.status===408)return s("network",n.network);if(a.status===429||a.status>=500)return s("service",n.service);return s("unknown",n.unknown)}let l=typeof a.code==="number"?a.code:void 0;if(l===4001||a.code==="ACTION_REJECTED"||Ro.test(i)){if(t.step==="switching")return s("wrong_network",n.wrongNetwork);return s("rejected",n.rejected)}if(l===4902||l===-32603&&t.step==="switching")return s("wrong_network",n.wrongNetwork);if(l===-32002)return s("wallet_busy",n.walletBusy);if(e instanceof TypeError||/failed to fetch|networkerror|load failed/i.test(i))return s("network",n.network);if(t.step==="switching")return s("wrong_network",n.wrongNetwork);if(/insufficient funds/i.test(i))return s("no_gas",n.noGas);if(/reverted|transaction failed|failed on chain/i.test(i))return s("tx_failed",n.txFailed);return s("unknown",n.unknown)}function Oa(e){let t=e&&typeof e==="object"?e:{};if(typeof t.status!=="number")return!1;return t.status===410||typeof t.code==="string"&&/expired/i.test(t.code)||t.status===422&&/expired|valid_before|validbefore/i.test(String(t.message??""))}function ct(e){let t=e&&typeof e==="object"?e:{};return t.status===409&&(t.code==="payment_in_flight"||t.code==="authorization_in_flight")}var ma=["idle","connecting","switching","checking","signing","submitting","processing","paid"],an={step:"idle",problem:null};function ha(e){return e!=="idle"&&e!=="paid"&&e!=="processing"}function Ma(e,t){switch(t.type){case"start":return e.step==="idle"?{step:"connecting",problem:null}:e;case"step":return ha(e.step)&&ma.indexOf(t.step)>ma.indexOf(e.step)?{step:t.step,problem:null}:e;case"submitted":return ha(e.step)?{step:"processing",problem:null}:e;case"failed":return e.step==="paid"?e:{step:"idle",problem:t.problem};case"paid":return{step:"paid",problem:null};case"reset":return e.step==="paid"?e:an}}function _a(e){let t=e==="connecting"||e==="switching"||e==="checking"||e==="signing"?0:e==="submitting"?1:e==="processing"?2:e==="paid"?3:-1;return["wallet","sent","confirmed"].map((a,r)=>({key:a,state:r<t?"done":r===t?"active":"pending"}))}function Wa(e,t,n=je,a){switch(e){case"connecting":case"switching":case"checking":return a?B(n.openingNamed,{wallet:a}):n.opening;case"signing":return a?B(n.confirmNamed,{wallet:a}):n.confirm;case"submitting":return n.sending;case"processing":return n.confirming;case"paid":return n.paid;default:return B(n.pay,{amount:t})}}function lt(e,t,n){return B(n?e.confirmTxNamed:e.confirmTx,{n:t.i+1,total:t.total,...n?{wallet:n}:{}})}function Ba(e,t){let n=typeof t==="string"?t.trim().slice(0,60):"";return n?B(e.titleFor,{merchant:n}):e.title}var Da="payments:prefs";function Ua(){try{return typeof window>"u"?null:window.localStorage}catch{return null}}function fe(e=Ua()){try{let t=e?.getItem(Da),n=t?JSON.parse(t):null;if(!n||typeof n!=="object")return{};let{wallet:a}=n;return typeof a==="string"&&a.length<=40?{wallet:a}:{}}catch{return{}}}function rn(e,t=Ua()){try{if(!t)return;t.setItem(Da,JSON.stringify({...fe(t),...e}))}catch{}}var ja=Object.freeze({name:"Rio",poweredBy:"Powered by Rio"}),za="M 13 70 L 13 12 L 40 12 C 59 12 68 22 68 35 C 68 48 58 55 41 55 L 13 55 M 41 55 L 67 70";var Ha=`.sc-root{--scd-bg:#fff;--scd-surface:#f3f5f8;--scd-fg:#0b1220;--scd-muted:#5a6376;--scd-border:#dfe3e9;--scd-line:#8a92a0;--scd-accent:#315cff;--scd-on-accent:#fff;--scd-success:#15803d;--scd-danger:#b42318;--scd-warn:#a15c07;--scd-shadow:0 24px 64px rgba(15,23,42,.22),0 2px 8px rgba(15,23,42,.08);--scd-scrim:rgba(15,23,42,.42)}
|
|
4
4
|
.sc-root[data-appearance="dark"]{--scd-bg:#0b1220;--scd-surface:#141d31;--scd-fg:#f3f5f8;--scd-muted:#a9b3c7;--scd-border:#26314a;--scd-line:#6f7b94;--scd-accent:#7c97ff;--scd-on-accent:#0b1220;--scd-success:#4ade80;--scd-danger:#ff8f84;--scd-warn:#fbbf24;--scd-shadow:0 24px 64px rgba(0,0,0,.6),0 2px 8px rgba(0,0,0,.4);--scd-scrim:rgba(0,0,0,.62)}
|
|
5
|
-
@media (prefers-color-scheme:dark){.sc-root[data-appearance="auto"]{--scd-bg:#0b1220;--scd-surface:#141d31;--scd-fg:#f3f5f8;--scd-muted:#a9b3c7;--scd-border:#26314a;--scd-line:#6f7b94;--scd-accent:#7c97ff;--scd-on-accent:#0b1220;--scd-success:#4ade80;--scd-danger:#ff8f84;--scd-warn:#fbbf24;--scd-shadow:0 24px 64px rgba(0,0,0,.6),0 2px 8px rgba(0,0,0,.4);--scd-scrim:rgba(0,0,0,.62)}}`;import{jsx as c,jsxs as b,Fragment as gt}from"react/jsx-runtime";var
|
|
5
|
+
@media (prefers-color-scheme:dark){.sc-root[data-appearance="auto"]{--scd-bg:#0b1220;--scd-surface:#141d31;--scd-fg:#f3f5f8;--scd-muted:#a9b3c7;--scd-border:#26314a;--scd-line:#6f7b94;--scd-accent:#7c97ff;--scd-on-accent:#0b1220;--scd-success:#4ade80;--scd-danger:#ff8f84;--scd-warn:#fbbf24;--scd-shadow:0 24px 64px rgba(0,0,0,.6),0 2px 8px rgba(0,0,0,.4);--scd-scrim:rgba(0,0,0,.62)}}`;import{jsx as c,jsxs as b,Fragment as gt}from"react/jsx-runtime";var on=`
|
|
6
6
|
${Ha}
|
|
7
7
|
.sc-root{--c-bg:var(--sc-bg,var(--scd-bg));--c-fg:var(--sc-fg,var(--scd-fg));--c-muted:var(--sc-muted,var(--scd-muted));--c-border:var(--sc-border,var(--scd-border));--c-accent:var(--sc-accent,var(--scd-accent));--c-success:var(--sc-success,var(--scd-success));--c-danger:var(--sc-danger,var(--scd-danger));--c-radius:var(--sc-radius,12px);--c-surface:var(--sc-surface,var(--scd-surface));--c-on-accent:var(--sc-on-accent,var(--scd-on-accent));--c-line:var(--sc-line,var(--scd-line));--c-warn:var(--sc-warn,var(--scd-warn));--c-ease:cubic-bezier(.22,1,.36,1);--c-spring:cubic-bezier(.34,1.4,.64,1)}
|
|
8
8
|
.sc-root{box-sizing:border-box;display:block;width:100%;min-width:0;color:var(--c-fg);font-family:inherit;font-size:15px;line-height:1.5;text-align:left;-webkit-text-size-adjust:100%}
|
|
@@ -204,5 +204,5 @@ html:has(.sc-dialog[open]){overflow:hidden}
|
|
|
204
204
|
@keyframes sc-sheet-out{to{transform:translateY(100%)}}
|
|
205
205
|
@media (max-width:360px){.sc-card{padding:16px 16px 12px}.sc-tok sub{max-width:84px}}
|
|
206
206
|
@media (prefers-reduced-motion:reduce){.sc-root *,.sc-root *::before,.sc-root *::after,.sc-dialog,.sc-dialog::backdrop{animation-duration:.001ms!important;animation-delay:0s!important;animation-iteration-count:1!important;transition:none!important}.sc-spin{animation:none!important}.sc-sk{animation:none!important}.sc-check circle,.sc-check path{stroke-dashoffset:0!important}.sc-steps li[data-state="active"] .sc-dot::after{animation:none!important}.sc-hair>i{animation:none!important;transform:scaleX(.5)!important}.sc-deco-cycle{display:flex;gap:14px;justify-content:flex-end}.sc-deco-item{grid-area:auto;opacity:1}.sc-pause{display:none}}
|
|
207
|
-
`,ee=({children:e,size:t=20,className:n})=>c("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",className:n,children:e}),dt=({small:e})=>c(ee,{className:e?"sc-spin sc-spin-s":"sc-spin",children:c("path",{d:"M21 12a9 9 0 1 1-6.2-8.55"})}),$a=()=>c(ee,{size:16,className:"sc-chev",children:c("path",{d:"m6 9 6 6 6-6"})}),Rs=()=>c(ee,{size:16,children:c("path",{d:"m15 18-6-6 6-6"})}),$e=({size:e=16})=>c(ee,{size:e,children:c("path",{d:"M5 12.5l4.5 4.5L19 7.5"})}),on=()=>b(ee,{size:16,children:[c("rect",{x:"9",y:"9",width:"11",height:"11",rx:"2"}),c("path",{d:"M5 15V6a2 2 0 0 1 2-2h9"})]}),Es=()=>b(ee,{size:16,children:[c("path",{d:"M7 7h12l-3-3"}),c("path",{d:"M17 17H5l3 3"})]}),Ns=()=>b(ee,{size:16,children:[c("path",{d:"M12 3v8"}),c("path",{d:"M6.3 7.3a8 8 0 1 0 11.4 0"})]}),Ls=()=>c(ee,{size:14,children:c("path",{d:"M8 5v14M16 5v14"})}),Ts=()=>c(ee,{size:14,children:c("path",{d:"M7 4.5v15l12-7.5z"})}),Is=()=>b(ee,{children:[c("circle",{cx:"12",cy:"12",r:"9"}),c("path",{d:"M12 8v5"}),c("path",{d:"M12 16.5h.01"})]}),Os=()=>b(ee,{children:[c("circle",{cx:"12",cy:"12",r:"9"}),c("path",{d:"M12 11v5"}),c("path",{d:"M12 7.5h.01"})]});function Ms({size:e=28}){return b("svg",{className:"sc-logo",width:e,height:e,viewBox:"0 0 32 32","aria-hidden":"true",focusable:"false",children:[c("circle",{cx:"16",cy:"16",r:"16",fill:"#2775CA"}),c("path",{d:"M20.4 18.2c0-2.3-1.4-3.1-4.2-3.4-2-.3-2.4-.8-2.4-1.7 0-.9.7-1.4 2-1.4 1.2 0 1.9.4 2.2 1.4.1.2.3.3.5.3h1.1c.3 0 .5-.2.5-.5v-.1c-.3-1.4-1.4-2.4-2.9-2.6V8.3c0-.3-.2-.5-.5-.5h-1c-.3 0-.5.2-.5.5v1.4c-2 .3-3.2 1.6-3.2 3.2 0 2.2 1.3 3 4.1 3.3 1.9.4 2.5.8 2.5 1.8s-.9 1.6-2.2 1.6c-1.7 0-2.3-.7-2.5-1.7-.1-.3-.3-.4-.5-.4h-1.2c-.3 0-.5.2-.5.5v.1c.3 1.6 1.3 2.5 3.4 2.8v1.5c0 .3.2.5.5.5h1c.3 0 .5-.2.5-.5v-1.5c2-.3 3.3-1.7 3.3-3.4z",fill:"#fff"}),c("path",{d:"M12.6 25.2C7.7 23.4 5.2 18 7 13.2c.9-2.5 2.9-4.4 5.4-5.3.3-.1.4-.3.4-.6v-1c0-.3-.2-.5-.5-.5-.1 0-.1 0-.2.1C6 7.8 3 14.4 5.2 20.5c1.3 3.6 4.1 6.4 7.7 7.7.3.1.6 0 .6-.3.1-.1.1-.2.1-.2v-1c0-.2-.3-.4-.5-.6-.2-.1-.3-.1-.5-.1zM19.4 4.3c-.3-.1-.6 0-.6.3-.1.1-.1.2-.1.2v1c0 .3.3.5.5.6 4.9 1.8 7.4 7.2 5.6 12-.9 2.5-2.9 4.4-5.4 5.3-.3.1-.4.3-.4.6v1c0 .3.2.5.5.5.1 0 .1 0 .2-.1 6-1.9 9-8.5 6.8-14.6-1.3-3.7-4.2-6.5-7.1-7.8z",fill:"#fff"})]})}var _s=["M11.9969 23.9965H11.9965L11.9967 23.9965L11.9969 23.9965Z","M16.085 19.5256C16.8061 18.8689 17.9092 18.869 18.6303 19.5258L18.6305 19.5259L20.091 20.8558C17.957 22.8065 15.1158 23.9965 11.9967 23.9965C8.88824 23.9964 6.05591 22.8147 3.92448 20.876L5.4072 19.5259L5.40734 19.5258C6.12844 18.869 7.23147 18.8689 7.95265 19.5256L9.25088 20.7087L9.25109 20.7089C10.8195 22.1374 13.2182 22.1374 14.7866 20.7089L14.7868 20.7087L16.085 19.5256L16.085 19.5256Z","M11.9965 0C15.1214 0 17.9672 1.19421 20.1025 3.15105C20.0412 3.20075 19.981 3.25245 19.922 3.30619L19.9218 3.30636L18.6236 4.48944C17.9025 5.14605 16.7996 5.14605 16.0785 4.48944L14.7803 3.30636L14.78 3.30619L14.7431 3.27296C13.1742 1.87772 10.8007 1.88883 9.24454 3.30622L5.92566 6.32832L7.42038 7.96939L10.7394 4.94715L10.7395 4.94704C11.4607 4.29025 12.5637 4.29016 13.2849 4.94683L14.5831 6.12991L14.5833 6.13012C16.1517 7.55866 18.5504 7.55866 20.1188 6.13012L20.119 6.12994L21.4172 4.94687L21.4172 4.94683C21.4753 4.89391 21.5359 4.8453 21.5986 4.80091C23.1043 6.80592 23.9965 9.2979 23.9965 11.9983C23.9965 14.7069 23.0988 17.2058 21.5847 19.2139L20.1253 17.885L20.1253 17.8849C18.5569 16.4564 16.1582 16.4564 14.5898 17.8849L14.5896 17.8851L13.2914 19.0682C12.5703 19.7248 11.4674 19.7248 10.7463 19.0682L9.44805 17.8851L9.44784 17.8849L9.41092 17.8517C7.842 16.4565 5.46849 16.4676 3.91233 17.885L2.42664 19.2378C1.38127 17.8584 0.627365 16.2461 0.256536 14.4924L2.73458 12.236L2.73472 12.2359C3.45586 11.579 4.55861 11.579 5.27978 12.2358L6.57837 13.4188L6.57847 13.4189C8.14681 14.8474 10.5455 14.8476 12.1137 13.4188L13.4122 12.2358C14.1334 11.579 15.2365 11.579 15.9577 12.2359L15.9578 12.236L19.2769 15.2582L20.7716 13.6171L17.4527 10.595L17.4527 10.595C15.8843 9.16646 13.4856 9.16646 11.9172 10.595L11.9171 10.5951L10.6185 11.7782L10.6185 11.7782C9.89779 12.4348 8.79476 12.435 8.07352 11.7782L6.77493 10.5951L6.77486 10.595L6.73795 10.5618C5.16903 9.16654 2.79587 9.17765 1.23971 10.595L0 11.7239C0.145876 5.22438 5.46071 7.07913e-06 11.9965 0Z"],Ws="M0,101.12c0-34.64,0-51.95,6.53-65.28,6.25-12.76,16.56-23.07,29.32-29.32C49.17,0,66.48,0,101.12,0h1077.76c34.63,0,51.96,0,65.28,6.53,12.75,6.25,23.06,16.56,29.32,29.32,6.52,13.32,6.52,30.64,6.52,65.28v1077.76c0,34.63,0,51.96-6.52,65.28-6.26,12.75-16.57,23.06-29.32,29.32-13.32,6.52-30.65,6.52-65.28,6.52H101.12c-34.64,0-51.95,0-65.28-6.52-12.76-6.26-23.07-16.57-29.32-29.32-6.53-13.32-6.53-30.65-6.53-65.28V101.12Z",Bs="M100.48 69.3817L83.8068 86.8015C83.4444 87.1799 83.0058 87.4816 82.5185 87.6878C82.0312 87.894 81.5055 88.0003 80.9743 88H1.93563C1.55849 88 1.18957 87.8926 0.874202 87.6912C0.558829 87.4897 0.31074 87.2029 0.160416 86.8659C0.0100923 86.529 -0.0359181 86.1566 0.0280382 85.7945C0.0919944 85.4324 0.263131 85.0964 0.520422 84.8278L17.2061 67.408C17.5676 67.0306 18.0047 66.7295 18.4904 66.5234C18.9762 66.3172 19.5002 66.2104 20.0301 66.2095H99.0644C99.4415 66.2095 99.8104 66.3169 100.126 66.5183C100.441 66.7198 100.689 67.0067 100.84 67.3436C100.99 67.6806 101.036 68.0529 100.972 68.415C100.908 68.7771 100.737 69.1131 100.48 69.3817ZM83.8068 34.3032C83.4444 33.9248 83.0058 33.6231 82.5185 33.4169C82.0312 33.2108 81.5055 33.1045 80.9743 33.1048H1.93563C1.55849 33.1048 1.18957 33.2121 0.874202 33.4136C0.558829 33.6151 0.31074 33.9019 0.160416 34.2388C0.0100923 34.5758 -0.0359181 34.9482 0.0280382 35.3103C0.0919944 35.6723 0.263131 36.0083 0.520422 36.277L17.2061 53.6968C17.5676 54.0742 18.0047 54.3752 18.4904 54.5814C18.9762 54.7875 19.5002 54.8944 20.0301 54.8952H99.0644C99.4415 54.8952 99.8104 54.7879 100.126 54.5864C100.441 54.3849 100.689 54.0981 100.84 53.7612C100.99 53.4242 101.036 53.0518 100.972 52.6897C100.908 52.3277 100.737 51.9917 100.48 51.723L83.8068 34.3032ZM1.93563 21.7905H80.9743C81.5055 21.7907 82.0312 21.6845 82.5185 21.4783C83.0058 21.2721 83.4444 20.9704 83.8068 20.592L100.48 3.17219C100.737 2.90357 100.908 2.56758 100.972 2.2055C101.036 1.84342 100.99 1.47103 100.84 1.13408C100.689 0.79713 100.441 0.510296 100.126 0.308823C99.8104 0.107349 99.4415 1.24074e-05 99.0644 0L20.0301 0C19.5002 0.000878397 18.9762 0.107699 18.4904 0.313848C18.0047 0.519998 17.5676 0.821087 17.2061 1.19848L0.524723 18.6183C0.267681 18.8866 0.0966198 19.2223 0.0325185 19.5839C-0.0315829 19.9456 0.0140624 20.3177 0.163856 20.6545C0.31365 20.9913 0.561081 21.2781 0.875804 21.4799C1.19053 21.6817 1.55886 21.7896 1.93563 21.7905Z";function Ds({icon:e}){if(e==="sei")return b("svg",{viewBox:"0 0 24 24",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:[c("rect",{width:"24",height:"24",fill:"#000"}),c("g",{transform:"translate(4 4) scale(0.6667)",fill:"#fff",children:_s.map((t,n)=>c("path",{d:t},n))})]});if(e==="base")return c("svg",{viewBox:"0 0 1280 1280",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:c("path",{d:Ws,fill:"#0000FF"})});return b("svg",{viewBox:"0 0 24 24",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:[c("rect",{width:"24",height:"24",fill:"#000"}),c("defs",{children:b("linearGradient",{id:"sc-sol-grad",x1:"8.52558",y1:"90.0973",x2:"88.9933",y2:"-3.01622",gradientUnits:"userSpaceOnUse",children:[c("stop",{offset:"0.08",stopColor:"#9945FF"}),c("stop",{offset:"0.5",stopColor:"#5497D5"}),c("stop",{offset:"0.97",stopColor:"#19FB9B"})]})}),c("g",{transform:"translate(4.5 5.2) scale(0.1485)",children:c("path",{d:Bs,fill:"url(#sc-sol-grad)"})})]})}var Us={usdt:"#26A17B",eth:"#627EEA",pol:"#8247E5",usdc:"#2775CA"},js={usdt:"₮",eth:"Ξ"};function zs({token:e,size:t=28}){let n=e.logo.toLowerCase(),a=js[n]??(/[\p{L}\p{N}]/u.exec(e.symbol)?.[0]??"•").toUpperCase();return b("svg",{className:"sc-glyph",width:t,height:t,viewBox:"0 0 32 32","aria-hidden":"true",focusable:"false","data-token":n,children:[c("circle",{cx:"16",cy:"16",r:"16",fill:Us[n]??"#475569"}),c("text",{x:"16",y:"21.5",textAnchor:"middle",fontSize:"16",fontWeight:"700",fill:"#fff",fontFamily:"system-ui,sans-serif",children:a})]})}function ut({size:e=28,badge:t,token:n}){let a=!!n&&n.logo.toLowerCase()!=="usdc";return b("span",{className:"sc-mark",style:{width:e,height:e},children:[a?c(zs,{token:n,size:e}):c(Ms,{size:e}),t?t.icon?c("span",{className:"sc-badge sc-badge-icon","data-icon":t.icon,"aria-hidden":"true",children:c(Ds,{icon:t.icon})}):c("span",{className:"sc-badge","data-hue":t.hue,"aria-hidden":"true",children:t.letter}):null]})}function Hs(){return b("svg",{className:"sc-check",viewBox:"0 0 64 64","aria-hidden":"true",focusable:"false",children:[c("circle",{cx:"32",cy:"32",r:"28"}),c("path",{d:"M20 33l8 8 16-17"})]})}function pt({chain:e,symbol:t="USDC"}){return b("span",{className:"sc-tok",children:[t,c("sub",{children:e})]})}function $s({options:e,selectedId:t,open:n,locked:a,label:r,amount:s,onOpenChange:o,onSelect:i}){let l=ae(null),d=ae(null),g=e.find((p)=>p.id===t)??e[0]??null,h=e.length<=1,k=!h&&!a;Z(()=>{if(!n)return;let p=d.current?.querySelectorAll('[role="option"]'),f=Math.max(0,e.findIndex((D)=>D.id===t));p?.[f]?.focus({preventScroll:!0});let C=setTimeout(()=>{d.current?.closest(".sc-card")?.querySelector('[data-testid="sc-pay"]')?.scrollIntoView({block:"nearest",behavior:"smooth"})},240),te=(D)=>{let z=D.target;if(z&&!d.current?.contains(z)&&!l.current?.contains(z))o(!1)};return document.addEventListener("pointerdown",te,!0),()=>{clearTimeout(C),document.removeEventListener("pointerdown",te,!0)}},[n]);let A=(p)=>{let f=Array.from(d.current?.querySelectorAll('[role="option"]')??[]);if(f.length===0)return;let C=f.indexOf(document.activeElement),te=p==="first"?0:p==="last"?f.length-1:Math.min(f.length-1,Math.max(0,C+p));f[te]?.focus()},L=(p)=>{if(p.key==="Escape")p.preventDefault(),p.stopPropagation(),o(!1),l.current?.focus();else if(p.key==="ArrowDown")p.preventDefault(),A(1);else if(p.key==="ArrowUp")p.preventDefault(),A(-1);else if(p.key==="Home")p.preventDefault(),A("first");else if(p.key==="End")p.preventDefault(),A("last");else if(p.key==="Tab")o(!1)};return b(gt,{children:[b("div",{className:"sc-box",children:[c("div",{className:"sc-pick",children:b("button",{ref:l,type:"button",className:"sc-tok-btn","aria-haspopup":h?void 0:"listbox","aria-expanded":h?void 0:n,"aria-disabled":h||a,"aria-label":g?`${r}: ${g.symbol??"USDC"} ${g.chain}`:r,"data-testid":"sc-token","data-single":h?"true":void 0,onClick:()=>{if(k)o(!n)},onKeyDown:(p)=>{if((p.key==="ArrowDown"||p.key==="ArrowUp")&&k)p.preventDefault(),o(!0)},children:[c(ut,{badge:g?.badge,token:g?.symbol?{symbol:g.symbol,logo:g.logo??g.symbol.toLowerCase()}:null}),g?c(pt,{chain:g.chain,symbol:g.symbol}):c("span",{className:"sc-tok",children:"USDC"}),k&&c($a,{})]})}),s]}),n&&!h&&c("div",{ref:d,className:"sc-menu",role:"listbox","aria-label":r,onKeyDown:L,"data-testid":"sc-menu",children:e.map((p,f)=>b("button",{type:"button",role:"option",className:"sc-opt",style:{"--i":Math.min(f,3)},"aria-selected":p.id===t,"aria-disabled":p.disabled,"data-testid":"sc-option",onClick:()=>{if(p.disabled)return;i(p.id),o(!1),l.current?.focus()},children:[b("span",{className:"sc-opt-main",children:[c(ut,{badge:p.badge,token:p.symbol?{symbol:p.symbol,logo:p.logo??p.symbol.toLowerCase()}:null}),c(pt,{chain:p.chain,symbol:p.symbol})]}),p.loading?c("span",{className:"sc-sk",style:{width:56,height:14},"data-testid":"sc-row-skeleton","aria-hidden":"true"}):p.balanceText!==null||p.reason?b("span",{className:"sc-opt-bal","data-muted":p.disabled?"true":void 0,children:[p.balanceText!==null&&c("span",{children:p.balanceText}),p.reason&&c("span",{className:"sc-opt-sub",children:p.reason})]}):null,c("span",{className:"sc-opt-check","aria-hidden":"true",children:p.id===t?c($e,{}):null})]},p.id))})]})}function Fs({items:e,paused:t,lowGas:n,pauseLabel:a,optionKey:r,interval:s=2500}){let o=e.findIndex((j)=>j.warn),[i,l]=me(Math.max(0,o)),[d,g]=me(!1),[h,k]=me(!1),[A,L]=me(!1),p=e.map((j)=>j.label).join("|"),f=e.map((j)=>j.value).join(", "),[C,te]=me(f),D=ae(r??null);Z(()=>l(Math.max(0,o)),[p,o]),Z(()=>{if(e.length===0||D.current===(r??null))return;D.current=r??null,te(f)},[r,e.length]);let z=e.length>1&&o<0,ue=t||d||h||A;if(Z(()=>{if(!z||ue)return;let j=setInterval(()=>l((V)=>(V+1)%e.length),s);return()=>clearInterval(j)},[z,ue,e.length,s]),e.length===0)return null;return b("div",{className:"sc-deco","data-testid":"sc-decorator",onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),onFocus:(j)=>k(j.target.matches(":focus-visible")),onBlur:()=>k(!1),children:[c("span",{className:"sc-live",role:"status","aria-live":"polite",children:C}),c("span",{className:"sc-deco-cycle",children:e.map((j,V)=>b("span",{className:"sc-deco-item","aria-hidden":"true","data-active":V===i,"data-warn":j.warn,children:[c("span",{className:"sc-deco-v",children:j.value}),j.warn&&c("span",{className:"sc-deco-flag","data-testid":"sc-lowgas",children:n})]},j.label))}),z&&c("button",{type:"button",className:"sc-pause","aria-pressed":A,"aria-label":a,"data-testid":"sc-pause",onClick:()=>L((j)=>!j),children:A?c(Ts,{}):c(Ls,{})})]})}function qs({wallet:e,copy:t,actions:n,inert:a}){let[r,s]=me(!1),[o,i]=me(!1),l=ae(null),d=ae(null),g=ae(null);Z(()=>()=>{if(g.current)clearTimeout(g.current)},[]),Z(()=>{if(!r)return;d.current?.querySelector('[role="menuitem"]')?.focus();let p=(f)=>{let C=f.target;if(C&&!d.current?.contains(C)&&!l.current?.contains(C))s(!1)};return document.addEventListener("pointerdown",p,!0),()=>document.removeEventListener("pointerdown",p,!0)},[r]),Z(()=>{if(a)s(!1)},[a]);let h=e.name??t.walletName,k=b(gt,{children:[c("span",{className:"sc-wallet-dot","aria-hidden":"true"}),c("span",{className:"sc-wallet-name",children:h}),c("span",{className:"sc-wallet-addr",children:e.short}),!a&&n?c($a,{}):null]});if(a||!n)return c("div",{className:"sc-wrow",children:c("span",{className:"sc-wallet","data-static":"true","data-testid":"sc-wallet",children:k})});let A=[{key:"copy",icon:o?c($e,{}):c(on,{}),label:o?t.copied:t.copyWalletAddress,sub:e.short,run:()=>{if(n.onCopy(),i(!0),g.current)clearTimeout(g.current);g.current=setTimeout(()=>i(!1),1600)},keepOpen:!0},{key:"switch",icon:c(Es,{}),label:t.switchWallet,run:n.onSwitch},{key:"disconnect",icon:c(Ns,{}),label:t.disconnect,run:n.onDisconnect}],L=(p)=>{let f=Array.from(d.current?.querySelectorAll('[role="menuitem"]')??[]),C=f.indexOf(document.activeElement);if(p.key==="Escape")p.preventDefault(),p.stopPropagation(),s(!1),l.current?.focus();else if(p.key==="ArrowDown")p.preventDefault(),f[(C+1)%f.length]?.focus();else if(p.key==="ArrowUp")p.preventDefault(),f[(C-1+f.length)%f.length]?.focus();else if(p.key==="Tab")s(!1)};return b("div",{className:"sc-wrow",children:[c("button",{ref:l,type:"button",className:"sc-wallet","aria-haspopup":"menu","aria-expanded":r,"aria-label":`${t.walletMenu}: ${h} ${e.short}`,"data-testid":"sc-wallet",onClick:()=>s((p)=>!p),onKeyDown:(p)=>{if(p.key==="ArrowDown"&&!r)p.preventDefault(),s(!0)},children:k}),r&&c("div",{ref:d,className:"sc-pop",role:"menu","aria-label":t.walletMenu,onKeyDown:L,"data-testid":"sc-wallet-menu",children:A.map((p)=>b("button",{type:"button",role:"menuitem",className:"sc-mi","data-testid":`sc-wallet-${p.key}`,onClick:()=>{if(p.run(),!p.keepOpen)s(!1)},children:[p.icon,c("span",{children:p.label}),p.sub?c("span",{className:"sc-mi-sub",children:p.sub}):null]},p.key))})]})}function Ks({wallets:e,busyId:t,copy:n,onPick:a}){let r=ae(null);Z(()=>{r.current?.querySelector("button")?.focus({preventScroll:!0})},[]);let s=(o)=>{let i=Array.from(r.current?.querySelectorAll("button")??[]),l=i.indexOf(document.activeElement);if(o.key==="ArrowDown")o.preventDefault(),i[Math.min(i.length-1,l+1)]?.focus();else if(o.key==="ArrowUp")o.preventDefault(),i[Math.max(0,l-1)]?.focus()};return c("ul",{ref:r,className:"sc-wl","aria-label":n.chooseWallet,"data-testid":"sc-wallets",onKeyDown:s,children:e.map((o,i)=>{let l=t===o.id;return c("li",{children:b("button",{type:"button",className:"sc-wl-row",style:{animation:"sc-rise .2s var(--c-ease) both",animationDelay:`${Math.min(i,3)*20}ms`},"aria-disabled":t!==null,"aria-busy":l,"data-testid":"sc-wallet-option",onClick:()=>{if(t===null)a(o.id)},children:[o.icon?c("img",{className:"sc-wl-icon",src:o.icon,alt:"",width:32,height:32}):c("span",{className:"sc-wl-mono","aria-hidden":"true",children:o.name.charAt(0).toUpperCase()}),b("span",{className:"sc-wl-name",children:[o.name,l&&b("span",{className:"sc-wl-sub",children:[c(dt,{small:!0}),B(n.openingNamed,{wallet:o.name})]})]}),o.lastUsed&&!l?c("span",{className:"sc-wl-tag",children:n.lastUsed}):null]})},o.id)})})}function Gs({stages:e,copy:t,tx:n,walletName:a}){let r=(s)=>s.key==="wallet"?s.state==="active"&&n&&n.total>1?lt(t,n,a):a?B(t.confirmNamed,{wallet:a}):t.stageWallet:s.key==="sent"?t.stageSent:t.stageConfirmed;return c("ol",{className:"sc-steps","aria-label":t.stagesLabel,"data-testid":"sc-stages",children:e.map((s)=>b("li",{"data-state":s.state,"data-stage":s.key,children:[c("span",{className:"sc-dot","aria-hidden":"true",children:s.state==="done"?c($e,{size:14}):null}),b("span",{children:[r(s),c("span",{className:"sc-live",children:s.state==="done"?" (done)":s.state==="active"?" (in progress)":""})]})]},s.key))})}function ft({problem:e,copy:t,noticeRef:n,children:a}){let r=e.kind==="rejected";return b("div",{className:"sc-notice",ref:n,tabIndex:-1,"data-kind":e.kind,"data-testid":"sc-notice",children:[b("div",{className:"sc-notice-head",children:[r?c(Os,{}):c(Is,{}),c("p",{children:e.message})]}),a?c("div",{className:"sc-actions",children:a}):null,e.detail&&!r&&b("details",{className:"sc-tech",children:[c("summary",{children:t.details}),c("code",{children:e.detail})]})]})}function Qs({copy:e,amountText:t,receipt:n,finalizing:a,slot:r,returnHref:s,doneRef:o,onDone:i}){let l=s?c("a",{className:"sc-btn",href:s,ref:o,"data-testid":"sc-return",children:e.returnToStore}):i?c("button",{type:"button",className:"sc-btn",onClick:i,ref:o,"data-testid":"sc-done",children:e.done}):null;return b("div",{className:"sc-ok",ref:l?void 0:o,tabIndex:l?void 0:-1,"data-testid":"sc-success","data-receipt":a?"provisional":"final",children:[c(Hs,{}),c("h3",{children:a?e.receivedProvisional:e.received},a?"received":"confirmed"),c("p",{className:"sc-ok-amt",children:t}),b("p",{className:"sc-receipt",children:[e.receiptLabel," ",c("code",{children:n})]}),a&&c("p",{className:"sc-fin","data-testid":"sc-finalizing",children:e.finalizing}),r?c("div",{className:"sc-slot",children:r}):null,l]})}function Ys(){return b("div",{"aria-hidden":"true","data-testid":"sc-skeleton",children:[c("span",{className:"sc-sk",style:{width:120,height:14,margin:"6px 0 10px"}}),c("span",{className:"sc-sk",style:{width:"100%",height:96,borderRadius:16}}),c("span",{className:"sc-sk",style:{width:"100%",height:56,marginTop:16}})]})}var Js=()=>typeof window<"u"&&typeof window.matchMedia==="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,Vs=typeof window>"u"?Z:As;function Fa({open:e,onClose:t,onBackdrop:n,titleId:a,children:r,initialFocus:s}){let o=ae(null),[i,l]=me(e);return Vs(()=>{if(e)l(!0)},[e]),Z(()=>{let d=o.current;if(!d)return;if(e&&!d.open){d.removeAttribute("data-closing");try{d.showModal()}catch{d.setAttribute("open","")}s?.current?.focus();return}if(e||!d.open)return;let g=!1,h=()=>{if(g)return;g=!0,d.removeAttribute("data-closing"),d.close(),l(!1)};if(Js()){h();return}d.setAttribute("data-closing",""),d.addEventListener("animationend",h,{once:!0});let k=setTimeout(h,260);return()=>{if(clearTimeout(k),d.removeEventListener("animationend",h),!g&&o.current?.open)d.removeAttribute("data-closing")}},[e]),c("dialog",{ref:o,className:"sc-dialog","aria-labelledby":a,"data-testid":"sc-modal",onCancel:(d)=>{d.preventDefault(),t()},onClick:(d)=>{let g=o.current;if(!g||d.target!==g)return;let h=g.getBoundingClientRect();if(d.clientX<h.left||d.clientX>h.right||d.clientY<h.top||d.clientY>h.bottom)(n??t)()},children:e||i?r:null})}function Xs({title:e,titleId:t,titleRef:n,closeLabel:a,onClose:r,back:s}){return b("div",{className:"sc-head",children:[b("div",{className:"sc-head-end",children:[s&&b("button",{type:"button",className:"sc-back",onClick:s.onClick,"data-testid":"sc-back",children:[c(Rs,{}),s.label]}),c("h2",{className:"sc-title",id:t,ref:n,tabIndex:-1,children:e})]}),c("div",{className:"sc-head-end",children:r&&c("button",{type:"button",className:"sc-x",onClick:r,"aria-label":a,"data-testid":"sc-close",children:c(ee,{children:c("path",{d:"M6 6l12 12M18 6L6 18"})})})})]})}function Zs({children:e}){let t=ae(null),n=ae(null);return Z(()=>{let a=t.current,r=n.current;if(!a||!r||typeof ResizeObserver>"u")return;let s=!0,o,i=new ResizeObserver(()=>{let l=r.getBoundingClientRect().height;if(l===0){a.style.height="";return}if(a.style.height=`${l+8}px`,s){s=!1,requestAnimationFrame(()=>a.setAttribute("data-ready","true"));return}a.setAttribute("data-anim","true"),clearTimeout(o),o=setTimeout(()=>a.removeAttribute("data-anim"),260)});return i.observe(r),()=>{i.disconnect(),clearTimeout(o)}},[]),c("div",{className:"sc-hgt",ref:t,children:c("div",{ref:n,children:e})})}function eo({line:e,copy:t,onRetry:n}){let a=e.kind==="loading"||e.kind==="refreshing";return b("div",{className:"sc-payline",role:"status","aria-live":"polite","aria-atomic":"true","data-testid":"sc-payline","data-kind":e.kind,children:[a&&c(dt,{small:!0}),c("span",{className:e.kind==="ready"||e.kind==="refreshing"?"sc-payline-main":void 0,children:e.text}),e.note?c("span",{children:e.note}):null,e.eta?c("span",{children:e.eta}):null,e.kind==="unavailable"&&n?c("button",{type:"button",className:"sc-link",onClick:n,children:t.tryAgain}):null]})}function qa(e){let{copy:t}=e,n=e.phase==="paying",a=e.phase==="pick"||e.phase==="paying",r=ae(null),s=!!e.closeGuard&&n;Z(()=>{if(s)r.current?.focus()},[s]);let o=e.phase==="manual"?t.payAnotherWay:e.phase==="wallets"?t.chooseWallet:e.title??t.title;return b("div",{className:"sc-card","data-phase":e.phase,children:[b(Zs,{children:[c(Xs,{title:o,titleId:e.titleId,titleRef:e.titleRef,closeLabel:t.close,onClose:e.onClose,back:(e.phase==="manual"||e.phase==="wallets")&&e.onBack?{label:t.back,onClick:e.onBack}:null}),e.phase==="loading"&&!e.notice&&c(Ys,{}),a&&e.wallet&&c(qs,{wallet:e.wallet,copy:t,actions:e.walletActions??null,inert:n}),a&&b(gt,{children:[b("div",{className:"sc-deco-row",children:[c("span",{className:"sc-deco-label",children:t.payWith}),b("span",{className:"sc-deco-end",children:[e.refreshing?c("span",{"data-testid":"sc-refreshing",style:{display:"inline-flex"},children:c(dt,{small:!0})}):null,c(Fs,{items:e.decorator,paused:e.menuOpen||n,lowGas:t.lowGas,pauseLabel:t.pauseBalances,optionKey:e.decoratorKey})]})]}),c($s,{options:e.options,selectedId:e.selectedId,open:e.menuOpen,locked:n,label:t.chooseUsdc,amount:c("p",{className:"sc-amt","data-testid":"sc-amount","aria-label":`${t.amountDue} ${e.amountText}`,children:e.amountText}),onOpenChange:e.onMenuChange,onSelect:e.onSelect}),e.payLine&&c(eo,{line:e.payLine,copy:t,onRetry:e.onPayLineRetry})]}),e.phase==="wallets"&&e.walletPicker&&c(Ks,{wallets:e.walletPicker.wallets,busyId:e.walletPicker.busyId,copy:t,onPick:e.walletPicker.onPick}),(e.phase==="pick"||e.phase==="wallets")&&e.message?c("div",{className:"sc-msg",role:"status","data-testid":"sc-message",children:e.message}):null,e.notice,n&&e.stages&&b(gt,{children:[c(Gs,{stages:e.stages,copy:t,tx:e.tx,walletName:e.walletName}),c("div",{className:"sc-hair","aria-hidden":"true","data-testid":"sc-progress",children:c("i",{})}),e.slow?c("p",{className:"sc-expect","data-testid":"sc-status",children:t.slow}):null]}),s&&e.closeGuard&&b("div",{className:"sc-msg","data-testid":"sc-close-guard",children:[c("span",{className:"sc-msg-strong",children:t.closeConfirm}),b("div",{className:"sc-pair",children:[c("button",{type:"button",className:"sc-sec",onClick:e.closeGuard.onClose,"data-testid":"sc-close-anyway",children:t.closeAnyway}),c("button",{type:"button",className:"sc-sec",ref:r,onClick:e.closeGuard.onStay,"data-testid":"sc-stay",children:t.stay})]})]}),(e.phase==="pick"||e.phase==="paying")&&e.cta&&b("button",{ref:e.cta.ref,type:"button",className:"sc-btn sc-cta","aria-busy":e.cta.busy,"aria-disabled":e.cta.disabled||e.cta.busy,"data-testid":"sc-pay",onClick:()=>{if(!e.cta.disabled&&!e.cta.busy)e.cta.onClick()},children:[(e.cta.busy||e.cta.spinner)&&c(dt,{}),c("span",{children:e.cta.label})]}),e.phase==="pick"&&e.onPayAnotherWay&&c("div",{className:"sc-foot",children:c("button",{type:"button",className:"sc-link sc-link-quiet",onClick:e.onPayAnotherWay,"data-testid":"sc-another-way",children:t.payAnotherWay})}),e.phase==="done"&&e.done&&c(Qs,{copy:t,amountText:e.amountText,receipt:e.done.receipt,finalizing:e.done.finalizing,slot:e.done.slot,returnHref:e.done.returnHref,doneRef:e.done.ref,onDone:e.done.onDone}),e.phase==="manual"&&e.manual]}),b("p",{className:"sc-powered","data-testid":"sc-powered",children:[c("svg",{viewBox:"0 0 80 80","aria-hidden":"true",focusable:"false",children:c("path",{d:za,fill:"none",stroke:"currentColor",strokeWidth:"11",strokeLinecap:"round",strokeLinejoin:"round"})}),c("span",{children:ja.poweredBy})]})]})}var to={pending:"",event:"",data:[],started:!1},no=/\r\n|\n|\r/;function ao(e,t){if(t===""){let o=e.data.length>0?{event:e.event||"message",data:e.data.join(`
|
|
208
|
-
`)}:null;return{state:{...e,event:"",data:[]},frame:o}}if(t.startsWith(":"))return{state:e,frame:null};let n=t.indexOf(":"),a=n===-1?t:t.slice(0,n),r=n===-1?"":t.slice(n+1),s=r.startsWith(" ")?r.slice(1):r;if(a==="event")return{state:{...e,event:s},frame:null};if(a==="data")return{state:{...e,data:[...e.data,s]},frame:null};return{state:e,frame:null}}function ro(e,t){let n=e.pending+(e.started?t:t.replace(/^\uFEFF/,"")),a=n.endsWith("\r")?"\r":"",r=n.slice(0,n.length-a.length).split(no),s=r.pop(),o=r.reduce((i,l)=>{let d=ao(i.state,l);return{state:d.state,frames:d.frame?[...i.frames,d.frame]:i.frames}},{state:{...e,started:!0},frames:[]});return{state:{...o.state,pending:s+a},frames:o.frames}}async function Ka(e,t,n){let a=e.getReader(),r=new TextDecoder,s=()=>void a.cancel().catch(()=>{});if(n?.aborted)return s();n?.addEventListener("abort",s,{once:!0});try{let o=to;for(;;){let{done:i,value:l}=await a.read();if(i||n?.aborted)return;let d=ro(o,r.decode(l,{stream:!0}));o=d.state;for(let g of d.frames)if(t(g),n?.aborted)return s()}}finally{n?.removeEventListener("abort",s)}}class Se extends Error{status;code;constructor(e,t,n){super(n);this.status=e;this.code=t}}var so={retries:3,baseMs:400};function oo(e,t={}){let{retryRateLimit:n=!0}=t;return e instanceof Se&&(e.status===0||e.status===408||n&&e.status===429||e.status>=500)}async function io(e,t={}){let{retries:n,baseMs:a,retryRateLimit:r}={...so,...t};for(let s=0;;s++)try{return await e()}catch(o){if(s>=n||!oo(o,{retryRateLimit:r}))throw o;await new Promise((i)=>setTimeout(i,a*2**s+Math.random()*a*0.25))}}function cn(e,t,n,a){let r=`${e}/v1/charges/${encodeURIComponent(t)}`;async function s(i,l){let d;try{d=await fetch(`${r}${i}`,{method:l===void 0?"GET":"POST",headers:{"X-Client-Secret":n,...l===void 0?{}:{"content-type":"application/json"}},...l===void 0?{}:{body:JSON.stringify(l)},cache:"no-store"})}catch{throw new Se(0,"network","Network request failed")}let g=await d.text(),h=null;try{h=g?JSON.parse(g):null}catch{h=null}if(!d.ok){let k=h?.error;throw new Se(d.status,k?.code??"error",k?.message??`HTTP ${d.status}`)}return h}let o=(i,l)=>io(()=>s(i,l),{...a,retryRateLimit:l===void 0});return{charge:()=>s(""),events:async(i,l)=>{let d;try{d=await fetch(`${r}/events`,{headers:{"X-Client-Secret":n,accept:"text/event-stream"},cache:"no-store",...l?{signal:l}:{}})}catch{throw new Se(0,"network","Network request failed")}if(!d.ok||!d.body){let g=await d.json().catch(()=>null);throw new Se(d.status,g?.error?.code??"error",g?.error?.message??`HTTP ${d.status}`)}await Ka(d.body,i,l)},options:()=>o("/options"),pay:(i,l)=>o("/pay",{option_id:i,buyer:l}),authorize:(i)=>o("/authorizations",i),submitSolana:(i)=>o("/rails/cctp/submit",{transaction:i}),fundingAttempt:(i,l,d={})=>o("/funding_attempts",{rail:d.rail??"cctp",source_chain:i,tx_hash:l,...d.buyer?{buyer:d.buyer}:{}}),lifiQuote:(i,l)=>s(`/rails/lifi/quote?option_id=${encodeURIComponent(i)}&buyer=${encodeURIComponent(l)}`)}}async function we(e,t,n,a={}){let r=Error("No RPC endpoint available");for(let s of e){let o=new AbortController,i=setTimeout(()=>o.abort(),a.timeoutMs??8000);try{let l=await fetch(s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:1,method:t,params:n}),signal:o.signal});if(!l.ok)throw Error(`RPC HTTP ${l.status}`);let d=await l.json();if(d.error)throw Error(d.error.message??"RPC error");if(!("result"in d))throw Error("RPC returned no result");return d.result}catch(l){r=l}finally{clearTimeout(i)}}throw r}function Ae(e){return!!e&&typeof e==="object"}function co(e){if(!Ae(e)||typeof e.id!=="string"||!e.id)return null;if(e.kind!=="evm"&&e.kind!=="solana")return null;let{chain:t,token:n}=e;if(!Ae(t)||!(typeof t.id==="number"||typeof t.id==="string")||typeof t.name!=="string")return null;if(!Ae(n)||typeof n.address!=="string"||!n.address)return null;if(!Array.isArray(e.rpc_urls))return null;let a=e.native;return{id:e.id,kind:e.kind,chain:{id:t.id,name:t.name,display_name:typeof t.display_name==="string"&&t.display_name?t.display_name:null},...e.rail==="lifi"?{rail:"lifi"}:{},token:{symbol:typeof n.symbol==="string"?n.symbol:"USDC",address:n.address,decimals:typeof n.decimals==="number"?n.decimals:6,logo:typeof n.logo==="string"?n.logo:"usdc",...n.native===!0?{native:!0}:{}},native:Ae(a)&&typeof a.symbol==="string"&&typeof a.decimals==="number"?{symbol:a.symbol,decimals:a.decimals}:null,default:e.default===!0,route:e.route==="direct"?"direct":"bridge",...e.gasless===!0?{gasless:!0}:{},add_chain:Ae(e.add_chain)?e.add_chain:null,rpc_urls:e.rpc_urls.filter((r)=>typeof r==="string"&&/^https?:\/\//i.test(r))}}function Qa(e){return(Array.isArray(e)?e:Ae(e)&&Array.isArray(e.data)?e.data:[]).map(co).filter((n)=>n!==null)}function ht(e){return e.chain.display_name??Ra(e.chain.name)}function lo(e){let t=e.chain,n=t.add_chain?.nativeCurrency;return{id:`evm:${t.id}`,kind:"evm",chain:{id:t.id,name:t.name,display_name:t.add_chain?.chainName??null},token:{symbol:"USDC",address:t.usdc,decimals:6,logo:"usdc"},native:n?{symbol:n.symbol,decimals:n.decimals}:null,default:!0,route:"direct",add_chain:t.add_chain,rpc_urls:t.add_chain?.rpcUrls??[]}}var Ya=(e,t)=>t.find((n)=>n.default&&!F(n))??lo(e);function un(e){return!e.gasless&&(e.kind==="solana"||e.route==="bridge")}function dn(e,t){let n=10n**BigInt(t),a=e/n,s=(t===0?"":(e%n).toString().padStart(t,"0")).slice(0,4).replace(/0+$/,"");if(s.length<2)s=s.padEnd(2,"0");return`${a.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}.${s}`}var F=(e)=>e.rail==="lifi";function yt(e,t,n){return F(e)?t.usdc>0n:t.usdc>=BigInt(n)}function Ja(e,t,n,a){let r={balanceText:null,disabled:!1,reason:null,loading:!1};if(a&&!a[e.kind])return a.evm||a.solana?{...r,reason:"needs_wallet"}:r;if(!t)return{...r,loading:!!a?.[e.kind]};if(t.status==="loading")return{...r,loading:!0};if(t.status==="error")return{...r,reason:"unreadable"};let s=!yt(e,t,n);return{balanceText:dn(t.usdc,e.token.decimals),disabled:s,reason:s?"not_enough":null,loading:!1}}function Va(e,t,n,a){let r=e.filter((i)=>n[i.kind]);if(r.length===0)return e;if(r.some((i)=>{let l=t[i.id];return!l||l.status==="loading"}))return e;let s=(i)=>{let l=n[i.kind]?t[i.id]:void 0;return l?.status==="ok"?yt(i,l,a)?0:2:1},o=(i)=>{let l=t[i.id];return l?.status==="ok"?l.usdc:0n};return e.map((i,l)=>({o:i,i:l})).sort((i,l)=>{let d=s(i.o)-s(l.o);if(d!==0)return d;if(s(i.o)===0){let g=Number(F(i.o))-Number(F(l.o));if(g!==0)return g;if(!F(i.o)){let h=o(i.o),k=o(l.o);if(h!==k)return h>k?-1:1;let A=Number(l.o.default)-Number(i.o.default);if(A!==0)return A}}return i.i-l.i}).map((i)=>i.o)}function pn(e,t,n){return e.filter((a)=>{if(!n[a.kind])return!1;let r=t[a.id];return!r||r.status!=="ok"||r.usdc>0n})}var ln=6;function Xa(e){let t=new Set;return e.map((n)=>{let a=0;for(let o of n)a=a*31+o.charCodeAt(0)>>>0;let r=a%ln;for(let o=0;t.has(r)&&o<ln;o++)r=(r+1)%ln;return t.add(r),{letter:/[\p{L}\p{N}]/u.exec(n)?.[0]?.toUpperCase()??"•",hue:r}})}function Za(e,t,n){let a=BigInt(n),r=e.flatMap((l)=>{let d=t[l.id];return!F(l)&&d?.status==="ok"&&d.usdc>=a?[{o:l,usdc:d.usdc}]:[]});if(r.length>0)return r.sort((l,d)=>Number(d.o.default)-Number(l.o.default)||(l.usdc===d.usdc?0:l.usdc>d.usdc?-1:1)),r[0].o.id;let s=e.filter((l)=>{let d=t[l.id];return F(l)&&d?.status==="ok"&&d.usdc>0n}),o=(l)=>/^(usdc|usdt)$/i.test(l.token.logo)?0:1;if(s.length>0)return s.map((l,d)=>({o:l,i:d})).sort((l,d)=>o(l.o)-o(d.o)||l.i-d.i)[0].o.id;let i=e.filter((l)=>t[l.id]?.status==="error");return i.sort((l,d)=>Number(d.default)-Number(l.default)),i[0]?.id??null}function er(e,t){if(!un(e)||!e.native||!t||t.status!=="ok"||t.native===null)return"na";if(t.native===0n)return"none";return t.native<10n**BigInt(Math.max(0,e.native.decimals-4))?"low":"ok"}function tr(e,t,n){if(!t||t.status!=="ok")return[];let a=[{label:F(e)?B(n.balanceLabelFor,{symbol:e.token.symbol}):n.balanceLabel,value:`${dn(t.usdc,e.token.decimals)} ${e.token.symbol}`,warn:!1}];if(e.native&&t.native!==null){let r=er(e,t);a.push({label:n.gasLabel,value:`${dn(t.native,e.native.decimals)} ${e.native.symbol}`,warn:r==="low"||r==="none"})}return a}function nr(e,t,n,a){let r=e.filter((i)=>n[i.kind]);if(r.length===0)return"idle";let s=r.map((i)=>t[i.id]);if(s.some((i)=>!i||i.status==="loading"))return"loading";if(s.some((i)=>i.status==="error"))return"ok";let o=s;if(o.some((i,l)=>yt(r[l],i,a)))return"ok";return o.every((i)=>i.usdc===0n)?"empty":"short"}function ar(e,t,n,a,r){if(!e)return{kind:"connect",disabled:!0,reason:null};if(!t[e.kind])return{kind:"connect",disabled:!1,reason:null};if(!n||n.status==="loading")return{kind:"pay",disabled:!0,reason:"checking"};if(n.status==="ok"&&!yt(e,n,a))return{kind:"pay",disabled:!0,reason:"not_enough"};if(F(e)){let s=r??{status:"idle"};if(s.status==="unavailable")return{kind:"pay",disabled:!0,reason:"unavailable"};if(s.status!=="ready")return{kind:"pay",disabled:!0,reason:"checking"};let o=mn(e,n,s.quote);if(o!=="ok")return{kind:"pay",disabled:!0,reason:o};return{kind:"pay",disabled:!1,reason:null}}if(er(e,n)==="none")return{kind:"pay",disabled:!0,reason:"needs_gas"};return{kind:"pay",disabled:!1,reason:null}}function mt(e){return e&&typeof e==="object"?e:{}}var Ga=(e)=>typeof e==="string"&&/^\d+$/.test(e)?BigInt(e):null;function gn(e){let t=mt(e),n=mt(t.pay),a=Ga(n.amount);if(typeof t.option_id!=="string"||a===null||a===0n||typeof n.symbol!=="string"||typeof n.decimals!=="number"||!Number.isInteger(n.decimals))throw Error("Unexpected quote response");if(!Array.isArray(t.txs)||t.txs.length===0)throw Error("Unexpected quote response");let r=t.txs.map((i)=>{let l=mt(i);if(typeof l.to!=="string"||typeof l.data!=="string")throw Error("Unexpected quote response");return{description:typeof l.description==="string"?l.description:"",to:l.to,data:l.data,value:typeof l.value==="string"||typeof l.value==="number"?String(l.value):"0"}}),s=typeof t.expires_at==="string"?Date.parse(t.expires_at):NaN;if(!Number.isFinite(s))throw Error("Unexpected quote response");let o=mt(t.chain);return{optionId:t.option_id,pay:{amount:a,symbol:n.symbol,decimals:n.decimals},txs:r,chainName:typeof o.name==="string"?o.name:null,addChain:o.add_chain&&typeof o.add_chain==="object"?o.add_chain:null,estimatedSeconds:typeof t.estimated_seconds==="number"?t.estimated_seconds:null,expiresAt:s,gasEstimate:Ga(t.gas_estimate)}}function rr(e,t){switch(t.type){case"reset":return{status:"idle"};case"fetch":return{status:"loading",previous:e.status==="ready"?e.quote:e.status==="loading"?e.previous:null};case"ok":if(t.optionId!==void 0&&t.quote.optionId!==t.optionId)return e;return{status:"ready",quote:t.quote};case"fail":return{status:"unavailable"}}}function sr(e,t){return!!e&&t.pay.amount>e.pay.amount}function or(e,t){return Math.max(1000,e.expiresAt-15000-t)}function fn(e,t,n="up"){if(e===0n)return"0";let a=10n**BigInt(t),r=(e%a).toString().padStart(t,"0"),s=r.length-r.replace(/^0+/,"").length,o=Math.min(t,e>=a?4:s+4),i=10n**BigInt(t-o),l=e/i;if(n==="up"&&e%i!==0n)l+=1n;let d=10n**BigInt(o),g=(l%d).toString().padStart(o,"0").replace(/0+$/,"");return`${(l/d).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}${g?`.${g}`:""}`}function uo(e,t){if(t.gasEstimate!==null)return t.gasEstimate*3n/2n;return 10n**BigInt(Math.max(0,(e.native?.decimals??18)-4))}function mn(e,t,n){if(!t||t.status!=="ok")return"ok";if(t.usdc<n.pay.amount)return"not_enough";let a=uo(e,n);if(e.token.native)return t.usdc<n.pay.amount+a?"needs_gas":"ok";return t.native!==null&&t.native<a?"needs_gas":"ok"}function ir(e,t,n){if(!F(e))return null;let a=(s)=>B(n.youPay,{amount:`${fn(s.pay.amount,s.pay.decimals)} ${s.pay.symbol}`}),r=(s)=>s.estimatedSeconds?B(n.youPayTakes,{minutes:Math.max(1,Math.ceil(s.estimatedSeconds/60))}):null;if(t.status==="ready")return{kind:"ready",text:a(t.quote),eta:r(t.quote)};if(t.status==="loading"&&t.previous)return{kind:"refreshing",text:a(t.previous),eta:null,note:n.youPayUpdating};if(t.status==="unavailable")return{kind:"unavailable",text:n.optionUnavailableReason,eta:null};return{kind:"loading",text:n.youPayChecking,eta:null}}function cr(e){if(e.kind==="solana")return"solana";let t=typeof e.chain.id==="number"?e.chain.id:Number(e.chain.id);if(t===1328||t===1329)return"sei";if(t===84532||t===8453)return"base";return null}var Fe=(e)=>!!e&&typeof e.request==="function";function bt(e){let t=e;if(t.isRabby)return"Rabby";if(t.isCoinbaseWallet)return"Coinbase Wallet";if(t.isBraveWallet)return"Brave Wallet";if(t.isPhantom)return"Phantom";if(t.isMetaMask)return"MetaMask";return"your wallet"}function lr(e){if(typeof window>"u")return null;let t=window.ethereum;if(!Fe(t))return null;let n=Array.isArray(t.providers)?t.providers.filter(Fe):[];if(e&&n.length>1){let a=n.find((r)=>bt(r)===e);if(a)return a}return t}var po=/^data:image\/(png|svg\+xml|webp|jpeg|gif);/i;function go(e){let t=e,n=t?.info;if(!n||typeof n.uuid!=="string"||typeof n.name!=="string"||!n.name.trim()||!Fe(t?.provider))return null;let a=typeof n.icon==="string"&&po.test(n.icon)&&n.icon.length<200000?n.icon:null;return{id:n.uuid,name:n.name.trim().slice(0,40),icon:a,provider:t.provider}}function fo(){if(typeof window>"u")return[];let e=window.ethereum;if(!Fe(e))return[];let t=Array.isArray(e.providers)?e.providers.filter(Fe):[];return t.length>1?t:[e]}function dr(e,t={}){let n=t.target??(typeof window>"u"?null:window),a=new Map,r=!1,s=(l)=>{if(!r)e(l)},o=(l)=>{let d=go(l.detail);if(!d)return;for(let[g,h]of a)if(h.provider===d.provider&&g!==d.id)a.delete(g);a.set(d.id,d),s([...a.values()])};n?.addEventListener("eip6963:announceProvider",o);try{n?.dispatchEvent(new Event("eip6963:requestProvider"))}catch{}let i=setTimeout(()=>{if(a.size>0)return;let l=new Map;s((t.legacy??fo)().map((d)=>{let g=bt(d),h=(l.get(g)??0)+1;return l.set(g,h),{id:`legacy:${g}:${h}`,name:g,icon:null,provider:d}}))},t.timeoutMs??150);return()=>{r=!0,clearTimeout(i),n?.removeEventListener("eip6963:announceProvider",o)}}async function ur(e){try{await e.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]})}catch(t){if(gr(t)===4001)throw t}return vn(e)}async function yn(e){try{return(await e.request({method:"eth_accounts"}))?.[0]??null}catch{return null}}async function hn(e){try{let t=await e.request({method:"eth_chainId"}),n=Number.parseInt(t,16);return Number.isFinite(n)?n:null}catch{return null}}async function pr(e,t,n){let a=await e.request({method:"eth_call",params:[{to:t,data:nn(n)},"latest"]});return ze(a)}async function bn(e,t){return ze(await e.request({method:"eth_getBalance",params:[t,"latest"]}))}async function vt(e,t){let[n,a]=await Promise.allSettled([we(e.rpc_urls,"eth_call",[{to:e.token.address,data:nn(t)},"latest"]).then(ze),we(e.rpc_urls,"eth_getBalance",[t,"latest"]).then(ze)]);if(n.status==="rejected")throw n.reason;return{usdc:n.value,native:a.status==="fulfilled"?a.value:null}}function gr(e){let t=e?.code;return typeof t==="number"?t:void 0}async function vn(e){let n=(await e.request({method:"eth_requestAccounts"}))?.[0];if(!n)throw Error("No wallet account available");return n}async function fr(e,t,n){let a=ya(t);if(await hn(e)===t)return;let r=()=>e.request({method:"wallet_switchEthereumChain",params:[{chainId:a}]});try{await r()}catch(s){if(!(gr(s)===4902||/unrecogni[sz]ed chain|not been added/i.test(s instanceof Error?s.message:""))||!n)throw s;if(await e.request({method:"wallet_addEthereumChain",params:[n]}),await hn(e)!==t)await r()}if(await hn(e)!==t)throw Error("The wallet is still on another chain")}async function mr(e,t,n){let a=await e.request({method:"eth_signTypedData_v4",params:[t,va(n)]});return wa(n,t,a)}async function wn(e,t,n={}){let a=n.intervalMs??2000,r=Date.now()+(n.timeoutMs??600000);for(;;){if(n.signal?.aborted)return"unknown";let s=await e.request({method:"eth_getTransactionReceipt",params:[t]}).catch(()=>null);if(s)return s.status==="0x0"?"failed":"confirmed";if(Date.now()>r)return"unknown";await new Promise((o)=>setTimeout(o,a))}}async function hr(e,t,n,a={}){if(n.length===0)throw Error("No transactions to send");for(let r=0;;r++){let s=n[r];a.onStep?.(r,s.description);let o=await e.request({method:"eth_sendTransaction",params:[{from:t,to:s.to,data:s.data,value:ba(s.value)}]});if(r===n.length-1)return o;switch(await wn(e,o,{signal:a.signal,intervalMs:a.intervalMs})){case"confirmed":break;case"failed":throw Error("Transaction reverted");case"unknown":throw Error(a.signal?.aborted?"Cancelled":"Timed out waiting for the transaction to confirm")}}}function mo(e){let t=[],n=new Set,r=Object.freeze({register:(...s)=>{let o=!1;for(let i of s)if(!t.includes(i))t.push(i),o=!0;if(o)n.forEach((i)=>i());return()=>{for(let i of s){let l=t.indexOf(i);if(l>=0)t.splice(l,1)}n.forEach((i)=>i())}}});e.addEventListener("wallet-standard:register-wallet",(s)=>{try{let o=s.detail;if(typeof o==="function")o(r)}catch{}});try{e.dispatchEvent(new CustomEvent("wallet-standard:app-ready",{detail:r}))}catch{}return{get:()=>t.slice(),on:(s)=>(n.add(s),()=>void n.delete(s))}}var ho=null;function br(){if(typeof window>"u")return null;return ho??=mo(window)}function yo(e){return e.chains.some((t)=>t.startsWith("solana:"))&&typeof e.features["standard:connect"]?.connect==="function"&&typeof e.features["solana:signAndSendTransaction"]?.signAndSendTransaction==="function"}function vr(e,t){let n=(e?.get()??[]).filter(yo);return t?[...n].sort((a,r)=>Number(r.name===t)-Number(a.name===t)):n}var yr=(e)=>e?.find((t)=>!t.chains||t.chains.length===0||t.chains.some((n)=>n.startsWith("solana:")))??null;async function xn(e,t={}){let n=e.features["standard:connect"];try{let{accounts:a}=await n.connect(t.silent?{silent:!0}:void 0),r=yr(a)??yr(e.accounts);if(!r){if(t.silent)return null;throw Error("No wallet account available")}return{wallet:e,account:r,address:r.address}}catch(a){if(t.silent)return null;throw a}}var bo="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function vo(e){let t=0;while(t<e.length&&e[t]===0)t++;let n=[];for(let a=t;a<e.length;a++){let r=e[a];for(let s=0;s<n.length;s++)r+=n[s]<<8,n[s]=r%58,r=r/58|0;while(r>0)n.push(r%58),r=r/58|0}return"1".repeat(t)+n.reverse().map((a)=>bo[a]).join("")}function wo(e){let t="";for(let n of e)t+=String.fromCharCode(n);return btoa(t)}function wr(e){let t=atob(e),n=new Uint8Array(t.length);for(let a=0;a<t.length;a++)n[a]=t.charCodeAt(a);return n}async function xr(e,t,n){let a=e.wallet.features["solana:signAndSendTransaction"],[r]=await a.signAndSendTransaction({account:e.account,transaction:wr(t),chain:`solana:${n}`});if(!r?.signature)throw Error("The wallet returned no signature");return vo(r.signature)}async function kr(e,t,n){let a=e.wallet.features["solana:signTransaction"];if(typeof a?.signTransaction!=="function")throw Error("This wallet cannot sign this payment");let[r]=await a.signTransaction({account:e.account,transaction:wr(t),chain:`solana:${n}`});if(!r?.signedTransaction)throw Error("The wallet returned no transaction");return wo(r.signedTransaction)}async function wt(e,t){let[n,a]=await Promise.allSettled([we(e.rpc_urls,"getTokenAccountsByOwner",[t,{mint:e.token.address},{encoding:"jsonParsed"}]),we(e.rpc_urls,"getBalance",[t,{commitment:"confirmed"}])]);if(n.status==="rejected")throw n.reason;let r=n.value?.value??[],s=0n;for(let i of r){let l=i.account?.data?.parsed?.info?.tokenAmount?.amount;if(typeof l==="string"&&/^\d+$/.test(l))s+=BigInt(l)}let o=a.status==="fulfilled"?a.value?.value:void 0;return{usdc:s,native:typeof o==="number"||typeof o==="string"?BigInt(o):null}}async function Cr(e,t,n={}){let a=n.intervalMs??1500,r=Date.now()+(n.timeoutMs??90000);for(;;){if(n.signal?.aborted)return"unknown";let o=(await we(e,"getSignatureStatuses",[[t],{searchTransactionHistory:!0}]).catch(()=>null))?.value?.[0];if(o?.err)return"failed";if(o?.confirmationStatus==="confirmed"||o?.confirmationStatus==="finalized")return"confirmed";if(Date.now()>r)return"unknown";await new Promise((i)=>setTimeout(i,a))}}function ie(e){return!!e&&typeof e==="object"}function Sr(e){return{txs:e.txs,chain:{name:e.chainName,add_chain:e.addChain},estimated_seconds:e.estimatedSeconds,pay:{amount:e.pay.amount.toString(),symbol:e.pay.symbol,decimals:e.pay.decimals},gas_estimate:e.gasEstimate===null?null:e.gasEstimate.toString()}}var xo=new Set(["from","value","validAfter","validBefore","nonce","signature"]);function ko(e){if(!ie(e))throw Error("Unexpected pay response");if(ie(e.sign)&&ie(e.sign.typedData)){let i=ie(e.sign.extra)?Object.fromEntries(Object.entries(e.sign.extra).filter((l)=>typeof l[1]==="string"&&!xo.has(l[0]))):{};return{type:"sign",typedData:e.sign.typedData,extra:i}}let t=e.txs;if(!Array.isArray(t)||t.length===0)throw Error("Unexpected pay response");let n=ie(e.chain)?e.chain:{},a=typeof e.estimated_seconds==="number"?e.estimated_seconds:null,r=t[0];if(ie(r)&&r.kind==="solana"){if(typeof r.transaction!=="string"||!r.transaction)throw Error("Unexpected pay response");return{type:"solana",transaction:r.transaction,sponsored:r.sponsored===!0,estimatedSeconds:a}}let s=t.map((i)=>{if(!ie(i)||typeof i.to!=="string"||typeof i.data!=="string")throw Error("Unexpected pay response");return{description:typeof i.description==="string"?i.description:"",to:i.to,data:i.data,value:typeof i.value==="string"||typeof i.value==="number"?String(i.value):"0"}}),o=ie(e.pay)&&typeof e.pay.amount==="string"&&/^\d+$/.test(e.pay.amount)&&typeof e.pay.symbol==="string"&&typeof e.pay.decimals==="number"?{amount:BigInt(e.pay.amount),symbol:e.pay.symbol,decimals:e.pay.decimals}:null;return{type:"evm",txs:s,chainName:typeof n.name==="string"?n.name:null,addChain:ie(n.add_chain)?n.add_chain:null,estimatedSeconds:a,pay:o,gasEstimate:typeof e.gas_estimate==="string"&&/^\d+$/.test(e.gas_estimate)?BigInt(e.gas_estimate):null}}function Co(e){if(!ie(e)||typeof e.signature!=="string"||!e.signature)throw Error("Unexpected pay response");return e.signature}function Po(e,t,n){return new ne({kind:"insufficient",message:B(n.insufficient,{balance:ve(e),needed:ve(t)}),balance:e.toString(),needed:t.toString()})}function So(e,t,n){let a=(r,s)=>`${fn(r,t.decimals,s)} ${t.symbol}`;return new ne({kind:"insufficient",message:B(n.insufficient,{balance:a(e,"down"),needed:a(t.amount,"up")}),balance:e.toString(),needed:t.amount.toString()})}async function Ao(e,t){try{if(t.kind==="solana")return await wt(e,t.account);try{if(e.token.native){let r=await bn(t.provider,t.account);return{usdc:r,native:r}}let n=await pr(t.provider,e.token.address,t.account),a=await bn(t.provider,t.account).catch(()=>null);return{usdc:n,native:a}}catch{return await vt(e,t.account)}}catch{return null}}async function Pr(e,t){let n=()=>e().then(()=>!0,()=>!1),[a,r]=await Promise.all([n(),t()]);switch(r){case"failed":throw Error("Transaction failed on chain");case"confirmed":if(!a)await n();return;case"unknown":return}}async function Ar(e){try{return await Ro(e)}catch(t){if(ct(t))return{estimatedSeconds:null};throw t}}async function Ro(e){let{option:t,session:n,api:a,hooks:r,copy:s}=e,o=BigInt(e.amount);if(n.kind==="evm")r.step("switching"),await fr(n.provider,Number(t.chain.id),t.add_chain);r.step("checking");let i=await Ao(t,n),l=F(t);if(!l){if(i&&i.usdc<o)throw Po(i.usdc,o,s);if(i&&i.native===0n&&un(t))throw new ne({kind:"no_gas",message:s.noGas})}let d=ko(await a.pay(t.id,n.account));if(l){if(d.type!=="evm"||!d.pay)throw Error("Unexpected pay response");let g=mn(t,i?{status:"ok",...i}:void 0,{pay:d.pay,gasEstimate:d.gasEstimate});if(g==="not_enough")throw So(i?.usdc??0n,d.pay,s);if(g==="needs_gas")throw new ne({kind:"no_gas",message:s.noGas})}if(d.type==="sign"&&n.kind==="evm"){r.step("signing");let g=await mr(n.provider,n.account,d.typedData);return r.step("submitting"),await a.authorize({...g,...d.extra}),{estimatedSeconds:null}}if(d.type==="evm"&&n.kind==="evm"){r.step("signing");let g=await hr(n.provider,n.account,d.txs,{signal:e.signal,intervalMs:e.intervalMs,onStep:(h)=>r.tx?.(h,d.txs.length)});return r.step("submitting"),await Pr(()=>a.fundingAttempt(d.chainName??t.chain.name,g,l?{rail:"lifi",buyer:n.account}:void 0),()=>wn(n.provider,g,{signal:e.signal,intervalMs:e.intervalMs,timeoutMs:e.timeoutMs})),{estimatedSeconds:d.estimatedSeconds}}if(d.type==="solana"&&n.kind==="solana"){r.step("signing");let g=String(t.chain.id),h=d.sponsored?Co(await a.submitSolana(await kr(n.session,d.transaction,g))):await xr(n.session,d.transaction,g);return r.step("submitting"),await Pr(()=>a.fundingAttempt(t.chain.name,h),()=>Cr(t.rpc_urls,h,{signal:e.signal,intervalMs:e.intervalMs,timeoutMs:e.timeoutMs})),{estimatedSeconds:d.estimatedSeconds}}throw Error("Unexpected pay response")}import{jsx as x,jsxs as K,Fragment as Ct}from"react/jsx-runtime";function kt(e,t,n=!0){let a=S(!0);I(()=>{if(a.current){a.current=!1;return}if(n)e.current?.focus({preventScroll:!1})},[t])}var Eo="your wallet",Er=(e)=>e&&e!==Eo?e:null;function No(e){let[t,n]=N([]),a=S([]),[r,s]=N(null),o=S(null),i=S(!1),l=S(new Set),d=W((L)=>{o.current=L,s(L)},[]);I(()=>{if(!e)return;return dr((L)=>{a.current=L,n(L)})},[e]),I(()=>{if(!e||o.current||i.current||t.length===0)return;let L=fe().wallet,p=t.find((f)=>f.name===L)??(t.length===1?t[0]:void 0);if(!p||l.current.has(p.id))return;l.current.add(p.id),yn(p.provider).then((f)=>{if(f&&!o.current&&!i.current)d({provider:p.provider,account:f,name:p.name})})},[e,t,d]);let g=r?.provider;I(()=>{if(!g)return;let L=(p)=>{let f=Array.isArray(p)&&typeof p[0]==="string"?p[0]:null,C=o.current;if(C?.provider===g)d(f?{...C,account:f}:null)};return g.on?.("accountsChanged",L),()=>g.removeListener?.("accountsChanged",L)},[g,d]);let h=W(async(L)=>{let p=a.current,f=L?L:p.find((z)=>z.name===fe().wallet)??(p.length===1?p[0]:null)??(()=>{let z=lr(fe().wallet);return z?{provider:z,name:bt(z)}:null})();if(!f)return null;let te=(o.current?.provider===f.provider?o.current.account:null)??await yn(f.provider)??await vn(f.provider);i.current=!1;let D={provider:f.provider,account:te,name:f.name};return d(D),rn({wallet:D.name}),D},[d]),k=W(()=>{i.current=!0,d(null)},[d]),A=W(async()=>{let L=o.current;if(!L)return;let p=await ur(L.provider);d({...L,account:p})},[d]);return{wallets:t,conn:r,connRef:o,connect:h,disconnect:k,switchAccount:A}}var Lo=/^data:image\/(png|svg\+xml|webp|jpeg|gif);/i,To=(e)=>{let t=e.icon;return typeof t==="string"&&Lo.test(t)?t:null};function Io(e){let[t,n]=N([]),[a,r]=N(null),s=S(null),o=S(!1),i=W((g)=>{s.current=g,r(g)},[]);I(()=>{if(!e)return;let g=br(),h=()=>n(vr(g,fe().wallet));return h(),g?.on(h)},[e]),I(()=>{if(!e||o.current)return;let g=fe().wallet;if(!g)return;let h=t.find((A)=>A.name===g);if(!h)return;let k=!0;return xn(h,{silent:!0}).then((A)=>k&&A&&!s.current&&!o.current&&i({session:A,name:h.name})),()=>{k=!1}},[e,t,i]);let l=W(async(g)=>{let h=g??t[0];if(!h)return null;let k=(s.current?.session.wallet===h?s.current.session:null)??await xn(h);if(!k)return null;o.current=!1;let A={session:k,name:h.name};return i(A),rn({wallet:h.name}),A},[i,t]),d=W(()=>{o.current=!0,s.current?.session.wallet.features["standard:disconnect"]?.disconnect?.().catch(()=>{}),i(null)},[i]);return{wallets:t,conn:a,connRef:s,connect:l,disconnect:d}}var Oo=(e)=>new Promise((t)=>setTimeout(t,e));function Mo({orderId:e,createCharge:t,returnUrl:n,onPaid:a,statusUrl:r,className:s,appearance:o="auto",onStatusChange:i,onError:l,copy:d,successSlot:g,defaultOpen:h=!1,manualPayment:k=!1,presentation:A="modal",merchantName:L}){let p=A==="inline",f=xt(()=>Aa(d),[d]),C=S(f);C.current=f;let te=Nr(),[D,z]=N(h||p),[ue,j]=N(h||p),[V,xe]=N("pick"),[Re,Ir]=N("evm"),[Or,Cn]=N(null),[Mr,Ee]=N(!1),[_r,Pn]=N(0),[jo,Sn]=N(null),[R,An]=N(null),[ke,St]=N(null),[q,At]=N(null),[qe,Rn]=N(null),[O,ce]=Rr(Ma,an),[Rt,En]=N({status:"loading",list:[]}),[Wr,Br]=N(0),[G,Et]=N({}),[Ke,Ne]=Rr(rr,{status:"idle"}),[Dr,Ur]=N(0),[Nt,Nn]=N(null),[jr,Ge]=N(!1),[Le,Ln]=N(!1),[Te,re]=N(null),[Qe,Lt]=N(null),[zr,Tn]=N(!1),[Hr,$r]=N(!1),[Fr,Ie]=N(""),In=S(a);In.current=a;let On=S(r);On.current=r;let Mn=S(i);Mn.current=i;let _n=S(l);_n.current=l;let Wn=S(t);Wn.current=t;let Bn=S(Ke);Bn.current=Ke;let Dn=S(!1),T=No(ue),E=Io(ue),Oe=S(null),se=xt(()=>R?cn(R.serviceUrl,R.chargeId,R.clientSecret):null,[R]),Tt=S(0),Ye=S(null),Un=W(()=>{if(Ye.current)return Ye.current;let m=(async()=>{let y={ok:!1,status:503,error:C.current.createFailed};for(let w=0;w<3;w++){try{y=await Wn.current()}catch{y={ok:!1,status:503,error:C.current.createFailed}}if(y?.ok){let v=ka(y.charge);return v?{ok:!0,charge:v}:{ok:!1,status:503,error:C.current.createFailed}}if(y.status<500)return y;if(w<2)await Oo(700*2**w)}return y})().finally(()=>{Ye.current=null});return Ye.current=m,m},[]),It=S(0),oe=W(async(u)=>{let m=++Tt.current;if(!u)An(null),Oe.current=null,At(null),St(null),Rn(null),ce({type:"reset"});let y=await Un();if(y.ok){if(m===Tt.current)Oe.current=y.charge,An(y.charge),At({status:y.charge.status,confirmed:y.charge.confirmed,confirmation:y.charge.confirmation,funded_amount:null}),St(null);return{ok:!0,charge:y.charge}}let w=Ia(y,C.current);if(!u&&m===Tt.current)St(w);return{ok:!1,problem:w}},[Un]),jn=S(null);I(()=>{if(!ue)return;if(jn.current===e)return;jn.current=e,It.current=0,oe(!1)},[ue,e,oe]),I(()=>{$r(tn(navigator.userAgent))},[]),I(()=>{if(!se||!R)return;let u=!0;return se.options().then((m)=>{if(!u)return;let y=Qa(m);En(y.length?{status:"ready",list:y}:{status:"error",list:[]})}).catch(()=>{if(!u)return;En((m)=>m.status==="ready"?m:{status:"error",list:[]})}),()=>{u=!1}},[se,R,Wr]);let U=Rt.list,Ot=S(U);Ot.current=U;let he=R?.amount??"0",zn=S({evm:0,solana:0}),pe=W(async(u,m)=>{let y=Ot.current.filter((v)=>v.kind===u);if(y.length===0)return;let w=++zn.current[u];Et((v)=>({...v,...Object.fromEntries(y.map((P)=>[P.id,v[P.id]?.status==="ok"?v[P.id]:{status:"loading"}]))})),Pn((v)=>v+1);try{await Promise.all(y.map(async(v)=>{let P;try{let M=u==="evm"?await vt(v,m):await wt(v,m);P={status:"ok",usdc:M.usdc,native:M.native}}catch{P={status:"error"}}if(w===zn.current[u])Et((M)=>({...M,[v.id]:P.status==="error"&&M[v.id]?.status==="ok"?M[v.id]:P}))}))}finally{Pn((v)=>v-1)}},[]),Je=U.map((u)=>u.id).join("|"),ye=T.conn?.account??null,Mt=E.conn?.session.address??null,Ve=W((u)=>{Et((m)=>{let y={...m};for(let w of Ot.current)if(w.kind===u)delete y[w.id];return y})},[]);I(()=>{if(Ve("evm"),ye&&Je)pe("evm",ye)},[ye,Je,pe,Ve]),I(()=>{if(Ve("solana"),Mt&&Je)pe("solana",Mt)},[Mt,Je,pe,Ve]);let Q={evm:!!T.conn,solana:!!E.conn},Xe=new Set(U.map((u)=>u.kind)).size>1,Hn=S(!1),{evm:$n,solana:Fn}=Q;I(()=>{if(U.length===0)return;let u=pn(U,G,{evm:$n,solana:Fn}),m=u.length>0?u:U;Nn((y)=>{let w=y&&m.some((v)=>v.id===y);if(!Hn.current){let v=Za(m,G,he);if(v)return v}return w?y:(m.find((v)=>v.default)??m[0]).id})},[U,G,he,$n,Fn]);let _=U.find((u)=>u.id===Nt)??null,_t=nr(U,G,Q,he),qn=W((u)=>{At((m)=>m&&JSON.stringify(m)===JSON.stringify(u)?m:u)},[]),Kn=q?.status==="settled"||q?.status==="expired",Wt=O.step==="processing"||O.step==="submitting";I(()=>{if(!se||Kn)return;let u=!1,m=new AbortController,y=null,w=(M)=>{let Pe=xa(M);if(Pe&&!u)qn(Pe)},v=()=>{se.charge().then(w).catch(()=>{})},P=()=>{if(y||u)return;v(),y=setInterval(v,Wt?1500:3000)};if(v(),typeof ReadableStream>"u")P();else if(se.events((M)=>{if(M.event!=="charge.updated")return;try{w(JSON.parse(M.data))}catch{}},m.signal).catch(()=>{}).then(P),Wt)y=setInterval(v,1500);return()=>{if(u=!0,m.abort(),y)clearInterval(y)}},[se,Kn,Wt,qn]);let Bt=r===null,Gn=!!q&&q.confirmed,Dt=S(null);I(()=>{Dt.current=null},[R?.chargeId]),I(()=>{if(Bt||!R||!(Gn||O.step==="processing")||qe?.confirmation==="final")return;let u=Pa(R.chargeId,On.current);if(!u)return;let m=!1,y=async()=>{try{let v=await fetch(u,{cache:"no-store"}),P=v.ok?Ca(await v.json().catch(()=>null)):null;if(!P||m)return;if(Rn(P),P.confirmed&&Dt.current!==P.confirmation)Dt.current=P.confirmation,In.current?.(P)}catch{}};y();let w=setInterval(y,O.step==="processing"?1500:3000);return()=>{m=!0,clearInterval(w)}},[Bt,R,Gn,O.step,qe?.confirmation]),I(()=>{if(q?.status!=="expired"||O.step!=="idle")return;if(It.current>=3)return;It.current+=1,oe(!0)},[q,O.step,oe]);let Me=Bt?q?.confirmed?q.confirmation:null:qe?.confirmed?qe.confirmation:null,Y=!!Me;I(()=>{if(Y)ce({type:"paid"})},[Y]),I(()=>{if(O.step!=="processing"){Tn(!1);return}let u=setTimeout(()=>Tn(!0),30000);return()=>clearTimeout(u)},[O.step]);let Ze=R?ve(R.amount):"",H=O.problem??null,X=O.step!=="idle"&&O.step!=="paid";Dn.current=X;let le=_&&F(_)?_:null,et=le?G[le.id]:void 0,Ut=!!le&&!!ye&&(et?.status==="error"||et?.status==="ok"&&et.usdc>0n),tt=le?.id??null,qr=q?.funded_amount??"";I(()=>{if(Ne({type:"reset"}),!se||!R||!tt||!Ut||!ye)return;let u=!0,m=null,y=async()=>{if(!u)return;if(Dn.current){m=setTimeout(y,5000);return}Ne({type:"fetch"});try{let w=gn(await se.lifiQuote(tt,ye));if(!u)return;Ne({type:"ok",quote:w,optionId:tt}),m=setTimeout(y,or(w,Date.now()))}catch(w){if(!u)return;if(ct(w))m=setTimeout(y,5000);else Ne({type:"fail"})}};return m=setTimeout(y,350),()=>{if(u=!1,m)clearTimeout(m)}},[se,R?.chargeId,tt,Ut,ye,qr,Dr]);let _e=ke?"failed":!ue?"ready":!R||!q?"loading":Me==="final"||q.status==="settled"?"settled":Me?"paid":H?"problem":O.step==="signing"?"confirming":O.step==="connecting"||O.step==="switching"||O.step==="checking"||Le?"connecting":O.step==="submitting"||O.step==="processing"?"processing":"ready",Qn=S(null);I(()=>{if(Qn.current===_e)return;Qn.current=_e,Mn.current?.(_e)},[_e]);let jt=ke??H;I(()=>{if(jt)_n.current?.(jt)},[jt]);let Yn=T.conn?{name:Er(T.conn.name),address:T.conn.account}:null,Jn=E.conn?{name:Er(E.conn.name),address:E.conn.session.address}:null,be=_?.kind==="solana"?Jn:_?.kind==="evm"?Yn:Yn??Jn,zt=be?.name??null,nt=Qe&&Qe.total>1&&O.step==="signing"?lt(f,Qe,zt):Wa(O.step,Ze,f,zt);I(()=>{if(Me)Ie(f.received);else if(H?.kind==="rejected")Ie(H.message);else if(X)Ie(nt);else Ie("")},[Me,H,X,nt,f]);let Ht=S(null),at=S(null),Vn=S(null),$t=S(null);kt(Vn,Y,Y),kt(at,H,!!H&&H.kind!=="rejected"),kt(Ht,H?.kind==="rejected"?H:null,H?.kind==="rejected"),kt($t,V,V!=="pick");let Xn=W((u,m)=>{ce({type:"failed",problem:He(u,{step:m,copy:C.current})})},[]),Kr=()=>tn(navigator.userAgent)?C.current.noWalletMobile:C.current.noWallet,We=W((u)=>{Ir(u),re(null),Ge(!1),xe("wallets")},[]),Gr=W(async()=>{if(!_||Le)return;if(re(null),Xe&&T.wallets.length>0&&E.wallets.length>0&&!T.conn&&!E.conn){We("any");return}let m=Xe&&!T.conn&&!E.conn&&T.wallets.length===0&&E.wallets.length>0?"solana":_.kind;if(m==="evm"?T.wallets.length>1&&!T.conn:E.wallets.length>1&&!E.conn){We(m);return}Ln(!0);try{if(!(m==="evm"?await T.connect():await E.connect()))re(m==="evm"?Kr():C.current.noWalletForOption)}catch(y){let w=He(y,{step:"connecting",copy:C.current});re(w.kind==="rejected"?C.current.rejectedConnect:w.message)}finally{Ln(!1)}},[_,Le,T,E,We,Xe]),Zn=(u,m)=>`${m}:${u.name}`,ea=V==="wallets"?fe().wallet:void 0,ta=(u)=>T.wallets.map((m)=>({id:`${u}${m.id}`,name:m.name,icon:m.icon,lastUsed:m.name===ea})),na=(u)=>E.wallets.map((m,y)=>({id:`${u}${Zn(m,y)}`,name:m.name,icon:To(m),lastUsed:m.name===ea})),Qr=V!=="wallets"?[]:Re==="evm"?ta(""):Re==="solana"?na(""):[...ta("evm|"),...na("solana|")],Yr=async(u)=>{Cn(u),re(null);let m=Re==="any"?/^(evm|solana)\|(.*)$/.exec(u):null,y=m?m[1]:Re==="any"?"evm":Re,w=m?m[2]:u;try{let v=!1;if(y==="evm"){let P=T.wallets.find((M)=>M.id===w);v=!!P&&!!await T.connect(P)}else{let P=E.wallets.findIndex((Pe,J)=>Zn(Pe,J)===w),M=E.wallets[P];v=!!M&&!!await E.connect(M)}if(v)xe("pick")}catch(v){let P=He(v,{step:"connecting",copy:C.current});re(P.kind==="rejected"?C.current.rejectedPick:P.message)}finally{Cn(null)}},ge=W(async()=>{if(T.connRef.current)await pe("evm",T.connRef.current.account);if(E.connRef.current)await pe("solana",E.connRef.current.session.address)},[T.connRef,E.connRef,pe]),aa=W(async()=>{ce({type:"reset"}),re(null),await ge()},[ge]),Jr=(u)=>u.kind==="evm"?T.conn?{kind:"evm",provider:T.conn.provider,account:T.conn.account}:null:E.conn?{kind:"solana",session:E.conn.session,account:E.conn.session.address}:null,Vr=W(async()=>{let u=_,m=u?Jr(u):null;if(!u||!m||!Oe.current)return;ce({type:"start"}),Lt(null),Sn(null),Ee(!1);let y="connecting",w=Oe.current;try{for(let v=0;;v++)try{if(w.expiresAt&&Date.parse(w.expiresAt)-Date.now()<30000){let J=await oe(!0);if(!J.ok)throw new ne(J.problem);w=J.charge}let P=cn(w.serviceUrl,w.chargeId,w.clientSecret),M=F(u)?{...P,pay:async(J,Vt)=>{let st=Bn.current,fs=st.status==="ready"?st.quote:st.status==="loading"?st.previous:null,Xt=gn(await P.lifiQuote(J,Vt));if(Ne({type:"ok",quote:Xt,optionId:J}),sr(fs,Xt))throw new ne({kind:"service",message:C.current.priceChanged});return Sr(Xt)}}:P,Pe=await Ar({option:u,session:m,amount:w.amount,api:M,copy:C.current,hooks:{step:(J)=>{y=J,ce({type:"step",step:J})},tx:(J,Vt)=>Lt({i:J,total:Vt})}});Sn(Pe.estimatedSeconds),ce({type:"submitted"});return}catch(P){if(v===0&&Oa(P)){let M=await oe(!0);if(M.ok){w=M.charge;continue}ce({type:"failed",problem:{...M.problem}});return}throw P}}catch(v){if(v instanceof ne&&(v.problem.kind==="insufficient"||v.problem.kind==="no_gas"))ge();Xn(v,y)}finally{Lt(null)}},[_,T.conn,E.conn,oe,Xn,ge]),Xr=xt(()=>Va(U,G,{evm:Q.evm,solana:Q.solana},he),[U,G,Q.evm,Q.solana,he]),ra=xt(()=>{let u=Xa(U.map(ht));return new Map(U.map((m,y)=>[m.id,{...u[y],icon:cr(m)}]))},[U]),Zr=(u)=>u==="not_enough"?f.notEnough:u==="needs_wallet"?f.needsOtherWallet:u==="unreadable"?f.couldntCheck:null,es=new Set(pn(U,G,Q).map((u)=>u.id)),ts=Xr.filter((u)=>es.has(u.id)).map((u)=>{let m=Ja(u,G[u.id],he,Q);return{id:u.id,chain:ht(u),badge:ra.get(u.id)??null,balanceText:m.balanceText,disabled:m.disabled,reason:Zr(m.reason),loading:m.loading,...F(u)?{symbol:u.token.symbol,logo:u.token.logo}:{}}}),de=ar(_,Q,_?G[_.id]:void 0,he,Ke),Ft=de.reason==="needs_gas",qt=_t==="empty"||_t==="short",sa=qt||Ft||H?.kind==="insufficient"||H?.kind==="no_gas",ns=X?{label:nt,disabled:!0,busy:!0,onClick:()=>{},ref:Ht}:{label:(()=>de.kind==="connect"?Le?f.connectingWallet:f.connectWallet:de.reason==="checking"?le&&et?.status==="ok"?f.youPayChecking:f.checking:de.reason==="not_enough"?le?B(f.notEnoughToken,{symbol:le.token.symbol}):f.notEnoughUsdc:de.reason==="needs_gas"?f.needsGas:de.reason==="unavailable"?f.optionUnavailable:B(f.pay,{amount:Ze}))(),disabled:de.disabled||!R,busy:Le,spinner:de.reason==="checking",onClick:()=>void(de.kind==="connect"?Gr():Vr()),ref:Ht};I(()=>{if(!sa||!D)return;let u=()=>{if(document.visibilityState==="visible")ge()};return window.addEventListener("focus",u),document.addEventListener("visibilitychange",u),()=>{window.removeEventListener("focus",u),document.removeEventListener("visibilitychange",u)}},[sa,D,ge]);let rt=(qt||Ft)&&D;I(()=>{if(!rt)return;let u=Date.now(),m=setInterval(()=>{if(Date.now()-u>120000)clearInterval(m);else ge()},5000);return()=>clearInterval(m)},[rt,ge]);let Be=U.filter((u)=>Q[u.kind]).map((u)=>{let m=G[u.id];return m?.status==="ok"?`${u.id}:${m.usdc}:${m.native??""}`:m?.status??"-"}).join("|"),Kt=S(null),oa=S(!1);I(()=>{if(!Be.includes("loading")&&!Be.includes("-")){if(oa.current&&Kt.current!==null&&Kt.current!==Be)Ie(C.current.balanceUpdated);Kt.current=Be}oa.current=rt},[Be,rt]);let as=W(()=>{j(!0),xe("pick"),Ge(!1),Ee(!1),z(!0)},[]),De=W(()=>{z(!1)},[]);I(()=>{if(!D||O.step!=="idle")return;let u=Oe.current;if(u?.expiresAt&&Date.parse(u.expiresAt)-Date.now()<120000)oe(!0)},[D]);let ia=W(()=>{if(X&&!Y)Ee((u)=>!u);else De()},[X,Y,De]);I(()=>{if(!X||Y)Ee(!1)},[X,Y]);let ca={className:`sc-root${s?` ${s}`:""}`,"data-appearance":o,"data-testid":"payments-checkout","data-state":_e},Gt=x("div",{className:"sc-live",role:"status","aria-live":"polite","aria-atomic":"true","data-testid":"sc-live",children:Fr}),Qt=Sa(n,typeof window>"u"?"":window.location.origin),Yt=q?.status==="underpaid"&&R?Na(R.amount,q.funded_amount):null,rs=be&&_?{onCopy:()=>{try{navigator.clipboard?.writeText(be.address)?.catch(()=>{})}catch{}},onSwitch:()=>{let u=_.kind;if(Xe&&T.wallets.length>0&&E.wallets.length>0)We("any");else if(u==="evm"?T.wallets.length>1:E.wallets.length>1)We(u);else if(u==="evm")T.switchAccount().catch((m)=>{let y=He(m,{step:"connecting",copy:C.current});if(y.kind!=="rejected")re(y.message)});else E.disconnect(),E.connect().catch(()=>{})},onDisconnect:()=>{if(Ge(!1),re(null),_.kind==="evm")T.disconnect();else E.disconnect()}}:null,la=x("button",{type:"button",className:"sc-sec",onClick:()=>void aa(),children:f.checkAgain}),ss=x("button",{type:"button",className:"sc-link",onClick:()=>void aa(),children:f.checkAgain}),os=k?x("button",{type:"button",className:"sc-link",onClick:()=>xe("manual"),children:f.payAnotherWay}):null,Ce=typeof window>"u"?"":window.location.href,is=Te===f.noWallet||Te===f.noWalletMobile,cs=Yt!==null&&Yt>0n?B(f.partial,{received:ve(BigInt(q?.funded_amount||"0")),remaining:ve(Yt)}):Te?K(Ct,{children:[Te,Hr&&is&&_?.kind==="evm"&&(ot(Ce)||it(Ce))&&K("div",{className:"sc-actions",children:[ot(Ce)&&x("a",{className:"sc-link",href:ot(Ce),children:f.openInWalletApp}),it(Ce)&&x("a",{className:"sc-link",href:it(Ce),children:f.openInPhantom})]})]}):qt?K(Ct,{children:[_t==="empty"?f.noUsdc:f.insufficientAll,la]}):Ft?K(Ct,{children:[f.needsGasReason,la]}):null,ls=(u)=>{switch(u.kind){case"insufficient":case"no_gas":return ss;case"expired":case"conflict":return x("button",{type:"button",className:"sc-link",onClick:()=>void oe(!1),children:f.startNew});case"network":case"service":case"unknown":case"tx_failed":return x("button",{type:"button",className:"sc-link",onClick:()=>ce({type:"reset"}),children:f.tryAgain});default:return null}},da=!ke&&R&&Rt.status==="error"?{kind:"service",message:f.service}:null,ds=ke?x(ft,{problem:ke,copy:f,noticeRef:at,children:x("button",{type:"button",className:"sc-link",onClick:()=>void oe(!1),children:ke.kind==="conflict"?f.startNew:f.tryAgain})}):da?K(ft,{problem:da,copy:f,noticeRef:at,children:[x("button",{type:"button",className:"sc-link",onClick:()=>Br((u)=>u+1),children:f.tryAgain}),os]}):H?x(ft,{problem:H,copy:f,noticeRef:at,children:ls(H)}):null,us=!!R&&!!q&&Rt.status==="ready",ps=Y?"done":V==="manual"&&R?"manual":!us?"loading":X?"paying":V==="wallets"?"wallets":"pick",Jt=R?Ya(R,U):null,gs=R&&Jt?x(_o,{entry:{address:R.chargeAddress,chain:ht(Jt),badge:ra.get(Jt.id)??null},copy:f,amountText:Ze}):null,ua=_&&Q[_.kind]?tr(_,G[_.id],f):[],pa=x(qa,{copy:f,titleId:te,titleRef:$t,title:Ba(f,L),amountText:Ze,phase:ps,wallet:be?{name:be.name,short:Zt(be.address),address:be.address}:null,walletActions:rs,walletPicker:V==="wallets"?{wallets:Qr,busyId:Or,onPick:(u)=>void Yr(u)}:null,onClose:p?null:ia,onBack:()=>xe("pick"),options:ts,selectedId:Nt,menuOpen:jr,onMenuChange:Ge,onSelect:(u)=>{Hn.current=!0,re(null),Nn(u);let m=U.find((w)=>w.id===u),y=m?.kind==="evm"?T.connRef.current?.account:E.connRef.current?.session.address;if(m&&y&&G[u]?.status==="error")pe(m.kind,y)},decorator:ua,payLine:le&&Q.evm&&Ut?ir(le,Ke,f):null,onPayLineRetry:()=>Ur((u)=>u+1),decoratorKey:Nt,refreshing:_r>0&&ua.length>0,cta:ns,message:V==="wallets"?Te:cs,notice:ds,stages:X?_a(O.step):null,tx:Qe,walletName:zt,slow:zr,closeGuard:Mr?{onStay:()=>Ee(!1),onClose:De}:null,done:Y&&R?{receipt:Ea(R.chargeId),finalizing:!1,slot:g,returnHref:Qt,ref:Vn,onDone:p?void 0:De}:null,manual:gs,onPayAnotherWay:R&&k?()=>xe("manual"):null});if(p)return K("div",{...ca,children:[x("style",{children:sn}),Gt,pa]});let ga=X&&!Y?nt:null;return K("div",{...ca,children:[x("style",{children:sn}),!D&&Gt,Y&&!D?K("div",{"data-testid":"sc-inline-done",children:[x("p",{className:"sc-inline-ok",role:"status",children:f.received}),g?x("div",{className:"sc-slot",children:g}):null,Qt&&x("a",{className:"sc-link-a",href:Qt,children:f.returnToStore})]}):x("button",{type:"button",className:"sc-btn","aria-haspopup":"dialog","aria-busy":!!ga,"data-testid":"sc-trigger",onClick:as,children:x("span",{children:ga??f.trigger})}),K(Fa,{open:D,onClose:ia,onBackdrop:X&&!Y?()=>{}:De,titleId:te,initialFocus:$t,children:[Gt,pa]})]})}function kn(e,t){return e.split("{network}").flatMap((n,a)=>a===0?[n]:[x("strong",{className:"sc-net",children:t},a),n])}function _o({entry:e,copy:t,amountText:n}){let[a,r]=N(!1),[s,o]=N(!1),i=S(null),l=S(null),d=Nr();I(()=>()=>{if(i.current)clearTimeout(i.current)},[]);let g=(k)=>{r(k),o(!1)};async function h(k){let A=!1;try{await navigator.clipboard.writeText(k),A=!0}catch{let L=l.current;if(L){let p=document.createRange();p.selectNodeContents(L);let f=window.getSelection();f?.removeAllRanges(),f?.addRange(p);try{A=document.execCommand("copy")}catch{A=!1}}}if(A){if(o(!0),i.current)clearTimeout(i.current);i.current=setTimeout(()=>o(!1),2000)}}return K("div",{"data-testid":"sc-manual",children:[K("span",{className:"sc-chip",children:[x(ut,{badge:e.badge}),x(pt,{chain:e.chain})]}),x("div",{className:"sc-notice","data-kind":"manual",role:"note",id:d,"data-testid":"sc-manual-warning",children:kn(t.manualWarning,e.chain)}),K("label",{className:"sc-confirm",children:[x("input",{type:"checkbox",checked:a,onChange:(k)=>g(k.target.checked),"aria-describedby":d,"data-testid":"sc-manual-confirm"}),x("span",{children:kn(t.manualConfirm,e.chain)})]}),a&&K(Ct,{children:[x("p",{className:"sc-muted",children:B(t.manualIntro,{amount:n})}),x("code",{className:"sc-addr",ref:l,"data-testid":"charge-address",title:Zt(e.address),children:e.address}),x("div",{className:"sc-two",children:K("button",{type:"button",className:"sc-btn",onClick:()=>void h(e.address),"data-testid":"sc-copy",children:[s?x($e,{size:18}):x(on,{}),x("span",{children:s?t.copied:t.copyAddress})]})})]}),x("p",{className:"sc-live",role:"status","aria-live":"polite",children:s?t.copied:""}),x("p",{className:"sc-muted",children:t.manualWaiting}),x("p",{className:"sc-muted","data-testid":"sc-manual-own-wallet",children:kn(t.manualOwnWallet,e.chain)})]})}var Lr={ok:!1,status:503,error:"Checkout is temporarily unavailable."},Tr=(e)=>!!e&&typeof e==="object"&&!Array.isArray(e),Pt=(e)=>typeof e==="string"?e:void 0,Wo=(e)=>Tr(e)?{error:Pt(e.error),code:Pt(e.code)}:{};async function Bo(e){let t=new Headers({"content-type":"application/json"}),n=typeof e==="function"?await e():e;if(n)new Headers(n).forEach((a,r)=>t.set(r,a));return t}function Do(e,t,n){let a=(()=>{try{return n(t)??{}}catch{return{}}})(),r=Pt(a.code);return{ok:!1,status:e,error:Pt(a.error)??"Checkout is temporarily unavailable.",...r?{code:r}:{}}}async function Uo(e,t,n={}){let{method:a="POST",credentials:r,signal:s,selectCharge:o=(l)=>l,selectError:i=Wo}=n;try{let d=await(n.fetch??fetch)(e,{method:a,headers:await Bo(n.headers),body:typeof t==="string"?t:JSON.stringify(t),...r?{credentials:r}:{},...s?{signal:s}:{}}),g=await d.json().catch(()=>null);if(!d.ok)return Do(d.status,g,i);let h=o(g);return Tr(h)?{ok:!0,charge:h}:Lr}catch{return Lr}}export{Mo as PaymentsCheckout,Uo as postCreateCharge};
|
|
207
|
+
`,ee=({children:e,size:t=20,className:n})=>c("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",className:n,children:e}),ut=({small:e})=>c(ee,{className:e?"sc-spin sc-spin-s":"sc-spin",children:c("path",{d:"M21 12a9 9 0 1 1-6.2-8.55"})}),$a=()=>c(ee,{size:16,className:"sc-chev",children:c("path",{d:"m6 9 6 6 6-6"})}),No=()=>c(ee,{size:16,children:c("path",{d:"m15 18-6-6 6-6"})}),$e=({size:e=16})=>c(ee,{size:e,children:c("path",{d:"M5 12.5l4.5 4.5L19 7.5"})}),sn=()=>b(ee,{size:16,children:[c("rect",{x:"9",y:"9",width:"11",height:"11",rx:"2"}),c("path",{d:"M5 15V6a2 2 0 0 1 2-2h9"})]}),Lo=()=>b(ee,{size:16,children:[c("path",{d:"M7 7h12l-3-3"}),c("path",{d:"M17 17H5l3 3"})]}),To=()=>b(ee,{size:16,children:[c("path",{d:"M12 3v8"}),c("path",{d:"M6.3 7.3a8 8 0 1 0 11.4 0"})]}),Io=()=>c(ee,{size:14,children:c("path",{d:"M8 5v14M16 5v14"})}),Oo=()=>c(ee,{size:14,children:c("path",{d:"M7 4.5v15l12-7.5z"})}),Mo=()=>b(ee,{children:[c("circle",{cx:"12",cy:"12",r:"9"}),c("path",{d:"M12 8v5"}),c("path",{d:"M12 16.5h.01"})]}),_o=()=>b(ee,{children:[c("circle",{cx:"12",cy:"12",r:"9"}),c("path",{d:"M12 11v5"}),c("path",{d:"M12 7.5h.01"})]});function Wo({size:e=28}){return b("svg",{className:"sc-logo",width:e,height:e,viewBox:"0 0 32 32","aria-hidden":"true",focusable:"false",children:[c("circle",{cx:"16",cy:"16",r:"16",fill:"#2775CA"}),c("path",{d:"M20.4 18.2c0-2.3-1.4-3.1-4.2-3.4-2-.3-2.4-.8-2.4-1.7 0-.9.7-1.4 2-1.4 1.2 0 1.9.4 2.2 1.4.1.2.3.3.5.3h1.1c.3 0 .5-.2.5-.5v-.1c-.3-1.4-1.4-2.4-2.9-2.6V8.3c0-.3-.2-.5-.5-.5h-1c-.3 0-.5.2-.5.5v1.4c-2 .3-3.2 1.6-3.2 3.2 0 2.2 1.3 3 4.1 3.3 1.9.4 2.5.8 2.5 1.8s-.9 1.6-2.2 1.6c-1.7 0-2.3-.7-2.5-1.7-.1-.3-.3-.4-.5-.4h-1.2c-.3 0-.5.2-.5.5v.1c.3 1.6 1.3 2.5 3.4 2.8v1.5c0 .3.2.5.5.5h1c.3 0 .5-.2.5-.5v-1.5c2-.3 3.3-1.7 3.3-3.4z",fill:"#fff"}),c("path",{d:"M12.6 25.2C7.7 23.4 5.2 18 7 13.2c.9-2.5 2.9-4.4 5.4-5.3.3-.1.4-.3.4-.6v-1c0-.3-.2-.5-.5-.5-.1 0-.1 0-.2.1C6 7.8 3 14.4 5.2 20.5c1.3 3.6 4.1 6.4 7.7 7.7.3.1.6 0 .6-.3.1-.1.1-.2.1-.2v-1c0-.2-.3-.4-.5-.6-.2-.1-.3-.1-.5-.1zM19.4 4.3c-.3-.1-.6 0-.6.3-.1.1-.1.2-.1.2v1c0 .3.3.5.5.6 4.9 1.8 7.4 7.2 5.6 12-.9 2.5-2.9 4.4-5.4 5.3-.3.1-.4.3-.4.6v1c0 .3.2.5.5.5.1 0 .1 0 .2-.1 6-1.9 9-8.5 6.8-14.6-1.3-3.7-4.2-6.5-7.1-7.8z",fill:"#fff"})]})}var Bo=["M11.9969 23.9965H11.9965L11.9967 23.9965L11.9969 23.9965Z","M16.085 19.5256C16.8061 18.8689 17.9092 18.869 18.6303 19.5258L18.6305 19.5259L20.091 20.8558C17.957 22.8065 15.1158 23.9965 11.9967 23.9965C8.88824 23.9964 6.05591 22.8147 3.92448 20.876L5.4072 19.5259L5.40734 19.5258C6.12844 18.869 7.23147 18.8689 7.95265 19.5256L9.25088 20.7087L9.25109 20.7089C10.8195 22.1374 13.2182 22.1374 14.7866 20.7089L14.7868 20.7087L16.085 19.5256L16.085 19.5256Z","M11.9965 0C15.1214 0 17.9672 1.19421 20.1025 3.15105C20.0412 3.20075 19.981 3.25245 19.922 3.30619L19.9218 3.30636L18.6236 4.48944C17.9025 5.14605 16.7996 5.14605 16.0785 4.48944L14.7803 3.30636L14.78 3.30619L14.7431 3.27296C13.1742 1.87772 10.8007 1.88883 9.24454 3.30622L5.92566 6.32832L7.42038 7.96939L10.7394 4.94715L10.7395 4.94704C11.4607 4.29025 12.5637 4.29016 13.2849 4.94683L14.5831 6.12991L14.5833 6.13012C16.1517 7.55866 18.5504 7.55866 20.1188 6.13012L20.119 6.12994L21.4172 4.94687L21.4172 4.94683C21.4753 4.89391 21.5359 4.8453 21.5986 4.80091C23.1043 6.80592 23.9965 9.2979 23.9965 11.9983C23.9965 14.7069 23.0988 17.2058 21.5847 19.2139L20.1253 17.885L20.1253 17.8849C18.5569 16.4564 16.1582 16.4564 14.5898 17.8849L14.5896 17.8851L13.2914 19.0682C12.5703 19.7248 11.4674 19.7248 10.7463 19.0682L9.44805 17.8851L9.44784 17.8849L9.41092 17.8517C7.842 16.4565 5.46849 16.4676 3.91233 17.885L2.42664 19.2378C1.38127 17.8584 0.627365 16.2461 0.256536 14.4924L2.73458 12.236L2.73472 12.2359C3.45586 11.579 4.55861 11.579 5.27978 12.2358L6.57837 13.4188L6.57847 13.4189C8.14681 14.8474 10.5455 14.8476 12.1137 13.4188L13.4122 12.2358C14.1334 11.579 15.2365 11.579 15.9577 12.2359L15.9578 12.236L19.2769 15.2582L20.7716 13.6171L17.4527 10.595L17.4527 10.595C15.8843 9.16646 13.4856 9.16646 11.9172 10.595L11.9171 10.5951L10.6185 11.7782L10.6185 11.7782C9.89779 12.4348 8.79476 12.435 8.07352 11.7782L6.77493 10.5951L6.77486 10.595L6.73795 10.5618C5.16903 9.16654 2.79587 9.17765 1.23971 10.595L0 11.7239C0.145876 5.22438 5.46071 7.07913e-06 11.9965 0Z"],Do="M0,101.12c0-34.64,0-51.95,6.53-65.28,6.25-12.76,16.56-23.07,29.32-29.32C49.17,0,66.48,0,101.12,0h1077.76c34.63,0,51.96,0,65.28,6.53,12.75,6.25,23.06,16.56,29.32,29.32,6.52,13.32,6.52,30.64,6.52,65.28v1077.76c0,34.63,0,51.96-6.52,65.28-6.26,12.75-16.57,23.06-29.32,29.32-13.32,6.52-30.65,6.52-65.28,6.52H101.12c-34.64,0-51.95,0-65.28-6.52-12.76-6.26-23.07-16.57-29.32-29.32-6.53-13.32-6.53-30.65-6.53-65.28V101.12Z",Uo="M100.48 69.3817L83.8068 86.8015C83.4444 87.1799 83.0058 87.4816 82.5185 87.6878C82.0312 87.894 81.5055 88.0003 80.9743 88H1.93563C1.55849 88 1.18957 87.8926 0.874202 87.6912C0.558829 87.4897 0.31074 87.2029 0.160416 86.8659C0.0100923 86.529 -0.0359181 86.1566 0.0280382 85.7945C0.0919944 85.4324 0.263131 85.0964 0.520422 84.8278L17.2061 67.408C17.5676 67.0306 18.0047 66.7295 18.4904 66.5234C18.9762 66.3172 19.5002 66.2104 20.0301 66.2095H99.0644C99.4415 66.2095 99.8104 66.3169 100.126 66.5183C100.441 66.7198 100.689 67.0067 100.84 67.3436C100.99 67.6806 101.036 68.0529 100.972 68.415C100.908 68.7771 100.737 69.1131 100.48 69.3817ZM83.8068 34.3032C83.4444 33.9248 83.0058 33.6231 82.5185 33.4169C82.0312 33.2108 81.5055 33.1045 80.9743 33.1048H1.93563C1.55849 33.1048 1.18957 33.2121 0.874202 33.4136C0.558829 33.6151 0.31074 33.9019 0.160416 34.2388C0.0100923 34.5758 -0.0359181 34.9482 0.0280382 35.3103C0.0919944 35.6723 0.263131 36.0083 0.520422 36.277L17.2061 53.6968C17.5676 54.0742 18.0047 54.3752 18.4904 54.5814C18.9762 54.7875 19.5002 54.8944 20.0301 54.8952H99.0644C99.4415 54.8952 99.8104 54.7879 100.126 54.5864C100.441 54.3849 100.689 54.0981 100.84 53.7612C100.99 53.4242 101.036 53.0518 100.972 52.6897C100.908 52.3277 100.737 51.9917 100.48 51.723L83.8068 34.3032ZM1.93563 21.7905H80.9743C81.5055 21.7907 82.0312 21.6845 82.5185 21.4783C83.0058 21.2721 83.4444 20.9704 83.8068 20.592L100.48 3.17219C100.737 2.90357 100.908 2.56758 100.972 2.2055C101.036 1.84342 100.99 1.47103 100.84 1.13408C100.689 0.79713 100.441 0.510296 100.126 0.308823C99.8104 0.107349 99.4415 1.24074e-05 99.0644 0L20.0301 0C19.5002 0.000878397 18.9762 0.107699 18.4904 0.313848C18.0047 0.519998 17.5676 0.821087 17.2061 1.19848L0.524723 18.6183C0.267681 18.8866 0.0966198 19.2223 0.0325185 19.5839C-0.0315829 19.9456 0.0140624 20.3177 0.163856 20.6545C0.31365 20.9913 0.561081 21.2781 0.875804 21.4799C1.19053 21.6817 1.55886 21.7896 1.93563 21.7905Z";function jo({icon:e}){if(e==="sei")return b("svg",{viewBox:"0 0 24 24",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:[c("rect",{width:"24",height:"24",fill:"#000"}),c("g",{transform:"translate(4 4) scale(0.6667)",fill:"#fff",children:Bo.map((t,n)=>c("path",{d:t},n))})]});if(e==="base")return c("svg",{viewBox:"0 0 1280 1280",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:c("path",{d:Do,fill:"#0000FF"})});return b("svg",{viewBox:"0 0 24 24",width:"100%",height:"100%","aria-hidden":"true",focusable:"false",children:[c("rect",{width:"24",height:"24",fill:"#000"}),c("defs",{children:b("linearGradient",{id:"sc-sol-grad",x1:"8.52558",y1:"90.0973",x2:"88.9933",y2:"-3.01622",gradientUnits:"userSpaceOnUse",children:[c("stop",{offset:"0.08",stopColor:"#9945FF"}),c("stop",{offset:"0.5",stopColor:"#5497D5"}),c("stop",{offset:"0.97",stopColor:"#19FB9B"})]})}),c("g",{transform:"translate(4.5 5.2) scale(0.1485)",children:c("path",{d:Uo,fill:"url(#sc-sol-grad)"})})]})}var zo={usdt:"#26A17B",eth:"#627EEA",pol:"#8247E5",usdc:"#2775CA"},Ho={usdt:"₮",eth:"Ξ"};function $o({token:e,size:t=28}){let n=e.logo.toLowerCase(),a=Ho[n]??(/[\p{L}\p{N}]/u.exec(e.symbol)?.[0]??"•").toUpperCase();return b("svg",{className:"sc-glyph",width:t,height:t,viewBox:"0 0 32 32","aria-hidden":"true",focusable:"false","data-token":n,children:[c("circle",{cx:"16",cy:"16",r:"16",fill:zo[n]??"#475569"}),c("text",{x:"16",y:"21.5",textAnchor:"middle",fontSize:"16",fontWeight:"700",fill:"#fff",fontFamily:"system-ui,sans-serif",children:a})]})}function dt({size:e=28,badge:t,token:n}){let a=!!n&&n.logo.toLowerCase()!=="usdc";return b("span",{className:"sc-mark",style:{width:e,height:e},children:[a?c($o,{token:n,size:e}):c(Wo,{size:e}),t?t.icon?c("span",{className:"sc-badge sc-badge-icon","data-icon":t.icon,"aria-hidden":"true",children:c(jo,{icon:t.icon})}):c("span",{className:"sc-badge","data-hue":t.hue,"aria-hidden":"true",children:t.letter}):null]})}function Fo(){return b("svg",{className:"sc-check",viewBox:"0 0 64 64","aria-hidden":"true",focusable:"false",children:[c("circle",{cx:"32",cy:"32",r:"28"}),c("path",{d:"M20 33l8 8 16-17"})]})}function pt({chain:e,symbol:t="USDC"}){return b("span",{className:"sc-tok",children:[t,c("sub",{children:e})]})}function qo({options:e,selectedId:t,open:n,locked:a,label:r,amount:o,onOpenChange:s,onSelect:i}){let l=ae(null),u=ae(null),g=e.find((p)=>p.id===t)??e[0]??null,h=e.length<=1,k=!h&&!a;Z(()=>{if(!n)return;let p=u.current?.querySelectorAll('[role="option"]'),f=Math.max(0,e.findIndex((D)=>D.id===t));p?.[f]?.focus({preventScroll:!0});let C=setTimeout(()=>{u.current?.closest(".sc-card")?.querySelector('[data-testid="sc-pay"]')?.scrollIntoView({block:"nearest",behavior:"smooth"})},240),te=(D)=>{let z=D.target;if(z&&!u.current?.contains(z)&&!l.current?.contains(z))s(!1)};return document.addEventListener("pointerdown",te,!0),()=>{clearTimeout(C),document.removeEventListener("pointerdown",te,!0)}},[n]);let R=(p)=>{let f=Array.from(u.current?.querySelectorAll('[role="option"]')??[]);if(f.length===0)return;let C=f.indexOf(document.activeElement),te=p==="first"?0:p==="last"?f.length-1:Math.min(f.length-1,Math.max(0,C+p));f[te]?.focus()},L=(p)=>{if(p.key==="Escape")p.preventDefault(),p.stopPropagation(),s(!1),l.current?.focus();else if(p.key==="ArrowDown")p.preventDefault(),R(1);else if(p.key==="ArrowUp")p.preventDefault(),R(-1);else if(p.key==="Home")p.preventDefault(),R("first");else if(p.key==="End")p.preventDefault(),R("last");else if(p.key==="Tab")s(!1)};return b(gt,{children:[b("div",{className:"sc-box",children:[c("div",{className:"sc-pick",children:b("button",{ref:l,type:"button",className:"sc-tok-btn","aria-haspopup":h?void 0:"listbox","aria-expanded":h?void 0:n,"aria-disabled":h||a,"aria-label":g?`${r}: ${g.symbol??"USDC"} ${g.chain}`:r,"data-testid":"sc-token","data-single":h?"true":void 0,onClick:()=>{if(k)s(!n)},onKeyDown:(p)=>{if((p.key==="ArrowDown"||p.key==="ArrowUp")&&k)p.preventDefault(),s(!0)},children:[c(dt,{badge:g?.badge,token:g?.symbol?{symbol:g.symbol,logo:g.logo??g.symbol.toLowerCase()}:null}),g?c(pt,{chain:g.chain,symbol:g.symbol}):c("span",{className:"sc-tok",children:"USDC"}),k&&c($a,{})]})}),o]}),n&&!h&&c("div",{ref:u,className:"sc-menu",role:"listbox","aria-label":r,onKeyDown:L,"data-testid":"sc-menu",children:e.map((p,f)=>b("button",{type:"button",role:"option",className:"sc-opt",style:{"--i":Math.min(f,3)},"aria-selected":p.id===t,"aria-disabled":p.disabled,"data-testid":"sc-option",onClick:()=>{if(p.disabled)return;i(p.id),s(!1),l.current?.focus()},children:[b("span",{className:"sc-opt-main",children:[c(dt,{badge:p.badge,token:p.symbol?{symbol:p.symbol,logo:p.logo??p.symbol.toLowerCase()}:null}),c(pt,{chain:p.chain,symbol:p.symbol})]}),p.loading?c("span",{className:"sc-sk",style:{width:56,height:14},"data-testid":"sc-row-skeleton","aria-hidden":"true"}):p.balanceText!==null||p.reason?b("span",{className:"sc-opt-bal","data-muted":p.disabled?"true":void 0,children:[p.balanceText!==null&&c("span",{children:p.balanceText}),p.reason&&c("span",{className:"sc-opt-sub",children:p.reason})]}):null,c("span",{className:"sc-opt-check","aria-hidden":"true",children:p.id===t?c($e,{}):null})]},p.id))})]})}function Ko({items:e,paused:t,lowGas:n,pauseLabel:a,optionKey:r,interval:o=2500}){let s=e.findIndex((j)=>j.warn),[i,l]=me(Math.max(0,s)),[u,g]=me(!1),[h,k]=me(!1),[R,L]=me(!1),p=e.map((j)=>j.label).join("|"),f=e.map((j)=>j.value).join(", "),[C,te]=me(f),D=ae(r??null);Z(()=>l(Math.max(0,s)),[p,s]),Z(()=>{if(e.length===0||D.current===(r??null))return;D.current=r??null,te(f)},[r,e.length]);let z=e.length>1&&s<0,de=t||u||h||R;if(Z(()=>{if(!z||de)return;let j=setInterval(()=>l((V)=>(V+1)%e.length),o);return()=>clearInterval(j)},[z,de,e.length,o]),e.length===0)return null;return b("div",{className:"sc-deco","data-testid":"sc-decorator",onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),onFocus:(j)=>k(j.target.matches(":focus-visible")),onBlur:()=>k(!1),children:[c("span",{className:"sc-live",role:"status","aria-live":"polite",children:C}),c("span",{className:"sc-deco-cycle",children:e.map((j,V)=>b("span",{className:"sc-deco-item","aria-hidden":"true","data-active":V===i,"data-warn":j.warn,children:[c("span",{className:"sc-deco-v",children:j.value}),j.warn&&c("span",{className:"sc-deco-flag","data-testid":"sc-lowgas",children:n})]},j.label))}),z&&c("button",{type:"button",className:"sc-pause","aria-pressed":R,"aria-label":a,"data-testid":"sc-pause",onClick:()=>L((j)=>!j),children:R?c(Oo,{}):c(Io,{})})]})}function Go({wallet:e,copy:t,actions:n,inert:a}){let[r,o]=me(!1),[s,i]=me(!1),l=ae(null),u=ae(null),g=ae(null);Z(()=>()=>{if(g.current)clearTimeout(g.current)},[]),Z(()=>{if(!r)return;u.current?.querySelector('[role="menuitem"]')?.focus();let p=(f)=>{let C=f.target;if(C&&!u.current?.contains(C)&&!l.current?.contains(C))o(!1)};return document.addEventListener("pointerdown",p,!0),()=>document.removeEventListener("pointerdown",p,!0)},[r]),Z(()=>{if(a)o(!1)},[a]);let h=e.name??t.walletName,k=b(gt,{children:[c("span",{className:"sc-wallet-dot","aria-hidden":"true"}),c("span",{className:"sc-wallet-name",children:h}),c("span",{className:"sc-wallet-addr",children:e.short}),!a&&n?c($a,{}):null]});if(a||!n)return c("div",{className:"sc-wrow",children:c("span",{className:"sc-wallet","data-static":"true","data-testid":"sc-wallet",children:k})});let R=[{key:"copy",icon:s?c($e,{}):c(sn,{}),label:s?t.copied:t.copyWalletAddress,sub:e.short,run:()=>{if(n.onCopy(),i(!0),g.current)clearTimeout(g.current);g.current=setTimeout(()=>i(!1),1600)},keepOpen:!0},{key:"switch",icon:c(Lo,{}),label:t.switchWallet,run:n.onSwitch},{key:"disconnect",icon:c(To,{}),label:t.disconnect,run:n.onDisconnect}],L=(p)=>{let f=Array.from(u.current?.querySelectorAll('[role="menuitem"]')??[]),C=f.indexOf(document.activeElement);if(p.key==="Escape")p.preventDefault(),p.stopPropagation(),o(!1),l.current?.focus();else if(p.key==="ArrowDown")p.preventDefault(),f[(C+1)%f.length]?.focus();else if(p.key==="ArrowUp")p.preventDefault(),f[(C-1+f.length)%f.length]?.focus();else if(p.key==="Tab")o(!1)};return b("div",{className:"sc-wrow",children:[c("button",{ref:l,type:"button",className:"sc-wallet","aria-haspopup":"menu","aria-expanded":r,"aria-label":`${t.walletMenu}: ${h} ${e.short}`,"data-testid":"sc-wallet",onClick:()=>o((p)=>!p),onKeyDown:(p)=>{if(p.key==="ArrowDown"&&!r)p.preventDefault(),o(!0)},children:k}),r&&c("div",{ref:u,className:"sc-pop",role:"menu","aria-label":t.walletMenu,onKeyDown:L,"data-testid":"sc-wallet-menu",children:R.map((p)=>b("button",{type:"button",role:"menuitem",className:"sc-mi","data-testid":`sc-wallet-${p.key}`,onClick:()=>{if(p.run(),!p.keepOpen)o(!1)},children:[p.icon,c("span",{children:p.label}),p.sub?c("span",{className:"sc-mi-sub",children:p.sub}):null]},p.key))})]})}function Qo({wallets:e,busyId:t,copy:n,onPick:a}){let r=ae(null);Z(()=>{r.current?.querySelector("button")?.focus({preventScroll:!0})},[]);let o=(s)=>{let i=Array.from(r.current?.querySelectorAll("button")??[]),l=i.indexOf(document.activeElement);if(s.key==="ArrowDown")s.preventDefault(),i[Math.min(i.length-1,l+1)]?.focus();else if(s.key==="ArrowUp")s.preventDefault(),i[Math.max(0,l-1)]?.focus()};return c("ul",{ref:r,className:"sc-wl","aria-label":n.chooseWallet,"data-testid":"sc-wallets",onKeyDown:o,children:e.map((s,i)=>{let l=t===s.id;return c("li",{children:b("button",{type:"button",className:"sc-wl-row",style:{animation:"sc-rise .2s var(--c-ease) both",animationDelay:`${Math.min(i,3)*20}ms`},"aria-disabled":t!==null,"aria-busy":l,"data-testid":"sc-wallet-option",onClick:()=>{if(t===null)a(s.id)},children:[s.icon?c("img",{className:"sc-wl-icon",src:s.icon,alt:"",width:32,height:32}):c("span",{className:"sc-wl-mono","aria-hidden":"true",children:s.name.charAt(0).toUpperCase()}),b("span",{className:"sc-wl-name",children:[s.name,l&&b("span",{className:"sc-wl-sub",children:[c(ut,{small:!0}),B(n.openingNamed,{wallet:s.name})]})]}),s.lastUsed&&!l?c("span",{className:"sc-wl-tag",children:n.lastUsed}):null]})},s.id)})})}function Yo({stages:e,copy:t,tx:n,walletName:a}){let r=(o)=>o.key==="wallet"?o.state==="active"&&n&&n.total>1?lt(t,n,a):a?B(t.confirmNamed,{wallet:a}):t.stageWallet:o.key==="sent"?t.stageSent:t.stageConfirmed;return c("ol",{className:"sc-steps","aria-label":t.stagesLabel,"data-testid":"sc-stages",children:e.map((o)=>b("li",{"data-state":o.state,"data-stage":o.key,children:[c("span",{className:"sc-dot","aria-hidden":"true",children:o.state==="done"?c($e,{size:14}):null}),b("span",{children:[r(o),c("span",{className:"sc-live",children:o.state==="done"?" (done)":o.state==="active"?" (in progress)":""})]})]},o.key))})}function ft({problem:e,copy:t,noticeRef:n,children:a}){let r=e.kind==="rejected";return b("div",{className:"sc-notice",ref:n,tabIndex:-1,"data-kind":e.kind,"data-testid":"sc-notice",children:[b("div",{className:"sc-notice-head",children:[r?c(_o,{}):c(Mo,{}),c("p",{children:e.message})]}),a?c("div",{className:"sc-actions",children:a}):null,e.detail&&!r&&b("details",{className:"sc-tech",children:[c("summary",{children:t.details}),c("code",{children:e.detail})]})]})}function Jo({copy:e,amountText:t,receipt:n,finalizing:a,slot:r,returnHref:o,doneRef:s,onDone:i}){let l=o?c("a",{className:"sc-btn",href:o,ref:s,"data-testid":"sc-return",children:e.returnToStore}):i?c("button",{type:"button",className:"sc-btn",onClick:i,ref:s,"data-testid":"sc-done",children:e.done}):null;return b("div",{className:"sc-ok",ref:l?void 0:s,tabIndex:l?void 0:-1,"data-testid":"sc-success","data-receipt":a?"provisional":"final",children:[c(Fo,{}),c("h3",{children:a?e.receivedProvisional:e.received},a?"received":"confirmed"),c("p",{className:"sc-ok-amt",children:t}),b("p",{className:"sc-receipt",children:[e.receiptLabel," ",c("code",{children:n})]}),a&&c("p",{className:"sc-fin","data-testid":"sc-finalizing",children:e.finalizing}),r?c("div",{className:"sc-slot",children:r}):null,l]})}function Vo(){return b("div",{"aria-hidden":"true","data-testid":"sc-skeleton",children:[c("span",{className:"sc-sk",style:{width:120,height:14,margin:"6px 0 10px"}}),c("span",{className:"sc-sk",style:{width:"100%",height:96,borderRadius:16}}),c("span",{className:"sc-sk",style:{width:"100%",height:56,marginTop:16}})]})}var Xo=()=>typeof window<"u"&&typeof window.matchMedia==="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,Zo=typeof window>"u"?Z:Eo;function Fa({open:e,onClose:t,onBackdrop:n,titleId:a,children:r,initialFocus:o}){let s=ae(null),[i,l]=me(e);return Zo(()=>{if(e)l(!0)},[e]),Z(()=>{let u=s.current;if(!u)return;if(e&&!u.open){u.removeAttribute("data-closing");try{u.showModal()}catch{u.setAttribute("open","")}o?.current?.focus();return}if(e||!u.open)return;let g=!1,h=()=>{if(g)return;g=!0,u.removeAttribute("data-closing"),u.close(),l(!1)};if(Xo()){h();return}u.setAttribute("data-closing",""),u.addEventListener("animationend",h,{once:!0});let k=setTimeout(h,260);return()=>{if(clearTimeout(k),u.removeEventListener("animationend",h),!g&&s.current?.open)u.removeAttribute("data-closing")}},[e]),c("dialog",{ref:s,className:"sc-dialog","aria-labelledby":a,"data-testid":"sc-modal",onCancel:(u)=>{u.preventDefault(),t()},onClick:(u)=>{let g=s.current;if(!g||u.target!==g)return;let h=g.getBoundingClientRect();if(u.clientX<h.left||u.clientX>h.right||u.clientY<h.top||u.clientY>h.bottom)(n??t)()},children:e||i?r:null})}function es({title:e,titleId:t,titleRef:n,closeLabel:a,onClose:r,back:o}){return b("div",{className:"sc-head",children:[b("div",{className:"sc-head-end",children:[o&&b("button",{type:"button",className:"sc-back",onClick:o.onClick,"data-testid":"sc-back",children:[c(No,{}),o.label]}),c("h2",{className:"sc-title",id:t,ref:n,tabIndex:-1,children:e})]}),c("div",{className:"sc-head-end",children:r&&c("button",{type:"button",className:"sc-x",onClick:r,"aria-label":a,"data-testid":"sc-close",children:c(ee,{children:c("path",{d:"M6 6l12 12M18 6L6 18"})})})})]})}function ts({children:e}){let t=ae(null),n=ae(null);return Z(()=>{let a=t.current,r=n.current;if(!a||!r||typeof ResizeObserver>"u")return;let o=!0,s,i=new ResizeObserver(()=>{let l=r.getBoundingClientRect().height;if(l===0){a.style.height="";return}if(a.style.height=`${l+8}px`,o){o=!1,requestAnimationFrame(()=>a.setAttribute("data-ready","true"));return}a.setAttribute("data-anim","true"),clearTimeout(s),s=setTimeout(()=>a.removeAttribute("data-anim"),260)});return i.observe(r),()=>{i.disconnect(),clearTimeout(s)}},[]),c("div",{className:"sc-hgt",ref:t,children:c("div",{ref:n,children:e})})}function ns({line:e,copy:t,onRetry:n}){let a=e.kind==="loading"||e.kind==="refreshing";return b("div",{className:"sc-payline",role:"status","aria-live":"polite","aria-atomic":"true","data-testid":"sc-payline","data-kind":e.kind,children:[a&&c(ut,{small:!0}),c("span",{className:e.kind==="ready"||e.kind==="refreshing"?"sc-payline-main":void 0,children:e.text}),e.note?c("span",{children:e.note}):null,e.eta?c("span",{children:e.eta}):null,e.kind==="unavailable"&&n?c("button",{type:"button",className:"sc-link",onClick:n,children:t.tryAgain}):null]})}function qa(e){let{copy:t}=e,n=e.phase==="paying",a=e.phase==="pick"||e.phase==="paying",r=ae(null),o=!!e.closeGuard&&n;Z(()=>{if(o)r.current?.focus()},[o]);let s=e.phase==="manual"?t.payAnotherWay:e.phase==="wallets"?t.chooseWallet:e.title??t.title;return b("div",{className:"sc-card","data-phase":e.phase,children:[b(ts,{children:[c(es,{title:s,titleId:e.titleId,titleRef:e.titleRef,closeLabel:t.close,onClose:e.onClose,back:(e.phase==="manual"||e.phase==="wallets")&&e.onBack?{label:t.back,onClick:e.onBack}:null}),e.phase==="loading"&&!e.notice&&c(Vo,{}),a&&e.wallet&&c(Go,{wallet:e.wallet,copy:t,actions:e.walletActions??null,inert:n}),a&&b(gt,{children:[b("div",{className:"sc-deco-row",children:[c("span",{className:"sc-deco-label",children:t.payWith}),b("span",{className:"sc-deco-end",children:[e.refreshing?c("span",{"data-testid":"sc-refreshing",style:{display:"inline-flex"},children:c(ut,{small:!0})}):null,c(Ko,{items:e.decorator,paused:e.menuOpen||n,lowGas:t.lowGas,pauseLabel:t.pauseBalances,optionKey:e.decoratorKey})]})]}),c(qo,{options:e.options,selectedId:e.selectedId,open:e.menuOpen,locked:n,label:t.chooseUsdc,amount:c("p",{className:"sc-amt","data-testid":"sc-amount","aria-label":`${t.amountDue} ${e.amountText}`,children:e.amountText}),onOpenChange:e.onMenuChange,onSelect:e.onSelect}),e.payLine&&c(ns,{line:e.payLine,copy:t,onRetry:e.onPayLineRetry})]}),e.phase==="wallets"&&e.walletPicker&&c(Qo,{wallets:e.walletPicker.wallets,busyId:e.walletPicker.busyId,copy:t,onPick:e.walletPicker.onPick}),(e.phase==="pick"||e.phase==="wallets")&&e.message?c("div",{className:"sc-msg",role:"status","data-testid":"sc-message",children:e.message}):null,e.notice,n&&e.stages&&b(gt,{children:[c(Yo,{stages:e.stages,copy:t,tx:e.tx,walletName:e.walletName}),c("div",{className:"sc-hair","aria-hidden":"true","data-testid":"sc-progress",children:c("i",{})}),e.slow?c("p",{className:"sc-expect","data-testid":"sc-status",children:t.slow}):null]}),o&&e.closeGuard&&b("div",{className:"sc-msg","data-testid":"sc-close-guard",children:[c("span",{className:"sc-msg-strong",children:t.closeConfirm}),b("div",{className:"sc-pair",children:[c("button",{type:"button",className:"sc-sec",onClick:e.closeGuard.onClose,"data-testid":"sc-close-anyway",children:t.closeAnyway}),c("button",{type:"button",className:"sc-sec",ref:r,onClick:e.closeGuard.onStay,"data-testid":"sc-stay",children:t.stay})]})]}),(e.phase==="pick"||e.phase==="paying")&&e.cta&&b("button",{ref:e.cta.ref,type:"button",className:"sc-btn sc-cta","aria-busy":e.cta.busy,"aria-disabled":e.cta.disabled||e.cta.busy,"data-testid":"sc-pay",onClick:()=>{if(!e.cta.disabled&&!e.cta.busy)e.cta.onClick()},children:[(e.cta.busy||e.cta.spinner)&&c(ut,{}),c("span",{children:e.cta.label})]}),e.phase==="pick"&&e.onPayAnotherWay&&c("div",{className:"sc-foot",children:c("button",{type:"button",className:"sc-link sc-link-quiet",onClick:e.onPayAnotherWay,"data-testid":"sc-another-way",children:t.payAnotherWay})}),e.phase==="done"&&e.done&&c(Jo,{copy:t,amountText:e.amountText,receipt:e.done.receipt,finalizing:e.done.finalizing,slot:e.done.slot,returnHref:e.done.returnHref,doneRef:e.done.ref,onDone:e.done.onDone}),e.phase==="manual"&&e.manual]}),b("p",{className:"sc-powered","data-testid":"sc-powered",children:[c("svg",{viewBox:"0 0 80 80","aria-hidden":"true",focusable:"false",children:c("path",{d:za,fill:"none",stroke:"currentColor",strokeWidth:"11",strokeLinecap:"round",strokeLinejoin:"round"})}),c("span",{children:ja.poweredBy})]})]})}var as={pending:"",event:"",data:[],started:!1},rs=/\r\n|\n|\r/;function os(e,t){if(t===""){let s=e.data.length>0?{event:e.event||"message",data:e.data.join(`
|
|
208
|
+
`)}:null;return{state:{...e,event:"",data:[]},frame:s}}if(t.startsWith(":"))return{state:e,frame:null};let n=t.indexOf(":"),a=n===-1?t:t.slice(0,n),r=n===-1?"":t.slice(n+1),o=r.startsWith(" ")?r.slice(1):r;if(a==="event")return{state:{...e,event:o},frame:null};if(a==="data")return{state:{...e,data:[...e.data,o]},frame:null};return{state:e,frame:null}}function ss(e,t){let n=e.pending+(e.started?t:t.replace(/^\uFEFF/,"")),a=n.endsWith("\r")?"\r":"",r=n.slice(0,n.length-a.length).split(rs),o=r.pop(),s=r.reduce((i,l)=>{let u=os(i.state,l);return{state:u.state,frames:u.frame?[...i.frames,u.frame]:i.frames}},{state:{...e,started:!0},frames:[]});return{state:{...s.state,pending:o+a},frames:s.frames}}async function Ka(e,t,n){let a=e.getReader(),r=new TextDecoder,o=()=>void a.cancel().catch(()=>{});if(n?.aborted)return o();n?.addEventListener("abort",o,{once:!0});try{let s=as;for(;;){let{done:i,value:l}=await a.read();if(i||n?.aborted)return;let u=ss(s,r.decode(l,{stream:!0}));s=u.state;for(let g of u.frames)if(t(g),n?.aborted)return o()}}finally{n?.removeEventListener("abort",o)}}class Pe extends Error{status;code;constructor(e,t,n){super(n);this.status=e;this.code=t}}var is={retries:3,baseMs:400};function cs(e,t={}){let{retryRateLimit:n=!0}=t;return e instanceof Pe&&(e.status===0||e.status===408||n&&e.status===429||e.status>=500)}async function ls(e,t={}){let{retries:n,baseMs:a,retryRateLimit:r}={...is,...t};for(let o=0;;o++)try{return await e()}catch(s){if(o>=n||!cs(s,{retryRateLimit:r}))throw s;await new Promise((i)=>setTimeout(i,a*2**o+Math.random()*a*0.25))}}function cn(e,t,n,a){let r=`${e}/v1/charges/${encodeURIComponent(t)}`;async function o(i,l){let u;try{u=await fetch(`${r}${i}`,{method:l===void 0?"GET":"POST",headers:{"X-Client-Secret":n,...l===void 0?{}:{"content-type":"application/json"}},...l===void 0?{}:{body:JSON.stringify(l)},cache:"no-store"})}catch{throw new Pe(0,"network","Network request failed")}let g=await u.text(),h=null;try{h=g?JSON.parse(g):null}catch{h=null}if(!u.ok){let k=h?.error;throw new Pe(u.status,k?.code??"error",k?.message??`HTTP ${u.status}`)}return h}let s=(i,l)=>ls(()=>o(i,l),{...a,retryRateLimit:l===void 0});return{charge:()=>o(""),events:async(i,l)=>{let u;try{u=await fetch(`${r}/events`,{headers:{"X-Client-Secret":n,accept:"text/event-stream"},cache:"no-store",...l?{signal:l}:{}})}catch{throw new Pe(0,"network","Network request failed")}if(!u.ok||!u.body){let g=await u.json().catch(()=>null);throw new Pe(u.status,g?.error?.code??"error",g?.error?.message??`HTTP ${u.status}`)}await Ka(u.body,i,l)},options:()=>s("/options"),pay:(i,l)=>s("/pay",{option_id:i,buyer:l}),authorize:(i)=>s("/authorizations",i),submitSolana:(i)=>s("/rails/cctp/submit",{transaction:i}),fundingAttempt:(i,l,u={})=>s("/funding_attempts",{rail:u.rail??"cctp",source_chain:i,tx_hash:l,...u.buyer?{buyer:u.buyer}:{}}),lifiQuote:(i,l)=>o(`/rails/lifi/quote?option_id=${encodeURIComponent(i)}&buyer=${encodeURIComponent(l)}`)}}async function ve(e,t,n,a={}){let r=Error("No RPC endpoint available");for(let o of e){let s=new AbortController,i=setTimeout(()=>s.abort(),a.timeoutMs??8000);try{let l=await fetch(o,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:1,method:t,params:n}),signal:s.signal});if(!l.ok)throw Error(`RPC HTTP ${l.status}`);let u=await l.json();if(u.error)throw Error(u.error.message??"RPC error");if(!("result"in u))throw Error("RPC returned no result");return u.result}catch(l){r=l}finally{clearTimeout(i)}}throw r}function Ae(e){return!!e&&typeof e==="object"}function us(e){if(!Ae(e)||typeof e.id!=="string"||!e.id)return null;if(e.kind!=="evm"&&e.kind!=="solana")return null;let{chain:t,token:n}=e;if(!Ae(t)||!(typeof t.id==="number"||typeof t.id==="string")||typeof t.name!=="string")return null;if(!Ae(n)||typeof n.address!=="string"||!n.address)return null;if(!Array.isArray(e.rpc_urls))return null;let a=e.native;return{id:e.id,kind:e.kind,chain:{id:t.id,name:t.name,display_name:typeof t.display_name==="string"&&t.display_name?t.display_name:null},...e.rail==="lifi"?{rail:"lifi"}:{},token:{symbol:typeof n.symbol==="string"?n.symbol:"USDC",address:n.address,decimals:typeof n.decimals==="number"?n.decimals:6,logo:typeof n.logo==="string"?n.logo:"usdc",...n.native===!0?{native:!0}:{}},native:Ae(a)&&typeof a.symbol==="string"&&typeof a.decimals==="number"?{symbol:a.symbol,decimals:a.decimals}:null,default:e.default===!0,route:e.route==="direct"?"direct":"bridge",...e.gasless===!0?{gasless:!0}:{},add_chain:Ae(e.add_chain)?e.add_chain:null,rpc_urls:e.rpc_urls.filter((r)=>typeof r==="string"&&/^https?:\/\//i.test(r))}}function Qa(e){return(Array.isArray(e)?e:Ae(e)&&Array.isArray(e.data)?e.data:[]).map(us).filter((n)=>n!==null)}function ht(e){return e.chain.display_name??Ra(e.chain.name)}function ds(e){let t=e.chain,n=t.add_chain?.nativeCurrency;return{id:`evm:${t.id}`,kind:"evm",chain:{id:t.id,name:t.name,display_name:t.add_chain?.chainName??null},token:{symbol:"USDC",address:t.usdc,decimals:6,logo:"usdc"},native:n?{symbol:n.symbol,decimals:n.decimals}:null,default:!0,route:"direct",add_chain:t.add_chain,rpc_urls:t.add_chain?.rpcUrls??[]}}var Ya=(e,t)=>t.find((n)=>n.default&&!F(n))??ds(e);function dn(e){return!e.gasless&&(e.kind==="solana"||e.route==="bridge")}function un(e,t){let n=10n**BigInt(t),a=e/n,o=(t===0?"":(e%n).toString().padStart(t,"0")).slice(0,4).replace(/0+$/,"");if(o.length<2)o=o.padEnd(2,"0");return`${a.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}.${o}`}var F=(e)=>e.rail==="lifi";function yt(e,t,n){return F(e)?t.usdc>0n:t.usdc>=BigInt(n)}function Ja(e,t,n,a){let r={balanceText:null,disabled:!1,reason:null,loading:!1};if(a&&!a[e.kind])return a.evm||a.solana?{...r,reason:"needs_wallet"}:r;if(!t)return{...r,loading:!!a?.[e.kind]};if(t.status==="loading")return{...r,loading:!0};if(t.status==="error")return{...r,reason:"unreadable"};let o=!yt(e,t,n);return{balanceText:un(t.usdc,e.token.decimals),disabled:o,reason:o?"not_enough":null,loading:!1}}function Va(e,t,n,a){let r=e.filter((i)=>n[i.kind]);if(r.length===0)return e;if(r.some((i)=>{let l=t[i.id];return!l||l.status==="loading"}))return e;let o=(i)=>{let l=n[i.kind]?t[i.id]:void 0;return l?.status==="ok"?yt(i,l,a)?0:2:1},s=(i)=>{let l=t[i.id];return l?.status==="ok"?l.usdc:0n};return e.map((i,l)=>({o:i,i:l})).sort((i,l)=>{let u=o(i.o)-o(l.o);if(u!==0)return u;if(o(i.o)===0){let g=Number(F(i.o))-Number(F(l.o));if(g!==0)return g;if(!F(i.o)){let h=s(i.o),k=s(l.o);if(h!==k)return h>k?-1:1;let R=Number(l.o.default)-Number(i.o.default);if(R!==0)return R}}return i.i-l.i}).map((i)=>i.o)}function pn(e,t,n){return e.filter((a)=>{if(!n[a.kind])return!1;let r=t[a.id];return!r||r.status!=="ok"||r.usdc>0n})}var ln=6;function Xa(e){let t=new Set;return e.map((n)=>{let a=0;for(let s of n)a=a*31+s.charCodeAt(0)>>>0;let r=a%ln;for(let s=0;t.has(r)&&s<ln;s++)r=(r+1)%ln;return t.add(r),{letter:/[\p{L}\p{N}]/u.exec(n)?.[0]?.toUpperCase()??"•",hue:r}})}function Za(e,t,n){let a=BigInt(n),r=e.flatMap((l)=>{let u=t[l.id];return!F(l)&&u?.status==="ok"&&u.usdc>=a?[{o:l,usdc:u.usdc}]:[]});if(r.length>0)return r.sort((l,u)=>Number(u.o.default)-Number(l.o.default)||(l.usdc===u.usdc?0:l.usdc>u.usdc?-1:1)),r[0].o.id;let o=e.filter((l)=>{let u=t[l.id];return F(l)&&u?.status==="ok"&&u.usdc>0n}),s=(l)=>/^(usdc|usdt)$/i.test(l.token.logo)?0:1;if(o.length>0)return o.map((l,u)=>({o:l,i:u})).sort((l,u)=>s(l.o)-s(u.o)||l.i-u.i)[0].o.id;let i=e.filter((l)=>t[l.id]?.status==="error");return i.sort((l,u)=>Number(u.default)-Number(l.default)),i[0]?.id??null}function er(e,t){if(!dn(e)||!e.native||!t||t.status!=="ok"||t.native===null)return"na";if(t.native===0n)return"none";return t.native<10n**BigInt(Math.max(0,e.native.decimals-4))?"low":"ok"}function tr(e,t,n){if(!t||t.status!=="ok")return[];let a=[{label:F(e)?B(n.balanceLabelFor,{symbol:e.token.symbol}):n.balanceLabel,value:`${un(t.usdc,e.token.decimals)} ${e.token.symbol}`,warn:!1}];if(e.native&&t.native!==null){let r=er(e,t);a.push({label:n.gasLabel,value:`${un(t.native,e.native.decimals)} ${e.native.symbol}`,warn:r==="low"||r==="none"})}return a}function nr(e,t,n,a){let r=e.filter((i)=>n[i.kind]);if(r.length===0)return"idle";let o=r.map((i)=>t[i.id]);if(o.some((i)=>!i||i.status==="loading"))return"loading";if(o.some((i)=>i.status==="error"))return"ok";let s=o;if(s.some((i,l)=>yt(r[l],i,a)))return"ok";return s.every((i)=>i.usdc===0n)?"empty":"short"}function ar(e,t,n,a,r){if(!e)return{kind:"connect",disabled:!0,reason:null};if(!t[e.kind])return{kind:"connect",disabled:!1,reason:null};if(!n||n.status==="loading")return{kind:"pay",disabled:!0,reason:"checking"};if(n.status==="ok"&&!yt(e,n,a))return{kind:"pay",disabled:!0,reason:"not_enough"};if(F(e)){let o=r??{status:"idle"};if(o.status==="unavailable")return{kind:"pay",disabled:!0,reason:"unavailable"};if(o.status!=="ready")return{kind:"pay",disabled:!0,reason:"checking"};let s=mn(e,n,o.quote);if(s!=="ok")return{kind:"pay",disabled:!0,reason:s};return{kind:"pay",disabled:!1,reason:null}}if(er(e,n)==="none")return{kind:"pay",disabled:!0,reason:"needs_gas"};return{kind:"pay",disabled:!1,reason:null}}function mt(e){return e&&typeof e==="object"?e:{}}var Ga=(e)=>typeof e==="string"&&/^\d+$/.test(e)?BigInt(e):null;function gn(e){let t=mt(e),n=mt(t.pay),a=Ga(n.amount);if(typeof t.option_id!=="string"||a===null||a===0n||typeof n.symbol!=="string"||typeof n.decimals!=="number"||!Number.isInteger(n.decimals))throw Error("Unexpected quote response");if(!Array.isArray(t.txs)||t.txs.length===0)throw Error("Unexpected quote response");let r=t.txs.map((i)=>{let l=mt(i);if(typeof l.to!=="string"||typeof l.data!=="string")throw Error("Unexpected quote response");return{description:typeof l.description==="string"?l.description:"",to:l.to,data:l.data,value:typeof l.value==="string"||typeof l.value==="number"?String(l.value):"0"}}),o=typeof t.expires_at==="string"?Date.parse(t.expires_at):NaN;if(!Number.isFinite(o))throw Error("Unexpected quote response");let s=mt(t.chain);return{optionId:t.option_id,pay:{amount:a,symbol:n.symbol,decimals:n.decimals},txs:r,chainName:typeof s.name==="string"?s.name:null,addChain:s.add_chain&&typeof s.add_chain==="object"?s.add_chain:null,estimatedSeconds:typeof t.estimated_seconds==="number"?t.estimated_seconds:null,expiresAt:o,gasEstimate:Ga(t.gas_estimate)}}function rr(e,t){switch(t.type){case"reset":return{status:"idle"};case"fetch":return{status:"loading",previous:e.status==="ready"?e.quote:e.status==="loading"?e.previous:null};case"ok":if(t.optionId!==void 0&&t.quote.optionId!==t.optionId)return e;return{status:"ready",quote:t.quote};case"fail":return{status:"unavailable"}}}function or(e,t){return!!e&&t.pay.amount>e.pay.amount}function sr(e,t){return Math.max(1000,e.expiresAt-15000-t)}function fn(e,t,n="up"){if(e===0n)return"0";let a=10n**BigInt(t),r=(e%a).toString().padStart(t,"0"),o=r.length-r.replace(/^0+/,"").length,s=Math.min(t,e>=a?4:o+4),i=10n**BigInt(t-s),l=e/i;if(n==="up"&&e%i!==0n)l+=1n;let u=10n**BigInt(s),g=(l%u).toString().padStart(s,"0").replace(/0+$/,"");return`${(l/u).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}${g?`.${g}`:""}`}function ps(e,t){if(t.gasEstimate!==null)return t.gasEstimate*3n/2n;return 10n**BigInt(Math.max(0,(e.native?.decimals??18)-4))}function mn(e,t,n){if(!t||t.status!=="ok")return"ok";if(t.usdc<n.pay.amount)return"not_enough";let a=ps(e,n);if(e.token.native)return t.usdc<n.pay.amount+a?"needs_gas":"ok";return t.native!==null&&t.native<a?"needs_gas":"ok"}function ir(e,t,n){if(!F(e))return null;let a=(o)=>B(n.youPay,{amount:`${fn(o.pay.amount,o.pay.decimals)} ${o.pay.symbol}`}),r=(o)=>o.estimatedSeconds?B(n.youPayTakes,{minutes:Math.max(1,Math.ceil(o.estimatedSeconds/60))}):null;if(t.status==="ready")return{kind:"ready",text:a(t.quote),eta:r(t.quote)};if(t.status==="loading"&&t.previous)return{kind:"refreshing",text:a(t.previous),eta:null,note:n.youPayUpdating};if(t.status==="unavailable")return{kind:"unavailable",text:n.optionUnavailableReason,eta:null};return{kind:"loading",text:n.youPayChecking,eta:null}}function cr(e){if(e.kind==="solana")return"solana";let t=typeof e.chain.id==="number"?e.chain.id:Number(e.chain.id);if(t===1328||t===1329)return"sei";if(t===84532||t===8453)return"base";return null}var Fe=(e)=>!!e&&typeof e.request==="function";function bt(e){let t=e;if(t.isRabby)return"Rabby";if(t.isCoinbaseWallet)return"Coinbase Wallet";if(t.isBraveWallet)return"Brave Wallet";if(t.isPhantom)return"Phantom";if(t.isMetaMask)return"MetaMask";return"your wallet"}function lr(e){if(typeof window>"u")return null;let t=window.ethereum;if(!Fe(t))return null;let n=Array.isArray(t.providers)?t.providers.filter(Fe):[];if(e&&n.length>1){let a=n.find((r)=>bt(r)===e);if(a)return a}return t}var gs=/^data:image\/(png|svg\+xml|webp|jpeg|gif);/i;function fs(e){let t=e,n=t?.info;if(!n||typeof n.uuid!=="string"||typeof n.name!=="string"||!n.name.trim()||!Fe(t?.provider))return null;let a=typeof n.icon==="string"&&gs.test(n.icon)&&n.icon.length<200000?n.icon:null;return{id:n.uuid,name:n.name.trim().slice(0,40),icon:a,provider:t.provider}}function ms(){if(typeof window>"u")return[];let e=window.ethereum;if(!Fe(e))return[];let t=Array.isArray(e.providers)?e.providers.filter(Fe):[];return t.length>1?t:[e]}function ur(e,t={}){let n=t.target??(typeof window>"u"?null:window),a=new Map,r=!1,o=(l)=>{if(!r)e(l)},s=(l)=>{let u=fs(l.detail);if(!u)return;for(let[g,h]of a)if(h.provider===u.provider&&g!==u.id)a.delete(g);a.set(u.id,u),o([...a.values()])};n?.addEventListener("eip6963:announceProvider",s);try{n?.dispatchEvent(new Event("eip6963:requestProvider"))}catch{}let i=setTimeout(()=>{if(a.size>0)return;let l=new Map;o((t.legacy??ms)().map((u)=>{let g=bt(u),h=(l.get(g)??0)+1;return l.set(g,h),{id:`legacy:${g}:${h}`,name:g,icon:null,provider:u}}))},t.timeoutMs??150);return()=>{r=!0,clearTimeout(i),n?.removeEventListener("eip6963:announceProvider",s)}}async function dr(e){try{await e.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]})}catch(t){if(gr(t)===4001)throw t}return wn(e)}async function yn(e){try{return(await e.request({method:"eth_accounts"}))?.[0]??null}catch{return null}}async function hn(e){try{let t=await e.request({method:"eth_chainId"}),n=Number.parseInt(t,16);return Number.isFinite(n)?n:null}catch{return null}}async function pr(e,t,n){let a=await e.request({method:"eth_call",params:[{to:t,data:nn(n)},"latest"]});return ze(a)}async function bn(e,t){return ze(await e.request({method:"eth_getBalance",params:[t,"latest"]}))}async function wt(e,t){let[n,a]=await Promise.allSettled([ve(e.rpc_urls,"eth_call",[{to:e.token.address,data:nn(t)},"latest"]).then(ze),ve(e.rpc_urls,"eth_getBalance",[t,"latest"]).then(ze)]);if(n.status==="rejected")throw n.reason;return{usdc:n.value,native:a.status==="fulfilled"?a.value:null}}function gr(e){let t=e?.code;return typeof t==="number"?t:void 0}async function wn(e){let n=(await e.request({method:"eth_requestAccounts"}))?.[0];if(!n)throw Error("No wallet account available");return n}async function fr(e,t,n){let a=ya(t);if(await hn(e)===t)return;let r=()=>e.request({method:"wallet_switchEthereumChain",params:[{chainId:a}]});try{await r()}catch(o){if(!(gr(o)===4902||/unrecogni[sz]ed chain|not been added/i.test(o instanceof Error?o.message:""))||!n)throw o;if(await e.request({method:"wallet_addEthereumChain",params:[n]}),await hn(e)!==t)await r()}if(await hn(e)!==t)throw Error("The wallet is still on another chain")}async function mr(e,t,n){let a=await e.request({method:"eth_signTypedData_v4",params:[t,wa(n)]});return va(n,t,a)}async function vn(e,t,n={}){let a=n.intervalMs??2000,r=Date.now()+(n.timeoutMs??600000);for(;;){if(n.signal?.aborted)return"unknown";let o=await e.request({method:"eth_getTransactionReceipt",params:[t]}).catch(()=>null);if(o)return o.status==="0x0"?"failed":"confirmed";if(Date.now()>r)return"unknown";await new Promise((s)=>setTimeout(s,a))}}async function hr(e,t,n,a={}){if(n.length===0)throw Error("No transactions to send");for(let r=0;;r++){let o=n[r];a.onStep?.(r,o.description);let s=await e.request({method:"eth_sendTransaction",params:[{from:t,to:o.to,data:o.data,value:ba(o.value)}]});if(r===n.length-1)return s;switch(await vn(e,s,{signal:a.signal,intervalMs:a.intervalMs})){case"confirmed":break;case"failed":throw Error("Transaction reverted");case"unknown":throw Error(a.signal?.aborted?"Cancelled":"Timed out waiting for the transaction to confirm")}}}function hs(e){let t=[],n=new Set,r=Object.freeze({register:(...o)=>{let s=!1;for(let i of o)if(!t.includes(i))t.push(i),s=!0;if(s)n.forEach((i)=>i());return()=>{for(let i of o){let l=t.indexOf(i);if(l>=0)t.splice(l,1)}n.forEach((i)=>i())}}});e.addEventListener("wallet-standard:register-wallet",(o)=>{try{let s=o.detail;if(typeof s==="function")s(r)}catch{}});try{e.dispatchEvent(new CustomEvent("wallet-standard:app-ready",{detail:r}))}catch{}return{get:()=>t.slice(),on:(o)=>(n.add(o),()=>void n.delete(o))}}var ys=null;function br(){if(typeof window>"u")return null;return ys??=hs(window)}function bs(e){return e.chains.some((t)=>t.startsWith("solana:"))&&typeof e.features["standard:connect"]?.connect==="function"&&typeof e.features["solana:signAndSendTransaction"]?.signAndSendTransaction==="function"}function wr(e,t){let n=(e?.get()??[]).filter(bs);return t?[...n].sort((a,r)=>Number(r.name===t)-Number(a.name===t)):n}var yr=(e)=>e?.find((t)=>!t.chains||t.chains.length===0||t.chains.some((n)=>n.startsWith("solana:")))??null;async function xn(e,t={}){let n=e.features["standard:connect"];try{let{accounts:a}=await n.connect(t.silent?{silent:!0}:void 0),r=yr(a)??yr(e.accounts);if(!r){if(t.silent)return null;throw Error("No wallet account available")}return{wallet:e,account:r,address:r.address}}catch(a){if(t.silent)return null;throw a}}var ws="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function vs(e){let t=0;while(t<e.length&&e[t]===0)t++;let n=[];for(let a=t;a<e.length;a++){let r=e[a];for(let o=0;o<n.length;o++)r+=n[o]<<8,n[o]=r%58,r=r/58|0;while(r>0)n.push(r%58),r=r/58|0}return"1".repeat(t)+n.reverse().map((a)=>ws[a]).join("")}function xs(e){let t="";for(let n of e)t+=String.fromCharCode(n);return btoa(t)}function vr(e){let t=atob(e),n=new Uint8Array(t.length);for(let a=0;a<t.length;a++)n[a]=t.charCodeAt(a);return n}async function xr(e,t,n){let a=e.wallet.features["solana:signAndSendTransaction"],[r]=await a.signAndSendTransaction({account:e.account,transaction:vr(t),chain:`solana:${n}`});if(!r?.signature)throw Error("The wallet returned no signature");return vs(r.signature)}async function kr(e,t,n){let a=e.wallet.features["solana:signTransaction"];if(typeof a?.signTransaction!=="function")throw Error("This wallet cannot sign this payment");let[r]=await a.signTransaction({account:e.account,transaction:vr(t),chain:`solana:${n}`});if(!r?.signedTransaction)throw Error("The wallet returned no transaction");return xs(r.signedTransaction)}async function vt(e,t){let[n,a]=await Promise.allSettled([ve(e.rpc_urls,"getTokenAccountsByOwner",[t,{mint:e.token.address},{encoding:"jsonParsed"}]),ve(e.rpc_urls,"getBalance",[t,{commitment:"confirmed"}])]);if(n.status==="rejected")throw n.reason;let r=n.value?.value??[],o=0n;for(let i of r){let l=i.account?.data?.parsed?.info?.tokenAmount?.amount;if(typeof l==="string"&&/^\d+$/.test(l))o+=BigInt(l)}let s=a.status==="fulfilled"?a.value?.value:void 0;return{usdc:o,native:typeof s==="number"||typeof s==="string"?BigInt(s):null}}async function Cr(e,t,n={}){let a=n.intervalMs??1500,r=Date.now()+(n.timeoutMs??90000);for(;;){if(n.signal?.aborted)return"unknown";let s=(await ve(e,"getSignatureStatuses",[[t],{searchTransactionHistory:!0}]).catch(()=>null))?.value?.[0];if(s?.err)return"failed";if(s?.confirmationStatus==="confirmed"||s?.confirmationStatus==="finalized")return"confirmed";if(Date.now()>r)return"unknown";await new Promise((i)=>setTimeout(i,a))}}function ie(e){return!!e&&typeof e==="object"}function Pr(e){return{txs:e.txs,chain:{name:e.chainName,add_chain:e.addChain},estimated_seconds:e.estimatedSeconds,pay:{amount:e.pay.amount.toString(),symbol:e.pay.symbol,decimals:e.pay.decimals},gas_estimate:e.gasEstimate===null?null:e.gasEstimate.toString()}}var ks=new Set(["from","value","validAfter","validBefore","nonce","signature"]);function Cs(e){if(!ie(e))throw Error("Unexpected pay response");if(ie(e.sign)&&ie(e.sign.typedData)){let i=ie(e.sign.extra)?Object.fromEntries(Object.entries(e.sign.extra).filter((l)=>typeof l[1]==="string"&&!ks.has(l[0]))):{};return{type:"sign",typedData:e.sign.typedData,extra:i}}let t=e.txs;if(!Array.isArray(t)||t.length===0)throw Error("Unexpected pay response");let n=ie(e.chain)?e.chain:{},a=typeof e.estimated_seconds==="number"?e.estimated_seconds:null,r=t[0];if(ie(r)&&r.kind==="solana"){if(typeof r.transaction!=="string"||!r.transaction)throw Error("Unexpected pay response");return{type:"solana",transaction:r.transaction,sponsored:r.sponsored===!0,estimatedSeconds:a}}let o=t.map((i)=>{if(!ie(i)||typeof i.to!=="string"||typeof i.data!=="string")throw Error("Unexpected pay response");return{description:typeof i.description==="string"?i.description:"",to:i.to,data:i.data,value:typeof i.value==="string"||typeof i.value==="number"?String(i.value):"0"}}),s=ie(e.pay)&&typeof e.pay.amount==="string"&&/^\d+$/.test(e.pay.amount)&&typeof e.pay.symbol==="string"&&typeof e.pay.decimals==="number"?{amount:BigInt(e.pay.amount),symbol:e.pay.symbol,decimals:e.pay.decimals}:null;return{type:"evm",txs:o,chainName:typeof n.name==="string"?n.name:null,addChain:ie(n.add_chain)?n.add_chain:null,estimatedSeconds:a,pay:s,gasEstimate:typeof e.gas_estimate==="string"&&/^\d+$/.test(e.gas_estimate)?BigInt(e.gas_estimate):null}}function Ss(e){if(!ie(e)||typeof e.signature!=="string"||!e.signature)throw Error("Unexpected pay response");return e.signature}function Ps(e,t,n){return new ne({kind:"insufficient",message:B(n.insufficient,{balance:we(e),needed:we(t)}),balance:e.toString(),needed:t.toString()})}function As(e,t,n){let a=(r,o)=>`${fn(r,t.decimals,o)} ${t.symbol}`;return new ne({kind:"insufficient",message:B(n.insufficient,{balance:a(e,"down"),needed:a(t.amount,"up")}),balance:e.toString(),needed:t.amount.toString()})}async function Rs(e,t){try{if(t.kind==="solana")return await vt(e,t.account);try{if(e.token.native){let r=await bn(t.provider,t.account);return{usdc:r,native:r}}let n=await pr(t.provider,e.token.address,t.account),a=await bn(t.provider,t.account).catch(()=>null);return{usdc:n,native:a}}catch{return await wt(e,t.account)}}catch{return null}}async function Sr(e,t){let n=()=>e().then(()=>!0,()=>!1),[a,r]=await Promise.all([n(),t()]);switch(r){case"failed":throw Error("Transaction failed on chain");case"confirmed":if(!a)await n();return;case"unknown":return}}async function Ar(e){try{return await Es(e)}catch(t){if(ct(t))return{estimatedSeconds:null};throw t}}async function Es(e){let{option:t,session:n,api:a,hooks:r,copy:o}=e,s=BigInt(e.amount);if(n.kind==="evm")r.step("switching"),await fr(n.provider,Number(t.chain.id),t.add_chain);r.step("checking");let i=await Rs(t,n),l=F(t);if(!l){if(i&&i.usdc<s)throw Ps(i.usdc,s,o);if(i&&i.native===0n&&dn(t))throw new ne({kind:"no_gas",message:o.noGas})}let u=Cs(await a.pay(t.id,n.account));if(l){if(u.type!=="evm"||!u.pay)throw Error("Unexpected pay response");let g=mn(t,i?{status:"ok",...i}:void 0,{pay:u.pay,gasEstimate:u.gasEstimate});if(g==="not_enough")throw As(i?.usdc??0n,u.pay,o);if(g==="needs_gas")throw new ne({kind:"no_gas",message:o.noGas})}if(u.type==="sign"&&n.kind==="evm"){r.step("signing");let g=await mr(n.provider,n.account,u.typedData);return r.step("submitting"),await a.authorize({...g,...u.extra}),{estimatedSeconds:null}}if(u.type==="evm"&&n.kind==="evm"){r.step("signing");let g=await hr(n.provider,n.account,u.txs,{signal:e.signal,intervalMs:e.intervalMs,onStep:(h)=>r.tx?.(h,u.txs.length)});return r.step("submitting"),await Sr(()=>a.fundingAttempt(u.chainName??t.chain.name,g,l?{rail:"lifi",buyer:n.account}:void 0),()=>vn(n.provider,g,{signal:e.signal,intervalMs:e.intervalMs,timeoutMs:e.timeoutMs})),{estimatedSeconds:u.estimatedSeconds}}if(u.type==="solana"&&n.kind==="solana"){r.step("signing");let g=String(t.chain.id),h=u.sponsored?Ss(await a.submitSolana(await kr(n.session,u.transaction,g))):await xr(n.session,u.transaction,g);return r.step("submitting"),await Sr(()=>a.fundingAttempt(t.chain.name,h),()=>Cr(t.rpc_urls,h,{signal:e.signal,intervalMs:e.intervalMs,timeoutMs:e.timeoutMs})),{estimatedSeconds:u.estimatedSeconds}}throw Error("Unexpected pay response")}import{jsx as x,jsxs as K,Fragment as Ct}from"react/jsx-runtime";function kt(e,t,n=!0){let a=P(!0);I(()=>{if(a.current){a.current=!1;return}if(n)e.current?.focus({preventScroll:!1})},[t])}var Ns="your wallet",Er=(e)=>e&&e!==Ns?e:null;function Ls(e){let[t,n]=N([]),a=P([]),[r,o]=N(null),s=P(null),i=P(!1),l=P(new Set),u=W((L)=>{s.current=L,o(L)},[]);I(()=>{if(!e)return;return ur((L)=>{a.current=L,n(L)})},[e]),I(()=>{if(!e||s.current||i.current||t.length===0)return;let L=fe().wallet,p=t.find((f)=>f.name===L)??(t.length===1?t[0]:void 0);if(!p||l.current.has(p.id))return;l.current.add(p.id),yn(p.provider).then((f)=>{if(f&&!s.current&&!i.current)u({provider:p.provider,account:f,name:p.name})})},[e,t,u]);let g=r?.provider;I(()=>{if(!g)return;let L=(p)=>{let f=Array.isArray(p)&&typeof p[0]==="string"?p[0]:null,C=s.current;if(C?.provider===g)u(f?{...C,account:f}:null)};return g.on?.("accountsChanged",L),()=>g.removeListener?.("accountsChanged",L)},[g,u]);let h=W(async(L)=>{let p=a.current,f=L?L:p.find((z)=>z.name===fe().wallet)??(p.length===1?p[0]:null)??(()=>{let z=lr(fe().wallet);return z?{provider:z,name:bt(z)}:null})();if(!f)return null;let te=(s.current?.provider===f.provider?s.current.account:null)??await yn(f.provider)??await wn(f.provider);i.current=!1;let D={provider:f.provider,account:te,name:f.name};return u(D),rn({wallet:D.name}),D},[u]),k=W(()=>{i.current=!0,u(null)},[u]),R=W(async()=>{let L=s.current;if(!L)return;let p=await dr(L.provider);u({...L,account:p})},[u]);return{wallets:t,conn:r,connRef:s,connect:h,disconnect:k,switchAccount:R}}var Ts=/^data:image\/(png|svg\+xml|webp|jpeg|gif);/i,Is=(e)=>{let t=e.icon;return typeof t==="string"&&Ts.test(t)?t:null};function Os(e){let[t,n]=N([]),[a,r]=N(null),o=P(null),s=P(!1),i=W((g)=>{o.current=g,r(g)},[]);I(()=>{if(!e)return;let g=br(),h=()=>n(wr(g,fe().wallet));return h(),g?.on(h)},[e]),I(()=>{if(!e||s.current)return;let g=fe().wallet;if(!g)return;let h=t.find((R)=>R.name===g);if(!h)return;let k=!0;return xn(h,{silent:!0}).then((R)=>k&&R&&!o.current&&!s.current&&i({session:R,name:h.name})),()=>{k=!1}},[e,t,i]);let l=W(async(g)=>{let h=g??t[0];if(!h)return null;let k=(o.current?.session.wallet===h?o.current.session:null)??await xn(h);if(!k)return null;s.current=!1;let R={session:k,name:h.name};return i(R),rn({wallet:h.name}),R},[i,t]),u=W(()=>{s.current=!0,o.current?.session.wallet.features["standard:disconnect"]?.disconnect?.().catch(()=>{}),i(null)},[i]);return{wallets:t,conn:a,connRef:o,connect:l,disconnect:u}}var Ms=(e)=>new Promise((t)=>setTimeout(t,e));function _s({orderId:e,createCharge:t,returnUrl:n,onPaid:a,statusUrl:r,className:o,appearance:s="auto",onStatusChange:i,onError:l,copy:u,successSlot:g,defaultOpen:h=!1,manualPayment:k=!1,presentation:R="modal",merchantName:L}){let p=R==="inline",f=xt(()=>Aa(u),[u]),C=P(f);C.current=f;let te=Nr(),[D,z]=N(h||p),[de,j]=N(h||p),[V,xe]=N("pick"),[Re,Ir]=N("evm"),[Or,Cn]=N(null),[Mr,Ee]=N(!1),[_r,Sn]=N(0),[zs,Pn]=N(null),[A,An]=N(null),[ke,Pt]=N(null),[q,At]=N(null),[qe,Rn]=N(null),[O,ce]=Rr(Ma,an),[Rt,En]=N({status:"loading",list:[]}),[Wr,Br]=N(0),[G,Et]=N({}),[Ke,Ne]=Rr(rr,{status:"idle"}),[Dr,Ur]=N(0),[Nt,Nn]=N(null),[jr,Ge]=N(!1),[Le,Ln]=N(!1),[Te,re]=N(null),[Qe,Lt]=N(null),[zr,Tn]=N(!1),[Hr,$r]=N(!1),[Fr,Ie]=N(""),In=P(a);In.current=a;let On=P(r);On.current=r;let Mn=P(i);Mn.current=i;let _n=P(l);_n.current=l;let Wn=P(t);Wn.current=t;let Bn=P(Ke);Bn.current=Ke;let Dn=P(!1),T=Ls(de),E=Os(de),Oe=P(null),oe=xt(()=>A?cn(A.serviceUrl,A.chargeId,A.clientSecret):null,[A]),Tt=P(0),Ye=P(null),Un=W(()=>{if(Ye.current)return Ye.current;let m=(async()=>{let y={ok:!1,status:503,error:C.current.createFailed};for(let v=0;v<3;v++){try{y=await Wn.current()}catch{y={ok:!1,status:503,error:C.current.createFailed}}if(y?.ok){let w=ka(y.charge);return w?{ok:!0,charge:w}:{ok:!1,status:503,error:C.current.createFailed}}if(y.status<500)return y;if(v<2)await Ms(700*2**v)}return y})().finally(()=>{Ye.current=null});return Ye.current=m,m},[]),It=P(0),se=W(async(d)=>{let m=++Tt.current;if(!d)An(null),Oe.current=null,At(null),Pt(null),Rn(null),ce({type:"reset"});let y=await Un();if(y.ok){if(m===Tt.current)Oe.current=y.charge,An(y.charge),At({status:y.charge.status,confirmed:y.charge.confirmed,confirmation:y.charge.confirmation,funded_amount:null}),Pt(null);return{ok:!0,charge:y.charge}}let v=Ia(y,C.current);if(!d&&m===Tt.current)Pt(v);return{ok:!1,problem:v}},[Un]),jn=P(null);I(()=>{if(!de)return;if(jn.current===e)return;jn.current=e,It.current=0,se(!1)},[de,e,se]),I(()=>{$r(tn(navigator.userAgent))},[]),I(()=>{if(!oe||!A)return;let d=!0;return oe.options().then((m)=>{if(!d)return;let y=Qa(m);En(y.length?{status:"ready",list:y}:{status:"error",list:[]})}).catch(()=>{if(!d)return;En((m)=>m.status==="ready"?m:{status:"error",list:[]})}),()=>{d=!1}},[oe,A,Wr]);let U=Rt.list,Ot=P(U);Ot.current=U;let he=A?.amount??"0",zn=P({evm:0,solana:0}),pe=W(async(d,m)=>{let y=Ot.current.filter((w)=>w.kind===d);if(y.length===0)return;let v=++zn.current[d];Et((w)=>({...w,...Object.fromEntries(y.map((S)=>[S.id,w[S.id]?.status==="ok"?w[S.id]:{status:"loading"}]))})),Sn((w)=>w+1);try{await Promise.all(y.map(async(w)=>{let S;try{let M=d==="evm"?await wt(w,m):await vt(w,m);S={status:"ok",usdc:M.usdc,native:M.native}}catch{S={status:"error"}}if(v===zn.current[d])Et((M)=>({...M,[w.id]:S.status==="error"&&M[w.id]?.status==="ok"?M[w.id]:S}))}))}finally{Sn((w)=>w-1)}},[]),Je=U.map((d)=>d.id).join("|"),ye=T.conn?.account??null,Mt=E.conn?.session.address??null,Ve=W((d)=>{Et((m)=>{let y={...m};for(let v of Ot.current)if(v.kind===d)delete y[v.id];return y})},[]);I(()=>{if(Ve("evm"),ye&&Je)pe("evm",ye)},[ye,Je,pe,Ve]),I(()=>{if(Ve("solana"),Mt&&Je)pe("solana",Mt)},[Mt,Je,pe,Ve]);let Q={evm:!!T.conn,solana:!!E.conn},Xe=new Set(U.map((d)=>d.kind)).size>1,Hn=P(!1),{evm:$n,solana:Fn}=Q;I(()=>{if(U.length===0)return;let d=pn(U,G,{evm:$n,solana:Fn}),m=d.length>0?d:U;Nn((y)=>{let v=y&&m.some((w)=>w.id===y);if(!Hn.current){let w=Za(m,G,he);if(w)return w}return v?y:(m.find((w)=>w.default)??m[0]).id})},[U,G,he,$n,Fn]);let _=U.find((d)=>d.id===Nt)??null,_t=nr(U,G,Q,he),qn=W((d)=>{At((m)=>m&&JSON.stringify(m)===JSON.stringify(d)?m:d)},[]),Kn=q?.status==="settled"||q?.status==="expired",Wt=O.step==="processing"||O.step==="submitting";I(()=>{if(!oe||Kn)return;let d=!1,m=new AbortController,y=null,v=(M)=>{let Se=xa(M);if(Se&&!d)qn(Se)},w=()=>{oe.charge().then(v).catch(()=>{})},S=()=>{if(y||d)return;w(),y=setInterval(w,Wt?1500:3000)};if(w(),typeof ReadableStream>"u")S();else if(oe.events((M)=>{if(M.event!=="charge.updated")return;try{v(JSON.parse(M.data))}catch{}},m.signal).catch(()=>{}).then(S),Wt)y=setInterval(w,1500);return()=>{if(d=!0,m.abort(),y)clearInterval(y)}},[oe,Kn,Wt,qn]);let Bt=r===null,Gn=!!q&&q.confirmed,Dt=P(null);I(()=>{Dt.current=null},[A?.chargeId]),I(()=>{if(Bt||!A||!(Gn||O.step==="processing")||qe?.confirmation==="final")return;let d=Sa(A.chargeId,On.current);if(!d)return;let m=!1,y=async()=>{try{let w=await fetch(d,{cache:"no-store"}),S=w.ok?Ca(await w.json().catch(()=>null)):null;if(!S||m||S.chargeId!==A.chargeId)return;if(Rn(S),S.confirmed&&Dt.current!==S.confirmation)Dt.current=S.confirmation,In.current?.(S)}catch{}};y();let v=setInterval(y,O.step==="processing"?1500:3000);return()=>{m=!0,clearInterval(v)}},[Bt,A,Gn,O.step,qe?.confirmation]),I(()=>{if(q?.status!=="expired"||O.step!=="idle")return;if(It.current>=3)return;It.current+=1,se(!0)},[q,O.step,se]);let Me=Bt?q?.confirmed?q.confirmation:null:qe?.confirmed?qe.confirmation:null,Y=!!Me;I(()=>{if(Y)ce({type:"paid"})},[Y]),I(()=>{if(O.step!=="processing"){Tn(!1);return}let d=setTimeout(()=>Tn(!0),30000);return()=>clearTimeout(d)},[O.step]);let Ze=A?we(A.amount):"",H=O.problem??null,X=O.step!=="idle"&&O.step!=="paid";Dn.current=X;let le=_&&F(_)?_:null,et=le?G[le.id]:void 0,Ut=!!le&&!!ye&&(et?.status==="error"||et?.status==="ok"&&et.usdc>0n),tt=le?.id??null,qr=q?.funded_amount??"";I(()=>{if(Ne({type:"reset"}),!oe||!A||!tt||!Ut||!ye)return;let d=!0,m=null,y=async()=>{if(!d)return;if(Dn.current){m=setTimeout(y,5000);return}Ne({type:"fetch"});try{let v=gn(await oe.lifiQuote(tt,ye));if(!d)return;Ne({type:"ok",quote:v,optionId:tt}),m=setTimeout(y,sr(v,Date.now()))}catch(v){if(!d)return;if(ct(v))m=setTimeout(y,5000);else Ne({type:"fail"})}};return m=setTimeout(y,350),()=>{if(d=!1,m)clearTimeout(m)}},[oe,A?.chargeId,tt,Ut,ye,qr,Dr]);let _e=ke?"failed":!de?"ready":!A||!q?"loading":Me==="final"||q.status==="settled"?"settled":Me?"paid":H?"problem":O.step==="signing"?"confirming":O.step==="connecting"||O.step==="switching"||O.step==="checking"||Le?"connecting":O.step==="submitting"||O.step==="processing"?"processing":"ready",Qn=P(null);I(()=>{if(Qn.current===_e)return;Qn.current=_e,Mn.current?.(_e)},[_e]);let jt=ke??H;I(()=>{if(jt)_n.current?.(jt)},[jt]);let Yn=T.conn?{name:Er(T.conn.name),address:T.conn.account}:null,Jn=E.conn?{name:Er(E.conn.name),address:E.conn.session.address}:null,be=_?.kind==="solana"?Jn:_?.kind==="evm"?Yn:Yn??Jn,zt=be?.name??null,nt=Qe&&Qe.total>1&&O.step==="signing"?lt(f,Qe,zt):Wa(O.step,Ze,f,zt);I(()=>{if(Me)Ie(f.received);else if(H?.kind==="rejected")Ie(H.message);else if(X)Ie(nt);else Ie("")},[Me,H,X,nt,f]);let Ht=P(null),at=P(null),Vn=P(null),$t=P(null);kt(Vn,Y,Y),kt(at,H,!!H&&H.kind!=="rejected"),kt(Ht,H?.kind==="rejected"?H:null,H?.kind==="rejected"),kt($t,V,V!=="pick");let Xn=W((d,m)=>{ce({type:"failed",problem:He(d,{step:m,copy:C.current})})},[]),Kr=()=>tn(navigator.userAgent)?C.current.noWalletMobile:C.current.noWallet,We=W((d)=>{Ir(d),re(null),Ge(!1),xe("wallets")},[]),Gr=W(async()=>{if(!_||Le)return;if(re(null),Xe&&T.wallets.length>0&&E.wallets.length>0&&!T.conn&&!E.conn){We("any");return}let m=Xe&&!T.conn&&!E.conn&&T.wallets.length===0&&E.wallets.length>0?"solana":_.kind;if(m==="evm"?T.wallets.length>1&&!T.conn:E.wallets.length>1&&!E.conn){We(m);return}Ln(!0);try{if(!(m==="evm"?await T.connect():await E.connect()))re(m==="evm"?Kr():C.current.noWalletForOption)}catch(y){let v=He(y,{step:"connecting",copy:C.current});re(v.kind==="rejected"?C.current.rejectedConnect:v.message)}finally{Ln(!1)}},[_,Le,T,E,We,Xe]),Zn=(d,m)=>`${m}:${d.name}`,ea=V==="wallets"?fe().wallet:void 0,ta=(d)=>T.wallets.map((m)=>({id:`${d}${m.id}`,name:m.name,icon:m.icon,lastUsed:m.name===ea})),na=(d)=>E.wallets.map((m,y)=>({id:`${d}${Zn(m,y)}`,name:m.name,icon:Is(m),lastUsed:m.name===ea})),Qr=V!=="wallets"?[]:Re==="evm"?ta(""):Re==="solana"?na(""):[...ta("evm|"),...na("solana|")],Yr=async(d)=>{Cn(d),re(null);let m=Re==="any"?/^(evm|solana)\|(.*)$/.exec(d):null,y=m?m[1]:Re==="any"?"evm":Re,v=m?m[2]:d;try{let w=!1;if(y==="evm"){let S=T.wallets.find((M)=>M.id===v);w=!!S&&!!await T.connect(S)}else{let S=E.wallets.findIndex((Se,J)=>Zn(Se,J)===v),M=E.wallets[S];w=!!M&&!!await E.connect(M)}if(w)xe("pick")}catch(w){let S=He(w,{step:"connecting",copy:C.current});re(S.kind==="rejected"?C.current.rejectedPick:S.message)}finally{Cn(null)}},ge=W(async()=>{if(T.connRef.current)await pe("evm",T.connRef.current.account);if(E.connRef.current)await pe("solana",E.connRef.current.session.address)},[T.connRef,E.connRef,pe]),aa=W(async()=>{ce({type:"reset"}),re(null),await ge()},[ge]),Jr=(d)=>d.kind==="evm"?T.conn?{kind:"evm",provider:T.conn.provider,account:T.conn.account}:null:E.conn?{kind:"solana",session:E.conn.session,account:E.conn.session.address}:null,Vr=W(async()=>{let d=_,m=d?Jr(d):null;if(!d||!m||!Oe.current)return;ce({type:"start"}),Lt(null),Pn(null),Ee(!1);let y="connecting",v=Oe.current;try{for(let w=0;;w++)try{if(v.expiresAt&&Date.parse(v.expiresAt)-Date.now()<30000){let J=await se(!0);if(!J.ok)throw new ne(J.problem);v=J.charge}let S=cn(v.serviceUrl,v.chargeId,v.clientSecret),M=F(d)?{...S,pay:async(J,Vt)=>{let ot=Bn.current,mo=ot.status==="ready"?ot.quote:ot.status==="loading"?ot.previous:null,Xt=gn(await S.lifiQuote(J,Vt));if(Ne({type:"ok",quote:Xt,optionId:J}),or(mo,Xt))throw new ne({kind:"service",message:C.current.priceChanged});return Pr(Xt)}}:S,Se=await Ar({option:d,session:m,amount:v.amount,api:M,copy:C.current,hooks:{step:(J)=>{y=J,ce({type:"step",step:J})},tx:(J,Vt)=>Lt({i:J,total:Vt})}});Pn(Se.estimatedSeconds),ce({type:"submitted"});return}catch(S){if(w===0&&Oa(S)){let M=await se(!0);if(M.ok){v=M.charge;continue}ce({type:"failed",problem:{...M.problem}});return}throw S}}catch(w){if(w instanceof ne&&(w.problem.kind==="insufficient"||w.problem.kind==="no_gas"))ge();Xn(w,y)}finally{Lt(null)}},[_,T.conn,E.conn,se,Xn,ge]),Xr=xt(()=>Va(U,G,{evm:Q.evm,solana:Q.solana},he),[U,G,Q.evm,Q.solana,he]),ra=xt(()=>{let d=Xa(U.map(ht));return new Map(U.map((m,y)=>[m.id,{...d[y],icon:cr(m)}]))},[U]),Zr=(d)=>d==="not_enough"?f.notEnough:d==="needs_wallet"?f.needsOtherWallet:d==="unreadable"?f.couldntCheck:null,eo=new Set(pn(U,G,Q).map((d)=>d.id)),to=Xr.filter((d)=>eo.has(d.id)).map((d)=>{let m=Ja(d,G[d.id],he,Q);return{id:d.id,chain:ht(d),badge:ra.get(d.id)??null,balanceText:m.balanceText,disabled:m.disabled,reason:Zr(m.reason),loading:m.loading,...F(d)?{symbol:d.token.symbol,logo:d.token.logo}:{}}}),ue=ar(_,Q,_?G[_.id]:void 0,he,Ke),Ft=ue.reason==="needs_gas",qt=_t==="empty"||_t==="short",oa=qt||Ft||H?.kind==="insufficient"||H?.kind==="no_gas",no=X?{label:nt,disabled:!0,busy:!0,onClick:()=>{},ref:Ht}:{label:(()=>ue.kind==="connect"?Le?f.connectingWallet:f.connectWallet:ue.reason==="checking"?le&&et?.status==="ok"?f.youPayChecking:f.checking:ue.reason==="not_enough"?le?B(f.notEnoughToken,{symbol:le.token.symbol}):f.notEnoughUsdc:ue.reason==="needs_gas"?f.needsGas:ue.reason==="unavailable"?f.optionUnavailable:B(f.pay,{amount:Ze}))(),disabled:ue.disabled||!A,busy:Le,spinner:ue.reason==="checking",onClick:()=>void(ue.kind==="connect"?Gr():Vr()),ref:Ht};I(()=>{if(!oa||!D)return;let d=()=>{if(document.visibilityState==="visible")ge()};return window.addEventListener("focus",d),document.addEventListener("visibilitychange",d),()=>{window.removeEventListener("focus",d),document.removeEventListener("visibilitychange",d)}},[oa,D,ge]);let rt=(qt||Ft)&&D;I(()=>{if(!rt)return;let d=Date.now(),m=setInterval(()=>{if(Date.now()-d>120000)clearInterval(m);else ge()},5000);return()=>clearInterval(m)},[rt,ge]);let Be=U.filter((d)=>Q[d.kind]).map((d)=>{let m=G[d.id];return m?.status==="ok"?`${d.id}:${m.usdc}:${m.native??""}`:m?.status??"-"}).join("|"),Kt=P(null),sa=P(!1);I(()=>{if(!Be.includes("loading")&&!Be.includes("-")){if(sa.current&&Kt.current!==null&&Kt.current!==Be)Ie(C.current.balanceUpdated);Kt.current=Be}sa.current=rt},[Be,rt]);let ao=W(()=>{j(!0),xe("pick"),Ge(!1),Ee(!1),z(!0)},[]),De=W(()=>{z(!1)},[]);I(()=>{if(!D||O.step!=="idle")return;let d=Oe.current;if(d?.expiresAt&&Date.parse(d.expiresAt)-Date.now()<120000)se(!0)},[D]);let ia=W(()=>{if(X&&!Y)Ee((d)=>!d);else De()},[X,Y,De]);I(()=>{if(!X||Y)Ee(!1)},[X,Y]);let ca={className:`sc-root${o?` ${o}`:""}`,"data-appearance":s,"data-testid":"payments-checkout","data-state":_e},Gt=x("div",{className:"sc-live",role:"status","aria-live":"polite","aria-atomic":"true","data-testid":"sc-live",children:Fr}),Qt=Pa(n,typeof window>"u"?"":window.location.origin),Yt=q?.status==="underpaid"&&A?Na(A.amount,q.funded_amount):null,ro=be&&_?{onCopy:()=>{try{navigator.clipboard?.writeText(be.address)?.catch(()=>{})}catch{}},onSwitch:()=>{let d=_.kind;if(Xe&&T.wallets.length>0&&E.wallets.length>0)We("any");else if(d==="evm"?T.wallets.length>1:E.wallets.length>1)We(d);else if(d==="evm")T.switchAccount().catch((m)=>{let y=He(m,{step:"connecting",copy:C.current});if(y.kind!=="rejected")re(y.message)});else E.disconnect(),E.connect().catch(()=>{})},onDisconnect:()=>{if(Ge(!1),re(null),_.kind==="evm")T.disconnect();else E.disconnect()}}:null,la=x("button",{type:"button",className:"sc-sec",onClick:()=>void aa(),children:f.checkAgain}),oo=x("button",{type:"button",className:"sc-link",onClick:()=>void aa(),children:f.checkAgain}),so=k?x("button",{type:"button",className:"sc-link",onClick:()=>xe("manual"),children:f.payAnotherWay}):null,Ce=typeof window>"u"?"":window.location.href,io=Te===f.noWallet||Te===f.noWalletMobile,co=Yt!==null&&Yt>0n?B(f.partial,{received:we(BigInt(q?.funded_amount||"0")),remaining:we(Yt)}):Te?K(Ct,{children:[Te,Hr&&io&&_?.kind==="evm"&&(st(Ce)||it(Ce))&&K("div",{className:"sc-actions",children:[st(Ce)&&x("a",{className:"sc-link",href:st(Ce),children:f.openInWalletApp}),it(Ce)&&x("a",{className:"sc-link",href:it(Ce),children:f.openInPhantom})]})]}):qt?K(Ct,{children:[_t==="empty"?f.noUsdc:f.insufficientAll,la]}):Ft?K(Ct,{children:[f.needsGasReason,la]}):null,lo=(d)=>{switch(d.kind){case"insufficient":case"no_gas":return oo;case"expired":case"conflict":return x("button",{type:"button",className:"sc-link",onClick:()=>void se(!1),children:f.startNew});case"network":case"service":case"unknown":case"tx_failed":return x("button",{type:"button",className:"sc-link",onClick:()=>ce({type:"reset"}),children:f.tryAgain});default:return null}},ua=!ke&&A&&Rt.status==="error"?{kind:"service",message:f.service}:null,uo=ke?x(ft,{problem:ke,copy:f,noticeRef:at,children:x("button",{type:"button",className:"sc-link",onClick:()=>void se(!1),children:ke.kind==="conflict"?f.startNew:f.tryAgain})}):ua?K(ft,{problem:ua,copy:f,noticeRef:at,children:[x("button",{type:"button",className:"sc-link",onClick:()=>Br((d)=>d+1),children:f.tryAgain}),so]}):H?x(ft,{problem:H,copy:f,noticeRef:at,children:lo(H)}):null,po=!!A&&!!q&&Rt.status==="ready",go=Y?"done":V==="manual"&&A?"manual":!po?"loading":X?"paying":V==="wallets"?"wallets":"pick",Jt=A?Ya(A,U):null,fo=A&&Jt?x(Ws,{entry:{address:A.chargeAddress,chain:ht(Jt),badge:ra.get(Jt.id)??null},copy:f,amountText:Ze}):null,da=_&&Q[_.kind]?tr(_,G[_.id],f):[],pa=x(qa,{copy:f,titleId:te,titleRef:$t,title:Ba(f,L),amountText:Ze,phase:go,wallet:be?{name:be.name,short:Zt(be.address),address:be.address}:null,walletActions:ro,walletPicker:V==="wallets"?{wallets:Qr,busyId:Or,onPick:(d)=>void Yr(d)}:null,onClose:p?null:ia,onBack:()=>xe("pick"),options:to,selectedId:Nt,menuOpen:jr,onMenuChange:Ge,onSelect:(d)=>{Hn.current=!0,re(null),Nn(d);let m=U.find((v)=>v.id===d),y=m?.kind==="evm"?T.connRef.current?.account:E.connRef.current?.session.address;if(m&&y&&G[d]?.status==="error")pe(m.kind,y)},decorator:da,payLine:le&&Q.evm&&Ut?ir(le,Ke,f):null,onPayLineRetry:()=>Ur((d)=>d+1),decoratorKey:Nt,refreshing:_r>0&&da.length>0,cta:no,message:V==="wallets"?Te:co,notice:uo,stages:X?_a(O.step):null,tx:Qe,walletName:zt,slow:zr,closeGuard:Mr?{onStay:()=>Ee(!1),onClose:De}:null,done:Y&&A?{receipt:Ea(A.chargeId),finalizing:!1,slot:g,returnHref:Qt,ref:Vn,onDone:p?void 0:De}:null,manual:fo,onPayAnotherWay:A&&k?()=>xe("manual"):null});if(p)return K("div",{...ca,children:[x("style",{children:on}),Gt,pa]});let ga=X&&!Y?nt:null;return K("div",{...ca,children:[x("style",{children:on}),!D&&Gt,Y&&!D?K("div",{"data-testid":"sc-inline-done",children:[x("p",{className:"sc-inline-ok",role:"status",children:f.received}),g?x("div",{className:"sc-slot",children:g}):null,Qt&&x("a",{className:"sc-link-a",href:Qt,children:f.returnToStore})]}):x("button",{type:"button",className:"sc-btn","aria-haspopup":"dialog","aria-busy":!!ga,"data-testid":"sc-trigger",onClick:ao,children:x("span",{children:ga??f.trigger})}),K(Fa,{open:D,onClose:ia,onBackdrop:X&&!Y?()=>{}:De,titleId:te,initialFocus:$t,children:[Gt,pa]})]})}function kn(e,t){return e.split("{network}").flatMap((n,a)=>a===0?[n]:[x("strong",{className:"sc-net",children:t},a),n])}function Ws({entry:e,copy:t,amountText:n}){let[a,r]=N(!1),[o,s]=N(!1),i=P(null),l=P(null),u=Nr();I(()=>()=>{if(i.current)clearTimeout(i.current)},[]);let g=(k)=>{r(k),s(!1)};async function h(k){let R=!1;try{await navigator.clipboard.writeText(k),R=!0}catch{let L=l.current;if(L){let p=document.createRange();p.selectNodeContents(L);let f=window.getSelection();f?.removeAllRanges(),f?.addRange(p);try{R=document.execCommand("copy")}catch{R=!1}}}if(R){if(s(!0),i.current)clearTimeout(i.current);i.current=setTimeout(()=>s(!1),2000)}}return K("div",{"data-testid":"sc-manual",children:[K("span",{className:"sc-chip",children:[x(dt,{badge:e.badge}),x(pt,{chain:e.chain})]}),x("div",{className:"sc-notice","data-kind":"manual",role:"note",id:u,"data-testid":"sc-manual-warning",children:kn(t.manualWarning,e.chain)}),K("label",{className:"sc-confirm",children:[x("input",{type:"checkbox",checked:a,onChange:(k)=>g(k.target.checked),"aria-describedby":u,"data-testid":"sc-manual-confirm"}),x("span",{children:kn(t.manualConfirm,e.chain)})]}),a&&K(Ct,{children:[x("p",{className:"sc-muted",children:B(t.manualIntro,{amount:n})}),x("code",{className:"sc-addr",ref:l,"data-testid":"charge-address",title:Zt(e.address),children:e.address}),x("div",{className:"sc-two",children:K("button",{type:"button",className:"sc-btn",onClick:()=>void h(e.address),"data-testid":"sc-copy",children:[o?x($e,{size:18}):x(sn,{}),x("span",{children:o?t.copied:t.copyAddress})]})})]}),x("p",{className:"sc-live",role:"status","aria-live":"polite",children:o?t.copied:""}),x("p",{className:"sc-muted",children:t.manualWaiting}),x("p",{className:"sc-muted","data-testid":"sc-manual-own-wallet",children:kn(t.manualOwnWallet,e.chain)})]})}var Lr={ok:!1,status:503,error:"Checkout is temporarily unavailable."},Tr=(e)=>!!e&&typeof e==="object"&&!Array.isArray(e),St=(e)=>typeof e==="string"?e:void 0,Bs=(e)=>Tr(e)?{error:St(e.error),code:St(e.code)}:{};async function Ds(e){let t=new Headers({"content-type":"application/json"}),n=typeof e==="function"?await e():e;if(n)new Headers(n).forEach((a,r)=>t.set(r,a));return t}function Us(e,t,n){let a=(()=>{try{return n(t)??{}}catch{return{}}})(),r=St(a.code);return{ok:!1,status:e,error:St(a.error)??"Checkout is temporarily unavailable.",...r?{code:r}:{}}}async function js(e,t,n={}){let{method:a="POST",credentials:r,signal:o,selectCharge:s=(l)=>l,selectError:i=Bs}=n;try{let u=await(n.fetch??fetch)(e,{method:a,headers:await Ds(n.headers),body:typeof t==="string"?t:JSON.stringify(t),...r?{credentials:r}:{},...o?{signal:o}:{}}),g=await u.json().catch(()=>null);if(!u.ok)return Us(u.status,g,i);let h=s(g);return Tr(h)?{ok:!0,charge:h}:Lr}catch{return Lr}}export{_s as CheckoutWidget,js as postCreateCharge};
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var C={testnet:void 0,mainnet:void 0};class d extends Error{status;code;constructor(e,n,a){super(a);this.name="RioError",this.status=e,this.code=n}}var w=3,h=(e)=>!!e&&typeof e==="object"&&!Array.isArray(e),l=(e)=>typeof e==="string"?e:void 0,R=(e)=>["localhost","127.0.0.1","[::1]"].includes(e.hostname),v=(e)=>{let n;try{n=new URL(e)}catch{throw TypeError("createRioClient: serviceUrl is not a URL.")}if(n.username||n.password)throw TypeError("createRioClient: serviceUrl must not contain credentials.");if(n.protocol!=="https:"&&!(n.protocol==="http:"&&R(n)))throw TypeError("createRioClient: serviceUrl must be https (http only for localhost).");return`${n.origin}${n.pathname.replace(/\/+$/,"")}`},x=(e,n,a)=>{if(e.serviceUrl!==void 0)return e.serviceUrl;if(e.environment!==void 0&&!(e.environment in n))throw TypeError(`createRioClient: unknown environment "${String(e.environment)}".`);let c=e.environment??(a?void 0:"mainnet");if(c===void 0)return a;let s=n[c];if(s===void 0)throw TypeError(`createRioClient: there is no default URL for ${c} yet. Pass serviceUrl (or set RIO_SERVICE_URL).`);return s},_=(e)=>({amount:e.amount,external_ref:e.externalId,...e.origin!==void 0?{origin:e.origin}:{},...e.merchantId!==void 0?{merchant_id:e.merchantId}:{},...e.returnUrl!==void 0?{return_url:e.returnUrl}:{},...e.expiresInSeconds!==void 0?{expires_in_seconds:e.expiresInSeconds}:{},...e.requireConfirmation!==void 0?{require_confirmation:e.requireConfirmation}:{},...e.speed!==void 0?{speed:e.speed}:{},...e.tags!==void 0?{tags:e.tags}:{},...e.metadata!==void 0?{metadata:e.metadata}:{}}),y=(e,n)=>{let a=n.chain;if(typeof n.id!=="string"||typeof n.client_secret!=="string"||!h(a))return null;return{chargeId:n.id,clientSecret:n.client_secret,serviceUrl:e,amount:String(n.amount),chain:a,chargeAddress:String(n.charge_address),status:n.status,confirmed:n.confirmed===!0,confirmation:n.confirmation,expiresAt:l(n.expires_at)??null}},p=(e)=>({chargeId:String(e.id),orderId:l(e.external_ref)??null,status:e.status,confirmed:e.confirmed===!0,confirmation:e.confirmation,collectedAmount:l(e.collected_amount)??null});function I(e){if(!e.apiKey)throw TypeError("createRioClient needs an apiKey.");let n=v(x(e,C,typeof process>"u"?void 0:process.env?.RIO_SERVICE_URL)),a=e.apiKey,c=async(s,r)=>{let t=await(async()=>{try{return await(e.fetch??fetch)(`${n}${s}`,{method:r.method,headers:{authorization:`Bearer ${a}`,...r.body!==void 0?{"content-type":"application/json"}:{},...r.headers},...r.body!==void 0?{body:JSON.stringify(r.body)}:{},cache:"no-store"})}catch{throw new d(0,"network_error","Could not reach the service.")}})(),o=await t.json().catch(()=>null);if(!t.ok){let i=h(o)&&h(o.error)?o.error:{};throw new d(t.status,l(i.code)??"request_failed",l(i.message)??`The request failed (${t.status}).`)}if(!h(o))throw new d(t.status,"invalid_response","The service answered with something that is not a charge.");return{status:t.status,json:o}};return{charges:{create:async(s,r={})=>{let t=r.idempotencyKey??s.externalId;for(let o=0;o<=w;o+=1){let{json:i}=await c("/v1/charges",{method:"POST",headers:{"idempotency-key":t},body:_(s)}),f=y(n,i);if(f!==null)return f;let u=l(i.id);if(u===void 0)throw new d(200,"invalid_response","The service answered with something that is not a charge.");if(r.idempotencyKey===void 0&&i.status==="expired"){t=`renew:${u}`;continue}let g=await c(`/v1/charges/${encodeURIComponent(u)}/client_secret`,{method:"POST"}),m=y(n,{...i,client_secret:g.json.client_secret});if(m===null)throw new d(g.status,"client_secret_unavailable","The service did not return a client secret for this charge.");return m}throw new d(409,"charge_expired","Every charge for this order has expired. Create the order again with a new external id.")},get:async(s)=>{let{id:r,externalId:t}=s;if(r===void 0===(t===void 0))throw TypeError("charges.get needs exactly one of { id } or { externalId }.");if(r!==void 0)return p((await c(`/v1/charges/${encodeURIComponent(r)}`,{method:"GET"})).json);let o=await c(`/v1/charges?external_ref=${encodeURIComponent(t)}&limit=1`,{method:"GET"}),i=Array.isArray(o.json.data)?o.json.data[0]:void 0;if(!h(i))throw new d(404,"not_found","No charge has this external id.");return p(i)}}}}export{C as RIO_ENVIRONMENT_URLS,d as RioError,I as createRioClient};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import { type ChainBadge } from "./payments-modal";
|
|
3
|
-
import { type ChargeCreateResult, type PlatformChargeStatus, type Problem, type
|
|
4
|
-
export type {
|
|
5
|
-
interface
|
|
3
|
+
import { type ChargeCreateResult, type PlatformChargeStatus, type Problem, type CheckoutCopy, type CheckoutState } from "../lib/payments";
|
|
4
|
+
export type { CheckoutCopy, CheckoutState, Problem as CheckoutError };
|
|
5
|
+
interface CheckoutWidgetBaseProps {
|
|
6
6
|
/** Your order id. The charge is idempotent per order. */
|
|
7
7
|
orderId: string;
|
|
8
8
|
/** Creates the charge through your own server route and resolves to a `ChargeCreateResult` (`postCreateCharge(url, body)` does the fetch for the common case). Called when the modal first opens. The widget validates the charge itself before using it. */
|
|
@@ -17,11 +17,11 @@ interface PaymentsCheckoutBaseProps {
|
|
|
17
17
|
/** "auto" follows the visitor's prefers-color-scheme. Default "auto". */
|
|
18
18
|
appearance?: "auto" | "light" | "dark";
|
|
19
19
|
/** Coarse, UI-facing state changes (loading, ready, connecting, confirming, processing, paid, settled, problem, failed). */
|
|
20
|
-
onStatusChange?: (state:
|
|
20
|
+
onStatusChange?: (state: CheckoutState) => void;
|
|
21
21
|
/** Called whenever the buyer is shown a problem (never contains the client secret). `cause` holds the raw host, service or wallet text, which is never shown to the buyer. */
|
|
22
22
|
onError?: (error: Problem) => void;
|
|
23
23
|
/** Override any user-facing string (i18n, the trigger label). `{amount}`-style placeholders are filled in. */
|
|
24
|
-
copy?: Partial<
|
|
24
|
+
copy?: Partial<CheckoutCopy>;
|
|
25
25
|
/** Rendered under the success message. */
|
|
26
26
|
successSlot?: ReactNode;
|
|
27
27
|
/** Open the modal on mount (and create the charge right away). Default false. */
|
|
@@ -52,8 +52,8 @@ interface PaymentsCheckoutBaseProps {
|
|
|
52
52
|
* Theme with CSS custom properties on the widget or any ancestor: --sc-accent,
|
|
53
53
|
* --sc-radius, --sc-bg, --sc-fg, --sc-muted, --sc-border, --sc-success, --sc-danger.
|
|
54
54
|
*/
|
|
55
|
-
export type
|
|
56
|
-
export declare function
|
|
55
|
+
export type CheckoutWidgetProps = CheckoutWidgetBaseProps;
|
|
56
|
+
export declare function CheckoutWidget({ orderId, createCharge, returnUrl, onPaid, statusUrl, className, appearance, onStatusChange, onError, copy: copyOverrides, successSlot, defaultOpen, manualPayment, presentation, merchantName, }: CheckoutWidgetProps): import("react").JSX.Element;
|
|
57
57
|
/** The address on the "pay another way" screen: the chip shows which chain's USDC it takes (service data). */
|
|
58
58
|
export interface ManualEntry {
|
|
59
59
|
address: string;
|
|
@@ -68,6 +68,6 @@ export interface ManualEntry {
|
|
|
68
68
|
*/
|
|
69
69
|
export declare function PayManual({ entry, copy, amountText }: {
|
|
70
70
|
entry: ManualEntry;
|
|
71
|
-
copy:
|
|
71
|
+
copy: CheckoutCopy;
|
|
72
72
|
amountText: string;
|
|
73
73
|
}): import("react").JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
import { type Problem, type
|
|
2
|
+
import { type Problem, type CheckoutCopy, type Stage } from "../lib/payments";
|
|
3
3
|
import type { DecoratorItem, PayLine } from "../lib/payments-options";
|
|
4
4
|
export declare const CSS: string;
|
|
5
5
|
export declare const Spinner: ({ small }: {
|
|
@@ -98,7 +98,7 @@ export interface WalletActions {
|
|
|
98
98
|
/** The connected wallet: a button that opens copy address / switch wallet / disconnect (inert while a payment is in flight). */
|
|
99
99
|
export declare function WalletChip({ wallet, copy, actions, inert }: {
|
|
100
100
|
wallet: WalletChipInfo;
|
|
101
|
-
copy:
|
|
101
|
+
copy: CheckoutCopy;
|
|
102
102
|
actions: WalletActions | null;
|
|
103
103
|
inert: boolean;
|
|
104
104
|
}): import("react").JSX.Element;
|
|
@@ -112,12 +112,12 @@ export interface PickerWallet {
|
|
|
112
112
|
export declare function WalletList({ wallets, busyId, copy, onPick }: {
|
|
113
113
|
wallets: PickerWallet[];
|
|
114
114
|
busyId: string | null;
|
|
115
|
-
copy:
|
|
115
|
+
copy: CheckoutCopy;
|
|
116
116
|
onPick: (id: string) => void;
|
|
117
117
|
}): import("react").JSX.Element;
|
|
118
118
|
export declare function Stepper({ stages, copy, tx, walletName }: {
|
|
119
119
|
stages: Stage[];
|
|
120
|
-
copy:
|
|
120
|
+
copy: CheckoutCopy;
|
|
121
121
|
tx: {
|
|
122
122
|
i: number;
|
|
123
123
|
total: number;
|
|
@@ -126,12 +126,12 @@ export declare function Stepper({ stages, copy, tx, walletName }: {
|
|
|
126
126
|
}): import("react").JSX.Element;
|
|
127
127
|
export declare function ProblemNotice({ problem, copy, noticeRef, children, }: {
|
|
128
128
|
problem: Problem;
|
|
129
|
-
copy:
|
|
129
|
+
copy: CheckoutCopy;
|
|
130
130
|
noticeRef?: React.RefObject<HTMLDivElement | null>;
|
|
131
131
|
children?: ReactNode;
|
|
132
132
|
}): import("react").JSX.Element;
|
|
133
133
|
export declare function DoneView({ copy, amountText, receipt, finalizing, slot, returnHref, doneRef, onDone, }: {
|
|
134
|
-
copy:
|
|
134
|
+
copy: CheckoutCopy;
|
|
135
135
|
amountText: string;
|
|
136
136
|
receipt: string;
|
|
137
137
|
finalizing: boolean;
|
|
@@ -180,11 +180,11 @@ export interface Cta {
|
|
|
180
180
|
/** What the buyer pays in their own token, as a polite status (so a price change is announced, never silent). */
|
|
181
181
|
export declare function PayLineView({ line, copy, onRetry }: {
|
|
182
182
|
line: PayLine;
|
|
183
|
-
copy:
|
|
183
|
+
copy: CheckoutCopy;
|
|
184
184
|
onRetry?: () => void;
|
|
185
185
|
}): import("react").JSX.Element;
|
|
186
186
|
export interface ModalCardProps {
|
|
187
|
-
copy:
|
|
187
|
+
copy: CheckoutCopy;
|
|
188
188
|
titleId: string;
|
|
189
189
|
titleRef?: React.RefObject<HTMLHeadingElement | null>;
|
|
190
190
|
/** Header text; defaults to `copy.title`. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { ChargeCreateResult, ChargeStatus, Confirmation, CreatedCharge,
|
|
1
|
+
export type { ChargeCreateResult, ChargeStatus, Confirmation, CreatedCharge, CheckoutCopy, PlatformChargeStatus, } from "./lib/payments";
|
|
2
2
|
export type { PostCreateChargeOptions } from "./lib/create-charge";
|
|
3
3
|
export type { WebhookEvent, WebhookEventType } from "./lib/events";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AddChainParams, type CreatedCharge, type
|
|
1
|
+
import { type AddChainParams, type CreatedCharge, type CheckoutCopy } from "./payments";
|
|
2
2
|
export type OptionKind = "evm" | "solana";
|
|
3
3
|
export interface PaymentOption {
|
|
4
4
|
id: string;
|
|
@@ -115,7 +115,7 @@ export type GasState = "na" | "ok" | "low" | "none";
|
|
|
115
115
|
*/
|
|
116
116
|
export declare function gasState(o: PaymentOption, bal: OptionBalance | undefined): GasState;
|
|
117
117
|
/** The balances the decorator row cycles through, each shown as a plain "amount SYMBOL" (e.g. "19.60 USDC", then "4.31 SEI"). `label` is only a stable key. */
|
|
118
|
-
export declare function decoratorItems(o: PaymentOption, bal: OptionBalance | undefined, copy:
|
|
118
|
+
export declare function decoratorItems(o: PaymentOption, bal: OptionBalance | undefined, copy: CheckoutCopy): DecoratorItem[];
|
|
119
119
|
export type BalanceSummary = "idle" | "loading" | "empty" | "short" | "ok";
|
|
120
120
|
/**
|
|
121
121
|
* How the connected wallet(s) look overall, for the calm message under the amount:
|
|
@@ -219,7 +219,7 @@ export interface PayLine {
|
|
|
219
219
|
note?: string;
|
|
220
220
|
}
|
|
221
221
|
/** The line that tells the buyer what they pay in their own token. Absent for every other option. */
|
|
222
|
-
export declare function lifiPayLine(o: PaymentOption, state: LifiQuoteState, copy:
|
|
222
|
+
export declare function lifiPayLine(o: PaymentOption, state: LifiQuoteState, copy: CheckoutCopy): PayLine | null;
|
|
223
223
|
export type ChainIconKey = "sei" | "base" | "solana";
|
|
224
224
|
/** Which official chain mark an option gets, from its (service-provided) chain id. Unknown chains fall back to the letter badge. */
|
|
225
225
|
export declare function chainIconKey(o: Pick<PaymentOption, "kind" | "chain">): ChainIconKey | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AddChainParams, type PayStep, type
|
|
1
|
+
import { type AddChainParams, type PayStep, type CheckoutCopy, type TypedDataPayload } from "./payments";
|
|
2
2
|
import { type LifiQuote, type PaymentOption } from "./payments-options";
|
|
3
3
|
import { type Eip1193Provider } from "./payments-wallet";
|
|
4
4
|
import { type SolanaSession } from "./payments-solana";
|
|
@@ -66,7 +66,7 @@ type PayArgs = {
|
|
|
66
66
|
amount: string;
|
|
67
67
|
api: PayApi;
|
|
68
68
|
hooks: PayHooks;
|
|
69
|
-
copy:
|
|
69
|
+
copy: CheckoutCopy;
|
|
70
70
|
signal?: AbortSignal;
|
|
71
71
|
intervalMs?: number;
|
|
72
72
|
/** How long to follow a sent payment on chain before leaving it to the charge's status (defaults per chain). */
|
package/dist/lib/payments.d.ts
CHANGED
|
@@ -117,7 +117,7 @@ export declare function sameOriginReturnUrl(returnUrl: unknown, origin: string):
|
|
|
117
117
|
* Every user-facing string. `{name}` placeholders are filled by `fill`. Override any subset via the `copy` prop.
|
|
118
118
|
* Network names are never copy: they come from the service as data and appear only on the token chip.
|
|
119
119
|
*/
|
|
120
|
-
export interface
|
|
120
|
+
export interface CheckoutCopy {
|
|
121
121
|
trigger: string;
|
|
122
122
|
title: string;
|
|
123
123
|
/** Header when the host names the merchant: `{merchant}` is filled in. */
|
|
@@ -229,9 +229,9 @@ export interface PaymentsCopy {
|
|
|
229
229
|
notEnoughToken: string;
|
|
230
230
|
priceChanged: string;
|
|
231
231
|
}
|
|
232
|
-
export declare const DEFAULT_COPY:
|
|
232
|
+
export declare const DEFAULT_COPY: CheckoutCopy;
|
|
233
233
|
export declare function fill(template: string, vars?: Record<string, string | number>): string;
|
|
234
|
-
export declare function resolveCopy(overrides?: Partial<
|
|
234
|
+
export declare function resolveCopy(overrides?: Partial<CheckoutCopy>): CheckoutCopy;
|
|
235
235
|
/** "$0.05", "$12.50", "$1,234.56": USDC base units shown as dollars. */
|
|
236
236
|
export declare function formatUsd(base: string | bigint): string;
|
|
237
237
|
/** "base-sepolia" -> "Base Sepolia". Fallback label when the service sends no display name. */
|
|
@@ -271,7 +271,7 @@ export declare class PaymentProblem extends Error {
|
|
|
271
271
|
export interface ErrorContext {
|
|
272
272
|
/** The pay step that was running when the error happened. */
|
|
273
273
|
step?: PayStep;
|
|
274
|
-
copy?:
|
|
274
|
+
copy?: CheckoutCopy;
|
|
275
275
|
}
|
|
276
276
|
/** The only fields a buyer may see under "Show details": an HTTP status and a code from a fixed list, never free text. */
|
|
277
277
|
export declare function safeDetail(parts: {
|
|
@@ -283,7 +283,7 @@ export declare function mapCreateFailure(r: {
|
|
|
283
283
|
status: number;
|
|
284
284
|
error?: string;
|
|
285
285
|
code?: string;
|
|
286
|
-
}, copy?:
|
|
286
|
+
}, copy?: CheckoutCopy): Problem;
|
|
287
287
|
/** Turns any wallet/provider/service error into one controlled message plus a collapsed detail of controlled fields; the raw text goes to `cause` (host only). */
|
|
288
288
|
export declare function mapError(e: unknown, ctx?: ErrorContext): Problem;
|
|
289
289
|
/** True when a raw error means the charge/authorization can no longer be used and a fresh one should be made. */
|
|
@@ -328,16 +328,16 @@ export declare function deriveStages(step: PayStep): Stage[];
|
|
|
328
328
|
* Text for the exact step, used by the live region, the busy button and the store-page trigger.
|
|
329
329
|
* `wallet` is the connected wallet's name when it is known ("your wallet" is the fallback).
|
|
330
330
|
*/
|
|
331
|
-
export declare function primaryLabel(step: PayStep, amountText: string, copy?:
|
|
331
|
+
export declare function primaryLabel(step: PayStep, amountText: string, copy?: CheckoutCopy, wallet?: string | null): string;
|
|
332
332
|
/** "Confirm in MetaMask (1 of 2)" / "Confirm in your wallet (1 of 2)". */
|
|
333
|
-
export declare function confirmTxLabel(copy:
|
|
333
|
+
export declare function confirmTxLabel(copy: CheckoutCopy, tx: {
|
|
334
334
|
i: number;
|
|
335
335
|
total: number;
|
|
336
336
|
}, wallet?: string | null): string;
|
|
337
337
|
/** Header text: "Pay" or "Pay {merchant}" when the host names the store. */
|
|
338
|
-
export declare function headerTitle(copy:
|
|
338
|
+
export declare function headerTitle(copy: CheckoutCopy, merchantName?: string | null): string;
|
|
339
339
|
/** Coarse state surfaced through `onStatusChange`. */
|
|
340
|
-
export type
|
|
340
|
+
export type CheckoutState = "loading" | "ready" | "connecting" | "confirming" | "processing" | "paid" | "settled" | "problem" | "failed";
|
|
341
341
|
export interface Prefs {
|
|
342
342
|
wallet?: string;
|
|
343
343
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { CreatedCharge, PlatformChargeStatus } from "./payments";
|
|
2
|
+
/** The networks the service runs on. Each has a default API URL: pick one with `environment`, or pass your own `serviceUrl`. */
|
|
3
|
+
export type RioEnvironment = "testnet" | "mainnet";
|
|
4
|
+
/**
|
|
5
|
+
* The default API base URL of each environment. `undefined` until the stable URL exists (set it here when it does): an environment
|
|
6
|
+
* without one makes `createRioClient` throw and ask for a `serviceUrl`, rather than call a host that is not there.
|
|
7
|
+
*/
|
|
8
|
+
export declare const RIO_ENVIRONMENT_URLS: Readonly<Record<RioEnvironment, string | undefined>>;
|
|
9
|
+
export interface RioClientOptions {
|
|
10
|
+
/** A secret API key (`sk_…`), from the dashboard's Developers page. Keep it on your server. */
|
|
11
|
+
apiKey: string;
|
|
12
|
+
/** The API base URL. It wins over `environment`. */
|
|
13
|
+
serviceUrl?: string;
|
|
14
|
+
/** `"testnet"` or `"mainnet"`: the default URL of that environment. Default: the `RIO_SERVICE_URL` environment variable where there is one, else `"mainnet"`. */
|
|
15
|
+
environment?: RioEnvironment;
|
|
16
|
+
/** A custom `fetch`. Default: the global `fetch`, looked up at call time. */
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
}
|
|
19
|
+
export interface CreateChargeInput {
|
|
20
|
+
/** USDC base units, as a string: `"12500000"` is $12.50. Decide it on your server, never from the browser. */
|
|
21
|
+
amount: string;
|
|
22
|
+
/** Your order id (the charge's external id). `charges.get` finds the charge by it. */
|
|
23
|
+
externalId: string;
|
|
24
|
+
/** Your storefront's web origin. A browser can only use the charge from there. Leave it out for a charge only a server handles. */
|
|
25
|
+
origin?: string;
|
|
26
|
+
merchantId?: string;
|
|
27
|
+
returnUrl?: string;
|
|
28
|
+
expiresInSeconds?: number;
|
|
29
|
+
requireConfirmation?: "provisional" | "final";
|
|
30
|
+
/** Settlement speed: `"standard"` (the default, no fee) or `"fast"`. */
|
|
31
|
+
speed?: "standard" | "fast";
|
|
32
|
+
/** Labels for filtering and reporting (at most 10, lowercase `[a-z0-9][a-z0-9:_./-]{0,63}`). */
|
|
33
|
+
tags?: readonly string[];
|
|
34
|
+
/** Private values to keep with the charge (strings, numbers or booleans, never nested). Returned to you, never to the buyer. */
|
|
35
|
+
metadata?: Readonly<Record<string, string | number | boolean>>;
|
|
36
|
+
}
|
|
37
|
+
export interface CreateChargeOptions {
|
|
38
|
+
/** Default: the external id, so a retried request returns the same charge instead of making another. */
|
|
39
|
+
idempotencyKey?: string;
|
|
40
|
+
}
|
|
41
|
+
/** Why a call failed. `status` is the HTTP status, or 0 when the service could not be reached. */
|
|
42
|
+
export declare class RioError extends Error {
|
|
43
|
+
readonly status: number;
|
|
44
|
+
readonly code: string;
|
|
45
|
+
constructor(status: number, code: string, message: string);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The base URL to use: an explicit `serviceUrl`, else the environment's, else `RIO_SERVICE_URL`, else mainnet's. `urls` and `fromEnvironmentVariable`
|
|
49
|
+
* come in as arguments so this can be tested; `createRioClient` passes the real ones.
|
|
50
|
+
*/
|
|
51
|
+
export declare const resolveServiceUrl: (options: RioClientOptions, urls: Readonly<Record<RioEnvironment, string | undefined>>, fromEnvironmentVariable: string | undefined) => string;
|
|
52
|
+
/** Which charge: by its id, or by the external id (your order id) it was created with. Exactly one. */
|
|
53
|
+
export type ChargeRef = {
|
|
54
|
+
readonly id: string;
|
|
55
|
+
readonly externalId?: never;
|
|
56
|
+
} | {
|
|
57
|
+
readonly externalId: string;
|
|
58
|
+
readonly id?: never;
|
|
59
|
+
};
|
|
60
|
+
/** A client for your server's side of the API. Make one with `createRioClient`. */
|
|
61
|
+
export interface RioClient {
|
|
62
|
+
readonly charges: {
|
|
63
|
+
/** Creates the order's charge and returns it as the checkout widget takes it: your route can `Response.json(charge)`. A retry of the same order returns the same charge with a replacement client secret. */
|
|
64
|
+
readonly create: (input: CreateChargeInput, options?: CreateChargeOptions) => Promise<CreatedCharge>;
|
|
65
|
+
/**
|
|
66
|
+
* A charge's status, in the shape the widget's status poll takes: your status route can `Response.json(status)`. Name the charge
|
|
67
|
+
* by its `id`, or by its `externalId` (the order id you created it with): exactly one.
|
|
68
|
+
*/
|
|
69
|
+
readonly get: (which: ChargeRef) => Promise<PlatformChargeStatus>;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Makes a client: `createRioClient({ apiKey })`. Throws a `TypeError` for a missing key, an unknown environment or an unusable service URL. */
|
|
73
|
+
export declare function createRioClient(options: RioClientOptions): RioClient;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rio-pay/sdk",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
4
|
-
"description": "SDK for Rio USDC payments: the checkout widget, shared types and webhook signature verification.",
|
|
3
|
+
"version": "0.0.1-alpha.3",
|
|
4
|
+
"description": "SDK for Rio USDC payments: the checkout widget, an API client, shared types and webhook signature verification.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sei",
|
|
7
7
|
"usdc",
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
"import": "./dist/server.js",
|
|
33
33
|
"default": "./dist/server.js"
|
|
34
34
|
},
|
|
35
|
+
"./client": {
|
|
36
|
+
"types": "./dist/client.d.ts",
|
|
37
|
+
"import": "./dist/client.js",
|
|
38
|
+
"default": "./dist/client.js"
|
|
39
|
+
},
|
|
35
40
|
"./checkout/react": {
|
|
36
41
|
"types": "./dist/checkout/react.d.ts",
|
|
37
42
|
"import": "./dist/checkout/react.js",
|
|
@@ -50,7 +55,7 @@
|
|
|
50
55
|
"node": ">=18"
|
|
51
56
|
},
|
|
52
57
|
"scripts": {
|
|
53
|
-
"build": "bun run clean && bun build src/index.ts src/server.ts --production --outdir dist --root src --target browser --format esm && bun build src/checkout/react.ts --production --outdir dist --root src --target browser --format esm --external react --external react/jsx-runtime --banner '\"use client\";' && tsc -p tsconfig.build.json",
|
|
58
|
+
"build": "bun run clean && bun build src/index.ts src/server.ts src/client.ts --production --outdir dist --root src --target browser --format esm && bun build src/checkout/react.ts --production --outdir dist --root src --target browser --format esm --external react --external react/jsx-runtime --banner '\"use client\";' && tsc -p tsconfig.build.json",
|
|
54
59
|
"clean": "rm -rf dist",
|
|
55
60
|
"dev": "bun dev/server.ts",
|
|
56
61
|
"typecheck": "tsc -p tsconfig.json",
|