@spicenet-io/spiceflow-ui 3.1.6 → 3.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/auth-dynamic.cjs.js +1 -1
- package/dist/auth-dynamic.js +1 -1
- package/dist/auth-starknet.cjs.js +1 -1
- package/dist/auth-starknet.js +1 -1
- package/dist/{index-hsU5I_yP.js → index-DpXZlnx3.js} +1 -1
- package/dist/{index-CFwYPy9b.js → index-lOgGr0vB.js} +1 -1
- package/dist/index.cjs.js +11 -11
- package/dist/index.js +13 -13
- package/dist/{providerWallet-BNa0Ucq3.js → providerWallet-CQ6CUPn1.js} +1 -1
- package/dist/{providerWallet-CVPKjRIg.js → providerWallet-CjLlcK4T.js} +1 -1
- package/dist/types/lock.d.ts +6 -0
- package/dist/{useSpiceBrand-Bl8KAgnG.js → useSpiceBrand-C6IJP2it.js} +1 -1
- package/dist/{useSpiceBrand-DgeLaHwa.js → useSpiceBrand-TOVHDNnp.js} +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,6 +47,13 @@ function App() {
|
|
|
47
47
|
|
|
48
48
|
## Development
|
|
49
49
|
|
|
50
|
+
### Fee-Charging Intent Flows
|
|
51
|
+
|
|
52
|
+
- `SpiceSupply` and `SpicePay` are fee-charging intent-execution flows and must surface fee estimation before enabling submission.
|
|
53
|
+
- `SpiceLockModal` is also a fee-charging intent-execution flow and must surface fee estimation before enabling submission.
|
|
54
|
+
- `SpiceDeposit` and `SpiceWithdraw` are treated as non-fee actions and should not use the fee-estimation gating UX.
|
|
55
|
+
- Rule of thumb: every intent-execution flow other than deposit/withdraw should assume fees apply and should gate CTA enablement on successful fee estimation.
|
|
56
|
+
|
|
50
57
|
### Building the Library
|
|
51
58
|
|
|
52
59
|
```bash
|
package/dist/auth-dynamic.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";const e=require("react/jsx-runtime"),c=require("react"),t=require("./Button-B_UpyUH-.js"),L=require("@dynamic-labs/sdk-react-core"),W=require("./providerWallet-
|
|
2
|
+
"use strict";const e=require("react/jsx-runtime"),c=require("react"),t=require("./Button-B_UpyUH-.js"),L=require("@dynamic-labs/sdk-react-core"),W=require("./providerWallet-CjLlcK4T.js");require("viem"),require("./index-DpXZlnx3.js"),require("viem/actions"),require("@spicenet-io/spiceflow-core");const k=({onAuthSuccess:a,onAuthError:r,theme:h="light",className:i="",buttonText:o="Login with Dynamic",autoTrigger:l=!1})=>{const s=t.createTheme(h),[m,D]=c.useState(!1),[g,S]=c.useState(!1),b=L.useDynamicContext(),{user:w,primaryWallet:f,connectedWallets:E,handleLogOut:N,setShowAuthFlow:x,sdkHasLoaded:p,showAuthFlow:j}=b,n=(W.getDynamicEmbeddedWallet({connectedWallets:E,primaryWallet:f})||f)?.address,v=!!w,d=v&&!!n;c.useEffect(()=>{D(!0)},[]),c.useEffect(()=>{d&&n&&a&&a(n)},[d,n,a]),c.useEffect(()=>{l&&p&&m&&!d&&!j&&!g&&(S(!0),x(!0))},[l,p,m,d,j,g,x]);const q=()=>{try{x(!0)}catch(y){const u=`Dynamic login failed: ${String(y)}`;r?r(u):console.error(u)}},C=async()=>{try{await N()}catch(y){const u=`Dynamic logout failed: ${String(y)}`;r?r(u):console.error(u)}};return m?p?v&&!n?e.jsx("div",{className:i,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[e.jsx(t.Spinner,{size:40,borderWidth:3,color:s.colors.primary}),e.jsx("p",{style:{color:s.colors.textMuted,fontSize:"14px"},children:"Finishing wallet setup..."})]})}):d&&n?e.jsx("div",{className:i,children:e.jsxs(t.Button,{variant:"primary",onClick:C,theme:s,children:["Logout (",n.slice(0,6),"...",n.slice(-4),")"]})}):l?e.jsx("div",{className:i,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[e.jsx(t.Spinner,{size:40,borderWidth:3,color:s.colors.primary}),e.jsx("p",{style:{color:s.colors.textMuted,fontSize:"14px"},children:"Opening login..."})]})}):e.jsx("div",{className:i,children:e.jsx(t.Button,{variant:"primary",onClick:q,theme:s,children:o})}):e.jsx("div",{className:i,children:e.jsx(t.Button,{variant:"primary",disabled:!0,theme:s,children:"Loading..."})}):e.jsx("div",{className:i,children:e.jsx(t.Button,{variant:"primary",disabled:!0,theme:s,children:o})})};class B extends c.Component{constructor(r){super(r),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback:this.props.children}}const F=a=>{const{theme:r="light",className:h="",buttonText:i="Login with Dynamic",onAuthError:o}=a,l=t.createTheme(r);return e.jsx(B,{fallback:e.jsx("div",{className:h,children:e.jsx(t.Button,{variant:"primary",onClick:()=>{o&&o('DynamicLogin must be used within SpiceFlowProvider provider="dynamic" and a mounted DynamicContextProvider.')},theme:l,children:i})}),children:e.jsx(k,{...a})})};exports.DynamicLogin=F;
|
package/dist/auth-dynamic.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as e,jsxs as g}from"react/jsx-runtime";import A,{useState as b,useEffect as f}from"react";import{B as d,c as w,S as N}from"./Button-CaguAr48.js";import{useDynamicContext as T}from"@dynamic-labs/sdk-react-core";import{g as j}from"./providerWallet-
|
|
2
|
+
import{jsx as e,jsxs as g}from"react/jsx-runtime";import A,{useState as b,useEffect as f}from"react";import{B as d,c as w,S as N}from"./Button-CaguAr48.js";import{useDynamicContext as T}from"@dynamic-labs/sdk-react-core";import{g as j}from"./providerWallet-CQ6CUPn1.js";import"viem";import"./index-lOgGr0vB.js";import"viem/actions";import"@spicenet-io/spiceflow-core";const z=({onAuthSuccess:a,onAuthError:r,theme:m="light",className:t="",buttonText:o="Login with Dynamic",autoTrigger:s=!1})=>{const i=w(m),[h,E]=b(!1),[x,W]=b(!1),C=T(),{user:L,primaryWallet:v,connectedWallets:k,handleLogOut:F,setShowAuthFlow:p,sdkHasLoaded:u,showAuthFlow:D}=C,n=(j({connectedWallets:k,primaryWallet:v})||v)?.address,S=!!L,l=S&&!!n;return f(()=>{E(!0)},[]),f(()=>{l&&n&&a&&a(n)},[l,n,a]),f(()=>{s&&u&&h&&!l&&!D&&!x&&(W(!0),p(!0))},[s,u,h,l,D,x,p]),h?u?S&&!n?e("div",{className:t,children:g("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[e(N,{size:40,borderWidth:3,color:i.colors.primary}),e("p",{style:{color:i.colors.textMuted,fontSize:"14px"},children:"Finishing wallet setup..."})]})}):l&&n?e("div",{className:t,children:g(d,{variant:"primary",onClick:async()=>{try{await F()}catch(y){const c=`Dynamic logout failed: ${String(y)}`;r?r(c):console.error(c)}},theme:i,children:["Logout (",n.slice(0,6),"...",n.slice(-4),")"]})}):s?e("div",{className:t,children:g("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[e(N,{size:40,borderWidth:3,color:i.colors.primary}),e("p",{style:{color:i.colors.textMuted,fontSize:"14px"},children:"Opening login..."})]})}):e("div",{className:t,children:e(d,{variant:"primary",onClick:()=>{try{p(!0)}catch(y){const c=`Dynamic login failed: ${String(y)}`;r?r(c):console.error(c)}},theme:i,children:o})}):e("div",{className:t,children:e(d,{variant:"primary",disabled:!0,theme:i,children:"Loading..."})}):e("div",{className:t,children:e(d,{variant:"primary",disabled:!0,theme:i,children:o})})};class B extends A.Component{constructor(r){super(r),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback:this.props.children}}const I=a=>{const{theme:r="light",className:m="",buttonText:t="Login with Dynamic",onAuthError:o}=a,s=w(r);return e(B,{fallback:e("div",{className:m,children:e(d,{variant:"primary",onClick:()=>{o&&o('DynamicLogin must be used within SpiceFlowProvider provider="dynamic" and a mounted DynamicContextProvider.')},theme:s,children:t})}),children:e(z,{...a})})};export{I as DynamicLogin};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var A=Object.create;var C=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var _=(e,a,l,u)=>{if(a&&typeof a=="object"||typeof a=="function")for(let t of E(a))!z.call(e,t)&&t!==l&&C(e,t,{get:()=>a[t],enumerable:!(u=P(a,t))||u.enumerable});return e};var h=(e,a,l)=>(l=e!=null?A(R(e)):{},_(a||!e||!e.__esModule?C(l,"default",{value:e,enumerable:!0}):l,e));const r=require("react"),y=require("@spicenet-io/spiceflow-core"),c=require("react/jsx-runtime"),D=require("./useSpiceBrand-
|
|
2
|
+
"use strict";var A=Object.create;var C=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var _=(e,a,l,u)=>{if(a&&typeof a=="object"||typeof a=="function")for(let t of E(a))!z.call(e,t)&&t!==l&&C(e,t,{get:()=>a[t],enumerable:!(u=P(a,t))||u.enumerable});return e};var h=(e,a,l)=>(l=e!=null?A(R(e)):{},_(a||!e||!e.__esModule?C(l,"default",{value:e,enumerable:!0}):l,e));const r=require("react"),y=require("@spicenet-io/spiceflow-core"),c=require("react/jsx-runtime"),D=require("./useSpiceBrand-TOVHDNnp.js"),v=require("./Button-B_UpyUH-.js");require("./index-DpXZlnx3.js"),require("viem"),require("viem/actions");const S="spiceflow:starknet-wallet-connected",T=y.getChainMeta(y.STARKNET_MAINNET_CHAIN_ID)?.rpcUrl??"https://starknet-mainnet.public.blastapi.io",W=(e=T)=>{const[a,l]=r.useState(null),[u,t]=r.useState(!1),[d,p]=r.useState(null),[f,w]=r.useState(null),[g,I]=r.useState(null),x=r.useRef(null);r.useEffect(()=>{import("starknet").then(({RpcProvider:n})=>{I(new n({nodeUrl:e}))}).catch(()=>{})},[e]);const q=r.useCallback(n=>n?`${n.slice(0,6)}...${n.slice(-4)}`:"",[]),k=r.useCallback(async(n,s)=>{const o=await n.enable(s),i=(await o.request({type:"wallet_requestAccounts"}))?.[0];return i?(x.current=o,l(i),w(s.name||s.id),localStorage.setItem(S,s.id),p(o),!0):!1},[g,e]),B=r.useCallback(async()=>{t(!0);try{const{getStarknet:n}=await import("get-starknet-core"),s=n(),o=await s.getAvailableWallets();if(o.length===0)return window.open("https://www.argent.xyz/argent-x/","_blank"),t(!1),!1;const i=o.find(m=>m.id==="argentX")||o.find(m=>m.id==="braavos")||o[0];return await k(s,i)}catch(n){const s=n instanceof Error?n.message:String(n);return console.error("[SpiceFlow:StarkNet] Connection failed:",s),!1}finally{t(!1)}},[k]),j=r.useCallback(()=>{l(null),p(null),w(null),x.current=null,localStorage.removeItem(S)},[]);return r.useEffect(()=>{const n=localStorage.getItem(S);n&&(async()=>{try{const{getStarknet:s}=await import("get-starknet-core"),o=s(),i=(await o.getAuthorizedWallets()).find(m=>m.id===n);if(!i){localStorage.removeItem(S);return}await k(o,i)}catch{localStorage.removeItem(S)}})()},[k]),{address:a,isConnected:!!a,isConnecting:u,account:d,provider:g,walletName:f,connect:B,disconnect:j,formatAddress:q}},b=r.createContext(null),U=({children:e,rpcUrl:a})=>{const l=W(a);return c.jsx(b.Provider,{value:l,children:e})},N=()=>{const e=r.useContext(b);if(!e)throw new Error("useStarknetWalletContext must be used within a <StarknetWalletProvider>. Wrap your StarkNet section with <StarknetWalletProvider> from '@spicenet-io/spiceflow-ui/auth/starknet'.");return e},$=({className:e,styles:a,onConnect:l,onDisconnect:u})=>{const t=N(),{dk:d,dark:p,theme:f}=D.useSpiceBrand(a),w=async()=>{await t.connect()&&l?.()},g=()=>{t.disconnect(),u?.()};return t.isConnected&&t.address?c.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},className:e,children:[c.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",background:d.cardBg,border:`1px solid ${d.cardBorder}`,fontSize:"14px",minWidth:0},children:[c.jsx("span",{style:{fontWeight:500,color:d.textPrimary},children:t.formatAddress(t.address)}),t.walletName&&c.jsxs("span",{style:{color:d.textSecondary,fontSize:"12px",maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["(",t.walletName,")"]})]}),c.jsx(v.Button,{variant:"ghost",size:"sm",onClick:g,title:"Disconnect StarkNet wallet",dark:p,theme:f,children:"\u2715"})]}):c.jsx(v.Button,{variant:"primary",onClick:w,disabled:t.isConnecting,loading:t.isConnecting,className:e,dark:p,theme:f,children:t.isConnecting?"Connecting...":"Connect StarkNet Wallet"})};exports.StarknetWalletButton=$,exports.StarknetWalletProvider=U,exports.useStarknetWallet=W,exports.useStarknetWalletContext=N;
|
package/dist/auth-starknet.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{useState as u,useRef as z,useEffect as C,useCallback as h,createContext as E,useContext as R}from"react";import{getChainMeta as _,STARKNET_MAINNET_CHAIN_ID as D}from"@spicenet-io/spiceflow-core";import{jsx as S,jsxs as x}from"react/jsx-runtime";import{u as T}from"./useSpiceBrand-
|
|
2
|
+
import{useState as u,useRef as z,useEffect as C,useCallback as h,createContext as E,useContext as R}from"react";import{getChainMeta as _,STARKNET_MAINNET_CHAIN_ID as D}from"@spicenet-io/spiceflow-core";import{jsx as S,jsxs as x}from"react/jsx-runtime";import{u as T}from"./useSpiceBrand-C6IJP2it.js";import{B as v}from"./Button-CaguAr48.js";import"./index-lOgGr0vB.js";import"viem";import"viem/actions";const p="spiceflow:starknet-wallet-connected",U=_(D)?.rpcUrl??"https://starknet-mainnet.public.blastapi.io",N=(n=U)=>{const[l,i]=u(null),[k,t]=u(!1),[s,c]=u(null),[m,f]=u(null),[g,I]=u(null),y=z(null);C(()=>{import("starknet").then(({RpcProvider:e})=>{I(new e({nodeUrl:n}))}).catch(()=>{})},[n]);const A=h(e=>e?`${e.slice(0,6)}...${e.slice(-4)}`:"",[]),w=h(async(e,r)=>{const a=await e.enable(r),o=(await a.request({type:"wallet_requestAccounts"}))?.[0];return o?(y.current=a,i(o),f(r.name||r.id),localStorage.setItem(p,r.id),c(a),!0):!1},[g,n]),B=h(async()=>{t(!0);try{const{getStarknet:e}=await import("get-starknet-core"),r=e(),a=await r.getAvailableWallets();if(a.length===0)return window.open("https://www.argent.xyz/argent-x/","_blank"),t(!1),!1;const o=a.find(d=>d.id==="argentX")||a.find(d=>d.id==="braavos")||a[0];return await w(r,o)}catch(e){const r=e instanceof Error?e.message:String(e);return console.error("[SpiceFlow:StarkNet] Connection failed:",r),!1}finally{t(!1)}},[w]),P=h(()=>{i(null),c(null),f(null),y.current=null,localStorage.removeItem(p)},[]);return C(()=>{const e=localStorage.getItem(p);e&&(async()=>{try{const{getStarknet:r}=await import("get-starknet-core"),a=r(),o=(await a.getAuthorizedWallets()).find(d=>d.id===e);if(!o){localStorage.removeItem(p);return}await w(a,o)}catch{localStorage.removeItem(p)}})()},[w]),{address:l,isConnected:!!l,isConnecting:k,account:s,provider:g,walletName:m,connect:B,disconnect:P,formatAddress:A}},W=E(null),$=({children:n,rpcUrl:l})=>{const i=N(l);return S(W.Provider,{value:i,children:n})},b=()=>{const n=R(W);if(!n)throw new Error("useStarknetWalletContext must be used within a <StarknetWalletProvider>. Wrap your StarkNet section with <StarknetWalletProvider> from '@spicenet-io/spiceflow-ui/auth/starknet'.");return n},j=({className:n,styles:l,onConnect:i,onDisconnect:k})=>{const t=b(),{dk:s,dark:c,theme:m}=T(l),f=async()=>{await t.connect()&&i?.()},g=()=>{t.disconnect(),k?.()};return t.isConnected&&t.address?x("div",{style:{display:"flex",alignItems:"center",gap:"8px"},className:n,children:[x("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",background:s.cardBg,border:`1px solid ${s.cardBorder}`,fontSize:"14px",minWidth:0},children:[S("span",{style:{fontWeight:500,color:s.textPrimary},children:t.formatAddress(t.address)}),t.walletName&&x("span",{style:{color:s.textSecondary,fontSize:"12px",maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["(",t.walletName,")"]})]}),S(v,{variant:"ghost",size:"sm",onClick:g,title:"Disconnect StarkNet wallet",dark:c,theme:m,children:"\u2715"})]}):S(v,{variant:"primary",onClick:f,disabled:t.isConnecting,loading:t.isConnecting,className:n,dark:c,theme:m,children:t.isConnecting?"Connecting...":"Connect StarkNet Wallet"})};export{j as StarknetWalletButton,$ as StarknetWalletProvider,N as useStarknetWallet,b as useStarknetWalletContext};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
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",g={4114:"0x860aFc632a6D625B95d8B96f39ECC48E988c6962"},v=new Set([5115]);function w(e){const t=g[e.id]??(v.has(e.id)?void 0:h);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",...t?{contracts:{multicall3:{address:t}}}:{}})}const E=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],u=Object.fromEntries(E.map(e=>o.getChainMeta(e)).filter(e=>e!=null).map(e=>[e.id,{...e,viemChain:w(e),supportedTokens:o.getTokensForChain(e.id)}])),N=u;let f={};const p=new Map,I=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],k=e=>{const t=o.getChainMeta(e);return t?.displayName||t?.name||`Chain ${e}`},A=e=>{const t=o.getDelegateContract(e);if(!t)throw new Error(`Unsupported chain ID: ${e}`);return t},U=(e,t,n)=>{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 n=d(e);if(!n)throw new Error(`No RPC URL configured for chain ID: ${e}`);const s=`${e}:${n}`,r=p.get(s);if(r)return r;const a=l.createPublicClient({chain:t.viemChain,transport:l.http(n,{timeout:15e3,retryCount:2,retryDelay:300}),batch:{multicall:{wait:16}}});return p.set(s,a),a},F=()=>{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},x=(e,t=[])=>{const n=c(e);if(!n)return[];const s=[];if(![11155111,421614,84532,688689].includes(e)){const a=t.find(i=>i.chainId===e&&i.isNative);a?s.push(a):s.push({address:o.ZERO_ADDRESS,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&&o.isNativeToken(a.address))return;const i=t.find(m=>m.chainId===e&&m.address.toLowerCase()===a.address.toLowerCase());i?s.push(i):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},_=async(e,t)=>{const n=c(e);if(!n)throw new Error(`Unsupported chain ID: ${e}`);const s=t.toLowerCase();if(o.isNativeToken(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(!l.isAddress(t,{strict:!1}))throw new Error(`Invalid token address: ${t}`);const r=l.getAddress(t),a=b(e),i=await C.readContract(a,{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=N,exports.
|
|
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",g={4114:"0x860aFc632a6D625B95d8B96f39ECC48E988c6962"},v=new Set([5115]);function w(e){const t=g[e.id]??(v.has(e.id)?void 0:h);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",...t?{contracts:{multicall3:{address:t}}}:{}})}const E=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],u=Object.fromEntries(E.map(e=>o.getChainMeta(e)).filter(e=>e!=null).map(e=>[e.id,{...e,viemChain:w(e),supportedTokens:o.getTokensForChain(e.id)}])),N=u;let f={};const p=new Map,I=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],k=e=>{const t=o.getChainMeta(e);return t?.displayName||t?.name||`Chain ${e}`},A=e=>{const t=o.getDelegateContract(e);if(!t)throw new Error(`Unsupported chain ID: ${e}`);return t},U=(e,t,n)=>{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 n=d(e);if(!n)throw new Error(`No RPC URL configured for chain ID: ${e}`);const s=`${e}:${n}`,r=p.get(s);if(r)return r;const a=l.createPublicClient({chain:t.viemChain,transport:l.http(n,{timeout:15e3,retryCount:2,retryDelay:300}),batch:{multicall:{wait:16}}});return p.set(s,a),a},F=()=>{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},x=(e,t=[])=>{const n=c(e);if(!n)return[];const s=[];if(![11155111,421614,84532,688689].includes(e)){const a=t.find(i=>i.chainId===e&&i.isNative);a?s.push(a):s.push({address:o.ZERO_ADDRESS,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&&o.isNativeToken(a.address))return;const i=t.find(m=>m.chainId===e&&m.address.toLowerCase()===a.address.toLowerCase());i?s.push(i):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},_=async(e,t)=>{const n=c(e);if(!n)throw new Error(`Unsupported chain ID: ${e}`);const s=t.toLowerCase();if(o.isNativeToken(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(!l.isAddress(t,{strict:!1}))throw new Error(`Invalid token address: ${t}`);const r=l.getAddress(t),a=b(e),i=await C.readContract(a,{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=N,exports.G=y,exports.getAllAssetsForChain=x,exports.getChainConfig=c,exports.getChainName=k,exports.getChainsForAssets=F,exports.getClientForChain=b,exports.getDelegateContractAddress=A,exports.getExplorerUrl=U,exports.getRpcUrlForChain=d,exports.getTokenDecimals=_,exports.setRpcOverrides=I;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
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"}],x="0xcA11bde05977b3631167028862bE2a173976CA11",U={4114:"0x860aFc632a6D625B95d8B96f39ECC48E988c6962"},$=new Set([5115]);function _(e){const t=U[e.id]??($.has(e.id)?void 0:x);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",...t?{contracts:{multicall3:{address:t}}}:{}})}const A=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],l=Object.fromEntries(A.map(e=>d(e)).filter(e=>e!=null).map(e=>[e.id,{...e,viemChain:_(e),supportedTokens:I(e.id)}])),M=l;let f={};const u=new Map,D=e=>{f={...e||{}},u.clear()},c=e=>{const t=f[e];return t&&typeof t=="string"&&t.length>0?t:l[e]?.rpcUrl},i=e=>l[e],F=e=>{const t=d(e);return t?.displayName||t?.name||`Chain ${e}`},T=e=>{const t=N(e);if(!t)throw new Error(`Unsupported chain ID: ${e}`);return t},R=(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=c(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,{timeout:15e3,retryCount:2,retryDelay:300}),batch:{multicall:{wait:16}}});return u.set(s,a),a},O=()=>{const e={};return Object.values(l).forEach(t=>{e[t.id]={name:t.name,moralisName:t.moralisId||"",chain:t.viemChain,rpcUrl:c(t.id)||t.rpcUrl}}),e},S=(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(p=>p.chainId===e&&p.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},L=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{M as C,y as
|
|
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"}],x="0xcA11bde05977b3631167028862bE2a173976CA11",U={4114:"0x860aFc632a6D625B95d8B96f39ECC48E988c6962"},$=new Set([5115]);function _(e){const t=U[e.id]??($.has(e.id)?void 0:x);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",...t?{contracts:{multicall3:{address:t}}}:{}})}const A=[1,8453,42161,4114,11155111,421614,84532,5115,123420001114,688688,688689],l=Object.fromEntries(A.map(e=>d(e)).filter(e=>e!=null).map(e=>[e.id,{...e,viemChain:_(e),supportedTokens:I(e.id)}])),M=l;let f={};const u=new Map,D=e=>{f={...e||{}},u.clear()},c=e=>{const t=f[e];return t&&typeof t=="string"&&t.length>0?t:l[e]?.rpcUrl},i=e=>l[e],F=e=>{const t=d(e);return t?.displayName||t?.name||`Chain ${e}`},T=e=>{const t=N(e);if(!t)throw new Error(`Unsupported chain ID: ${e}`);return t},R=(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=c(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,{timeout:15e3,retryCount:2,retryDelay:300}),batch:{multicall:{wait:16}}});return u.set(s,a),a},O=()=>{const e={};return Object.values(l).forEach(t=>{e[t.id]={name:t.name,moralisName:t.moralisId||"",chain:t.viemChain,rpcUrl:c(t.id)||t.rpcUrl}}),e},S=(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(p=>p.chainId===e&&p.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},L=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{M as C,y as G,F as a,b,O as c,R as d,T as e,S as f,i as g,c as h,L as i,D as s};
|