@spicenet-io/spiceflow-ui 3.3.1 → 3.3.3
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/README.md +7 -7
- package/dist/Button-CQTlAU0Y.js +2 -0
- package/dist/Button-Do5RhaOj.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.d.ts +1 -3
- package/dist/index.js +12 -12
- package/dist/{providerWallet-BMCMyG4_.js → providerWallet-C7u5UfJy.js} +1 -1
- package/dist/{providerWallet-BMOS9yt1.js → providerWallet-DTXTPnDa.js} +1 -1
- package/dist/types/supply.d.ts +1 -2
- package/dist/types/ui.d.ts +0 -1
- package/dist/types/unified.d.ts +0 -1
- package/dist/utils/abis/spicenet.d.ts +0 -66
- package/dist/utils/relayer/index.d.ts +0 -5
- package/dist/utils/tokenResolution.d.ts +1 -1
- package/package.json +46 -46
- package/dist/Button-Ba4gIhbT.js +0 -2
- package/dist/Button-Davf3Lcw.js +0 -2
- package/dist/utils/fees.d.ts +0 -9
- package/dist/utils/rebalancing/index.d.ts +0 -70
package/README.md
CHANGED
|
@@ -57,20 +57,20 @@ function App() {
|
|
|
57
57
|
### Building the Library
|
|
58
58
|
|
|
59
59
|
```bash
|
|
60
|
-
|
|
60
|
+
npm run build
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
### Type Checking
|
|
64
64
|
|
|
65
65
|
```bash
|
|
66
|
-
|
|
66
|
+
npm run typecheck
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
### Linting
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
npm run lint
|
|
73
|
+
npm run lint:fix
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
## Component Playground
|
|
@@ -82,7 +82,7 @@ This repository includes a lightweight React playground app for viewing and test
|
|
|
82
82
|
1. Install dependencies (if not already done):
|
|
83
83
|
|
|
84
84
|
```bash
|
|
85
|
-
|
|
85
|
+
npm install
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
2. Navigate to the playground directory:
|
|
@@ -94,13 +94,13 @@ This repository includes a lightweight React playground app for viewing and test
|
|
|
94
94
|
3. Install playground dependencies:
|
|
95
95
|
|
|
96
96
|
```bash
|
|
97
|
-
|
|
97
|
+
npm install
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
4. Start the development server:
|
|
101
101
|
|
|
102
102
|
```bash
|
|
103
|
-
|
|
103
|
+
npm run dev
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
The playground will open automatically at `http://localhost:3000`
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{jsx as v,jsxs as de}from"react/jsx-runtime";import{createContext as L,useEffect as _,useState as A,useCallback as le,useContext as ue,useMemo as pe,useRef as fe}from"react";import{getChainMeta as j,getTokensForChain as me,getDelegateContract as he,ZERO_ADDRESS as ge,isNativeToken as N,getTokenByAddress as ye,getChainIdsByNetwork as be}from"@spicenet-io/spiceflow-core";import{defineChain as we,createPublicClient as xe,http as Be,isAddress as $e,getAddress as Ee,formatUnits as D}from"viem";import{readContract as ve}from"viem/actions";class u extends Error{constructor(e,a,t={}){super(a),this.code=e,this.context=t,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,u)}}function Re(r){return r instanceof u}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",Ce={4114:"0x860aFc632a6D625B95d8B96f39ECC48E988c6962"},ke=new Set([5115]);function Te(r){const e=Ce[r.id]??(ke.has(r.id)?void 0:Se);return we({id:r.id,name:r.name,nativeCurrency:r.nativeCurrency,rpcUrls:{default:{http:[r.rpcUrl]}},blockExplorers:{default:{name:r.displayName,url:r.blockExplorer}},testnet:r.network==="testnet",...e?{contracts:{multicall3:{address:e}}}:{}})}const Ie=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],R=Object.fromEntries(Ie.map(r=>j(r)).filter(r=>r!=null).map(r=>[r.id,{...r,viemChain:Te(r),supportedTokens:me(r.id)}])),Ue=R;let Y={};const M=new Map,H=r=>{Y={...r||{}},M.clear()},O=r=>{const e=Y[r];return e&&typeof e=="string"&&e.length>0?e:R[r]?.rpcUrl},$=r=>R[r],S=r=>{const e=j(r);return e?.displayName||e?.name||`Chain ${r}`},_e=r=>{const e=he(r);if(!e)throw new Error(`Unsupported chain ID: ${r}`);return e},Ae=(r,e,a)=>{const t=$(r);return t?.blockExplorer?`${t.blockExplorer}/tx/${e}`:"#"},W=r=>{const e=$(r);if(!e)throw new Error(`Unsupported chain ID: ${r}`);const a=O(r);if(!a)throw new Error(`No RPC URL configured for chain ID: ${r}`);const t=`${r}:${a}`,s=M.get(t);if(s)return s;const o=xe({chain:e.viemChain,transport:Be(a,{timeout:15e3,retryCount:2,retryDelay:300}),batch:{multicall:{wait:16}}});return M.set(t,o),o},Ne=()=>{const r={};return Object.values(R).forEach(e=>{r[e.id]={name:e.name,moralisName:e.moralisId||"",chain:e.viemChain,rpcUrl:O(e.id)||e.rpcUrl}}),r},Me=(r,e=[])=>{const a=$(r);if(!a)return[];const t=[];if(![11155111,421614,84532,688689].includes(r)){const o=e.find(c=>c.chainId===r&&c.isNative);o?t.push(o):t.push({address:ge,name:a.nativeCurrency.name,symbol:a.nativeCurrency.symbol,decimals:a.nativeCurrency.decimals,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,logoURI:void 0,isNative:!0,chainId:r})}if(!a.supportedTokens)return t;const s=t.some(o=>o.isNative);return a.supportedTokens.forEach(o=>{if(s&&N(o.address))return;const c=e.find(d=>d.chainId===r&&d.address.toLowerCase()===o.address.toLowerCase());c?t.push(c):t.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:r})}),t},Oe=async(r,e)=>{const a=$(r);if(!a)throw new Error(`Unsupported chain ID: ${r}`);const t=e.toLowerCase();if(N(t)){if(!a.nativeCurrency?.decimals)throw new Error(`Native currency decimals not configured for chain ${r}`);return a.nativeCurrency.decimals}if(a.supportedTokens){const s=a.supportedTokens.find(o=>o.address.toLowerCase()===t);if(s)return s.decimals}try{if(!$e(e,{strict:!1}))throw new Error(`Invalid token address: ${e}`);const s=Ee(e),o=W(r),c=await ve(o,{address:s,abi:z,functionName:"decimals"});return Number(c)}catch{throw new Error(`Could not determine decimals for token ${e} on chain ${r}`)}},J=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",G="__SPICEFLOW_RELAYER_API_URL__";function Pe(r,e){const a=e.match(/Output amount (\d+) is insufficient after fees (\d+) on chain (\d+)/);if(!a)return e;const[,t,s,o]=a,c=Number(o),d=BigInt(t),l=BigInt(s);let i;for(const p of r.intents){const b=p.chainBatches.find(E=>E.chainId===c);if(b){i=b;break}}const m=i?.tokenTransfers.find(p=>p.from==="escrow"&&p.to.toLowerCase()===r.user.toLowerCase()&&!N(p.token));if(!m)return`Amount is too small to cover the estimated fee on ${S(c)}.`;const f=ye(m.token,c),g=f?.decimals??18,y=f?.symbol??"tokens",w=D(d,g),n=D(l,g);return`Amount is too small to cover the estimated fee on ${S(c)}. Amount: ${w} ${y}. Estimated fee: ${n} ${y}.`}function Fe(){if(typeof globalThis>"u")return;const r=globalThis[G];return typeof r=="string"&&r.length>0?r:void 0}class Le{constructor(){this.baseUrl=J}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[G]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return Fe()||this.baseUrl}async createAction(e){const a=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(t,s)=>typeof s=="bigint"?s.toString():s)});if(!a.ok){const t=await a.text();throw new u("RELAYER_ERROR",`Relayer API error: ${a.status} - ${t}`,{httpStatus:a.status,responseBody:t,endpoint:"/actions"})}return await a.json()}async estimateActionFees(e){const a=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)}),t=await a.json();if(!a.ok||!t.success||!t.data?.feeEstimate){const s=t.error?.message||`Relayer fee estimate error: ${a.status}`,o=Pe(e,s);throw new u("RELAYER_ERROR",o,{httpStatus:a.status,responseBody:JSON.stringify(t),endpoint:"/actions/fees/estimate"})}return t.data.feeEstimate}async estimateBatchGas(e){const a=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)}),t=await a.json();if(!a.ok||!t.success||!t.data?.gasFee){const s=t.error?.message||`Relayer gas estimate error: ${a.status}`;throw new u("RELAYER_ERROR",s,{httpStatus:a.status,responseBody:JSON.stringify(t),endpoint:"/actions/gas/estimate"})}return{gasFee:BigInt(t.data.gasFee),gasQuoteSource:t.data.gasQuoteSource}}async executeStep(e,a,t,s){const o=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/${a}/steps/${t}`,c=fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});let d;try{d=await Promise.race([c,new Promise((i,m)=>setTimeout(()=>m(new u("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:e,intentIndex:a,stepIndex:t,endpoint:`/actions/${e}/intents/${a}/steps/${t}`})),1e4))])}catch(i){throw i}if(!d.ok){const i=await d.text();throw new u("RELAYER_EXECUTE_ERROR",`Execute step error: ${d.status} - ${i}`,{httpStatus:d.status,responseBody:i,endpoint:`/actions/${e}/intents/${a}/steps/${t}`,actionId:e})}const l=await d.json();if(l?.status==="error"||l?.status==="reverted")throw new u("RELAYER_EXECUTE_ERROR",`Step ${t} previously ${l.status}${l?.error?`: ${l.error}`:""}`,{httpStatus:d.status,responseBody:JSON.stringify(l),endpoint:`/actions/${e}/intents/${a}/steps/${t}`,actionId:e,intentIndex:a,stepIndex:t,stepStatus:l.status});return{success:!0,transactionHash:l.transactionHash}}async checkStepStatus(e,a){const t=e.split("/");let s="";if(t.length>=2){const d=t[0],l=t[1];s=`${this.getEffectiveBaseUrl()}/actions/${d}/intents/${l}/steps/${a}`}else s=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/0/steps/${a}`;const o=await fetch(s);if(!o.ok)throw new u("RELAYER_STATUS_ERROR",`Intent step status check failed: ${o.status}`,{httpStatus:o.status,endpoint:s,intentId:e});const c=await o.json();return{success:!0,data:{status:c.status==="error"?"reverted":c.status,transactionHash:c.txid}}}async createWallet(e,a){const t=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!t.ok){const s=await t.text();throw new u("RELAYER_ERROR",`Create wallet error: ${t.status} - ${s}`,{httpStatus:t.status,endpoint:`/wallets/${e}`})}return t.json()}async getWallet(e){const a=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`);if(!a.ok){const t=await a.text();throw new u("RELAYER_ERROR",`Get wallet error: ${a.status} - ${t}`,{httpStatus:a.status,endpoint:`/wallets/${e}`})}return a.json()}async createWithdrawal(e){const a=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(t,s)=>typeof s=="bigint"?s.toString():s)});if(!a.ok){const t=await a.text();throw new u("RELAYER_ERROR",`Create withdrawal error: ${a.status} - ${t}`,{httpStatus:a.status,endpoint:"/withdrawals"})}return a.json()}async getWithdrawal(e){const a=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${e}`);if(!a.ok){const t=await a.text();throw new u("RELAYER_ERROR",`Get withdrawal error: ${a.status} - ${t}`,{httpStatus:a.status,endpoint:`/withdrawals/${e}`})}return a.json()}async getRollupTimestamp(){const e=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!e.ok)throw new u("RELAYER_ERROR",`Get rollup timestamp error: ${e.status}`,{httpStatus:e.status,endpoint:"/time"});return e.json()}}const C=new Le,je=(r,e)=>{const a=s=>e?e(s):S(s),t=[];return r.forEach((s,o)=>{const c=s.calls&&s.calls.length>0,d=s.tokenTransfers&&s.tokenTransfers.length>0;if(c||d){const l={stepId:o,status:o===0?"processing":"pending",chainId:s.chainId,chainName:a(s.chainId),description:"Processing transaction"};t.push(l)}}),t},X="spiceflow-mode",q=()=>{if(typeof window>"u")return null;try{const r=window.localStorage.getItem(X);return r==="embedded"?"7702":r==="external"?"ondemand":null}catch{return null}},De=r=>{if(!(typeof window>"u"))try{window.localStorage.setItem(X,r==="7702"?"embedded":"external")}catch{}},ze=()=>q()!==null,Q=L(null),V=L(null),Ye=({children:r,provider:e,supportedChainIds:a,network:t="testnet",mode:s="7702",skipFlow:o=[],nativeChainId:c,appName:d="Spicenet",apiUrl:l,theme:i,rpcOverrides:m})=>{_(()=>{if(!l)return;const p=C.getBaseUrl();return C.setBaseUrl(l),()=>C.setBaseUrl(p)},[l]),_(()=>(H(m),()=>H(void 0)),[m]);const f=a??be(t),g=i??null,[y,w]=A(()=>q()??s),n=le(p=>{w(p),De(p)},[]);return v(Q.Provider,{value:g,children:v(V.Provider,{value:{provider:e,supportedChainIds:f,skipFlow:o,mode:y,setMode:n,network:t,nativeChainId:c,appName:d,apiUrl:l,rpcOverrides:m},children:r})})},He={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"}},We={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"},Je={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"},Z=(r="light")=>({mode:r,...He,colors:r==="light"?We:Je});function k(r,e){const a=r.replace("#",""),t=Math.max(0,Math.round(parseInt(a.substring(0,2),16)*(1-e))),s=Math.max(0,Math.round(parseInt(a.substring(2,4),16)*(1-e))),o=Math.max(0,Math.round(parseInt(a.substring(4,6),16)*(1-e)));return`#${t.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}function Ge(r,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 Xe(r){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 K(r,e){const a=e?{...r,...e}:r,t=a.dark??!1,s=a.primaryColor,o=a.shell??(t?"#141414":"#ffffff");return{primaryColor:s,dark:t,fontFamily:a.fontFamily??'"Helvetica Neue", sans-serif',appName:a.appName??"Spicenet",logo:a.logo,borderRadius:a.borderRadius??"8px",shell:o,shellBorder:k(o,t?.35:.085),shellInnerBorder:k(o,t?.55:.165),card:a.card??(t?"#1e1e1e":"#f9fafb"),input:t?"#171717":"#ffffff",hover:t?"#2a2a2a":"#f3f4f6",text:a.text??(t?"#ffffff":"#111827"),textMuted:a.textMuted??(t?"#888888":"#6b7280"),inputText:t?"#e0e0e0":"#111827",inputPlaceholder:t?"#555555":"#9ca3af",border:a.border??(t?"rgba(255,255,255,0.08)":"#e5e7eb"),inputBorder:t?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:t?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:t?"#0a1f18":"#d1fae5",successBorder:t?"#1a4a3a":"#6ee7b7",successText:t?"#6ee7b7":"#065f46",warningBg:t?"#1f1a0d":"#fef3c7",warningBorder:t?"#4a3820":"#fde68a",warningText:t?"#fbbf24":"#92400e",errorBg:t?"#1f0d0d":"#fef2f2",errorBorder:t?"#4a2020":"#fecaca",errorText:t?"#f87171":"#dc2626",infoBg:t?"#0d1325":"#dbeafe",infoBorder:t?"#2a3a5a":"#93c5fd",infoText:t?"#60a5fa":"#1e40af"}}function ee(r,e){const a=ue(Q)??void 0;return pe(()=>{const t=a??{primaryColor:"#EA4B4B"},s={...r?.primaryColor?{primaryColor:r.primaryColor}:{},...r?.fontFamily?{fontFamily:r.fontFamily}:{},...e!==void 0?{dark:e}:{}},o=K(t,s),{dark:c,primaryColor:d,appName:l}=o,i=Z(c?"dark":"light"),m={...i,colors:{...i.colors,primary:d,primaryHover:`${d}dd`},typography:{...i.typography,fontFamily:o.fontFamily}},f={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:a,theme:m,dark:c,appName:l,primaryColor:d,dk:f,palette:f}},[a,r,e])}const te="spiceflow-spinner-keyframes";function qe(){if(typeof document>"u"||document.getElementById(te))return;const r=document.createElement("style");r.id=te,r.textContent="@keyframes spiceflow-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}",document.head.appendChild(r)}const re=({size:r=16,borderWidth:e=2,color:a="currentColor",style:t})=>{const s=fe(!1);return _(()=>{s.current||(qe(),s.current=!0)},[]),v("div",{role:"status","aria-label":"Loading",style:{width:`${r}px`,height:`${r}px`,border:`${e}px solid ${a}`,borderTop:`${e}px solid transparent`,borderRadius:"50%",animation:"spiceflow-spin 1s linear infinite",flexShrink:0,...t}})},Qe=({variant:r="primary",size:e="md",loading:a=!1,fullWidth:t=!1,disabled:s,children:o,className:c="",style:d,theme:l,styles:i,dark:m,...f})=>{const{theme:g,dark:y,palette:w}=ee(i,m),n=l||g,p=m??y,[b,E]=A(!1),[T,I]=A(!1),U=p?w.shell:"white",ae=()=>{switch(r){case"primary":return{backgroundColor:i?.button?.backgroundColor||n.colors.primary,color:i?.button?.color||"#ffffff",border:`1px solid ${i?.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 h=i?.button?.backgroundColor||n.colors.primary,F=i?.button?.color||(p?"#ffffff":"#0e0d0b"),x=i?.button?.borderColor||(p?`${n.colors.primary}88`:"#0e0d0b"),B=s||a,ne=p?"1px":"1.5px",ie=i?.button?.disabledBackgroundColor||`${h}88`,ce=i?.button?.disabledColor||F;return{height:"56px",backgroundColor:B?ie:T?`${h}cc`:b?`${h}ee`:h,color:B?ce:F,border:`${ne} solid ${x}`,borderRadius:i?.button?.borderRadius||"12px",fontSize:"22px",fontWeight:500,fontFamily:'"IBM Plex Mono", monospace',opacity:B?.78:1,transform:B?"none":T?"scale(0.98)":b?"translateY(-2px)":"none",boxShadow:B?`3px 3px 0px ${U}, 4px 4px 0px ${x}`:T?`2px 2px 0px ${x}`:b?`5px 5px 0px ${U}, 6px 6px 0px ${x}`:`3px 3px 0px ${U}, 4px 4px 0px ${x}`,transition:"transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease, border-color 150ms ease, color 150ms ease"}}default:return{}}},oe=()=>{if(r==="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{}}},se={borderRadius:i?.button?.borderRadius||n.borderRadius.md,fontWeight:i?.button?.fontWeight||n.typography.fontWeight.medium,fontFamily:i?.button?.fontFamily||n.typography.fontFamily,fontSize:i?.button?.fontSize||void 0,transition:"background-color 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease",cursor:s||a?"not-allowed":"pointer",opacity:(s||a)&&r!=="outline"?.6:1,width:t?"100%":"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:n.spacing.sm,...ae(),...oe(),...i?.button?.fontSize&&{fontSize:i.button.fontSize}},P=s||a;return de("button",{type:f.type??"button","data-spiceflow-focus":!0,"aria-busy":a||void 0,"aria-disabled":P||void 0,style:{...se,...d},className:c,disabled:P,onMouseEnter:h=>{E(!0),f.onMouseEnter?.(h)},onMouseLeave:h=>{E(!1),I(!1),f.onMouseLeave?.(h)},onMouseDown:h=>{I(!0),f.onMouseDown?.(h)},onMouseUp:h=>{I(!1),f.onMouseUp?.(h)},...f,children:[a&&v(re,{size:16}),o]})};export{Qe as B,Ue as C,J as R,re as S,z as V,Ne as a,W as b,Z as c,V as d,S as e,Ae as f,$ as g,Me as h,Re as i,O as j,_e as k,Oe as l,je as m,u as n,ze as o,Ye as p,K as q,C as r,Ge as s,Xe as t,ee as u};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";const v=require("react/jsx-runtime"),g=require("react"),y=require("@spicenet-io/spiceflow-core"),b=require("viem"),se=require("viem/actions");class u extends Error{constructor(e,o,t={}){super(o),this.code=e,this.context=t,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,u)}}function ie(r){return r instanceof u}const L=[{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"}],ce="0xcA11bde05977b3631167028862bE2a173976CA11",de={4114:"0x860aFc632a6D625B95d8B96f39ECC48E988c6962"},le=new Set([5115]);function ue(r){const e=de[r.id]??(le.has(r.id)?void 0:ce);return b.defineChain({id:r.id,name:r.name,nativeCurrency:r.nativeCurrency,rpcUrls:{default:{http:[r.rpcUrl]}},blockExplorers:{default:{name:r.displayName,url:r.blockExplorer}},testnet:r.network==="testnet",...e?{contracts:{multicall3:{address:e}}}:{}})}const pe=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],T=Object.fromEntries(pe.map(r=>y.getChainMeta(r)).filter(r=>r!=null).map(r=>[r.id,{...r,viemChain:ue(r),supportedTokens:y.getTokensForChain(r.id)}])),fe=T;let j={};const F=new Map,D=r=>{j={...r||{}},F.clear()},M=r=>{const e=j[r];return e&&typeof e=="string"&&e.length>0?e:T[r]?.rpcUrl},S=r=>T[r],k=r=>{const e=y.getChainMeta(r);return e?.displayName||e?.name||`Chain ${r}`},me=r=>{const e=y.getDelegateContract(r);if(!e)throw new Error(`Unsupported chain ID: ${r}`);return e},he=(r,e,o)=>{const t=S(r);return t?.blockExplorer?`${t.blockExplorer}/tx/${e}`:"#"},Y=r=>{const e=S(r);if(!e)throw new Error(`Unsupported chain ID: ${r}`);const o=M(r);if(!o)throw new Error(`No RPC URL configured for chain ID: ${r}`);const t=`${r}:${o}`,n=F.get(t);if(n)return n;const a=b.createPublicClient({chain:e.viemChain,transport:b.http(o,{timeout:15e3,retryCount:2,retryDelay:300}),batch:{multicall:{wait:16}}});return F.set(t,a),a},ge=()=>{const r={};return Object.values(T).forEach(e=>{r[e.id]={name:e.name,moralisName:e.moralisId||"",chain:e.viemChain,rpcUrl:M(e.id)||e.rpcUrl}}),r},ye=(r,e=[])=>{const o=S(r);if(!o)return[];const t=[];if(![11155111,421614,84532,688689].includes(r)){const a=e.find(c=>c.chainId===r&&c.isNative);a?t.push(a):t.push({address:y.ZERO_ADDRESS,name:o.nativeCurrency.name,symbol:o.nativeCurrency.symbol,decimals:o.nativeCurrency.decimals,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,logoURI:void 0,isNative:!0,chainId:r})}if(!o.supportedTokens)return t;const n=t.some(a=>a.isNative);return o.supportedTokens.forEach(a=>{if(n&&y.isNativeToken(a.address))return;const c=e.find(d=>d.chainId===r&&d.address.toLowerCase()===a.address.toLowerCase());c?t.push(c):t.push({address:a.address,name:a.name,symbol:a.symbol,decimals:a.decimals,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,logoURI:a.logo,isNative:!1,chainId:r})}),t},be=async(r,e)=>{const o=S(r);if(!o)throw new Error(`Unsupported chain ID: ${r}`);const t=e.toLowerCase();if(y.isNativeToken(t)){if(!o.nativeCurrency?.decimals)throw new Error(`Native currency decimals not configured for chain ${r}`);return o.nativeCurrency.decimals}if(o.supportedTokens){const n=o.supportedTokens.find(a=>a.address.toLowerCase()===t);if(n)return n.decimals}try{if(!b.isAddress(e,{strict:!1}))throw new Error(`Invalid token address: ${e}`);const n=b.getAddress(e),a=Y(r),c=await se.readContract(a,{address:n,abi:L,functionName:"decimals"});return Number(c)}catch{throw new Error(`Could not determine decimals for token ${e} on chain ${r}`)}},z=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",H="__SPICEFLOW_RELAYER_API_URL__";function we(r,e){const o=e.match(/Output amount (\d+) is insufficient after fees (\d+) on chain (\d+)/);if(!o)return e;const[,t,n,a]=o,c=Number(a),d=BigInt(t),l=BigInt(n);let i;for(const p of r.intents){const B=p.chainBatches.find(R=>R.chainId===c);if(B){i=B;break}}const m=i?.tokenTransfers.find(p=>p.from==="escrow"&&p.to.toLowerCase()===r.user.toLowerCase()&&!y.isNativeToken(p.token));if(!m)return`Amount is too small to cover the estimated fee on ${k(c)}.`;const f=y.getTokenByAddress(m.token,c),w=f?.decimals??18,x=f?.symbol??"tokens",E=b.formatUnits(d,w),s=b.formatUnits(l,w);return`Amount is too small to cover the estimated fee on ${k(c)}. Amount: ${E} ${x}. Estimated fee: ${s} ${x}.`}function xe(){if(typeof globalThis>"u")return;const r=globalThis[H];return typeof r=="string"&&r.length>0?r:void 0}class Be{constructor(){this.baseUrl=z}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[H]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return xe()||this.baseUrl}async createAction(e){const o=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(t,n)=>typeof n=="bigint"?n.toString():n)});if(!o.ok){const t=await o.text();throw new u("RELAYER_ERROR",`Relayer API error: ${o.status} - ${t}`,{httpStatus:o.status,responseBody:t,endpoint:"/actions"})}return await o.json()}async estimateActionFees(e){const o=await fetch(`${this.getEffectiveBaseUrl()}/actions/fees/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(n,a)=>typeof a=="bigint"?a.toString():a)}),t=await o.json();if(!o.ok||!t.success||!t.data?.feeEstimate){const n=t.error?.message||`Relayer fee estimate error: ${o.status}`,a=we(e,n);throw new u("RELAYER_ERROR",a,{httpStatus:o.status,responseBody:JSON.stringify(t),endpoint:"/actions/fees/estimate"})}return t.data.feeEstimate}async estimateBatchGas(e){const o=await fetch(`${this.getEffectiveBaseUrl()}/actions/gas/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(n,a)=>typeof a=="bigint"?a.toString():a)}),t=await o.json();if(!o.ok||!t.success||!t.data?.gasFee){const n=t.error?.message||`Relayer gas estimate error: ${o.status}`;throw new u("RELAYER_ERROR",n,{httpStatus:o.status,responseBody:JSON.stringify(t),endpoint:"/actions/gas/estimate"})}return{gasFee:BigInt(t.data.gasFee),gasQuoteSource:t.data.gasQuoteSource}}async executeStep(e,o,t,n){const a=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/${o}/steps/${t}`,c=fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});let d;try{d=await Promise.race([c,new Promise((i,m)=>setTimeout(()=>m(new u("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:e,intentIndex:o,stepIndex:t,endpoint:`/actions/${e}/intents/${o}/steps/${t}`})),1e4))])}catch(i){throw i}if(!d.ok){const i=await d.text();throw new u("RELAYER_EXECUTE_ERROR",`Execute step error: ${d.status} - ${i}`,{httpStatus:d.status,responseBody:i,endpoint:`/actions/${e}/intents/${o}/steps/${t}`,actionId:e})}const l=await d.json();if(l?.status==="error"||l?.status==="reverted")throw new u("RELAYER_EXECUTE_ERROR",`Step ${t} previously ${l.status}${l?.error?`: ${l.error}`:""}`,{httpStatus:d.status,responseBody:JSON.stringify(l),endpoint:`/actions/${e}/intents/${o}/steps/${t}`,actionId:e,intentIndex:o,stepIndex:t,stepStatus:l.status});return{success:!0,transactionHash:l.transactionHash}}async checkStepStatus(e,o){const t=e.split("/");let n="";if(t.length>=2){const d=t[0],l=t[1];n=`${this.getEffectiveBaseUrl()}/actions/${d}/intents/${l}/steps/${o}`}else n=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/0/steps/${o}`;const a=await fetch(n);if(!a.ok)throw new u("RELAYER_STATUS_ERROR",`Intent step status check failed: ${a.status}`,{httpStatus:a.status,endpoint:n,intentId:e});const c=await a.json();return{success:!0,data:{status:c.status==="error"?"reverted":c.status,transactionHash:c.txid}}}async createWallet(e,o){const t=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!t.ok){const n=await t.text();throw new u("RELAYER_ERROR",`Create wallet error: ${t.status} - ${n}`,{httpStatus:t.status,endpoint:`/wallets/${e}`})}return t.json()}async getWallet(e){const o=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`);if(!o.ok){const t=await o.text();throw new u("RELAYER_ERROR",`Get wallet error: ${o.status} - ${t}`,{httpStatus:o.status,endpoint:`/wallets/${e}`})}return o.json()}async createWithdrawal(e){const o=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(t,n)=>typeof n=="bigint"?n.toString():n)});if(!o.ok){const t=await o.text();throw new u("RELAYER_ERROR",`Create withdrawal error: ${o.status} - ${t}`,{httpStatus:o.status,endpoint:"/withdrawals"})}return o.json()}async getWithdrawal(e){const o=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${e}`);if(!o.ok){const t=await o.text();throw new u("RELAYER_ERROR",`Get withdrawal error: ${o.status} - ${t}`,{httpStatus:o.status,endpoint:`/withdrawals/${e}`})}return o.json()}async getRollupTimestamp(){const e=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!e.ok)throw new u("RELAYER_ERROR",`Get rollup timestamp error: ${e.status}`,{httpStatus:e.status,endpoint:"/time"});return e.json()}}const I=new Be,Ee=(r,e)=>{const o=n=>e?e(n):k(n),t=[];return r.forEach((n,a)=>{const c=n.calls&&n.calls.length>0,d=n.tokenTransfers&&n.tokenTransfers.length>0;if(c||d){const l={stepId:a,status:a===0?"processing":"pending",chainId:n.chainId,chainName:o(n.chainId),description:"Processing transaction"};t.push(l)}}),t},W="spiceflow-mode",J=()=>{if(typeof window>"u")return null;try{const r=window.localStorage.getItem(W);return r==="embedded"?"7702":r==="external"?"ondemand":null}catch{return null}},$e=r=>{if(!(typeof window>"u"))try{window.localStorage.setItem(W,r==="7702"?"embedded":"external")}catch{}},Ce=()=>J()!==null,G=g.createContext(null),q=g.createContext(null),ve=({children:r,provider:e,supportedChainIds:o,network:t="testnet",mode:n="7702",skipFlow:a=[],nativeChainId:c,appName:d="Spicenet",apiUrl:l,theme:i,rpcOverrides:m})=>{g.useEffect(()=>{if(!l)return;const p=I.getBaseUrl();return I.setBaseUrl(l),()=>I.setBaseUrl(p)},[l]),g.useEffect(()=>(D(m),()=>D(void 0)),[m]);const f=o??y.getChainIdsByNetwork(t),w=i??null,[x,E]=g.useState(()=>J()??n),s=g.useCallback(p=>{E(p),$e(p)},[]);return v.jsx(G.Provider,{value:w,children:v.jsx(q.Provider,{value:{provider:e,supportedChainIds:f,skipFlow:a,mode:x,setMode:s,network:t,nativeChainId:c,appName:d,apiUrl:l,rpcOverrides:m},children:r})})},Se={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"}},Re={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"},Te={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"},X=(r="light")=>({mode:r,...Se,colors:r==="light"?Re:Te});function U(r,e){const o=r.replace("#",""),t=Math.max(0,Math.round(parseInt(o.substring(0,2),16)*(1-e))),n=Math.max(0,Math.round(parseInt(o.substring(2,4),16)*(1-e))),a=Math.max(0,Math.round(parseInt(o.substring(4,6),16)*(1-e)));return`#${t.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}`}function ke(r,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 Ie(r){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 Q(r,e){const o=e?{...r,...e}:r,t=o.dark??!1,n=o.primaryColor,a=o.shell??(t?"#141414":"#ffffff");return{primaryColor:n,dark:t,fontFamily:o.fontFamily??'"Helvetica Neue", sans-serif',appName:o.appName??"Spicenet",logo:o.logo,borderRadius:o.borderRadius??"8px",shell:a,shellBorder:U(a,t?.35:.085),shellInnerBorder:U(a,t?.55:.165),card:o.card??(t?"#1e1e1e":"#f9fafb"),input:t?"#171717":"#ffffff",hover:t?"#2a2a2a":"#f3f4f6",text:o.text??(t?"#ffffff":"#111827"),textMuted:o.textMuted??(t?"#888888":"#6b7280"),inputText:t?"#e0e0e0":"#111827",inputPlaceholder:t?"#555555":"#9ca3af",border:o.border??(t?"rgba(255,255,255,0.08)":"#e5e7eb"),inputBorder:t?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:t?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:t?"#0a1f18":"#d1fae5",successBorder:t?"#1a4a3a":"#6ee7b7",successText:t?"#6ee7b7":"#065f46",warningBg:t?"#1f1a0d":"#fef3c7",warningBorder:t?"#4a3820":"#fde68a",warningText:t?"#fbbf24":"#92400e",errorBg:t?"#1f0d0d":"#fef2f2",errorBorder:t?"#4a2020":"#fecaca",errorText:t?"#f87171":"#dc2626",infoBg:t?"#0d1325":"#dbeafe",infoBorder:t?"#2a3a5a":"#93c5fd",infoText:t?"#60a5fa":"#1e40af"}}function V(r,e){const o=g.useContext(G)??void 0;return g.useMemo(()=>{const t=o??{primaryColor:"#EA4B4B"},n={...r?.primaryColor?{primaryColor:r.primaryColor}:{},...r?.fontFamily?{fontFamily:r.fontFamily}:{},...e!==void 0?{dark:e}:{}},a=Q(t,n),{dark:c,primaryColor:d,appName:l}=a,i=X(c?"dark":"light"),m={...i,colors:{...i.colors,primary:d,primaryHover:`${d}dd`},typography:{...i.typography,fontFamily:a.fontFamily}},f={shell:a.shell,shellBorder:a.shellBorder,shellInnerBorder:a.shellInnerBorder,cardBg:a.card,inputBg:a.input,hoverBg:a.hover,textPrimary:a.text,textSecondary:a.textMuted,inputText:a.inputText,inputPlaceholder:a.inputPlaceholder,cardBorder:a.border,inputBorder:a.inputBorder,buttonBorder:a.buttonBorder,successBg:a.successBg,successBorder:a.successBorder,successText:a.successText,warningBg:a.warningBg,warningBorder:a.warningBorder,warningText:a.warningText,errorBg:a.errorBg,errorBorder:a.errorBorder,errorText:a.errorText,infoBg:a.infoBg,infoBorder:a.infoBorder,infoText:a.infoText};return{brand:o,theme:m,dark:c,appName:l,primaryColor:d,dk:f,palette:f}},[o,r,e])}const Z="spiceflow-spinner-keyframes";function Ue(){if(typeof document>"u"||document.getElementById(Z))return;const r=document.createElement("style");r.id=Z,r.textContent="@keyframes spiceflow-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}",document.head.appendChild(r)}const K=({size:r=16,borderWidth:e=2,color:o="currentColor",style:t})=>{const n=g.useRef(!1);return g.useEffect(()=>{n.current||(Ue(),n.current=!0)},[]),v.jsx("div",{role:"status","aria-label":"Loading",style:{width:`${r}px`,height:`${r}px`,border:`${e}px solid ${o}`,borderTop:`${e}px solid transparent`,borderRadius:"50%",animation:"spiceflow-spin 1s linear infinite",flexShrink:0,...t}})},Ae=({variant:r="primary",size:e="md",loading:o=!1,fullWidth:t=!1,disabled:n,children:a,className:c="",style:d,theme:l,styles:i,dark:m,...f})=>{const{theme:w,dark:x,palette:E}=V(i,m),s=l||w,p=m??x,[B,R]=g.useState(!1),[A,N]=g.useState(!1),_=p?E.shell:"white",ee=()=>{switch(r){case"primary":return{backgroundColor:i?.button?.backgroundColor||s.colors.primary,color:i?.button?.color||"#ffffff",border:`1px solid ${i?.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 h=i?.button?.backgroundColor||s.colors.primary,O=i?.button?.color||(p?"#ffffff":"#0e0d0b"),$=i?.button?.borderColor||(p?`${s.colors.primary}88`:"#0e0d0b"),C=n||o,oe=p?"1px":"1.5px",ae=i?.button?.disabledBackgroundColor||`${h}88`,ne=i?.button?.disabledColor||O;return{height:"56px",backgroundColor:C?ae:A?`${h}cc`:B?`${h}ee`:h,color:C?ne:O,border:`${oe} solid ${$}`,borderRadius:i?.button?.borderRadius||"12px",fontSize:"22px",fontWeight:500,fontFamily:'"IBM Plex Mono", monospace',opacity:C?.78:1,transform:C?"none":A?"scale(0.98)":B?"translateY(-2px)":"none",boxShadow:C?`3px 3px 0px ${_}, 4px 4px 0px ${$}`:A?`2px 2px 0px ${$}`:B?`5px 5px 0px ${_}, 6px 6px 0px ${$}`:`3px 3px 0px ${_}, 4px 4px 0px ${$}`,transition:"transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease, border-color 150ms ease, color 150ms ease"}}default:return{}}},te=()=>{if(r==="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{}}},re={borderRadius:i?.button?.borderRadius||s.borderRadius.md,fontWeight:i?.button?.fontWeight||s.typography.fontWeight.medium,fontFamily:i?.button?.fontFamily||s.typography.fontFamily,fontSize:i?.button?.fontSize||void 0,transition:"background-color 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease",cursor:n||o?"not-allowed":"pointer",opacity:(n||o)&&r!=="outline"?.6:1,width:t?"100%":"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:s.spacing.sm,...ee(),...te(),...i?.button?.fontSize&&{fontSize:i.button.fontSize}},P=n||o;return v.jsxs("button",{type:f.type??"button","data-spiceflow-focus":!0,"aria-busy":o||void 0,"aria-disabled":P||void 0,style:{...re,...d},className:c,disabled:P,onMouseEnter:h=>{R(!0),f.onMouseEnter?.(h)},onMouseLeave:h=>{R(!1),N(!1),f.onMouseLeave?.(h)},onMouseDown:h=>{N(!0),f.onMouseDown?.(h)},onMouseUp:h=>{N(!1),f.onMouseUp?.(h)},...f,children:[o&&v.jsx(K,{size:16}),a]})};exports.Button=Ae,exports.CHAIN_CONFIGS=fe,exports.RELAYER_API_URL=z,exports.SpiceFlowProvider=ve,exports.SpiceFlowProviderContext=q,exports.SpiceflowError=u,exports.Spinner=K,exports.V=L,exports.buildDarkPalette=ke,exports.buildLightPalette=Ie,exports.createInitialSteps=Ee,exports.createTheme=X,exports.getAllAssetsForChain=ye,exports.getChainConfig=S,exports.getChainName=k,exports.getChainsForAssets=ge,exports.getClientForChain=Y,exports.getDelegateContractAddress=me,exports.getExplorerUrl=he,exports.getRpcUrlForChain=M,exports.getTokenDecimals=be,exports.hasStoredSpiceFlowMode=Ce,exports.isSpiceflowError=ie,exports.relayerService=I,exports.resolveTheme=Q,exports.useSpiceBrand=V;
|
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-Do5RhaOj.js"),W=require("@dynamic-labs/sdk-react-core"),k=require("./providerWallet-DTXTPnDa.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-dynamic.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as e,jsxs as g}from"react/jsx-runtime";import A,{useState as N,useEffect as f}from"react";import{B as d,c as S,S as b}from"./Button-
|
|
2
|
+
import{jsx as e,jsxs as g}from"react/jsx-runtime";import A,{useState as N,useEffect as f}from"react";import{B as d,c as S,S as b}from"./Button-CQTlAU0Y.js";import{useDynamicContext as j}from"@dynamic-labs/sdk-react-core";import{g as z}from"./providerWallet-C7u5UfJy.js";import"@spicenet-io/spiceflow-core";import"viem";import"viem/actions";const M=({onAuthSuccess:a,onAuthError:r,theme:m="light",className:t="",buttonText:o="Login with Dynamic",autoTrigger:s=!1})=>{const i=S(m),[h,C]=N(!1),[x,E]=N(!1),L=j(),{user:W,primaryWallet:v,connectedWallets:k,handleLogOut:F,setShowAuthFlow:p,sdkHasLoaded:u,showAuthFlow:D}=L,n=(z({connectedWallets:k,primaryWallet:v})||v)?.address,w=!!W,l=w&&!!n;return f(()=>{C(!0)},[]),f(()=>{l&&n&&a&&a(n)},[l,n,a]),f(()=>{s&&u&&h&&!l&&!D&&!x&&(E(!0),p(!0))},[s,u,h,l,D,x,p]),h?u?w&&!n?e("div",{className:t,children:g("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[e(b,{size:40,borderWidth:3,color:i.colors.primary}),e("p",{style:{color:i.colors.textMuted,fontSize:"14px"},children:"Finishing wallet setup..."})]})}):l&&n?e("div",{className:t,children:g(d,{variant:"primary",onClick:async()=>{try{await F()}catch(y){const c=`Dynamic logout failed: ${String(y)}`;r?r(c):console.error(c)}},theme:i,children:["Logout (",n.slice(0,6),"...",n.slice(-4),")"]})}):s?e("div",{className:t,children:g("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[e(b,{size:40,borderWidth:3,color:i.colors.primary}),e("p",{style:{color:i.colors.textMuted,fontSize:"14px"},children:"Opening login..."})]})}):e("div",{className:t,children:e(d,{variant:"primary",onClick:()=>{try{p(!0)}catch(y){const c=`Dynamic login failed: ${String(y)}`;r?r(c):console.error(c)}},theme:i,children:o})}):e("div",{className:t,children:e(d,{variant:"primary",disabled:!0,theme:i,children:"Loading..."})}):e("div",{className:t,children:e(d,{variant:"primary",disabled:!0,theme:i,children:o})})};class T extends A.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 B=a=>{const{theme:r="light",className:m="",buttonText:t="Login with Dynamic",onAuthError:o}=a,s=S(r);return e(T,{fallback:e("div",{className:m,children:e(d,{variant:"primary",onClick:()=>{o&&o('DynamicLogin must be used within SpiceFlowProvider provider="dynamic" and a mounted DynamicContextProvider.')},theme:s,children:t})}),children:e(M,{...a})})};export{B as DynamicLogin};
|
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-Do5RhaOj.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;
|
package/dist/auth-privy.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as r,jsxs as y}from"react/jsx-runtime";import{useState as v,useEffect as c}from"react";import{B as d,c as P,S as $}from"./Button-
|
|
2
|
+
import{jsx as r,jsxs as y}from"react/jsx-runtime";import{useState as v,useEffect as c}from"react";import{B as d,c as P,S as $}from"./Button-CQTlAU0Y.js";import{usePrivy as j,useLogin as w,useLogout as B}from"@privy-io/react-auth";import"@spicenet-io/spiceflow-core";import"viem";import"viem/actions";const T=({onAuthSuccess:m,onAuthError:n,theme:x="light",className:a="",buttonText:g="Login with Privy",autoTrigger:u=!1})=>{const l=P(x),[h,L]=v(!1),[p,b]=v(!1),{ready:o,authenticated:s,user:t}=j(),{login:S}=w(),{logout:N}=B();c(()=>{L(!0)},[]),c(()=>{u&&o&&!s&&h&&!p&&(b(!0),f())},[u,o,s,h,p]),c(()=>{if(o&&s&&t&&m){const e=t.wallet?.address||t.email?.address;e&&m(e)}},[o,s,t,m]),c(()=>{},[o,s,n]);const f=()=>{try{S()}catch(e){const i=`Login failed: ${String(e)}`;n?n(i):console.error(i)}},C=()=>{try{N()}catch(e){const i=`Logout failed: ${String(e)}`;n?n(i):console.error(i)}};if(!h)return r("div",{className:a,children:r(d,{variant:"primary",disabled:!0,theme:l,children:g})});if(!o)return r("div",{className:a,children:r(d,{variant:"primary",disabled:!0,theme:l,children:"Loading..."})});if(s&&t){const e=t.wallet?.address||t.email?.address,i=e?`${e.slice(0,6)}...${e.slice(-4)}`:"Connected";return r("div",{className:a,children:y(d,{variant:"primary",onClick:C,theme:l,children:["Logout (",i,")"]})})}return u?r("div",{className:a,children:y("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[r($,{size:40,borderWidth:3,color:"#3b82f6"}),r("p",{style:{color:"#6b7280",fontSize:"14px"},children:"Opening login..."})]})}):r("div",{className:a,children:r(d,{variant:"primary",onClick:f,theme:l,children:g})})};export{T as PrivyLogin};
|