@tokenflight/swap 0.3.0-rc.1 → 0.3.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bridge.d.ts CHANGED
@@ -1,3 +1,22 @@
1
+ /**
2
+ * Parameters for the EIP-3085 `wallet_addEthereumChain` request. Returned by
3
+ * adapters that know the chain's RPC/native-currency metadata so the widget
4
+ * can recover from Coinbase Wallet's "Unrecognized chain" failure by adding
5
+ * the chain before retrying the switch.
6
+ */
7
+ declare interface AddEthereumChainParameters {
8
+ chainId: string;
9
+ chainName: string;
10
+ nativeCurrency: {
11
+ name: string;
12
+ symbol: string;
13
+ decimals: number;
14
+ };
15
+ rpcUrls: string[];
16
+ blockExplorerUrls?: string[];
17
+ iconUrls?: string[];
18
+ }
19
+
1
20
  export declare interface BridgeEventMap {
2
21
  ready: {
3
22
  version: string;
@@ -295,6 +314,22 @@ declare interface IWalletAdapter {
295
314
  signMessage?(message: string, chainType?: ChainType): Promise<string>;
296
315
  /** Optional: open the wallet's native account/connected modal */
297
316
  openAccountModal?(): Promise<void>;
317
+ /**
318
+ * Optional: return `wallet_addEthereumChain` parameters for the given
319
+ * chain, or `undefined` if unknown. Used by the switch-chain fallback to
320
+ * recover from Coinbase Wallet's `-32603` "Unrecognized chain" response
321
+ * (see coinbase/coinbase-wallet-sdk#915) by adding the chain before
322
+ * retrying the switch.
323
+ */
324
+ getAddEthereumChainParams?(chainId: number): AddEthereumChainParameters | undefined;
325
+ /**
326
+ * Optional: read-only, side-effect-free probe for the wallet's current
327
+ * chain ID. MUST NOT trigger a chain switch or any user-facing prompt.
328
+ * Returns `null` if the current chain cannot be determined (e.g. not
329
+ * connected). Used by `safeSwitchChain` to skip no-op switches without
330
+ * opening a wallet prompt first.
331
+ */
332
+ getCurrentChainId?(): Promise<bigint | null>;
298
333
  /** Optional: clean up internal subscriptions and watchers */
299
334
  destroy?(): void;
300
335
  /** Subscribe to wallet events */
@@ -558,6 +593,20 @@ declare interface WalletActionResult {
558
593
  success: boolean;
559
594
  data?: unknown;
560
595
  error?: string;
596
+ /**
597
+ * Optional: JSON-RPC / EIP-1193 provider error code (e.g. `-32603`,
598
+ * `4001`). Populated by adapters when the underlying error object
599
+ * exposes a numeric `.code` so downstream callers (notably the
600
+ * Coinbase `-32603` fallback in `safeSwitchChain`) can reliably
601
+ * detect provider signatures without relying on stringified messages.
602
+ */
603
+ errorCode?: number;
604
+ /**
605
+ * Optional: the provider's structured error data (e.g. `data.cause`),
606
+ * preserved from the thrown error for detectors that inspect nested
607
+ * fields. Adapters may pass through whatever shape the provider gave.
608
+ */
609
+ errorData?: unknown;
561
610
  txHash?: string;
562
611
  }
563
612
 
@@ -1,3 +1,3 @@
1
- import{_ as e,b as t,v as n,x as r,y as i}from"./shared.module-C-kWMzqW.js";function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var l=class extends Error{constructor(e,t,n){let r=`${e.status||e.status===0?e.status:``} ${e.statusText??``}`.trim(),i=r?`status code ${r}`:`an unknown error`;super(`Request failed with ${i}: ${t.method} ${t.url}`),c(this,`response`,void 0),c(this,`request`,void 0),c(this,`options`,void 0),this.name=`HTTPError`,this.response=e,this.request=t,this.options=n}},u=class extends Error{constructor(e){let t=`Non-error value was thrown`;try{typeof e==`string`?t=e:e&&typeof e==`object`&&`message`in e&&typeof e.message==`string`&&(t=e.message)}catch{}super(t),c(this,`name`,`NonError`),c(this,`value`,void 0),this.value=e}},d=class extends Error{constructor(e){let t=e?.cause?e.cause instanceof Error?e.cause:new u(e.cause):void 0;super(e?.code?`Forced retry: ${e.code}`:`Forced retry`,t?{cause:t}:void 0),c(this,`name`,`ForceRetryError`),c(this,`customDelay`,void 0),c(this,`code`,void 0),c(this,`customRequest`,void 0),this.customDelay=e?.delay,this.code=e?.code,this.customRequest=e?.request}},f=(()=>{let e=!1,t=!1,n=typeof globalThis.ReadableStream==`function`,r=typeof globalThis.Request==`function`;if(n&&r)try{t=new globalThis.Request(`https://empty.invalid`,{body:new globalThis.ReadableStream,method:`POST`,get duplex(){return e=!0,`half`}}).headers.has(`Content-Type`)}catch(e){if(e instanceof Error&&e.message===`unsupported BodyInit type`)return!1;throw e}return e&&!t})(),p=typeof globalThis.AbortController==`function`,m=typeof globalThis.AbortSignal==`function`&&typeof globalThis.AbortSignal.any==`function`,h=typeof globalThis.ReadableStream==`function`,g=typeof globalThis.FormData==`function`,_=[`get`,`post`,`put`,`patch`,`head`,`delete`],ee={json:`application/json`,text:`text/*`,formData:`multipart/form-data`,arrayBuffer:`*/*`,blob:`*/*`,bytes:`*/*`},v=2147483647,te=new TextEncoder().encode(`------WebKitFormBoundaryaxpyiPgbbPti10Rw`).length,y=Symbol(`stop`),b=class{constructor(e){c(this,`options`,void 0),this.options=e}},ne=e=>new b(e),re={json:!0,parseJson:!0,stringifyJson:!0,searchParams:!0,prefixUrl:!0,retry:!0,timeout:!0,hooks:!0,throwHttpErrors:!0,onDownloadProgress:!0,onUploadProgress:!0,fetch:!0,context:!0},ie={next:!0},ae={method:!0,headers:!0,body:!0,mode:!0,credentials:!0,cache:!0,redirect:!0,referrer:!0,referrerPolicy:!0,integrity:!0,keepalive:!0,signal:!0,window:!0,duplex:!0},oe=e=>{if(!e)return 0;if(e instanceof FormData){let t=0;for(let[n,r]of e)t+=te,t+=new TextEncoder().encode(`Content-Disposition: form-data; name="${n}"`).length,t+=typeof r==`string`?new TextEncoder().encode(r).length:r.size;return t}if(e instanceof Blob)return e.size;if(e instanceof ArrayBuffer)return e.byteLength;if(typeof e==`string`)return new TextEncoder().encode(e).length;if(e instanceof URLSearchParams)return new TextEncoder().encode(e.toString()).length;if(`byteLength`in e)return e.byteLength;if(typeof e==`object`&&e)try{let t=JSON.stringify(e);return new TextEncoder().encode(t).length}catch{return 0}return 0},x=(e,t,n)=>{let r,i=0;return e.pipeThrough(new TransformStream({transform(e,a){if(a.enqueue(e),r){i+=r.byteLength;let e=t===0?0:i/t;e>=1&&(e=1-2**-52),n?.({percent:e,totalBytes:Math.max(t,i),transferredBytes:i},r)}r=e},flush(){r&&(i+=r.byteLength,n?.({percent:1,totalBytes:Math.max(t,i),transferredBytes:i},r))}}))},se=(e,t)=>{if(!e.body)return e;if(e.status===204)return new Response(null,{status:e.status,statusText:e.statusText,headers:e.headers});let n=Math.max(0,Number(e.headers.get(`content-length`))||0);return new Response(x(e.body,n,t),{status:e.status,statusText:e.statusText,headers:e.headers})},ce=(e,t,n)=>{if(!e.body)return e;let r=oe(n??e.body);return new Request(e,{duplex:`half`,body:x(e.body,r,t)})},S=e=>typeof e==`object`&&!!e,C=(...e)=>{for(let t of e)if((!S(t)||Array.isArray(t))&&t!==void 0)throw TypeError("The `options` argument must be an object");return D({},...e)},w=(e={},t={})=>{let n=new globalThis.Headers(e),r=t instanceof globalThis.Headers,i=new globalThis.Headers(t);for(let[e,t]of i.entries())r&&t===`undefined`||t===void 0?n.delete(e):n.set(e,t);return n};function T(e,t,n){return Object.hasOwn(t,n)&&t[n]===void 0?[]:D(e[n]??[],t[n]??[])}var E=(e={},t={})=>({beforeRequest:T(e,t,`beforeRequest`),beforeRetry:T(e,t,`beforeRetry`),afterResponse:T(e,t,`afterResponse`),beforeError:T(e,t,`beforeError`)}),le=(e,t)=>{let n=new URLSearchParams;for(let r of[e,t])if(r!==void 0)if(r instanceof URLSearchParams)for(let[e,t]of r.entries())n.append(e,t);else if(Array.isArray(r))for(let e of r){if(!Array.isArray(e)||e.length!==2)throw TypeError(`Array search parameters must be provided in [[key, value], ...] format`);n.append(String(e[0]),String(e[1]))}else if(S(r))for(let[e,t]of Object.entries(r))t!==void 0&&n.append(e,String(t));else{let e=new URLSearchParams(r);for(let[t,r]of e.entries())n.append(t,r)}return n},D=(...e)=>{let t={},n={},r={},i,a=[];for(let o of e)if(Array.isArray(o))Array.isArray(t)||(t=[]),t=[...t,...o];else if(S(o)){for(let[e,n]of Object.entries(o)){if(e===`signal`&&n instanceof globalThis.AbortSignal){a.push(n);continue}if(e===`context`){if(n!=null&&(!S(n)||Array.isArray(n)))throw TypeError("The `context` option must be an object");t={...t,context:n==null?{}:{...t.context,...n}};continue}if(e===`searchParams`){i=n==null?void 0:i===void 0?n:le(i,n);continue}S(n)&&e in t&&(n=D(t[e],n)),t={...t,[e]:n}}S(o.hooks)&&(r=E(r,o.hooks),t.hooks=r),S(o.headers)&&(n=w(n,o.headers),t.headers=n)}return i!==void 0&&(t.searchParams=i),a.length>0&&(a.length===1?t.signal=a[0]:m?t.signal=AbortSignal.any(a):t.signal=a.at(-1)),t},ue=e=>_.includes(e)?e.toUpperCase():e,O={limit:2,methods:[`get`,`put`,`head`,`delete`,`options`,`trace`],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:[413,429,503],maxRetryAfter:1/0,backoffLimit:1/0,delay:e=>.3*2**(e-1)*1e3,jitter:void 0,retryOnTimeout:!1},de=(e={})=>{if(typeof e==`number`)return{...O,limit:e};if(e.methods&&!Array.isArray(e.methods))throw Error(`retry.methods must be an array`);if(e.methods&&(e.methods=e.methods.map(e=>e.toLowerCase())),e.statusCodes&&!Array.isArray(e.statusCodes))throw Error(`retry.statusCodes must be an array`);let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0));return{...O,...t}},k=class extends Error{constructor(e){super(`Request timed out: ${e.method} ${e.url}`),c(this,`request`,void 0),this.name=`TimeoutError`,this.request=e}};async function fe(e,t,n,r){return new Promise((i,a)=>{let o=setTimeout(()=>{n&&n.abort(),a(new k(e))},r.timeout);r.fetch(e,t).then(i).catch(a).then(()=>{clearTimeout(o)})})}async function pe(e,{signal:t}){return new Promise((n,r)=>{t&&(t.throwIfAborted(),t.addEventListener(`abort`,i,{once:!0}));function i(){clearTimeout(a),r(t.reason)}let a=setTimeout(()=>{t?.removeEventListener(`abort`,i),n()},e)})}var me=(e,t)=>{let n={};for(let r in t)Object.hasOwn(t,r)&&!(r in ae)&&!(r in re)&&(!(r in e)||r in ie)&&(n[r]=t[r]);return n},he=e=>e===void 0?!1:Array.isArray(e)?e.length>0:e instanceof URLSearchParams?e.size>0:typeof e==`object`?Object.keys(e).length>0:typeof e==`string`?e.trim().length>0:!!e;function ge(e){return e instanceof l||e?.name===l.name}function _e(e){return e instanceof k||e?.name===k.name}var A=new WeakMap,j=new WeakMap,M=new WeakMap,N=new WeakMap,P=new WeakMap,F=new WeakMap,I=new WeakMap,L=new WeakSet,R=class a{static create(e,t){let r=new a(e,t),o=i(L,r,U).call(r,async()=>{if(typeof n(N,r).timeout==`number`&&n(N,r).timeout>2147483647)throw RangeError(`The \`timeout\` option cannot be greater than ${v}`);await Promise.resolve();let e=await i(L,r,be).call(r);for(let t of n(N,r).hooks.afterResponse){let a=i(L,r,B).call(r,e.clone()),o;try{o=await t(r.request,i(L,r,W).call(r),a,{retryCount:n(j,r)})}catch(t){throw i(L,r,H).call(r,a),i(L,r,H).call(r,e),t}if(o instanceof b)throw i(L,r,H).call(r,a),i(L,r,H).call(r,e),new d(o.options);let s=o instanceof globalThis.Response?o:e;a!==s&&i(L,r,H).call(r,a),e!==s&&i(L,r,H).call(r,e),e=s}if(i(L,r,B).call(r,e),!e.ok&&(typeof n(N,r).throwHttpErrors==`function`?n(N,r).throwHttpErrors(e.status):n(N,r).throwHttpErrors)){let t=new l(e,r.request,i(L,r,W).call(r));for(let e of n(N,r).hooks.beforeError)t=await e(t,{retryCount:n(j,r)});throw t}if(n(N,r).onDownloadProgress){if(typeof n(N,r).onDownloadProgress!=`function`)throw TypeError("The `onDownloadProgress` option must be a function");if(!h)throw Error("Streams are not supported in your environment. `ReadableStream` is missing.");let t=e.clone();return i(L,r,H).call(r,e),se(t,n(N,r).onDownloadProgress)}return e}).finally(()=>{let e=n(P,r);i(L,r,V).call(r,e?.body??void 0),i(L,r,V).call(r,r.request.body??void 0)});for(let[e,n]of Object.entries(ee))e===`bytes`&&typeof globalThis.Response?.prototype?.bytes!=`function`||(o[e]=async()=>{r.request.headers.set(`accept`,r.request.headers.get(`accept`)||n);let i=await o;if(e===`json`){if(i.status===204)return``;let e=await i.text();return e===``?``:t.parseJson?t.parseJson(e):JSON.parse(e)}return i[e]()});return o}constructor(o,s={}){if(r(this,L),c(this,`request`,void 0),t(this,A,void 0),t(this,j,0),t(this,M,void 0),t(this,N,void 0),t(this,P,void 0),t(this,F,void 0),t(this,I,void 0),e(M,this,o),e(N,this,{...s,headers:w(n(M,this).headers,s.headers),hooks:E({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},s.hooks),method:ue(s.method??n(M,this).method??`GET`),prefixUrl:String(s.prefixUrl||``),retry:de(s.retry),throwHttpErrors:s.throwHttpErrors??!0,timeout:s.timeout??1e4,fetch:s.fetch??globalThis.fetch.bind(globalThis),context:s.context??{}}),typeof n(M,this)!=`string`&&!(n(M,this)instanceof URL||n(M,this)instanceof globalThis.Request))throw TypeError("`input` must be a string, URL, or Request");if(n(N,this).prefixUrl&&typeof n(M,this)==`string`){if(n(M,this).startsWith(`/`))throw Error("`input` must not begin with a slash when using `prefixUrl`");n(N,this).prefixUrl.endsWith(`/`)||(n(N,this).prefixUrl+=`/`),e(M,this,n(N,this).prefixUrl+n(M,this))}p&&m&&(e(F,this,n(N,this).signal??n(M,this).signal),e(A,this,new globalThis.AbortController),n(N,this).signal=n(F,this)?AbortSignal.any([n(F,this),n(A,this).signal]):n(A,this).signal),f&&(n(N,this).duplex=`half`),n(N,this).json!==void 0&&(n(N,this).body=n(N,this).stringifyJson?.(n(N,this).json)??JSON.stringify(n(N,this).json),n(N,this).headers.set(`content-type`,n(N,this).headers.get(`content-type`)??`application/json`));let l=s.headers&&new globalThis.Headers(s.headers).has(`content-type`);if(n(M,this)instanceof globalThis.Request&&(g&&n(N,this).body instanceof globalThis.FormData||n(N,this).body instanceof URLSearchParams)&&!l&&n(N,this).headers.delete(`content-type`),this.request=new globalThis.Request(n(M,this),n(N,this)),he(n(N,this).searchParams)){let e=`?`+(typeof n(N,this).searchParams==`string`?n(N,this).searchParams.replace(/^\?/,``):new URLSearchParams(ve.call(a,n(N,this).searchParams)).toString()),t=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,e);this.request=new globalThis.Request(t,n(N,this))}if(n(N,this).onUploadProgress){if(typeof n(N,this).onUploadProgress!=`function`)throw TypeError("The `onUploadProgress` option must be a function");if(!f)throw Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");this.request=i(L,this,K).call(this,this.request,n(N,this).body??void 0)}}};function ve(e){return e&&typeof e==`object`&&!Array.isArray(e)&&!(e instanceof URLSearchParams)?Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0)):e}function z(){let e=n(N,this).retry.delay(n(j,this)),t=e;n(N,this).retry.jitter===!0?t=Math.random()*e:typeof n(N,this).retry.jitter==`function`&&(t=n(N,this).retry.jitter(e),(!Number.isFinite(t)||t<0)&&(t=e));let r=n(N,this).retry.backoffLimit??1/0;return Math.min(r,t)}async function ye(t){var r;if(e(j,this,(r=n(j,this),r++,r)),n(j,this)>n(N,this).retry.limit)throw t;let a=t instanceof Error?t:new u(t);if(a instanceof d)return a.customDelay??i(L,this,z).call(this);if(!n(N,this).retry.methods.includes(this.request.method.toLowerCase()))throw t;if(n(N,this).retry.shouldRetry!==void 0){let e=await n(N,this).retry.shouldRetry({error:a,retryCount:n(j,this)});if(e===!1)throw t;if(e===!0)return i(L,this,z).call(this)}if(_e(t)&&!n(N,this).retry.retryOnTimeout)throw t;if(ge(t)){if(!n(N,this).retry.statusCodes.includes(t.response.status))throw t;let e=t.response.headers.get(`Retry-After`)??t.response.headers.get(`RateLimit-Reset`)??t.response.headers.get(`X-RateLimit-Retry-After`)??t.response.headers.get(`X-RateLimit-Reset`)??t.response.headers.get(`X-Rate-Limit-Reset`);if(e&&n(N,this).retry.afterStatusCodes.includes(t.response.status)){let t=Number(e)*1e3;Number.isNaN(t)?t=Date.parse(e)-Date.now():t>=Date.parse(`2024-01-01`)&&(t-=Date.now());let r=n(N,this).retry.maxRetryAfter??t;return t<r?t:r}if(t.response.status===413)throw t}return i(L,this,z).call(this)}function B(e){return n(N,this).parseJson&&(e.json=async()=>n(N,this).parseJson(await e.text())),e}function V(e){e&&e.cancel().catch(()=>void 0)}function H(e){i(L,this,V).call(this,e.body??void 0)}async function U(e){try{return await e()}catch(t){let r=Math.min(await i(L,this,ye).call(this,t),v);if(n(j,this)<1)throw t;if(await pe(r,n(F,this)?{signal:n(F,this)}:{}),t instanceof d&&t.customRequest){let e=n(N,this).signal?new globalThis.Request(t.customRequest,{signal:n(N,this).signal}):new globalThis.Request(t.customRequest);i(L,this,G).call(this,e)}for(let e of n(N,this).hooks.beforeRetry){let r=await e({request:this.request,options:i(L,this,W).call(this),error:t,retryCount:n(j,this)});if(r instanceof globalThis.Request){i(L,this,G).call(this,r);break}if(r instanceof globalThis.Response)return r;if(r===y)return}return i(L,this,U).call(this,e)}}async function be(){n(A,this)?.signal.aborted&&(e(A,this,new globalThis.AbortController),n(N,this).signal=n(F,this)?AbortSignal.any([n(F,this),n(A,this).signal]):n(A,this).signal,this.request=new globalThis.Request(this.request,{signal:n(N,this).signal}));for(let e of n(N,this).hooks.beforeRequest){let t=await e(this.request,i(L,this,W).call(this),{retryCount:n(j,this)});if(t instanceof Response)return t;if(t instanceof globalThis.Request){i(L,this,G).call(this,t);break}}let t=me(this.request,n(N,this));return e(P,this,this.request),this.request=n(P,this).clone(),n(N,this).timeout===!1?n(N,this).fetch(n(P,this),t):fe(n(P,this),t,n(A,this),n(N,this))}function W(){if(!n(I,this)){let{hooks:t,...r}=n(N,this);e(I,this,Object.freeze(r))}return n(I,this)}function G(t){e(I,this,void 0),this.request=i(L,this,K).call(this,t)}function K(e,t){return!n(N,this).onUploadProgress||!e.body?e:ce(e,n(N,this).onUploadProgress,t??n(N,this).body??void 0)}var q=e=>{let t=(t,n)=>R.create(t,C(e,n));for(let n of _)t[n]=(t,r)=>R.create(t,C(e,r,{method:n}));return t.create=e=>q(C(e)),t.extend=t=>(typeof t==`function`&&(t=t(e??{})),q(C(e,t))),t.stop=y,t.retry=ne,t},xe=q(),J={API_REQUEST_FAILED:`TF3001`,API_TIMEOUT:`TF3002`,API_INVALID_RESPONSE:`TF3003`,QUOTE_FAILED:`TF3004`,QUOTE_EXPIRED:`TF3005`,DEPOSIT_BUILD_FAILED:`TF3006`,DEPOSIT_SUBMIT_FAILED:`TF3007`,ORDER_FAILED:`TF3008`,API_ABORTED:`TF3009`,FIAT_QUOTE_FAILED:`TF6001`,FIAT_ORDER_FAILED:`TF6002`,FIAT_STATUS_FAILED:`TF6003`,FIAT_PROVIDER_ERROR:`TF6004`,FIAT_AMOUNT_OUT_OF_RANGE:`TF6005`,FIAT_POPUP_BLOCKED:`TF6006`,FIAT_CHECKOUT_UNAVAILABLE:`TF6007`},Y={[J.API_REQUEST_FAILED]:`API request failed`,[J.API_TIMEOUT]:`API request timed out`,[J.API_INVALID_RESPONSE]:`Invalid API response`,[J.QUOTE_FAILED]:`Failed to get quote`,[J.QUOTE_EXPIRED]:`Quote has expired`,[J.DEPOSIT_BUILD_FAILED]:`Failed to build deposit transaction`,[J.DEPOSIT_SUBMIT_FAILED]:`Failed to submit deposit`,[J.ORDER_FAILED]:`Order processing failed`,[J.API_ABORTED]:`Request was aborted`,[J.FIAT_QUOTE_FAILED]:`Failed to get fiat quote`,[J.FIAT_ORDER_FAILED]:`Failed to create fiat order`,[J.FIAT_STATUS_FAILED]:`Failed to get fiat order status`,[J.FIAT_PROVIDER_ERROR]:`Fiat provider error`,[J.FIAT_AMOUNT_OUT_OF_RANGE]:`Fiat amount is out of range`,[J.FIAT_POPUP_BLOCKED]:`Payment popup was blocked by the browser`,[J.FIAT_CHECKOUT_UNAVAILABLE]:`Fiat checkout requires a browser window`},X=class extends Error{constructor(e,t,n){let r=typeof t==`string`?t:t instanceof Error||typeof t==`object`&&t&&`message`in t&&typeof t.message==`string`?t.message:Y[e]??`Unknown error`;super(r),this.name=`TokenFlightError`,this.code=e,this.details=n}},Se=class extends X{constructor(e,t){super(J.API_TIMEOUT,e,t),this.name=`ApiTimeoutError`}},Z=class extends X{constructor(e,t){super(J.API_ABORTED,e,t),this.name=`ApiAbortedError`}},Q=class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`ApiValidationError`}},Ce={ValidationException:Q,ZodValidationException:Q,BadRequestException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`BadRequestError`}},QuoteNotFoundException:class extends X{constructor(e,t){super(J.QUOTE_FAILED,e,t),this.name=`QuoteNotFoundError`}},QuoteExpiredException:class extends X{constructor(e,t){super(J.QUOTE_EXPIRED,e,t),this.name=`QuoteExpiredError`}},CannotFillException:class extends X{constructor(e,t){super(J.QUOTE_FAILED,e,t),this.name=`CannotFillError`}},NotSupportedTokenException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`NotSupportedTokenError`}},NotSupportedChainException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`NotSupportedChainError`}},NotSupportedDepositMethodException:class extends X{constructor(e,t){super(J.DEPOSIT_BUILD_FAILED,e,t),this.name=`NotSupportedDepositMethodError`}},UnexpectedFromAddressException:class extends X{constructor(e,t){super(J.DEPOSIT_BUILD_FAILED,e,t),this.name=`UnexpectedFromAddressError`}},IntentNotFoundException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`IntentNotFoundError`}},DuplicateRecordException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`DuplicateRecordError`}},BroadcastException:class extends X{constructor(e,t){super(J.DEPOSIT_SUBMIT_FAILED,e,t),this.name=`BroadcastError`}},InternalErrorException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`InternalServerError`}}};function we(e,t,n){if(typeof e==`object`&&e){let r=e,i=typeof r.name==`string`?r.name:null,a=typeof r.message==`string`?r.message:t;if(i&&Ce[i]){let t=Ce[i];return new t(a,n??e)}return new X(J.API_REQUEST_FAILED,a,n??e)}return new X(J.API_REQUEST_FAILED,t,n)}function Te(e){return xe.create({prefixUrl:e.baseUrl,timeout:e.timeout??15e3,retry:0,...e.fetch?{fetch:e.fetch}:{},headers:{"X-TF-SDK-Version":De(),...e.headers}})}function Ee(e){return e.replace(/\/$/,``)}function De(){return`0.3.0-rc.1`}async function Oe(e,t){try{return await e}catch(e){if(e instanceof X)throw e;if(e instanceof k)throw new Se(t.timeoutMessage,e);if(e instanceof DOMException&&e.name===`AbortError`)throw new Z(`Request was aborted`,e);if(e instanceof l){let n=``;try{n=await e.response.json()}catch{n=await e.response.text().catch(()=>``)}let r=`${t.failureMessage}: ${e.response.status} ${e.response.statusText}`;throw we(n,r,{status:e.response.status,body:n})}throw new X(J.API_REQUEST_FAILED,`${t.failureMessage}: ${String(e)}`,e)}}async function*ke(e){if(!e.ok){let t=``;try{t=await e.json()}catch{t=await e.text().catch(()=>``)}throw we(t,`API request failed: ${e.status} ${e.statusText}`,{status:e.status,body:t})}if(!e.body)throw new X(J.API_INVALID_RESPONSE,`Streaming response has no body`);let t=e.body.getReader(),n=new TextDecoder(`utf-8`),r=``;try{for(;;){let{value:e,done:i}=await t.read();e&&(r+=n.decode(e,{stream:!0}));let a=r.indexOf(`
1
+ import{_ as e,b as t,v as n,x as r,y as i}from"./shared.module-C-kWMzqW.js";function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var l=class extends Error{constructor(e,t,n){let r=`${e.status||e.status===0?e.status:``} ${e.statusText??``}`.trim(),i=r?`status code ${r}`:`an unknown error`;super(`Request failed with ${i}: ${t.method} ${t.url}`),c(this,`response`,void 0),c(this,`request`,void 0),c(this,`options`,void 0),this.name=`HTTPError`,this.response=e,this.request=t,this.options=n}},u=class extends Error{constructor(e){let t=`Non-error value was thrown`;try{typeof e==`string`?t=e:e&&typeof e==`object`&&`message`in e&&typeof e.message==`string`&&(t=e.message)}catch{}super(t),c(this,`name`,`NonError`),c(this,`value`,void 0),this.value=e}},d=class extends Error{constructor(e){let t=e?.cause?e.cause instanceof Error?e.cause:new u(e.cause):void 0;super(e?.code?`Forced retry: ${e.code}`:`Forced retry`,t?{cause:t}:void 0),c(this,`name`,`ForceRetryError`),c(this,`customDelay`,void 0),c(this,`code`,void 0),c(this,`customRequest`,void 0),this.customDelay=e?.delay,this.code=e?.code,this.customRequest=e?.request}},f=(()=>{let e=!1,t=!1,n=typeof globalThis.ReadableStream==`function`,r=typeof globalThis.Request==`function`;if(n&&r)try{t=new globalThis.Request(`https://empty.invalid`,{body:new globalThis.ReadableStream,method:`POST`,get duplex(){return e=!0,`half`}}).headers.has(`Content-Type`)}catch(e){if(e instanceof Error&&e.message===`unsupported BodyInit type`)return!1;throw e}return e&&!t})(),p=typeof globalThis.AbortController==`function`,m=typeof globalThis.AbortSignal==`function`&&typeof globalThis.AbortSignal.any==`function`,h=typeof globalThis.ReadableStream==`function`,g=typeof globalThis.FormData==`function`,_=[`get`,`post`,`put`,`patch`,`head`,`delete`],ee={json:`application/json`,text:`text/*`,formData:`multipart/form-data`,arrayBuffer:`*/*`,blob:`*/*`,bytes:`*/*`},v=2147483647,te=new TextEncoder().encode(`------WebKitFormBoundaryaxpyiPgbbPti10Rw`).length,y=Symbol(`stop`),b=class{constructor(e){c(this,`options`,void 0),this.options=e}},ne=e=>new b(e),re={json:!0,parseJson:!0,stringifyJson:!0,searchParams:!0,prefixUrl:!0,retry:!0,timeout:!0,hooks:!0,throwHttpErrors:!0,onDownloadProgress:!0,onUploadProgress:!0,fetch:!0,context:!0},ie={next:!0},ae={method:!0,headers:!0,body:!0,mode:!0,credentials:!0,cache:!0,redirect:!0,referrer:!0,referrerPolicy:!0,integrity:!0,keepalive:!0,signal:!0,window:!0,duplex:!0},oe=e=>{if(!e)return 0;if(e instanceof FormData){let t=0;for(let[n,r]of e)t+=te,t+=new TextEncoder().encode(`Content-Disposition: form-data; name="${n}"`).length,t+=typeof r==`string`?new TextEncoder().encode(r).length:r.size;return t}if(e instanceof Blob)return e.size;if(e instanceof ArrayBuffer)return e.byteLength;if(typeof e==`string`)return new TextEncoder().encode(e).length;if(e instanceof URLSearchParams)return new TextEncoder().encode(e.toString()).length;if(`byteLength`in e)return e.byteLength;if(typeof e==`object`&&e)try{let t=JSON.stringify(e);return new TextEncoder().encode(t).length}catch{return 0}return 0},x=(e,t,n)=>{let r,i=0;return e.pipeThrough(new TransformStream({transform(e,a){if(a.enqueue(e),r){i+=r.byteLength;let e=t===0?0:i/t;e>=1&&(e=1-2**-52),n?.({percent:e,totalBytes:Math.max(t,i),transferredBytes:i},r)}r=e},flush(){r&&(i+=r.byteLength,n?.({percent:1,totalBytes:Math.max(t,i),transferredBytes:i},r))}}))},se=(e,t)=>{if(!e.body)return e;if(e.status===204)return new Response(null,{status:e.status,statusText:e.statusText,headers:e.headers});let n=Math.max(0,Number(e.headers.get(`content-length`))||0);return new Response(x(e.body,n,t),{status:e.status,statusText:e.statusText,headers:e.headers})},ce=(e,t,n)=>{if(!e.body)return e;let r=oe(n??e.body);return new Request(e,{duplex:`half`,body:x(e.body,r,t)})},S=e=>typeof e==`object`&&!!e,C=(...e)=>{for(let t of e)if((!S(t)||Array.isArray(t))&&t!==void 0)throw TypeError("The `options` argument must be an object");return D({},...e)},w=(e={},t={})=>{let n=new globalThis.Headers(e),r=t instanceof globalThis.Headers,i=new globalThis.Headers(t);for(let[e,t]of i.entries())r&&t===`undefined`||t===void 0?n.delete(e):n.set(e,t);return n};function T(e,t,n){return Object.hasOwn(t,n)&&t[n]===void 0?[]:D(e[n]??[],t[n]??[])}var E=(e={},t={})=>({beforeRequest:T(e,t,`beforeRequest`),beforeRetry:T(e,t,`beforeRetry`),afterResponse:T(e,t,`afterResponse`),beforeError:T(e,t,`beforeError`)}),le=(e,t)=>{let n=new URLSearchParams;for(let r of[e,t])if(r!==void 0)if(r instanceof URLSearchParams)for(let[e,t]of r.entries())n.append(e,t);else if(Array.isArray(r))for(let e of r){if(!Array.isArray(e)||e.length!==2)throw TypeError(`Array search parameters must be provided in [[key, value], ...] format`);n.append(String(e[0]),String(e[1]))}else if(S(r))for(let[e,t]of Object.entries(r))t!==void 0&&n.append(e,String(t));else{let e=new URLSearchParams(r);for(let[t,r]of e.entries())n.append(t,r)}return n},D=(...e)=>{let t={},n={},r={},i,a=[];for(let o of e)if(Array.isArray(o))Array.isArray(t)||(t=[]),t=[...t,...o];else if(S(o)){for(let[e,n]of Object.entries(o)){if(e===`signal`&&n instanceof globalThis.AbortSignal){a.push(n);continue}if(e===`context`){if(n!=null&&(!S(n)||Array.isArray(n)))throw TypeError("The `context` option must be an object");t={...t,context:n==null?{}:{...t.context,...n}};continue}if(e===`searchParams`){i=n==null?void 0:i===void 0?n:le(i,n);continue}S(n)&&e in t&&(n=D(t[e],n)),t={...t,[e]:n}}S(o.hooks)&&(r=E(r,o.hooks),t.hooks=r),S(o.headers)&&(n=w(n,o.headers),t.headers=n)}return i!==void 0&&(t.searchParams=i),a.length>0&&(a.length===1?t.signal=a[0]:m?t.signal=AbortSignal.any(a):t.signal=a.at(-1)),t},ue=e=>_.includes(e)?e.toUpperCase():e,O={limit:2,methods:[`get`,`put`,`head`,`delete`,`options`,`trace`],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:[413,429,503],maxRetryAfter:1/0,backoffLimit:1/0,delay:e=>.3*2**(e-1)*1e3,jitter:void 0,retryOnTimeout:!1},de=(e={})=>{if(typeof e==`number`)return{...O,limit:e};if(e.methods&&!Array.isArray(e.methods))throw Error(`retry.methods must be an array`);if(e.methods&&(e.methods=e.methods.map(e=>e.toLowerCase())),e.statusCodes&&!Array.isArray(e.statusCodes))throw Error(`retry.statusCodes must be an array`);let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0));return{...O,...t}},k=class extends Error{constructor(e){super(`Request timed out: ${e.method} ${e.url}`),c(this,`request`,void 0),this.name=`TimeoutError`,this.request=e}};async function fe(e,t,n,r){return new Promise((i,a)=>{let o=setTimeout(()=>{n&&n.abort(),a(new k(e))},r.timeout);r.fetch(e,t).then(i).catch(a).then(()=>{clearTimeout(o)})})}async function pe(e,{signal:t}){return new Promise((n,r)=>{t&&(t.throwIfAborted(),t.addEventListener(`abort`,i,{once:!0}));function i(){clearTimeout(a),r(t.reason)}let a=setTimeout(()=>{t?.removeEventListener(`abort`,i),n()},e)})}var me=(e,t)=>{let n={};for(let r in t)Object.hasOwn(t,r)&&!(r in ae)&&!(r in re)&&(!(r in e)||r in ie)&&(n[r]=t[r]);return n},he=e=>e===void 0?!1:Array.isArray(e)?e.length>0:e instanceof URLSearchParams?e.size>0:typeof e==`object`?Object.keys(e).length>0:typeof e==`string`?e.trim().length>0:!!e;function ge(e){return e instanceof l||e?.name===l.name}function _e(e){return e instanceof k||e?.name===k.name}var A=new WeakMap,j=new WeakMap,M=new WeakMap,N=new WeakMap,P=new WeakMap,F=new WeakMap,I=new WeakMap,L=new WeakSet,R=class a{static create(e,t){let r=new a(e,t),o=i(L,r,U).call(r,async()=>{if(typeof n(N,r).timeout==`number`&&n(N,r).timeout>2147483647)throw RangeError(`The \`timeout\` option cannot be greater than ${v}`);await Promise.resolve();let e=await i(L,r,be).call(r);for(let t of n(N,r).hooks.afterResponse){let a=i(L,r,B).call(r,e.clone()),o;try{o=await t(r.request,i(L,r,W).call(r),a,{retryCount:n(j,r)})}catch(t){throw i(L,r,H).call(r,a),i(L,r,H).call(r,e),t}if(o instanceof b)throw i(L,r,H).call(r,a),i(L,r,H).call(r,e),new d(o.options);let s=o instanceof globalThis.Response?o:e;a!==s&&i(L,r,H).call(r,a),e!==s&&i(L,r,H).call(r,e),e=s}if(i(L,r,B).call(r,e),!e.ok&&(typeof n(N,r).throwHttpErrors==`function`?n(N,r).throwHttpErrors(e.status):n(N,r).throwHttpErrors)){let t=new l(e,r.request,i(L,r,W).call(r));for(let e of n(N,r).hooks.beforeError)t=await e(t,{retryCount:n(j,r)});throw t}if(n(N,r).onDownloadProgress){if(typeof n(N,r).onDownloadProgress!=`function`)throw TypeError("The `onDownloadProgress` option must be a function");if(!h)throw Error("Streams are not supported in your environment. `ReadableStream` is missing.");let t=e.clone();return i(L,r,H).call(r,e),se(t,n(N,r).onDownloadProgress)}return e}).finally(()=>{let e=n(P,r);i(L,r,V).call(r,e?.body??void 0),i(L,r,V).call(r,r.request.body??void 0)});for(let[e,n]of Object.entries(ee))e===`bytes`&&typeof globalThis.Response?.prototype?.bytes!=`function`||(o[e]=async()=>{r.request.headers.set(`accept`,r.request.headers.get(`accept`)||n);let i=await o;if(e===`json`){if(i.status===204)return``;let e=await i.text();return e===``?``:t.parseJson?t.parseJson(e):JSON.parse(e)}return i[e]()});return o}constructor(o,s={}){if(r(this,L),c(this,`request`,void 0),t(this,A,void 0),t(this,j,0),t(this,M,void 0),t(this,N,void 0),t(this,P,void 0),t(this,F,void 0),t(this,I,void 0),e(M,this,o),e(N,this,{...s,headers:w(n(M,this).headers,s.headers),hooks:E({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},s.hooks),method:ue(s.method??n(M,this).method??`GET`),prefixUrl:String(s.prefixUrl||``),retry:de(s.retry),throwHttpErrors:s.throwHttpErrors??!0,timeout:s.timeout??1e4,fetch:s.fetch??globalThis.fetch.bind(globalThis),context:s.context??{}}),typeof n(M,this)!=`string`&&!(n(M,this)instanceof URL||n(M,this)instanceof globalThis.Request))throw TypeError("`input` must be a string, URL, or Request");if(n(N,this).prefixUrl&&typeof n(M,this)==`string`){if(n(M,this).startsWith(`/`))throw Error("`input` must not begin with a slash when using `prefixUrl`");n(N,this).prefixUrl.endsWith(`/`)||(n(N,this).prefixUrl+=`/`),e(M,this,n(N,this).prefixUrl+n(M,this))}p&&m&&(e(F,this,n(N,this).signal??n(M,this).signal),e(A,this,new globalThis.AbortController),n(N,this).signal=n(F,this)?AbortSignal.any([n(F,this),n(A,this).signal]):n(A,this).signal),f&&(n(N,this).duplex=`half`),n(N,this).json!==void 0&&(n(N,this).body=n(N,this).stringifyJson?.(n(N,this).json)??JSON.stringify(n(N,this).json),n(N,this).headers.set(`content-type`,n(N,this).headers.get(`content-type`)??`application/json`));let l=s.headers&&new globalThis.Headers(s.headers).has(`content-type`);if(n(M,this)instanceof globalThis.Request&&(g&&n(N,this).body instanceof globalThis.FormData||n(N,this).body instanceof URLSearchParams)&&!l&&n(N,this).headers.delete(`content-type`),this.request=new globalThis.Request(n(M,this),n(N,this)),he(n(N,this).searchParams)){let e=`?`+(typeof n(N,this).searchParams==`string`?n(N,this).searchParams.replace(/^\?/,``):new URLSearchParams(ve.call(a,n(N,this).searchParams)).toString()),t=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,e);this.request=new globalThis.Request(t,n(N,this))}if(n(N,this).onUploadProgress){if(typeof n(N,this).onUploadProgress!=`function`)throw TypeError("The `onUploadProgress` option must be a function");if(!f)throw Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");this.request=i(L,this,K).call(this,this.request,n(N,this).body??void 0)}}};function ve(e){return e&&typeof e==`object`&&!Array.isArray(e)&&!(e instanceof URLSearchParams)?Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0)):e}function z(){let e=n(N,this).retry.delay(n(j,this)),t=e;n(N,this).retry.jitter===!0?t=Math.random()*e:typeof n(N,this).retry.jitter==`function`&&(t=n(N,this).retry.jitter(e),(!Number.isFinite(t)||t<0)&&(t=e));let r=n(N,this).retry.backoffLimit??1/0;return Math.min(r,t)}async function ye(t){var r;if(e(j,this,(r=n(j,this),r++,r)),n(j,this)>n(N,this).retry.limit)throw t;let a=t instanceof Error?t:new u(t);if(a instanceof d)return a.customDelay??i(L,this,z).call(this);if(!n(N,this).retry.methods.includes(this.request.method.toLowerCase()))throw t;if(n(N,this).retry.shouldRetry!==void 0){let e=await n(N,this).retry.shouldRetry({error:a,retryCount:n(j,this)});if(e===!1)throw t;if(e===!0)return i(L,this,z).call(this)}if(_e(t)&&!n(N,this).retry.retryOnTimeout)throw t;if(ge(t)){if(!n(N,this).retry.statusCodes.includes(t.response.status))throw t;let e=t.response.headers.get(`Retry-After`)??t.response.headers.get(`RateLimit-Reset`)??t.response.headers.get(`X-RateLimit-Retry-After`)??t.response.headers.get(`X-RateLimit-Reset`)??t.response.headers.get(`X-Rate-Limit-Reset`);if(e&&n(N,this).retry.afterStatusCodes.includes(t.response.status)){let t=Number(e)*1e3;Number.isNaN(t)?t=Date.parse(e)-Date.now():t>=Date.parse(`2024-01-01`)&&(t-=Date.now());let r=n(N,this).retry.maxRetryAfter??t;return t<r?t:r}if(t.response.status===413)throw t}return i(L,this,z).call(this)}function B(e){return n(N,this).parseJson&&(e.json=async()=>n(N,this).parseJson(await e.text())),e}function V(e){e&&e.cancel().catch(()=>void 0)}function H(e){i(L,this,V).call(this,e.body??void 0)}async function U(e){try{return await e()}catch(t){let r=Math.min(await i(L,this,ye).call(this,t),v);if(n(j,this)<1)throw t;if(await pe(r,n(F,this)?{signal:n(F,this)}:{}),t instanceof d&&t.customRequest){let e=n(N,this).signal?new globalThis.Request(t.customRequest,{signal:n(N,this).signal}):new globalThis.Request(t.customRequest);i(L,this,G).call(this,e)}for(let e of n(N,this).hooks.beforeRetry){let r=await e({request:this.request,options:i(L,this,W).call(this),error:t,retryCount:n(j,this)});if(r instanceof globalThis.Request){i(L,this,G).call(this,r);break}if(r instanceof globalThis.Response)return r;if(r===y)return}return i(L,this,U).call(this,e)}}async function be(){n(A,this)?.signal.aborted&&(e(A,this,new globalThis.AbortController),n(N,this).signal=n(F,this)?AbortSignal.any([n(F,this),n(A,this).signal]):n(A,this).signal,this.request=new globalThis.Request(this.request,{signal:n(N,this).signal}));for(let e of n(N,this).hooks.beforeRequest){let t=await e(this.request,i(L,this,W).call(this),{retryCount:n(j,this)});if(t instanceof Response)return t;if(t instanceof globalThis.Request){i(L,this,G).call(this,t);break}}let t=me(this.request,n(N,this));return e(P,this,this.request),this.request=n(P,this).clone(),n(N,this).timeout===!1?n(N,this).fetch(n(P,this),t):fe(n(P,this),t,n(A,this),n(N,this))}function W(){if(!n(I,this)){let{hooks:t,...r}=n(N,this);e(I,this,Object.freeze(r))}return n(I,this)}function G(t){e(I,this,void 0),this.request=i(L,this,K).call(this,t)}function K(e,t){return!n(N,this).onUploadProgress||!e.body?e:ce(e,n(N,this).onUploadProgress,t??n(N,this).body??void 0)}var q=e=>{let t=(t,n)=>R.create(t,C(e,n));for(let n of _)t[n]=(t,r)=>R.create(t,C(e,r,{method:n}));return t.create=e=>q(C(e)),t.extend=t=>(typeof t==`function`&&(t=t(e??{})),q(C(e,t))),t.stop=y,t.retry=ne,t},xe=q(),J={API_REQUEST_FAILED:`TF3001`,API_TIMEOUT:`TF3002`,API_INVALID_RESPONSE:`TF3003`,QUOTE_FAILED:`TF3004`,QUOTE_EXPIRED:`TF3005`,DEPOSIT_BUILD_FAILED:`TF3006`,DEPOSIT_SUBMIT_FAILED:`TF3007`,ORDER_FAILED:`TF3008`,API_ABORTED:`TF3009`,FIAT_QUOTE_FAILED:`TF6001`,FIAT_ORDER_FAILED:`TF6002`,FIAT_STATUS_FAILED:`TF6003`,FIAT_PROVIDER_ERROR:`TF6004`,FIAT_AMOUNT_OUT_OF_RANGE:`TF6005`,FIAT_POPUP_BLOCKED:`TF6006`,FIAT_CHECKOUT_UNAVAILABLE:`TF6007`},Y={[J.API_REQUEST_FAILED]:`API request failed`,[J.API_TIMEOUT]:`API request timed out`,[J.API_INVALID_RESPONSE]:`Invalid API response`,[J.QUOTE_FAILED]:`Failed to get quote`,[J.QUOTE_EXPIRED]:`Quote has expired`,[J.DEPOSIT_BUILD_FAILED]:`Failed to build deposit transaction`,[J.DEPOSIT_SUBMIT_FAILED]:`Failed to submit deposit`,[J.ORDER_FAILED]:`Order processing failed`,[J.API_ABORTED]:`Request was aborted`,[J.FIAT_QUOTE_FAILED]:`Failed to get fiat quote`,[J.FIAT_ORDER_FAILED]:`Failed to create fiat order`,[J.FIAT_STATUS_FAILED]:`Failed to get fiat order status`,[J.FIAT_PROVIDER_ERROR]:`Fiat provider error`,[J.FIAT_AMOUNT_OUT_OF_RANGE]:`Fiat amount is out of range`,[J.FIAT_POPUP_BLOCKED]:`Payment popup was blocked by the browser`,[J.FIAT_CHECKOUT_UNAVAILABLE]:`Fiat checkout requires a browser window`},X=class extends Error{constructor(e,t,n){let r=typeof t==`string`?t:t instanceof Error||typeof t==`object`&&t&&`message`in t&&typeof t.message==`string`?t.message:Y[e]??`Unknown error`;super(r),this.name=`TokenFlightError`,this.code=e,this.details=n}},Se=class extends X{constructor(e,t){super(J.API_TIMEOUT,e,t),this.name=`ApiTimeoutError`}},Z=class extends X{constructor(e,t){super(J.API_ABORTED,e,t),this.name=`ApiAbortedError`}},Q=class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`ApiValidationError`}},Ce={ValidationException:Q,ZodValidationException:Q,BadRequestException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`BadRequestError`}},QuoteNotFoundException:class extends X{constructor(e,t){super(J.QUOTE_FAILED,e,t),this.name=`QuoteNotFoundError`}},QuoteExpiredException:class extends X{constructor(e,t){super(J.QUOTE_EXPIRED,e,t),this.name=`QuoteExpiredError`}},CannotFillException:class extends X{constructor(e,t){super(J.QUOTE_FAILED,e,t),this.name=`CannotFillError`}},NotSupportedTokenException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`NotSupportedTokenError`}},NotSupportedChainException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`NotSupportedChainError`}},NotSupportedDepositMethodException:class extends X{constructor(e,t){super(J.DEPOSIT_BUILD_FAILED,e,t),this.name=`NotSupportedDepositMethodError`}},UnexpectedFromAddressException:class extends X{constructor(e,t){super(J.DEPOSIT_BUILD_FAILED,e,t),this.name=`UnexpectedFromAddressError`}},IntentNotFoundException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`IntentNotFoundError`}},DuplicateRecordException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`DuplicateRecordError`}},BroadcastException:class extends X{constructor(e,t){super(J.DEPOSIT_SUBMIT_FAILED,e,t),this.name=`BroadcastError`}},InternalErrorException:class extends X{constructor(e,t){super(J.API_REQUEST_FAILED,e,t),this.name=`InternalServerError`}}};function we(e,t,n){if(typeof e==`object`&&e){let r=e,i=typeof r.name==`string`?r.name:null,a=typeof r.message==`string`?r.message:t;if(i&&Ce[i]){let t=Ce[i];return new t(a,n??e)}return new X(J.API_REQUEST_FAILED,a,n??e)}return new X(J.API_REQUEST_FAILED,t,n)}function Te(e){return xe.create({prefixUrl:e.baseUrl,timeout:e.timeout??15e3,retry:0,...e.fetch?{fetch:e.fetch}:{},headers:{"X-TF-SDK-Version":De(),...e.headers}})}function Ee(e){return e.replace(/\/$/,``)}function De(){return`0.3.0-rc.2`}async function Oe(e,t){try{return await e}catch(e){if(e instanceof X)throw e;if(e instanceof k)throw new Se(t.timeoutMessage,e);if(e instanceof DOMException&&e.name===`AbortError`)throw new Z(`Request was aborted`,e);if(e instanceof l){let n=``;try{n=await e.response.json()}catch{n=await e.response.text().catch(()=>``)}let r=`${t.failureMessage}: ${e.response.status} ${e.response.statusText}`;throw we(n,r,{status:e.response.status,body:n})}throw new X(J.API_REQUEST_FAILED,`${t.failureMessage}: ${String(e)}`,e)}}async function*ke(e){if(!e.ok){let t=``;try{t=await e.json()}catch{t=await e.text().catch(()=>``)}throw we(t,`API request failed: ${e.status} ${e.statusText}`,{status:e.status,body:t})}if(!e.body)throw new X(J.API_INVALID_RESPONSE,`Streaming response has no body`);let t=e.body.getReader(),n=new TextDecoder(`utf-8`),r=``;try{for(;;){let{value:e,done:i}=await t.read();e&&(r+=n.decode(e,{stream:!0}));let a=r.indexOf(`
2
2
  `);for(;a!==-1;){let e=r.slice(0,a).trim();r=r.slice(a+1),e&&(yield Ae(e)),a=r.indexOf(`
3
3
  `)}if(i){let e=r.trim();e&&(yield Ae(e));return}}}finally{t.releaseLock()}}function Ae(e){try{return JSON.parse(e)}catch(t){throw new X(J.API_INVALID_RESPONSE,`Failed to parse NDJSON frame: ${String(t)}`,{line:e})}}var je=`https://api.hyperstream.dev`,Me=2e3,Ne=500,Pe=5e3,Fe=class{constructor(e){this.baseUrl=Ee(e.baseUrl),this.ky=Te({baseUrl:this.baseUrl,timeout:e.timeout,fetch:e.fetch,headers:e.headers}),this.fetchImpl=e.fetch??globalThis.fetch.bind(globalThis),this.extraHeaders=e.headers??{}}request(e){return Oe(e,{timeoutMessage:`API request timed out`,failureMessage:`API request failed`})}getQuotes(e,t){return this.request(this.ky.post(`v1/quotes`,{json:e,signal:t?.signal}).json())}async*streamQuotes(e,t){yield*ke(await this.fetchImpl(`${this.baseUrl}/v1/quotes?mode=stream`,{method:`POST`,headers:{"Content-Type":`application/json`,"X-TF-SDK-Version":De(),...this.extraHeaders},body:JSON.stringify(e),signal:t?.signal}))}buildDeposit(e,t){return this.request(this.ky.post(`v1/deposit/build`,{json:e,signal:t?.signal}).json())}submitDeposit(e,t){return this.request(this.ky.put(`v1/deposit/submit`,{json:e,signal:t?.signal}).json())}getOrdersByAddress(e,t){let n={};return t?.orderIds?.length&&(n.orderIds=t.orderIds.join(`,`)),t?.limit&&(n.limit=t.limit.toString()),t?.cursor&&(n.cursor=t.cursor.toString()),this.request(this.ky.get(`v1/orders/${e}`,{searchParams:n,signal:t?.signal}).json())}async getOrderById(e,t,n){return(await this.getOrdersByAddress(e,{orderIds:[t],signal:n?.signal})).data[0]??null}getOrder(e,t){return this.request(this.ky.get(`v1/orders/by-id/${e}`,{signal:t?.signal}).json())}trackOrder(e,t={}){let n=Math.max(Ne,t.intervalMs??Me);return new Promise((r,i)=>{let a=!1,o=null,s=()=>{o&&(clearTimeout(o),o=null),t.signal&&t.signal.removeEventListener(`abort`,c)},c=()=>{a||(a=!0,s(),i(new Z(`Order tracking was aborted`)))};if(t.signal){if(t.signal.aborted){c();return}t.signal.addEventListener(`abort`,c)}let l=async()=>{if(!a)try{let i=await this.getOrder(e,{signal:t.signal});if(a)return;if(t.onStatus?.(i),Ie.includes(i.status)){a=!0,s(),r(i);return}o=setTimeout(l,n)}catch(e){if(a)return;if(e instanceof Z){a=!0,s(),i(e);return}o=setTimeout(l,Pe)}};l()})}getTokens(e){let t={};return e?.q&&(t.q=e.q),e?.chainIds?.length&&(t.chainIds=e.chainIds.join(`,`)),e?.limit&&(t.limit=e.limit.toString()),e?.cursor&&(t.cursor=e.cursor.toString()),this.request(this.ky.get(`v1/tokens`,{searchParams:t,signal:e?.signal}).json())}searchTokens(e,t){let n={q:e};return t?.chainIds?.length&&(n.chainIds=t.chainIds.join(`,`)),this.request(this.ky.get(`v1/tokens/search`,{searchParams:n,signal:t?.signal}).json())}getTopTokens(e){let t={};return e?.chainIds?.length&&(t.chainIds=e.chainIds.join(`,`)),this.request(this.ky.get(`v1/tokens/top`,{searchParams:t,signal:e?.signal}).json())}getTokenBalances(e,t){let n={};return t?.chainIds?.length&&(n.chainIds=t.chainIds.join(`,`)),this.request(this.ky.get(`v1/tokens/balances/${e}`,{searchParams:n,signal:t?.signal}).json())}getTokenAutocomplete(e,t){let n={};return t?.chainIds?.length&&(n.chainIds=t.chainIds.join(`,`)),t?.limit&&(n.limit=t.limit.toString()),this.request(this.ky.get(`v1/tokens/autocomplete/${encodeURIComponent(e)}`,{searchParams:n,signal:t?.signal}).json())}getTokenAutocompleteSuggestions(e){return this.request(this.ky.get(`v1/tokens/autocomplete/suggestions`,{signal:e?.signal}).json())}getChains(e){return this.request(this.ky.get(`v1/chains`,{signal:e?.signal}).json())}getArcadiaConfig(e){return this.request(this.ky.get(`v1/config/arcadia`,{signal:e?.signal}).json())}getVaults(e){return this.request(this.ky.get(`v1/vaults`,{signal:e?.signal}).json())}getMTokens(e){return this.request(this.ky.get(`v1/mtokens`,{signal:e?.signal}).json())}getIntent(e,t){return this.request(this.ky.get(`v1/intent/${e}`,{signal:t?.signal}).json())}getIntentByDeposit(e,t){return this.request(this.ky.get(`v1/intent/deposit`,{searchParams:{chainId:e.chainId.toString(),txHash:e.txHash},signal:t?.signal}).json())}getIntentsByAuthor(e,t){let n={};return t?.limit&&(n.limit=t.limit.toString()),t?.cursor&&(n.cursor=t.cursor.toString()),t?.fromChainId&&(n.fromChainId=t.fromChainId.toString()),t?.toChainId&&(n.toChainId=t.toChainId.toString()),this.request(this.ky.get(`v1/intents/${e}`,{searchParams:n,signal:t?.signal}).json())}},Ie=[`filled`,`refunded`,`failed`],Le=500,Re=700,ze=2e3,Be=500,Ve=5e3;function He(e,t){let n=typeof window.outerWidth==`number`?window.outerWidth:0,r=typeof window.outerHeight==`number`?window.outerHeight:0,i=typeof window.screenX==`number`?window.screenX:0,a=typeof window.screenY==`number`?window.screenY:0,o=n>0?n:screen.width,s=r>0?r:screen.height,c=n>0?i:0,l=r>0?a:0;return`width=${e},height=${t},left=${Math.max(0,Math.round(c+(o-e)/2))},top=${Math.max(0,Math.round(l+(s-t)/2))}`}function Ue(e){return e===`completed`?`completed`:e===`canceled`?`canceled`:`failed`}function We(e,t,n={}){if(typeof window>`u`)return Promise.reject(new X(J.FIAT_CHECKOUT_UNAVAILABLE,`Fiat checkout requires a browser window`));let r=n.popup?.width??Le,i=n.popup?.height??Re,a=n.minPollIntervalMs??ze,o=window.open(t.wrapperUrl,`tf-fiat-${t.orderId}`,He(r,i));if(!o||o.closed)return Promise.reject(new X(J.FIAT_POPUP_BLOCKED,`Payment popup was blocked by the browser`));let s;try{s=new URL(e.baseUrl).origin}catch{return o.close(),Promise.reject(new X(J.FIAT_CHECKOUT_UNAVAILABLE,`Fiat API base URL is malformed`))}return new Promise((r,i)=>{let c=!1,l=!1,u=null,d=null,f=()=>{window.removeEventListener(`message`,m),u&&(clearTimeout(u),u=null),d&&(clearInterval(d),d=null),n.signal&&n.signal.removeEventListener(`abort`,h)},p=async n=>{if(!c){c=!0,f();try{let i=await e.getStatus(t.orderId);o.closed||o.close(),r({orderId:t.orderId,finalStatus:i,outcome:n})}catch(e){o.closed||o.close(),i(e)}}},m=e=>{if(e.origin!==s)return;let r=e.data;if(!(!r||typeof r!=`object`||r.type!==`FIAT_WIDGET_EVENT`)&&!(r.orderId&&r.orderId!==t.orderId))switch(n.onEvent?.(r),r.event){case`widget_ready`:l=!0;break;case`order_completed`:p(`completed`);break;case`order_failed`:l&&p(`failed`);break;case`widget_close`:break}},h=()=>{o.closed||o.close(),p(`canceled`)};if(window.addEventListener(`message`,m),n.signal){if(n.signal.aborted){h();return}n.signal.addEventListener(`abort`,h)}d=setInterval(()=>{o.closed&&!c&&p(`canceled`)},Be);let g=async()=>{if(!c)try{let r=await e.getStatus(t.orderId);if(c)return;if(n.onStatus?.(r),r.polling.isTerminal){p(Ue(r.status));return}let i=Math.max(a,r.polling.suggestedIntervalMs);u=setTimeout(g,i)}catch{c||(u=setTimeout(g,Ve))}};g()})}var Ge=`https://fiat.hyperstream.dev`,Ke=class{constructor(e){this.baseUrl=Ee(e.baseUrl),this.ky=Te({baseUrl:this.baseUrl,timeout:e.timeout,fetch:e.fetch,headers:e.headers})}request(e){return Oe(e,{timeoutMessage:`Fiat API request timed out`,failureMessage:`Fiat API request failed`})}getProviders(e){return this.request(this.ky.get(`v1/fiat/providers`,{signal:e?.signal}).json())}getQuote(e,t){return this.request(this.ky.post(`v1/fiat/quote`,{json:e,signal:t?.signal}).json())}createOrder(e,t){return this.request(this.ky.post(`v1/fiat/order`,{json:e,signal:t?.signal}).json())}getStatus(e,t){let n=t?.force?{force:`1`}:void 0;return this.request(this.ky.get(`v1/fiat/status/${e}`,{signal:t?.signal,searchParams:n}).json())}startCheckout(e,t){return We(this,e,t)}getOrdersByAddress(e,t){let n={};return t?.status&&(n.status=t.status),t?.limit&&(n.limit=t.limit.toString()),t?.cursor&&(n.cursor=t.cursor.toString()),this.request(this.ky.get(`v1/fiat/orders/${e}`,{searchParams:n,signal:t?.signal}).json())}};function qe(e,t){if(e)return`${e.replace(/\/$/,``)}/v1/chain/${t}/icon`}var Je=new Set([`completed`,`failed`,`canceled`]),$={...J,INVALID_CONFIG:`TF1001`,INVALID_TOKEN_IDENTIFIER:`TF1002`,INVALID_AMOUNT:`TF1003`,WALLET_CONNECTION_FAILED:`TF2002`,WALLET_ACTION_FAILED:`TF2003`,TRANSACTION_FAILED:`TF4001`,ELEMENT_NOT_FOUND:`TF5001`},Ye={[$.INVALID_CONFIG]:`Invalid configuration provided`,[$.INVALID_TOKEN_IDENTIFIER]:`Invalid token identifier format`,[$.INVALID_AMOUNT]:`Invalid amount value`,[$.WALLET_CONNECTION_FAILED]:`Failed to connect wallet`,[$.WALLET_ACTION_FAILED]:`Wallet action failed`,[$.TRANSACTION_FAILED]:`Transaction failed`,[$.ELEMENT_NOT_FOUND]:`Target DOM element not found`};({...Y,...Ye});export{Ie as a,X as c,Fe as i,je as l,qe as n,Ge as o,Je as r,Ke as s,$ as t,c as u};
@@ -1,4 +1,4 @@
1
- import{S as e,m as t,o as n,p as r,u as i,v as a}from"./solid-iWr5Czxc.js";import{h as o,l as s,n as c,r as l,u}from"./shared.module-C-kWMzqW.js";import{i as d,o as f,r as p,t as m}from"./theme-C9tsVWlo.js";import{n as h,t as g}from"./widget-BadYytj9.js";import{n as _,r as v,t as y}from"./iframe-receiver-PfhKUIZW.js";function b(e=document){return e.querySelector(`[data-widget-root="stable"]`)??e.querySelector(`[part="container"]`)}function x(e,t=document){let n=()=>{let n=b(t);return n?(e.observeResize(n),!0):!1};if(n())return;let r=new MutationObserver(()=>{n()&&r.disconnect()});r.observe(document.body,{childList:!0,subtree:!0})}var S=o(`<div style="position:fixed;top:12px;left:50%;transform:translateX(-50%);z-index:9999;padding:6px 12px;border-radius:999px;background:color-mix(in srgb, var(--tf-primary) 15%, transparent);color:var(--tf-primary);border:1px solid color-mix(in srgb, var(--tf-primary) 35%, transparent);font-family:'DM Sans', sans-serif;font-size:11px;font-weight:600;letter-spacing:0.03em;user-select:none;pointer-events:none">Standalone preview · embed via &lt;tokenflight-iframe-widget&gt;`),C=o(`<div style="color:#95a8c4;font-family:'DM Sans', sans-serif;font-size:13px;text-align:center;padding-top:60px">Waiting for host bridge…`);function w(e={}){if(typeof window>`u`)return()=>{};E(),D();let t=T(e.target);if(!t)return()=>{};let n=e.queryClient??c,r=u(()=>i(P,{queryClient:n}),t);return()=>r()}function T(e){return typeof e==`string`?document.querySelector(e):e||document.getElementById(`root`)}function E(){if(!g||document.querySelector(`style[data-tokenflight-widget]`))return;let e=document.createElement(`style`);e.setAttribute(`data-tokenflight-widget`,``),e.textContent=g,document.head.appendChild(e)}function D(){if(document.querySelector(`style[data-tokenflight-flat]`))return;let e=document.createElement(`style`);e.setAttribute(`data-tokenflight-flat`,``),e.textContent=`
1
+ import{S as e,m as t,o as n,p as r,u as i,v as a}from"./solid-iWr5Czxc.js";import{h as o,l as s,n as c,r as l,u}from"./shared.module-C-kWMzqW.js";import{i as d,o as f,r as p,t as m}from"./theme-C9tsVWlo.js";import{n as h,t as g}from"./widget-DQLVNkNn.js";import{n as _,r as v,t as y}from"./iframe-receiver-PfhKUIZW.js";function b(e=document){return e.querySelector(`[data-widget-root="stable"]`)??e.querySelector(`[part="container"]`)}function x(e,t=document){let n=()=>{let n=b(t);return n?(e.observeResize(n),!0):!1};if(n())return;let r=new MutationObserver(()=>{n()&&r.disconnect()});r.observe(document.body,{childList:!0,subtree:!0})}var S=o(`<div style="position:fixed;top:12px;left:50%;transform:translateX(-50%);z-index:9999;padding:6px 12px;border-radius:999px;background:color-mix(in srgb, var(--tf-primary) 15%, transparent);color:var(--tf-primary);border:1px solid color-mix(in srgb, var(--tf-primary) 35%, transparent);font-family:'DM Sans', sans-serif;font-size:11px;font-weight:600;letter-spacing:0.03em;user-select:none;pointer-events:none">Standalone preview · embed via &lt;tokenflight-iframe-widget&gt;`),C=o(`<div style="color:#95a8c4;font-family:'DM Sans', sans-serif;font-size:13px;text-align:center;padding-top:60px">Waiting for host bridge…`);function w(e={}){if(typeof window>`u`)return()=>{};E(),D();let t=T(e.target);if(!t)return()=>{};let n=e.queryClient??c,r=u(()=>i(P,{queryClient:n}),t);return()=>r()}function T(e){return typeof e==`string`?document.querySelector(e):e||document.getElementById(`root`)}function E(){if(!g||document.querySelector(`style[data-tokenflight-widget]`))return;let e=document.createElement(`style`);e.setAttribute(`data-tokenflight-widget`,``),e.textContent=g,document.head.appendChild(e)}function D(){if(document.querySelector(`style[data-tokenflight-flat]`))return;let e=document.createElement(`style`);e.setAttribute(`data-tokenflight-flat`,``),e.textContent=`
2
2
  html, body {
3
3
  margin: 0;
4
4
  padding: 0;
package/dist/iframe.d.ts CHANGED
@@ -1,5 +1,24 @@
1
1
  import { HyperstreamApi } from '@tokenflight/api';
2
2
 
3
+ /**
4
+ * Parameters for the EIP-3085 `wallet_addEthereumChain` request. Returned by
5
+ * adapters that know the chain's RPC/native-currency metadata so the widget
6
+ * can recover from Coinbase Wallet's "Unrecognized chain" failure by adding
7
+ * the chain before retrying the switch.
8
+ */
9
+ declare interface AddEthereumChainParameters {
10
+ chainId: string;
11
+ chainName: string;
12
+ nativeCurrency: {
13
+ name: string;
14
+ symbol: string;
15
+ decimals: number;
16
+ };
17
+ rpcUrls: string[];
18
+ blockExplorerUrls?: string[];
19
+ iconUrls?: string[];
20
+ }
21
+
3
22
  /** Amount change data */
4
23
  declare interface AmountChangedData {
5
24
  amount: string;
@@ -108,6 +127,22 @@ export declare interface IWalletAdapter {
108
127
  signMessage?(message: string, chainType?: ChainType): Promise<string>;
109
128
  /** Optional: open the wallet's native account/connected modal */
110
129
  openAccountModal?(): Promise<void>;
130
+ /**
131
+ * Optional: return `wallet_addEthereumChain` parameters for the given
132
+ * chain, or `undefined` if unknown. Used by the switch-chain fallback to
133
+ * recover from Coinbase Wallet's `-32603` "Unrecognized chain" response
134
+ * (see coinbase/coinbase-wallet-sdk#915) by adding the chain before
135
+ * retrying the switch.
136
+ */
137
+ getAddEthereumChainParams?(chainId: number): AddEthereumChainParameters | undefined;
138
+ /**
139
+ * Optional: read-only, side-effect-free probe for the wallet's current
140
+ * chain ID. MUST NOT trigger a chain switch or any user-facing prompt.
141
+ * Returns `null` if the current chain cannot be determined (e.g. not
142
+ * connected). Used by `safeSwitchChain` to skip no-op switches without
143
+ * opening a wallet prompt first.
144
+ */
145
+ getCurrentChainId?(): Promise<bigint | null>;
111
146
  /** Optional: clean up internal subscriptions and watchers */
112
147
  destroy?(): void;
113
148
  /** Subscribe to wallet events */
@@ -398,6 +433,20 @@ declare interface WalletActionResult {
398
433
  success: boolean;
399
434
  data?: unknown;
400
435
  error?: string;
436
+ /**
437
+ * Optional: JSON-RPC / EIP-1193 provider error code (e.g. `-32603`,
438
+ * `4001`). Populated by adapters when the underlying error object
439
+ * exposes a numeric `.code` so downstream callers (notably the
440
+ * Coinbase `-32603` fallback in `safeSwitchChain`) can reliably
441
+ * detect provider signatures without relying on stringified messages.
442
+ */
443
+ errorCode?: number;
444
+ /**
445
+ * Optional: the provider's structured error data (e.g. `data.cause`),
446
+ * preserved from the thrown error for detectors that inspect nested
447
+ * fields. Adapters may pass through whatever shape the provider gave.
448
+ */
449
+ errorData?: unknown;
401
450
  txHash?: string;
402
451
  }
403
452
 
@@ -1 +1 @@
1
- import{c as e,i as t,t as n}from"./errors-Nd9setTj.js";import{n as r}from"./shared.module-C-kWMzqW.js";var i={ETH:[`ETH`,`WETH`],USDC:[`USDC`,`USDC.e`,`USDbC`],USDT:[`USDT`,`USDT.e`]},a={STABLES_MAJOR:[`USDT`,`USDC`,`USDE`,`DAI`,`USDS`,`USD1`,`BUIDL`,`USDF`,`USDTB`,`PYUSD`],STABLE_WRAPPED:[`USDE`,`SUSDE`,`USDS`,`SUSDS`,`DAI`,`SDAI`],BTC:[`BTC`,`WBTC`,`TBTC`,`CBBTC`,`BTC.B`,`CKBTC`],ETH_LST_LRT:[`ETH`,`WETH`,`STETH`,`WSTETH`,`RETH`,`CBETH`,`FRXETH`,`SFRXETH`,`OSETH`,`ETHX`,`METH`,`EETH`,`WEETH`,`EZETH`,`PUFETH`,`RSETH`,`WBETH`]},o=new Set([`BTC`,`ETH`,`WETH`,`WBTC`,`USDC`,`USDT`,`DAI`,`BNB`,`XRP`,`SOL`,`TRX`,`DOGE`,`ADA`,`BCH`,`HYPE`,`XMR`,`LEO`,`LINK`,`MATIC`,`AVAX`]),s=new Set([`USDC`,`USDT`,`DAI`,`USDE`,`USDS`,`USD1`,`USDF`,`USDG`,`RLUSD`,`USDD`,`BUSD`,`TUSD`,`USDP`,`FRAX`,`LUSD`,`GUSD`,`PYUSD`]),c=.1,l=new Set([1]),u=new Set([`0x0000000000000000000000000000000000000000`,`0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee`,`11111111111111111111111111111111`]);function d(e){return e?u.has(e.toLowerCase()):!1}function f(e,t){let n=e.toUpperCase(),r=t.toUpperCase();if(n===r)return!0;for(let e of Object.values(i)){let t=e.some(e=>e.toUpperCase()===n),i=e.some(e=>e.toUpperCase()===r);if(t&&i)return!0}return!1}function p(e,t){let n=e.toUpperCase(),r=t.toUpperCase();for(let e of Object.values(a)){let t=e.some(e=>e.toUpperCase()===n),i=e.some(e=>e.toUpperCase()===r);if(t&&i)return!0}return!1}function m(e){return s.has(e.toUpperCase())}function h(e){return o.has(e.toUpperCase())}function g(e){return d(e)&&(e.startsWith(`0x`)||e.startsWith(`0X`))?`0x0000000000000000000000000000000000000000`:e.toLowerCase()}function _(e,t){return e.chainId===t.chainId&&g(e.address)===g(t.address)}function v(e){return`${e.chainId}:${g(e.address)}`}function y(e,t){return t?e.find(e=>_(e,t))??null:null}function b(e){let{defaultFromToken:t,balances:n,currentSelection:r,userPicked:i}=e;return!t||n.length===0||i||r&&_(r,t)?null:y(n,t)}var x=`tf:token:`,S=1440*60*1e3,C=200;function w(e,t,n){return[`tokenInfo`,n??`__default__`,e,t.toLowerCase()]}function T(e,t){return`${x}${e}:${t.toLowerCase()}`}function E(e,t,n){return r.getQueryData(w(e,t,n))??null}function D(e,t){r.setQueryData(w(e.chainId,e.address,t),e)}function O(e,t){try{let n=T(e,t),r=localStorage.getItem(n);if(!r)return null;let i=JSON.parse(r);return Date.now()-i.timestamp>S?(localStorage.removeItem(n),null):i.token}catch{return null}}function k(e){try{let t=T(e.chainId,e.address),n={token:e,timestamp:Date.now()};localStorage.setItem(t,JSON.stringify(n)),A()}catch{}}function A(){let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);if(n?.startsWith(x))try{let t=localStorage.getItem(n);if(t){let r=JSON.parse(t);e.push({key:n,timestamp:r.timestamp})}}catch{n&&localStorage.removeItem(n)}}if(e.length<=C)return;e.sort((e,t)=>e.timestamp-t.timestamp);let t=e.length-C;for(let n=0;n<t;n++)localStorage.removeItem(e[n].key)}function j(e,t){k(e),D(e,t)}function M(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n?.startsWith(x)&&e.push(n)}for(let t of e)localStorage.removeItem(t)}catch{}}async function N(r,i,a,o){let s=(o?.baseUrl??a)?.replace(/\/$/,``),c=E(r,i,s);if(c)return c;let l=O(r,i);if(l)return D(l,s),l;let u=e=>({chainId:e.chainId??r,address:e.address??i,symbol:e.symbol,name:e.name,decimals:e.decimals,logoURI:e.logoURI,...Number.isFinite(Number(e.extensions?.price?.usd??``))?{priceUsd:Number(e.extensions?.price?.usd??``)}:{}}),d=e=>{let t=g(i);return e.find(e=>Number(e.chainId)===r&&g(e.address)===t)};if(o||a)try{let c=d((await(o??new t({baseUrl:a})).searchTokens(i,{chainIds:[r]})).data??[]);if(c){let e=u(c);return j(e,s),e}throw new e(n.INVALID_TOKEN_IDENTIFIER,`Token not found for chain ${r}: ${i}`)}catch(t){if(t instanceof e)throw t}return{chainId:r,address:i,decimals:void 0}}function P(e,t){if(!e||t<0)return`0`;let n;try{n=(e.startsWith(`0x`),BigInt(e).toString())}catch{return`0`}let r=n.startsWith(`-`),i=r?n.slice(1):n;if(t===0)return r?`-${i}`:i;let a=i.padStart(t+1,`0`),o=a.slice(0,a.length-t),s=a.slice(a.length-t).replace(/0+$/,``),c=s?`${o}.${s}`:o;return r?`-${c}`:c}function F(e,t){if(!e||!/^-?(?:\d+(?:\.\d*)?|\.\d+)$/.test(e))return`0`;let n=e.startsWith(`-`),r=(n?e.slice(1):e).split(`.`),i=((r[0]??`0`)+(r[1]??``).slice(0,t).padEnd(t,`0`)).replace(/^0+/,``)||`0`;return n?`-${i}`:i}function I(e,t,n,r){if(!e||!n||e===`0`||t<0||r<0)return`0`;let i,a;try{i=BigInt(e),a=BigInt(n)}catch{return`0`}if(i===0n)return`0`;let o=10n**BigInt(8),s=(a*10n**BigInt(t)*o/(i*10n**BigInt(r))).toString().padStart(9,`0`),c=s.slice(0,s.length-8),l=s.slice(s.length-8).replace(/0+$/,``);return l?`${c}.${l}`:c}function L(e){let t=e.split(`.`),n=t[0]??`0`,r=n.startsWith(`-`),i=(r?n.slice(1):n).replace(/\B(?=(\d{3})+(?!\d))/g,`,`),a=r?`-${i}`:i;return t[1]===void 0?a:`${a}.${t[1]}`}function R(e,t=6){if(!e||e===`0`)return`0`;let n=e.split(`.`),r=n[0]??`0`;if(!n[1])return e;let i=n[1];if(r!==`0`&&r!==`-0`){let e=i.slice(0,t).replace(/0+$/,``);return e?`${r}.${e}`:r}let a=i.search(/[1-9]/);if(a===-1)return`0`;let o=a+t,s=i.slice(0,o).replace(/0+$/,``);return s?`${r}.${s}`:`0`}var z=20011e6;function B(e){return e===z}function V(e){return e!==z}function H(e){return B(e)?`solana`:`evm`}function U(e,t){return H(e)!==H(t)}function W(e){return B(e)?`11111111111111111111111111111111`:`0x0000000000000000000000000000000000000000`}function G(e,t){return t?.get(e)?.name??`Chain ${e}`}function K(e,t){return t===`evm`?/^0x[0-9a-fA-F]{40}$/.test(e):/^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e)}function q(e){return e?.includes(`1-click`)??!1}function J(e){try{return e.startsWith(`0x`),BigInt(e)}catch{return null}}function Y(e){let t=[];for(let n of e){let e=J(n.quote.amountOut);e!==null&&t.push({routeId:n.routeId,amountOut:e,etaSeconds:Number.isFinite(n.quote.expectedDurationSeconds)?n.quote.expectedDurationSeconds:2**53-1,isGuaranteedOutput:!1,isOneClick:q(n.tags)})}return t}function X(e,t){let n=[];for(let r of e){let e=J(r.quote.amountIn);if(e===null)continue;let i=t===`EXACT_OUTPUT`&&r.exactOutMethod===`native`;n.push({routeId:r.routeId,amountIn:e,etaSeconds:Number.isFinite(r.quote.expectedDurationSeconds)?r.quote.expectedDurationSeconds:2**53-1,isGuaranteedOutput:i,isOneClick:q(r.tags)})}return n}function Z(e){if(e.length===0)return[];let t=e[0].amountOut;for(let n of e)n.amountOut>t&&(t=n.amountOut);let n=t*999n/1000n,r=[...e.filter(e=>e.amountOut>=n)].sort((e,t)=>{if(e.isGuaranteedOutput!==t.isGuaranteedOutput)return e.isGuaranteedOutput?-1:1;if(e.isOneClick!==t.isOneClick)return e.isOneClick?-1:1;let n=e.etaSeconds-t.etaSeconds;return n===0?t.amountOut>e.amountOut?1:t.amountOut<e.amountOut?-1:0:n}),i=new Set(r.map(e=>e.routeId)),a=e.filter(e=>!i.has(e.routeId)).sort((e,t)=>t.amountOut>e.amountOut?1:t.amountOut<e.amountOut?-1:0);return[...r.map(e=>e.routeId),...a.map(e=>e.routeId)]}function Q(e){if(e.length===0)return[];let t=e[0].amountIn;for(let n of e)n.amountIn<t&&(t=n.amountIn);let n=t*1001n/1000n,r=[...e.filter(e=>e.amountIn<=n)].sort((e,t)=>{if(e.isGuaranteedOutput!==t.isGuaranteedOutput)return e.isGuaranteedOutput?-1:1;if(e.isOneClick!==t.isOneClick)return e.isOneClick?-1:1;let n=e.etaSeconds-t.etaSeconds;return n===0?e.amountIn>t.amountIn?1:e.amountIn<t.amountIn?-1:0:n}),i=new Set(r.map(e=>e.routeId)),a=e.filter(e=>!i.has(e.routeId)).sort((e,t)=>e.amountIn>t.amountIn?1:e.amountIn<t.amountIn?-1:0);return[...r.map(e=>e.routeId),...a.map(e=>e.routeId)]}function $(e){return Z(Y(e))[0]??null}function ee(e,t){return Q(X(e,t))[0]??null}export{p as A,b as C,f as D,c as E,h as O,_ as S,l as T,P as _,z as a,N as b,W as c,V as d,B as f,F as g,R as h,Q as i,m as j,d as k,K as l,I as m,ee as n,G as o,L as p,$ as r,H as s,X as t,U as u,M as v,v as w,y as x,j as y};
1
+ import{c as e,i as t,t as n}from"./errors-BZKSEUy5.js";import{n as r}from"./shared.module-C-kWMzqW.js";var i={ETH:[`ETH`,`WETH`],USDC:[`USDC`,`USDC.e`,`USDbC`],USDT:[`USDT`,`USDT.e`]},a={STABLES_MAJOR:[`USDT`,`USDC`,`USDE`,`DAI`,`USDS`,`USD1`,`BUIDL`,`USDF`,`USDTB`,`PYUSD`],STABLE_WRAPPED:[`USDE`,`SUSDE`,`USDS`,`SUSDS`,`DAI`,`SDAI`],BTC:[`BTC`,`WBTC`,`TBTC`,`CBBTC`,`BTC.B`,`CKBTC`],ETH_LST_LRT:[`ETH`,`WETH`,`STETH`,`WSTETH`,`RETH`,`CBETH`,`FRXETH`,`SFRXETH`,`OSETH`,`ETHX`,`METH`,`EETH`,`WEETH`,`EZETH`,`PUFETH`,`RSETH`,`WBETH`]},o=new Set([`BTC`,`ETH`,`WETH`,`WBTC`,`USDC`,`USDT`,`DAI`,`BNB`,`XRP`,`SOL`,`TRX`,`DOGE`,`ADA`,`BCH`,`HYPE`,`XMR`,`LEO`,`LINK`,`MATIC`,`AVAX`]),s=new Set([`USDC`,`USDT`,`DAI`,`USDE`,`USDS`,`USD1`,`USDF`,`USDG`,`RLUSD`,`USDD`,`BUSD`,`TUSD`,`USDP`,`FRAX`,`LUSD`,`GUSD`,`PYUSD`]),c=.1,l=new Set([1]),u=new Set([`0x0000000000000000000000000000000000000000`,`0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee`,`11111111111111111111111111111111`]);function d(e){return e?u.has(e.toLowerCase()):!1}function f(e,t){let n=e.toUpperCase(),r=t.toUpperCase();if(n===r)return!0;for(let e of Object.values(i)){let t=e.some(e=>e.toUpperCase()===n),i=e.some(e=>e.toUpperCase()===r);if(t&&i)return!0}return!1}function p(e,t){let n=e.toUpperCase(),r=t.toUpperCase();for(let e of Object.values(a)){let t=e.some(e=>e.toUpperCase()===n),i=e.some(e=>e.toUpperCase()===r);if(t&&i)return!0}return!1}function m(e){return s.has(e.toUpperCase())}function h(e){return o.has(e.toUpperCase())}function g(e){return d(e)&&(e.startsWith(`0x`)||e.startsWith(`0X`))?`0x0000000000000000000000000000000000000000`:e.toLowerCase()}function _(e,t){return e.chainId===t.chainId&&g(e.address)===g(t.address)}function v(e){return`${e.chainId}:${g(e.address)}`}function y(e,t){return t?e.find(e=>_(e,t))??null:null}function b(e){let{defaultFromToken:t,balances:n,currentSelection:r,userPicked:i}=e;return!t||n.length===0||i||r&&_(r,t)?null:y(n,t)}var x=`tf:token:`,S=1440*60*1e3,C=200;function w(e,t,n){return[`tokenInfo`,n??`__default__`,e,t.toLowerCase()]}function T(e,t){return`${x}${e}:${t.toLowerCase()}`}function E(e,t,n){return r.getQueryData(w(e,t,n))??null}function D(e,t){r.setQueryData(w(e.chainId,e.address,t),e)}function O(e,t){try{let n=T(e,t),r=localStorage.getItem(n);if(!r)return null;let i=JSON.parse(r);return Date.now()-i.timestamp>S?(localStorage.removeItem(n),null):i.token}catch{return null}}function k(e){try{let t=T(e.chainId,e.address),n={token:e,timestamp:Date.now()};localStorage.setItem(t,JSON.stringify(n)),A()}catch{}}function A(){let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);if(n?.startsWith(x))try{let t=localStorage.getItem(n);if(t){let r=JSON.parse(t);e.push({key:n,timestamp:r.timestamp})}}catch{n&&localStorage.removeItem(n)}}if(e.length<=C)return;e.sort((e,t)=>e.timestamp-t.timestamp);let t=e.length-C;for(let n=0;n<t;n++)localStorage.removeItem(e[n].key)}function j(e,t){k(e),D(e,t)}function M(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n?.startsWith(x)&&e.push(n)}for(let t of e)localStorage.removeItem(t)}catch{}}async function N(r,i,a,o){let s=(o?.baseUrl??a)?.replace(/\/$/,``),c=E(r,i,s);if(c)return c;let l=O(r,i);if(l)return D(l,s),l;let u=e=>({chainId:e.chainId??r,address:e.address??i,symbol:e.symbol,name:e.name,decimals:e.decimals,logoURI:e.logoURI,...Number.isFinite(Number(e.extensions?.price?.usd??``))?{priceUsd:Number(e.extensions?.price?.usd??``)}:{}}),d=e=>{let t=g(i);return e.find(e=>Number(e.chainId)===r&&g(e.address)===t)};if(o||a)try{let c=d((await(o??new t({baseUrl:a})).searchTokens(i,{chainIds:[r]})).data??[]);if(c){let e=u(c);return j(e,s),e}throw new e(n.INVALID_TOKEN_IDENTIFIER,`Token not found for chain ${r}: ${i}`)}catch(t){if(t instanceof e)throw t}return{chainId:r,address:i,decimals:void 0}}function P(e,t){if(!e||t<0)return`0`;let n;try{n=(e.startsWith(`0x`),BigInt(e).toString())}catch{return`0`}let r=n.startsWith(`-`),i=r?n.slice(1):n;if(t===0)return r?`-${i}`:i;let a=i.padStart(t+1,`0`),o=a.slice(0,a.length-t),s=a.slice(a.length-t).replace(/0+$/,``),c=s?`${o}.${s}`:o;return r?`-${c}`:c}function F(e,t){if(!e||!/^-?(?:\d+(?:\.\d*)?|\.\d+)$/.test(e))return`0`;let n=e.startsWith(`-`),r=(n?e.slice(1):e).split(`.`),i=((r[0]??`0`)+(r[1]??``).slice(0,t).padEnd(t,`0`)).replace(/^0+/,``)||`0`;return n?`-${i}`:i}function I(e,t,n,r){if(!e||!n||e===`0`||t<0||r<0)return`0`;let i,a;try{i=BigInt(e),a=BigInt(n)}catch{return`0`}if(i===0n)return`0`;let o=10n**BigInt(8),s=(a*10n**BigInt(t)*o/(i*10n**BigInt(r))).toString().padStart(9,`0`),c=s.slice(0,s.length-8),l=s.slice(s.length-8).replace(/0+$/,``);return l?`${c}.${l}`:c}function L(e){let t=e.split(`.`),n=t[0]??`0`,r=n.startsWith(`-`),i=(r?n.slice(1):n).replace(/\B(?=(\d{3})+(?!\d))/g,`,`),a=r?`-${i}`:i;return t[1]===void 0?a:`${a}.${t[1]}`}function R(e,t=6){if(!e||e===`0`)return`0`;let n=e.split(`.`),r=n[0]??`0`;if(!n[1])return e;let i=n[1];if(r!==`0`&&r!==`-0`){let e=i.slice(0,t).replace(/0+$/,``);return e?`${r}.${e}`:r}let a=i.search(/[1-9]/);if(a===-1)return`0`;let o=a+t,s=i.slice(0,o).replace(/0+$/,``);return s?`${r}.${s}`:`0`}var z=20011e6;function B(e){return e===z}function V(e){return e!==z}function H(e){return B(e)?`solana`:`evm`}function U(e,t){return H(e)!==H(t)}function W(e){return B(e)?`11111111111111111111111111111111`:`0x0000000000000000000000000000000000000000`}function G(e,t){return t?.get(e)?.name??`Chain ${e}`}function K(e,t){return t===`evm`?/^0x[0-9a-fA-F]{40}$/.test(e):/^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(e)}function q(e){return e?.includes(`1-click`)??!1}function J(e){try{return e.startsWith(`0x`),BigInt(e)}catch{return null}}function Y(e){let t=[];for(let n of e){let e=J(n.quote.amountOut);e!==null&&t.push({routeId:n.routeId,amountOut:e,etaSeconds:Number.isFinite(n.quote.expectedDurationSeconds)?n.quote.expectedDurationSeconds:2**53-1,isGuaranteedOutput:!1,isOneClick:q(n.tags)})}return t}function X(e,t){let n=[];for(let r of e){let e=J(r.quote.amountIn);if(e===null)continue;let i=t===`EXACT_OUTPUT`&&r.exactOutMethod===`native`;n.push({routeId:r.routeId,amountIn:e,etaSeconds:Number.isFinite(r.quote.expectedDurationSeconds)?r.quote.expectedDurationSeconds:2**53-1,isGuaranteedOutput:i,isOneClick:q(r.tags)})}return n}function Z(e){if(e.length===0)return[];let t=e[0].amountOut;for(let n of e)n.amountOut>t&&(t=n.amountOut);let n=t*999n/1000n,r=[...e.filter(e=>e.amountOut>=n)].sort((e,t)=>{if(e.isGuaranteedOutput!==t.isGuaranteedOutput)return e.isGuaranteedOutput?-1:1;if(e.isOneClick!==t.isOneClick)return e.isOneClick?-1:1;let n=e.etaSeconds-t.etaSeconds;return n===0?t.amountOut>e.amountOut?1:t.amountOut<e.amountOut?-1:0:n}),i=new Set(r.map(e=>e.routeId)),a=e.filter(e=>!i.has(e.routeId)).sort((e,t)=>t.amountOut>e.amountOut?1:t.amountOut<e.amountOut?-1:0);return[...r.map(e=>e.routeId),...a.map(e=>e.routeId)]}function Q(e){if(e.length===0)return[];let t=e[0].amountIn;for(let n of e)n.amountIn<t&&(t=n.amountIn);let n=t*1001n/1000n,r=[...e.filter(e=>e.amountIn<=n)].sort((e,t)=>{if(e.isGuaranteedOutput!==t.isGuaranteedOutput)return e.isGuaranteedOutput?-1:1;if(e.isOneClick!==t.isOneClick)return e.isOneClick?-1:1;let n=e.etaSeconds-t.etaSeconds;return n===0?e.amountIn>t.amountIn?1:e.amountIn<t.amountIn?-1:0:n}),i=new Set(r.map(e=>e.routeId)),a=e.filter(e=>!i.has(e.routeId)).sort((e,t)=>e.amountIn>t.amountIn?1:e.amountIn<t.amountIn?-1:0);return[...r.map(e=>e.routeId),...a.map(e=>e.routeId)]}function $(e){return Z(Y(e))[0]??null}function ee(e,t){return Q(X(e,t))[0]??null}export{p as A,b as C,f as D,c as E,h as O,_ as S,l as T,P as _,z as a,N as b,W as c,V as d,B as f,F as g,R as h,Q as i,m as j,d as k,K as l,I as m,ee as n,G as o,L as p,$ as r,H as s,X as t,U as u,M as v,v as w,y as x,j as y};
@@ -1 +1 @@
1
- import{S as e,_ as t,m as n,u as r,v as i}from"./solid-iWr5Czxc.js";import{S as a,a as o,b as s,c,d as l,f as u,g as d,h as f,i as p,l as m,m as h,n as g,o as _,p as v,r as y,s as ee,t as b,u as x,v as S,y as te}from"./register-defaults-C_q7CG7x.js";import{c as C,t as w}from"./errors-Nd9setTj.js";import{_ as T,b as E,c as D,d as O,h as k,n as A,r as j,u as M,v as N,x as P,y as F}from"./shared.module-C-kWMzqW.js";import{a as I,n as L,o as R,r as z,t as B}from"./theme-C9tsVWlo.js";import{n as V,t as H}from"./widget-BadYytj9.js";function ne(e){if(typeof e==`string`){let t=document.querySelector(e);if(!t)throw new C(w.ELEMENT_NOT_FOUND,`Element not found: ${e}`);return t}return e}function re(e,t){var n,i,a,o,s,c,l,u;return n=new WeakMap,i=new WeakMap,a=new WeakMap,o=new WeakMap,s=new WeakMap,c=new WeakMap,l=new WeakMap,u=new WeakSet,class{constructor(e){P(this,u),E(this,n,null),E(this,i,null),E(this,a,void 0),E(this,o,null),E(this,s,void 0),E(this,c,void 0),E(this,l,void 0),T(a,this,ne(e.container)),T(s,this,e.config),T(c,this,e.walletAdapter),T(l,this,e.callbacks)}initialize(){N(n,this)&&this.destroy();let t=document.createElement(`div`);N(a,this).appendChild(t);let i=t.attachShadow({mode:`open`});T(o,this,i);let p=document.createElement(`style`),m=N(s,this).theme??`light`;F(u,this,d).call(this,p,m),i.appendChild(p),F(u,this,f).call(this,p);let h=document.createElement(`div`);i.appendChild(h),N(s,this).customColors&&B(t,N(s,this).customColors);let g=N(s,this),_=N(c,this),v=N(l,this);T(n,this,M(()=>r(j,{client:A,get children(){return e(g,_,v)}}),h))}destroy(){N(i,this)&&(N(i,this).call(this),T(i,this,null)),N(n,this)&&(N(n,this).call(this),T(n,this,null)),T(o,this,null),N(a,this).innerHTML=``}setTheme(e){T(s,this,{...N(s,this),theme:e});let t=N(o,this);if(t){let n=t.querySelector(`style`);n&&(F(u,this,d).call(this,n,e),F(u,this,f).call(this,n))}}setCustomColors(e){let t=N(o,this)?.host;t&&B(t,e)}};function d(e,n){let r=(n===`auto`?typeof window<`u`&&window.matchMedia?.(`(prefers-color-scheme: dark)`).matches===!0:n===`dark`)?z:I;e.textContent=`${t()}\n:host { ${L(r)} }`}function f(e){N(i,this)&&(N(i,this).call(this),T(i,this,null)),N(s,this).theme===`auto`&&T(i,this,R(n=>{e.textContent=`${t()}\n:host { ${L(n)} }`}))}}var U=re((e,t,n)=>r(V,{config:e,walletAdapter:t,callbacks:n}),()=>H);function W(e){return Object.keys(e).reduce((t,n)=>{let r=e[n];return t[n]=Object.assign({},r),X(r.value)&&!ae(r.value)&&!Array.isArray(r.value)&&(t[n].value=Object.assign({},r.value)),Array.isArray(r.value)&&(t[n].value=r.value.slice(0)),t},{})}function G(e){return e?Object.keys(e).reduce((t,n)=>{let r=e[n];return t[n]=X(r)&&`value`in r?r:{value:r},t[n].attribute||(t[n].attribute=ie(n)),t[n].parse=`parse`in t[n]?t[n].parse:typeof t[n].value!=`string`,t},{}):{}}function K(e){return Object.keys(e).reduce((t,n)=>(t[n]=e[n].value,t),{})}function q(e,t){let n=W(t);return Object.keys(t).forEach(t=>{let r=n[t],i=e.getAttribute(r.attribute),a=e[t];i!=null&&(r.value=r.parse?J(i):i),a!=null&&(r.value=Array.isArray(a)?a.slice(0):a),r.reflect&&Y(e,r.attribute,r.value,!!r.parse),Object.defineProperty(e,t,{get(){return r.value},set(e){let n=r.value;r.value=e,r.reflect&&Y(this,r.attribute,r.value,!!r.parse);for(let r=0,i=this.__propertyChangedCallbacks.length;r<i;r++)this.__propertyChangedCallbacks[r](t,e,n)},enumerable:!0,configurable:!0})}),n}function J(e){if(e)try{return JSON.parse(e)}catch{return e}}function Y(e,t,n,r){if(n==null||n===!1)return e.removeAttribute(t);let i=r?JSON.stringify(n):n;e.__updating[t]=!0,i===`true`&&(i=``),e.setAttribute(t,i),Promise.resolve().then(()=>delete e.__updating[t])}function ie(e){return e.replace(/\.?([A-Z]+)/g,(e,t)=>`-`+t.toLowerCase()).replace(`_`,`-`).replace(/^-/,``)}function X(e){return e!=null&&(typeof e==`object`||typeof e==`function`)}function ae(e){return Object.prototype.toString.call(e)===`[object Function]`}function oe(e){return typeof e==`function`&&e.toString().indexOf(`class`)===0}var Z;function se(e,t){let n=Object.keys(t);return class extends e{static get observedAttributes(){return n.map(e=>t[e].attribute)}constructor(){super(),this.__initialized=!1,this.__released=!1,this.__releaseCallbacks=[],this.__propertyChangedCallbacks=[],this.__updating={},this.props={};for(let e of n)this[e]=void 0}connectedCallback(){if(this.__initialized)return;this.__releaseCallbacks=[],this.__propertyChangedCallbacks=[],this.__updating={},this.props=q(this,t);let e=K(this.props),n=this.Component,r=Z;try{Z=this,this.__initialized=!0,oe(n)?new n(e,{element:this}):n(e,{element:this})}finally{Z=r}}async disconnectedCallback(){if(await Promise.resolve(),this.isConnected)return;this.__propertyChangedCallbacks.length=0;let e=null;for(;e=this.__releaseCallbacks.pop();)e(this);delete this.__initialized,this.__released=!0}attributeChangedCallback(e,n,r){if(this.__initialized&&!this.__updating[e]&&(e=this.lookupProp(e),e in t)){if(r==null&&!this[e])return;this[e]=t[e].parse?J(r):r}}lookupProp(e){if(t)return n.find(n=>e===n||e===t[n].attribute)}get renderRoot(){return this.shadowRoot||this.attachShadow({mode:`open`})}addReleaseCallback(e){this.__releaseCallbacks.push(e)}addPropertyChangedCallback(e){this.__propertyChangedCallbacks.push(e)}}}function ce(e,t={},n={}){let{BaseElement:r=HTMLElement,extension:i,customElements:a=window.customElements}=n;return n=>{if(!e)throw Error(`tag is required to register a Component`);let o=a.get(e);return o?(o.prototype.Component=n,o):(o=se(r,G(t)),o.prototype.Component=n,o.prototype.registeredTag=e,a.define(e,o,i),o)}}function le(e){let t=Object.keys(e),n={};for(let r=0;r<t.length;r++){let[a,o]=i(e[t[r]]);Object.defineProperty(n,t[r],{get:a,set(e){o(()=>e)}})}return n}function Q(e){if(e.assignedSlot&&e.assignedSlot._$owner)return e.assignedSlot._$owner;let t=e.parentNode;for(;t&&!t._$owner&&!(t.assignedSlot&&t.assignedSlot._$owner);)t=t.parentNode;return t&&t.assignedSlot?t.assignedSlot._$owner:e._$owner}function ue(e){return(n,r)=>{let{element:i}=r;return t(t=>{let a=le(n);i.addPropertyChangedCallback((e,t)=>a[e]=t),i.addReleaseCallback(()=>{i.renderRoot.textContent=``,t()});let o=e(a,r);return D(i.renderRoot,o)},Q(i))}}function de(e,t,n){return arguments.length===2&&(n=t,t={}),ce(e,t)(ue(n))}var fe=k(`<style>`);function pe(e){if(!e)return``;let t=e.trim();if(t.startsWith(`[`))try{let e=JSON.parse(t);if(Array.isArray(e))return e}catch{}return t}function $(e){if(e)try{let t=JSON.parse(e.trim());if(Array.isArray(t))return t}catch{}}function me(e){if(e)try{let t=JSON.parse(e.trim());if(Array.isArray(t))return t}catch{}}function he(e){if(e)try{let t=JSON.parse(e.trim());if(typeof t==`object`&&t&&!Array.isArray(t)&&Object.values(t).every(e=>typeof e==`string`))return t}catch{}}function ge(e){return e===`hidden`||e===`visible`?e:void 0}function _e(t){t&&b(t),!(typeof customElements>`u`)&&(customElements.get(`tokenflight-widget`)||de(`tokenflight-widget`,{"api-endpoint":``,"fiat-api-endpoint":``,"to-token":``,"from-token":``,"trade-type":``,amount:``,recipient:``,icon:``,"lock-from-token":!1,"lock-to-token":!1,"fiat-currency":``,methods:``,"default-pay-method":``,"from-tokens":``,"to-tokens":``,"title-text":``,"title-image":``,theme:``,locale:``,"csp-nonce":``,"hide-title":!1,"hide-powered-by":!1,"hide-provider":!1,"quote-card":``,"no-background":!1,"no-border":!1,"recipient-editable":!1,"refund-to":``,"rpc-overrides":``,referrer:``,"referrer-fee-bps":``},(t,{element:b})=>{let C={get apiEndpoint(){return t[`api-endpoint`]||y()||void 0},get fiatApiEndpoint(){return t[`fiat-api-endpoint`]||_()||void 0},get toToken(){return pe(t[`to-token`])},get fromToken(){return t[`from-token`]||void 0},get tradeType(){return t[`trade-type`]||void 0},get amount(){return t.amount||void 0},get recipient(){return t.recipient||void 0},get recipientEditable(){return s(t[`recipient-editable`])},get refundTo(){return t[`refund-to`]||void 0},get icon(){return t.icon||void 0},get lockFromToken(){return s(t[`lock-from-token`])},get lockToToken(){return s(t[`lock-to-token`])},get fiatCurrency(){return t[`fiat-currency`]||void 0},get methods(){return me(t.methods)??l()},get defaultPayMethod(){return t[`default-pay-method`]||void 0},get fromTokens(){return $(t[`from-tokens`])},get toTokens(){return $(t[`to-tokens`])},get titleText(){return t[`title-text`]||void 0},get titleImageUrl(){return t[`title-image`]||void 0},get theme(){return t.theme||S()||`light`},get locale(){return t.locale||x()||`en-US`},get hideTitle(){return g(b,t[`hide-title`],`hide-title`)?s(t[`hide-title`])??!1:m()},get hidePoweredBy(){return g(b,t[`hide-powered-by`],`hide-powered-by`)?s(t[`hide-powered-by`])??!1:ee()},get hideProvider(){return g(b,t[`hide-provider`],`hide-provider`)?s(t[`hide-provider`])??!1:c()},get quoteCard(){return ge(t[`quote-card`])},get noBackground(){return g(b,t[`no-background`],`no-background`)?s(t[`no-background`])??!1:u()},get noBorder(){return g(b,t[`no-border`],`no-border`)?s(t[`no-border`])??!1:v()},get rpcOverrides(){return he(t[`rpc-overrides`])??d()},get referrer(){return w().referrer},get referrerFeeBps(){return w().referrerFeeBps}},w=()=>a(t.referrer||h(),t[`referrer-fee-bps`]===``?f():Number(t[`referrer-fee-bps`]),b),T=t[`csp-nonce`]||void 0,[E,k]=i(typeof window<`u`&&window.matchMedia?.(`(prefers-color-scheme: dark)`).matches===!0);e(R(e=>{k(e===z)}));let M=b.__customColors,N=n(()=>{let e=t.theme||S()||`light`,n=(e===`auto`?E():e===`dark`)?z:I,r=o();return`${H}\n:host { ${L(r||M?{...n,...r,...M}:n)} }`}),P=b.__walletAdapter,F=b.__callbacks;return[(()=>{var e=fe();return O(e,`nonce`,T),D(e,N),e})(),r(j,{client:A,get children(){return r(V,{config:C,get walletAdapter(){return P??te()},get callbacks(){return F?{...p(),...F}:p()}})}})]}))}export{U as n,_e as t};
1
+ import{S as e,_ as t,m as n,u as r,v as i}from"./solid-iWr5Czxc.js";import{S as a,a as o,b as s,c,d as l,f as u,g as d,h as f,i as p,l as m,m as h,n as g,o as _,p as v,r as y,s as ee,t as b,u as x,v as S,y as te}from"./register-defaults-C_q7CG7x.js";import{c as C,t as w}from"./errors-BZKSEUy5.js";import{_ as T,b as E,c as D,d as O,h as k,n as A,r as j,u as M,v as N,x as P,y as F}from"./shared.module-C-kWMzqW.js";import{a as I,n as L,o as R,r as z,t as B}from"./theme-C9tsVWlo.js";import{n as V,t as H}from"./widget-DQLVNkNn.js";function ne(e){if(typeof e==`string`){let t=document.querySelector(e);if(!t)throw new C(w.ELEMENT_NOT_FOUND,`Element not found: ${e}`);return t}return e}function re(e,t){var n,i,a,o,s,c,l,u;return n=new WeakMap,i=new WeakMap,a=new WeakMap,o=new WeakMap,s=new WeakMap,c=new WeakMap,l=new WeakMap,u=new WeakSet,class{constructor(e){P(this,u),E(this,n,null),E(this,i,null),E(this,a,void 0),E(this,o,null),E(this,s,void 0),E(this,c,void 0),E(this,l,void 0),T(a,this,ne(e.container)),T(s,this,e.config),T(c,this,e.walletAdapter),T(l,this,e.callbacks)}initialize(){N(n,this)&&this.destroy();let t=document.createElement(`div`);N(a,this).appendChild(t);let i=t.attachShadow({mode:`open`});T(o,this,i);let p=document.createElement(`style`),m=N(s,this).theme??`light`;F(u,this,d).call(this,p,m),i.appendChild(p),F(u,this,f).call(this,p);let h=document.createElement(`div`);i.appendChild(h),N(s,this).customColors&&B(t,N(s,this).customColors);let g=N(s,this),_=N(c,this),v=N(l,this);T(n,this,M(()=>r(j,{client:A,get children(){return e(g,_,v)}}),h))}destroy(){N(i,this)&&(N(i,this).call(this),T(i,this,null)),N(n,this)&&(N(n,this).call(this),T(n,this,null)),T(o,this,null),N(a,this).innerHTML=``}setTheme(e){T(s,this,{...N(s,this),theme:e});let t=N(o,this);if(t){let n=t.querySelector(`style`);n&&(F(u,this,d).call(this,n,e),F(u,this,f).call(this,n))}}setCustomColors(e){let t=N(o,this)?.host;t&&B(t,e)}};function d(e,n){let r=(n===`auto`?typeof window<`u`&&window.matchMedia?.(`(prefers-color-scheme: dark)`).matches===!0:n===`dark`)?z:I;e.textContent=`${t()}\n:host { ${L(r)} }`}function f(e){N(i,this)&&(N(i,this).call(this),T(i,this,null)),N(s,this).theme===`auto`&&T(i,this,R(n=>{e.textContent=`${t()}\n:host { ${L(n)} }`}))}}var U=re((e,t,n)=>r(V,{config:e,walletAdapter:t,callbacks:n}),()=>H);function W(e){return Object.keys(e).reduce((t,n)=>{let r=e[n];return t[n]=Object.assign({},r),X(r.value)&&!ae(r.value)&&!Array.isArray(r.value)&&(t[n].value=Object.assign({},r.value)),Array.isArray(r.value)&&(t[n].value=r.value.slice(0)),t},{})}function G(e){return e?Object.keys(e).reduce((t,n)=>{let r=e[n];return t[n]=X(r)&&`value`in r?r:{value:r},t[n].attribute||(t[n].attribute=ie(n)),t[n].parse=`parse`in t[n]?t[n].parse:typeof t[n].value!=`string`,t},{}):{}}function K(e){return Object.keys(e).reduce((t,n)=>(t[n]=e[n].value,t),{})}function q(e,t){let n=W(t);return Object.keys(t).forEach(t=>{let r=n[t],i=e.getAttribute(r.attribute),a=e[t];i!=null&&(r.value=r.parse?J(i):i),a!=null&&(r.value=Array.isArray(a)?a.slice(0):a),r.reflect&&Y(e,r.attribute,r.value,!!r.parse),Object.defineProperty(e,t,{get(){return r.value},set(e){let n=r.value;r.value=e,r.reflect&&Y(this,r.attribute,r.value,!!r.parse);for(let r=0,i=this.__propertyChangedCallbacks.length;r<i;r++)this.__propertyChangedCallbacks[r](t,e,n)},enumerable:!0,configurable:!0})}),n}function J(e){if(e)try{return JSON.parse(e)}catch{return e}}function Y(e,t,n,r){if(n==null||n===!1)return e.removeAttribute(t);let i=r?JSON.stringify(n):n;e.__updating[t]=!0,i===`true`&&(i=``),e.setAttribute(t,i),Promise.resolve().then(()=>delete e.__updating[t])}function ie(e){return e.replace(/\.?([A-Z]+)/g,(e,t)=>`-`+t.toLowerCase()).replace(`_`,`-`).replace(/^-/,``)}function X(e){return e!=null&&(typeof e==`object`||typeof e==`function`)}function ae(e){return Object.prototype.toString.call(e)===`[object Function]`}function oe(e){return typeof e==`function`&&e.toString().indexOf(`class`)===0}var Z;function se(e,t){let n=Object.keys(t);return class extends e{static get observedAttributes(){return n.map(e=>t[e].attribute)}constructor(){super(),this.__initialized=!1,this.__released=!1,this.__releaseCallbacks=[],this.__propertyChangedCallbacks=[],this.__updating={},this.props={};for(let e of n)this[e]=void 0}connectedCallback(){if(this.__initialized)return;this.__releaseCallbacks=[],this.__propertyChangedCallbacks=[],this.__updating={},this.props=q(this,t);let e=K(this.props),n=this.Component,r=Z;try{Z=this,this.__initialized=!0,oe(n)?new n(e,{element:this}):n(e,{element:this})}finally{Z=r}}async disconnectedCallback(){if(await Promise.resolve(),this.isConnected)return;this.__propertyChangedCallbacks.length=0;let e=null;for(;e=this.__releaseCallbacks.pop();)e(this);delete this.__initialized,this.__released=!0}attributeChangedCallback(e,n,r){if(this.__initialized&&!this.__updating[e]&&(e=this.lookupProp(e),e in t)){if(r==null&&!this[e])return;this[e]=t[e].parse?J(r):r}}lookupProp(e){if(t)return n.find(n=>e===n||e===t[n].attribute)}get renderRoot(){return this.shadowRoot||this.attachShadow({mode:`open`})}addReleaseCallback(e){this.__releaseCallbacks.push(e)}addPropertyChangedCallback(e){this.__propertyChangedCallbacks.push(e)}}}function ce(e,t={},n={}){let{BaseElement:r=HTMLElement,extension:i,customElements:a=window.customElements}=n;return n=>{if(!e)throw Error(`tag is required to register a Component`);let o=a.get(e);return o?(o.prototype.Component=n,o):(o=se(r,G(t)),o.prototype.Component=n,o.prototype.registeredTag=e,a.define(e,o,i),o)}}function le(e){let t=Object.keys(e),n={};for(let r=0;r<t.length;r++){let[a,o]=i(e[t[r]]);Object.defineProperty(n,t[r],{get:a,set(e){o(()=>e)}})}return n}function Q(e){if(e.assignedSlot&&e.assignedSlot._$owner)return e.assignedSlot._$owner;let t=e.parentNode;for(;t&&!t._$owner&&!(t.assignedSlot&&t.assignedSlot._$owner);)t=t.parentNode;return t&&t.assignedSlot?t.assignedSlot._$owner:e._$owner}function ue(e){return(n,r)=>{let{element:i}=r;return t(t=>{let a=le(n);i.addPropertyChangedCallback((e,t)=>a[e]=t),i.addReleaseCallback(()=>{i.renderRoot.textContent=``,t()});let o=e(a,r);return D(i.renderRoot,o)},Q(i))}}function de(e,t,n){return arguments.length===2&&(n=t,t={}),ce(e,t)(ue(n))}var fe=k(`<style>`);function pe(e){if(!e)return``;let t=e.trim();if(t.startsWith(`[`))try{let e=JSON.parse(t);if(Array.isArray(e))return e}catch{}return t}function $(e){if(e)try{let t=JSON.parse(e.trim());if(Array.isArray(t))return t}catch{}}function me(e){if(e)try{let t=JSON.parse(e.trim());if(Array.isArray(t))return t}catch{}}function he(e){if(e)try{let t=JSON.parse(e.trim());if(typeof t==`object`&&t&&!Array.isArray(t)&&Object.values(t).every(e=>typeof e==`string`))return t}catch{}}function ge(e){return e===`hidden`||e===`visible`?e:void 0}function _e(t){t&&b(t),!(typeof customElements>`u`)&&(customElements.get(`tokenflight-widget`)||de(`tokenflight-widget`,{"api-endpoint":``,"fiat-api-endpoint":``,"to-token":``,"from-token":``,"trade-type":``,amount:``,recipient:``,icon:``,"lock-from-token":!1,"lock-to-token":!1,"fiat-currency":``,methods:``,"default-pay-method":``,"from-tokens":``,"to-tokens":``,"title-text":``,"title-image":``,theme:``,locale:``,"csp-nonce":``,"hide-title":!1,"hide-powered-by":!1,"hide-provider":!1,"quote-card":``,"no-background":!1,"no-border":!1,"recipient-editable":!1,"refund-to":``,"rpc-overrides":``,referrer:``,"referrer-fee-bps":``},(t,{element:b})=>{let C={get apiEndpoint(){return t[`api-endpoint`]||y()||void 0},get fiatApiEndpoint(){return t[`fiat-api-endpoint`]||_()||void 0},get toToken(){return pe(t[`to-token`])},get fromToken(){return t[`from-token`]||void 0},get tradeType(){return t[`trade-type`]||void 0},get amount(){return t.amount||void 0},get recipient(){return t.recipient||void 0},get recipientEditable(){return s(t[`recipient-editable`])},get refundTo(){return t[`refund-to`]||void 0},get icon(){return t.icon||void 0},get lockFromToken(){return s(t[`lock-from-token`])},get lockToToken(){return s(t[`lock-to-token`])},get fiatCurrency(){return t[`fiat-currency`]||void 0},get methods(){return me(t.methods)??l()},get defaultPayMethod(){return t[`default-pay-method`]||void 0},get fromTokens(){return $(t[`from-tokens`])},get toTokens(){return $(t[`to-tokens`])},get titleText(){return t[`title-text`]||void 0},get titleImageUrl(){return t[`title-image`]||void 0},get theme(){return t.theme||S()||`light`},get locale(){return t.locale||x()||`en-US`},get hideTitle(){return g(b,t[`hide-title`],`hide-title`)?s(t[`hide-title`])??!1:m()},get hidePoweredBy(){return g(b,t[`hide-powered-by`],`hide-powered-by`)?s(t[`hide-powered-by`])??!1:ee()},get hideProvider(){return g(b,t[`hide-provider`],`hide-provider`)?s(t[`hide-provider`])??!1:c()},get quoteCard(){return ge(t[`quote-card`])},get noBackground(){return g(b,t[`no-background`],`no-background`)?s(t[`no-background`])??!1:u()},get noBorder(){return g(b,t[`no-border`],`no-border`)?s(t[`no-border`])??!1:v()},get rpcOverrides(){return he(t[`rpc-overrides`])??d()},get referrer(){return w().referrer},get referrerFeeBps(){return w().referrerFeeBps}},w=()=>a(t.referrer||h(),t[`referrer-fee-bps`]===``?f():Number(t[`referrer-fee-bps`]),b),T=t[`csp-nonce`]||void 0,[E,k]=i(typeof window<`u`&&window.matchMedia?.(`(prefers-color-scheme: dark)`).matches===!0);e(R(e=>{k(e===z)}));let M=b.__customColors,N=n(()=>{let e=t.theme||S()||`light`,n=(e===`auto`?E():e===`dark`)?z:I,r=o();return`${H}\n:host { ${L(r||M?{...n,...r,...M}:n)} }`}),P=b.__walletAdapter,F=b.__callbacks;return[(()=>{var e=fe();return O(e,`nonce`,T),D(e,N),e})(),r(j,{client:A,get children(){return r(V,{config:C,get walletAdapter(){return P??te()},get callbacks(){return F?{...p(),...F}:p()}})}})]}))}export{U as n,_e as t};