@spicenet-io/spiceflow-ui 3.1.2 → 3.1.4

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.
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{createWalletClient as l,custom as d}from"viem";import{g as c}from"./index-Bv5PiWia.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};
2
+ import{createWalletClient as l,custom as d}from"viem";import{g as c}from"./index-CJJLFvEf.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};
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";const o=require("viem"),c=require("./index-BEUnI98r.js"),a=e=>{if(!e)return!1;const t=e.connector;if(!t)return!1;if(t.isEmbeddedWallet===!0)return!0;const r=(t.key||t.connectorKey||"").toLowerCase();if(r.includes("embedded")||r.includes("turnkey"))return!0;const n=(t.name||e.walletName||"").toLowerCase();return!!(n.includes("embedded")||n.includes("turnkey"))},s=e=>(e?.connectedWallets||[]).find(t=>a(t))||(a(e?.primaryWallet)?e.primaryWallet:null),u=e=>(e?.connectedWallets||[]).find(t=>t?.address&&t?.connector&&!a(t))||null,l=async(e,t)=>{if(!e?.address)throw new Error("Wallet not available");if(typeof e.getWalletClient=="function"){const r=t===void 0?[void 0]:[String(t),t,void 0];let n=null;for(const d of r)try{const i=await e.getWalletClient(d);if(i)return i}catch(i){n=i}if(n)throw n}if(typeof e.getEthereumProvider=="function"){const r=await e.getEthereumProvider(),n=t?c.getChainConfig(t)?.viemChain:void 0;return o.createWalletClient({account:e.address,chain:n,transport:o.custom(r)})}throw new Error("Wallet client not available")},m=async(e,t)=>{if(!e?.address)throw new Error("Wallet not available");if(typeof e.getEthereumProvider=="function")return e.getEthereumProvider();const r=await l(e,t);return{request:n=>r.request(n)}},f=(e,t)=>({address:e?.address||t.address,chainId:Number(e?.chainId??t.chainId),contractAddress:e?.contractAddress||e?.delegate||t.contractAddress,nonce:BigInt(e?.nonce??t.nonce),r:e?.r,s:e?.s,yParity:(()=>{if(typeof e?.yParity=="number")return e.yParity;const r=Number(e?.v??27);return Number.isFinite(r)?r>=27?r-27:r:0})()});exports.getDynamicEmbeddedWallet=s,exports.getDynamicExternalWallet=u,exports.getProviderEthereumProvider=m,exports.getProviderWalletClient=l,exports.normalizeAuthorization=f;
2
+ "use strict";const o=require("viem"),c=require("./index-eS_pa_hv.js"),a=e=>{if(!e)return!1;const t=e.connector;if(!t)return!1;if(t.isEmbeddedWallet===!0)return!0;const r=(t.key||t.connectorKey||"").toLowerCase();if(r.includes("embedded")||r.includes("turnkey"))return!0;const n=(t.name||e.walletName||"").toLowerCase();return!!(n.includes("embedded")||n.includes("turnkey"))},s=e=>(e?.connectedWallets||[]).find(t=>a(t))||(a(e?.primaryWallet)?e.primaryWallet:null),u=e=>(e?.connectedWallets||[]).find(t=>t?.address&&t?.connector&&!a(t))||null,l=async(e,t)=>{if(!e?.address)throw new Error("Wallet not available");if(typeof e.getWalletClient=="function"){const r=t===void 0?[void 0]:[String(t),t,void 0];let n=null;for(const d of r)try{const i=await e.getWalletClient(d);if(i)return i}catch(i){n=i}if(n)throw n}if(typeof e.getEthereumProvider=="function"){const r=await e.getEthereumProvider(),n=t?c.getChainConfig(t)?.viemChain:void 0;return o.createWalletClient({account:e.address,chain:n,transport:o.custom(r)})}throw new Error("Wallet client not available")},m=async(e,t)=>{if(!e?.address)throw new Error("Wallet not available");if(typeof e.getEthereumProvider=="function")return e.getEthereumProvider();const r=await l(e,t);return{request:n=>r.request(n)}},f=(e,t)=>({address:e?.address||t.address,chainId:Number(e?.chainId??t.chainId),contractAddress:e?.contractAddress||e?.delegate||t.contractAddress,nonce:BigInt(e?.nonce??t.nonce),r:e?.r,s:e?.s,yParity:(()=>{if(typeof e?.yParity=="number")return e.yParity;const r=Number(e?.v??27);return Number.isFinite(r)?r>=27?r-27:r:0})()});exports.getDynamicEmbeddedWallet=s,exports.getDynamicExternalWallet=u,exports.getProviderEthereumProvider=m,exports.getProviderWalletClient=l,exports.normalizeAuthorization=f;
@@ -12,6 +12,7 @@ export interface Authorization {
12
12
  }
13
13
  export interface ChainBatch {
14
14
  chainId: number;
15
+ domain?: "evm" | "spicenet";
15
16
  calls: Call[];
16
17
  tokenTransfers?: TokenTransferConfig[];
17
18
  }
@@ -8,6 +8,9 @@ export interface LockBatchContext {
8
8
  asset: Asset;
9
9
  amount: string;
10
10
  amountWei: bigint;
11
+ grossAmount?: string;
12
+ grossAmountWei?: bigint;
13
+ feeAdjusted?: boolean;
11
14
  }
12
15
  export interface LockDurationOption {
13
16
  label: string;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";const p=require("react"),b=require("react/jsx-runtime"),R=require("@spicenet-io/spiceflow-core"),g=require("./index-BEUnI98r.js"),T=require("viem"),U=require("./Button-B_UpyUH-.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(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 A(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 u of o.intents){const S=u.chainBatches.find(P=>P.chainId===c);if(S){f=S;break}}const l=f?.tokenTransfers.find(u=>u.from==="solver"&&u.to.toLowerCase()===o.user.toLowerCase()&&!R.isNativeToken(u.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,m=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} ${m}. Estimated fee: ${x} ${m}.`}function _(o){return o.intents.some(e=>e.batches.some(r=>BigInt(r.netOutput)<BigInt(r.grossOutput)))}function L(){if(typeof globalThis>"u")return;const o=globalThis[v];return typeof o=="string"&&o.length>0?o:void 0}class N{constructor(){this.baseUrl=$}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[v]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return L()||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=A(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 w=new N,F=(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=p.createContext(null),k=p.createContext(null),j=({children:o,provider:e,supportedChainIds:r,network:t="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:c,appName:n="Spicenet",apiUrl:i,theme:f,rpcOverrides:l})=>{p.useEffect(()=>{if(!i)return;const u=w.getBaseUrl();return w.setBaseUrl(i),()=>w.setBaseUrl(u)},[i]),p.useEffect(()=>(g.setRpcOverrides(l),()=>g.setRpcOverrides(void 0)),[l]);const h=r??R.getChainIdsByNetwork(t),B=f??null,[m,E]=p.useState(a),x=p.useCallback(u=>E(u),[]);return b.jsx(I.Provider,{value:B,children:b.jsx(k.Provider,{value:{provider:e,supportedChainIds:h,skipFlow:s,mode:m,setMode:x,network:t,nativeChainId:c,appName:n,apiUrl:i,rpcOverrides:l},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 M(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 Y(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 C(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 q(o,e){const r=p.useContext(I)??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=C(t,a),{dark:c,primaryColor:n,appName:i}=s,f=U.createTheme(c?"dark":"light"),l={...f,colors:{...f.colors,primary:n,primaryHover:`${n}dd`},typography:{...f.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,e])}exports.RELAYER_API_URL=$,exports.SpiceFlowProvider=j,exports.SpiceFlowProviderContext=k,exports.SpiceflowError=d,exports.buildDarkPalette=M,exports.buildLightPalette=Y,exports.createInitialSteps=F,exports.hasReducedFeeOutput=_,exports.isSpiceflowError=O,exports.relayerService=w,exports.resolveTheme=C,exports.useSpiceBrand=q;
2
+ "use strict";const p=require("react"),b=require("react/jsx-runtime"),R=require("@spicenet-io/spiceflow-core"),g=require("./index-eS_pa_hv.js"),T=require("viem"),U=require("./Button-B_UpyUH-.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(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 A(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 u of o.intents){const S=u.chainBatches.find(P=>P.chainId===c);if(S){f=S;break}}const l=f?.tokenTransfers.find(u=>u.from==="solver"&&u.to.toLowerCase()===o.user.toLowerCase()&&!R.isNativeToken(u.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,m=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} ${m}. Estimated fee: ${x} ${m}.`}function _(o){return o.intents.some(e=>e.batches.some(r=>BigInt(r.netOutput)<BigInt(r.grossOutput)))}function L(){if(typeof globalThis>"u")return;const o=globalThis[v];return typeof o=="string"&&o.length>0?o:void 0}class N{constructor(){this.baseUrl=$}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[v]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return L()||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=A(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 w=new N,F=(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=p.createContext(null),k=p.createContext(null),j=({children:o,provider:e,supportedChainIds:r,network:t="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:c,appName:n="Spicenet",apiUrl:i,theme:f,rpcOverrides:l})=>{p.useEffect(()=>{if(!i)return;const u=w.getBaseUrl();return w.setBaseUrl(i),()=>w.setBaseUrl(u)},[i]),p.useEffect(()=>(g.setRpcOverrides(l),()=>g.setRpcOverrides(void 0)),[l]);const h=r??R.getChainIdsByNetwork(t),B=f??null,[m,E]=p.useState(a),x=p.useCallback(u=>E(u),[]);return b.jsx(I.Provider,{value:B,children:b.jsx(k.Provider,{value:{provider:e,supportedChainIds:h,skipFlow:s,mode:m,setMode:x,network:t,nativeChainId:c,appName:n,apiUrl:i,rpcOverrides:l},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 M(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 Y(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 C(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 q(o,e){const r=p.useContext(I)??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=C(t,a),{dark:c,primaryColor:n,appName:i}=s,f=U.createTheme(c?"dark":"light"),l={...f,colors:{...f.colors,primary:n,primaryHover:`${n}dd`},typography:{...f.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,e])}exports.RELAYER_API_URL=$,exports.SpiceFlowProvider=j,exports.SpiceFlowProviderContext=k,exports.SpiceflowError=d,exports.buildDarkPalette=M,exports.buildLightPalette=Y,exports.createInitialSteps=F,exports.hasReducedFeeOutput=_,exports.isSpiceflowError=O,exports.relayerService=w,exports.resolveTheme=C,exports.useSpiceBrand=q;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{createContext as R,useEffect as b,useState as O,useCallback as A,useContext as _,useMemo as L}from"react";import{jsx as T}from"react/jsx-runtime";import{isNativeToken as N,getTokenByAddress as j,getChainIdsByNetwork as F}from"@spicenet-io/spiceflow-core";import{a as E,s as S}from"./index-Bv5PiWia.js";import{formatUnits as $}from"viem";import{c as M}from"./Button-CaguAr48.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 Y(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 H(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 u of o.intents){const x=u.chainBatches.find(P=>P.chainId===c);if(x){f=x;break}}const l=f?.tokenTransfers.find(u=>u.from==="solver"&&u.to.toLowerCase()===o.user.toLowerCase()&&!N(u.token));if(!l)return`Amount is too small to cover the estimated fee on ${E(c)}.`;const p=j(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 J(o){return o.intents.some(e=>e.batches.some(r=>BigInt(r.netOutput)<BigInt(r.grossOutput)))}function q(){if(typeof globalThis>"u")return;const o=globalThis[I];return typeof o=="string"&&o.length>0?o:void 0}class W{constructor(){this.baseUrl=v}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[I]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return q()||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=H(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 W,D=(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=R(null),U=R(null),G=({children:o,provider:e,supportedChainIds:r,network:t="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:c,appName:n="Spicenet",apiUrl:i,theme:f,rpcOverrides:l})=>{b(()=>{if(!i)return;const u=B.getBaseUrl();return B.setBaseUrl(i),()=>B.setBaseUrl(u)},[i]),b(()=>(S(l),()=>S(void 0)),[l]);const p=r??F(t),h=f??null,[g,w]=O(a),y=A(u=>w(u),[]);return T(k.Provider,{value:h,children:T(U.Provider,{value:{provider:e,supportedChainIds:p,skipFlow:s,mode:g,setMode:y,network:t,nativeChainId:c,appName:n,apiUrl:i,rpcOverrides:l},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 X(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 C(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 K(o,e){const r=_(k)??void 0;return L(()=>{const t=r??{primaryColor:"#EA4B4B"},a={...o?.primaryColor?{primaryColor:o.primaryColor}:{},...o?.fontFamily?{fontFamily:o.fontFamily}:{},...e!==void 0?{dark:e}:{}},s=C(t,a),{dark:c,primaryColor:n,appName:i}=s,f=M(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,e])}export{v as R,U as S,z as a,X as b,D as c,d,G as e,C as f,J as h,Y as i,B as r,K as u};
2
+ import{createContext as R,useEffect as b,useState as O,useCallback as A,useContext as _,useMemo as L}from"react";import{jsx as T}from"react/jsx-runtime";import{isNativeToken as N,getTokenByAddress as j,getChainIdsByNetwork as F}from"@spicenet-io/spiceflow-core";import{a as E,s as S}from"./index-CJJLFvEf.js";import{formatUnits as $}from"viem";import{c as M}from"./Button-CaguAr48.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 Y(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 H(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 u of o.intents){const x=u.chainBatches.find(P=>P.chainId===c);if(x){f=x;break}}const l=f?.tokenTransfers.find(u=>u.from==="solver"&&u.to.toLowerCase()===o.user.toLowerCase()&&!N(u.token));if(!l)return`Amount is too small to cover the estimated fee on ${E(c)}.`;const p=j(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 J(o){return o.intents.some(e=>e.batches.some(r=>BigInt(r.netOutput)<BigInt(r.grossOutput)))}function q(){if(typeof globalThis>"u")return;const o=globalThis[I];return typeof o=="string"&&o.length>0?o:void 0}class W{constructor(){this.baseUrl=v}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[I]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return q()||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=H(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 W,D=(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=R(null),U=R(null),G=({children:o,provider:e,supportedChainIds:r,network:t="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:c,appName:n="Spicenet",apiUrl:i,theme:f,rpcOverrides:l})=>{b(()=>{if(!i)return;const u=B.getBaseUrl();return B.setBaseUrl(i),()=>B.setBaseUrl(u)},[i]),b(()=>(S(l),()=>S(void 0)),[l]);const p=r??F(t),h=f??null,[g,w]=O(a),y=A(u=>w(u),[]);return T(k.Provider,{value:h,children:T(U.Provider,{value:{provider:e,supportedChainIds:p,skipFlow:s,mode:g,setMode:y,network:t,nativeChainId:c,appName:n,apiUrl:i,rpcOverrides:l},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 X(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 C(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 K(o,e){const r=_(k)??void 0;return L(()=>{const t=r??{primaryColor:"#EA4B4B"},a={...o?.primaryColor?{primaryColor:o.primaryColor}:{},...o?.fontFamily?{fontFamily:o.fontFamily}:{},...e!==void 0?{dark:e}:{}},s=C(t,a),{dark:c,primaryColor:n,appName:i}=s,f=M(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,e])}export{v as R,U as S,z as a,X as b,D as c,d,G as e,C as f,J as h,Y as i,B as r,K as u};
@@ -1,12 +1,17 @@
1
1
  import type { Address } from "viem";
2
2
  import type { Asset } from "../types/assets";
3
3
  import type { ChainToken } from "@spicenet-io/spiceflow-core";
4
+ type AssetTokenInput = Pick<Asset, "address" | "symbol" | "name" | "decimals" | "chainId" | "displaySymbol" | "displayName" | "receiptTokenName" | "chainTokens" | "isUniversal">;
4
5
  export declare function parseEvmChainTokenRef(ref: string): {
5
6
  chainId: number;
6
7
  address: Address;
7
8
  } | null;
8
- export declare function getAssetChainTokenCandidates(asset: Asset, chainId: number): Address[];
9
+ export declare function getAssetChainTokenCandidates(asset: AssetTokenInput, chainId: number): Address[];
9
10
  export declare function findEquivalentTokenOnChain(sourceAddress: string, sourceChainId: number, targetChainId: number): import("@spicenet-io/spiceflow-core").Token | undefined;
10
- export declare function resolveAssetTokenAddressOnChain(asset: Asset, targetChainId: number): Address | null;
11
+ export declare function resolveAssetTokenAddressOnChain(asset: AssetTokenInput, targetChainId: number): Address | null;
12
+ export declare function resolveFundedToken(asset: AssetTokenInput, targetChainId: number, options?: {
13
+ requiredAmount?: bigint;
14
+ }): Promise<Address | null>;
11
15
  export declare function areEquivalentOnChains(sourceAddress: Address, sourceChainId: number, targetAddress: Address, targetChainId: number): boolean;
12
16
  export declare function areEquivalentChainTokens(a: ChainToken, b: ChainToken): boolean;
17
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spicenet-io/spiceflow-ui",
3
- "version": "3.1.2",
3
+ "version": "3.1.4",
4
4
  "description": "Spiceflow UI SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",