@spicenet-io/spiceflow-ui 3.2.3 → 3.3.0
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-Hm-OAnzQ.js → Button-MVjcEXYc.js} +1 -1
- package/dist/auth-dynamic.cjs.js +1 -1
- package/dist/auth-privy.cjs.js +1 -1
- package/dist/index.cjs.js +8 -8
- package/dist/index.js +8 -8
- package/dist/{providerWallet-Ca-gOLIW.js → providerWallet-BUP1lSjN.js} +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
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}`:"#"},Y=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=Y(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}`)}},z=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=z}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=z,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=Y,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;
|
|
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;
|
package/dist/auth-dynamic.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";const e=require("react/jsx-runtime"),c=require("react"),t=require("./Button-
|
|
2
|
+
"use strict";const e=require("react/jsx-runtime"),c=require("react"),t=require("./Button-MVjcEXYc.js"),W=require("@dynamic-labs/sdk-react-core"),k=require("./providerWallet-BUP1lSjN.js");require("@spicenet-io/spiceflow-core"),require("viem"),require("viem/actions");const q=({onAuthSuccess:a,onAuthError:r,theme:h="light",className:i="",buttonText:o="Login with Dynamic",autoTrigger:l=!1})=>{const s=t.createTheme(h),[m,D]=c.useState(!1),[g,S]=c.useState(!1),w=W.useDynamicContext(),{user:E,primaryWallet:f,connectedWallets:b,handleLogOut:C,setShowAuthFlow:x,sdkHasLoaded:p,showAuthFlow:j}=w,n=(k.getDynamicEmbeddedWallet({connectedWallets:b,primaryWallet:f})||f)?.address,v=!!E,d=v&&!!n;c.useEffect(()=>{D(!0)},[]),c.useEffect(()=>{d&&n&&a&&a(n)},[d,n,a]),c.useEffect(()=>{l&&p&&m&&!d&&!j&&!g&&(S(!0),x(!0))},[l,p,m,d,j,g,x]);const N=()=>{try{x(!0)}catch(y){const u=`Dynamic login failed: ${String(y)}`;r?r(u):console.error(u)}},L=async()=>{try{await C()}catch(y){const u=`Dynamic logout failed: ${String(y)}`;r?r(u):console.error(u)}};return m?p?v&&!n?e.jsx("div",{className:i,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[e.jsx(t.Spinner,{size:40,borderWidth:3,color:s.colors.primary}),e.jsx("p",{style:{color:s.colors.textMuted,fontSize:"14px"},children:"Finishing wallet setup..."})]})}):d&&n?e.jsx("div",{className:i,children:e.jsxs(t.Button,{variant:"primary",onClick:L,theme:s,children:["Logout (",n.slice(0,6),"...",n.slice(-4),")"]})}):l?e.jsx("div",{className:i,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[e.jsx(t.Spinner,{size:40,borderWidth:3,color:s.colors.primary}),e.jsx("p",{style:{color:s.colors.textMuted,fontSize:"14px"},children:"Opening login..."})]})}):e.jsx("div",{className:i,children:e.jsx(t.Button,{variant:"primary",onClick:N,theme:s,children:o})}):e.jsx("div",{className:i,children:e.jsx(t.Button,{variant:"primary",disabled:!0,theme:s,children:"Loading..."})}):e.jsx("div",{className:i,children:e.jsx(t.Button,{variant:"primary",disabled:!0,theme:s,children:o})})};class B extends c.Component{constructor(r){super(r),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback:this.props.children}}const F=a=>{const{theme:r="light",className:h="",buttonText:i="Login with Dynamic",onAuthError:o}=a,l=t.createTheme(r);return e.jsx(B,{fallback:e.jsx("div",{className:h,children:e.jsx(t.Button,{variant:"primary",onClick:()=>{o&&o('DynamicLogin must be used within SpiceFlowProvider provider="dynamic" and a mounted DynamicContextProvider.')},theme:l,children:i})}),children:e.jsx(q,{...a})})};exports.DynamicLogin=F;
|
package/dist/auth-privy.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";const e=require("react/jsx-runtime"),o=require("react"),c=require("./Button-
|
|
2
|
+
"use strict";const e=require("react/jsx-runtime"),o=require("react"),c=require("./Button-MVjcEXYc.js"),f=require("@privy-io/react-auth");require("@spicenet-io/spiceflow-core"),require("viem"),require("viem/actions");const S=({onAuthSuccess:d,onAuthError:a,theme:v="light",className:l="",buttonText:g="Login with Privy",autoTrigger:h=!1})=>{const u=c.createTheme(v),[m,j]=o.useState(!1),[x,p]=o.useState(!1),{ready:i,authenticated:n,user:r}=f.usePrivy(),{login:L}=f.useLogin(),{logout:b}=f.useLogout();o.useEffect(()=>{j(!0)},[]),o.useEffect(()=>{h&&i&&!n&&m&&!x&&(p(!0),y())},[h,i,n,m,x]),o.useEffect(()=>{if(i&&n&&r&&d){const t=r.wallet?.address||r.email?.address;t&&d(t)}},[i,n,r,d]),o.useEffect(()=>{},[i,n,a]);const y=()=>{try{L()}catch(t){const s=`Login failed: ${String(t)}`;a?a(s):console.error(s)}},q=()=>{try{b()}catch(t){const s=`Logout failed: ${String(t)}`;a?a(s):console.error(s)}};if(!m)return e.jsx("div",{className:l,children:e.jsx(c.Button,{variant:"primary",disabled:!0,theme:u,children:g})});if(!i)return e.jsx("div",{className:l,children:e.jsx(c.Button,{variant:"primary",disabled:!0,theme:u,children:"Loading..."})});if(n&&r){const t=r.wallet?.address||r.email?.address,s=t?`${t.slice(0,6)}...${t.slice(-4)}`:"Connected";return e.jsx("div",{className:l,children:e.jsxs(c.Button,{variant:"primary",onClick:q,theme:u,children:["Logout (",s,")"]})})}return h?e.jsx("div",{className:l,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[e.jsx(c.Spinner,{size:40,borderWidth:3,color:"#3b82f6"}),e.jsx("p",{style:{color:"#6b7280",fontSize:"14px"},children:"Opening login..."})]})}):e.jsx("div",{className:l,children:e.jsx(c.Button,{variant:"primary",onClick:y,theme:u,children:g})})};exports.PrivyLogin=S;
|