@spicenet-io/spiceflow-ui 3.1.19 → 3.1.21
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/auth-dynamic.js +1 -1
- package/dist/auth-privy.js +1 -1
- package/dist/auth-starknet.cjs.js +1 -1
- package/dist/auth-starknet.js +1 -1
- package/dist/index.cjs.js +11 -11
- package/dist/index.js +9 -9
- package/dist/{providerWallet-DZdb5rlK.js → providerWallet-DeNDXTJA.js} +1 -1
- package/dist/useSpiceBrand-CttloC0D.js +2 -0
- package/dist/useSpiceBrand-DyEkEu8z.js +2 -0
- package/dist/utils/relayer/index.d.ts +19 -0
- package/package.json +1 -1
- package/dist/useSpiceBrand-BLSt3hs4.js +0 -2
- package/dist/useSpiceBrand-ib5fdnfb.js +0 -2
- /package/dist/{Button-BJ2OiyLY.js → Button-D5zwqrrP.js} +0 -0
- /package/dist/{index-C1DEtFS6.js → index-DJQ17ocQ.js} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{createWalletClient as l,custom as d}from"viem";import{g as c}from"./index-
|
|
2
|
+
import{createWalletClient as l,custom as d}from"viem";import{g as c}from"./index-DJQ17ocQ.js";const o=t=>{if(!t)return!1;const e=t.connector;if(!e)return!1;if(e.isEmbeddedWallet===!0)return!0;const r=(e.key||e.connectorKey||"").toLowerCase();if(r.includes("embedded")||r.includes("turnkey"))return!0;const n=(e.name||t.walletName||"").toLowerCase();return!!(n.includes("embedded")||n.includes("turnkey"))},u=t=>(t?.connectedWallets||[]).find(e=>o(e))||(o(t?.primaryWallet)?t.primaryWallet:null),f=t=>(t?.connectedWallets||[]).find(e=>e?.address&&e?.connector&&!o(e))||null,i=async(t,e)=>{if(!t?.address)throw new Error("Wallet not available");if(typeof t.getWalletClient=="function"){const r=e===void 0?[void 0]:[String(e),e,void 0];let n=null;for(const s of r)try{const a=await t.getWalletClient(s);if(a)return a}catch(a){n=a}if(n)throw n}if(typeof t.getEthereumProvider=="function"){const r=await t.getEthereumProvider(),n=e?c(e)?.viemChain:void 0;return l({account:t.address,chain:n,transport:d(r)})}throw new Error("Wallet client not available")},m=async(t,e)=>{if(!t?.address)throw new Error("Wallet not available");if(typeof t.getEthereumProvider=="function")return t.getEthereumProvider();const r=await i(t,e);return{request:n=>r.request(n)}},y=(t,e)=>({address:t?.address||e.address,chainId:Number(t?.chainId??e.chainId),contractAddress:t?.contractAddress||t?.delegate||e.contractAddress,nonce:BigInt(t?.nonce??e.nonce),r:t?.r,s:t?.s,yParity:(()=>{if(typeof t?.yParity=="number")return t.yParity;const r=Number(t?.v??27);return Number.isFinite(r)?r>=27?r-27:r:0})()});export{m as a,f as b,i as c,u as g,y as n};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{createContext as R,useEffect as S,useState as _,useCallback as N,useContext as F,useMemo as L}from"react";import{jsx as b}from"react/jsx-runtime";import{isNativeToken as j,getTokenByAddress as M,getChainIdsByNetwork as Y}from"@spicenet-io/spiceflow-core";import{a as E,s as T}from"./index-DJQ17ocQ.js";import{formatUnits as $}from"viem";import{c as H}from"./Button-D5zwqrrP.js";class d extends Error{constructor(t,r,e={}){super(r),this.code=t,this.context=e,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,d)}}function J(o){return o instanceof d}const v=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",I="__SPICEFLOW_RELAYER_API_URL__";function q(o,t){const r=t.match(/Output amount (\d+) is insufficient after fees (\d+) on chain (\d+)/);if(!r)return t;const[,e,a,s]=r,c=Number(s),n=BigInt(e),i=BigInt(a);let f;for(const u of o.intents){const x=u.chainBatches.find(A=>A.chainId===c);if(x){f=x;break}}const l=f?.tokenTransfers.find(u=>u.from==="solver"&&u.to.toLowerCase()===o.user.toLowerCase()&&!j(u.token));if(!l)return`Amount is too small to cover the estimated fee on ${E(c)}.`;const p=M(l.token,c),h=p?.decimals??18,g=p?.symbol??"tokens",w=$(n,h),y=$(i,h);return`Amount is too small to cover the estimated fee on ${E(c)}. Amount: ${w} ${g}. Estimated fee: ${y} ${g}.`}function W(o){return o.intents.some(t=>t.batches.some(r=>BigInt(r.netOutput)<BigInt(r.grossOutput)))}function D(){if(typeof globalThis>"u")return;const o=globalThis[I];return typeof o=="string"&&o.length>0?o:void 0}class G{constructor(){this.baseUrl=v}setBaseUrl(t){this.baseUrl=t,typeof globalThis<"u"&&(globalThis[I]=t)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return D()||this.baseUrl}async createAction(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(e,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const e=await r.text();throw new d("RELAYER_ERROR",`Relayer API error: ${r.status} - ${e}`,{httpStatus:r.status,responseBody:e,endpoint:"/actions"})}return await r.json()}async estimateActionFees(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions/fees/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(a,s)=>typeof s=="bigint"?s.toString():s)}),e=await r.json();if(!r.ok||!e.success||!e.data?.feeEstimate){const a=e.error?.message||`Relayer fee estimate error: ${r.status}`,s=q(t,a);throw new d("RELAYER_ERROR",s,{httpStatus:r.status,responseBody:JSON.stringify(e),endpoint:"/actions/fees/estimate"})}return e.data.feeEstimate}async estimateBatchGas(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions/gas/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(a,s)=>typeof s=="bigint"?s.toString():s)}),e=await r.json();if(!r.ok||!e.success||!e.data?.gasFee){const a=e.error?.message||`Relayer gas estimate error: ${r.status}`;throw new d("RELAYER_ERROR",a,{httpStatus:r.status,responseBody:JSON.stringify(e),endpoint:"/actions/gas/estimate"})}return{gasFee:BigInt(e.data.gasFee),gasQuoteSource:e.data.gasQuoteSource}}async executeStep(t,r,e,a){const s=`${this.getEffectiveBaseUrl()}/actions/${t}/intents/${r}/steps/${e}`,c=fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});let n;try{n=await Promise.race([c,new Promise((i,f)=>setTimeout(()=>f(new d("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:t,intentIndex:r,stepIndex:e,endpoint:`/actions/${t}/intents/${r}/steps/${e}`})),1e4))])}catch(i){throw i}if(!n.ok){const i=await n.text();throw new d("RELAYER_EXECUTE_ERROR",`Execute step error: ${n.status} - ${i}`,{httpStatus:n.status,responseBody:i,endpoint:`/actions/${t}/intents/${r}/steps/${e}`,actionId:t})}return{success:!0,transactionHash:(await n.json()).transactionHash}}async checkStepStatus(t,r){const e=t.split("/");let a="";if(e.length>=2){const n=e[0],i=e[1];a=`${this.getEffectiveBaseUrl()}/actions/${n}/intents/${i}/steps/${r}`}else a=`${this.getEffectiveBaseUrl()}/actions/${t}/intents/0/steps/${r}`;const s=await fetch(a);if(!s.ok)throw new d("RELAYER_STATUS_ERROR",`Intent step status check failed: ${s.status}`,{httpStatus:s.status,endpoint:a,intentId:t});const c=await s.json();return{success:!0,data:{status:c.status==="error"?"reverted":c.status,transactionHash:c.txid}}}async requestSpiceUsdAirdrop(t){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop/${t.chainId}/spiceUsd`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wallet:t.address})}),e=await r.json().catch(()=>({}));if(!r.ok){const a=e&&(e.error||e.message)||"Failed to request airdrop";return{success:!1,errorMessage:String(a)}}return e&&typeof e.error=="string"?{success:!1,errorMessage:e.error}:e&&(e.txHash||e.amount)?{success:!0,txHash:e.txHash,amount:e.amount}:{success:!0}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async requestAirdrop(t){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:t.tag||"default",airdrops:[{chainId:t.chainId,tokenId:t.tokenId,wallet:t.wallet,amount:t.amount||"0.0001"}]})}),e=await r.json().catch(()=>({}));if(!r.ok){const s=e?.message||e?.errors?.[0]?.error||"Failed to request airdrop";return{success:!1,errorMessage:String(s)}}const a=e?.airdrops?.[t.chainId]?.[t.tokenId]?.txHash;return e.errors&&e.errors.length>0?{success:!1,errorMessage:e.errors[0].error}:{success:!0,txHash:a}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async createWallet(t,r){const e=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok){const a=await e.text();throw new d("RELAYER_ERROR",`Create wallet error: ${e.status} - ${a}`,{httpStatus:e.status,endpoint:`/wallets/${t}`})}return e.json()}async getWallet(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${t}`);if(!r.ok){const e=await r.text();throw new d("RELAYER_ERROR",`Get wallet error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:`/wallets/${t}`})}return r.json()}async createWithdrawal(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(e,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const e=await r.text();throw new d("RELAYER_ERROR",`Create withdrawal error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:"/withdrawals"})}return r.json()}async getWithdrawal(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${t}`);if(!r.ok){const e=await r.text();throw new d("RELAYER_ERROR",`Get withdrawal error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:`/withdrawals/${t}`})}return r.json()}async getRollupTimestamp(){const t=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!t.ok)throw new d("RELAYER_ERROR",`Get rollup timestamp error: ${t.status}`,{httpStatus:t.status,endpoint:"/time"});return t.json()}}const B=new G,X=(o,t)=>{const r=a=>t?t(a):E(a),e=[];return o.forEach((a,s)=>{const c=a.calls&&a.calls.length>0,n=a.tokenTransfers&&a.tokenTransfers.length>0;if(c||n){const i={stepId:s,status:s===0?"processing":"pending",chainId:a.chainId,chainName:r(a.chainId),description:"Processing transaction"};e.push(i)}}),e},k="spiceflow-mode",C=()=>{if(typeof window>"u")return null;try{const o=window.localStorage.getItem(k);return o==="embedded"?"7702":o==="external"?"ondemand":null}catch{return null}},Q=o=>{if(!(typeof window>"u"))try{window.localStorage.setItem(k,o==="7702"?"embedded":"external")}catch{}},z=()=>C()!==null,O=R(null),U=R(null),K=({children:o,provider:t,supportedChainIds:r,network:e="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:c,appName:n="Spicenet",apiUrl:i,theme:f,rpcOverrides:l})=>{S(()=>{if(!i)return;const u=B.getBaseUrl();return B.setBaseUrl(i),()=>B.setBaseUrl(u)},[i]),S(()=>(T(l),()=>T(void 0)),[l]);const p=r??Y(e),h=f??null,[g,w]=_(()=>C()??a),y=N(u=>{w(u),Q(u)},[]);return b(O.Provider,{value:h,children:b(U.Provider,{value:{provider:t,supportedChainIds:p,skipFlow:s,mode:g,setMode:y,network:e,nativeChainId:c,appName:n,apiUrl:i,rpcOverrides:l},children:o})})};function m(o,t){const r=o.replace("#",""),e=Math.max(0,Math.round(parseInt(r.substring(0,2),16)*(1-t))),a=Math.max(0,Math.round(parseInt(r.substring(2,4),16)*(1-t))),s=Math.max(0,Math.round(parseInt(r.substring(4,6),16)*(1-t)));return`#${e.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function V(o,t){return{shell:t?.shell??"#141414",shellBorder:t?.shellBorder??m(t?.shell??"#141414",.35),shellInnerBorder:t?.shellInnerBorder??m(t?.shell??"#141414",.55),cardBg:t?.cardBg??"#1e1e1e",inputBg:t?.inputBg??"#171717",hoverBg:t?.hoverBg??"#2a2a2a",textPrimary:t?.textPrimary??"#ffffff",textSecondary:t?.textSecondary??"#888888",inputText:t?.inputText??"#e0e0e0",inputPlaceholder:t?.inputPlaceholder??"#555555",cardBorder:t?.cardBorder??"rgba(255,255,255,0.08)",inputBorder:t?.inputBorder??"rgba(255,255,255,0.10)",buttonBorder:t?.buttonBorder??"rgba(255,255,255,0.12)",successBg:t?.successBg??"#0a1f18",successBorder:t?.successBorder??"#1a4a3a",successText:t?.successText??"#6ee7b7",warningBg:t?.warningBg??"#1f1a0d",warningBorder:t?.warningBorder??"#4a3820",warningText:t?.warningText??"#fbbf24",errorBg:t?.errorBg??"#1f0d0d",errorBorder:t?.errorBorder??"#4a2020",errorText:t?.errorText??"#f87171",infoBg:t?.infoBg??"#0d1325",infoBorder:t?.infoBorder??"#2a3a5a",infoText:t?.infoText??"#60a5fa"}}function Z(o){return{shell:"#ffffff",shellBorder:"#E9E9E9",shellInnerBorder:"#D5D5D5",cardBg:"#f9fafb",inputBg:"#ffffff",hoverBg:"#f3f4f6",textPrimary:"#111827",textSecondary:"#6b7280",inputText:"#111827",inputPlaceholder:"#9ca3af",cardBorder:"#E0E0E0",inputBorder:"#d1d5db",buttonBorder:"#0e0d0b",successBg:"#d1fae5",successBorder:"#6ee7b7",successText:"#065f46",warningBg:"#fef3c7",warningBorder:"#fcd34d",warningText:"#92400e",errorBg:"#fee2e2",errorBorder:"#fca5a5",errorText:"#dc2626",infoBg:"#dbeafe",infoBorder:"#93c5fd",infoText:"#1e40af"}}function P(o,t){const r=t?{...o,...t}:o,e=r.dark??!1,a=r.primaryColor,s=r.shell??(e?"#141414":"#ffffff");return{primaryColor:a,dark:e,fontFamily:r.fontFamily??'"Helvetica Neue", sans-serif',appName:r.appName??"Spicenet",logo:r.logo,borderRadius:r.borderRadius??"8px",shell:s,shellBorder:m(s,e?.35:.085),shellInnerBorder:m(s,e?.55:.165),card:r.card??(e?"#1e1e1e":"#f9fafb"),input:e?"#171717":"#ffffff",hover:e?"#2a2a2a":"#f3f4f6",text:r.text??(e?"#ffffff":"#111827"),textMuted:r.textMuted??(e?"#888888":"#6b7280"),inputText:e?"#e0e0e0":"#111827",inputPlaceholder:e?"#555555":"#9ca3af",border:r.border??(e?"rgba(255,255,255,0.08)":"#E0E0E0"),inputBorder:e?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:e?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:e?"#0a1f18":"#d1fae5",successBorder:e?"#1a4a3a":"#6ee7b7",successText:e?"#6ee7b7":"#065f46",warningBg:e?"#1f1a0d":"#fef3c7",warningBorder:e?"#4a3820":"#fcd34d",warningText:e?"#fbbf24":"#92400e",errorBg:e?"#1f0d0d":"#fee2e2",errorBorder:e?"#4a2020":"#fca5a5",errorText:e?"#f87171":"#dc2626",infoBg:e?"#0d1325":"#dbeafe",infoBorder:e?"#2a3a5a":"#93c5fd",infoText:e?"#60a5fa":"#1e40af"}}function ee(o,t){const r=F(O)??void 0;return L(()=>{const e=r??{primaryColor:"#EA4B4B"},a={...o?.primaryColor?{primaryColor:o.primaryColor}:{},...o?.fontFamily?{fontFamily:o.fontFamily}:{},...t!==void 0?{dark:t}:{}},s=P(e,a),{dark:c,primaryColor:n,appName:i}=s,f=H(c?"dark":"light"),l={...f,colors:{...f.colors,primary:n,primaryHover:`${n}dd`},typography:{...f.typography,fontFamily:s.fontFamily}},p={shell:s.shell,shellBorder:s.shellBorder,shellInnerBorder:s.shellInnerBorder,cardBg:s.card,inputBg:s.input,hoverBg:s.hover,textPrimary:s.text,textSecondary:s.textMuted,inputText:s.inputText,inputPlaceholder:s.inputPlaceholder,cardBorder:s.border,inputBorder:s.inputBorder,buttonBorder:s.buttonBorder,successBg:s.successBg,successBorder:s.successBorder,successText:s.successText,warningBg:s.warningBg,warningBorder:s.warningBorder,warningText:s.warningText,errorBg:s.errorBg,errorBorder:s.errorBorder,errorText:s.errorText,infoBg:s.infoBg,infoBorder:s.infoBorder,infoText:s.infoText};return{brand:r,theme:l,dark:c,appName:i,primaryColor:n,dk:p,palette:p}},[r,o,t])}export{v as R,U as S,Z as a,V as b,X as c,d,z as e,K as f,P as g,W as h,J as i,B as r,ee as u};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";const p=require("react"),b=require("react/jsx-runtime"),R=require("@spicenet-io/spiceflow-core"),g=require("./index-WLbJouQ7.js"),T=require("viem"),A=require("./Button-KtHGKIo6.js");class d extends Error{constructor(t,r,e={}){super(r),this.code=t,this.context=e,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,d)}}function _(o){return o instanceof d}const $=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",v="__SPICEFLOW_RELAYER_API_URL__";function F(o,t){const r=t.match(/Output amount (\d+) is insufficient after fees (\d+) on chain (\d+)/);if(!r)return t;const[,e,a,s]=r,c=Number(s),n=BigInt(e),i=BigInt(a);let u;for(const f of o.intents){const S=f.chainBatches.find(U=>U.chainId===c);if(S){u=S;break}}const l=u?.tokenTransfers.find(f=>f.from==="solver"&&f.to.toLowerCase()===o.user.toLowerCase()&&!R.isNativeToken(f.token));if(!l)return`Amount is too small to cover the estimated fee on ${g.getChainName(c)}.`;const h=R.getTokenByAddress(l.token,c),B=h?.decimals??18,w=h?.symbol??"tokens",E=T.formatUnits(n,B),x=T.formatUnits(i,B);return`Amount is too small to cover the estimated fee on ${g.getChainName(c)}. Amount: ${E} ${w}. Estimated fee: ${x} ${w}.`}function L(o){return o.intents.some(t=>t.batches.some(r=>BigInt(r.netOutput)<BigInt(r.grossOutput)))}function N(){if(typeof globalThis>"u")return;const o=globalThis[v];return typeof o=="string"&&o.length>0?o:void 0}class j{constructor(){this.baseUrl=$}setBaseUrl(t){this.baseUrl=t,typeof globalThis<"u"&&(globalThis[v]=t)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return N()||this.baseUrl}async createAction(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(e,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const e=await r.text();throw new d("RELAYER_ERROR",`Relayer API error: ${r.status} - ${e}`,{httpStatus:r.status,responseBody:e,endpoint:"/actions"})}return await r.json()}async estimateActionFees(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions/fees/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(a,s)=>typeof s=="bigint"?s.toString():s)}),e=await r.json();if(!r.ok||!e.success||!e.data?.feeEstimate){const a=e.error?.message||`Relayer fee estimate error: ${r.status}`,s=F(t,a);throw new d("RELAYER_ERROR",s,{httpStatus:r.status,responseBody:JSON.stringify(e),endpoint:"/actions/fees/estimate"})}return e.data.feeEstimate}async estimateBatchGas(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions/gas/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(a,s)=>typeof s=="bigint"?s.toString():s)}),e=await r.json();if(!r.ok||!e.success||!e.data?.gasFee){const a=e.error?.message||`Relayer gas estimate error: ${r.status}`;throw new d("RELAYER_ERROR",a,{httpStatus:r.status,responseBody:JSON.stringify(e),endpoint:"/actions/gas/estimate"})}return{gasFee:BigInt(e.data.gasFee),gasQuoteSource:e.data.gasQuoteSource}}async executeStep(t,r,e,a){const s=`${this.getEffectiveBaseUrl()}/actions/${t}/intents/${r}/steps/${e}`,c=fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});let n;try{n=await Promise.race([c,new Promise((i,u)=>setTimeout(()=>u(new d("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:t,intentIndex:r,stepIndex:e,endpoint:`/actions/${t}/intents/${r}/steps/${e}`})),1e4))])}catch(i){throw i}if(!n.ok){const i=await n.text();throw new d("RELAYER_EXECUTE_ERROR",`Execute step error: ${n.status} - ${i}`,{httpStatus:n.status,responseBody:i,endpoint:`/actions/${t}/intents/${r}/steps/${e}`,actionId:t})}return{success:!0,transactionHash:(await n.json()).transactionHash}}async checkStepStatus(t,r){const e=t.split("/");let a="";if(e.length>=2){const n=e[0],i=e[1];a=`${this.getEffectiveBaseUrl()}/actions/${n}/intents/${i}/steps/${r}`}else a=`${this.getEffectiveBaseUrl()}/actions/${t}/intents/0/steps/${r}`;const s=await fetch(a);if(!s.ok)throw new d("RELAYER_STATUS_ERROR",`Intent step status check failed: ${s.status}`,{httpStatus:s.status,endpoint:a,intentId:t});const c=await s.json();return{success:!0,data:{status:c.status==="error"?"reverted":c.status,transactionHash:c.txid}}}async requestSpiceUsdAirdrop(t){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop/${t.chainId}/spiceUsd`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wallet:t.address})}),e=await r.json().catch(()=>({}));if(!r.ok){const a=e&&(e.error||e.message)||"Failed to request airdrop";return{success:!1,errorMessage:String(a)}}return e&&typeof e.error=="string"?{success:!1,errorMessage:e.error}:e&&(e.txHash||e.amount)?{success:!0,txHash:e.txHash,amount:e.amount}:{success:!0}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async requestAirdrop(t){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:t.tag||"default",airdrops:[{chainId:t.chainId,tokenId:t.tokenId,wallet:t.wallet,amount:t.amount||"0.0001"}]})}),e=await r.json().catch(()=>({}));if(!r.ok){const s=e?.message||e?.errors?.[0]?.error||"Failed to request airdrop";return{success:!1,errorMessage:String(s)}}const a=e?.airdrops?.[t.chainId]?.[t.tokenId]?.txHash;return e.errors&&e.errors.length>0?{success:!1,errorMessage:e.errors[0].error}:{success:!0,txHash:a}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async createWallet(t,r){const e=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok){const a=await e.text();throw new d("RELAYER_ERROR",`Create wallet error: ${e.status} - ${a}`,{httpStatus:e.status,endpoint:`/wallets/${t}`})}return e.json()}async getWallet(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${t}`);if(!r.ok){const e=await r.text();throw new d("RELAYER_ERROR",`Get wallet error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:`/wallets/${t}`})}return r.json()}async createWithdrawal(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(e,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const e=await r.text();throw new d("RELAYER_ERROR",`Create withdrawal error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:"/withdrawals"})}return r.json()}async getWithdrawal(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${t}`);if(!r.ok){const e=await r.text();throw new d("RELAYER_ERROR",`Get withdrawal error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:`/withdrawals/${t}`})}return r.json()}async getRollupTimestamp(){const t=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!t.ok)throw new d("RELAYER_ERROR",`Get rollup timestamp error: ${t.status}`,{httpStatus:t.status,endpoint:"/time"});return t.json()}}const m=new j,M=(o,t)=>{const r=a=>t?t(a):g.getChainName(a),e=[];return o.forEach((a,s)=>{const c=a.calls&&a.calls.length>0,n=a.tokenTransfers&&a.tokenTransfers.length>0;if(c||n){const i={stepId:s,status:s===0?"processing":"pending",chainId:a.chainId,chainName:r(a.chainId),description:"Processing transaction"};e.push(i)}}),e},I="spiceflow-mode",k=()=>{if(typeof window>"u")return null;try{const o=window.localStorage.getItem(I);return o==="embedded"?"7702":o==="external"?"ondemand":null}catch{return null}},Y=o=>{if(!(typeof window>"u"))try{window.localStorage.setItem(I,o==="7702"?"embedded":"external")}catch{}},q=()=>k()!==null,C=p.createContext(null),O=p.createContext(null),H=({children:o,provider:t,supportedChainIds:r,network:e="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:c,appName:n="Spicenet",apiUrl:i,theme:u,rpcOverrides:l})=>{p.useEffect(()=>{if(!i)return;const f=m.getBaseUrl();return m.setBaseUrl(i),()=>m.setBaseUrl(f)},[i]),p.useEffect(()=>(g.setRpcOverrides(l),()=>g.setRpcOverrides(void 0)),[l]);const h=r??R.getChainIdsByNetwork(e),B=u??null,[w,E]=p.useState(()=>k()??a),x=p.useCallback(f=>{E(f),Y(f)},[]);return b.jsx(C.Provider,{value:B,children:b.jsx(O.Provider,{value:{provider:t,supportedChainIds:h,skipFlow:s,mode:w,setMode:x,network:e,nativeChainId:c,appName:n,apiUrl:i,rpcOverrides:l},children:o})})};function y(o,t){const r=o.replace("#",""),e=Math.max(0,Math.round(parseInt(r.substring(0,2),16)*(1-t))),a=Math.max(0,Math.round(parseInt(r.substring(2,4),16)*(1-t))),s=Math.max(0,Math.round(parseInt(r.substring(4,6),16)*(1-t)));return`#${e.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function J(o,t){return{shell:t?.shell??"#141414",shellBorder:t?.shellBorder??y(t?.shell??"#141414",.35),shellInnerBorder:t?.shellInnerBorder??y(t?.shell??"#141414",.55),cardBg:t?.cardBg??"#1e1e1e",inputBg:t?.inputBg??"#171717",hoverBg:t?.hoverBg??"#2a2a2a",textPrimary:t?.textPrimary??"#ffffff",textSecondary:t?.textSecondary??"#888888",inputText:t?.inputText??"#e0e0e0",inputPlaceholder:t?.inputPlaceholder??"#555555",cardBorder:t?.cardBorder??"rgba(255,255,255,0.08)",inputBorder:t?.inputBorder??"rgba(255,255,255,0.10)",buttonBorder:t?.buttonBorder??"rgba(255,255,255,0.12)",successBg:t?.successBg??"#0a1f18",successBorder:t?.successBorder??"#1a4a3a",successText:t?.successText??"#6ee7b7",warningBg:t?.warningBg??"#1f1a0d",warningBorder:t?.warningBorder??"#4a3820",warningText:t?.warningText??"#fbbf24",errorBg:t?.errorBg??"#1f0d0d",errorBorder:t?.errorBorder??"#4a2020",errorText:t?.errorText??"#f87171",infoBg:t?.infoBg??"#0d1325",infoBorder:t?.infoBorder??"#2a3a5a",infoText:t?.infoText??"#60a5fa"}}function D(o){return{shell:"#ffffff",shellBorder:"#E9E9E9",shellInnerBorder:"#D5D5D5",cardBg:"#f9fafb",inputBg:"#ffffff",hoverBg:"#f3f4f6",textPrimary:"#111827",textSecondary:"#6b7280",inputText:"#111827",inputPlaceholder:"#9ca3af",cardBorder:"#E0E0E0",inputBorder:"#d1d5db",buttonBorder:"#0e0d0b",successBg:"#d1fae5",successBorder:"#6ee7b7",successText:"#065f46",warningBg:"#fef3c7",warningBorder:"#fcd34d",warningText:"#92400e",errorBg:"#fee2e2",errorBorder:"#fca5a5",errorText:"#dc2626",infoBg:"#dbeafe",infoBorder:"#93c5fd",infoText:"#1e40af"}}function P(o,t){const r=t?{...o,...t}:o,e=r.dark??!1,a=r.primaryColor,s=r.shell??(e?"#141414":"#ffffff");return{primaryColor:a,dark:e,fontFamily:r.fontFamily??'"Helvetica Neue", sans-serif',appName:r.appName??"Spicenet",logo:r.logo,borderRadius:r.borderRadius??"8px",shell:s,shellBorder:y(s,e?.35:.085),shellInnerBorder:y(s,e?.55:.165),card:r.card??(e?"#1e1e1e":"#f9fafb"),input:e?"#171717":"#ffffff",hover:e?"#2a2a2a":"#f3f4f6",text:r.text??(e?"#ffffff":"#111827"),textMuted:r.textMuted??(e?"#888888":"#6b7280"),inputText:e?"#e0e0e0":"#111827",inputPlaceholder:e?"#555555":"#9ca3af",border:r.border??(e?"rgba(255,255,255,0.08)":"#E0E0E0"),inputBorder:e?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:e?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:e?"#0a1f18":"#d1fae5",successBorder:e?"#1a4a3a":"#6ee7b7",successText:e?"#6ee7b7":"#065f46",warningBg:e?"#1f1a0d":"#fef3c7",warningBorder:e?"#4a3820":"#fcd34d",warningText:e?"#fbbf24":"#92400e",errorBg:e?"#1f0d0d":"#fee2e2",errorBorder:e?"#4a2020":"#fca5a5",errorText:e?"#f87171":"#dc2626",infoBg:e?"#0d1325":"#dbeafe",infoBorder:e?"#2a3a5a":"#93c5fd",infoText:e?"#60a5fa":"#1e40af"}}function W(o,t){const r=p.useContext(C)??void 0;return p.useMemo(()=>{const e=r??{primaryColor:"#EA4B4B"},a={...o?.primaryColor?{primaryColor:o.primaryColor}:{},...o?.fontFamily?{fontFamily:o.fontFamily}:{},...t!==void 0?{dark:t}:{}},s=P(e,a),{dark:c,primaryColor:n,appName:i}=s,u=A.createTheme(c?"dark":"light"),l={...u,colors:{...u.colors,primary:n,primaryHover:`${n}dd`},typography:{...u.typography,fontFamily:s.fontFamily}},h={shell:s.shell,shellBorder:s.shellBorder,shellInnerBorder:s.shellInnerBorder,cardBg:s.card,inputBg:s.input,hoverBg:s.hover,textPrimary:s.text,textSecondary:s.textMuted,inputText:s.inputText,inputPlaceholder:s.inputPlaceholder,cardBorder:s.border,inputBorder:s.inputBorder,buttonBorder:s.buttonBorder,successBg:s.successBg,successBorder:s.successBorder,successText:s.successText,warningBg:s.warningBg,warningBorder:s.warningBorder,warningText:s.warningText,errorBg:s.errorBg,errorBorder:s.errorBorder,errorText:s.errorText,infoBg:s.infoBg,infoBorder:s.infoBorder,infoText:s.infoText};return{brand:r,theme:l,dark:c,appName:i,primaryColor:n,dk:h,palette:h}},[r,o,t])}exports.RELAYER_API_URL=$,exports.SpiceFlowProvider=H,exports.SpiceFlowProviderContext=O,exports.SpiceflowError=d,exports.buildDarkPalette=J,exports.buildLightPalette=D,exports.createInitialSteps=M,exports.hasReducedFeeOutput=L,exports.hasStoredSpiceFlowMode=q,exports.isSpiceflowError=_,exports.relayerService=m,exports.resolveTheme=P,exports.useSpiceBrand=W;
|
|
@@ -12,6 +12,25 @@ export declare class RelayerService {
|
|
|
12
12
|
private getEffectiveBaseUrl;
|
|
13
13
|
createAction(request: CreateActionRequest): Promise<CreateActionResponse>;
|
|
14
14
|
estimateActionFees(request: CreateActionRequest): Promise<NonNullable<EstimateActionFeesResponse["data"]>["feeEstimate"]>;
|
|
15
|
+
estimateBatchGas(request: {
|
|
16
|
+
user: string;
|
|
17
|
+
outputToken: string;
|
|
18
|
+
stepIndex?: number;
|
|
19
|
+
chainBatches: Array<ChainBatch & {
|
|
20
|
+
hash?: `0x${string}`;
|
|
21
|
+
}>;
|
|
22
|
+
chainAuthorizations?: Array<{
|
|
23
|
+
address: string;
|
|
24
|
+
chainId: number;
|
|
25
|
+
nonce: number;
|
|
26
|
+
r: `0x${string}`;
|
|
27
|
+
s: `0x${string}`;
|
|
28
|
+
yParity?: number;
|
|
29
|
+
}>;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
gasFee: bigint;
|
|
32
|
+
gasQuoteSource: string;
|
|
33
|
+
}>;
|
|
15
34
|
executeStep(actionId: string, intentIndex: number, stepIndex: number, request: ExecuteStepRequest): Promise<{
|
|
16
35
|
success: true;
|
|
17
36
|
transactionHash?: string;
|
package/package.json
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import{createContext as R,useEffect as b,useState as _,useCallback as L,useContext as N,useMemo as j}from"react";import{jsx as S}from"react/jsx-runtime";import{isNativeToken as F,getTokenByAddress as M,getChainIdsByNetwork as Y}from"@spicenet-io/spiceflow-core";import{a as E,s as T}from"./index-C1DEtFS6.js";import{formatUnits as $}from"viem";import{c as H}from"./Button-BJ2OiyLY.js";class d extends Error{constructor(e,r,t={}){super(r),this.code=e,this.context=t,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,d)}}function J(o){return o instanceof d}const v=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",I="__SPICEFLOW_RELAYER_API_URL__";function q(o,e){const r=e.match(/Output amount (\d+) is insufficient after fees (\d+) on chain (\d+)/);if(!r)return e;const[,t,a,s]=r,c=Number(s),n=BigInt(t),i=BigInt(a);let f;for(const l of o.intents){const x=l.chainBatches.find(A=>A.chainId===c);if(x){f=x;break}}const u=f?.tokenTransfers.find(l=>l.from==="solver"&&l.to.toLowerCase()===o.user.toLowerCase()&&!F(l.token));if(!u)return`Amount is too small to cover the estimated fee on ${E(c)}.`;const p=M(u.token,c),h=p?.decimals??18,g=p?.symbol??"tokens",w=$(n,h),y=$(i,h);return`Amount is too small to cover the estimated fee on ${E(c)}. Amount: ${w} ${g}. Estimated fee: ${y} ${g}.`}function W(o){return o.intents.some(e=>e.batches.some(r=>BigInt(r.netOutput)<BigInt(r.grossOutput)))}function D(){if(typeof globalThis>"u")return;const o=globalThis[I];return typeof o=="string"&&o.length>0?o:void 0}class G{constructor(){this.baseUrl=v}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[I]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return D()||this.baseUrl}async createAction(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(t,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const t=await r.text();throw new d("RELAYER_ERROR",`Relayer API error: ${r.status} - ${t}`,{httpStatus:r.status,responseBody:t,endpoint:"/actions"})}return await r.json()}async estimateActionFees(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions/fees/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(a,s)=>typeof s=="bigint"?s.toString():s)}),t=await r.json();if(!r.ok||!t.success||!t.data?.feeEstimate){const a=t.error?.message||`Relayer fee estimate error: ${r.status}`,s=q(e,a);throw new d("RELAYER_ERROR",s,{httpStatus:r.status,responseBody:JSON.stringify(t),endpoint:"/actions/fees/estimate"})}return t.data.feeEstimate}async executeStep(e,r,t,a){const s=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/${r}/steps/${t}`,c=fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});let n;try{n=await Promise.race([c,new Promise((i,f)=>setTimeout(()=>f(new d("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:e,intentIndex:r,stepIndex:t,endpoint:`/actions/${e}/intents/${r}/steps/${t}`})),1e4))])}catch(i){throw i}if(!n.ok){const i=await n.text();throw new d("RELAYER_EXECUTE_ERROR",`Execute step error: ${n.status} - ${i}`,{httpStatus:n.status,responseBody:i,endpoint:`/actions/${e}/intents/${r}/steps/${t}`,actionId:e})}return{success:!0,transactionHash:(await n.json()).transactionHash}}async checkStepStatus(e,r){const t=e.split("/");let a="";if(t.length>=2){const n=t[0],i=t[1];a=`${this.getEffectiveBaseUrl()}/actions/${n}/intents/${i}/steps/${r}`}else a=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/0/steps/${r}`;const s=await fetch(a);if(!s.ok)throw new d("RELAYER_STATUS_ERROR",`Intent step status check failed: ${s.status}`,{httpStatus:s.status,endpoint:a,intentId:e});const c=await s.json();return{success:!0,data:{status:c.status==="error"?"reverted":c.status,transactionHash:c.txid}}}async requestSpiceUsdAirdrop(e){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop/${e.chainId}/spiceUsd`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wallet:e.address})}),t=await r.json().catch(()=>({}));if(!r.ok){const a=t&&(t.error||t.message)||"Failed to request airdrop";return{success:!1,errorMessage:String(a)}}return t&&typeof t.error=="string"?{success:!1,errorMessage:t.error}:t&&(t.txHash||t.amount)?{success:!0,txHash:t.txHash,amount:t.amount}:{success:!0}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async requestAirdrop(e){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:e.tag||"default",airdrops:[{chainId:e.chainId,tokenId:e.tokenId,wallet:e.wallet,amount:e.amount||"0.0001"}]})}),t=await r.json().catch(()=>({}));if(!r.ok){const s=t?.message||t?.errors?.[0]?.error||"Failed to request airdrop";return{success:!1,errorMessage:String(s)}}const a=t?.airdrops?.[e.chainId]?.[e.tokenId]?.txHash;return t.errors&&t.errors.length>0?{success:!1,errorMessage:t.errors[0].error}:{success:!0,txHash:a}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async createWallet(e,r){const t=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!t.ok){const a=await t.text();throw new d("RELAYER_ERROR",`Create wallet error: ${t.status} - ${a}`,{httpStatus:t.status,endpoint:`/wallets/${e}`})}return t.json()}async getWallet(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`);if(!r.ok){const t=await r.text();throw new d("RELAYER_ERROR",`Get wallet error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:`/wallets/${e}`})}return r.json()}async createWithdrawal(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(t,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const t=await r.text();throw new d("RELAYER_ERROR",`Create withdrawal error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:"/withdrawals"})}return r.json()}async getWithdrawal(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${e}`);if(!r.ok){const t=await r.text();throw new d("RELAYER_ERROR",`Get withdrawal error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:`/withdrawals/${e}`})}return r.json()}async getRollupTimestamp(){const e=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!e.ok)throw new d("RELAYER_ERROR",`Get rollup timestamp error: ${e.status}`,{httpStatus:e.status,endpoint:"/time"});return e.json()}}const B=new G,X=(o,e)=>{const r=a=>e?e(a):E(a),t=[];return o.forEach((a,s)=>{const c=a.calls&&a.calls.length>0,n=a.tokenTransfers&&a.tokenTransfers.length>0;if(c||n){const i={stepId:s,status:s===0?"processing":"pending",chainId:a.chainId,chainName:r(a.chainId),description:"Processing transaction"};t.push(i)}}),t},k="spiceflow-mode",U=()=>{if(typeof window>"u")return null;try{const o=window.localStorage.getItem(k);return o==="embedded"?"7702":o==="external"?"ondemand":null}catch{return null}},z=o=>{if(!(typeof window>"u"))try{window.localStorage.setItem(k,o==="7702"?"embedded":"external")}catch{}},K=()=>U()!==null,C=R(null),O=R(null),Q=({children:o,provider:e,supportedChainIds:r,network:t="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:c,appName:n="Spicenet",apiUrl:i,theme:f,rpcOverrides:u})=>{b(()=>{if(!i)return;const l=B.getBaseUrl();return B.setBaseUrl(i),()=>B.setBaseUrl(l)},[i]),b(()=>(T(u),()=>T(void 0)),[u]);const p=r??Y(t),h=f??null,[g,w]=_(()=>U()??a),y=L(l=>{w(l),z(l)},[]);return S(C.Provider,{value:h,children:S(O.Provider,{value:{provider:e,supportedChainIds:p,skipFlow:s,mode:g,setMode:y,network:t,nativeChainId:c,appName:n,apiUrl:i,rpcOverrides:u},children:o})})};function m(o,e){const r=o.replace("#",""),t=Math.max(0,Math.round(parseInt(r.substring(0,2),16)*(1-e))),a=Math.max(0,Math.round(parseInt(r.substring(2,4),16)*(1-e))),s=Math.max(0,Math.round(parseInt(r.substring(4,6),16)*(1-e)));return`#${t.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function V(o,e){return{shell:e?.shell??"#141414",shellBorder:e?.shellBorder??m(e?.shell??"#141414",.35),shellInnerBorder:e?.shellInnerBorder??m(e?.shell??"#141414",.55),cardBg:e?.cardBg??"#1e1e1e",inputBg:e?.inputBg??"#171717",hoverBg:e?.hoverBg??"#2a2a2a",textPrimary:e?.textPrimary??"#ffffff",textSecondary:e?.textSecondary??"#888888",inputText:e?.inputText??"#e0e0e0",inputPlaceholder:e?.inputPlaceholder??"#555555",cardBorder:e?.cardBorder??"rgba(255,255,255,0.08)",inputBorder:e?.inputBorder??"rgba(255,255,255,0.10)",buttonBorder:e?.buttonBorder??"rgba(255,255,255,0.12)",successBg:e?.successBg??"#0a1f18",successBorder:e?.successBorder??"#1a4a3a",successText:e?.successText??"#6ee7b7",warningBg:e?.warningBg??"#1f1a0d",warningBorder:e?.warningBorder??"#4a3820",warningText:e?.warningText??"#fbbf24",errorBg:e?.errorBg??"#1f0d0d",errorBorder:e?.errorBorder??"#4a2020",errorText:e?.errorText??"#f87171",infoBg:e?.infoBg??"#0d1325",infoBorder:e?.infoBorder??"#2a3a5a",infoText:e?.infoText??"#60a5fa"}}function Z(o){return{shell:"#ffffff",shellBorder:"#E9E9E9",shellInnerBorder:"#D5D5D5",cardBg:"#f9fafb",inputBg:"#ffffff",hoverBg:"#f3f4f6",textPrimary:"#111827",textSecondary:"#6b7280",inputText:"#111827",inputPlaceholder:"#9ca3af",cardBorder:"#E0E0E0",inputBorder:"#d1d5db",buttonBorder:"#0e0d0b",successBg:"#d1fae5",successBorder:"#6ee7b7",successText:"#065f46",warningBg:"#fef3c7",warningBorder:"#fcd34d",warningText:"#92400e",errorBg:"#fee2e2",errorBorder:"#fca5a5",errorText:"#dc2626",infoBg:"#dbeafe",infoBorder:"#93c5fd",infoText:"#1e40af"}}function P(o,e){const r=e?{...o,...e}:o,t=r.dark??!1,a=r.primaryColor,s=r.shell??(t?"#141414":"#ffffff");return{primaryColor:a,dark:t,fontFamily:r.fontFamily??'"Helvetica Neue", sans-serif',appName:r.appName??"Spicenet",logo:r.logo,borderRadius:r.borderRadius??"8px",shell:s,shellBorder:m(s,t?.35:.085),shellInnerBorder:m(s,t?.55:.165),card:r.card??(t?"#1e1e1e":"#f9fafb"),input:t?"#171717":"#ffffff",hover:t?"#2a2a2a":"#f3f4f6",text:r.text??(t?"#ffffff":"#111827"),textMuted:r.textMuted??(t?"#888888":"#6b7280"),inputText:t?"#e0e0e0":"#111827",inputPlaceholder:t?"#555555":"#9ca3af",border:r.border??(t?"rgba(255,255,255,0.08)":"#E0E0E0"),inputBorder:t?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:t?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:t?"#0a1f18":"#d1fae5",successBorder:t?"#1a4a3a":"#6ee7b7",successText:t?"#6ee7b7":"#065f46",warningBg:t?"#1f1a0d":"#fef3c7",warningBorder:t?"#4a3820":"#fcd34d",warningText:t?"#fbbf24":"#92400e",errorBg:t?"#1f0d0d":"#fee2e2",errorBorder:t?"#4a2020":"#fca5a5",errorText:t?"#f87171":"#dc2626",infoBg:t?"#0d1325":"#dbeafe",infoBorder:t?"#2a3a5a":"#93c5fd",infoText:t?"#60a5fa":"#1e40af"}}function ee(o,e){const r=N(C)??void 0;return j(()=>{const t=r??{primaryColor:"#EA4B4B"},a={...o?.primaryColor?{primaryColor:o.primaryColor}:{},...o?.fontFamily?{fontFamily:o.fontFamily}:{},...e!==void 0?{dark:e}:{}},s=P(t,a),{dark:c,primaryColor:n,appName:i}=s,f=H(c?"dark":"light"),u={...f,colors:{...f.colors,primary:n,primaryHover:`${n}dd`},typography:{...f.typography,fontFamily:s.fontFamily}},p={shell:s.shell,shellBorder:s.shellBorder,shellInnerBorder:s.shellInnerBorder,cardBg:s.card,inputBg:s.input,hoverBg:s.hover,textPrimary:s.text,textSecondary:s.textMuted,inputText:s.inputText,inputPlaceholder:s.inputPlaceholder,cardBorder:s.border,inputBorder:s.inputBorder,buttonBorder:s.buttonBorder,successBg:s.successBg,successBorder:s.successBorder,successText:s.successText,warningBg:s.warningBg,warningBorder:s.warningBorder,warningText:s.warningText,errorBg:s.errorBg,errorBorder:s.errorBorder,errorText:s.errorText,infoBg:s.infoBg,infoBorder:s.infoBorder,infoText:s.infoText};return{brand:r,theme:u,dark:c,appName:i,primaryColor:n,dk:p,palette:p}},[r,o,e])}export{v as R,O as S,Z as a,V as b,X as c,d,K as e,Q as f,P as g,W as h,J as i,B as r,ee as u};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";const p=require("react"),b=require("react/jsx-runtime"),R=require("@spicenet-io/spiceflow-core"),g=require("./index-WLbJouQ7.js"),T=require("viem"),A=require("./Button-KtHGKIo6.js");class d extends Error{constructor(e,r,t={}){super(r),this.code=e,this.context=t,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,d)}}function _(o){return o instanceof d}const $=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",v="__SPICEFLOW_RELAYER_API_URL__";function L(o,e){const r=e.match(/Output amount (\d+) is insufficient after fees (\d+) on chain (\d+)/);if(!r)return e;const[,t,a,s]=r,c=Number(s),n=BigInt(t),i=BigInt(a);let l;for(const f of o.intents){const S=f.chainBatches.find(O=>O.chainId===c);if(S){l=S;break}}const u=l?.tokenTransfers.find(f=>f.from==="solver"&&f.to.toLowerCase()===o.user.toLowerCase()&&!R.isNativeToken(f.token));if(!u)return`Amount is too small to cover the estimated fee on ${g.getChainName(c)}.`;const h=R.getTokenByAddress(u.token,c),B=h?.decimals??18,w=h?.symbol??"tokens",E=T.formatUnits(n,B),x=T.formatUnits(i,B);return`Amount is too small to cover the estimated fee on ${g.getChainName(c)}. Amount: ${E} ${w}. Estimated fee: ${x} ${w}.`}function F(o){return o.intents.some(e=>e.batches.some(r=>BigInt(r.netOutput)<BigInt(r.grossOutput)))}function N(){if(typeof globalThis>"u")return;const o=globalThis[v];return typeof o=="string"&&o.length>0?o:void 0}class j{constructor(){this.baseUrl=$}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[v]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return N()||this.baseUrl}async createAction(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(t,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const t=await r.text();throw new d("RELAYER_ERROR",`Relayer API error: ${r.status} - ${t}`,{httpStatus:r.status,responseBody:t,endpoint:"/actions"})}return await r.json()}async estimateActionFees(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions/fees/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(a,s)=>typeof s=="bigint"?s.toString():s)}),t=await r.json();if(!r.ok||!t.success||!t.data?.feeEstimate){const a=t.error?.message||`Relayer fee estimate error: ${r.status}`,s=L(e,a);throw new d("RELAYER_ERROR",s,{httpStatus:r.status,responseBody:JSON.stringify(t),endpoint:"/actions/fees/estimate"})}return t.data.feeEstimate}async executeStep(e,r,t,a){const s=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/${r}/steps/${t}`,c=fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});let n;try{n=await Promise.race([c,new Promise((i,l)=>setTimeout(()=>l(new d("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:e,intentIndex:r,stepIndex:t,endpoint:`/actions/${e}/intents/${r}/steps/${t}`})),1e4))])}catch(i){throw i}if(!n.ok){const i=await n.text();throw new d("RELAYER_EXECUTE_ERROR",`Execute step error: ${n.status} - ${i}`,{httpStatus:n.status,responseBody:i,endpoint:`/actions/${e}/intents/${r}/steps/${t}`,actionId:e})}return{success:!0,transactionHash:(await n.json()).transactionHash}}async checkStepStatus(e,r){const t=e.split("/");let a="";if(t.length>=2){const n=t[0],i=t[1];a=`${this.getEffectiveBaseUrl()}/actions/${n}/intents/${i}/steps/${r}`}else a=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/0/steps/${r}`;const s=await fetch(a);if(!s.ok)throw new d("RELAYER_STATUS_ERROR",`Intent step status check failed: ${s.status}`,{httpStatus:s.status,endpoint:a,intentId:e});const c=await s.json();return{success:!0,data:{status:c.status==="error"?"reverted":c.status,transactionHash:c.txid}}}async requestSpiceUsdAirdrop(e){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop/${e.chainId}/spiceUsd`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wallet:e.address})}),t=await r.json().catch(()=>({}));if(!r.ok){const a=t&&(t.error||t.message)||"Failed to request airdrop";return{success:!1,errorMessage:String(a)}}return t&&typeof t.error=="string"?{success:!1,errorMessage:t.error}:t&&(t.txHash||t.amount)?{success:!0,txHash:t.txHash,amount:t.amount}:{success:!0}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async requestAirdrop(e){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:e.tag||"default",airdrops:[{chainId:e.chainId,tokenId:e.tokenId,wallet:e.wallet,amount:e.amount||"0.0001"}]})}),t=await r.json().catch(()=>({}));if(!r.ok){const s=t?.message||t?.errors?.[0]?.error||"Failed to request airdrop";return{success:!1,errorMessage:String(s)}}const a=t?.airdrops?.[e.chainId]?.[e.tokenId]?.txHash;return t.errors&&t.errors.length>0?{success:!1,errorMessage:t.errors[0].error}:{success:!0,txHash:a}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async createWallet(e,r){const t=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!t.ok){const a=await t.text();throw new d("RELAYER_ERROR",`Create wallet error: ${t.status} - ${a}`,{httpStatus:t.status,endpoint:`/wallets/${e}`})}return t.json()}async getWallet(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`);if(!r.ok){const t=await r.text();throw new d("RELAYER_ERROR",`Get wallet error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:`/wallets/${e}`})}return r.json()}async createWithdrawal(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(t,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const t=await r.text();throw new d("RELAYER_ERROR",`Create withdrawal error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:"/withdrawals"})}return r.json()}async getWithdrawal(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${e}`);if(!r.ok){const t=await r.text();throw new d("RELAYER_ERROR",`Get withdrawal error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:`/withdrawals/${e}`})}return r.json()}async getRollupTimestamp(){const e=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!e.ok)throw new d("RELAYER_ERROR",`Get rollup timestamp error: ${e.status}`,{httpStatus:e.status,endpoint:"/time"});return e.json()}}const m=new j,M=(o,e)=>{const r=a=>e?e(a):g.getChainName(a),t=[];return o.forEach((a,s)=>{const c=a.calls&&a.calls.length>0,n=a.tokenTransfers&&a.tokenTransfers.length>0;if(c||n){const i={stepId:s,status:s===0?"processing":"pending",chainId:a.chainId,chainName:r(a.chainId),description:"Processing transaction"};t.push(i)}}),t},I="spiceflow-mode",k=()=>{if(typeof window>"u")return null;try{const o=window.localStorage.getItem(I);return o==="embedded"?"7702":o==="external"?"ondemand":null}catch{return null}},Y=o=>{if(!(typeof window>"u"))try{window.localStorage.setItem(I,o==="7702"?"embedded":"external")}catch{}},q=()=>k()!==null,C=p.createContext(null),U=p.createContext(null),H=({children:o,provider:e,supportedChainIds:r,network:t="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:c,appName:n="Spicenet",apiUrl:i,theme:l,rpcOverrides:u})=>{p.useEffect(()=>{if(!i)return;const f=m.getBaseUrl();return m.setBaseUrl(i),()=>m.setBaseUrl(f)},[i]),p.useEffect(()=>(g.setRpcOverrides(u),()=>g.setRpcOverrides(void 0)),[u]);const h=r??R.getChainIdsByNetwork(t),B=l??null,[w,E]=p.useState(()=>k()??a),x=p.useCallback(f=>{E(f),Y(f)},[]);return b.jsx(C.Provider,{value:B,children:b.jsx(U.Provider,{value:{provider:e,supportedChainIds:h,skipFlow:s,mode:w,setMode:x,network:t,nativeChainId:c,appName:n,apiUrl:i,rpcOverrides:u},children:o})})};function y(o,e){const r=o.replace("#",""),t=Math.max(0,Math.round(parseInt(r.substring(0,2),16)*(1-e))),a=Math.max(0,Math.round(parseInt(r.substring(2,4),16)*(1-e))),s=Math.max(0,Math.round(parseInt(r.substring(4,6),16)*(1-e)));return`#${t.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function J(o,e){return{shell:e?.shell??"#141414",shellBorder:e?.shellBorder??y(e?.shell??"#141414",.35),shellInnerBorder:e?.shellInnerBorder??y(e?.shell??"#141414",.55),cardBg:e?.cardBg??"#1e1e1e",inputBg:e?.inputBg??"#171717",hoverBg:e?.hoverBg??"#2a2a2a",textPrimary:e?.textPrimary??"#ffffff",textSecondary:e?.textSecondary??"#888888",inputText:e?.inputText??"#e0e0e0",inputPlaceholder:e?.inputPlaceholder??"#555555",cardBorder:e?.cardBorder??"rgba(255,255,255,0.08)",inputBorder:e?.inputBorder??"rgba(255,255,255,0.10)",buttonBorder:e?.buttonBorder??"rgba(255,255,255,0.12)",successBg:e?.successBg??"#0a1f18",successBorder:e?.successBorder??"#1a4a3a",successText:e?.successText??"#6ee7b7",warningBg:e?.warningBg??"#1f1a0d",warningBorder:e?.warningBorder??"#4a3820",warningText:e?.warningText??"#fbbf24",errorBg:e?.errorBg??"#1f0d0d",errorBorder:e?.errorBorder??"#4a2020",errorText:e?.errorText??"#f87171",infoBg:e?.infoBg??"#0d1325",infoBorder:e?.infoBorder??"#2a3a5a",infoText:e?.infoText??"#60a5fa"}}function D(o){return{shell:"#ffffff",shellBorder:"#E9E9E9",shellInnerBorder:"#D5D5D5",cardBg:"#f9fafb",inputBg:"#ffffff",hoverBg:"#f3f4f6",textPrimary:"#111827",textSecondary:"#6b7280",inputText:"#111827",inputPlaceholder:"#9ca3af",cardBorder:"#E0E0E0",inputBorder:"#d1d5db",buttonBorder:"#0e0d0b",successBg:"#d1fae5",successBorder:"#6ee7b7",successText:"#065f46",warningBg:"#fef3c7",warningBorder:"#fcd34d",warningText:"#92400e",errorBg:"#fee2e2",errorBorder:"#fca5a5",errorText:"#dc2626",infoBg:"#dbeafe",infoBorder:"#93c5fd",infoText:"#1e40af"}}function P(o,e){const r=e?{...o,...e}:o,t=r.dark??!1,a=r.primaryColor,s=r.shell??(t?"#141414":"#ffffff");return{primaryColor:a,dark:t,fontFamily:r.fontFamily??'"Helvetica Neue", sans-serif',appName:r.appName??"Spicenet",logo:r.logo,borderRadius:r.borderRadius??"8px",shell:s,shellBorder:y(s,t?.35:.085),shellInnerBorder:y(s,t?.55:.165),card:r.card??(t?"#1e1e1e":"#f9fafb"),input:t?"#171717":"#ffffff",hover:t?"#2a2a2a":"#f3f4f6",text:r.text??(t?"#ffffff":"#111827"),textMuted:r.textMuted??(t?"#888888":"#6b7280"),inputText:t?"#e0e0e0":"#111827",inputPlaceholder:t?"#555555":"#9ca3af",border:r.border??(t?"rgba(255,255,255,0.08)":"#E0E0E0"),inputBorder:t?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:t?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:t?"#0a1f18":"#d1fae5",successBorder:t?"#1a4a3a":"#6ee7b7",successText:t?"#6ee7b7":"#065f46",warningBg:t?"#1f1a0d":"#fef3c7",warningBorder:t?"#4a3820":"#fcd34d",warningText:t?"#fbbf24":"#92400e",errorBg:t?"#1f0d0d":"#fee2e2",errorBorder:t?"#4a2020":"#fca5a5",errorText:t?"#f87171":"#dc2626",infoBg:t?"#0d1325":"#dbeafe",infoBorder:t?"#2a3a5a":"#93c5fd",infoText:t?"#60a5fa":"#1e40af"}}function W(o,e){const r=p.useContext(C)??void 0;return p.useMemo(()=>{const t=r??{primaryColor:"#EA4B4B"},a={...o?.primaryColor?{primaryColor:o.primaryColor}:{},...o?.fontFamily?{fontFamily:o.fontFamily}:{},...e!==void 0?{dark:e}:{}},s=P(t,a),{dark:c,primaryColor:n,appName:i}=s,l=A.createTheme(c?"dark":"light"),u={...l,colors:{...l.colors,primary:n,primaryHover:`${n}dd`},typography:{...l.typography,fontFamily:s.fontFamily}},h={shell:s.shell,shellBorder:s.shellBorder,shellInnerBorder:s.shellInnerBorder,cardBg:s.card,inputBg:s.input,hoverBg:s.hover,textPrimary:s.text,textSecondary:s.textMuted,inputText:s.inputText,inputPlaceholder:s.inputPlaceholder,cardBorder:s.border,inputBorder:s.inputBorder,buttonBorder:s.buttonBorder,successBg:s.successBg,successBorder:s.successBorder,successText:s.successText,warningBg:s.warningBg,warningBorder:s.warningBorder,warningText:s.warningText,errorBg:s.errorBg,errorBorder:s.errorBorder,errorText:s.errorText,infoBg:s.infoBg,infoBorder:s.infoBorder,infoText:s.infoText};return{brand:r,theme:u,dark:c,appName:i,primaryColor:n,dk:h,palette:h}},[r,o,e])}exports.RELAYER_API_URL=$,exports.SpiceFlowProvider=H,exports.SpiceFlowProviderContext=U,exports.SpiceflowError=d,exports.buildDarkPalette=J,exports.buildLightPalette=D,exports.createInitialSteps=M,exports.hasReducedFeeOutput=F,exports.hasStoredSpiceFlowMode=q,exports.isSpiceflowError=_,exports.relayerService=m,exports.resolveTheme=P,exports.useSpiceBrand=W;
|
|
File without changes
|
|
File without changes
|