@spicenet-io/spiceflow-ui 3.3.15 → 3.3.17
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-C63ipqQS.js +2 -0
- package/dist/Button-e9V76FKz.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/hooks/index.d.ts +2 -0
- package/dist/hooks/useIsUserWhitelisted.d.ts +220 -0
- package/dist/index.cjs.js +14 -14
- package/dist/index.d.ts +3 -3
- package/dist/index.js +8 -8
- package/dist/providers/SpiceFlowProvider.d.ts +9 -2
- package/dist/providers/index.d.ts +1 -1
- package/dist/utils/relayer/index.d.ts +2 -0
- package/dist/utils/rollupBalances.d.ts +2 -0
- package/package.json +1 -1
- package/dist/Button-CpPbEdQV.js +0 -2
- package/dist/Button-Dvhm0yVc.js +0 -2
- package/dist/providerWallet-Q1RM8u1X.js +0 -2
- package/dist/providerWallet-q8k_N1C_.js +0 -2
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { SpiceTheme } from "../types/theme";
|
|
3
|
+
import { type PartnerWhitelistCheckResponse, type UseIsUserWhitelistedOptions } from "../hooks/useIsUserWhitelisted";
|
|
3
4
|
export type WalletProvider = "privy" | "dynamic";
|
|
4
5
|
export type SpiceFlowMode = "7702" | "presign" | "ondemand";
|
|
5
6
|
export declare const hasStoredSpiceFlowMode: () => boolean;
|
|
6
7
|
import type { Network } from "@spicenet-io/spiceflow-core";
|
|
7
8
|
export type SpiceFlowNetwork = Network;
|
|
8
9
|
export declare const SpiceBrandContext: React.Context<SpiceTheme | null>;
|
|
9
|
-
export
|
|
10
|
+
export interface SpiceFlowProviderContextValue {
|
|
10
11
|
provider: WalletProvider;
|
|
11
12
|
supportedChainIds: number[];
|
|
12
13
|
allowedTokens?: string[];
|
|
@@ -18,7 +19,12 @@ export declare const SpiceFlowProviderContext: React.Context<{
|
|
|
18
19
|
appName?: string;
|
|
19
20
|
apiUrl?: string;
|
|
20
21
|
rpcOverrides?: Record<number, string>;
|
|
21
|
-
|
|
22
|
+
isUserWhitelisted: boolean | null;
|
|
23
|
+
isWhitelistChecking: boolean;
|
|
24
|
+
isWhitelistGateActive: boolean;
|
|
25
|
+
whitelistCheck?: PartnerWhitelistCheckResponse;
|
|
26
|
+
}
|
|
27
|
+
export declare const SpiceFlowProviderContext: React.Context<SpiceFlowProviderContextValue | null>;
|
|
22
28
|
export interface SpiceFlowProviderProps {
|
|
23
29
|
children: React.ReactNode;
|
|
24
30
|
provider: WalletProvider;
|
|
@@ -37,5 +43,6 @@ export interface SpiceFlowProviderProps {
|
|
|
37
43
|
apiUrl?: string;
|
|
38
44
|
theme?: SpiceTheme;
|
|
39
45
|
rpcOverrides?: Record<number, string>;
|
|
46
|
+
whitelist?: UseIsUserWhitelistedOptions | false;
|
|
40
47
|
}
|
|
41
48
|
export declare const SpiceFlowProvider: React.FC<SpiceFlowProviderProps>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { SpiceFlowProvider, SpiceFlowProviderContext, SpiceBrandContext, } from "./SpiceFlowProvider";
|
|
2
|
-
export type { SpiceFlowProviderProps, WalletProvider, SpiceFlowNetwork, } from "./SpiceFlowProvider";
|
|
2
|
+
export type { SpiceFlowProviderProps, SpiceFlowProviderContextValue, WalletProvider, SpiceFlowNetwork, } from "./SpiceFlowProvider";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CreateActionRequest, CreateActionResponse, ExecuteStepRequest, FeeEstimateSummary, CreateWalletRequest, WalletInfo, CreateWithdrawalRequest, CreateWithdrawalResponse, WithdrawalStatus, RollupTimestamp } from "@spicenet-io/spiceflow-core";
|
|
2
2
|
import { SwapStep } from "../../types/status";
|
|
3
3
|
import { ChainBatch } from "../../types/authorization";
|
|
4
|
+
import type { RollupBalanceEntry } from "../rollupBalances";
|
|
4
5
|
export declare const RELAYER_API_URL: string;
|
|
5
6
|
export declare class RelayerService {
|
|
6
7
|
private baseUrl;
|
|
@@ -46,6 +47,7 @@ export declare class RelayerService {
|
|
|
46
47
|
getRollupTimestamp(): Promise<RollupTimestamp>;
|
|
47
48
|
}
|
|
48
49
|
export declare const relayerService: RelayerService;
|
|
50
|
+
export declare function getWalletBalanceEntries(address: string): Promise<RollupBalanceEntry[]>;
|
|
49
51
|
type SmartWalletSigner = (message: string) => Promise<string | {
|
|
50
52
|
signature?: string;
|
|
51
53
|
}>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Address } from "viem";
|
|
1
2
|
import type { Asset } from "../types/assets";
|
|
2
3
|
export interface RollupBalanceEntry {
|
|
3
4
|
receiptToken?: string;
|
|
@@ -10,5 +11,6 @@ export interface RollupBalanceEntry {
|
|
|
10
11
|
decimals?: number;
|
|
11
12
|
balanceUsd?: number | string | null;
|
|
12
13
|
}
|
|
14
|
+
export declare function getRollupBalanceForChainToken(entries: RollupBalanceEntry[], chainId: number, tokenAddress: Address, fallbackNames?: Array<string | undefined>): bigint;
|
|
13
15
|
export declare function parseRollupBalanceEntry(token: RollupBalanceEntry, supportedChains?: number[]): Asset | null;
|
|
14
16
|
export declare function fallbackRollupChainName(chainId: number): string;
|
package/package.json
CHANGED
package/dist/Button-CpPbEdQV.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";const I=require("react/jsx-runtime"),g=require("react"),x=require("@spicenet-io/spiceflow-core"),w=require("viem"),pe=require("viem/actions");function N(t,e){return!t||!e?!1:w.isAddress(t)&&w.isAddress(e)?w.getAddress(t)===w.getAddress(e):t.toLowerCase()===e.toLowerCase()}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"}],fe="0xcA11bde05977b3631167028862bE2a173976CA11",me={4114:"0x860aFc632a6D625B95d8B96f39ECC48E988c6962"},he=new Set([5115]);function ye(t){const e=me[t.id]??(he.has(t.id)?void 0:fe);return w.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 ge=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],U=Object.fromEntries(ge.map(t=>x.getChainMeta(t)).filter(t=>t!=null).map(t=>[t.id,{...t,viemChain:ye(t),supportedTokens:x.getTokensForChain(t.id)}])),be=U;let H={};const M=new Map,Y=t=>{H={...t||{}},M.clear()},P=t=>{const e=H[t];return e&&typeof e=="string"&&e.length>0?e:U[t]?.rpcUrl},$=t=>U[t],L=t=>{const e=x.getChainMeta(t);return e?.displayName||e?.name||`Chain ${t}`},we=t=>{const e=x.getDelegateContract(t);if(!e)throw new Error(`Unsupported chain ID: ${t}`);return e},xe=(t,e,a)=>{const r=$(t);return r?.blockExplorer?`${r.blockExplorer}/tx/${e}`:"#"};async function Be(t,e){const a=`0x${e.toString(16)}`;try{await t.request({method:"wallet_switchEthereumChain",params:[{chainId:a}]});return}catch(s){if(!(s?.code===4902||typeof s?.message=="string"&&s.message.includes("Unrecognized chain ID")))throw s}const r=$(e);if(!r)throw new Error(`Cannot add unknown chain ${e} to wallet`);await t.request({method:"wallet_addEthereumChain",params:[{chainId:a,chainName:r.name||`Chain ${e}`,nativeCurrency:r.nativeCurrency||{name:"ETH",symbol:"ETH",decimals:18},rpcUrls:[P(e)||r.rpcUrl],blockExplorerUrls:r.blockExplorer?[r.blockExplorer]:void 0}]})}const q=t=>{const e=$(t);if(!e)throw new Error(`Unsupported chain ID: ${t}`);const a=P(t);if(!a)throw new Error(`No RPC URL configured for chain ID: ${t}`);const r=`${t}:${a}`,s=M.get(r);if(s)return s;const n=w.createPublicClient({chain:e.viemChain,transport:w.http(a,{timeout:15e3,retryCount:2,retryDelay:300}),batch:{multicall:{wait:16}}});return M.set(r,n),n},Ee=()=>{const t={};return Object.values(U).forEach(e=>{t[e.id]={name:e.name,moralisName:e.moralisId||"",chain:e.viemChain,rpcUrl:P(e.id)||e.rpcUrl}}),t},Ce=(t,e=[])=>{const a=$(t);if(!a)return[];const r=[];if(![11155111,421614,84532,688689].includes(t)){const n=e.find(c=>c.chainId===t&&c.isNative);n?r.push(n):r.push({address:x.ZERO_ADDRESS,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:t})}if(!a.supportedTokens)return r;const s=r.some(n=>n.isNative);return a.supportedTokens.forEach(n=>{if(s&&x.isNativeToken(n.address))return;const c=e.find(d=>d.chainId===t&&N(d.address,n.address));c?r.push(c):r.push({address:n.address,name:n.name,symbol:n.symbol,decimals:n.decimals,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,logoURI:n.logo,isNative:!1,chainId:t})}),r},Se=async(t,e)=>{const a=$(t);if(!a)throw new Error(`Unsupported chain ID: ${t}`);const r=e.toLowerCase();if(x.isNativeToken(r)){if(!a.nativeCurrency?.decimals)throw new Error(`Native currency decimals not configured for chain ${t}`);return a.nativeCurrency.decimals}if(a.supportedTokens){const s=a.supportedTokens.find(n=>N(n.address,r));if(s)return s.decimals}try{if(!w.isAddress(e,{strict:!1}))throw new Error(`Invalid token address: ${e}`);const s=w.getAddress(e),n=q(t),c=await pe.readContract(n,{address:s,abi:J,functionName:"decimals"});return Number(c)}catch{throw new Error(`Could not determine decimals for token ${e} on chain ${t}`)}};class f extends Error{constructor(e,a,r={}){super(a),this.code=e,this.context=r,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,f)}}function j(t){return t instanceof f}const $e=["user rejected","user denied","user cancelled","rejected the request","action_rejected","4001"];function G(t){if(!t)return"";if(typeof t=="string")return t;const e=t,a=e.message||e.reason||"",r=e.details||"";return`${a} ${r}`.trim()}const X=t=>{if(j(t))return t.code==="WALLET_REJECTED";const e=G(t).toLowerCase();return $e.some(a=>e.includes(a))},Re=(t,e="Something went wrong. Please try again.")=>X(t)?"Transaction was rejected.":j(t)?t.message||e:G(t)||e;function ve(t,e){const a=e.match(/Output amount (\d+) is insufficient after fees (\d+) on chain (\d+)/);if(!a)return e;const[,r,s,n]=a,c=Number(n),d=BigInt(r),u=BigInt(s);let o;for(const h of t.intents){const R=h.chainBatches.find(v=>v.chainId===c);if(R){o=R;break}}const p=o?.tokenTransfers.find(h=>h.from==="escrow"&&N(h.to,t.user)&&!x.isNativeToken(h.token)),l=L(c);if(!p)return`Amount is too small to cover the estimated fee on ${l}.`;const m=x.getTokenByAddress(p.token,c),C=m?.decimals??18,S=m?.symbol??"tokens",i=w.formatUnits(d,C),B=w.formatUnits(u,C);return`Amount is too small to cover the estimated fee on ${l}. Amount: ${i} ${S}. Estimated fee: ${B} ${S}.`}const Q=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io";function A(t,e){return typeof e=="bigint"?e.toString():e}function b(t,e){return t&&(t.message||t.error?.message||(typeof t.error=="string"?t.error:""))||e}class ke{constructor(){this.baseUrl=Q}setBaseUrl(e){this.baseUrl=e}getBaseUrl(){return this.baseUrl}async createAction(e){const a=`${this.baseUrl}/actions`,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,A)}),s=await r.json();if(!r.ok||s.success===!1)throw new f("RELAYER_ERROR",b(s,`Relayer API error: ${r.status}`),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:"/actions"});return s}async estimateActionFees(e){const a=`${this.baseUrl}/actions/fees/estimate`,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,A)}),s=await r.json();if(!r.ok||!s.success||!s.data?.feeEstimate){const n=b(s,`Relayer fee estimate error: ${r.status}`);throw new f("RELAYER_ERROR",ve(e,n),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:"/actions/fees/estimate"})}return s.data.feeEstimate}async estimateBatchGas(e){const a=`${this.baseUrl}/actions/gas/estimate`,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,A)}),s=await r.json();if(!r.ok||!s.success||!s.data?.gasFee)throw new f("RELAYER_ERROR",b(s,`Relayer gas estimate error: ${r.status}`),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:"/actions/gas/estimate"});return{gasFee:BigInt(s.data.gasFee),gasQuoteSource:s.data.gasQuoteSource}}async executeStep(e,a,r,s){const n=`${this.baseUrl}/actions/${e}/intents/${a}/steps/${r}`,c=`/actions/${e}/intents/${a}/steps/${r}`,d=1e4,u=new Promise((l,m)=>setTimeout(()=>m(new f("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${d/1e3}s`,{actionId:e,intentIndex:a,stepIndex:r,endpoint:c})),d)),o=await Promise.race([fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),u]),p=await o.json();if(!o.ok||p.success===!1)throw new f("RELAYER_EXECUTE_ERROR",b(p,`Execute step error: ${o.status}`),{httpStatus:o.status,responseBody:JSON.stringify(p),endpoint:c,actionId:e});if(p?.status==="error"||p?.status==="reverted"){const l=b(p,""),m=l?`: ${l}`:"";throw new f("RELAYER_EXECUTE_ERROR",`Step ${r} previously ${p.status}${m}`,{httpStatus:o.status,responseBody:JSON.stringify(p),endpoint:c,actionId:e,intentIndex:a,stepIndex:r,stepStatus:p.status})}return{success:!0,transactionHash:p.transactionHash}}async checkStepStatus(e,a){const r=e.split("/"),s=r[0],n=r.length>=2?r[1]:"0",c=`${this.baseUrl}/actions/${s}/intents/${n}/steps/${a}`,d=await fetch(c),u=await d.json();if(!d.ok||u.success===!1)throw new f("RELAYER_STATUS_ERROR",b(u,`Intent step status check failed: ${d.status}`),{httpStatus:d.status,responseBody:JSON.stringify(u),endpoint:c,intentId:e});return{success:!0,data:{status:u.status==="error"?"reverted":u.status,transactionHash:u.txid,error:b(u,"")}}}async createWallet(e,a){const r=`${this.baseUrl}/wallets/${e}`,s=await fetch(r,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),n=await s.json();if(!s.ok||n.success===!1)throw new f("RELAYER_ERROR",b(n,`Create wallet error: ${s.status}`),{httpStatus:s.status,responseBody:JSON.stringify(n),endpoint:`/wallets/${e}`});return n}async getWallet(e){const a=`${this.baseUrl}/wallets/${e}`,r=await fetch(a),s=await r.json();if(!r.ok||s.success===!1)throw new f("RELAYER_ERROR",b(s,`Get wallet error: ${r.status}`),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:`/wallets/${e}`});return s}async createWithdrawal(e){const a=`${this.baseUrl}/withdrawals`,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,A)}),s=await r.json();if(!r.ok||s.success===!1)throw new f("RELAYER_ERROR",b(s,`Create withdrawal error: ${r.status}`),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:"/withdrawals"});return s}async getWithdrawal(e){const a=`${this.baseUrl}/withdrawals/${e}`,r=await fetch(a),s=await r.json();if(!r.ok||s.success===!1)throw new f("RELAYER_ERROR",b(s,`Get withdrawal error: ${r.status}`),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:`/withdrawals/${e}`});return s}async getRollupTimestamp(){const e=`${this.baseUrl}/time`,a=await fetch(e),r=await a.json();if(!a.ok||r.success===!1)throw new f("RELAYER_ERROR",b(r,`Get rollup timestamp error: ${a.status}`),{httpStatus:a.status,responseBody:JSON.stringify(r),endpoint:"/time"});return r}}const E=new ke,D=new Map;async function Te(t,e){const a=t.toLowerCase(),r=D.get(a);if(r)return r;const s=(async()=>{try{await E.getWallet(t);return}catch{}const{unix_timestamp:n}=await E.getRollupTimestamp(),c=`I am creating a new smart wallet and adding an admin wallet ethereum:0x${t.slice(2).toLowerCase()}. Nonce: ${n}`,d=await e(c),u=typeof d=="string"?d:d.signature;if(!u)throw new Error("Wallet returned no smart wallet signature");await E.createWallet(t,{timestamp:n,signature:u})})();D.set(a,s);try{await s}finally{D.delete(a)}}const Ie=(t,e)=>{const a=s=>e?e(s):L(s),r=[];return t.forEach((s,n)=>{const c=s.calls&&s.calls.length>0,d=s.tokenTransfers&&s.tokenTransfers.length>0;!c&&!d||r.push({stepId:n,status:n===0?"processing":"pending",chainId:s.chainId,chainName:a(s.chainId),description:"Processing transaction"})}),r},V="spiceflow-mode",Z=()=>{if(typeof window>"u")return null;try{const t=window.localStorage.getItem(V);return t==="embedded"?"7702":t==="external"?"ondemand":null}catch{return null}},Ne=t=>{if(!(typeof window>"u"))try{window.localStorage.setItem(V,t==="7702"?"embedded":"external")}catch{}},Ue=()=>Z()!==null,K=g.createContext(null),ee=g.createContext(null),Ae=({children:t,provider:e,supportedChainIds:a,allowedTokens:r,network:s="testnet",mode:n="7702",skipFlow:c=[],nativeChainId:d,appName:u="Spicenet",apiUrl:o,theme:p,rpcOverrides:l})=>{g.useEffect(()=>{if(!o)return;const h=E.getBaseUrl();return E.setBaseUrl(o),()=>E.setBaseUrl(h)},[o]),g.useEffect(()=>(Y(l),()=>Y(void 0)),[l]);const m=a??x.getChainIdsByNetwork(s),C=p??null,[S,i]=g.useState(()=>Z()??n),B=g.useCallback(h=>{i(h),Ne(h)},[]);return I.jsx(K.Provider,{value:C,children:I.jsx(ee.Provider,{value:{provider:e,supportedChainIds:m,allowedTokens:r,skipFlow:c,mode:S,setMode:B,network:s,nativeChainId:d,appName:u,apiUrl:o,rpcOverrides:l},children:t})})},Oe={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"}},_e={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"},Fe={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"},te=(t="light")=>({mode:t,...Oe,colors:t==="light"?_e:Fe});function O(t,e){const a=t.replace("#",""),r=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))),n=Math.max(0,Math.round(parseInt(a.substring(4,6),16)*(1-e)));return`#${r.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}`}function Me(t,e){return{shell:e?.shell??"#141414",shellBorder:e?.shellBorder??O(e?.shell??"#141414",.35),shellInnerBorder:e?.shellInnerBorder??O(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 Pe(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 re(t,e){const a=e?{...t,...e}:t,r=a.dark??!1,s=a.primaryColor,n=a.shell??(r?"#141414":"#ffffff");return{primaryColor:s,dark:r,fontFamily:a.fontFamily??'"Helvetica Neue", sans-serif',appName:a.appName??"Spicenet",logo:a.logo,borderRadius:a.borderRadius??"8px",shell:n,shellBorder:O(n,r?.35:.085),shellInnerBorder:O(n,r?.55:.165),card:a.card??(r?"#1e1e1e":"#f9fafb"),input:r?"#171717":"#ffffff",hover:r?"#2a2a2a":"#f3f4f6",text:a.text??(r?"#ffffff":"#111827"),textMuted:a.textMuted??(r?"#888888":"#6b7280"),inputText:r?"#e0e0e0":"#111827",inputPlaceholder:r?"#555555":"#9ca3af",border:a.border??(r?"rgba(255,255,255,0.08)":"#e5e7eb"),inputBorder:r?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:r?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:r?"#0a1f18":"#d1fae5",successBorder:r?"#1a4a3a":"#6ee7b7",successText:r?"#6ee7b7":"#065f46",warningBg:r?"#1f1a0d":"#fef3c7",warningBorder:r?"#4a3820":"#fde68a",warningText:r?"#fbbf24":"#92400e",errorBg:r?"#1f0d0d":"#fef2f2",errorBorder:r?"#4a2020":"#fecaca",errorText:r?"#f87171":"#dc2626",infoBg:r?"#0d1325":"#dbeafe",infoBorder:r?"#2a3a5a":"#93c5fd",infoText:r?"#60a5fa":"#1e40af"}}const Le='"IBM Plex Mono", monospace';function ae(t,e){const a=g.useContext(K)??void 0;return g.useMemo(()=>{const r=a??{primaryColor:"#EA4B4B"},s={...t?.primaryColor?{primaryColor:t.primaryColor}:{},...t?.fontFamily?{fontFamily:t.fontFamily}:{},...e!==void 0?{dark:e}:{}},n=re(r,s),{dark:c,primaryColor:d,appName:u}=n,o=te(c?"dark":"light"),p={...o,colors:{...o.colors,primary:d,primaryHover:`${d}dd`},typography:{...o.typography,fontFamily:n.fontFamily}},l={shell:n.shell,shellBorder:n.shellBorder,shellInnerBorder:n.shellInnerBorder,cardBg:n.card,inputBg:n.input,hoverBg:n.hover,textPrimary:n.text,textSecondary:n.textMuted,inputText:n.inputText,inputPlaceholder:n.inputPlaceholder,cardBorder:n.border,inputBorder:n.inputBorder,buttonBorder:n.buttonBorder,successBg:n.successBg,successBorder:n.successBorder,successText:n.successText,warningBg:n.warningBg,warningBorder:n.warningBorder,warningText:n.warningText,errorBg:n.errorBg,errorBorder:n.errorBorder,errorText:n.errorText,infoBg:n.infoBg,infoBorder:n.infoBorder,infoText:n.infoText},m=t?.inputVariant?t.inputVariant==="dark":c;return{brand:a,theme:p,dark:c,appName:u,primaryColor:d,dk:l,palette:l,fontFamily:n.fontFamily,monoFont:Le,inputDark:m,cardBg:m?l.cardBg:"#E9E9E9",cardBorder:m?l.cardBorder:"#C6C6C6",textPrimary:l.textPrimary,textSecondary:l.textSecondary,subtitleText:m?l.textSecondary:"#979AA0"}},[a,t,e])}const se="spiceflow-spinner-keyframes";function je(){if(typeof document>"u"||document.getElementById(se))return;const t=document.createElement("style");t.id=se,t.textContent="@keyframes spiceflow-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}",document.head.appendChild(t)}const ne=({size:t=16,borderWidth:e=2,color:a="currentColor",style:r})=>{const s=g.useRef(!1);return g.useEffect(()=>{s.current||(je(),s.current=!0)},[]),I.jsx("div",{role:"status","aria-label":"Loading",style:{width:`${t}px`,height:`${t}px`,border:`${e}px solid ${a}`,borderTop:`${e}px solid transparent`,borderRadius:"50%",animation:"spiceflow-spin 1s linear infinite",flexShrink:0,...r}})},De=({variant:t="primary",size:e="md",loading:a=!1,fullWidth:r=!1,disabled:s,children:n,className:c="",style:d,theme:u,styles:o,dark:p,...l})=>{const{theme:m,dark:C,palette:S}=ae(o,p),i=u||m,B=p??C,[h,R]=g.useState(!1),[v,_]=g.useState(!1),F=B?S.shell:"white",oe=()=>{switch(t){case"primary":return{backgroundColor:o?.button?.backgroundColor||i.colors.primary,color:o?.button?.color||"#ffffff",border:`1px solid ${o?.button?.backgroundColor||i.colors.primary}`};case"secondary":return{backgroundColor:i.colors.secondary,color:i.colors.text,border:`1px solid ${i.colors.border}`};case"success":return{backgroundColor:i.colors.success,color:i.colors.text,border:`1px solid ${i.colors.success}`};case"error":return{backgroundColor:i.colors.error,color:i.colors.text,border:`1px solid ${i.colors.error}`};case"ghost":return{backgroundColor:"transparent",color:i.colors.textSecondary,border:`1px solid ${i.colors.border}`};case"outline":{const y=o?.button?.backgroundColor||i.colors.primary,z=o?.button?.color||(B?"#ffffff":"#0e0d0b"),k=o?.button?.borderColor||(B?`${i.colors.primary}88`:"#0e0d0b"),T=s||a,de=B?"1px":"1.5px",le=o?.button?.disabledBackgroundColor||`${y}88`,ue=o?.button?.disabledColor||z;return{height:"56px",backgroundColor:T?le:v?`${y}cc`:h?`${y}ee`:y,color:T?ue:z,border:`${de} solid ${k}`,borderRadius:o?.button?.borderRadius||"12px",fontSize:"22px",fontWeight:500,fontFamily:'"IBM Plex Mono", monospace',opacity:T?.78:1,transform:T?"none":v?"scale(0.98)":h?"translateY(-2px)":"none",boxShadow:T?`3px 3px 0px ${F}, 4px 4px 0px ${k}`:v?`2px 2px 0px ${k}`:h?`5px 5px 0px ${F}, 6px 6px 0px ${k}`:`3px 3px 0px ${F}, 4px 4px 0px ${k}`,transition:"transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease, border-color 150ms ease, color 150ms ease"}}default:return{}}},ie=()=>{if(t==="outline")return{};switch(e){case"sm":return{padding:`${i.spacing.sm} ${i.spacing.md}`,fontSize:i.typography.fontSize.sm};case"md":return{padding:`${i.spacing.md} ${i.spacing.lg}`,fontSize:i.typography.fontSize.base};case"lg":return{padding:`${i.spacing.lg} ${i.spacing.xl}`,fontSize:i.typography.fontSize.lg};default:return{}}},ce={borderRadius:o?.button?.borderRadius||i.borderRadius.md,fontWeight:o?.button?.fontWeight||i.typography.fontWeight.medium,fontFamily:o?.button?.fontFamily||i.typography.fontFamily,fontSize:o?.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)&&t!=="outline"?.6:1,width:r?"100%":"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:i.spacing.sm,...oe(),...ie(),...o?.button?.fontSize&&{fontSize:o.button.fontSize}},W=s||a;return I.jsxs("button",{type:l.type??"button","data-spiceflow-focus":!0,"aria-busy":a||void 0,"aria-disabled":W||void 0,style:{...ce,...d},className:c,disabled:W,onMouseEnter:y=>{R(!0),l.onMouseEnter?.(y)},onMouseLeave:y=>{R(!1),_(!1),l.onMouseLeave?.(y)},onMouseDown:y=>{_(!0),l.onMouseDown?.(y)},onMouseUp:y=>{_(!1),l.onMouseUp?.(y)},...l,children:[a&&I.jsx(ne,{size:16}),n]})};exports.Button=De,exports.CHAIN_CONFIGS=be,exports.RELAYER_API_URL=Q,exports.SpiceFlowProvider=Ae,exports.SpiceFlowProviderContext=ee,exports.SpiceflowError=f,exports.Spinner=ne,exports._=J,exports.addressesEqual=N,exports.buildDarkPalette=Me,exports.buildLightPalette=Pe,exports.createInitialSteps=Ie,exports.createTheme=te,exports.ensureSmartWallet=Te,exports.ensureWalletOnChain=Be,exports.getAllAssetsForChain=Ce,exports.getChainConfig=$,exports.getChainName=L,exports.getChainsForAssets=Ee,exports.getClientForChain=q,exports.getDelegateContractAddress=we,exports.getExplorerUrl=xe,exports.getTokenDecimals=Se,exports.hasStoredSpiceFlowMode=Ue,exports.isSpiceflowError=j,exports.isUserRejection=X,exports.relayerService=E,exports.resolveTheme=re,exports.sanitizeError=Re,exports.useSpiceBrand=ae;
|
package/dist/Button-Dvhm0yVc.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import{jsx as v,jsxs as ge}from"react/jsx-runtime";import{createContext as Y,useEffect as A,useState as M,useCallback as be,useContext as we,useMemo as xe,useRef as Be}from"react";import{getChainMeta as q,getTokensForChain as Ee,getDelegateContract as $e,ZERO_ADDRESS as Se,isNativeToken as _,getTokenByAddress as Ce,getChainIdsByNetwork as Re}from"@spicenet-io/spiceflow-core";import{isAddress as P,getAddress as F,defineChain as ve,createPublicClient as ke,http as Te,formatUnits as G}from"viem";import{readContract as Ie}from"viem/actions";function k(t,e){return!t||!e?!1:P(t)&&P(e)?F(t)===F(e):t.toLowerCase()===e.toLowerCase()}const X=[{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"}],Ne="0xcA11bde05977b3631167028862bE2a173976CA11",Ue={4114:"0x860aFc632a6D625B95d8B96f39ECC48E988c6962"},Oe=new Set([5115]);function Ae(t){const e=Ue[t.id]??(Oe.has(t.id)?void 0:Ne);return ve({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 Me=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],T=Object.fromEntries(Me.map(t=>q(t)).filter(t=>t!=null).map(t=>[t.id,{...t,viemChain:Ae(t),supportedTokens:Ee(t.id)}])),_e=T;let Q={};const L=new Map,V=t=>{Q={...t||{}},L.clear()},j=t=>{const e=Q[t];return e&&typeof e=="string"&&e.length>0?e:T[t]?.rpcUrl},E=t=>T[t],D=t=>{const e=q(t);return e?.displayName||e?.name||`Chain ${t}`},Pe=t=>{const e=$e(t);if(!e)throw new Error(`Unsupported chain ID: ${t}`);return e},Fe=(t,e,a)=>{const r=E(t);return r?.blockExplorer?`${r.blockExplorer}/tx/${e}`:"#"};async function Le(t,e){const a=`0x${e.toString(16)}`;try{await t.request({method:"wallet_switchEthereumChain",params:[{chainId:a}]});return}catch(s){if(!(s?.code===4902||typeof s?.message=="string"&&s.message.includes("Unrecognized chain ID")))throw s}const r=E(e);if(!r)throw new Error(`Cannot add unknown chain ${e} to wallet`);await t.request({method:"wallet_addEthereumChain",params:[{chainId:a,chainName:r.name||`Chain ${e}`,nativeCurrency:r.nativeCurrency||{name:"ETH",symbol:"ETH",decimals:18},rpcUrls:[j(e)||r.rpcUrl],blockExplorerUrls:r.blockExplorer?[r.blockExplorer]:void 0}]})}const Z=t=>{const e=E(t);if(!e)throw new Error(`Unsupported chain ID: ${t}`);const a=j(t);if(!a)throw new Error(`No RPC URL configured for chain ID: ${t}`);const r=`${t}:${a}`,s=L.get(r);if(s)return s;const n=ke({chain:e.viemChain,transport:Te(a,{timeout:15e3,retryCount:2,retryDelay:300}),batch:{multicall:{wait:16}}});return L.set(r,n),n},je=()=>{const t={};return Object.values(T).forEach(e=>{t[e.id]={name:e.name,moralisName:e.moralisId||"",chain:e.viemChain,rpcUrl:j(e.id)||e.rpcUrl}}),t},De=(t,e=[])=>{const a=E(t);if(!a)return[];const r=[];if(![11155111,421614,84532,688689].includes(t)){const n=e.find(c=>c.chainId===t&&c.isNative);n?r.push(n):r.push({address:Se,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:t})}if(!a.supportedTokens)return r;const s=r.some(n=>n.isNative);return a.supportedTokens.forEach(n=>{if(s&&_(n.address))return;const c=e.find(d=>d.chainId===t&&k(d.address,n.address));c?r.push(c):r.push({address:n.address,name:n.name,symbol:n.symbol,decimals:n.decimals,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,logoURI:n.logo,isNative:!1,chainId:t})}),r},ze=async(t,e)=>{const a=E(t);if(!a)throw new Error(`Unsupported chain ID: ${t}`);const r=e.toLowerCase();if(_(r)){if(!a.nativeCurrency?.decimals)throw new Error(`Native currency decimals not configured for chain ${t}`);return a.nativeCurrency.decimals}if(a.supportedTokens){const s=a.supportedTokens.find(n=>k(n.address,r));if(s)return s.decimals}try{if(!P(e,{strict:!1}))throw new Error(`Invalid token address: ${e}`);const s=F(e),n=Z(t),c=await Ie(n,{address:s,abi:X,functionName:"decimals"});return Number(c)}catch{throw new Error(`Could not determine decimals for token ${e} on chain ${t}`)}};class f extends Error{constructor(e,a,r={}){super(a),this.code=e,this.context=r,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,f)}}function z(t){return t instanceof f}const Je=["user rejected","user denied","user cancelled","rejected the request","action_rejected","4001"];function K(t){if(!t)return"";if(typeof t=="string")return t;const e=t,a=e.message||e.reason||"",r=e.details||"";return`${a} ${r}`.trim()}const ee=t=>{if(z(t))return t.code==="WALLET_REJECTED";const e=K(t).toLowerCase();return Je.some(a=>e.includes(a))},We=(t,e="Something went wrong. Please try again.")=>ee(t)?"Transaction was rejected.":z(t)?t.message||e:K(t)||e;function He(t,e){const a=e.match(/Output amount (\d+) is insufficient after fees (\d+) on chain (\d+)/);if(!a)return e;const[,r,s,n]=a,c=Number(n),d=BigInt(r),u=BigInt(s);let o;for(const h of t.intents){const $=h.chainBatches.find(S=>S.chainId===c);if($){o=$;break}}const p=o?.tokenTransfers.find(h=>h.from==="escrow"&&k(h.to,t.user)&&!_(h.token)),l=D(c);if(!p)return`Amount is too small to cover the estimated fee on ${l}.`;const m=Ce(p.token,c),x=m?.decimals??18,B=m?.symbol??"tokens",i=G(d,x),b=G(u,x);return`Amount is too small to cover the estimated fee on ${l}. Amount: ${i} ${B}. Estimated fee: ${b} ${B}.`}const te=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io";function I(t,e){return typeof e=="bigint"?e.toString():e}function g(t,e){return t&&(t.message||t.error?.message||(typeof t.error=="string"?t.error:""))||e}class Ye{constructor(){this.baseUrl=te}setBaseUrl(e){this.baseUrl=e}getBaseUrl(){return this.baseUrl}async createAction(e){const a=`${this.baseUrl}/actions`,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,I)}),s=await r.json();if(!r.ok||s.success===!1)throw new f("RELAYER_ERROR",g(s,`Relayer API error: ${r.status}`),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:"/actions"});return s}async estimateActionFees(e){const a=`${this.baseUrl}/actions/fees/estimate`,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,I)}),s=await r.json();if(!r.ok||!s.success||!s.data?.feeEstimate){const n=g(s,`Relayer fee estimate error: ${r.status}`);throw new f("RELAYER_ERROR",He(e,n),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:"/actions/fees/estimate"})}return s.data.feeEstimate}async estimateBatchGas(e){const a=`${this.baseUrl}/actions/gas/estimate`,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,I)}),s=await r.json();if(!r.ok||!s.success||!s.data?.gasFee)throw new f("RELAYER_ERROR",g(s,`Relayer gas estimate error: ${r.status}`),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:"/actions/gas/estimate"});return{gasFee:BigInt(s.data.gasFee),gasQuoteSource:s.data.gasQuoteSource}}async executeStep(e,a,r,s){const n=`${this.baseUrl}/actions/${e}/intents/${a}/steps/${r}`,c=`/actions/${e}/intents/${a}/steps/${r}`,d=1e4,u=new Promise((l,m)=>setTimeout(()=>m(new f("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${d/1e3}s`,{actionId:e,intentIndex:a,stepIndex:r,endpoint:c})),d)),o=await Promise.race([fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),u]),p=await o.json();if(!o.ok||p.success===!1)throw new f("RELAYER_EXECUTE_ERROR",g(p,`Execute step error: ${o.status}`),{httpStatus:o.status,responseBody:JSON.stringify(p),endpoint:c,actionId:e});if(p?.status==="error"||p?.status==="reverted"){const l=g(p,""),m=l?`: ${l}`:"";throw new f("RELAYER_EXECUTE_ERROR",`Step ${r} previously ${p.status}${m}`,{httpStatus:o.status,responseBody:JSON.stringify(p),endpoint:c,actionId:e,intentIndex:a,stepIndex:r,stepStatus:p.status})}return{success:!0,transactionHash:p.transactionHash}}async checkStepStatus(e,a){const r=e.split("/"),s=r[0],n=r.length>=2?r[1]:"0",c=`${this.baseUrl}/actions/${s}/intents/${n}/steps/${a}`,d=await fetch(c),u=await d.json();if(!d.ok||u.success===!1)throw new f("RELAYER_STATUS_ERROR",g(u,`Intent step status check failed: ${d.status}`),{httpStatus:d.status,responseBody:JSON.stringify(u),endpoint:c,intentId:e});return{success:!0,data:{status:u.status==="error"?"reverted":u.status,transactionHash:u.txid,error:g(u,"")}}}async createWallet(e,a){const r=`${this.baseUrl}/wallets/${e}`,s=await fetch(r,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),n=await s.json();if(!s.ok||n.success===!1)throw new f("RELAYER_ERROR",g(n,`Create wallet error: ${s.status}`),{httpStatus:s.status,responseBody:JSON.stringify(n),endpoint:`/wallets/${e}`});return n}async getWallet(e){const a=`${this.baseUrl}/wallets/${e}`,r=await fetch(a),s=await r.json();if(!r.ok||s.success===!1)throw new f("RELAYER_ERROR",g(s,`Get wallet error: ${r.status}`),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:`/wallets/${e}`});return s}async createWithdrawal(e){const a=`${this.baseUrl}/withdrawals`,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,I)}),s=await r.json();if(!r.ok||s.success===!1)throw new f("RELAYER_ERROR",g(s,`Create withdrawal error: ${r.status}`),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:"/withdrawals"});return s}async getWithdrawal(e){const a=`${this.baseUrl}/withdrawals/${e}`,r=await fetch(a),s=await r.json();if(!r.ok||s.success===!1)throw new f("RELAYER_ERROR",g(s,`Get withdrawal error: ${r.status}`),{httpStatus:r.status,responseBody:JSON.stringify(s),endpoint:`/withdrawals/${e}`});return s}async getRollupTimestamp(){const e=`${this.baseUrl}/time`,a=await fetch(e),r=await a.json();if(!a.ok||r.success===!1)throw new f("RELAYER_ERROR",g(r,`Get rollup timestamp error: ${a.status}`),{httpStatus:a.status,responseBody:JSON.stringify(r),endpoint:"/time"});return r}}const w=new Ye,J=new Map;async function qe(t,e){const a=t.toLowerCase(),r=J.get(a);if(r)return r;const s=(async()=>{try{await w.getWallet(t);return}catch{}const{unix_timestamp:n}=await w.getRollupTimestamp(),c=`I am creating a new smart wallet and adding an admin wallet ethereum:0x${t.slice(2).toLowerCase()}. Nonce: ${n}`,d=await e(c),u=typeof d=="string"?d:d.signature;if(!u)throw new Error("Wallet returned no smart wallet signature");await w.createWallet(t,{timestamp:n,signature:u})})();J.set(a,s);try{await s}finally{J.delete(a)}}const Ge=(t,e)=>{const a=s=>e?e(s):D(s),r=[];return t.forEach((s,n)=>{const c=s.calls&&s.calls.length>0,d=s.tokenTransfers&&s.tokenTransfers.length>0;!c&&!d||r.push({stepId:n,status:n===0?"processing":"pending",chainId:s.chainId,chainName:a(s.chainId),description:"Processing transaction"})}),r},re="spiceflow-mode",ae=()=>{if(typeof window>"u")return null;try{const t=window.localStorage.getItem(re);return t==="embedded"?"7702":t==="external"?"ondemand":null}catch{return null}},Xe=t=>{if(!(typeof window>"u"))try{window.localStorage.setItem(re,t==="7702"?"embedded":"external")}catch{}},Qe=()=>ae()!==null,se=Y(null),ne=Y(null),Ve=({children:t,provider:e,supportedChainIds:a,allowedTokens:r,network:s="testnet",mode:n="7702",skipFlow:c=[],nativeChainId:d,appName:u="Spicenet",apiUrl:o,theme:p,rpcOverrides:l})=>{A(()=>{if(!o)return;const h=w.getBaseUrl();return w.setBaseUrl(o),()=>w.setBaseUrl(h)},[o]),A(()=>(V(l),()=>V(void 0)),[l]);const m=a??Re(s),x=p??null,[B,i]=M(()=>ae()??n),b=be(h=>{i(h),Xe(h)},[]);return v(se.Provider,{value:x,children:v(ne.Provider,{value:{provider:e,supportedChainIds:m,allowedTokens:r,skipFlow:c,mode:B,setMode:b,network:s,nativeChainId:d,appName:u,apiUrl:o,rpcOverrides:l},children:t})})},Ze={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"},et={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"},oe=(t="light")=>({mode:t,...Ze,colors:t==="light"?Ke:et});function N(t,e){const a=t.replace("#",""),r=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))),n=Math.max(0,Math.round(parseInt(a.substring(4,6),16)*(1-e)));return`#${r.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}`}function tt(t,e){return{shell:e?.shell??"#141414",shellBorder:e?.shellBorder??N(e?.shell??"#141414",.35),shellInnerBorder:e?.shellInnerBorder??N(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 rt(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 ie(t,e){const a=e?{...t,...e}:t,r=a.dark??!1,s=a.primaryColor,n=a.shell??(r?"#141414":"#ffffff");return{primaryColor:s,dark:r,fontFamily:a.fontFamily??'"Helvetica Neue", sans-serif',appName:a.appName??"Spicenet",logo:a.logo,borderRadius:a.borderRadius??"8px",shell:n,shellBorder:N(n,r?.35:.085),shellInnerBorder:N(n,r?.55:.165),card:a.card??(r?"#1e1e1e":"#f9fafb"),input:r?"#171717":"#ffffff",hover:r?"#2a2a2a":"#f3f4f6",text:a.text??(r?"#ffffff":"#111827"),textMuted:a.textMuted??(r?"#888888":"#6b7280"),inputText:r?"#e0e0e0":"#111827",inputPlaceholder:r?"#555555":"#9ca3af",border:a.border??(r?"rgba(255,255,255,0.08)":"#e5e7eb"),inputBorder:r?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:r?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:r?"#0a1f18":"#d1fae5",successBorder:r?"#1a4a3a":"#6ee7b7",successText:r?"#6ee7b7":"#065f46",warningBg:r?"#1f1a0d":"#fef3c7",warningBorder:r?"#4a3820":"#fde68a",warningText:r?"#fbbf24":"#92400e",errorBg:r?"#1f0d0d":"#fef2f2",errorBorder:r?"#4a2020":"#fecaca",errorText:r?"#f87171":"#dc2626",infoBg:r?"#0d1325":"#dbeafe",infoBorder:r?"#2a3a5a":"#93c5fd",infoText:r?"#60a5fa":"#1e40af"}}const at='"IBM Plex Mono", monospace';function ce(t,e){const a=we(se)??void 0;return xe(()=>{const r=a??{primaryColor:"#EA4B4B"},s={...t?.primaryColor?{primaryColor:t.primaryColor}:{},...t?.fontFamily?{fontFamily:t.fontFamily}:{},...e!==void 0?{dark:e}:{}},n=ie(r,s),{dark:c,primaryColor:d,appName:u}=n,o=oe(c?"dark":"light"),p={...o,colors:{...o.colors,primary:d,primaryHover:`${d}dd`},typography:{...o.typography,fontFamily:n.fontFamily}},l={shell:n.shell,shellBorder:n.shellBorder,shellInnerBorder:n.shellInnerBorder,cardBg:n.card,inputBg:n.input,hoverBg:n.hover,textPrimary:n.text,textSecondary:n.textMuted,inputText:n.inputText,inputPlaceholder:n.inputPlaceholder,cardBorder:n.border,inputBorder:n.inputBorder,buttonBorder:n.buttonBorder,successBg:n.successBg,successBorder:n.successBorder,successText:n.successText,warningBg:n.warningBg,warningBorder:n.warningBorder,warningText:n.warningText,errorBg:n.errorBg,errorBorder:n.errorBorder,errorText:n.errorText,infoBg:n.infoBg,infoBorder:n.infoBorder,infoText:n.infoText},m=t?.inputVariant?t.inputVariant==="dark":c;return{brand:a,theme:p,dark:c,appName:u,primaryColor:d,dk:l,palette:l,fontFamily:n.fontFamily,monoFont:at,inputDark:m,cardBg:m?l.cardBg:"#E9E9E9",cardBorder:m?l.cardBorder:"#C6C6C6",textPrimary:l.textPrimary,textSecondary:l.textSecondary,subtitleText:m?l.textSecondary:"#979AA0"}},[a,t,e])}const de="spiceflow-spinner-keyframes";function st(){if(typeof document>"u"||document.getElementById(de))return;const t=document.createElement("style");t.id=de,t.textContent="@keyframes spiceflow-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}",document.head.appendChild(t)}const le=({size:t=16,borderWidth:e=2,color:a="currentColor",style:r})=>{const s=Be(!1);return A(()=>{s.current||(st(),s.current=!0)},[]),v("div",{role:"status","aria-label":"Loading",style:{width:`${t}px`,height:`${t}px`,border:`${e}px solid ${a}`,borderTop:`${e}px solid transparent`,borderRadius:"50%",animation:"spiceflow-spin 1s linear infinite",flexShrink:0,...r}})},nt=({variant:t="primary",size:e="md",loading:a=!1,fullWidth:r=!1,disabled:s,children:n,className:c="",style:d,theme:u,styles:o,dark:p,...l})=>{const{theme:m,dark:x,palette:B}=ce(o,p),i=u||m,b=p??x,[h,$]=M(!1),[S,U]=M(!1),O=b?B.shell:"white",ue=()=>{switch(t){case"primary":return{backgroundColor:o?.button?.backgroundColor||i.colors.primary,color:o?.button?.color||"#ffffff",border:`1px solid ${o?.button?.backgroundColor||i.colors.primary}`};case"secondary":return{backgroundColor:i.colors.secondary,color:i.colors.text,border:`1px solid ${i.colors.border}`};case"success":return{backgroundColor:i.colors.success,color:i.colors.text,border:`1px solid ${i.colors.success}`};case"error":return{backgroundColor:i.colors.error,color:i.colors.text,border:`1px solid ${i.colors.error}`};case"ghost":return{backgroundColor:"transparent",color:i.colors.textSecondary,border:`1px solid ${i.colors.border}`};case"outline":{const y=o?.button?.backgroundColor||i.colors.primary,H=o?.button?.color||(b?"#ffffff":"#0e0d0b"),C=o?.button?.borderColor||(b?`${i.colors.primary}88`:"#0e0d0b"),R=s||a,me=b?"1px":"1.5px",he=o?.button?.disabledBackgroundColor||`${y}88`,ye=o?.button?.disabledColor||H;return{height:"56px",backgroundColor:R?he:S?`${y}cc`:h?`${y}ee`:y,color:R?ye:H,border:`${me} solid ${C}`,borderRadius:o?.button?.borderRadius||"12px",fontSize:"22px",fontWeight:500,fontFamily:'"IBM Plex Mono", monospace',opacity:R?.78:1,transform:R?"none":S?"scale(0.98)":h?"translateY(-2px)":"none",boxShadow:R?`3px 3px 0px ${O}, 4px 4px 0px ${C}`:S?`2px 2px 0px ${C}`:h?`5px 5px 0px ${O}, 6px 6px 0px ${C}`:`3px 3px 0px ${O}, 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{}}},pe=()=>{if(t==="outline")return{};switch(e){case"sm":return{padding:`${i.spacing.sm} ${i.spacing.md}`,fontSize:i.typography.fontSize.sm};case"md":return{padding:`${i.spacing.md} ${i.spacing.lg}`,fontSize:i.typography.fontSize.base};case"lg":return{padding:`${i.spacing.lg} ${i.spacing.xl}`,fontSize:i.typography.fontSize.lg};default:return{}}},fe={borderRadius:o?.button?.borderRadius||i.borderRadius.md,fontWeight:o?.button?.fontWeight||i.typography.fontWeight.medium,fontFamily:o?.button?.fontFamily||i.typography.fontFamily,fontSize:o?.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)&&t!=="outline"?.6:1,width:r?"100%":"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:i.spacing.sm,...ue(),...pe(),...o?.button?.fontSize&&{fontSize:o.button.fontSize}},W=s||a;return ge("button",{type:l.type??"button","data-spiceflow-focus":!0,"aria-busy":a||void 0,"aria-disabled":W||void 0,style:{...fe,...d},className:c,disabled:W,onMouseEnter:y=>{$(!0),l.onMouseEnter?.(y)},onMouseLeave:y=>{$(!1),U(!1),l.onMouseLeave?.(y)},onMouseDown:y=>{U(!0),l.onMouseDown?.(y)},onMouseUp:y=>{U(!1),l.onMouseUp?.(y)},...l,children:[a&&v(le,{size:16}),n]})};export{nt as B,_e as C,te as R,le as S,X as _,je as a,Z as b,oe as c,D as d,ne as e,qe as f,E as g,Fe as h,ee as i,k as j,Le as k,Pe as l,ze as m,Ge as n,De as o,f as p,Qe as q,w as r,We as s,z as t,ce as u,Ve as v,ie as w,tt as x,rt as y};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";const o=require("viem"),c=require("./Button-CpPbEdQV.js"),a=e=>{if(!e)return!1;const t=e.connector;if(!t)return!1;if(t.isEmbeddedWallet===!0)return!0;const r=(t.key||t.connectorKey||"").toLowerCase();if(r.includes("embedded")||r.includes("turnkey"))return!0;const n=(t.name||e.walletName||"").toLowerCase();return!!(n.includes("embedded")||n.includes("turnkey"))},s=e=>(e?.connectedWallets||[]).find(t=>a(t))||(a(e?.primaryWallet)?e.primaryWallet:null),u=e=>(e?.connectedWallets||[]).find(t=>t?.address&&t?.connector&&!a(t))||null,l=async(e,t)=>{if(!e?.address)throw new Error("Wallet not available");if(typeof e.getWalletClient=="function"){const r=t===void 0?[void 0]:[String(t),t,void 0];let n=null;for(const d of r)try{const i=await e.getWalletClient(d);if(i)return i}catch(i){n=i}if(n)throw n}if(typeof e.getEthereumProvider=="function"){const r=await e.getEthereumProvider(),n=t?c.getChainConfig(t)?.viemChain:void 0;return o.createWalletClient({account:e.address,chain:n,transport:o.custom(r)})}throw new Error("Wallet client not available")},m=async(e,t)=>{if(!e?.address)throw new Error("Wallet not available");if(typeof e.getEthereumProvider=="function")return e.getEthereumProvider();const r=await l(e,t);return{request:n=>r.request(n)}},f=(e,t)=>({address:e?.address||t.address,chainId:Number(e?.chainId??t.chainId),contractAddress:e?.contractAddress||e?.delegate||t.contractAddress,nonce:BigInt(e?.nonce??t.nonce),r:e?.r,s:e?.s,yParity:(()=>{if(typeof e?.yParity=="number")return e.yParity;const r=Number(e?.v??27);return Number.isFinite(r)?r>=27?r-27:r:0})()});exports.getDynamicEmbeddedWallet=s,exports.getDynamicExternalWallet=u,exports.getProviderEthereumProvider=m,exports.getProviderWalletClient=l,exports.normalizeAuthorization=f;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import{createWalletClient as l,custom as d}from"viem";import{g as c}from"./Button-Dvhm0yVc.js";const o=t=>{if(!t)return!1;const e=t.connector;if(!e)return!1;if(e.isEmbeddedWallet===!0)return!0;const r=(e.key||e.connectorKey||"").toLowerCase();if(r.includes("embedded")||r.includes("turnkey"))return!0;const n=(e.name||t.walletName||"").toLowerCase();return!!(n.includes("embedded")||n.includes("turnkey"))},u=t=>(t?.connectedWallets||[]).find(e=>o(e))||(o(t?.primaryWallet)?t.primaryWallet:null),f=t=>(t?.connectedWallets||[]).find(e=>e?.address&&e?.connector&&!o(e))||null,i=async(t,e)=>{if(!t?.address)throw new Error("Wallet not available");if(typeof t.getWalletClient=="function"){const r=e===void 0?[void 0]:[String(e),e,void 0];let n=null;for(const s of r)try{const a=await t.getWalletClient(s);if(a)return a}catch(a){n=a}if(n)throw n}if(typeof t.getEthereumProvider=="function"){const r=await t.getEthereumProvider(),n=e?c(e)?.viemChain:void 0;return l({account:t.address,chain:n,transport:d(r)})}throw new Error("Wallet client not available")},m=async(t,e)=>{if(!t?.address)throw new Error("Wallet not available");if(typeof t.getEthereumProvider=="function")return t.getEthereumProvider();const r=await i(t,e);return{request:n=>r.request(n)}},y=(t,e)=>({address:t?.address||e.address,chainId:Number(t?.chainId??e.chainId),contractAddress:t?.contractAddress||t?.delegate||e.contractAddress,nonce:BigInt(t?.nonce??e.nonce),r:t?.r,s:t?.s,yParity:(()=>{if(typeof t?.yParity=="number")return t.yParity;const r=Number(t?.v??27);return Number.isFinite(r)?r>=27?r-27:r:0})()});export{m as a,f as b,i as c,u as g,y as n};
|