@rio-pay/sdk 0.0.1-alpha.2 → 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 CHANGED
@@ -9,7 +9,7 @@ The SDK for Rio USDC payments: the checkout widget, shared types and the utiliti
9
9
  | Import | What it is | Runs in |
10
10
  |---|---|---|
11
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 })`: `charges.create` returns the charge as the widget takes it, `charges.retrieve` the status its poll takes; failures are `RioError`. Server-side only. | Node 18+, Bun, edge runtimes |
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 |
13
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 |
14
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 |
15
15
 
@@ -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}),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 A=(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(),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")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),[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,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||A;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":A,"aria-label":a,"data-testid":"sc-pause",onClick:()=>L((j)=>!j),children:A?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 A=[{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:A.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 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 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]),A=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:A}}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((A)=>A.name===g);if(!h)return;let k=!0;return xn(h,{silent:!0}).then((A)=>k&&A&&!o.current&&!s.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=(o.current?.session.wallet===h?o.current.session:null)??await xn(h);if(!k)return null;s.current=!1;let A={session:k,name:h.name};return i(A),rn({wallet:h.name}),A},[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:A="modal",merchantName:L}){let p=A==="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),[R,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(()=>R?cn(R.serviceUrl,R.chargeId,R.clientSecret):null,[R]),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||!R)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,R,Wr]);let U=Rt.list,Ot=P(U);Ot.current=U;let he=R?.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},[R?.chargeId]),I(()=>{if(Bt||!R||!(Gn||O.step==="processing")||qe?.confirmation==="final")return;let d=Sa(R.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)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,R,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=R?we(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"}),!oe||!R||!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,R?.chargeId,tt,Ut,ye,qr,Dr]);let _e=ke?"failed":!de?"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=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||!R,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"&&R?Na(R.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&&R&&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=!!R&&!!q&&Rt.status==="ready",go=Y?"done":V==="manual"&&R?"manual":!po?"loading":X?"paying":V==="wallets"?"wallets":"pick",Jt=R?Ya(R,U):null,fo=R&&Jt?x(Ws,{entry:{address:R.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&&R?{receipt:Ea(R.chargeId),finalizing:!1,slot:g,returnHref:Qt,ref:Vn,onDone:p?void 0:De}:null,manual:fo,onPayAnotherWay:R&&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 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(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};
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 CHANGED
@@ -1,2 +1,2 @@
1
- export { createRioClient, RioError } from "./lib/rio-client";
2
- export type { CreateChargeInput, CreateChargeOptions, RioClient, RioClientOptions } from "./lib/rio-client";
1
+ export { createRioClient, RIO_ENVIRONMENT_URLS, RioError } from "./lib/rio-client";
2
+ export type { ChargeRef, CreateChargeInput, CreateChargeOptions, RioClient, RioClientOptions, RioEnvironment } from "./lib/rio-client";
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- class a extends Error{status;code;constructor(e,r,s){super(s);this.name="RioError",this.status=e,this.code=r}}var l=(e)=>!!e&&typeof e==="object"&&!Array.isArray(e),c=(e)=>typeof e==="string"?e:void 0,m=(e)=>["localhost","127.0.0.1","[::1]"].includes(e.hostname),p=(e)=>{if(!e)throw TypeError("createRioClient needs a serviceUrl (or the RIO_SERVICE_URL environment variable).");let r;try{r=new URL(e)}catch{throw TypeError("createRioClient: serviceUrl is not a URL.")}if(r.username||r.password)throw TypeError("createRioClient: serviceUrl must not contain credentials.");if(r.protocol!=="https:"&&!(r.protocol==="http:"&&m(r)))throw TypeError("createRioClient: serviceUrl must be https (http only for localhost).");return`${r.origin}${r.pathname.replace(/\/+$/,"")}`},C=(e)=>({amount:e.amount,external_ref:e.externalRef,...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}:{}}),f=(e,r)=>{let s=r.chain;if(typeof r.id!=="string"||typeof r.client_secret!=="string"||!l(s))return null;return{chargeId:r.id,clientSecret:r.client_secret,serviceUrl:e,amount:String(r.amount),chain:s,chargeAddress:String(r.charge_address),status:r.status,confirmed:r.confirmed===!0,confirmation:r.confirmation,expiresAt:c(r.expires_at)??null}},y=(e)=>({chargeId:String(e.id),orderId:c(e.external_ref)??null,status:e.status,confirmed:e.confirmed===!0,confirmation:e.confirmation,collectedAmount:c(e.collected_amount)??null});function w(e){if(!e.apiKey)throw TypeError("createRioClient needs an apiKey.");let r=p(e.serviceUrl??(typeof process>"u"?void 0:process.env?.RIO_SERVICE_URL)),s=e.apiKey,h=async(i,o)=>{let t=await(async()=>{try{return await(e.fetch??fetch)(`${r}${i}`,{method:o.method,headers:{authorization:`Bearer ${s}`,...o.body!==void 0?{"content-type":"application/json"}:{},...o.headers},...o.body!==void 0?{body:JSON.stringify(o.body)}:{},cache:"no-store"})}catch{throw new a(0,"network_error","Could not reach the service.")}})(),n=await t.json().catch(()=>null);if(!t.ok){let d=l(n)&&l(n.error)?n.error:{};throw new a(t.status,c(d.code)??"request_failed",c(d.message)??`The request failed (${t.status}).`)}if(!l(n))throw new a(t.status,"invalid_response","The service answered with something that is not a charge.");return{status:t.status,json:n}};return{charges:{create:async(i,o={})=>{let{json:t}=await h("/v1/charges",{method:"POST",headers:{"idempotency-key":o.idempotencyKey??i.externalRef},body:C(i)}),n=f(r,t);if(n!==null)return n;let d=c(t.id);if(d===void 0)throw new a(200,"invalid_response","The service answered with something that is not a charge.");let u=await h(`/v1/charges/${encodeURIComponent(d)}/client_secret`,{method:"POST"}),g=f(r,{...t,client_secret:u.json.client_secret});if(g===null)throw new a(u.status,"client_secret_unavailable","The service did not return a client secret for this charge.");return g},retrieve:async(i)=>y((await h(`/v1/charges/${encodeURIComponent(i)}`,{method:"GET"})).json)}}}export{a as RioError,w as createRioClient};
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,17 +1,26 @@
1
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>>;
2
9
  export interface RioClientOptions {
3
10
  /** A secret API key (`sk_…`), from the dashboard's Developers page. Keep it on your server. */
4
11
  apiKey: string;
5
- /** The API base URL from the dashboard. Default: the `RIO_SERVICE_URL` environment variable, where there is one. */
12
+ /** The API base URL. It wins over `environment`. */
6
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;
7
16
  /** A custom `fetch`. Default: the global `fetch`, looked up at call time. */
8
17
  fetch?: typeof fetch;
9
18
  }
10
19
  export interface CreateChargeInput {
11
20
  /** USDC base units, as a string: `"12500000"` is $12.50. Decide it on your server, never from the browser. */
12
21
  amount: string;
13
- /** Your order id. */
14
- externalRef: string;
22
+ /** Your order id (the charge's external id). `charges.get` finds the charge by it. */
23
+ externalId: string;
15
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. */
16
25
  origin?: string;
17
26
  merchantId?: string;
@@ -26,7 +35,7 @@ export interface CreateChargeInput {
26
35
  metadata?: Readonly<Record<string, string | number | boolean>>;
27
36
  }
28
37
  export interface CreateChargeOptions {
29
- /** Default: the order id, so a retried request returns the same charge instead of making another. */
38
+ /** Default: the external id, so a retried request returns the same charge instead of making another. */
30
39
  idempotencyKey?: string;
31
40
  }
32
41
  /** Why a call failed. `status` is the HTTP status, or 0 when the service could not be reached. */
@@ -35,14 +44,30 @@ export declare class RioError extends Error {
35
44
  readonly code: string;
36
45
  constructor(status: number, code: string, message: string);
37
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
+ };
38
60
  /** A client for your server's side of the API. Make one with `createRioClient`. */
39
61
  export interface RioClient {
40
62
  readonly charges: {
41
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. */
42
64
  readonly create: (input: CreateChargeInput, options?: CreateChargeOptions) => Promise<CreatedCharge>;
43
- /** A charge's status, in the shape the widget's status poll takes: your status route can `Response.json(status)`. */
44
- readonly retrieve: (id: string) => Promise<PlatformChargeStatus>;
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>;
45
70
  };
46
71
  }
47
- /** Makes a client: `createRioClient({ apiKey })`. Throws a `TypeError` for a missing key or an unusable service URL. */
72
+ /** Makes a client: `createRioClient({ apiKey })`. Throws a `TypeError` for a missing key, an unknown environment or an unusable service URL. */
48
73
  export declare function createRioClient(options: RioClientOptions): RioClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rio-pay/sdk",
3
- "version": "0.0.1-alpha.2",
3
+ "version": "0.0.1-alpha.3",
4
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",