@spicenet-io/spiceflow-ui 3.3.0 → 3.3.1
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/Button-Ba4gIhbT.js +2 -0
- package/dist/Button-Davf3Lcw.js +2 -0
- package/dist/auth-dynamic.cjs.js +1 -1
- package/dist/auth-dynamic.js +1 -1
- package/dist/auth-privy.cjs.js +1 -1
- package/dist/auth-privy.js +1 -1
- package/dist/index.cjs.js +12 -12
- package/dist/index.js +12 -12
- package/dist/{providerWallet-uz6t-bDC.js → providerWallet-BMCMyG4_.js} +1 -1
- package/dist/{providerWallet-BUP1lSjN.js → providerWallet-BMOS9yt1.js} +1 -1
- package/dist/types/ui.d.ts +1 -0
- package/dist/types/unified.d.ts +1 -0
- package/dist/utils/fees.d.ts +9 -0
- package/package.json +1 -1
- package/dist/Button-B1aDv3aK.js +0 -2
- package/dist/Button-MVjcEXYc.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{createWalletClient as l,custom as d}from"viem";import{g as c}from"./Button-
|
|
2
|
+
import{createWalletClient as l,custom as d}from"viem";import{g as c}from"./Button-Davf3Lcw.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("./Button-
|
|
2
|
+
"use strict";const o=require("viem"),c=require("./Button-Ba4gIhbT.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;
|
package/dist/types/ui.d.ts
CHANGED
package/dist/types/unified.d.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FeeEstimateBatch } from "../types/unified";
|
|
2
|
+
export declare function getBatchFees(batch: FeeEstimateBatch): {
|
|
3
|
+
spicenetFee: bigint;
|
|
4
|
+
gasFee: bigint;
|
|
5
|
+
bridgeFee: bigint;
|
|
6
|
+
totalFee: bigint;
|
|
7
|
+
};
|
|
8
|
+
export declare function hasFeeValue(batch: FeeEstimateBatch): boolean;
|
|
9
|
+
export declare function getBatchGrossDebit(batch: FeeEstimateBatch): bigint;
|
package/package.json
CHANGED
package/dist/Button-B1aDv3aK.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import{jsx as C,jsxs as le}from"react/jsx-runtime";import{createContext as j,useEffect as _,useState as A,useCallback as ue,useContext as fe,useMemo as pe,useRef as me}from"react";import{getChainMeta as D,getTokensForChain as he,getDelegateContract as ge,ZERO_ADDRESS as ye,isNativeToken as N,getTokenByAddress as be,getChainIdsByNetwork as we}from"@spicenet-io/spiceflow-core";import{defineChain as xe,createPublicClient as Be,http as $e,isAddress as Ee,getAddress as ve,formatUnits as W}from"viem";import{readContract as Ce}from"viem/actions";class f extends Error{constructor(e,r,a={}){super(r),this.code=e,this.context=a,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,f)}}function Re(t){return t instanceof f}const z=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"owner",type:"address"},{indexed:!0,name:"spender",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"from",type:"address"},{indexed:!0,name:"to",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Transfer",type:"event"}],Se="0xcA11bde05977b3631167028862bE2a173976CA11",ke={4114:"0x860aFc632a6D625B95d8B96f39ECC48E988c6962"},Te=new Set([5115]);function Ie(t){const e=ke[t.id]??(Te.has(t.id)?void 0:Se);return xe({id:t.id,name:t.name,nativeCurrency:t.nativeCurrency,rpcUrls:{default:{http:[t.rpcUrl]}},blockExplorers:{default:{name:t.displayName,url:t.blockExplorer}},testnet:t.network==="testnet",...e?{contracts:{multicall3:{address:e}}}:{}})}const Ue=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],R=Object.fromEntries(Ue.map(t=>D(t)).filter(t=>t!=null).map(t=>[t.id,{...t,viemChain:Ie(t),supportedTokens:he(t.id)}])),_e=R;let Y={};const M=new Map,H=t=>{Y={...t||{}},M.clear()},O=t=>{const e=Y[t];return e&&typeof e=="string"&&e.length>0?e:R[t]?.rpcUrl},E=t=>R[t],S=t=>{const e=D(t);return e?.displayName||e?.name||`Chain ${t}`},Ae=t=>{const e=ge(t);if(!e)throw new Error(`Unsupported chain ID: ${t}`);return e},Ne=(t,e,r)=>{const a=E(t);return a?.blockExplorer?`${a.blockExplorer}/tx/${e}`:"#"},J=t=>{const e=E(t);if(!e)throw new Error(`Unsupported chain ID: ${t}`);const r=O(t);if(!r)throw new Error(`No RPC URL configured for chain ID: ${t}`);const a=`${t}:${r}`,s=M.get(a);if(s)return s;const o=Be({chain:e.viemChain,transport:$e(r,{timeout:15e3,retryCount:2,retryDelay:300}),batch:{multicall:{wait:16}}});return M.set(a,o),o},Me=()=>{const t={};return Object.values(R).forEach(e=>{t[e.id]={name:e.name,moralisName:e.moralisId||"",chain:e.viemChain,rpcUrl:O(e.id)||e.rpcUrl}}),t},Oe=(t,e=[])=>{const r=E(t);if(!r)return[];const a=[];if(![11155111,421614,84532,688689].includes(t)){const o=e.find(i=>i.chainId===t&&i.isNative);o?a.push(o):a.push({address:ye,name:r.nativeCurrency.name,symbol:r.nativeCurrency.symbol,decimals:r.nativeCurrency.decimals,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,logoURI:void 0,isNative:!0,chainId:t})}if(!r.supportedTokens)return a;const s=a.some(o=>o.isNative);return r.supportedTokens.forEach(o=>{if(s&&N(o.address))return;const i=e.find(c=>c.chainId===t&&c.address.toLowerCase()===o.address.toLowerCase());i?a.push(i):a.push({address:o.address,name:o.name,symbol:o.symbol,decimals:o.decimals,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,logoURI:o.logo,isNative:!1,chainId:t})}),a},Pe=async(t,e)=>{const r=E(t);if(!r)throw new Error(`Unsupported chain ID: ${t}`);const a=e.toLowerCase();if(N(a)){if(!r.nativeCurrency?.decimals)throw new Error(`Native currency decimals not configured for chain ${t}`);return r.nativeCurrency.decimals}if(r.supportedTokens){const s=r.supportedTokens.find(o=>o.address.toLowerCase()===a);if(s)return s.decimals}try{if(!Ee(e,{strict:!1}))throw new Error(`Invalid token address: ${e}`);const s=ve(e),o=J(t),i=await Ce(o,{address:s,abi:z,functionName:"decimals"});return Number(i)}catch{throw new Error(`Could not determine decimals for token ${e} on chain ${t}`)}},G=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",X="__SPICEFLOW_RELAYER_API_URL__";function Fe(t,e){const r=e.match(/Output amount (\d+) is insufficient after fees (\d+) on chain (\d+)/);if(!r)return e;const[,a,s,o]=r,i=Number(o),c=BigInt(a),l=BigInt(s);let d;for(const u of t.intents){const w=u.chainBatches.find(v=>v.chainId===i);if(w){d=w;break}}const h=d?.tokenTransfers.find(u=>u.from==="escrow"&&u.to.toLowerCase()===t.user.toLowerCase()&&!N(u.token));if(!h)return`Amount is too small to cover the estimated fee on ${S(i)}.`;const p=be(h.token,i),y=p?.decimals??18,b=p?.symbol??"tokens",x=W(c,y),n=W(l,y);return`Amount is too small to cover the estimated fee on ${S(i)}. Amount: ${x} ${b}. Estimated fee: ${n} ${b}.`}function Le(){if(typeof globalThis>"u")return;const t=globalThis[X];return typeof t=="string"&&t.length>0?t:void 0}class je{constructor(){this.baseUrl=G}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[X]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return Le()||this.baseUrl}async createAction(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(a,s)=>typeof s=="bigint"?s.toString():s)});if(!r.ok){const a=await r.text();throw new f("RELAYER_ERROR",`Relayer API error: ${r.status} - ${a}`,{httpStatus:r.status,responseBody:a,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,(s,o)=>typeof o=="bigint"?o.toString():o)}),a=await r.json();if(!r.ok||!a.success||!a.data?.feeEstimate){const s=a.error?.message||`Relayer fee estimate error: ${r.status}`,o=Fe(e,s);throw new f("RELAYER_ERROR",o,{httpStatus:r.status,responseBody:JSON.stringify(a),endpoint:"/actions/fees/estimate"})}return a.data.feeEstimate}async estimateBatchGas(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions/gas/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(s,o)=>typeof o=="bigint"?o.toString():o)}),a=await r.json();if(!r.ok||!a.success||!a.data?.gasFee){const s=a.error?.message||`Relayer gas estimate error: ${r.status}`;throw new f("RELAYER_ERROR",s,{httpStatus:r.status,responseBody:JSON.stringify(a),endpoint:"/actions/gas/estimate"})}return{gasFee:BigInt(a.data.gasFee),gasQuoteSource:a.data.gasQuoteSource}}async executeStep(e,r,a,s){const o=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/${r}/steps/${a}`,i=fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});let c;try{c=await Promise.race([i,new Promise((l,d)=>setTimeout(()=>d(new f("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:e,intentIndex:r,stepIndex:a,endpoint:`/actions/${e}/intents/${r}/steps/${a}`})),1e4))])}catch(l){throw l}if(!c.ok){const l=await c.text();throw new f("RELAYER_EXECUTE_ERROR",`Execute step error: ${c.status} - ${l}`,{httpStatus:c.status,responseBody:l,endpoint:`/actions/${e}/intents/${r}/steps/${a}`,actionId:e})}return{success:!0,transactionHash:(await c.json()).transactionHash}}async checkStepStatus(e,r){const a=e.split("/");let s="";if(a.length>=2){const c=a[0],l=a[1];s=`${this.getEffectiveBaseUrl()}/actions/${c}/intents/${l}/steps/${r}`}else s=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/0/steps/${r}`;const o=await fetch(s);if(!o.ok)throw new f("RELAYER_STATUS_ERROR",`Intent step status check failed: ${o.status}`,{httpStatus:o.status,endpoint:s,intentId:e});const i=await o.json();return{success:!0,data:{status:i.status==="error"?"reverted":i.status,transactionHash:i.txid}}}async createWallet(e,r){const a=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!a.ok){const s=await a.text();throw new f("RELAYER_ERROR",`Create wallet error: ${a.status} - ${s}`,{httpStatus:a.status,endpoint:`/wallets/${e}`})}return a.json()}async getWallet(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`);if(!r.ok){const a=await r.text();throw new f("RELAYER_ERROR",`Get wallet error: ${r.status} - ${a}`,{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,(a,s)=>typeof s=="bigint"?s.toString():s)});if(!r.ok){const a=await r.text();throw new f("RELAYER_ERROR",`Create withdrawal error: ${r.status} - ${a}`,{httpStatus:r.status,endpoint:"/withdrawals"})}return r.json()}async getWithdrawal(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${e}`);if(!r.ok){const a=await r.text();throw new f("RELAYER_ERROR",`Get withdrawal error: ${r.status} - ${a}`,{httpStatus:r.status,endpoint:`/withdrawals/${e}`})}return r.json()}async getRollupTimestamp(){const e=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!e.ok)throw new f("RELAYER_ERROR",`Get rollup timestamp error: ${e.status}`,{httpStatus:e.status,endpoint:"/time"});return e.json()}}const g=new je,P=new Map;async function De(t,e){const r=t.toLowerCase(),a=P.get(r);if(a)return a;const s=(async()=>{try{await g.getWallet(t);return}catch{}const{unix_timestamp:o}=await g.getRollupTimestamp(),i=`I am creating a new smart wallet and adding an admin wallet ethereum:0x${t.slice(2).toLowerCase()}. Nonce: ${o}`,c=await e(i),l=typeof c=="string"?c:c.signature;if(!l)throw new Error("Wallet returned no smart wallet signature");await g.createWallet(t,{timestamp:o,signature:l})})();P.set(r,s);try{await s}finally{P.delete(r)}}const We=(t,e)=>{const r=s=>e?e(s):S(s),a=[];return t.forEach((s,o)=>{const i=s.calls&&s.calls.length>0,c=s.tokenTransfers&&s.tokenTransfers.length>0;if(i||c){const l={stepId:o,status:o===0?"processing":"pending",chainId:s.chainId,chainName:r(s.chainId),description:"Processing transaction"};a.push(l)}}),a},q="spiceflow-mode",Q=()=>{if(typeof window>"u")return null;try{const t=window.localStorage.getItem(q);return t==="embedded"?"7702":t==="external"?"ondemand":null}catch{return null}},ze=t=>{if(!(typeof window>"u"))try{window.localStorage.setItem(q,t==="7702"?"embedded":"external")}catch{}},Ye=()=>Q()!==null,Z=j(null),K=j(null),He=({children:t,provider:e,supportedChainIds:r,network:a="testnet",mode:s="7702",skipFlow:o=[],nativeChainId:i,appName:c="Spicenet",apiUrl:l,theme:d,rpcOverrides:h})=>{_(()=>{if(!l)return;const u=g.getBaseUrl();return g.setBaseUrl(l),()=>g.setBaseUrl(u)},[l]),_(()=>(H(h),()=>H(void 0)),[h]);const p=r??we(a),y=d??null,[b,x]=A(()=>Q()??s),n=ue(u=>{x(u),ze(u)},[]);return C(Z.Provider,{value:y,children:C(K.Provider,{value:{provider:e,supportedChainIds:p,skipFlow:o,mode:b,setMode:n,network:a,nativeChainId:i,appName:c,apiUrl:l,rpcOverrides:h},children:t})})},Je={spacing:{xs:"0.25rem",sm:"0.5rem",md:"1rem",lg:"1.5rem",xl:"2rem"},borderRadius:{sm:"0.25rem",md:"0.5rem",lg:"0.75rem",full:"9999px"},typography:{fontFamily:'"Helvetica Neue", sans-serif',fontSize:{xs:"0.75rem",sm:"0.875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem","2xl":"1.5rem","3xl":"1.75rem"},fontWeight:{normal:400,medium:500,semibold:600,bold:700}},shadows:{sm:"0 1px 2px 0 rgb(0 0 0 / 0.05)",md:"0 4px 6px -1px rgb(0 0 0 / 0.1)",lg:"0 10px 15px -3px rgb(0 0 0 / 0.1)"},animation:{fast:"150ms ease-in-out",normal:"200ms ease-in-out",slow:"300ms ease-in-out"}},Ge={primary:"#EA4B4B",primaryHover:"#E43838",secondary:"#f3f4f6",background:"#ffffff",surface:"#f9fafb",surfaceHover:"#f3f4f6",border:"#e5e7eb",borderHover:"#d1d5db",text:"#111827",textSecondary:"#374151",textMuted:"#6b7280",success:"#10b981",error:"#ef4444",warning:"#f59e0b",info:"#3b82f6"},Xe={primary:"#EA4B4B",primaryHover:"#E43838",secondary:"#171717",background:"#141414",surface:"#1e1e1e",surfaceHover:"#2a2a2a",border:"#2d2d2d",borderHover:"#3a3a3a",text:"#ffffff",textSecondary:"#888888",textMuted:"#666666",success:"#10b981",error:"#ef4444",warning:"#f59e0b",info:"#3b82f6"},V=(t="light")=>({mode:t,...Je,colors:t==="light"?Ge:Xe});function k(t,e){const r=t.replace("#",""),a=Math.max(0,Math.round(parseInt(r.substring(0,2),16)*(1-e))),s=Math.max(0,Math.round(parseInt(r.substring(2,4),16)*(1-e))),o=Math.max(0,Math.round(parseInt(r.substring(4,6),16)*(1-e)));return`#${a.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}function qe(t,e){return{shell:e?.shell??"#141414",shellBorder:e?.shellBorder??k(e?.shell??"#141414",.35),shellInnerBorder:e?.shellInnerBorder??k(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 Qe(t){return{shell:"#ffffff",shellBorder:"#E9E9E9",shellInnerBorder:"#D5D5D5",cardBg:"#f9fafb",inputBg:"#ffffff",hoverBg:"#f3f4f6",textPrimary:"#111827",textSecondary:"#6b7280",inputText:"#111827",inputPlaceholder:"#9ca3af",cardBorder:"#e5e7eb",inputBorder:"#d1d5db",buttonBorder:"#0e0d0b",successBg:"#d1fae5",successBorder:"#6ee7b7",successText:"#065f46",warningBg:"#fef3c7",warningBorder:"#fde68a",warningText:"#92400e",errorBg:"#fef2f2",errorBorder:"#fecaca",errorText:"#dc2626",infoBg:"#dbeafe",infoBorder:"#93c5fd",infoText:"#1e40af"}}function ee(t,e){const r=e?{...t,...e}:t,a=r.dark??!1,s=r.primaryColor,o=r.shell??(a?"#141414":"#ffffff");return{primaryColor:s,dark:a,fontFamily:r.fontFamily??'"Helvetica Neue", sans-serif',appName:r.appName??"Spicenet",logo:r.logo,borderRadius:r.borderRadius??"8px",shell:o,shellBorder:k(o,a?.35:.085),shellInnerBorder:k(o,a?.55:.165),card:r.card??(a?"#1e1e1e":"#f9fafb"),input:a?"#171717":"#ffffff",hover:a?"#2a2a2a":"#f3f4f6",text:r.text??(a?"#ffffff":"#111827"),textMuted:r.textMuted??(a?"#888888":"#6b7280"),inputText:a?"#e0e0e0":"#111827",inputPlaceholder:a?"#555555":"#9ca3af",border:r.border??(a?"rgba(255,255,255,0.08)":"#e5e7eb"),inputBorder:a?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:a?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:a?"#0a1f18":"#d1fae5",successBorder:a?"#1a4a3a":"#6ee7b7",successText:a?"#6ee7b7":"#065f46",warningBg:a?"#1f1a0d":"#fef3c7",warningBorder:a?"#4a3820":"#fde68a",warningText:a?"#fbbf24":"#92400e",errorBg:a?"#1f0d0d":"#fef2f2",errorBorder:a?"#4a2020":"#fecaca",errorText:a?"#f87171":"#dc2626",infoBg:a?"#0d1325":"#dbeafe",infoBorder:a?"#2a3a5a":"#93c5fd",infoText:a?"#60a5fa":"#1e40af"}}function te(t,e){const r=fe(Z)??void 0;return pe(()=>{const a=r??{primaryColor:"#EA4B4B"},s={...t?.primaryColor?{primaryColor:t.primaryColor}:{},...t?.fontFamily?{fontFamily:t.fontFamily}:{},...e!==void 0?{dark:e}:{}},o=ee(a,s),{dark:i,primaryColor:c,appName:l}=o,d=V(i?"dark":"light"),h={...d,colors:{...d.colors,primary:c,primaryHover:`${c}dd`},typography:{...d.typography,fontFamily:o.fontFamily}},p={shell:o.shell,shellBorder:o.shellBorder,shellInnerBorder:o.shellInnerBorder,cardBg:o.card,inputBg:o.input,hoverBg:o.hover,textPrimary:o.text,textSecondary:o.textMuted,inputText:o.inputText,inputPlaceholder:o.inputPlaceholder,cardBorder:o.border,inputBorder:o.inputBorder,buttonBorder:o.buttonBorder,successBg:o.successBg,successBorder:o.successBorder,successText:o.successText,warningBg:o.warningBg,warningBorder:o.warningBorder,warningText:o.warningText,errorBg:o.errorBg,errorBorder:o.errorBorder,errorText:o.errorText,infoBg:o.infoBg,infoBorder:o.infoBorder,infoText:o.infoText};return{brand:r,theme:h,dark:i,appName:l,primaryColor:c,dk:p,palette:p}},[r,t,e])}const re="spiceflow-spinner-keyframes";function Ze(){if(typeof document>"u"||document.getElementById(re))return;const t=document.createElement("style");t.id=re,t.textContent="@keyframes spiceflow-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}",document.head.appendChild(t)}const ae=({size:t=16,borderWidth:e=2,color:r="currentColor",style:a})=>{const s=me(!1);return _(()=>{s.current||(Ze(),s.current=!0)},[]),C("div",{role:"status","aria-label":"Loading",style:{width:`${t}px`,height:`${t}px`,border:`${e}px solid ${r}`,borderTop:`${e}px solid transparent`,borderRadius:"50%",animation:"spiceflow-spin 1s linear infinite",flexShrink:0,...a}})},Ke=({variant:t="primary",size:e="md",loading:r=!1,fullWidth:a=!1,disabled:s,children:o,className:i="",style:c,theme:l,styles:d,dark:h,...p})=>{const{theme:y,dark:b,palette:x}=te(d,h),n=l||y,u=h??b,[w,v]=A(!1),[T,I]=A(!1),U=u?x.shell:"white",oe=()=>{switch(t){case"primary":return{backgroundColor:d?.button?.backgroundColor||n.colors.primary,color:d?.button?.color||"#ffffff",border:`1px solid ${d?.button?.backgroundColor||n.colors.primary}`};case"secondary":return{backgroundColor:n.colors.secondary,color:n.colors.text,border:`1px solid ${n.colors.border}`};case"success":return{backgroundColor:n.colors.success,color:n.colors.text,border:`1px solid ${n.colors.success}`};case"error":return{backgroundColor:n.colors.error,color:n.colors.text,border:`1px solid ${n.colors.error}`};case"ghost":return{backgroundColor:"transparent",color:n.colors.textSecondary,border:`1px solid ${n.colors.border}`};case"outline":{const m=d?.button?.backgroundColor||n.colors.primary,L=d?.button?.color||(u?"#ffffff":"#0e0d0b"),B=d?.button?.borderColor||(u?`${n.colors.primary}88`:"#0e0d0b"),$=s||r,ie=u?"1px":"1.5px",ce=d?.button?.disabledBackgroundColor||`${m}88`,de=d?.button?.disabledColor||L;return{height:"56px",backgroundColor:$?ce:T?`${m}cc`:w?`${m}ee`:m,color:$?de:L,border:`${ie} solid ${B}`,borderRadius:d?.button?.borderRadius||"12px",fontSize:"22px",fontWeight:500,fontFamily:'"IBM Plex Mono", monospace',opacity:$?.78:1,transform:$?"none":T?"scale(0.98)":w?"translateY(-2px)":"none",boxShadow:$?`3px 3px 0px ${U}, 4px 4px 0px ${B}`:T?`2px 2px 0px ${B}`:w?`5px 5px 0px ${U}, 6px 6px 0px ${B}`:`3px 3px 0px ${U}, 4px 4px 0px ${B}`,transition:"transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease, border-color 150ms ease, color 150ms ease"}}default:return{}}},se=()=>{if(t==="outline")return{};switch(e){case"sm":return{padding:`${n.spacing.sm} ${n.spacing.md}`,fontSize:n.typography.fontSize.sm};case"md":return{padding:`${n.spacing.md} ${n.spacing.lg}`,fontSize:n.typography.fontSize.base};case"lg":return{padding:`${n.spacing.lg} ${n.spacing.xl}`,fontSize:n.typography.fontSize.lg};default:return{}}},ne={borderRadius:d?.button?.borderRadius||n.borderRadius.md,fontWeight:d?.button?.fontWeight||n.typography.fontWeight.medium,fontFamily:d?.button?.fontFamily||n.typography.fontFamily,fontSize:d?.button?.fontSize||void 0,transition:"background-color 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease",cursor:s||r?"not-allowed":"pointer",opacity:(s||r)&&t!=="outline"?.6:1,width:a?"100%":"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:n.spacing.sm,...oe(),...se(),...d?.button?.fontSize&&{fontSize:d.button.fontSize}},F=s||r;return le("button",{type:p.type??"button","data-spiceflow-focus":!0,"aria-busy":r||void 0,"aria-disabled":F||void 0,style:{...ne,...c},className:i,disabled:F,onMouseEnter:m=>{v(!0),p.onMouseEnter?.(m)},onMouseLeave:m=>{v(!1),I(!1),p.onMouseLeave?.(m)},onMouseDown:m=>{I(!0),p.onMouseDown?.(m)},onMouseUp:m=>{I(!1),p.onMouseUp?.(m)},...p,children:[r&&C(ae,{size:16}),o]})};export{Ke as B,_e as C,G as R,ae as S,Me as a,J as b,V as c,K as d,De as e,S as f,E as g,Ne as h,Re as i,z as j,Oe as k,O as l,Ae as m,Pe as n,We as o,f as p,Ye as q,g as r,He as s,ee as t,te as u,qe as v,Qe as w};
|
package/dist/Button-MVjcEXYc.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";const v=require("react/jsx-runtime"),h=require("react"),y=require("@spicenet-io/spiceflow-core"),b=require("viem"),ie=require("viem/actions");class f extends Error{constructor(e,r,a={}){super(r),this.code=e,this.context=a,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,f)}}function ce(t){return t instanceof f}const j=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"owner",type:"address"},{indexed:!0,name:"spender",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"from",type:"address"},{indexed:!0,name:"to",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Transfer",type:"event"}],le="0xcA11bde05977b3631167028862bE2a173976CA11",de={4114:"0x860aFc632a6D625B95d8B96f39ECC48E988c6962"},ue=new Set([5115]);function fe(t){const e=de[t.id]??(ue.has(t.id)?void 0:le);return b.defineChain({id:t.id,name:t.name,nativeCurrency:t.nativeCurrency,rpcUrls:{default:{http:[t.rpcUrl]}},blockExplorers:{default:{name:t.displayName,url:t.blockExplorer}},testnet:t.network==="testnet",...e?{contracts:{multicall3:{address:e}}}:{}})}const pe=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],k=Object.fromEntries(pe.map(t=>y.getChainMeta(t)).filter(t=>t!=null).map(t=>[t.id,{...t,viemChain:fe(t),supportedTokens:y.getTokensForChain(t.id)}])),me=k;let D={};const F=new Map,W=t=>{D={...t||{}},F.clear()},M=t=>{const e=D[t];return e&&typeof e=="string"&&e.length>0?e:k[t]?.rpcUrl},R=t=>k[t],I=t=>{const e=y.getChainMeta(t);return e?.displayName||e?.name||`Chain ${t}`},he=t=>{const e=y.getDelegateContract(t);if(!e)throw new Error(`Unsupported chain ID: ${t}`);return e},ge=(t,e,r)=>{const a=R(t);return a?.blockExplorer?`${a.blockExplorer}/tx/${e}`:"#"},z=t=>{const e=R(t);if(!e)throw new Error(`Unsupported chain ID: ${t}`);const r=M(t);if(!r)throw new Error(`No RPC URL configured for chain ID: ${t}`);const a=`${t}:${r}`,n=F.get(a);if(n)return n;const o=b.createPublicClient({chain:e.viemChain,transport:b.http(r,{timeout:15e3,retryCount:2,retryDelay:300}),batch:{multicall:{wait:16}}});return F.set(a,o),o},ye=()=>{const t={};return Object.values(k).forEach(e=>{t[e.id]={name:e.name,moralisName:e.moralisId||"",chain:e.viemChain,rpcUrl:M(e.id)||e.rpcUrl}}),t},be=(t,e=[])=>{const r=R(t);if(!r)return[];const a=[];if(![11155111,421614,84532,688689].includes(t)){const o=e.find(i=>i.chainId===t&&i.isNative);o?a.push(o):a.push({address:y.ZERO_ADDRESS,name:r.nativeCurrency.name,symbol:r.nativeCurrency.symbol,decimals:r.nativeCurrency.decimals,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,logoURI:void 0,isNative:!0,chainId:t})}if(!r.supportedTokens)return a;const n=a.some(o=>o.isNative);return r.supportedTokens.forEach(o=>{if(n&&y.isNativeToken(o.address))return;const i=e.find(c=>c.chainId===t&&c.address.toLowerCase()===o.address.toLowerCase());i?a.push(i):a.push({address:o.address,name:o.name,symbol:o.symbol,decimals:o.decimals,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,logoURI:o.logo,isNative:!1,chainId:t})}),a},we=async(t,e)=>{const r=R(t);if(!r)throw new Error(`Unsupported chain ID: ${t}`);const a=e.toLowerCase();if(y.isNativeToken(a)){if(!r.nativeCurrency?.decimals)throw new Error(`Native currency decimals not configured for chain ${t}`);return r.nativeCurrency.decimals}if(r.supportedTokens){const n=r.supportedTokens.find(o=>o.address.toLowerCase()===a);if(n)return n.decimals}try{if(!b.isAddress(e,{strict:!1}))throw new Error(`Invalid token address: ${e}`);const n=b.getAddress(e),o=z(t),i=await ie.readContract(o,{address:n,abi:j,functionName:"decimals"});return Number(i)}catch{throw new Error(`Could not determine decimals for token ${e} on chain ${t}`)}},Y=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",H="__SPICEFLOW_RELAYER_API_URL__";function xe(t,e){const r=e.match(/Output amount (\d+) is insufficient after fees (\d+) on chain (\d+)/);if(!r)return e;const[,a,n,o]=r,i=Number(o),c=BigInt(a),d=BigInt(n);let l;for(const u of t.intents){const E=u.chainBatches.find(T=>T.chainId===i);if(E){l=E;break}}const g=l?.tokenTransfers.find(u=>u.from==="escrow"&&u.to.toLowerCase()===t.user.toLowerCase()&&!y.isNativeToken(u.token));if(!g)return`Amount is too small to cover the estimated fee on ${I(i)}.`;const p=y.getTokenByAddress(g.token,i),x=p?.decimals??18,B=p?.symbol??"tokens",$=b.formatUnits(c,x),s=b.formatUnits(d,x);return`Amount is too small to cover the estimated fee on ${I(i)}. Amount: ${$} ${B}. Estimated fee: ${s} ${B}.`}function Be(){if(typeof globalThis>"u")return;const t=globalThis[H];return typeof t=="string"&&t.length>0?t:void 0}class Ee{constructor(){this.baseUrl=Y}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[H]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return Be()||this.baseUrl}async createAction(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(a,n)=>typeof n=="bigint"?n.toString():n)});if(!r.ok){const a=await r.text();throw new f("RELAYER_ERROR",`Relayer API error: ${r.status} - ${a}`,{httpStatus:r.status,responseBody:a,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,(n,o)=>typeof o=="bigint"?o.toString():o)}),a=await r.json();if(!r.ok||!a.success||!a.data?.feeEstimate){const n=a.error?.message||`Relayer fee estimate error: ${r.status}`,o=xe(e,n);throw new f("RELAYER_ERROR",o,{httpStatus:r.status,responseBody:JSON.stringify(a),endpoint:"/actions/fees/estimate"})}return a.data.feeEstimate}async estimateBatchGas(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions/gas/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(n,o)=>typeof o=="bigint"?o.toString():o)}),a=await r.json();if(!r.ok||!a.success||!a.data?.gasFee){const n=a.error?.message||`Relayer gas estimate error: ${r.status}`;throw new f("RELAYER_ERROR",n,{httpStatus:r.status,responseBody:JSON.stringify(a),endpoint:"/actions/gas/estimate"})}return{gasFee:BigInt(a.data.gasFee),gasQuoteSource:a.data.gasQuoteSource}}async executeStep(e,r,a,n){const o=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/${r}/steps/${a}`,i=fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});let c;try{c=await Promise.race([i,new Promise((d,l)=>setTimeout(()=>l(new f("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:e,intentIndex:r,stepIndex:a,endpoint:`/actions/${e}/intents/${r}/steps/${a}`})),1e4))])}catch(d){throw d}if(!c.ok){const d=await c.text();throw new f("RELAYER_EXECUTE_ERROR",`Execute step error: ${c.status} - ${d}`,{httpStatus:c.status,responseBody:d,endpoint:`/actions/${e}/intents/${r}/steps/${a}`,actionId:e})}return{success:!0,transactionHash:(await c.json()).transactionHash}}async checkStepStatus(e,r){const a=e.split("/");let n="";if(a.length>=2){const c=a[0],d=a[1];n=`${this.getEffectiveBaseUrl()}/actions/${c}/intents/${d}/steps/${r}`}else n=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/0/steps/${r}`;const o=await fetch(n);if(!o.ok)throw new f("RELAYER_STATUS_ERROR",`Intent step status check failed: ${o.status}`,{httpStatus:o.status,endpoint:n,intentId:e});const i=await o.json();return{success:!0,data:{status:i.status==="error"?"reverted":i.status,transactionHash:i.txid}}}async createWallet(e,r){const a=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!a.ok){const n=await a.text();throw new f("RELAYER_ERROR",`Create wallet error: ${a.status} - ${n}`,{httpStatus:a.status,endpoint:`/wallets/${e}`})}return a.json()}async getWallet(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`);if(!r.ok){const a=await r.text();throw new f("RELAYER_ERROR",`Get wallet error: ${r.status} - ${a}`,{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,(a,n)=>typeof n=="bigint"?n.toString():n)});if(!r.ok){const a=await r.text();throw new f("RELAYER_ERROR",`Create withdrawal error: ${r.status} - ${a}`,{httpStatus:r.status,endpoint:"/withdrawals"})}return r.json()}async getWithdrawal(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${e}`);if(!r.ok){const a=await r.text();throw new f("RELAYER_ERROR",`Get withdrawal error: ${r.status} - ${a}`,{httpStatus:r.status,endpoint:`/withdrawals/${e}`})}return r.json()}async getRollupTimestamp(){const e=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!e.ok)throw new f("RELAYER_ERROR",`Get rollup timestamp error: ${e.status}`,{httpStatus:e.status,endpoint:"/time"});return e.json()}}const w=new Ee,P=new Map;async function $e(t,e){const r=t.toLowerCase(),a=P.get(r);if(a)return a;const n=(async()=>{try{await w.getWallet(t);return}catch{}const{unix_timestamp:o}=await w.getRollupTimestamp(),i=`I am creating a new smart wallet and adding an admin wallet ethereum:0x${t.slice(2).toLowerCase()}. Nonce: ${o}`,c=await e(i),d=typeof c=="string"?c:c.signature;if(!d)throw new Error("Wallet returned no smart wallet signature");await w.createWallet(t,{timestamp:o,signature:d})})();P.set(r,n);try{await n}finally{P.delete(r)}}const Ce=(t,e)=>{const r=n=>e?e(n):I(n),a=[];return t.forEach((n,o)=>{const i=n.calls&&n.calls.length>0,c=n.tokenTransfers&&n.tokenTransfers.length>0;if(i||c){const d={stepId:o,status:o===0?"processing":"pending",chainId:n.chainId,chainName:r(n.chainId),description:"Processing transaction"};a.push(d)}}),a},J="spiceflow-mode",G=()=>{if(typeof window>"u")return null;try{const t=window.localStorage.getItem(J);return t==="embedded"?"7702":t==="external"?"ondemand":null}catch{return null}},Se=t=>{if(!(typeof window>"u"))try{window.localStorage.setItem(J,t==="7702"?"embedded":"external")}catch{}},ve=()=>G()!==null,q=h.createContext(null),X=h.createContext(null),Re=({children:t,provider:e,supportedChainIds:r,network:a="testnet",mode:n="7702",skipFlow:o=[],nativeChainId:i,appName:c="Spicenet",apiUrl:d,theme:l,rpcOverrides:g})=>{h.useEffect(()=>{if(!d)return;const u=w.getBaseUrl();return w.setBaseUrl(d),()=>w.setBaseUrl(u)},[d]),h.useEffect(()=>(W(g),()=>W(void 0)),[g]);const p=r??y.getChainIdsByNetwork(a),x=l??null,[B,$]=h.useState(()=>G()??n),s=h.useCallback(u=>{$(u),Se(u)},[]);return v.jsx(q.Provider,{value:x,children:v.jsx(X.Provider,{value:{provider:e,supportedChainIds:p,skipFlow:o,mode:B,setMode:s,network:a,nativeChainId:i,appName:c,apiUrl:d,rpcOverrides:g},children:t})})},Te={spacing:{xs:"0.25rem",sm:"0.5rem",md:"1rem",lg:"1.5rem",xl:"2rem"},borderRadius:{sm:"0.25rem",md:"0.5rem",lg:"0.75rem",full:"9999px"},typography:{fontFamily:'"Helvetica Neue", sans-serif',fontSize:{xs:"0.75rem",sm:"0.875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem","2xl":"1.5rem","3xl":"1.75rem"},fontWeight:{normal:400,medium:500,semibold:600,bold:700}},shadows:{sm:"0 1px 2px 0 rgb(0 0 0 / 0.05)",md:"0 4px 6px -1px rgb(0 0 0 / 0.1)",lg:"0 10px 15px -3px rgb(0 0 0 / 0.1)"},animation:{fast:"150ms ease-in-out",normal:"200ms ease-in-out",slow:"300ms ease-in-out"}},ke={primary:"#EA4B4B",primaryHover:"#E43838",secondary:"#f3f4f6",background:"#ffffff",surface:"#f9fafb",surfaceHover:"#f3f4f6",border:"#e5e7eb",borderHover:"#d1d5db",text:"#111827",textSecondary:"#374151",textMuted:"#6b7280",success:"#10b981",error:"#ef4444",warning:"#f59e0b",info:"#3b82f6"},Ie={primary:"#EA4B4B",primaryHover:"#E43838",secondary:"#171717",background:"#141414",surface:"#1e1e1e",surfaceHover:"#2a2a2a",border:"#2d2d2d",borderHover:"#3a3a3a",text:"#ffffff",textSecondary:"#888888",textMuted:"#666666",success:"#10b981",error:"#ef4444",warning:"#f59e0b",info:"#3b82f6"},Q=(t="light")=>({mode:t,...Te,colors:t==="light"?ke:Ie});function U(t,e){const r=t.replace("#",""),a=Math.max(0,Math.round(parseInt(r.substring(0,2),16)*(1-e))),n=Math.max(0,Math.round(parseInt(r.substring(2,4),16)*(1-e))),o=Math.max(0,Math.round(parseInt(r.substring(4,6),16)*(1-e)));return`#${a.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}function Ue(t,e){return{shell:e?.shell??"#141414",shellBorder:e?.shellBorder??U(e?.shell??"#141414",.35),shellInnerBorder:e?.shellInnerBorder??U(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 Ae(t){return{shell:"#ffffff",shellBorder:"#E9E9E9",shellInnerBorder:"#D5D5D5",cardBg:"#f9fafb",inputBg:"#ffffff",hoverBg:"#f3f4f6",textPrimary:"#111827",textSecondary:"#6b7280",inputText:"#111827",inputPlaceholder:"#9ca3af",cardBorder:"#e5e7eb",inputBorder:"#d1d5db",buttonBorder:"#0e0d0b",successBg:"#d1fae5",successBorder:"#6ee7b7",successText:"#065f46",warningBg:"#fef3c7",warningBorder:"#fde68a",warningText:"#92400e",errorBg:"#fef2f2",errorBorder:"#fecaca",errorText:"#dc2626",infoBg:"#dbeafe",infoBorder:"#93c5fd",infoText:"#1e40af"}}function Z(t,e){const r=e?{...t,...e}:t,a=r.dark??!1,n=r.primaryColor,o=r.shell??(a?"#141414":"#ffffff");return{primaryColor:n,dark:a,fontFamily:r.fontFamily??'"Helvetica Neue", sans-serif',appName:r.appName??"Spicenet",logo:r.logo,borderRadius:r.borderRadius??"8px",shell:o,shellBorder:U(o,a?.35:.085),shellInnerBorder:U(o,a?.55:.165),card:r.card??(a?"#1e1e1e":"#f9fafb"),input:a?"#171717":"#ffffff",hover:a?"#2a2a2a":"#f3f4f6",text:r.text??(a?"#ffffff":"#111827"),textMuted:r.textMuted??(a?"#888888":"#6b7280"),inputText:a?"#e0e0e0":"#111827",inputPlaceholder:a?"#555555":"#9ca3af",border:r.border??(a?"rgba(255,255,255,0.08)":"#e5e7eb"),inputBorder:a?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:a?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:a?"#0a1f18":"#d1fae5",successBorder:a?"#1a4a3a":"#6ee7b7",successText:a?"#6ee7b7":"#065f46",warningBg:a?"#1f1a0d":"#fef3c7",warningBorder:a?"#4a3820":"#fde68a",warningText:a?"#fbbf24":"#92400e",errorBg:a?"#1f0d0d":"#fef2f2",errorBorder:a?"#4a2020":"#fecaca",errorText:a?"#f87171":"#dc2626",infoBg:a?"#0d1325":"#dbeafe",infoBorder:a?"#2a3a5a":"#93c5fd",infoText:a?"#60a5fa":"#1e40af"}}function K(t,e){const r=h.useContext(q)??void 0;return h.useMemo(()=>{const a=r??{primaryColor:"#EA4B4B"},n={...t?.primaryColor?{primaryColor:t.primaryColor}:{},...t?.fontFamily?{fontFamily:t.fontFamily}:{},...e!==void 0?{dark:e}:{}},o=Z(a,n),{dark:i,primaryColor:c,appName:d}=o,l=Q(i?"dark":"light"),g={...l,colors:{...l.colors,primary:c,primaryHover:`${c}dd`},typography:{...l.typography,fontFamily:o.fontFamily}},p={shell:o.shell,shellBorder:o.shellBorder,shellInnerBorder:o.shellInnerBorder,cardBg:o.card,inputBg:o.input,hoverBg:o.hover,textPrimary:o.text,textSecondary:o.textMuted,inputText:o.inputText,inputPlaceholder:o.inputPlaceholder,cardBorder:o.border,inputBorder:o.inputBorder,buttonBorder:o.buttonBorder,successBg:o.successBg,successBorder:o.successBorder,successText:o.successText,warningBg:o.warningBg,warningBorder:o.warningBorder,warningText:o.warningText,errorBg:o.errorBg,errorBorder:o.errorBorder,errorText:o.errorText,infoBg:o.infoBg,infoBorder:o.infoBorder,infoText:o.infoText};return{brand:r,theme:g,dark:i,appName:d,primaryColor:c,dk:p,palette:p}},[r,t,e])}const V="spiceflow-spinner-keyframes";function Ne(){if(typeof document>"u"||document.getElementById(V))return;const t=document.createElement("style");t.id=V,t.textContent="@keyframes spiceflow-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}",document.head.appendChild(t)}const ee=({size:t=16,borderWidth:e=2,color:r="currentColor",style:a})=>{const n=h.useRef(!1);return h.useEffect(()=>{n.current||(Ne(),n.current=!0)},[]),v.jsx("div",{role:"status","aria-label":"Loading",style:{width:`${t}px`,height:`${t}px`,border:`${e}px solid ${r}`,borderTop:`${e}px solid transparent`,borderRadius:"50%",animation:"spiceflow-spin 1s linear infinite",flexShrink:0,...a}})},_e=({variant:t="primary",size:e="md",loading:r=!1,fullWidth:a=!1,disabled:n,children:o,className:i="",style:c,theme:d,styles:l,dark:g,...p})=>{const{theme:x,dark:B,palette:$}=K(l,g),s=d||x,u=g??B,[E,T]=h.useState(!1),[A,N]=h.useState(!1),_=u?$.shell:"white",te=()=>{switch(t){case"primary":return{backgroundColor:l?.button?.backgroundColor||s.colors.primary,color:l?.button?.color||"#ffffff",border:`1px solid ${l?.button?.backgroundColor||s.colors.primary}`};case"secondary":return{backgroundColor:s.colors.secondary,color:s.colors.text,border:`1px solid ${s.colors.border}`};case"success":return{backgroundColor:s.colors.success,color:s.colors.text,border:`1px solid ${s.colors.success}`};case"error":return{backgroundColor:s.colors.error,color:s.colors.text,border:`1px solid ${s.colors.error}`};case"ghost":return{backgroundColor:"transparent",color:s.colors.textSecondary,border:`1px solid ${s.colors.border}`};case"outline":{const m=l?.button?.backgroundColor||s.colors.primary,L=l?.button?.color||(u?"#ffffff":"#0e0d0b"),C=l?.button?.borderColor||(u?`${s.colors.primary}88`:"#0e0d0b"),S=n||r,oe=u?"1px":"1.5px",ne=l?.button?.disabledBackgroundColor||`${m}88`,se=l?.button?.disabledColor||L;return{height:"56px",backgroundColor:S?ne:A?`${m}cc`:E?`${m}ee`:m,color:S?se:L,border:`${oe} solid ${C}`,borderRadius:l?.button?.borderRadius||"12px",fontSize:"22px",fontWeight:500,fontFamily:'"IBM Plex Mono", monospace',opacity:S?.78:1,transform:S?"none":A?"scale(0.98)":E?"translateY(-2px)":"none",boxShadow:S?`3px 3px 0px ${_}, 4px 4px 0px ${C}`:A?`2px 2px 0px ${C}`:E?`5px 5px 0px ${_}, 6px 6px 0px ${C}`:`3px 3px 0px ${_}, 4px 4px 0px ${C}`,transition:"transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease, border-color 150ms ease, color 150ms ease"}}default:return{}}},re=()=>{if(t==="outline")return{};switch(e){case"sm":return{padding:`${s.spacing.sm} ${s.spacing.md}`,fontSize:s.typography.fontSize.sm};case"md":return{padding:`${s.spacing.md} ${s.spacing.lg}`,fontSize:s.typography.fontSize.base};case"lg":return{padding:`${s.spacing.lg} ${s.spacing.xl}`,fontSize:s.typography.fontSize.lg};default:return{}}},ae={borderRadius:l?.button?.borderRadius||s.borderRadius.md,fontWeight:l?.button?.fontWeight||s.typography.fontWeight.medium,fontFamily:l?.button?.fontFamily||s.typography.fontFamily,fontSize:l?.button?.fontSize||void 0,transition:"background-color 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease",cursor:n||r?"not-allowed":"pointer",opacity:(n||r)&&t!=="outline"?.6:1,width:a?"100%":"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:s.spacing.sm,...te(),...re(),...l?.button?.fontSize&&{fontSize:l.button.fontSize}},O=n||r;return v.jsxs("button",{type:p.type??"button","data-spiceflow-focus":!0,"aria-busy":r||void 0,"aria-disabled":O||void 0,style:{...ae,...c},className:i,disabled:O,onMouseEnter:m=>{T(!0),p.onMouseEnter?.(m)},onMouseLeave:m=>{T(!1),N(!1),p.onMouseLeave?.(m)},onMouseDown:m=>{N(!0),p.onMouseDown?.(m)},onMouseUp:m=>{N(!1),p.onMouseUp?.(m)},...p,children:[r&&v.jsx(ee,{size:16}),o]})};exports.Button=_e,exports.CHAIN_CONFIGS=me,exports.RELAYER_API_URL=Y,exports.SpiceFlowProvider=Re,exports.SpiceFlowProviderContext=X,exports.SpiceflowError=f,exports.Spinner=ee,exports.buildDarkPalette=Ue,exports.buildLightPalette=Ae,exports.createInitialSteps=Ce,exports.createTheme=Q,exports.ensureSmartWallet=$e,exports.getAllAssetsForChain=be,exports.getChainConfig=R,exports.getChainName=I,exports.getChainsForAssets=ye,exports.getClientForChain=z,exports.getDelegateContractAddress=he,exports.getExplorerUrl=ge,exports.getRpcUrlForChain=M,exports.getTokenDecimals=we,exports.hasStoredSpiceFlowMode=ve,exports.isSpiceflowError=ce,exports.j=j,exports.relayerService=w,exports.resolveTheme=Z,exports.useSpiceBrand=K;
|