@chainrails/react 0.0.28 → 0.0.29
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/chainrails-sdk.es.js +575 -259
- package/dist/chainrails-sdk.es.mjs +575 -259
- package/dist/chainrails-sdk.umd.js +2 -2
- package/dist/hooks/useGetSessionToken.d.ts +24 -0
- package/dist/hooks/useGetSessionToken.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
/*$vite$:1*/`,document.head.appendChild(O);function M(t){var e,r,s="";if(typeof t=="string"||typeof t=="number")s+=t;else if(typeof t=="object")if(Array.isArray(t)){var n=t.length;for(e=0;e<n;e++)t[e]&&(r=M(t[e]))&&(s&&(s+=" "),s+=r)}else for(r in t)t[r]&&(s&&(s+=" "),s+=r);return s}function G(){for(var t,e,r=0,s="",n=arguments.length;r<n;r++)(t=arguments[r])&&(e=M(t))&&(s&&(s+=" "),s+=e);return s}class S extends Error{response;request;options;constructor(e,r,s){const n=e.status||e.status===0?e.status:"",o=e.statusText??"",i=`${n} ${o}`.trim(),a=i?`status code ${i}`:"an unknown error";super(`Request failed with ${a}: ${r.method} ${r.url}`),this.name="HTTPError",this.response=e,this.request=r,this.options=s}}class I extends Error{name="NonError";value;constructor(e){let r="Non-error value was thrown";try{typeof e=="string"?r=e:e&&typeof e=="object"&&"message"in e&&typeof e.message=="string"&&(r=e.message)}catch{}super(r),this.value=e}}class A extends Error{name="ForceRetryError";customDelay;code;customRequest;constructor(e){const r=e?.cause?e.cause instanceof Error?e.cause:new I(e.cause):void 0;super(e?.code?`Forced retry: ${e.code}`:"Forced retry",r?{cause:r}:void 0),this.customDelay=e?.delay,this.code=e?.code,this.customRequest=e?.request}}const L=(()=>{let t=!1,e=!1;const r=typeof globalThis.ReadableStream=="function",s=typeof globalThis.Request=="function";if(r&&s)try{e=new globalThis.Request("https://empty.invalid",{body:new globalThis.ReadableStream,method:"POST",get duplex(){return t=!0,"half"}}).headers.has("Content-Type")}catch(n){if(n instanceof Error&&n.message==="unsupported BodyInit type")return!1;throw n}return t&&!e})(),X=typeof globalThis.AbortController=="function",B=typeof globalThis.AbortSignal=="function"&&typeof globalThis.AbortSignal.any=="function",Z=typeof globalThis.ReadableStream=="function",Q=typeof globalThis.FormData=="function",D=["get","post","put","patch","head","delete"],ee={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*",bytes:"*/*"},C=2147483647,te=new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length,H=Symbol("stop");class _{options;constructor(e){this.options=e}}const re=t=>new _(t),se={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},ne={next:!0},oe={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},ie=t=>{if(!t)return 0;if(t instanceof FormData){let e=0;for(const[r,s]of t)e+=te,e+=new TextEncoder().encode(`Content-Disposition: form-data; name="${r}"`).length,e+=typeof s=="string"?new TextEncoder().encode(s).length:s.size;return e}if(t instanceof Blob)return t.size;if(t instanceof ArrayBuffer)return t.byteLength;if(typeof t=="string")return new TextEncoder().encode(t).length;if(t instanceof URLSearchParams)return new TextEncoder().encode(t.toString()).length;if("byteLength"in t)return t.byteLength;if(typeof t=="object"&&t!==null)try{const e=JSON.stringify(t);return new TextEncoder().encode(e).length}catch{return 0}return 0},$=(t,e,r)=>{let s,n=0;return t.pipeThrough(new TransformStream({transform(o,i){if(i.enqueue(o),s){n+=s.byteLength;let a=e===0?0:n/e;a>=1&&(a=1-Number.EPSILON),r?.({percent:a,totalBytes:Math.max(e,n),transferredBytes:n},s)}s=o},flush(){s&&(n+=s.byteLength,r?.({percent:1,totalBytes:Math.max(e,n),transferredBytes:n},s))}}))},ae=(t,e)=>{if(!t.body)return t;if(t.status===204)return new Response(null,{status:t.status,statusText:t.statusText,headers:t.headers});const r=Math.max(0,Number(t.headers.get("content-length"))||0);return new Response($(t.body,r,e),{status:t.status,statusText:t.statusText,headers:t.headers})},ce=(t,e,r)=>{if(!t.body)return t;const s=ie(r??t.body);return new Request(t,{duplex:"half",body:$(t.body,s,e)})},p=t=>t!==null&&typeof t=="object",b=(...t)=>{for(const e of t)if((!p(e)||Array.isArray(e))&&e!==void 0)throw new TypeError("The `options` argument must be an object");return P({},...t)},z=(t={},e={})=>{const r=new globalThis.Headers(t),s=e instanceof globalThis.Headers,n=new globalThis.Headers(e);for(const[o,i]of n.entries())s&&i==="undefined"||i===void 0?r.delete(o):r.set(o,i);return r};function T(t,e,r){return Object.hasOwn(e,r)&&e[r]===void 0?[]:P(t[r]??[],e[r]??[])}const F=(t={},e={})=>({beforeRequest:T(t,e,"beforeRequest"),beforeRetry:T(t,e,"beforeRetry"),afterResponse:T(t,e,"afterResponse"),beforeError:T(t,e,"beforeError")}),ue=(t,e)=>{const r=new URLSearchParams;for(const s of[t,e])if(s!==void 0)if(s instanceof URLSearchParams)for(const[n,o]of s.entries())r.append(n,o);else if(Array.isArray(s))for(const n of s){if(!Array.isArray(n)||n.length!==2)throw new TypeError("Array search parameters must be provided in [[key, value], ...] format");r.append(String(n[0]),String(n[1]))}else if(p(s))for(const[n,o]of Object.entries(s))o!==void 0&&r.append(n,String(o));else{const n=new URLSearchParams(s);for(const[o,i]of n.entries())r.append(o,i)}return r},P=(...t)=>{let e={},r={},s={},n;const o=[];for(const i of t)if(Array.isArray(i))Array.isArray(e)||(e=[]),e=[...e,...i];else if(p(i)){for(let[a,c]of Object.entries(i)){if(a==="signal"&&c instanceof globalThis.AbortSignal){o.push(c);continue}if(a==="context"){if(c!=null&&(!p(c)||Array.isArray(c)))throw new TypeError("The `context` option must be an object");e={...e,context:c==null?{}:{...e.context,...c}};continue}if(a==="searchParams"){c==null?n=void 0:n=n===void 0?c:ue(n,c);continue}p(c)&&a in e&&(c=P(e[a],c)),e={...e,[a]:c}}p(i.hooks)&&(s=F(s,i.hooks),e.hooks=s),p(i.headers)&&(r=z(r,i.headers),e.headers=r)}return n!==void 0&&(e.searchParams=n),o.length>0&&(o.length===1?e.signal=o[0]:B?e.signal=AbortSignal.any(o):e.signal=o.at(-1)),e.context===void 0&&(e.context={}),e},le=t=>D.includes(t)?t.toUpperCase():t,J={limit:2,methods:["get","put","head","delete","options","trace"],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:[413,429,503],maxRetryAfter:Number.POSITIVE_INFINITY,backoffLimit:Number.POSITIVE_INFINITY,delay:t=>.3*2**(t-1)*1e3,jitter:void 0,retryOnTimeout:!1},he=(t={})=>{if(typeof t=="number")return{...J,limit:t};if(t.methods&&!Array.isArray(t.methods))throw new Error("retry.methods must be an array");if(t.statusCodes&&!Array.isArray(t.statusCodes))throw new Error("retry.statusCodes must be an array");return{...J,...t}};class v extends Error{request;constructor(e){super(`Request timed out: ${e.method} ${e.url}`),this.name="TimeoutError",this.request=e}}async function fe(t,e,r,s){return new Promise((n,o)=>{const i=setTimeout(()=>{r&&r.abort(),o(new v(t))},s.timeout);s.fetch(t,e).then(n).catch(o).then(()=>{clearTimeout(i)})})}async function de(t,{signal:e}){return new Promise((r,s)=>{e&&(e.throwIfAborted(),e.addEventListener("abort",n,{once:!0}));function n(){clearTimeout(o),s(e.reason)}const o=setTimeout(()=>{e?.removeEventListener("abort",n),r()},t)})}const pe=(t,e)=>{const r={};for(const s in e)Object.hasOwn(e,s)&&!(s in oe)&&!(s in se)&&(!(s in t)||s in ne)&&(r[s]=e[s]);return r},ye=t=>t===void 0?!1:Array.isArray(t)?t.length>0:t instanceof URLSearchParams?t.size>0:typeof t=="object"?Object.keys(t).length>0:typeof t=="string"?t.trim().length>0:!!t;function me(t){return t instanceof S||t?.name===S.name}function ge(t){return t instanceof v||t?.name===v.name}class m{static create(e,r){const s=new m(e,r),n=async()=>{if(typeof s.#e.timeout=="number"&&s.#e.timeout>C)throw new RangeError(`The \`timeout\` option cannot be greater than ${C}`);await Promise.resolve();let i=await s.#y();for(const a of s.#e.hooks.afterResponse){const c=s.#l(i.clone()),h=await a(s.request,s.#a(),c,{retryCount:s.#r});if(h instanceof globalThis.Response&&(i=h),h instanceof _)throw await Promise.all([c.body?.cancel(),i.body?.cancel()]),new A(h.options)}if(s.#l(i),!i.ok&&(typeof s.#e.throwHttpErrors=="function"?s.#e.throwHttpErrors(i.status):s.#e.throwHttpErrors)){let a=new S(i,s.request,s.#a());for(const c of s.#e.hooks.beforeError)a=await c(a,{retryCount:s.#r});throw a}if(s.#e.onDownloadProgress){if(typeof s.#e.onDownloadProgress!="function")throw new TypeError("The `onDownloadProgress` option must be a function");if(!Z)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return ae(i.clone(),s.#e.onDownloadProgress)}return i},o=s.#h(n).finally(async()=>{const i=s.#o,a=[];i&&!i.bodyUsed&&a.push(i.body?.cancel()),s.request.bodyUsed||a.push(s.request.body?.cancel()),await Promise.all(a)});for(const[i,a]of Object.entries(ee))i==="bytes"&&typeof globalThis.Response?.prototype?.bytes!="function"||(o[i]=async()=>{s.request.headers.set("accept",s.request.headers.get("accept")||a);const c=await o;if(i==="json"){if(c.status===204)return"";const h=await c.text();return h===""?"":r.parseJson?r.parseJson(h):JSON.parse(h)}return c[i]()});return o}static#d(e){return e&&typeof e=="object"&&!Array.isArray(e)&&!(e instanceof URLSearchParams)?Object.fromEntries(Object.entries(e).filter(([,r])=>r!==void 0)):e}request;#s;#r=0;#t;#e;#o;#n;#i;constructor(e,r={}){if(this.#t=e,this.#e={...r,headers:z(this.#t.headers,r.headers),hooks:F({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},r.hooks),method:le(r.method??this.#t.method??"GET"),prefixUrl:String(r.prefixUrl||""),retry:he(r.retry),throwHttpErrors:r.throwHttpErrors??!0,timeout:r.timeout??1e4,fetch:r.fetch??globalThis.fetch.bind(globalThis),context:r.context??{}},typeof this.#t!="string"&&!(this.#t instanceof URL||this.#t instanceof globalThis.Request))throw new TypeError("`input` must be a string, URL, or Request");if(this.#e.prefixUrl&&typeof this.#t=="string"){if(this.#t.startsWith("/"))throw new Error("`input` must not begin with a slash when using `prefixUrl`");this.#e.prefixUrl.endsWith("/")||(this.#e.prefixUrl+="/"),this.#t=this.#e.prefixUrl+this.#t}X&&B&&(this.#n=this.#e.signal??this.#t.signal,this.#s=new globalThis.AbortController,this.#e.signal=this.#n?AbortSignal.any([this.#n,this.#s.signal]):this.#s.signal),L&&(this.#e.duplex="half"),this.#e.json!==void 0&&(this.#e.body=this.#e.stringifyJson?.(this.#e.json)??JSON.stringify(this.#e.json),this.#e.headers.set("content-type",this.#e.headers.get("content-type")??"application/json"));const s=r.headers&&new globalThis.Headers(r.headers).has("content-type");if(this.#t instanceof globalThis.Request&&(Q&&this.#e.body instanceof globalThis.FormData||this.#e.body instanceof URLSearchParams)&&!s&&this.#e.headers.delete("content-type"),this.request=new globalThis.Request(this.#t,this.#e),ye(this.#e.searchParams)){const o="?"+(typeof this.#e.searchParams=="string"?this.#e.searchParams.replace(/^\?/,""):new URLSearchParams(m.#d(this.#e.searchParams)).toString()),i=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,o);this.request=new globalThis.Request(i,this.#e)}if(this.#e.onUploadProgress){if(typeof this.#e.onUploadProgress!="function")throw new TypeError("The `onUploadProgress` option must be a function");if(!L)throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");this.request=this.#f(this.request,this.#e.body??void 0)}}#c(){const e=this.#e.retry.delay(this.#r);let r=e;return this.#e.retry.jitter===!0?r=Math.random()*e:typeof this.#e.retry.jitter=="function"&&(r=this.#e.retry.jitter(e),(!Number.isFinite(r)||r<0)&&(r=e)),Math.min(this.#e.retry.backoffLimit,r)}async#p(e){if(this.#r++,this.#r>this.#e.retry.limit)throw e;const r=e instanceof Error?e:new I(e);if(r instanceof A)return r.customDelay??this.#c();if(!this.#e.retry.methods.includes(this.request.method.toLowerCase()))throw e;if(this.#e.retry.shouldRetry!==void 0){const s=await this.#e.retry.shouldRetry({error:r,retryCount:this.#r});if(s===!1)throw e;if(s===!0)return this.#c()}if(ge(e)&&!this.#e.retry.retryOnTimeout)throw e;if(me(e)){if(!this.#e.retry.statusCodes.includes(e.response.status))throw e;const s=e.response.headers.get("Retry-After")??e.response.headers.get("RateLimit-Reset")??e.response.headers.get("X-RateLimit-Retry-After")??e.response.headers.get("X-RateLimit-Reset")??e.response.headers.get("X-Rate-Limit-Reset");if(s&&this.#e.retry.afterStatusCodes.includes(e.response.status)){let n=Number(s)*1e3;Number.isNaN(n)?n=Date.parse(s)-Date.now():n>=Date.parse("2024-01-01")&&(n-=Date.now());const o=this.#e.retry.maxRetryAfter??n;return n<o?n:o}if(e.response.status===413)throw e}return this.#c()}#l(e){return this.#e.parseJson&&(e.json=async()=>this.#e.parseJson(await e.text())),e}async#h(e){try{return await e()}catch(r){const s=Math.min(await this.#p(r),C);if(this.#r<1)throw r;if(await de(s,this.#n?{signal:this.#n}:{}),r instanceof A&&r.customRequest){const n=this.#e.signal?new globalThis.Request(r.customRequest,{signal:this.#e.signal}):new globalThis.Request(r.customRequest);this.#u(n)}for(const n of this.#e.hooks.beforeRetry){const o=await n({request:this.request,options:this.#a(),error:r,retryCount:this.#r});if(o instanceof globalThis.Request){this.#u(o);break}if(o instanceof globalThis.Response)return o;if(o===H)return}return this.#h(e)}}async#y(){this.#s?.signal.aborted&&(this.#s=new globalThis.AbortController,this.#e.signal=this.#n?AbortSignal.any([this.#n,this.#s.signal]):this.#s.signal,this.request=new globalThis.Request(this.request,{signal:this.#e.signal}));for(const r of this.#e.hooks.beforeRequest){const s=await r(this.request,this.#a(),{retryCount:this.#r});if(s instanceof Response)return s;if(s instanceof globalThis.Request){this.#u(s);break}}const e=pe(this.request,this.#e);return this.#o=this.request,this.request=this.#o.clone(),this.#e.timeout===!1?this.#e.fetch(this.#o,e):fe(this.#o,e,this.#s,this.#e)}#a(){if(!this.#i){const{hooks:e,...r}=this.#e;this.#i=Object.freeze(r)}return this.#i}#u(e){this.#i=void 0,this.request=this.#f(e)}#f(e,r){return!this.#e.onUploadProgress||!e.body?e:ce(e,this.#e.onUploadProgress,r??this.#e.body??void 0)}}/*! MIT License © Sindre Sorhus */const x=t=>{const e=(r,s)=>m.create(r,b(t,s));for(const r of D)e[r]=(s,n)=>m.create(s,b(t,n,{method:r}));return e.create=r=>x(b(r)),e.extend=r=>(typeof r=="function"&&(r=r(t??{})),x(b(t,r))),e.stop=H,e.retry=re,e},we=x();var K=(t=>(t.ARBITRUM="ARBITRUM_MAINNET",t.ARBITRUM_TESTNET="ARBITRUM_TESTNET",t.AVALANCHE="AVALANCHE_MAINNET",t.AVALANCHE_TESTNET="AVALANCHE_TESTNET",t.BASE="BASE_MAINNET",t.BASE_TESTNET="BASE_TESTNET",t.BSC="BSC_MAINNET",t.ETHEREUM="ETHEREUM_MAINNET",t.ETHEREUM_TESTNET="ETHEREUM_TESTNET",t.STARKNET="STARKNET_MAINNET",t))(K||{}),W=(t=>(t.USDC="USDC",t))(W||{}),k=(t=>(t.PRODUCTION="production",t.STAGING="staging",t))(k||{});class u{constructor({api_key:e,env:r}){this.api_key=e,this.jwt="",this.env=r??k.PRODUCTION}static async config(e){if(!u.app){if(!e)throw new Error("Please provide an api_key");u.app=new u(e)}return e&&(u.app.api_key=e.api_key,e.env!==void 0&&(u.app.env=e.env),await this.updateJWT(),setInterval(this.updateJWT.bind(this),1500*1e3)),u.app}static async updateJWT(){try{const e=await(await fetch(this.getBaseUrl()+"/client/api-keys/session-token",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({apiKey:u.app.api_key})})).json();this.app.jwt=e.token}catch{}}static getApiKey(){if(!u.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return u.app.api_key}static getSessionKey(){return u.app.jwt}static getEnv(){if(!u.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return u.app.env==="internal"?"staging":u.app.env}static getBaseUrl(){if(!u.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");switch(u.app.env){case"production":return"https://api.chainrails.io/api/v1";case"staging":return"https://dev.chainrails.io/api/v1";case"internal":return"https://dev.chainrails.io/api/v1";default:return"https://api.chainrails.io/api/v1"}}static getPayModalUrl(e,r,s,n){if(!u.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");const o=u.app.env==="internal"?"https://chainrails-frontend-git-staging-horus-labs.vercel.app":"https://app.chainrails.io",i=n&&n>0?"/pay/":"/deposit/",a=`_chain_/${e}/_token_/${r}/_to_/${s}${n?"/_amount_/"+n*100:""}`;return o+i+a}}let j=null;function be(){j=we.create({prefixUrl:u.getBaseUrl(),headers:{"Content-Type":"application/json"},hooks:{beforeRequest:[t=>{const e=u.getSessionKey();t.headers.set("Authorization",`Bearer ${e}`)}],afterResponse:[(t,e,r)=>r]},retry:{limit:2}})}function l(){return j||be(),j}class Te{async getById(e){return await l().get("intents/"+e).json()}async getForSender(e){return await l().get("intents/user/"+e).json()}async getForAddress(e){return await l().get("intents/address/"+e).json()}async getAll(e){return await l().get("intents",{searchParams:e}).json()}async create(e){return await l().post("intents",{json:e}).json()}async update(e,r){return await l().post("intents",{json:r}).json()}async triggerProcessing(e){return await l().post(`intents/${e}/trigger-processing`).json()}}class Re{async getFromSpecificBridge(e){return await l().get("quotes/single",{searchParams:e}).json()}async getFromAllBridges(e){return await l().get("quotes/multiple",{searchParams:e}).json()}async getBestAcrossBridges(e){return await l().get("quotes/best",{searchParams:e}).json()}async getAll(e){return await l().get("quotes/multi-source",{searchParams:e}).json()}}class Ee{async getOptimalRoutes(e){return await l().get("router/optimal-route",{searchParams:e}).json()}async getAllSupportedBridges(){return await l().get("router/supported-bridges/all").json()}async getSupportedBridges(e){return await l().get("router/supported-bridges/route",{searchParams:e}).json()}async getSupportedRoutes(e,r){return await l().get("router/supported-bridges/bridge/"+e,{searchParams:r}).json()}}class Se{async getSupported(e){return await l().get("chains",{searchParams:e}).json()}}class Ae{async getClientInfo(){return await l().get("client/auth/client-info").json()}}const Ce={router:new Ee,quotes:new Re,intents:new Te,chains:new Se,client:new Ae};function Pe(t){const{to:e,token:r,chain:s,amount:n,isOpen:o,close:i,complete:a,cancel:c,chainSelected:h,intentCreated:R,...q}=t,[g,N]=d.useState(!0),U=d.useRef(null);d.useEffect(()=>{V();const w=document.body.style.overflow;o?(document.body.style.overflow="hidden",document.body.style.overflow="hidden"):document.body.style.overflow=w||"";const Y=E=>{E.data==="closed"&&c(),E.data==="completed"&&a(),E.data==="chainSelected"&&h(),E.data==="intentCreated"&&R()};return window.addEventListener("message",Y),()=>{document.body.style.overflow=w||"",window.removeEventListener("message",Y)}},[o,c,a,h,R]);function xe(){N(!1),V()}function V(){const w={type:"apiKey",apiKey:u.getApiKey(),environment:u.getEnv()||k.PRODUCTION};U.current?.contentWindow?.postMessage(w,"https://app.chainrails.io"),U.current?.contentWindow?.postMessage(w,"https://chainrails-frontend-git-staging-horus-labs.vercel.app")}return y.jsxs("div",{...q,className:G("payment-modal-wrapper",g?"loading":"not-loading",o?"open":"closed"),children:[g&&y.jsx("div",{role:"status",className:"payment-modal-loader",children:y.jsxs("svg",{"aria-hidden":"true",className:"icon",viewBox:"0 0 100 101",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[y.jsx("path",{d:"M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",fill:"currentColor"}),y.jsx("path",{d:"M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",fill:"currentFill"})]})}),y.jsx("iframe",{allow:"clipboard-read *; clipboard-write *",src:u.getPayModalUrl(s,r,e,n),onLoad:xe,className:`payment-modal ${g?"invisible":"visible"}`,"data-id":n,ref:U})]})}function ve(t){const{onCancel:e,onSuccess:r,onChainSelect:s,onIntentCreate:n,...o}=t,[i,a]=d.useState(!1);function c(){a(!0)}function h(){a(!1)}function R(){h(),e?.()}function q(){window.setTimeout(h,2e3),r?.()}function g(){s?.()}function N(){n?.()}return{open:c,close:h,complete:q,cancel:R,chainSelected:g,intentCreated:N,isOpen:i,...o}}f.Chainrails=u,f.PaymentModal=Pe,f.chains=K,f.crapi=Ce,f.tokens=W,f.usePaymentModal=ve,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(b,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime"],g):(b=typeof globalThis<"u"?globalThis:b||self,g(b.Chainrails={},b.React,b.jsxRuntime))})(this,(function(b,g,v){"use strict";var te=document.createElement("style");te.textContent=`.payment-modal-wrapper{position:fixed;inset:0;z-index:10000;height:100dvh;width:100vw;transition:all .1s ease-in-out}.payment-modal-wrapper.loading{background-color:#0003;-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px)}.payment-modal-wrapper.not-loading{background-color:#0008;-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px)}.payment-modal-wrapper.open{visibility:visible}.payment-modal-wrapper.closed{visibility:hidden;opacity:0;pointer-events:none}.payment-modal-wrapper.closed *{pointer-events:none!important}.payment-modal-wrapper.open iframe{transform:translateY(0);transform:scale(1)}.payment-modal-wrapper.closed iframe{transform:translateY(50vh);transform:scale(1)}.payment-modal-loader{position:absolute;inset:0;z-index:10000;display:grid;height:100%;width:100%;place-content:center}.payment-modal-loader .icon{height:48px;width:48px;animation:cr-spin 1s linear infinite;fill:#2563eb;color:#475569}.payment-modal{position:absolute;inset:0;z-index:10000;height:100%;width:100%;transition:all .3s cubic-bezier(.25,1,.5,1)}.payment-modal.visible{opacity:1}.payment-modal.invisible{opacity:0}@keyframes cr-spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}
|
|
2
|
+
/*$vite$:1*/`,document.head.appendChild(te);function re(t){var e,r,s="";if(typeof t=="string"||typeof t=="number")s+=t;else if(typeof t=="object")if(Array.isArray(t)){var n=t.length;for(e=0;e<n;e++)t[e]&&(r=re(t[e]))&&(s&&(s+=" "),s+=r)}else for(r in t)t[r]&&(s&&(s+=" "),s+=r);return s}function Oe(){for(var t,e,r=0,s="",n=arguments.length;r<n;r++)(t=arguments[r])&&(e=re(t))&&(s&&(s+=" "),s+=e);return s}class U extends Error{response;request;options;constructor(e,r,s){const n=e.status||e.status===0?e.status:"",i=e.statusText??"",o=`${n} ${i}`.trim(),a=o?`status code ${o}`:"an unknown error";super(`Request failed with ${a}: ${r.method} ${r.url}`),this.name="HTTPError",this.response=e,this.request=r,this.options=s}}class se extends Error{name="NonError";value;constructor(e){let r="Non-error value was thrown";try{typeof e=="string"?r=e:e&&typeof e=="object"&&"message"in e&&typeof e.message=="string"&&(r=e.message)}catch{}super(r),this.value=e}}class L extends Error{name="ForceRetryError";customDelay;code;customRequest;constructor(e){const r=e?.cause?e.cause instanceof Error?e.cause:new se(e.cause):void 0;super(e?.code?`Forced retry: ${e.code}`:"Forced retry",r?{cause:r}:void 0),this.customDelay=e?.delay,this.code=e?.code,this.customRequest=e?.request}}const ne=(()=>{let t=!1,e=!1;const r=typeof globalThis.ReadableStream=="function",s=typeof globalThis.Request=="function";if(r&&s)try{e=new globalThis.Request("https://empty.invalid",{body:new globalThis.ReadableStream,method:"POST",get duplex(){return t=!0,"half"}}).headers.has("Content-Type")}catch(n){if(n instanceof Error&&n.message==="unsupported BodyInit type")return!1;throw n}return t&&!e})(),ke=typeof globalThis.AbortController=="function",oe=typeof globalThis.AbortSignal=="function"&&typeof globalThis.AbortSignal.any=="function",Ne=typeof globalThis.ReadableStream=="function",qe=typeof globalThis.FormData=="function",ie=["get","post","put","patch","head","delete"],_e={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*",bytes:"*/*"},D=2147483647,xe=new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length,ae=Symbol("stop");class ce{options;constructor(e){this.options=e}}const Me=t=>new ce(t),je={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},Ue={next:!0},Le={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},De=t=>{if(!t)return 0;if(t instanceof FormData){let e=0;for(const[r,s]of t)e+=xe,e+=new TextEncoder().encode(`Content-Disposition: form-data; name="${r}"`).length,e+=typeof s=="string"?new TextEncoder().encode(s).length:s.size;return e}if(t instanceof Blob)return t.size;if(t instanceof ArrayBuffer)return t.byteLength;if(typeof t=="string")return new TextEncoder().encode(t).length;if(t instanceof URLSearchParams)return new TextEncoder().encode(t.toString()).length;if("byteLength"in t)return t.byteLength;if(typeof t=="object"&&t!==null)try{const e=JSON.stringify(t);return new TextEncoder().encode(e).length}catch{return 0}return 0},ue=(t,e,r)=>{let s,n=0;return t.pipeThrough(new TransformStream({transform(i,o){if(o.enqueue(i),s){n+=s.byteLength;let a=e===0?0:n/e;a>=1&&(a=1-Number.EPSILON),r?.({percent:a,totalBytes:Math.max(e,n),transferredBytes:n},s)}s=i},flush(){s&&(n+=s.byteLength,r?.({percent:1,totalBytes:Math.max(e,n),transferredBytes:n},s))}}))},Ie=(t,e)=>{if(!t.body)return t;if(t.status===204)return new Response(null,{status:t.status,statusText:t.statusText,headers:t.headers});const r=Math.max(0,Number(t.headers.get("content-length"))||0);return new Response(ue(t.body,r,e),{status:t.status,statusText:t.statusText,headers:t.headers})},Be=(t,e,r)=>{if(!t.body)return t;const s=De(r??t.body);return new Request(t,{duplex:"half",body:ue(t.body,s,e)})},S=t=>t!==null&&typeof t=="object",N=(...t)=>{for(const e of t)if((!S(e)||Array.isArray(e))&&e!==void 0)throw new TypeError("The `options` argument must be an object");return I({},...t)},le=(t={},e={})=>{const r=new globalThis.Headers(t),s=e instanceof globalThis.Headers,n=new globalThis.Headers(e);for(const[i,o]of n.entries())s&&o==="undefined"||o===void 0?r.delete(i):r.set(i,o);return r};function q(t,e,r){return Object.hasOwn(e,r)&&e[r]===void 0?[]:I(t[r]??[],e[r]??[])}const fe=(t={},e={})=>({beforeRequest:q(t,e,"beforeRequest"),beforeRetry:q(t,e,"beforeRetry"),afterResponse:q(t,e,"afterResponse"),beforeError:q(t,e,"beforeError")}),He=(t,e)=>{const r=new URLSearchParams;for(const s of[t,e])if(s!==void 0)if(s instanceof URLSearchParams)for(const[n,i]of s.entries())r.append(n,i);else if(Array.isArray(s))for(const n of s){if(!Array.isArray(n)||n.length!==2)throw new TypeError("Array search parameters must be provided in [[key, value], ...] format");r.append(String(n[0]),String(n[1]))}else if(S(s))for(const[n,i]of Object.entries(s))i!==void 0&&r.append(n,String(i));else{const n=new URLSearchParams(s);for(const[i,o]of n.entries())r.append(i,o)}return r},I=(...t)=>{let e={},r={},s={},n;const i=[];for(const o of t)if(Array.isArray(o))Array.isArray(e)||(e=[]),e=[...e,...o];else if(S(o)){for(let[a,c]of Object.entries(o)){if(a==="signal"&&c instanceof globalThis.AbortSignal){i.push(c);continue}if(a==="context"){if(c!=null&&(!S(c)||Array.isArray(c)))throw new TypeError("The `context` option must be an object");e={...e,context:c==null?{}:{...e.context,...c}};continue}if(a==="searchParams"){c==null?n=void 0:n=n===void 0?c:He(n,c);continue}S(c)&&a in e&&(c=I(e[a],c)),e={...e,[a]:c}}S(o.hooks)&&(s=fe(s,o.hooks),e.hooks=s),S(o.headers)&&(r=le(r,o.headers),e.headers=r)}return n!==void 0&&(e.searchParams=n),i.length>0&&(i.length===1?e.signal=i[0]:oe?e.signal=AbortSignal.any(i):e.signal=i.at(-1)),e.context===void 0&&(e.context={}),e},Ke=t=>ie.includes(t)?t.toUpperCase():t,he={limit:2,methods:["get","put","head","delete","options","trace"],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:[413,429,503],maxRetryAfter:Number.POSITIVE_INFINITY,backoffLimit:Number.POSITIVE_INFINITY,delay:t=>.3*2**(t-1)*1e3,jitter:void 0,retryOnTimeout:!1},$e=(t={})=>{if(typeof t=="number")return{...he,limit:t};if(t.methods&&!Array.isArray(t.methods))throw new Error("retry.methods must be an array");if(t.statusCodes&&!Array.isArray(t.statusCodes))throw new Error("retry.statusCodes must be an array");return{...he,...t}};class B extends Error{request;constructor(e){super(`Request timed out: ${e.method} ${e.url}`),this.name="TimeoutError",this.request=e}}async function We(t,e,r,s){return new Promise((n,i)=>{const o=setTimeout(()=>{r&&r.abort(),i(new B(t))},s.timeout);s.fetch(t,e).then(n).catch(i).then(()=>{clearTimeout(o)})})}async function ze(t,{signal:e}){return new Promise((r,s)=>{e&&(e.throwIfAborted(),e.addEventListener("abort",n,{once:!0}));function n(){clearTimeout(i),s(e.reason)}const i=setTimeout(()=>{e?.removeEventListener("abort",n),r()},t)})}const Ye=(t,e)=>{const r={};for(const s in e)Object.hasOwn(e,s)&&!(s in Le)&&!(s in je)&&(!(s in t)||s in Ue)&&(r[s]=e[s]);return r},Fe=t=>t===void 0?!1:Array.isArray(t)?t.length>0:t instanceof URLSearchParams?t.size>0:typeof t=="object"?Object.keys(t).length>0:typeof t=="string"?t.trim().length>0:!!t;function Ve(t){return t instanceof U||t?.name===U.name}function Je(t){return t instanceof B||t?.name===B.name}class C{static create(e,r){const s=new C(e,r),n=async()=>{if(typeof s.#e.timeout=="number"&&s.#e.timeout>D)throw new RangeError(`The \`timeout\` option cannot be greater than ${D}`);await Promise.resolve();let o=await s.#y();for(const a of s.#e.hooks.afterResponse){const c=s.#l(o.clone()),u=await a(s.request,s.#a(),c,{retryCount:s.#r});if(u instanceof globalThis.Response&&(o=u),u instanceof ce)throw await Promise.all([c.body?.cancel(),o.body?.cancel()]),new L(u.options)}if(s.#l(o),!o.ok&&(typeof s.#e.throwHttpErrors=="function"?s.#e.throwHttpErrors(o.status):s.#e.throwHttpErrors)){let a=new U(o,s.request,s.#a());for(const c of s.#e.hooks.beforeError)a=await c(a,{retryCount:s.#r});throw a}if(s.#e.onDownloadProgress){if(typeof s.#e.onDownloadProgress!="function")throw new TypeError("The `onDownloadProgress` option must be a function");if(!Ne)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return Ie(o.clone(),s.#e.onDownloadProgress)}return o},i=s.#f(n).finally(async()=>{const o=s.#o,a=[];o&&!o.bodyUsed&&a.push(o.body?.cancel()),s.request.bodyUsed||a.push(s.request.body?.cancel()),await Promise.all(a)});for(const[o,a]of Object.entries(_e))o==="bytes"&&typeof globalThis.Response?.prototype?.bytes!="function"||(i[o]=async()=>{s.request.headers.set("accept",s.request.headers.get("accept")||a);const c=await i;if(o==="json"){if(c.status===204)return"";const u=await c.text();return u===""?"":r.parseJson?r.parseJson(u):JSON.parse(u)}return c[o]()});return i}static#d(e){return e&&typeof e=="object"&&!Array.isArray(e)&&!(e instanceof URLSearchParams)?Object.fromEntries(Object.entries(e).filter(([,r])=>r!==void 0)):e}request;#s;#r=0;#t;#e;#o;#n;#i;constructor(e,r={}){if(this.#t=e,this.#e={...r,headers:le(this.#t.headers,r.headers),hooks:fe({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},r.hooks),method:Ke(r.method??this.#t.method??"GET"),prefixUrl:String(r.prefixUrl||""),retry:$e(r.retry),throwHttpErrors:r.throwHttpErrors??!0,timeout:r.timeout??1e4,fetch:r.fetch??globalThis.fetch.bind(globalThis),context:r.context??{}},typeof this.#t!="string"&&!(this.#t instanceof URL||this.#t instanceof globalThis.Request))throw new TypeError("`input` must be a string, URL, or Request");if(this.#e.prefixUrl&&typeof this.#t=="string"){if(this.#t.startsWith("/"))throw new Error("`input` must not begin with a slash when using `prefixUrl`");this.#e.prefixUrl.endsWith("/")||(this.#e.prefixUrl+="/"),this.#t=this.#e.prefixUrl+this.#t}ke&&oe&&(this.#n=this.#e.signal??this.#t.signal,this.#s=new globalThis.AbortController,this.#e.signal=this.#n?AbortSignal.any([this.#n,this.#s.signal]):this.#s.signal),ne&&(this.#e.duplex="half"),this.#e.json!==void 0&&(this.#e.body=this.#e.stringifyJson?.(this.#e.json)??JSON.stringify(this.#e.json),this.#e.headers.set("content-type",this.#e.headers.get("content-type")??"application/json"));const s=r.headers&&new globalThis.Headers(r.headers).has("content-type");if(this.#t instanceof globalThis.Request&&(qe&&this.#e.body instanceof globalThis.FormData||this.#e.body instanceof URLSearchParams)&&!s&&this.#e.headers.delete("content-type"),this.request=new globalThis.Request(this.#t,this.#e),Fe(this.#e.searchParams)){const i="?"+(typeof this.#e.searchParams=="string"?this.#e.searchParams.replace(/^\?/,""):new URLSearchParams(C.#d(this.#e.searchParams)).toString()),o=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,i);this.request=new globalThis.Request(o,this.#e)}if(this.#e.onUploadProgress){if(typeof this.#e.onUploadProgress!="function")throw new TypeError("The `onUploadProgress` option must be a function");if(!ne)throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");this.request=this.#h(this.request,this.#e.body??void 0)}}#c(){const e=this.#e.retry.delay(this.#r);let r=e;return this.#e.retry.jitter===!0?r=Math.random()*e:typeof this.#e.retry.jitter=="function"&&(r=this.#e.retry.jitter(e),(!Number.isFinite(r)||r<0)&&(r=e)),Math.min(this.#e.retry.backoffLimit,r)}async#p(e){if(this.#r++,this.#r>this.#e.retry.limit)throw e;const r=e instanceof Error?e:new se(e);if(r instanceof L)return r.customDelay??this.#c();if(!this.#e.retry.methods.includes(this.request.method.toLowerCase()))throw e;if(this.#e.retry.shouldRetry!==void 0){const s=await this.#e.retry.shouldRetry({error:r,retryCount:this.#r});if(s===!1)throw e;if(s===!0)return this.#c()}if(Je(e)&&!this.#e.retry.retryOnTimeout)throw e;if(Ve(e)){if(!this.#e.retry.statusCodes.includes(e.response.status))throw e;const s=e.response.headers.get("Retry-After")??e.response.headers.get("RateLimit-Reset")??e.response.headers.get("X-RateLimit-Retry-After")??e.response.headers.get("X-RateLimit-Reset")??e.response.headers.get("X-Rate-Limit-Reset");if(s&&this.#e.retry.afterStatusCodes.includes(e.response.status)){let n=Number(s)*1e3;Number.isNaN(n)?n=Date.parse(s)-Date.now():n>=Date.parse("2024-01-01")&&(n-=Date.now());const i=this.#e.retry.maxRetryAfter??n;return n<i?n:i}if(e.response.status===413)throw e}return this.#c()}#l(e){return this.#e.parseJson&&(e.json=async()=>this.#e.parseJson(await e.text())),e}async#f(e){try{return await e()}catch(r){const s=Math.min(await this.#p(r),D);if(this.#r<1)throw r;if(await ze(s,this.#n?{signal:this.#n}:{}),r instanceof L&&r.customRequest){const n=this.#e.signal?new globalThis.Request(r.customRequest,{signal:this.#e.signal}):new globalThis.Request(r.customRequest);this.#u(n)}for(const n of this.#e.hooks.beforeRetry){const i=await n({request:this.request,options:this.#a(),error:r,retryCount:this.#r});if(i instanceof globalThis.Request){this.#u(i);break}if(i instanceof globalThis.Response)return i;if(i===ae)return}return this.#f(e)}}async#y(){this.#s?.signal.aborted&&(this.#s=new globalThis.AbortController,this.#e.signal=this.#n?AbortSignal.any([this.#n,this.#s.signal]):this.#s.signal,this.request=new globalThis.Request(this.request,{signal:this.#e.signal}));for(const r of this.#e.hooks.beforeRequest){const s=await r(this.request,this.#a(),{retryCount:this.#r});if(s instanceof Response)return s;if(s instanceof globalThis.Request){this.#u(s);break}}const e=Ye(this.request,this.#e);return this.#o=this.request,this.request=this.#o.clone(),this.#e.timeout===!1?this.#e.fetch(this.#o,e):We(this.#o,e,this.#s,this.#e)}#a(){if(!this.#i){const{hooks:e,...r}=this.#e;this.#i=Object.freeze(r)}return this.#i}#u(e){this.#i=void 0,this.request=this.#h(e)}#h(e,r){return!this.#e.onUploadProgress||!e.body?e:Be(e,this.#e.onUploadProgress,r??this.#e.body??void 0)}}/*! MIT License © Sindre Sorhus */const H=t=>{const e=(r,s)=>C.create(r,N(t,s));for(const r of ie)e[r]=(s,n)=>C.create(s,N(t,n,{method:r}));return e.create=r=>H(N(r)),e.extend=r=>(typeof r=="function"&&(r=r(t??{})),H(N(t,r))),e.stop=ae,e.retry=Me,e},Ge=H();var de=(t=>(t.ARBITRUM="ARBITRUM_MAINNET",t.ARBITRUM_TESTNET="ARBITRUM_TESTNET",t.AVALANCHE="AVALANCHE_MAINNET",t.AVALANCHE_TESTNET="AVALANCHE_TESTNET",t.BASE="BASE_MAINNET",t.BASE_TESTNET="BASE_TESTNET",t.BSC="BSC_MAINNET",t.ETHEREUM="ETHEREUM_MAINNET",t.ETHEREUM_TESTNET="ETHEREUM_TESTNET",t.STARKNET="STARKNET_MAINNET",t))(de||{}),pe=(t=>(t.USDC="USDC",t))(pe||{}),K=(t=>(t.PRODUCTION="production",t.STAGING="staging",t))(K||{});class f{constructor({api_key:e,env:r}){this.api_key=e,this.jwt="",this.env=r??K.PRODUCTION}static async config(e){if(!f.app){if(!e)throw new Error("Please provide an api_key");f.app=new f(e)}return e&&(f.app.api_key=e.api_key,e.env!==void 0&&(f.app.env=e.env),await this.updateJWT(),setInterval(this.updateJWT.bind(this),1500*1e3)),f.app}static async updateJWT(){try{const e=await(await fetch(this.getBaseUrl()+"/client/api-keys/session-token",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({apiKey:f.app.api_key})})).json();this.app.jwt=e.token}catch{}}static getApiKey(){if(!f.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return f.app.api_key}static getSessionKey(){return f.app.jwt}static getEnv(){if(!f.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return f.app.env==="internal"?"staging":f.app.env}static getBaseUrl(){if(!f.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");switch(f.app.env){case"production":return"https://api.chainrails.io/api/v1";case"staging":return"https://dev.chainrails.io/api/v1";case"internal":return"https://dev.chainrails.io/api/v1";default:return"https://api.chainrails.io/api/v1"}}static getPayModalUrl(e,r,s,n){if(!f.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");const i=f.app.env==="internal"?"https://chainrails-frontend-git-staging-horus-labs.vercel.app":"https://app.chainrails.io",o=n&&n>0?"/pay/":"/deposit/",a=`_chain_/${e}/_token_/${r}/_to_/${s}${n?"/_amount_/"+n*100:""}`;return i+o+a}}let $=null;function Xe(){$=Ge.create({prefixUrl:f.getBaseUrl(),headers:{"Content-Type":"application/json"},hooks:{beforeRequest:[t=>{const e=f.getSessionKey();t.headers.set("Authorization",`Bearer ${e}`)}],afterResponse:[(t,e,r)=>r]},retry:{limit:2}})}function m(){return $||Xe(),$}class Ze{async getById(e){return await m().get("intents/"+e).json()}async getForSender(e){return await m().get("intents/user/"+e).json()}async getForAddress(e){return await m().get("intents/address/"+e).json()}async getAll(e){return await m().get("intents",{searchParams:e}).json()}async create(e){return await m().post("intents",{json:e}).json()}async update(e,r){return await m().post("intents",{json:r}).json()}async triggerProcessing(e){return await m().post(`intents/${e}/trigger-processing`).json()}}class Qe{async getFromSpecificBridge(e){return await m().get("quotes/single",{searchParams:e}).json()}async getFromAllBridges(e){return await m().get("quotes/multiple",{searchParams:e}).json()}async getBestAcrossBridges(e){return await m().get("quotes/best",{searchParams:e}).json()}async getAll(e){return await m().get("quotes/multi-source",{searchParams:e}).json()}}class et{async getOptimalRoutes(e){return await m().get("router/optimal-route",{searchParams:e}).json()}async getAllSupportedBridges(){return await m().get("router/supported-bridges/all").json()}async getSupportedBridges(e){return await m().get("router/supported-bridges/route",{searchParams:e}).json()}async getSupportedRoutes(e,r){return await m().get("router/supported-bridges/bridge/"+e,{searchParams:r}).json()}}class tt{async getSupported(e){return await m().get("chains",{searchParams:e}).json()}}class rt{async getClientInfo(){return await m().get("client/auth/client-info").json()}}const st={router:new et,quotes:new Qe,intents:new Ze,chains:new tt,client:new rt};function nt(t){const{to:e,token:r,chain:s,amount:n,isOpen:i,close:o,complete:a,cancel:c,chainSelected:u,intentCreated:p,...T}=t,[y,R]=g.useState(!0),E=g.useRef(null);g.useEffect(()=>{l();const h=document.body.style.overflow;i?(document.body.style.overflow="hidden",document.body.style.overflow="hidden"):document.body.style.overflow=h||"";const d=w=>{w.data==="closed"&&c(),w.data==="completed"&&a(),w.data==="chainSelected"&&u(),w.data==="intentCreated"&&p()};return window.addEventListener("message",d),()=>{document.body.style.overflow=h||"",window.removeEventListener("message",d)}},[i,c,a,u,p]);function ee(){R(!1),l()}function l(){const h={type:"apiKey",apiKey:f.getApiKey(),environment:f.getEnv()||K.PRODUCTION};E.current?.contentWindow?.postMessage(h,"https://app.chainrails.io"),E.current?.contentWindow?.postMessage(h,"https://chainrails-frontend-git-staging-horus-labs.vercel.app")}return v.jsxs("div",{...T,className:Oe("payment-modal-wrapper",y?"loading":"not-loading",i?"open":"closed"),children:[y&&v.jsx("div",{role:"status",className:"payment-modal-loader",children:v.jsxs("svg",{"aria-hidden":"true",className:"icon",viewBox:"0 0 100 101",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[v.jsx("path",{d:"M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",fill:"currentColor"}),v.jsx("path",{d:"M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",fill:"currentFill"})]})}),v.jsx("iframe",{allow:"clipboard-read *; clipboard-write *",src:f.getPayModalUrl(s,r,e,n),onLoad:ee,className:`payment-modal ${y?"invisible":"visible"}`,"data-id":n,ref:E})]})}function ot(t){const{onCancel:e,onSuccess:r,onChainSelect:s,onIntentCreate:n,...i}=t,[o,a]=g.useState(!1);function c(){a(!0)}function u(){a(!1)}function p(){u(),e?.()}function T(){window.setTimeout(u,2e3),r?.()}function y(){s?.()}function R(){n?.()}return{open:c,close:u,complete:T,cancel:p,chainSelected:y,intentCreated:R,isOpen:o,...i}}const it=Symbol(),W=Symbol(),O="a",ye="f",ge="p",me="c",we="t",z="h",k="w",Y="o",F="k";let at=(t,e)=>new Proxy(t,e);const V=Object.getPrototypeOf,J=new WeakMap,be=t=>t&&(J.has(t)?J.get(t):V(t)===Object.prototype||V(t)===Array.prototype),_=t=>typeof t=="object"&&t!==null,ct=t=>Object.values(Object.getOwnPropertyDescriptors(t)).some(e=>!e.configurable&&!e.writable),ut=t=>{if(Array.isArray(t))return Array.from(t);const e=Object.getOwnPropertyDescriptors(t);return Object.values(e).forEach(r=>{r.configurable=!0}),Object.create(V(t),e)},lt=(t,e)=>{const r={[ye]:e};let s=!1;const n=(a,c)=>{if(!s){let u=r[O].get(t);if(u||(u={},r[O].set(t,u)),a===k)u[k]=!0;else{let p=u[a];p||(p=new Set,u[a]=p),p.add(c)}}},i=()=>{s=!0,r[O].delete(t)},o={get(a,c){return c===W?t:(n(F,c),Te(Reflect.get(a,c),r[O],r[me],r[we]))},has(a,c){return c===it?(i(),!0):(n(z,c),Reflect.has(a,c))},getOwnPropertyDescriptor(a,c){return n(Y,c),Reflect.getOwnPropertyDescriptor(a,c)},ownKeys(a){return n(k),Reflect.ownKeys(a)}};return e&&(o.set=o.deleteProperty=()=>!1),[o,r]},G=t=>t[W]||t,Te=(t,e,r,s)=>{if(!be(t))return t;let n=s&&s.get(t);if(!n){const c=G(t);ct(c)?n=[c,ut(c)]:n=[c],s?.set(t,n)}const[i,o]=n;let a=r&&r.get(i);return(!a||a[1][ye]!==!!o)&&(a=lt(i,!!o),a[1][ge]=at(o||i,a[0]),r&&r.set(i,a)),a[1][O]=e,a[1][me]=r,a[1][we]=s,a[1][ge]},ft=(t,e)=>{const r=Reflect.ownKeys(t),s=Reflect.ownKeys(e);return r.length!==s.length||r.some((n,i)=>n!==s[i])},Re=(t,e,r,s,n=Object.is)=>{if(n(t,e))return!1;if(!_(t)||!_(e))return!0;const i=r.get(G(t));if(!i)return!0;if(s){if(s.get(t)===e)return!1;s.set(t,e)}let o=null;for(const a of i[z]||[])if(o=Reflect.has(t,a)!==Reflect.has(e,a),o)return o;if(i[k]===!0){if(o=ft(t,e),o)return o}else for(const a of i[Y]||[]){const c=!!Reflect.getOwnPropertyDescriptor(t,a),u=!!Reflect.getOwnPropertyDescriptor(e,a);if(o=c!==u,o)return o}for(const a of i[F]||[])if(o=Re(t[a],e[a],r,s,n),o)return o;if(o===null)throw new Error("invalid used");return o},ht=t=>be(t)&&t[W]||null,Ee=(t,e=!0)=>{J.set(t,e)},dt=(t,e,r)=>{const s=[],n=new WeakSet,i=(o,a)=>{var c,u,p;if(n.has(o))return;_(o)&&n.add(o);const T=_(o)&&e.get(G(o));if(T){if((c=T[z])===null||c===void 0||c.forEach(y=>{const R=`:has(${String(y)})`;s.push(a?[...a,R]:[R])}),T[k]===!0){const y=":ownKeys";s.push(a?[...a,y]:[y])}else(u=T[Y])===null||u===void 0||u.forEach(y=>{const R=`:hasOwn(${String(y)})`;s.push(a?[...a,R]:[R])});(p=T[F])===null||p===void 0||p.forEach(y=>{"value"in(Object.getOwnPropertyDescriptor(o,y)||{})&&i(o[y],a?[...a,y]:[y])})}else a&&s.push(a)};return i(t),s},x={},X=t=>typeof t=="object"&&t!==null,pt=t=>X(t)&&!Z.has(t)&&(Array.isArray(t)||!(Symbol.iterator in t))&&!(t instanceof WeakMap)&&!(t instanceof WeakSet)&&!(t instanceof Error)&&!(t instanceof Number)&&!(t instanceof Date)&&!(t instanceof String)&&!(t instanceof RegExp)&&!(t instanceof ArrayBuffer)&&!(t instanceof Promise),Se=(t,e)=>{const r=Pe.get(t);if(r?.[0]===e)return r[1];const s=Array.isArray(t)?[]:Object.create(Object.getPrototypeOf(t));return Ee(s,!0),Pe.set(t,[e,s]),Reflect.ownKeys(t).forEach(n=>{if(Object.getOwnPropertyDescriptor(s,n))return;const i=Reflect.get(t,n),{enumerable:o}=Reflect.getOwnPropertyDescriptor(t,n),a={value:i,enumerable:o,configurable:!0};if(Z.has(i))Ee(i,!1);else if(P.has(i)){const[c,u]=P.get(i);a.value=Se(c,u())}Object.defineProperty(s,n,a)}),Object.preventExtensions(s)},yt=(t,e,r,s)=>({deleteProperty(n,i){const o=Reflect.get(n,i);r(i);const a=Reflect.deleteProperty(n,i);return a&&s(["delete",[i],o]),a},set(n,i,o,a){const c=!t()&&Reflect.has(n,i),u=Reflect.get(n,i,a);if(c&&(Ae(u,o)||M.has(o)&&Ae(u,M.get(o))))return!0;r(i),X(o)&&(o=ht(o)||o);const p=!P.has(o)&&mt(o)?ve(o):o;return e(i,p),Reflect.set(n,i,p,a),s(["set",[i],o,u]),!0}}),P=new WeakMap,Z=new WeakSet,Pe=new WeakMap,Q=[1],M=new WeakMap;let Ae=Object.is,gt=(t,e)=>new Proxy(t,e),mt=pt,wt=Se,bt=yt;function ve(t={}){if(!X(t))throw new Error("object required");const e=M.get(t);if(e)return e;let r=Q[0];const s=new Set,n=(l,h=++Q[0])=>{r!==h&&(i=r=h,s.forEach(d=>d(l,h)))};let i=r;const o=(l=Q[0])=>(i!==l&&(i=l,c.forEach(([h])=>{const d=h[1](l);d>r&&(r=d)})),r),a=l=>(h,d)=>{const w=[...h];w[1]=[l,...w[1]],n(w,d)},c=new Map,u=(l,h)=>{const d=!Z.has(h)&&P.get(h);if(d){if((x?"production":void 0)!=="production"&&c.has(l))throw new Error("prop listener already exists");if(s.size){const w=d[2](a(l));c.set(l,[d,w])}else c.set(l,[d])}},p=l=>{var h;const d=c.get(l);d&&(c.delete(l),(h=d[1])==null||h.call(d))},T=l=>(s.add(l),s.size===1&&c.forEach(([d,w],j)=>{if((x?"production":void 0)!=="production"&&w)throw new Error("remove already exists");const vt=d[2](a(j));c.set(j,[d,vt])}),()=>{s.delete(l),s.size===0&&c.forEach(([d,w],j)=>{w&&(w(),c.set(j,[d]))})});let y=!0;const R=bt(()=>y,u,p,n),E=gt(t,R);M.set(t,E);const ee=[t,o,T];return P.set(E,ee),Reflect.ownKeys(t).forEach(l=>{const h=Object.getOwnPropertyDescriptor(t,l);"value"in h&&h.writable&&(E[l]=t[l])}),y=!1,E}function Tt(t,e,r){const s=P.get(t);(x?"production":void 0)!=="production"&&!s&&console.warn("Please use proxy object");let n;const i=[],o=s[2];let a=!1;const u=o(p=>{i.push(p),n||(n=Promise.resolve().then(()=>{n=void 0,a&&e(i.splice(0))}))});return a=!0,()=>{a=!1,u()}}function Ce(t){const e=P.get(t);(x?"production":void 0)!=="production"&&!e&&console.warn("Please use proxy object");const[r,s]=e;return wt(r,s())}const Rt={},Et=(t,e)=>{const r=g.useRef(void 0);g.useEffect(()=>{r.current=dt(t,e)}),g.useDebugValue(r.current)},St=new WeakMap;function Pt(t,e){const s=g.useMemo(()=>t&&new WeakMap,[t]),n=g.useRef(void 0);let i=!0;const o=g.useSyncExternalStore(g.useCallback(c=>{const u=Tt(t,c);return c(),u},[t,void 0]),()=>{const c=Ce(t);try{if(!i&&n.current&&!Re(n.current,c,s,new WeakMap))return n.current}catch{}return c},()=>Ce(t));i=!1,g.useLayoutEffect(()=>{n.current=o}),(Rt?"production":void 0)!=="production"&&Et(o,s);const a=g.useMemo(()=>new WeakMap,[]);return Te(o,s,a,St)}const A=ve({data:null,isPending:!1,error:null});function At({url:t,params:e,callbacks:r}){const s=Pt(A),n=()=>{A.isPending=!0,A.error=null,fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({amount:e?.amount})}).then(i=>i.json()).then(i=>{A.data=i,r?.onSuccess?.(),A.isPending=!1}).catch(i=>{A.error=i?.toString(),r?.onError?.(),A.isPending=!1})};return g.useEffect(n,[]),{...s,refetch:n}}b.Chainrails=f,b.PaymentModal=nt,b.chains=de,b.crapi=st,b.tokens=pe,b.useGetSessionToken=At,b.usePaymentModal=ot,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface useGetSessionTokenCallBacks {
|
|
2
|
+
onError?: () => void;
|
|
3
|
+
onSuccess?: () => void;
|
|
4
|
+
onRefetch?: () => void;
|
|
5
|
+
}
|
|
6
|
+
interface useGetSessionTokenProps {
|
|
7
|
+
url: string;
|
|
8
|
+
params?: {
|
|
9
|
+
amount?: string;
|
|
10
|
+
};
|
|
11
|
+
callbacks?: useGetSessionTokenCallBacks;
|
|
12
|
+
}
|
|
13
|
+
export declare function useGetSessionToken({ url, params, callbacks }: useGetSessionTokenProps): {
|
|
14
|
+
refetch: () => void;
|
|
15
|
+
data: {
|
|
16
|
+
readonly sessionToken: string;
|
|
17
|
+
readonly sessionId: string;
|
|
18
|
+
readonly expiresAt: string;
|
|
19
|
+
} | null;
|
|
20
|
+
error: string | null;
|
|
21
|
+
isPending: boolean;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=useGetSessionToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetSessionToken.d.ts","sourceRoot":"","sources":["../../src/hooks/useGetSessionToken.tsx"],"names":[],"mappings":"AAmBA,UAAU,2BAA2B;IACnC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,UAAU,uBAAuB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,SAAS,CAAC,EAAE,2BAA2B,CAAC;CACzC;AAED,wBAAgB,kBAAkB,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,uBAAuB;;;+BA7BtE,MAAM;4BACT,MAAM;4BACN,MAAM;;WAKV,MAAM,GAAG,IAAI;eACT,OAAO;EAuDnB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "./PaymentModal/index.css";
|
|
2
2
|
export { PaymentModal } from "./PaymentModal";
|
|
3
3
|
export { usePaymentModal } from "./hooks/usePaymentModal";
|
|
4
|
+
export { useGetSessionToken } from "./hooks/useGetSessionToken";
|
|
4
5
|
export { crapi, chains, tokens, Chainrails } from "@chainrails/sdk";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,0BAA0B,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|