@spicenet-io/spiceflow-ui 3.0.1 → 3.0.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.
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ "use strict";const o=require("viem"),c=require("./index-DfIyc-i4.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;
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{createWalletClient as l,custom as d}from"viem";import{g as c}from"./index-BliUKoV3.js";const o=t=>{if(!t)return!1;const e=t.connector;if(!e)return!1;if(e.isEmbeddedWallet===!0)return!0;const r=(e.key||e.connectorKey||"").toLowerCase();if(r.includes("embedded")||r.includes("turnkey"))return!0;const n=(e.name||t.walletName||"").toLowerCase();return!!(n.includes("embedded")||n.includes("turnkey"))},u=t=>(t?.connectedWallets||[]).find(e=>o(e))||(o(t?.primaryWallet)?t.primaryWallet:null),f=t=>(t?.connectedWallets||[]).find(e=>e?.address&&e?.connector&&!o(e))||null,i=async(t,e)=>{if(!t?.address)throw new Error("Wallet not available");if(typeof t.getWalletClient=="function"){const r=e===void 0?[void 0]:[String(e),e,void 0];let n=null;for(const s of r)try{const a=await t.getWalletClient(s);if(a)return a}catch(a){n=a}if(n)throw n}if(typeof t.getEthereumProvider=="function"){const r=await t.getEthereumProvider(),n=e?c(e)?.viemChain:void 0;return l({account:t.address,chain:n,transport:d(r)})}throw new Error("Wallet client not available")},m=async(t,e)=>{if(!t?.address)throw new Error("Wallet not available");if(typeof t.getEthereumProvider=="function")return t.getEthereumProvider();const r=await i(t,e);return{request:n=>r.request(n)}},y=(t,e)=>({address:t?.address||e.address,chainId:Number(t?.chainId??e.chainId),contractAddress:t?.contractAddress||t?.delegate||e.contractAddress,nonce:BigInt(t?.nonce??e.nonce),r:t?.r,s:t?.s,yParity:(()=>{if(typeof t?.yParity=="number")return t.yParity;const r=Number(t?.v??27);return Number.isFinite(r)?r>=27?r-27:r:0})()});export{m as a,f as b,i as c,u as g,y as n};
@@ -1,8 +1,18 @@
1
- import { Asset } from "./assets";
2
- import { CustomStyles, ThemeMode } from "./theme";
3
- import { UseAssetInputReturn } from "../hooks/useAssetInput";
4
1
  import { Address } from "viem";
5
2
  import { ChainBatch } from ".";
3
+ import { UseAssetInputReturn } from "../hooks/useAssetInput";
4
+ import { Asset } from "./assets";
5
+ import { CustomStyles, ThemeMode } from "./theme";
6
+ export interface PostDepositContext {
7
+ sourceChainId: number;
8
+ depositTokenAddress: Address;
9
+ depositAmount: string;
10
+ depositTokenDecimals: number;
11
+ destinationTokenAddress?: Address;
12
+ destinationChainId?: number;
13
+ destinationAmount?: bigint;
14
+ destinationTokenDecimals?: number;
15
+ }
6
16
  export interface SpiceDepositRequest {
7
17
  user: string;
8
18
  txHash: string;
@@ -10,13 +20,43 @@ export interface SpiceDepositRequest {
10
20
  tokenAddress: string;
11
21
  chainId: number;
12
22
  amount: string;
23
+ amountMode?: "gross_input" | "net_input";
13
24
  }
14
25
  export interface SpiceDepositResponse {
15
26
  success: boolean;
27
+ data?: {
28
+ creditedAmount?: string;
29
+ feeEstimate?: {
30
+ amountMode: "gross_input" | "net_input";
31
+ intents: Array<{
32
+ intentIndex: number;
33
+ batches: Array<{
34
+ chainId: number;
35
+ amountMode: "gross_input" | "net_input";
36
+ outputToken: string;
37
+ grossOutput: string;
38
+ netOutput: string;
39
+ totalFee: string;
40
+ gasQuoteSource: "estimated" | "configured_fallback" | "static_zero";
41
+ feeBreakdown: {
42
+ spicenetFee: string;
43
+ gasFee: string;
44
+ };
45
+ }>;
46
+ }>;
47
+ };
48
+ };
16
49
  error?: {
17
50
  message: string;
18
51
  };
19
52
  }
53
+ export interface SpiceDepositFeeEstimateRequest {
54
+ user: string;
55
+ chainId: number;
56
+ tokenAddress: string;
57
+ amount: string;
58
+ amountMode?: "gross_input" | "net_input";
59
+ }
20
60
  export interface DepositWidgetProps {
21
61
  depositBatches: ChainBatch[];
22
62
  tokenAddress: Address;
@@ -47,8 +87,10 @@ export interface DepositModalProps {
47
87
  onClose: () => void;
48
88
  onDepositSelect?: (asset: Asset) => void;
49
89
  title?: string;
50
- depositBatches?: ChainBatch[] | ((depositAmount: string, depositTokenAddress: string) => Promise<ChainBatch[]>);
90
+ depositBatches?: ChainBatch[] | ((context: PostDepositContext) => Promise<ChainBatch[]>) | ((depositAmount: string, depositTokenAddress: string) => Promise<ChainBatch[]>);
51
91
  supportedChains: number[];
92
+ selectedSourceChainId?: number;
93
+ skipChainSwitch?: boolean;
52
94
  styles?: CustomStyles;
53
95
  className?: string;
54
96
  onDepositAssetChange?: (asset: Asset | null) => void;
@@ -35,9 +35,41 @@ export interface CreateActionRequest {
35
35
  }[];
36
36
  intents: (Intent7702 | IntentNon7702OnDemand)[];
37
37
  }
38
+ export interface FeeEstimateBatch {
39
+ chainId: number;
40
+ amountMode: "gross_input" | "net_input";
41
+ outputToken: Address;
42
+ grossOutput: string;
43
+ netOutput: string;
44
+ totalFee: string;
45
+ gasQuoteSource: "estimated" | "configured_fallback" | "static_zero";
46
+ feeBreakdown: {
47
+ spicenetFee: string;
48
+ gasFee: string;
49
+ };
50
+ }
51
+ export interface FeeEstimateIntent {
52
+ intentIndex: number;
53
+ batches: FeeEstimateBatch[];
54
+ }
55
+ export interface FeeEstimateSummary {
56
+ amountMode: "gross_input" | "net_input";
57
+ intents: FeeEstimateIntent[];
58
+ }
38
59
  export interface CreateActionResponse {
39
60
  actionId: string;
40
61
  intentIds: string[];
62
+ feeEstimate?: FeeEstimateSummary;
63
+ }
64
+ export interface EstimateActionFeesResponse {
65
+ success: boolean;
66
+ data?: {
67
+ feeEstimate: FeeEstimateSummary;
68
+ };
69
+ error?: {
70
+ message: string;
71
+ code?: string;
72
+ };
41
73
  }
42
74
  export interface ExecuteStepExecuteRequest {
43
75
  action: "execute";
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{createContext as B,useEffect as w,useState as U,useCallback as k,useContext as C,useMemo as P}from"react";import{jsx as m}from"react/jsx-runtime";import{getChainIdsByNetwork as O}from"@spicenet-io/spiceflow-core";import{a as A,s as y}from"./index-BliUKoV3.js";import{c as _}from"./Button-DjsYc4v4.js";class c extends Error{constructor(t,r,e={}){super(r),this.code=t,this.context=e,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,c)}}function j(o){return o instanceof c}const E=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",x="__SPICEFLOW_RELAYER_API_URL__";function N(){if(typeof globalThis>"u")return;const o=globalThis[x];return typeof o=="string"&&o.length>0?o:void 0}class F{constructor(){this.baseUrl=E}setBaseUrl(t){this.baseUrl=t,typeof globalThis<"u"&&(globalThis[x]=t)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return N()||this.baseUrl}async createAction(t){console.log("[SpiceRelayer] createAction:start",{baseUrl:this.getEffectiveBaseUrl(),intentCount:t.intents.length,chainAuthorizationCount:t.chainAuthorizations?.length??0});const r=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(a,s)=>typeof s=="bigint"?s.toString():s)});if(!r.ok){const a=await r.text();throw console.log("[SpiceRelayer] createAction:error",{baseUrl:this.getEffectiveBaseUrl(),status:r.status,errorText:a}),new c("RELAYER_ERROR",`Relayer API error: ${r.status} - ${a}`,{httpStatus:r.status,responseBody:a,endpoint:"/actions"})}const e=await r.json();return console.log("[SpiceRelayer] createAction:success",{intentIds:e.intentIds}),e}async estimateActionFees(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions/fees/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(a,s)=>typeof s=="bigint"?s.toString():s)}),e=await r.json();if(!r.ok||!e.success||!e.data?.feeEstimate){const a=e.error?.message||`Relayer fee estimate error: ${r.status}`;throw new c("RELAYER_ERROR",a,{httpStatus:r.status,responseBody:JSON.stringify(e),endpoint:"/actions/fees/estimate"})}return e.data.feeEstimate}async estimateSpiceDepositFees(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/spicedeposit/fees/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(a,s)=>typeof s=="bigint"?s.toString():s)}),e=await r.json();if(!r.ok||!e.success||!e.data?.feeEstimate){const a=e.error?.message||`Deposit fee estimate error: ${r.status}`;throw new c("RELAYER_ERROR",a,{httpStatus:r.status,responseBody:JSON.stringify(e),endpoint:"/spicedeposit/fees/estimate"})}return e.data.feeEstimate}async executeStep(t,r,e,a){const s=`${this.getEffectiveBaseUrl()}/actions/${t}/intents/${r}/steps/${e}`,d=fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});let n;try{n=await Promise.race([d,new Promise((i,f)=>setTimeout(()=>f(new c("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:t,intentIndex:r,stepIndex:e,endpoint:`/actions/${t}/intents/${r}/steps/${e}`})),1e4))])}catch(i){throw i}if(!n.ok){const i=await n.text();throw new c("RELAYER_EXECUTE_ERROR",`Execute step error: ${n.status} - ${i}`,{httpStatus:n.status,responseBody:i,endpoint:`/actions/${t}/intents/${r}/steps/${e}`,actionId:t})}return{success:!0,transactionHash:(await n.json()).transactionHash}}async checkStepStatus(t,r){const e=t.split("/");let a="";if(e.length>=2){const n=e[0],i=e[1];a=`${this.getEffectiveBaseUrl()}/actions/${n}/intents/${i}/steps/${r}`}else a=`${this.getEffectiveBaseUrl()}/actions/${t}/intents/0/steps/${r}`;const s=await fetch(a);if(!s.ok)throw new c("RELAYER_STATUS_ERROR",`Intent step status check failed: ${s.status}`,{httpStatus:s.status,endpoint:a,intentId:t});const d=await s.json();return{success:!0,data:{status:d.status==="error"?"reverted":d.status,transactionHash:d.txid}}}async submitSpiceDeposit(t){const r=t.isDeposit?"deposit":"withdrawal";try{const e=await fetch(`${this.getEffectiveBaseUrl()}/spicedeposit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=await e.json();return!e.ok||!a.success?(console.error(`Failed to submit ${r} request to API:`,a.error?.message),{success:!1,error:a.error}):a}catch(e){return console.error(`Error submitting ${r} request to API:`,e),{success:!1,error:{message:e instanceof Error?e.message:"Unknown error"}}}}async requestSpiceUsdAirdrop(t){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop/${t.chainId}/spiceUsd`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wallet:t.address})}),e=await r.json().catch(()=>({}));if(!r.ok){const a=e&&(e.error||e.message)||"Failed to request airdrop";return{success:!1,errorMessage:String(a)}}return e&&typeof e.error=="string"?{success:!1,errorMessage:e.error}:e&&(e.txHash||e.amount)?{success:!0,txHash:e.txHash,amount:e.amount}:{success:!0}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async requestAirdrop(t){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:t.tag||"default",airdrops:[{chainId:t.chainId,tokenId:t.tokenId,wallet:t.wallet,amount:t.amount||"0.0001"}]})}),e=await r.json().catch(()=>({}));if(!r.ok){const s=e?.message||e?.errors?.[0]?.error||"Failed to request airdrop";return{success:!1,errorMessage:String(s)}}const a=e?.airdrops?.[t.chainId]?.[t.tokenId]?.txHash;return e.errors&&e.errors.length>0?{success:!1,errorMessage:e.errors[0].error}:{success:!0,txHash:a}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async createWallet(t,r){const e=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok){const a=await e.text();throw new c("RELAYER_ERROR",`Create wallet error: ${e.status} - ${a}`,{httpStatus:e.status,endpoint:`/wallets/${t}`})}return e.json()}async getWallet(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${t}`);if(!r.ok){const e=await r.text();throw new c("RELAYER_ERROR",`Get wallet error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:`/wallets/${t}`})}return r.json()}async createWithdrawal(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(e,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const e=await r.text();throw new c("RELAYER_ERROR",`Create withdrawal error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:"/withdrawals"})}return r.json()}async getWithdrawal(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${t}`);if(!r.ok){const e=await r.text();throw new c("RELAYER_ERROR",`Get withdrawal error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:`/withdrawals/${t}`})}return r.json()}async getRollupTimestamp(){const t=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!t.ok)throw new c("RELAYER_ERROR",`Get rollup timestamp error: ${t.status}`,{httpStatus:t.status,endpoint:"/time"});return t.json()}}const p=new F,L=(o,t)=>{const r=a=>t?t(a):A(a),e=[];return o.forEach((a,s)=>{const d=a.calls&&a.calls.length>0,n=a.tokenTransfers&&a.tokenTransfers.length>0;if(d||n){const i={stepId:s,status:s===0?"processing":"pending",chainId:a.chainId,chainName:r(a.chainId),description:"Processing transaction"};e.push(i)}}),e},R=B(null),S=B(null),M=({children:o,provider:t,supportedChainIds:r,network:e="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:d,appName:n="Spicenet",apiUrl:i,theme:f,rpcOverrides:l})=>{w(()=>{if(!i)return;const g=p.getBaseUrl();return p.setBaseUrl(i),()=>p.setBaseUrl(g)},[i]),w(()=>(y(l),()=>y(void 0)),[l]);const u=r??O(e),T=f??null,[$,v]=U(a),I=k(g=>v(g),[]);return m(R.Provider,{value:T,children:m(S.Provider,{value:{provider:t,supportedChainIds:u,skipFlow:s,mode:$,setMode:I,network:e,nativeChainId:d,appName:n,apiUrl:i,rpcOverrides:l},children:o})})};function h(o,t){const r=o.replace("#",""),e=Math.max(0,Math.round(parseInt(r.substring(0,2),16)*(1-t))),a=Math.max(0,Math.round(parseInt(r.substring(2,4),16)*(1-t))),s=Math.max(0,Math.round(parseInt(r.substring(4,6),16)*(1-t)));return`#${e.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function Y(o,t){return{shell:t?.shell??"#141414",shellBorder:t?.shellBorder??h(t?.shell??"#141414",.35),shellInnerBorder:t?.shellInnerBorder??h(t?.shell??"#141414",.55),cardBg:t?.cardBg??"#1e1e1e",inputBg:t?.inputBg??"#171717",hoverBg:t?.hoverBg??"#2a2a2a",textPrimary:t?.textPrimary??"#ffffff",textSecondary:t?.textSecondary??"#888888",inputText:t?.inputText??"#e0e0e0",inputPlaceholder:t?.inputPlaceholder??"#555555",cardBorder:t?.cardBorder??"rgba(255,255,255,0.08)",inputBorder:t?.inputBorder??"rgba(255,255,255,0.10)",buttonBorder:t?.buttonBorder??"rgba(255,255,255,0.12)",successBg:t?.successBg??"#0a1f18",successBorder:t?.successBorder??"#1a4a3a",successText:t?.successText??"#6ee7b7",warningBg:t?.warningBg??"#1f1a0d",warningBorder:t?.warningBorder??"#4a3820",warningText:t?.warningText??"#fbbf24",errorBg:t?.errorBg??"#1f0d0d",errorBorder:t?.errorBorder??"#4a2020",errorText:t?.errorText??"#f87171",infoBg:t?.infoBg??"#0d1325",infoBorder:t?.infoBorder??"#2a3a5a",infoText:t?.infoText??"#60a5fa"}}function J(o){return{shell:"#ffffff",shellBorder:"#E9E9E9",shellInnerBorder:"#D5D5D5",cardBg:"#f9fafb",inputBg:"#ffffff",hoverBg:"#f3f4f6",textPrimary:"#111827",textSecondary:"#6b7280",inputText:"#111827",inputPlaceholder:"#9ca3af",cardBorder:"#E0E0E0",inputBorder:"#d1d5db",buttonBorder:"#0e0d0b",successBg:"#d1fae5",successBorder:"#6ee7b7",successText:"#065f46",warningBg:"#fef3c7",warningBorder:"#fcd34d",warningText:"#92400e",errorBg:"#fee2e2",errorBorder:"#fca5a5",errorText:"#dc2626",infoBg:"#dbeafe",infoBorder:"#93c5fd",infoText:"#1e40af"}}function b(o,t){const r=t?{...o,...t}:o,e=r.dark??!1,a=r.primaryColor,s=r.shell??(e?"#141414":"#ffffff");return{primaryColor:a,dark:e,fontFamily:r.fontFamily??'"Helvetica Neue", sans-serif',appName:r.appName??"Spicenet",logo:r.logo,borderRadius:r.borderRadius??"8px",shell:s,shellBorder:h(s,e?.35:.085),shellInnerBorder:h(s,e?.55:.165),card:r.card??(e?"#1e1e1e":"#f9fafb"),input:e?"#171717":"#ffffff",hover:e?"#2a2a2a":"#f3f4f6",text:r.text??(e?"#ffffff":"#111827"),textMuted:r.textMuted??(e?"#888888":"#6b7280"),inputText:e?"#e0e0e0":"#111827",inputPlaceholder:e?"#555555":"#9ca3af",border:r.border??(e?"rgba(255,255,255,0.08)":"#E0E0E0"),inputBorder:e?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:e?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:e?"#0a1f18":"#d1fae5",successBorder:e?"#1a4a3a":"#6ee7b7",successText:e?"#6ee7b7":"#065f46",warningBg:e?"#1f1a0d":"#fef3c7",warningBorder:e?"#4a3820":"#fcd34d",warningText:e?"#fbbf24":"#92400e",errorBg:e?"#1f0d0d":"#fee2e2",errorBorder:e?"#4a2020":"#fca5a5",errorText:e?"#f87171":"#dc2626",infoBg:e?"#0d1325":"#dbeafe",infoBorder:e?"#2a3a5a":"#93c5fd",infoText:e?"#60a5fa":"#1e40af"}}function H(o,t){const r=C(R)??void 0;return P(()=>{const e=r??{primaryColor:"#EA4B4B"},a={...o?.primaryColor?{primaryColor:o.primaryColor}:{},...o?.fontFamily?{fontFamily:o.fontFamily}:{},...t!==void 0?{dark:t}:{}},s=b(e,a),{dark:d,primaryColor:n,appName:i}=s,f=_(d?"dark":"light"),l={...f,colors:{...f.colors,primary:n,primaryHover:`${n}dd`},typography:{...f.typography,fontFamily:s.fontFamily}},u={shell:s.shell,shellBorder:s.shellBorder,shellInnerBorder:s.shellInnerBorder,cardBg:s.card,inputBg:s.input,hoverBg:s.hover,textPrimary:s.text,textSecondary:s.textMuted,inputText:s.inputText,inputPlaceholder:s.inputPlaceholder,cardBorder:s.border,inputBorder:s.inputBorder,buttonBorder:s.buttonBorder,successBg:s.successBg,successBorder:s.successBorder,successText:s.successText,warningBg:s.warningBg,warningBorder:s.warningBorder,warningText:s.warningText,errorBg:s.errorBg,errorBorder:s.errorBorder,errorText:s.errorText,infoBg:s.infoBg,infoBorder:s.infoBorder,infoText:s.infoText};return{brand:r,theme:l,dark:d,appName:i,primaryColor:n,dk:u,palette:u}},[r,o,t])}export{E as R,S,J as a,Y as b,L as c,c as d,M as e,b as f,j as i,p as r,H as u};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ "use strict";const l=require("react"),y=require("react/jsx-runtime"),I=require("@spicenet-io/spiceflow-core"),w=require("./index-DfIyc-i4.js"),P=require("./Button-B_UpyUH-.js");class c extends Error{constructor(t,r,e={}){super(r),this.code=t,this.context=e,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,c)}}function U(o){return o instanceof c}const m=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",E="__SPICEFLOW_RELAYER_API_URL__";function C(){if(typeof globalThis>"u")return;const o=globalThis[E];return typeof o=="string"&&o.length>0?o:void 0}class k{constructor(){this.baseUrl=m}setBaseUrl(t){this.baseUrl=t,typeof globalThis<"u"&&(globalThis[E]=t)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return C()||this.baseUrl}async createAction(t){console.log("[SpiceRelayer] createAction:start",{baseUrl:this.getEffectiveBaseUrl(),intentCount:t.intents.length,chainAuthorizationCount:t.chainAuthorizations?.length??0});const r=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(a,s)=>typeof s=="bigint"?s.toString():s)});if(!r.ok){const a=await r.text();throw console.log("[SpiceRelayer] createAction:error",{baseUrl:this.getEffectiveBaseUrl(),status:r.status,errorText:a}),new c("RELAYER_ERROR",`Relayer API error: ${r.status} - ${a}`,{httpStatus:r.status,responseBody:a,endpoint:"/actions"})}const e=await r.json();return console.log("[SpiceRelayer] createAction:success",{intentIds:e.intentIds}),e}async estimateActionFees(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/actions/fees/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(a,s)=>typeof s=="bigint"?s.toString():s)}),e=await r.json();if(!r.ok||!e.success||!e.data?.feeEstimate){const a=e.error?.message||`Relayer fee estimate error: ${r.status}`;throw new c("RELAYER_ERROR",a,{httpStatus:r.status,responseBody:JSON.stringify(e),endpoint:"/actions/fees/estimate"})}return e.data.feeEstimate}async estimateSpiceDepositFees(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/spicedeposit/fees/estimate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(a,s)=>typeof s=="bigint"?s.toString():s)}),e=await r.json();if(!r.ok||!e.success||!e.data?.feeEstimate){const a=e.error?.message||`Deposit fee estimate error: ${r.status}`;throw new c("RELAYER_ERROR",a,{httpStatus:r.status,responseBody:JSON.stringify(e),endpoint:"/spicedeposit/fees/estimate"})}return e.data.feeEstimate}async executeStep(t,r,e,a){const s=`${this.getEffectiveBaseUrl()}/actions/${t}/intents/${r}/steps/${e}`,d=fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});let n;try{n=await Promise.race([d,new Promise((i,f)=>setTimeout(()=>f(new c("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:t,intentIndex:r,stepIndex:e,endpoint:`/actions/${t}/intents/${r}/steps/${e}`})),1e4))])}catch(i){throw i}if(!n.ok){const i=await n.text();throw new c("RELAYER_EXECUTE_ERROR",`Execute step error: ${n.status} - ${i}`,{httpStatus:n.status,responseBody:i,endpoint:`/actions/${t}/intents/${r}/steps/${e}`,actionId:t})}return{success:!0,transactionHash:(await n.json()).transactionHash}}async checkStepStatus(t,r){const e=t.split("/");let a="";if(e.length>=2){const n=e[0],i=e[1];a=`${this.getEffectiveBaseUrl()}/actions/${n}/intents/${i}/steps/${r}`}else a=`${this.getEffectiveBaseUrl()}/actions/${t}/intents/0/steps/${r}`;const s=await fetch(a);if(!s.ok)throw new c("RELAYER_STATUS_ERROR",`Intent step status check failed: ${s.status}`,{httpStatus:s.status,endpoint:a,intentId:t});const d=await s.json();return{success:!0,data:{status:d.status==="error"?"reverted":d.status,transactionHash:d.txid}}}async submitSpiceDeposit(t){const r=t.isDeposit?"deposit":"withdrawal";try{const e=await fetch(`${this.getEffectiveBaseUrl()}/spicedeposit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=await e.json();return!e.ok||!a.success?(console.error(`Failed to submit ${r} request to API:`,a.error?.message),{success:!1,error:a.error}):a}catch(e){return console.error(`Error submitting ${r} request to API:`,e),{success:!1,error:{message:e instanceof Error?e.message:"Unknown error"}}}}async requestSpiceUsdAirdrop(t){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop/${t.chainId}/spiceUsd`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wallet:t.address})}),e=await r.json().catch(()=>({}));if(!r.ok){const a=e&&(e.error||e.message)||"Failed to request airdrop";return{success:!1,errorMessage:String(a)}}return e&&typeof e.error=="string"?{success:!1,errorMessage:e.error}:e&&(e.txHash||e.amount)?{success:!0,txHash:e.txHash,amount:e.amount}:{success:!0}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async requestAirdrop(t){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:t.tag||"default",airdrops:[{chainId:t.chainId,tokenId:t.tokenId,wallet:t.wallet,amount:t.amount||"0.0001"}]})}),e=await r.json().catch(()=>({}));if(!r.ok){const s=e?.message||e?.errors?.[0]?.error||"Failed to request airdrop";return{success:!1,errorMessage:String(s)}}const a=e?.airdrops?.[t.chainId]?.[t.tokenId]?.txHash;return e.errors&&e.errors.length>0?{success:!1,errorMessage:e.errors[0].error}:{success:!0,txHash:a}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async createWallet(t,r){const e=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok){const a=await e.text();throw new c("RELAYER_ERROR",`Create wallet error: ${e.status} - ${a}`,{httpStatus:e.status,endpoint:`/wallets/${t}`})}return e.json()}async getWallet(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${t}`);if(!r.ok){const e=await r.text();throw new c("RELAYER_ERROR",`Get wallet error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:`/wallets/${t}`})}return r.json()}async createWithdrawal(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t,(e,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const e=await r.text();throw new c("RELAYER_ERROR",`Create withdrawal error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:"/withdrawals"})}return r.json()}async getWithdrawal(t){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${t}`);if(!r.ok){const e=await r.text();throw new c("RELAYER_ERROR",`Get withdrawal error: ${r.status} - ${e}`,{httpStatus:r.status,endpoint:`/withdrawals/${t}`})}return r.json()}async getRollupTimestamp(){const t=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!t.ok)throw new c("RELAYER_ERROR",`Get rollup timestamp error: ${t.status}`,{httpStatus:t.status,endpoint:"/time"});return t.json()}}const h=new k,O=(o,t)=>{const r=a=>t?t(a):w.getChainName(a),e=[];return o.forEach((a,s)=>{const d=a.calls&&a.calls.length>0,n=a.tokenTransfers&&a.tokenTransfers.length>0;if(d||n){const i={stepId:s,status:s===0?"processing":"pending",chainId:a.chainId,chainName:r(a.chainId),description:"Processing transaction"};e.push(i)}}),e},x=l.createContext(null),R=l.createContext(null),A=({children:o,provider:t,supportedChainIds:r,network:e="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:d,appName:n="Spicenet",apiUrl:i,theme:f,rpcOverrides:u})=>{l.useEffect(()=>{if(!i)return;const B=h.getBaseUrl();return h.setBaseUrl(i),()=>h.setBaseUrl(B)},[i]),l.useEffect(()=>(w.setRpcOverrides(u),()=>w.setRpcOverrides(void 0)),[u]);const p=r??I.getChainIdsByNetwork(e),b=f??null,[T,$]=l.useState(a),v=l.useCallback(B=>$(B),[]);return y.jsx(x.Provider,{value:b,children:y.jsx(R.Provider,{value:{provider:t,supportedChainIds:p,skipFlow:s,mode:T,setMode:v,network:e,nativeChainId:d,appName:n,apiUrl:i,rpcOverrides:u},children:o})})};function g(o,t){const r=o.replace("#",""),e=Math.max(0,Math.round(parseInt(r.substring(0,2),16)*(1-t))),a=Math.max(0,Math.round(parseInt(r.substring(2,4),16)*(1-t))),s=Math.max(0,Math.round(parseInt(r.substring(4,6),16)*(1-t)));return`#${e.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function _(o,t){return{shell:t?.shell??"#141414",shellBorder:t?.shellBorder??g(t?.shell??"#141414",.35),shellInnerBorder:t?.shellInnerBorder??g(t?.shell??"#141414",.55),cardBg:t?.cardBg??"#1e1e1e",inputBg:t?.inputBg??"#171717",hoverBg:t?.hoverBg??"#2a2a2a",textPrimary:t?.textPrimary??"#ffffff",textSecondary:t?.textSecondary??"#888888",inputText:t?.inputText??"#e0e0e0",inputPlaceholder:t?.inputPlaceholder??"#555555",cardBorder:t?.cardBorder??"rgba(255,255,255,0.08)",inputBorder:t?.inputBorder??"rgba(255,255,255,0.10)",buttonBorder:t?.buttonBorder??"rgba(255,255,255,0.12)",successBg:t?.successBg??"#0a1f18",successBorder:t?.successBorder??"#1a4a3a",successText:t?.successText??"#6ee7b7",warningBg:t?.warningBg??"#1f1a0d",warningBorder:t?.warningBorder??"#4a3820",warningText:t?.warningText??"#fbbf24",errorBg:t?.errorBg??"#1f0d0d",errorBorder:t?.errorBorder??"#4a2020",errorText:t?.errorText??"#f87171",infoBg:t?.infoBg??"#0d1325",infoBorder:t?.infoBorder??"#2a3a5a",infoText:t?.infoText??"#60a5fa"}}function j(o){return{shell:"#ffffff",shellBorder:"#E9E9E9",shellInnerBorder:"#D5D5D5",cardBg:"#f9fafb",inputBg:"#ffffff",hoverBg:"#f3f4f6",textPrimary:"#111827",textSecondary:"#6b7280",inputText:"#111827",inputPlaceholder:"#9ca3af",cardBorder:"#E0E0E0",inputBorder:"#d1d5db",buttonBorder:"#0e0d0b",successBg:"#d1fae5",successBorder:"#6ee7b7",successText:"#065f46",warningBg:"#fef3c7",warningBorder:"#fcd34d",warningText:"#92400e",errorBg:"#fee2e2",errorBorder:"#fca5a5",errorText:"#dc2626",infoBg:"#dbeafe",infoBorder:"#93c5fd",infoText:"#1e40af"}}function S(o,t){const r=t?{...o,...t}:o,e=r.dark??!1,a=r.primaryColor,s=r.shell??(e?"#141414":"#ffffff");return{primaryColor:a,dark:e,fontFamily:r.fontFamily??'"Helvetica Neue", sans-serif',appName:r.appName??"Spicenet",logo:r.logo,borderRadius:r.borderRadius??"8px",shell:s,shellBorder:g(s,e?.35:.085),shellInnerBorder:g(s,e?.55:.165),card:r.card??(e?"#1e1e1e":"#f9fafb"),input:e?"#171717":"#ffffff",hover:e?"#2a2a2a":"#f3f4f6",text:r.text??(e?"#ffffff":"#111827"),textMuted:r.textMuted??(e?"#888888":"#6b7280"),inputText:e?"#e0e0e0":"#111827",inputPlaceholder:e?"#555555":"#9ca3af",border:r.border??(e?"rgba(255,255,255,0.08)":"#E0E0E0"),inputBorder:e?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:e?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:e?"#0a1f18":"#d1fae5",successBorder:e?"#1a4a3a":"#6ee7b7",successText:e?"#6ee7b7":"#065f46",warningBg:e?"#1f1a0d":"#fef3c7",warningBorder:e?"#4a3820":"#fcd34d",warningText:e?"#fbbf24":"#92400e",errorBg:e?"#1f0d0d":"#fee2e2",errorBorder:e?"#4a2020":"#fca5a5",errorText:e?"#f87171":"#dc2626",infoBg:e?"#0d1325":"#dbeafe",infoBorder:e?"#2a3a5a":"#93c5fd",infoText:e?"#60a5fa":"#1e40af"}}function L(o,t){const r=l.useContext(x)??void 0;return l.useMemo(()=>{const e=r??{primaryColor:"#EA4B4B"},a={...o?.primaryColor?{primaryColor:o.primaryColor}:{},...o?.fontFamily?{fontFamily:o.fontFamily}:{},...t!==void 0?{dark:t}:{}},s=S(e,a),{dark:d,primaryColor:n,appName:i}=s,f=P.createTheme(d?"dark":"light"),u={...f,colors:{...f.colors,primary:n,primaryHover:`${n}dd`},typography:{...f.typography,fontFamily:s.fontFamily}},p={shell:s.shell,shellBorder:s.shellBorder,shellInnerBorder:s.shellInnerBorder,cardBg:s.card,inputBg:s.input,hoverBg:s.hover,textPrimary:s.text,textSecondary:s.textMuted,inputText:s.inputText,inputPlaceholder:s.inputPlaceholder,cardBorder:s.border,inputBorder:s.inputBorder,buttonBorder:s.buttonBorder,successBg:s.successBg,successBorder:s.successBorder,successText:s.successText,warningBg:s.warningBg,warningBorder:s.warningBorder,warningText:s.warningText,errorBg:s.errorBg,errorBorder:s.errorBorder,errorText:s.errorText,infoBg:s.infoBg,infoBorder:s.infoBorder,infoText:s.infoText};return{brand:r,theme:u,dark:d,appName:i,primaryColor:n,dk:p,palette:p}},[r,o,t])}exports.RELAYER_API_URL=m,exports.SpiceFlowProvider=A,exports.SpiceFlowProviderContext=R,exports.SpiceflowError=c,exports.buildDarkPalette=_,exports.buildLightPalette=j,exports.createInitialSteps=O,exports.isSpiceflowError=U,exports.relayerService=h,exports.resolveTheme=S,exports.useSpiceBrand=L;
@@ -1,4 +1,5 @@
1
- import { CreateActionRequest, CreateActionResponse, ExecuteStepRequest } from "../../types/unified";
1
+ import { CreateActionRequest, CreateActionResponse, EstimateActionFeesResponse, ExecuteStepRequest } from "../../types/unified";
2
+ import { SpiceDepositFeeEstimateRequest, SpiceDepositResponse } from "../../types/deposit";
2
3
  import { SwapStep } from "../../types/status";
3
4
  import { ChainBatch } from "../../types/authorization";
4
5
  import { CreateWalletRequest, WalletInfo, CreateWithdrawalRequest, CreateWithdrawalResponse, WithdrawalStatus, RollupTimestamp } from "../../types/rollup";
@@ -10,6 +11,8 @@ export declare class RelayerService {
10
11
  getBaseUrl(): string;
11
12
  private getEffectiveBaseUrl;
12
13
  createAction(request: CreateActionRequest): Promise<CreateActionResponse>;
14
+ estimateActionFees(request: CreateActionRequest): Promise<NonNullable<EstimateActionFeesResponse["data"]>["feeEstimate"]>;
15
+ estimateSpiceDepositFees(request: SpiceDepositFeeEstimateRequest): Promise<NonNullable<EstimateActionFeesResponse["data"]>["feeEstimate"]>;
13
16
  executeStep(actionId: string, intentIndex: number, stepIndex: number, request: ExecuteStepRequest): Promise<{
14
17
  success: true;
15
18
  transactionHash?: string;
@@ -21,6 +24,25 @@ export declare class RelayerService {
21
24
  transactionHash?: string;
22
25
  };
23
26
  }>;
27
+ submitSpiceDeposit(request: {
28
+ user: string;
29
+ txHash: string;
30
+ sender: string;
31
+ tokenAddress: string;
32
+ chainId: number;
33
+ amount: string;
34
+ amountMode?: "gross_input" | "net_input";
35
+ isDeposit?: boolean;
36
+ }): Promise<SpiceDepositResponse>;
37
+ requestSpiceUsdAirdrop(params: {
38
+ chainId: number;
39
+ address: string;
40
+ }): Promise<{
41
+ success: boolean;
42
+ txHash?: string;
43
+ amount?: string;
44
+ errorMessage?: string;
45
+ }>;
24
46
  requestAirdrop(params: {
25
47
  chainId: number;
26
48
  tokenId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spicenet-io/spiceflow-ui",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "Spiceflow UI SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
@@ -1,2 +0,0 @@
1
- "use client";
2
- import{jsx as i,jsxs as p}from"react/jsx-runtime";import z,{useState as E,useEffect as g}from"react";import{B as u,c as C,S as D}from"./Button-CaguAr48.js";import{useDynamicContext as T}from"@dynamic-labs/sdk-react-core";import{createWalletClient as j,custom as B}from"viem";import{b as q}from"./index-Uh1tWOql.js";const v=e=>{if(!e)return!1;const t=e.connector;if(!t)return!1;if(t.isEmbeddedWallet===!0)return!0;const n=(t.key||t.connectorKey||"").toLowerCase();if(n.includes("embedded")||n.includes("turnkey"))return!0;const r=(t.name||e.walletName||"").toLowerCase();return!!(r.includes("embedded")||r.includes("turnkey"))},N=e=>(e?.connectedWallets||[]).find(t=>v(t))||(v(e?.primaryWallet)?e.primaryWallet:null),M=e=>(e?.connectedWallets||[]).find(t=>t?.address&&t?.connector&&!v(t))||null,S=async(e,t)=>{if(!e?.address)throw new Error("Wallet not available");if(typeof e.getWalletClient=="function"){const n=t===void 0?[void 0]:[String(t),t,void 0];let r=null;for(const l of n)try{const a=await e.getWalletClient(l);if(a)return a}catch(a){r=a}if(r)throw r}if(typeof e.getEthereumProvider=="function"){const n=await e.getEthereumProvider(),r=t?q(t)?.viemChain:void 0;return j({account:e.address,chain:r,transport:B(n)})}throw new Error("Wallet client not available")},O=async(e,t)=>{if(!e?.address)throw new Error("Wallet not available");if(typeof e.getEthereumProvider=="function")return e.getEthereumProvider();const n=await S(e,t);return{request:r=>n.request(r)}},$=(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 n=Number(e?.v??27);return Number.isFinite(n)?n>=27?n-27:n:0})()}),G=({onAuthSuccess:e,onAuthError:t,theme:n="light",className:r="",buttonText:l="Login with Dynamic",autoTrigger:a=!1})=>{const o=C(n),[m,P]=E(!1),[w,k]=E(!1),L=T(),{user:A,primaryWallet:b,connectedWallets:F,handleLogOut:I,setShowAuthFlow:h,sdkHasLoaded:f,showAuthFlow:x}=L,s=(N({connectedWallets:F,primaryWallet:b})||b)?.address,W=!!A,c=W&&!!s;return g(()=>{P(!0)},[]),g(()=>{c&&s&&e&&e(s)},[c,s,e]),g(()=>{a&&f&&m&&!c&&!x&&!w&&(k(!0),h(!0))},[a,f,m,c,x,w,h]),m?f?W&&!s?i("div",{className:r,children:p("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[i(D,{size:40,borderWidth:3,color:o.colors.primary}),i("p",{style:{color:o.colors.textMuted,fontSize:"14px"},children:"Finishing wallet setup..."})]})}):c&&s?i("div",{className:r,children:p(u,{variant:"primary",onClick:async()=>{try{await I()}catch(y){const d=`Dynamic logout failed: ${String(y)}`;t?t(d):console.error(d)}},theme:o,children:["Logout (",s.slice(0,6),"...",s.slice(-4),")"]})}):a?i("div",{className:r,children:p("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[i(D,{size:40,borderWidth:3,color:o.colors.primary}),i("p",{style:{color:o.colors.textMuted,fontSize:"14px"},children:"Opening login..."})]})}):i("div",{className:r,children:i(u,{variant:"primary",onClick:()=>{try{h(!0)}catch(y){const d=`Dynamic login failed: ${String(y)}`;t?t(d):console.error(d)}},theme:o,children:l})}):i("div",{className:r,children:i(u,{variant:"primary",disabled:!0,theme:o,children:"Loading..."})}):i("div",{className:r,children:i(u,{variant:"primary",disabled:!0,theme:o,children:l})})};class H extends z.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback:this.props.children}}const K=e=>{const{theme:t="light",className:n="",buttonText:r="Login with Dynamic",onAuthError:l}=e,a=C(t);return i(H,{fallback:i("div",{className:n,children:i(u,{variant:"primary",onClick:()=>{l&&l('DynamicLogin must be used within SpiceFlowProvider provider="dynamic" and a mounted DynamicContextProvider.')},theme:a,children:r})}),children:i(G,{...e})})};export{K as D,O as a,M as b,S as c,N as g,$ as n};
@@ -1,2 +0,0 @@
1
- "use client";
2
- "use strict";const r=require("react/jsx-runtime"),d=require("react"),s=require("./Button-B_UpyUH-.js"),q=require("@dynamic-labs/sdk-react-core"),W=require("viem"),z=require("./index-CmpsCAqC.js"),p=e=>{if(!e)return!1;const t=e.connector;if(!t)return!1;if(t.isEmbeddedWallet===!0)return!0;const i=(t.key||t.connectorKey||"").toLowerCase();if(i.includes("embedded")||i.includes("turnkey"))return!0;const n=(t.name||e.walletName||"").toLowerCase();return!!(n.includes("embedded")||n.includes("turnkey"))},j=e=>(e?.connectedWallets||[]).find(t=>p(t))||(p(e?.primaryWallet)?e.primaryWallet:null),B=e=>(e?.connectedWallets||[]).find(t=>t?.address&&t?.connector&&!p(t))||null,b=async(e,t)=>{if(!e?.address)throw new Error("Wallet not available");if(typeof e.getWalletClient=="function"){const i=t===void 0?[void 0]:[String(t),t,void 0];let n=null;for(const c of i)try{const a=await e.getWalletClient(c);if(a)return a}catch(a){n=a}if(n)throw n}if(typeof e.getEthereumProvider=="function"){const i=await e.getEthereumProvider(),n=t?z.getChainConfig(t)?.viemChain:void 0;return W.createWalletClient({account:e.address,chain:n,transport:W.custom(i)})}throw new Error("Wallet client not available")},F=async(e,t)=>{if(!e?.address)throw new Error("Wallet not available");if(typeof e.getEthereumProvider=="function")return e.getEthereumProvider();const i=await b(e,t);return{request:n=>i.request(n)}},I=(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 i=Number(e?.v??27);return Number.isFinite(i)?i>=27?i-27:i:0})()}),T=({onAuthSuccess:e,onAuthError:t,theme:i="light",className:n="",buttonText:c="Login with Dynamic",autoTrigger:a=!1})=>{const o=s.createTheme(i),[h,C]=d.useState(!1),[x,D]=d.useState(!1),P=q.useDynamicContext(),{user:N,primaryWallet:v,connectedWallets:S,handleLogOut:k,setShowAuthFlow:y,sdkHasLoaded:f,showAuthFlow:w}=P,l=(j({connectedWallets:S,primaryWallet:v})||v)?.address,E=!!N,u=E&&!!l;d.useEffect(()=>{C(!0)},[]),d.useEffect(()=>{u&&l&&e&&e(l)},[u,l,e]),d.useEffect(()=>{a&&f&&h&&!u&&!w&&!x&&(D(!0),y(!0))},[a,f,h,u,w,x,y]);const L=()=>{try{y(!0)}catch(g){const m=`Dynamic login failed: ${String(g)}`;t?t(m):console.error(m)}},A=async()=>{try{await k()}catch(g){const m=`Dynamic logout failed: ${String(g)}`;t?t(m):console.error(m)}};return h?f?E&&!l?r.jsx("div",{className:n,children:r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[r.jsx(s.Spinner,{size:40,borderWidth:3,color:o.colors.primary}),r.jsx("p",{style:{color:o.colors.textMuted,fontSize:"14px"},children:"Finishing wallet setup..."})]})}):u&&l?r.jsx("div",{className:n,children:r.jsxs(s.Button,{variant:"primary",onClick:A,theme:o,children:["Logout (",l.slice(0,6),"...",l.slice(-4),")"]})}):a?r.jsx("div",{className:n,children:r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[r.jsx(s.Spinner,{size:40,borderWidth:3,color:o.colors.primary}),r.jsx("p",{style:{color:o.colors.textMuted,fontSize:"14px"},children:"Opening login..."})]})}):r.jsx("div",{className:n,children:r.jsx(s.Button,{variant:"primary",onClick:L,theme:o,children:c})}):r.jsx("div",{className:n,children:r.jsx(s.Button,{variant:"primary",disabled:!0,theme:o,children:"Loading..."})}):r.jsx("div",{className:n,children:r.jsx(s.Button,{variant:"primary",disabled:!0,theme:o,children:c})})};class M extends d.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback:this.props.children}}const O=e=>{const{theme:t="light",className:i="",buttonText:n="Login with Dynamic",onAuthError:c}=e,a=s.createTheme(t);return r.jsx(M,{fallback:r.jsx("div",{className:i,children:r.jsx(s.Button,{variant:"primary",onClick:()=>{c&&c('DynamicLogin must be used within SpiceFlowProvider provider="dynamic" and a mounted DynamicContextProvider.')},theme:a,children:n})}),children:r.jsx(T,{...e})})};exports.DynamicLogin=O,exports.getDynamicEmbeddedWallet=j,exports.getDynamicExternalWallet=B,exports.getProviderEthereumProvider=F,exports.getProviderWalletClient=b,exports.normalizeAuthorization=I;
@@ -1,2 +0,0 @@
1
- "use client";
2
- "use strict";const l=require("viem"),C=require("viem/actions"),o=require("@spicenet-io/spiceflow-core"),y=[{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"}],h="0xcA11bde05977b3631167028862bE2a173976CA11";function g(e){return l.defineChain({id:e.id,name:e.name,nativeCurrency:e.nativeCurrency,rpcUrls:{default:{http:[e.rpcUrl]}},blockExplorers:{default:{name:e.displayName,url:e.blockExplorer}},testnet:e.network==="testnet",contracts:{multicall3:{address:h}}})}const v=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],u=Object.fromEntries(v.map(e=>o.getChainMeta(e)).filter(e=>e!=null).map(e=>[e.id,{...e,viemChain:g(e),supportedTokens:o.getTokensForChain(e.id)}])),w=u;let f={};const p=new Map,N=e=>{f={...e||{}},p.clear()},d=e=>{const t=f[e];return t&&typeof t=="string"&&t.length>0?t:u[e]?.rpcUrl},c=e=>u[e],I=e=>{const t=o.getChainMeta(e);return t?.displayName||t?.name||`Chain ${e}`},E=e=>{const t=o.getDelegateContract(e);if(!t)throw new Error(`Unsupported chain ID: ${e}`);return t},k=(e,t,a)=>{const s=c(e);return s?.blockExplorer?`${s.blockExplorer}/tx/${t}`:"#"},b=e=>{const t=c(e);if(!t)throw new Error(`Unsupported chain ID: ${e}`);const a=d(e);if(!a)throw new Error(`No RPC URL configured for chain ID: ${e}`);const s=`${e}:${a}`,r=p.get(s);if(r)return r;const n=l.createPublicClient({chain:t.viemChain,transport:l.http(a)});return p.set(s,n),n},A=()=>{const e={};return Object.values(u).forEach(t=>{e[t.id]={name:t.name,moralisName:t.moralisId||"",chain:t.viemChain,rpcUrl:d(t.id)||t.rpcUrl}}),e},U=(e,t=[])=>{const a=c(e);if(!a)return[];const s=[];if(![11155111,421614,84532,688689].includes(e)){const n=t.find(i=>i.chainId===e&&i.isNative);n?s.push(n):s.push({address:o.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:e})}if(!a.supportedTokens)return s;const r=s.some(n=>n.isNative);return a.supportedTokens.forEach(n=>{if(r&&o.isNativeToken(n.address))return;const i=t.find(m=>m.chainId===e&&m.address.toLowerCase()===n.address.toLowerCase());i?s.push(i):s.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:e})}),s},F=async(e,t)=>{const a=c(e);if(!a)throw new Error(`Unsupported chain ID: ${e}`);const s=t.toLowerCase();if(o.isNativeToken(s)){if(!a.nativeCurrency?.decimals)throw new Error(`Native currency decimals not configured for chain ${e}`);return a.nativeCurrency.decimals}if(a.supportedTokens){const r=a.supportedTokens.find(n=>n.address.toLowerCase()===s);if(r)return r.decimals}try{if(!l.isAddress(t,{strict:!1}))throw new Error(`Invalid token address: ${t}`);const r=l.getAddress(t),n=b(e),i=await C.readContract(n,{address:r,abi:y,functionName:"decimals"});return Number(i)}catch{throw new Error(`Could not determine decimals for token ${t} on chain ${e}`)}};exports.CHAIN_CONFIGS=w,exports.T=y,exports.getAllAssetsForChain=U,exports.getChainConfig=c,exports.getChainName=I,exports.getChainsForAssets=A,exports.getClientForChain=b,exports.getDelegateContractAddress=E,exports.getExplorerUrl=k,exports.getRpcUrlForChain=d,exports.getTokenDecimals=F,exports.setRpcOverrides=N;
@@ -1,2 +0,0 @@
1
- "use client";
2
- import{defineChain as h,createPublicClient as C,http as v,isAddress as w,getAddress as g}from"viem";import{readContract as E}from"viem/actions";import{getChainMeta as d,getTokensForChain as I,getDelegateContract as N,ZERO_ADDRESS as k,isNativeToken as m}from"@spicenet-io/spiceflow-core";const y=[{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"}],U="0xcA11bde05977b3631167028862bE2a173976CA11";function x(e){return h({id:e.id,name:e.name,nativeCurrency:e.nativeCurrency,rpcUrls:{default:{http:[e.rpcUrl]}},blockExplorers:{default:{name:e.displayName,url:e.blockExplorer}},testnet:e.network==="testnet",contracts:{multicall3:{address:U}}})}const $=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],l=Object.fromEntries($.map(e=>d(e)).filter(e=>e!=null).map(e=>[e.id,{...e,viemChain:x(e),supportedTokens:I(e.id)}])),_=l;let f={};const u=new Map,A=e=>{f={...e||{}},u.clear()},p=e=>{const t=f[e];return t&&typeof t=="string"&&t.length>0?t:l[e]?.rpcUrl},i=e=>l[e],M=e=>{const t=d(e);return t?.displayName||t?.name||`Chain ${e}`},F=e=>{const t=N(e);if(!t)throw new Error(`Unsupported chain ID: ${e}`);return t},T=(e,t,n)=>{const s=i(e);return s?.blockExplorer?`${s.blockExplorer}/tx/${t}`:"#"},b=e=>{const t=i(e);if(!t)throw new Error(`Unsupported chain ID: ${e}`);const n=p(e);if(!n)throw new Error(`No RPC URL configured for chain ID: ${e}`);const s=`${e}:${n}`,r=u.get(s);if(r)return r;const a=C({chain:t.viemChain,transport:v(n)});return u.set(s,a),a},D=()=>{const e={};return Object.values(l).forEach(t=>{e[t.id]={name:t.name,moralisName:t.moralisId||"",chain:t.viemChain,rpcUrl:p(t.id)||t.rpcUrl}}),e},R=(e,t=[])=>{const n=i(e);if(!n)return[];const s=[];if(![11155111,421614,84532,688689].includes(e)){const a=t.find(o=>o.chainId===e&&o.isNative);a?s.push(a):s.push({address:k,name:n.nativeCurrency.name,symbol:n.nativeCurrency.symbol,decimals:n.nativeCurrency.decimals,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,logoURI:void 0,isNative:!0,chainId:e})}if(!n.supportedTokens)return s;const r=s.some(a=>a.isNative);return n.supportedTokens.forEach(a=>{if(r&&m(a.address))return;const o=t.find(c=>c.chainId===e&&c.address.toLowerCase()===a.address.toLowerCase());o?s.push(o):s.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:e})}),s},O=async(e,t)=>{const n=i(e);if(!n)throw new Error(`Unsupported chain ID: ${e}`);const s=t.toLowerCase();if(m(s)){if(!n.nativeCurrency?.decimals)throw new Error(`Native currency decimals not configured for chain ${e}`);return n.nativeCurrency.decimals}if(n.supportedTokens){const r=n.supportedTokens.find(a=>a.address.toLowerCase()===s);if(r)return r.decimals}try{if(!w(t,{strict:!1}))throw new Error(`Invalid token address: ${t}`);const r=g(t),a=b(e),o=await E(a,{address:r,abi:y,functionName:"decimals"});return Number(o)}catch{throw new Error(`Could not determine decimals for token ${t} on chain ${e}`)}};export{_ as C,y as T,b as a,i as b,T as c,F as d,D as e,R as f,M as g,p as h,O as i,A as s};
@@ -1,2 +0,0 @@
1
- "use client";
2
- "use strict";const l=require("react"),E=require("react/jsx-runtime"),I=require("@spicenet-io/spiceflow-core"),w=require("./index-CmpsCAqC.js"),C=require("./Button-B_UpyUH-.js");class c extends Error{constructor(e,r,t={}){super(r),this.code=e,this.context=t,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,c)}}function P(o){return o instanceof c}const x=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",y="__SPICEFLOW_RELAYER_API_URL__";function U(){if(typeof globalThis>"u")return;const o=globalThis[y];return typeof o=="string"&&o.length>0?o:void 0}class k{constructor(){this.baseUrl=x}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[y]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return U()||this.baseUrl}async createAction(e){console.log("[SpiceRelayer] createAction:start",{baseUrl:this.getEffectiveBaseUrl(),intentCount:e.intents.length,chainAuthorizationCount:e.chainAuthorizations?.length??0});const r=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(a,s)=>typeof s=="bigint"?s.toString():s)});if(!r.ok){const a=await r.text();throw console.log("[SpiceRelayer] createAction:error",{baseUrl:this.getEffectiveBaseUrl(),status:r.status,errorText:a}),new c("RELAYER_ERROR",`Relayer API error: ${r.status} - ${a}`,{httpStatus:r.status,responseBody:a,endpoint:"/actions"})}const t=await r.json();return console.log("[SpiceRelayer] createAction:success",{intentIds:t.intentIds}),t}async executeStep(e,r,t,a){const s=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/${r}/steps/${t}`,d=fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});let n;try{n=await Promise.race([d,new Promise((i,f)=>setTimeout(()=>f(new c("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:e,intentIndex:r,stepIndex:t,endpoint:`/actions/${e}/intents/${r}/steps/${t}`})),1e4))])}catch(i){throw i}if(!n.ok){const i=await n.text();throw new c("RELAYER_EXECUTE_ERROR",`Execute step error: ${n.status} - ${i}`,{httpStatus:n.status,responseBody:i,endpoint:`/actions/${e}/intents/${r}/steps/${t}`,actionId:e})}return{success:!0,transactionHash:(await n.json()).transactionHash}}async checkStepStatus(e,r){const t=e.split("/");let a="";if(t.length>=2){const n=t[0],i=t[1];a=`${this.getEffectiveBaseUrl()}/actions/${n}/intents/${i}/steps/${r}`}else a=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/0/steps/${r}`;const s=await fetch(a);if(!s.ok)throw new c("RELAYER_STATUS_ERROR",`Intent step status check failed: ${s.status}`,{httpStatus:s.status,endpoint:a,intentId:e});const d=await s.json();return{success:!0,data:{status:d.status==="error"?"reverted":d.status,transactionHash:d.txid}}}async requestAirdrop(e){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:e.tag||"default",airdrops:[{chainId:e.chainId,tokenId:e.tokenId,wallet:e.wallet,amount:e.amount||"0.0001"}]})}),t=await r.json().catch(()=>({}));if(!r.ok){const s=t?.message||t?.errors?.[0]?.error||"Failed to request airdrop";return{success:!1,errorMessage:String(s)}}const a=t?.airdrops?.[e.chainId]?.[e.tokenId]?.txHash;return t.errors&&t.errors.length>0?{success:!1,errorMessage:t.errors[0].error}:{success:!0,txHash:a}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async createWallet(e,r){const t=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!t.ok){const a=await t.text();throw new c("RELAYER_ERROR",`Create wallet error: ${t.status} - ${a}`,{httpStatus:t.status,endpoint:`/wallets/${e}`})}return t.json()}async getWallet(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`);if(!r.ok){const t=await r.text();throw new c("RELAYER_ERROR",`Get wallet error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:`/wallets/${e}`})}return r.json()}async createWithdrawal(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(t,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const t=await r.text();throw new c("RELAYER_ERROR",`Create withdrawal error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:"/withdrawals"})}return r.json()}async getWithdrawal(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${e}`);if(!r.ok){const t=await r.text();throw new c("RELAYER_ERROR",`Get withdrawal error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:`/withdrawals/${e}`})}return r.json()}async getRollupTimestamp(){const e=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!e.ok)throw new c("RELAYER_ERROR",`Get rollup timestamp error: ${e.status}`,{httpStatus:e.status,endpoint:"/time"});return e.json()}}const h=new k,A=(o,e)=>{const r=a=>e?e(a):w.getChainName(a),t=[];return o.forEach((a,s)=>{const d=a.calls&&a.calls.length>0,n=a.tokenTransfers&&a.tokenTransfers.length>0;if(d||n){const i={stepId:s,status:s===0?"processing":"pending",chainId:a.chainId,chainName:r(a.chainId),description:"Processing transaction"};t.push(i)}}),t},R=l.createContext(null),m=l.createContext(null),_=({children:o,provider:e,supportedChainIds:r,network:t="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:d,appName:n="Spicenet",apiUrl:i,theme:f,rpcOverrides:u})=>{l.useEffect(()=>{if(!i)return;const B=h.getBaseUrl();return h.setBaseUrl(i),()=>h.setBaseUrl(B)},[i]),l.useEffect(()=>(w.setRpcOverrides(u),()=>w.setRpcOverrides(void 0)),[u]);const p=r??I.getChainIdsByNetwork(t),S=f??null,[T,v]=l.useState(a),$=l.useCallback(B=>v(B),[]);return E.jsx(R.Provider,{value:S,children:E.jsx(m.Provider,{value:{provider:e,supportedChainIds:p,skipFlow:s,mode:T,setMode:$,network:t,nativeChainId:d,appName:n,apiUrl:i,rpcOverrides:u},children:o})})};function g(o,e){const r=o.replace("#",""),t=Math.max(0,Math.round(parseInt(r.substring(0,2),16)*(1-e))),a=Math.max(0,Math.round(parseInt(r.substring(2,4),16)*(1-e))),s=Math.max(0,Math.round(parseInt(r.substring(4,6),16)*(1-e)));return`#${t.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function O(o,e){return{shell:e?.shell??"#141414",shellBorder:e?.shellBorder??g(e?.shell??"#141414",.35),shellInnerBorder:e?.shellInnerBorder??g(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 L(o){return{shell:"#ffffff",shellBorder:"#E9E9E9",shellInnerBorder:"#D5D5D5",cardBg:"#f9fafb",inputBg:"#ffffff",hoverBg:"#f3f4f6",textPrimary:"#111827",textSecondary:"#6b7280",inputText:"#111827",inputPlaceholder:"#9ca3af",cardBorder:"#E0E0E0",inputBorder:"#d1d5db",buttonBorder:"#0e0d0b",successBg:"#d1fae5",successBorder:"#6ee7b7",successText:"#065f46",warningBg:"#fef3c7",warningBorder:"#fcd34d",warningText:"#92400e",errorBg:"#fee2e2",errorBorder:"#fca5a5",errorText:"#dc2626",infoBg:"#dbeafe",infoBorder:"#93c5fd",infoText:"#1e40af"}}function b(o,e){const r=e?{...o,...e}:o,t=r.dark??!1,a=r.primaryColor,s=r.shell??(t?"#141414":"#ffffff");return{primaryColor:a,dark:t,fontFamily:r.fontFamily??'"Helvetica Neue", sans-serif',appName:r.appName??"Spicenet",logo:r.logo,borderRadius:r.borderRadius??"8px",shell:s,shellBorder:g(s,t?.35:.085),shellInnerBorder:g(s,t?.55:.165),card:r.card??(t?"#1e1e1e":"#f9fafb"),input:t?"#171717":"#ffffff",hover:t?"#2a2a2a":"#f3f4f6",text:r.text??(t?"#ffffff":"#111827"),textMuted:r.textMuted??(t?"#888888":"#6b7280"),inputText:t?"#e0e0e0":"#111827",inputPlaceholder:t?"#555555":"#9ca3af",border:r.border??(t?"rgba(255,255,255,0.08)":"#E0E0E0"),inputBorder:t?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:t?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:t?"#0a1f18":"#d1fae5",successBorder:t?"#1a4a3a":"#6ee7b7",successText:t?"#6ee7b7":"#065f46",warningBg:t?"#1f1a0d":"#fef3c7",warningBorder:t?"#4a3820":"#fcd34d",warningText:t?"#fbbf24":"#92400e",errorBg:t?"#1f0d0d":"#fee2e2",errorBorder:t?"#4a2020":"#fca5a5",errorText:t?"#f87171":"#dc2626",infoBg:t?"#0d1325":"#dbeafe",infoBorder:t?"#2a3a5a":"#93c5fd",infoText:t?"#60a5fa":"#1e40af"}}function j(o,e){const r=l.useContext(R)??void 0;return l.useMemo(()=>{const t=r??{primaryColor:"#EA4B4B"},a={...o?.primaryColor?{primaryColor:o.primaryColor}:{},...o?.fontFamily?{fontFamily:o.fontFamily}:{},...e!==void 0?{dark:e}:{}},s=b(t,a),{dark:d,primaryColor:n,appName:i}=s,f=C.createTheme(d?"dark":"light"),u={...f,colors:{...f.colors,primary:n,primaryHover:`${n}dd`},typography:{...f.typography,fontFamily:s.fontFamily}},p={shell:s.shell,shellBorder:s.shellBorder,shellInnerBorder:s.shellInnerBorder,cardBg:s.card,inputBg:s.input,hoverBg:s.hover,textPrimary:s.text,textSecondary:s.textMuted,inputText:s.inputText,inputPlaceholder:s.inputPlaceholder,cardBorder:s.border,inputBorder:s.inputBorder,buttonBorder:s.buttonBorder,successBg:s.successBg,successBorder:s.successBorder,successText:s.successText,warningBg:s.warningBg,warningBorder:s.warningBorder,warningText:s.warningText,errorBg:s.errorBg,errorBorder:s.errorBorder,errorText:s.errorText,infoBg:s.infoBg,infoBorder:s.infoBorder,infoText:s.infoText};return{brand:r,theme:u,dark:d,appName:i,primaryColor:n,dk:p,palette:p}},[r,o,e])}exports.RELAYER_API_URL=x,exports.SpiceFlowProvider=_,exports.SpiceFlowProviderContext=m,exports.SpiceflowError=c,exports.buildDarkPalette=O,exports.buildLightPalette=L,exports.createInitialSteps=A,exports.isSpiceflowError=P,exports.relayerService=h,exports.resolveTheme=b,exports.useSpiceBrand=j;
@@ -1,2 +0,0 @@
1
- "use client";
2
- import{createContext as B,useEffect as w,useState as U,useCallback as C,useContext as k,useMemo as P}from"react";import{jsx as E}from"react/jsx-runtime";import{getChainIdsByNetwork as A}from"@spicenet-io/spiceflow-core";import{g as _,s as m}from"./index-Uh1tWOql.js";import{c as O}from"./Button-CaguAr48.js";class c extends Error{constructor(e,r,t={}){super(r),this.code=e,this.context=t,this.name="SpiceflowError",Error.captureStackTrace&&Error.captureStackTrace(this,c)}}function L(o){return o instanceof c}const x=typeof process<"u"&&process.env?.NEXT_PUBLIC_RELAYER_API_URL||"https://tx-api-devserver.spicenet.io",y="__SPICEFLOW_RELAYER_API_URL__";function N(){if(typeof globalThis>"u")return;const o=globalThis[y];return typeof o=="string"&&o.length>0?o:void 0}class j{constructor(){this.baseUrl=x}setBaseUrl(e){this.baseUrl=e,typeof globalThis<"u"&&(globalThis[y]=e)}getBaseUrl(){return this.getEffectiveBaseUrl()}getEffectiveBaseUrl(){return N()||this.baseUrl}async createAction(e){console.log("[SpiceRelayer] createAction:start",{baseUrl:this.getEffectiveBaseUrl(),intentCount:e.intents.length,chainAuthorizationCount:e.chainAuthorizations?.length??0});const r=await fetch(`${this.getEffectiveBaseUrl()}/actions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(a,s)=>typeof s=="bigint"?s.toString():s)});if(!r.ok){const a=await r.text();throw console.log("[SpiceRelayer] createAction:error",{baseUrl:this.getEffectiveBaseUrl(),status:r.status,errorText:a}),new c("RELAYER_ERROR",`Relayer API error: ${r.status} - ${a}`,{httpStatus:r.status,responseBody:a,endpoint:"/actions"})}const t=await r.json();return console.log("[SpiceRelayer] createAction:success",{intentIds:t.intentIds}),t}async executeStep(e,r,t,a){const s=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/${r}/steps/${t}`,d=fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});let n;try{n=await Promise.race([d,new Promise((i,l)=>setTimeout(()=>l(new c("RELAYER_EXECUTE_ERROR",`Execute step request timed out after ${1e4/1e3}s`,{actionId:e,intentIndex:r,stepIndex:t,endpoint:`/actions/${e}/intents/${r}/steps/${t}`})),1e4))])}catch(i){throw i}if(!n.ok){const i=await n.text();throw new c("RELAYER_EXECUTE_ERROR",`Execute step error: ${n.status} - ${i}`,{httpStatus:n.status,responseBody:i,endpoint:`/actions/${e}/intents/${r}/steps/${t}`,actionId:e})}return{success:!0,transactionHash:(await n.json()).transactionHash}}async checkStepStatus(e,r){const t=e.split("/");let a="";if(t.length>=2){const n=t[0],i=t[1];a=`${this.getEffectiveBaseUrl()}/actions/${n}/intents/${i}/steps/${r}`}else a=`${this.getEffectiveBaseUrl()}/actions/${e}/intents/0/steps/${r}`;const s=await fetch(a);if(!s.ok)throw new c("RELAYER_STATUS_ERROR",`Intent step status check failed: ${s.status}`,{httpStatus:s.status,endpoint:a,intentId:e});const d=await s.json();return{success:!0,data:{status:d.status==="error"?"reverted":d.status,transactionHash:d.txid}}}async requestAirdrop(e){try{const r=await fetch(`${this.getEffectiveBaseUrl()}/airdrop`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:e.tag||"default",airdrops:[{chainId:e.chainId,tokenId:e.tokenId,wallet:e.wallet,amount:e.amount||"0.0001"}]})}),t=await r.json().catch(()=>({}));if(!r.ok){const s=t?.message||t?.errors?.[0]?.error||"Failed to request airdrop";return{success:!1,errorMessage:String(s)}}const a=t?.airdrops?.[e.chainId]?.[e.tokenId]?.txHash;return t.errors&&t.errors.length>0?{success:!1,errorMessage:t.errors[0].error}:{success:!0,txHash:a}}catch(r){return{success:!1,errorMessage:r?.message&&typeof r.message=="string"?r.message:"Failed to request airdrop"}}}async createWallet(e,r){const t=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!t.ok){const a=await t.text();throw new c("RELAYER_ERROR",`Create wallet error: ${t.status} - ${a}`,{httpStatus:t.status,endpoint:`/wallets/${e}`})}return t.json()}async getWallet(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/wallets/${e}`);if(!r.ok){const t=await r.text();throw new c("RELAYER_ERROR",`Get wallet error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:`/wallets/${e}`})}return r.json()}async createWithdrawal(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e,(t,a)=>typeof a=="bigint"?a.toString():a)});if(!r.ok){const t=await r.text();throw new c("RELAYER_ERROR",`Create withdrawal error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:"/withdrawals"})}return r.json()}async getWithdrawal(e){const r=await fetch(`${this.getEffectiveBaseUrl()}/withdrawals/${e}`);if(!r.ok){const t=await r.text();throw new c("RELAYER_ERROR",`Get withdrawal error: ${r.status} - ${t}`,{httpStatus:r.status,endpoint:`/withdrawals/${e}`})}return r.json()}async getRollupTimestamp(){const e=await fetch(`${this.getEffectiveBaseUrl()}/time`);if(!e.ok)throw new c("RELAYER_ERROR",`Get rollup timestamp error: ${e.status}`,{httpStatus:e.status,endpoint:"/time"});return e.json()}}const p=new j,F=(o,e)=>{const r=a=>e?e(a):_(a),t=[];return o.forEach((a,s)=>{const d=a.calls&&a.calls.length>0,n=a.tokenTransfers&&a.tokenTransfers.length>0;if(d||n){const i={stepId:s,status:s===0?"processing":"pending",chainId:a.chainId,chainName:r(a.chainId),description:"Processing transaction"};t.push(i)}}),t},R=B(null),b=B(null),M=({children:o,provider:e,supportedChainIds:r,network:t="testnet",mode:a="7702",skipFlow:s=[],nativeChainId:d,appName:n="Spicenet",apiUrl:i,theme:l,rpcOverrides:f})=>{w(()=>{if(!i)return;const g=p.getBaseUrl();return p.setBaseUrl(i),()=>p.setBaseUrl(g)},[i]),w(()=>(m(f),()=>m(void 0)),[f]);const u=r??A(t),S=l??null,[$,v]=U(a),I=C(g=>v(g),[]);return E(R.Provider,{value:S,children:E(b.Provider,{value:{provider:e,supportedChainIds:u,skipFlow:s,mode:$,setMode:I,network:t,nativeChainId:d,appName:n,apiUrl:i,rpcOverrides:f},children:o})})};function h(o,e){const r=o.replace("#",""),t=Math.max(0,Math.round(parseInt(r.substring(0,2),16)*(1-e))),a=Math.max(0,Math.round(parseInt(r.substring(2,4),16)*(1-e))),s=Math.max(0,Math.round(parseInt(r.substring(4,6),16)*(1-e)));return`#${t.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function Y(o,e){return{shell:e?.shell??"#141414",shellBorder:e?.shellBorder??h(e?.shell??"#141414",.35),shellInnerBorder:e?.shellInnerBorder??h(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 H(o){return{shell:"#ffffff",shellBorder:"#E9E9E9",shellInnerBorder:"#D5D5D5",cardBg:"#f9fafb",inputBg:"#ffffff",hoverBg:"#f3f4f6",textPrimary:"#111827",textSecondary:"#6b7280",inputText:"#111827",inputPlaceholder:"#9ca3af",cardBorder:"#E0E0E0",inputBorder:"#d1d5db",buttonBorder:"#0e0d0b",successBg:"#d1fae5",successBorder:"#6ee7b7",successText:"#065f46",warningBg:"#fef3c7",warningBorder:"#fcd34d",warningText:"#92400e",errorBg:"#fee2e2",errorBorder:"#fca5a5",errorText:"#dc2626",infoBg:"#dbeafe",infoBorder:"#93c5fd",infoText:"#1e40af"}}function T(o,e){const r=e?{...o,...e}:o,t=r.dark??!1,a=r.primaryColor,s=r.shell??(t?"#141414":"#ffffff");return{primaryColor:a,dark:t,fontFamily:r.fontFamily??'"Helvetica Neue", sans-serif',appName:r.appName??"Spicenet",logo:r.logo,borderRadius:r.borderRadius??"8px",shell:s,shellBorder:h(s,t?.35:.085),shellInnerBorder:h(s,t?.55:.165),card:r.card??(t?"#1e1e1e":"#f9fafb"),input:t?"#171717":"#ffffff",hover:t?"#2a2a2a":"#f3f4f6",text:r.text??(t?"#ffffff":"#111827"),textMuted:r.textMuted??(t?"#888888":"#6b7280"),inputText:t?"#e0e0e0":"#111827",inputPlaceholder:t?"#555555":"#9ca3af",border:r.border??(t?"rgba(255,255,255,0.08)":"#E0E0E0"),inputBorder:t?"rgba(255,255,255,0.10)":"#d1d5db",buttonBorder:t?"rgba(255,255,255,0.12)":"#0e0d0b",successBg:t?"#0a1f18":"#d1fae5",successBorder:t?"#1a4a3a":"#6ee7b7",successText:t?"#6ee7b7":"#065f46",warningBg:t?"#1f1a0d":"#fef3c7",warningBorder:t?"#4a3820":"#fcd34d",warningText:t?"#fbbf24":"#92400e",errorBg:t?"#1f0d0d":"#fee2e2",errorBorder:t?"#4a2020":"#fca5a5",errorText:t?"#f87171":"#dc2626",infoBg:t?"#0d1325":"#dbeafe",infoBorder:t?"#2a3a5a":"#93c5fd",infoText:t?"#60a5fa":"#1e40af"}}function J(o,e){const r=k(R)??void 0;return P(()=>{const t=r??{primaryColor:"#EA4B4B"},a={...o?.primaryColor?{primaryColor:o.primaryColor}:{},...o?.fontFamily?{fontFamily:o.fontFamily}:{},...e!==void 0?{dark:e}:{}},s=T(t,a),{dark:d,primaryColor:n,appName:i}=s,l=O(d?"dark":"light"),f={...l,colors:{...l.colors,primary:n,primaryHover:`${n}dd`},typography:{...l.typography,fontFamily:s.fontFamily}},u={shell:s.shell,shellBorder:s.shellBorder,shellInnerBorder:s.shellInnerBorder,cardBg:s.card,inputBg:s.input,hoverBg:s.hover,textPrimary:s.text,textSecondary:s.textMuted,inputText:s.inputText,inputPlaceholder:s.inputPlaceholder,cardBorder:s.border,inputBorder:s.inputBorder,buttonBorder:s.buttonBorder,successBg:s.successBg,successBorder:s.successBorder,successText:s.successText,warningBg:s.warningBg,warningBorder:s.warningBorder,warningText:s.warningText,errorBg:s.errorBg,errorBorder:s.errorBorder,errorText:s.errorText,infoBg:s.infoBg,infoBorder:s.infoBorder,infoText:s.infoText};return{brand:r,theme:f,dark:d,appName:i,primaryColor:n,dk:u,palette:u}},[r,o,e])}export{x as R,b as S,H as a,Y as b,F as c,c as d,M as e,T as f,L as i,p as r,J as u};
File without changes