@luno-kit/react 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import {a,c as c$1,b}from'./chunk-A6LYVRYZ.js';export{a as ConnectionStatus}from'./chunk-62JXEP3B.js';export*from'@luno-kit/core';import Z,{useCallback,useEffect,useMemo,useState,useRef,useContext}from'react';import {isSameAddress,convertAddress,formatBalance,createPapiSigner}from'@luno-kit/core/utils';import {create}from'zustand';import {jsx}from'react/jsx-runtime';import {useQueryClient,useQuery,useMutation}from'@tanstack/react-query';import {isNumber}from'dedot/utils';var C={LAST_CONNECTOR_ID:"lastConnectorId",LAST_CHAIN_ID:"lastChainId",LAST_SELECTED_ACCOUNT_INFO:"lastSelectedAccountInfo"};var K=()=>{let e=useRef(false);return {isInitialized:e.current,markAsInitialized:()=>{e.current=true;}}};var M=[],R=()=>{M.forEach(e=>{try{e();}catch(r){console.warn("[LunoStore] Error during listener cleanup:",r);}}),M=[];},z=create((e,r)=>({config:void 0,status:"disconnected",activeConnector:void 0,accounts:[],account:void 0,currentChainId:void 0,currentChain:void 0,currentApi:void 0,isApiReady:false,apiError:null,_setConfig:async n=>{R();let s=null;try{s=await n.storage.getItem(C.LAST_CHAIN_ID);}catch(a){console.warn("[LunoStore] Failed to read stored chain ID from storage:",a);}let o=s?.toLowerCase(),t=o&&n.chains.some(a=>a.genesisHash.toLowerCase()===o)?o:n.chains[0]?.genesisHash,i=t?n.chains.find(a=>a.genesisHash.toLowerCase()===t):void 0;e({config:n,status:"disconnected",activeConnector:void 0,accounts:[],currentChainId:t,currentChain:i});},_setApi:n=>{e({currentApi:n});},_setIsApiReady:n=>{e({isApiReady:n});},setAccount:async n=>{if(!n)return;let{accounts:s,config:o}=r(),t=typeof n=="string"?n.toLowerCase():n.publicKey?.toLowerCase(),i=s.find(a=>a.publicKey?.toLowerCase()===t);if(!i)throw new Error("[LunoStore] setAccount: The provided account or address is not in the current accounts list. Ignored.");if(e({account:i}),o)try{let a={publicKey:i.publicKey,address:i.address,name:i.name,source:i.meta?.source};await o.storage.setItem(C.LAST_SELECTED_ACCOUNT_INFO,JSON.stringify(a)),console.log(`[LunoStore] Persisted selected account: ${i.address}`);}catch(a){console.error("[LunoStore] Failed to persist selected account:",a);}},connect:async(n,s)=>{let o=r().config;if(!o)throw e({status:"disconnected"}),new Error("[LunoStore] LunoConfig has not been initialized. Cannot connect.");let t=o.connectors.find(a=>a.id===n);if(!t)throw e({status:"disconnected"}),new Error(`[LunoStore] Connector with ID "${n}" not found in LunoConfig.`);e({status:"connecting"});let i=r().activeConnector;i&&i.id!==t.id?(console.log(`[LunoStore] Switching connector. Cleaning up listeners for old connector: ${i.id}`),R()):i&&i.id===t.id&&(console.log(`[LunoStore] Attempting to reconnect with the same connector: ${t.id}. Cleaning up existing listeners.`),R());try{let a=async p=>{if(console.log(`[LunoStore] accountsChanged event from ${t.name}:`,p),p.length===0){await r().disconnect();return}p.forEach(b=>{b.publicKey||console.warn(`[LunoStore] Account ${b.address} (from ${t.name}) is missing publicKey.`);});let m=p[0];try{let b=await o.storage.getItem(C.LAST_SELECTED_ACCOUNT_INFO);if(b){let S=JSON.parse(b),y=p.find(x=>S.publicKey&&x.publicKey?.toLowerCase()===S.publicKey.toLowerCase()||isSameAddress(x.address,S.address));y&&(m=y);}}catch(b){console.warn("[LunoStore] Failed to restore account during accountsChanged:",b);}e({accounts:p,account:m});},d=()=>{if(console.log(`[LunoStore] disconnect event from ${t.name}`),r().activeConnector?.id===t.id){R();try{o.storage.removeItem(C.LAST_CONNECTOR_ID),o.storage.removeItem(C.LAST_CHAIN_ID),console.log("[LunoStore] Removed persisted connection info from storage due to disconnect event.");}catch(p){console.error("[LunoStore] Failed to remove connection info from storage:",p);}e({status:"disconnected",activeConnector:void 0,accounts:[]});}else console.warn(`[LunoStore] Received disconnect event from an inactive connector ${t.name}. Ignored.`);};t.on("accountsChanged",a),M.push(()=>t.off("accountsChanged",a)),t.on("disconnect",d),M.push(()=>t.off("disconnect",d));let u=s||r().currentChainId||o.chains[0]?.genesisHash,f=await t.connect(o.appName,o.chains,u);if(!f||f?.length===0)throw new Error("[LunoStore] No accounts found from wallet");let h=f[0];try{let p=await o.storage.getItem(C.LAST_SELECTED_ACCOUNT_INFO);if(p){let m=JSON.parse(p),b=f.find(S=>m.publicKey&&S.publicKey?.toLowerCase()===m.publicKey.toLowerCase()||isSameAddress(S.address,m.address));b?(h=b,console.log(`[LunoStore] Restored previously selected account: ${h.address}`)):console.log("[LunoStore] Previously selected account not found in current accounts list, using first account");}}catch(p){console.warn("[LunoStore] Failed to restore selected account from storage:",p);}e({activeConnector:t,accounts:f,status:"connected",account:h});try{o.storage.setItem(C.LAST_CONNECTOR_ID,t.id),console.log(`[LunoStore] Persisted connectorId: ${t.id}`);}catch(p){console.error("[LunoStore] Failed to persist connectorId to storage:",p);}let l=r().currentChainId,g=s||l||o.chains[0]?.genesisHash;if(g){let p=o.chains.find(m=>m.genesisHash===g);if(p){(g!==l||!r().currentApi)&&e({currentChainId:g,currentChain:p,currentApi:void 0});try{o.storage.setItem(C.LAST_CHAIN_ID,g),console.log(`[LunoStore] Persisted chainId: ${g}`);}catch(m){console.error("[LunoStore] Failed to persist chainId to storage:",m);}}else console.warn(`[LunoStore] After connection, target chain ID "${g}" was not found in config. Current chain state might not have changed. Not persisting chainId.`);}}catch(a){throw R(),e({status:"disconnected",activeConnector:void 0,accounts:[]}),new Error(`[LunoStore] Error connecting with ${t.name}: ${a?.message||a}`)}},disconnect:async()=>{let{activeConnector:n,status:s,config:o}=r();if(!n||s==="disconnecting"||s==="disconnected"){console.log("[LunoStore] No active connector or already disconnected/disconnecting. Disconnect action aborted.");return}e({status:"disconnecting"});try{if(await n.disconnect(),o)try{console.log("[LunoStore] Attempting to remove persisted connection info due to user disconnect action..."),await o.storage.removeItem(C.LAST_CONNECTOR_ID),await o.storage.removeItem(C.LAST_CHAIN_ID),await o.storage.removeItem(C.LAST_SELECTED_ACCOUNT_INFO),console.log("[LunoStore] Removed persisted connection info from storage.");}catch(t){console.error("[LunoStore] Failed to remove connection info from storage during disconnect action:",t);}R(),e({status:"disconnected",activeConnector:void 0,accounts:[],account:void 0}),r().status!=="disconnected"&&console.warn("[LunoStore] disconnect method called, but status is not yet 'disconnected' (event handler might be delayed or did not fire). Check connector events.");}catch(t){throw e({status:"connected"}),new Error(`[LunoStore] Error disconnecting from ${n.name}: ${t?.message||t}`)}},switchChain:async n=>{let{config:s,currentChainId:o,currentApi:t,activeConnector:i,account:a$1,accounts:d}=r();if(!s)throw new Error("[LunoStore] LunoConfig has not been initialized. Cannot switch chain.");if(n===o){console.log(`[LunoStore] Already on chain ${n}. No switch needed.`);return}let u=s.chains.find(f=>f.genesisHash===n);if(!u)throw new Error(`[LunoStore] Chain with ID "${n}" not found in LunoConfig.`);try{try{t&&t.status==="connected"&&await t.disconnect();}catch(h){console.warn("[LunoStore] Failed to disconnect from previous chain:",h);}console.log(`[LunoStore] Attempting to switch chain to ${u.name} (ID: ${n})`),e({currentChainId:n,currentChain:u,currentApi:void 0,isApiReady:!1,apiError:null});let f=await a({config:s,chainId:n});e({currentApi:f,isApiReady:!0}),await s.storage.setItem(C.LAST_CHAIN_ID,n);}catch(f){e({apiError:f,isApiReady:false});}},_setApiError:n=>{e({apiError:n});}}));var k=Z.createContext({});var te=({config:e,children:r})=>{let{_setConfig:n,_setApi:s,_setIsApiReady:o,_setApiError:t,setAccount:i,currentChainId:a$1,config:d,currentApi:u,connect:f,status:h,activeConnector:l,accounts:g,account:p,currentChain:m,isApiReady:b,apiError:S,disconnect:y,switchChain:x}=z(),{markAsInitialized:E,isInitialized:w}=K(),I=useCallback(()=>{s(void 0),o(false);},[s,o]);useEffect(()=>{e&&(console.log("[LunoProvider] Setting config to store:",e),n(e));},[e]),useEffect(()=>{if(w)return;if(!e||!a$1){u&&u.status==="connected"&&u.disconnect().catch(console.error),I();return}let A=e.chains.find(T=>T.genesisHash===a$1),v=e.transports[a$1];if(!A||!v){u&&u.status==="connected"&&u.disconnect().catch(console.error),I();return}u&&u.status==="connected"&&(console.log("[LunoProvider]: Disconnecting API from previous render cycle:",u.runtimeVersion.specName),u.disconnect().catch(T=>console.error("[LunoProvider] Error disconnecting previous API:",T))),I(),a({config:e,chainId:a$1}).then(T=>{s(T),o(true);}).catch(T=>{I(),t(T);}).finally(()=>E());},[e,a$1]),useEffect(()=>{e&&(async()=>{if(await c$1(500),!e.autoConnect){console.log("[LunoProvider]: AutoConnect disabled or config not set.");return}if(!e.storage){console.warn("[LunoProvider]: AutoConnect Storage not available, cannot auto-connect.");return}try{let v=await e.storage.getItem(C.LAST_CONNECTOR_ID),T=await e.storage.getItem(C.LAST_CHAIN_ID);v?(console.log(`[LunoProvider]: AutoConnect Found persisted session: Connector ID "${v}", Chain ID "${T}"`),await f(v,T||void 0)):console.log("[LunoProvider]: AutoConnect No persisted session found or missing data.");}catch(v){console.error("[LunoProvider]: AutoConnect Error during auto-connect process:",v);}})();},[e]),useEffect(()=>{if(b&&u&&m&&m.ss58Format!==void 0&&m.ss58Format!==null)try{let A=u.consts.system.ss58Prefix;A!=null&&A!==m.ss58Format?console.error(`[LunoProvider]: SS58 Format Mismatch for chain "${m.name}" (genesisHash: ${m.genesisHash}):
2
- - Configured SS58Format: ${m.ss58Format}
3
- - Node Runtime SS58Format: ${A}
4
- Please verify your Luno configuration for this chain to ensure correct address display and interaction.`):A==null&&console.warn(`[LunoProvider]: Could not determine SS58 format from the API for chain "${m.name}". Cannot validate configured SS58Format (${m.ss58Format}). The application will use the configured value.`);}catch(A){console.error(`[LunoProvider]: Error retrieving SS58 format from API for chain "${m.name}" while attempting validation:`,A);}},[b,u,m]);let _=useMemo(()=>({config:d,status:h,activeConnector:l,accounts:g,account:p,setAccount:i,currentChainId:a$1,currentChain:m,currentApi:u,isApiReady:b,connect:f,disconnect:y,switchChain:x,apiError:S}),[d,h,l,g,p,a$1,m,u,b,S,f,y,x,i]);return jsx(k.Provider,{value:_,children:r})};var c=()=>{let e=useContext(k);if(e===void 0)throw new Error("useLuno must be used within a LunoProvider");return e};var D=()=>{let{account:e,currentChain:r}=c(),n=useMemo(()=>{if(e){if(!r||r?.ss58Format===void 0)return e;try{let s=convertAddress(e.address,r.ss58Format);return {...e,address:s}}catch(s){return console.error(`[useAccount]: Failed to re-format address for account ${e.address}:`,s),{...e}}}},[e,r,r?.ss58Format]);return {account:n,address:n?.address}};var pn=()=>{let{accounts:e,setAccount:r,currentChain:n}=c();return {accounts:useMemo(()=>!n||n?.ss58Format===void 0?e??[]:(e||[]).map(o=>{try{let t=convertAddress(o.address,n.ss58Format);return {...o,address:t}}catch(t){return console.error(`[useAccounts]: Failed to re-format address for account ${o.address}:`,t),{...o}}}),[e,n,n?.ss58Format]),selectAccount:r}};var gn=()=>{let{activeConnector:e}=c();return e};var yn=()=>{let{currentApi:e,isApiReady:r,apiError:n}=c();return {api:e,isApiReady:r,apiError:n}};var fe=e=>e,V=({queryKey:e,factory:r,params:n,options:s={}})=>{let[o,t]=useState(void 0),{currentApi:i,isApiReady:a}=c(),d=useQueryClient(),{enabled:u=true,transform:f=fe,defaultValue:h}=s,l=useRef(null),g=useMemo(()=>{if(!(!n||!i||!a))return typeof n=="function"?[n(i)]:n},[n,i,a]),p=useMemo(()=>[e,g,i?.genesisHash],[e,g,i?.genesisHash]);useEffect(()=>{if(l.current&&(l.current(),l.current=null),!(!u||!r||!i||!g||!a)){try{let S=r(i),y=typeof S=="function"?S.bind(i):S,x=E=>{try{let w=f(E);d.setQueryData(p,w),t(void 0);}catch(w){t(new Error(`[useSubscription]: ${w}`));}};y(...g,x).then(E=>{l.current=E;}).catch(E=>{t(new Error(`[useSubscription]: ${E}`));});}catch(S){t(new Error(`[useSubscription]: ${S}`));}return ()=>{l.current&&(l.current(),l.current=null,t(void 0));}}},[JSON.stringify(p),u,d]);let{data:m,isLoading:b}=useQuery({queryKey:p,queryFn:()=>Promise.resolve(h),enabled:false,initialData:h});return {data:m,error:o,isLoading:!!(u&&a&&!m)}};var ge=10,Se=(e,r)=>{let n=e[0],s=e[1],o=n.data.free,t=n.data.reserved,i=n.data.frozen,a=BigInt(o)+BigInt(t),d=o>i?BigInt(o)-BigInt(i):0n;return {free:o,total:a,reserved:t,transferable:d,formattedTransferable:formatBalance(d,r.tokenDecimals),formattedTotal:formatBalance(a,r.tokenDecimals),locks:s.map(u=>({id:u.id,amount:u.amount,reason:u.reasons,lockHuman:formatBalance(u.amount,r.tokenDecimals)}))}},In=({address:e})=>{let{currentApi:r,isApiReady:n,currentChain:s}=c();return V({queryKey:"/native-balance",factory:o=>o.queryMulti,params:o=>[{fn:o.query.system.account,args:[e]},{fn:o.query.balances.locks,args:[e]}],options:{enabled:!!r&&n&&!!e,transform:o=>{let t={tokenDecimals:s?.nativeCurrency?.decimals??ge,tokenSymbol:s?.nativeCurrency?.symbol,ss58Format:s?.ss58Format};return Se(o,t)}}})};var Pn=()=>{let{currentApi:e,isApiReady:r}=c();return V({queryKey:"/block-number",factory:s=>s.query.system.number,params:[],options:{enabled:!!e&&r,transform:s=>s}})};var kn=()=>{let{currentChain:e,currentChainId:r}=c();return {chain:e,chainId:r}};var Hn=()=>{let{config:e}=c();return e?.chains?[...e.chains]:[]};var _n=()=>{let{config:e}=c();return e};function L(e,r){let n={};r?.onSuccess&&(n.onSuccess=r.onSuccess),r?.onError&&(n.onError=r.onError),r?.onSettled&&(n.onSettled=r.onSettled);let s=useMutation({mutationFn:e,retry:false,throwOnError:false,...n});return {mutate:(o,t)=>{s.mutate(o,t);},mutateAsync:(o,t)=>s.mutateAsync(o,t),data:s.data,error:s.error,isError:s.isError,isIdle:s.isIdle,isPending:s.isPending,isSuccess:s.isSuccess,reset:s.reset,status:s.status,variables:s.variables}}var Jn=e=>{let{connect:r,config:n,activeConnector:s,status:o}=c(),i=L(async a=>{await r(a.connectorId,a.targetChainId),await c$1();},e);return {connect:i.mutate,connectAsync:i.mutateAsync,connectors:n?.connectors?[...n.connectors]:[],activeConnector:s,status:o,data:i.data,error:i.error,isError:i.isError,isIdle:i.isIdle,isPending:i.isPending,isSuccess:i.isSuccess,reset:i.reset,variables:i.variables}};var jn=()=>{let{config:e}=c();return e?.connectors?[...e.connectors]:[]};var et=e=>{let{disconnect:r,status:n}=c(),o=L(async()=>{await r();},e);return {disconnect:t=>o.mutate(void 0,t),disconnectAsync:t=>o.mutateAsync(void 0,t),status:n,data:o.data,error:o.error,isError:o.isError,isIdle:o.isIdle,isPending:o.isPending,isSuccess:o.isSuccess,reset:o.reset,variables:o.variables}};function st(){let{account:e,currentChain:r}=c(),[n,s]=useState(null),[o,t]=useState(false),[i,a]=useState(null),d=useCallback(async(u,f)=>{let h=f||e?.address;if(!(!u||!h||!r)){t(true),a(null);try{let l=await u.paymentInfo(h),g=r.nativeCurrency.decimals,p={...l,partialFeeFormatted:formatBalance(l.partialFee,g)};return s(p),p}catch(l){let g=l instanceof Error?l:new Error("Failed to estimate payment info");a(g);}finally{t(false);}}},[e?.address,r]);return {data:n,isLoading:o,error:i,estimate:d}}var ut=()=>{let{currentApi:e,currentChainId:r,isApiReady:n}=c(),{data:s,isLoading:o,error:t}=useQuery({queryKey:["/genesis-hash",r],queryFn:async()=>await e.rpc.chain_getBlockHash(0),enabled:!!e&&n&&!!r,staleTime:1/0,gcTime:1/0,retry:false});return {data:s,isLoading:o,error:t}};var G=()=>{let{activeConnector:e}=c(),{account:r}=D(),[n,s]=useState(void 0),[o,t]=useState(false);return useEffect(()=>{if(!e||!r?.address){s(void 0),t(false);return}t(true),e.getSigner().then(i=>s(i)).catch(()=>s(void 0)).finally(()=>t(false));},[e,r?.address]),{data:n,isLoading:o}};function bt(){let{data:e}=G(),{address:r}=D(),[n,s]=useState(false),[o,t]=useState(void 0);return useEffect(()=>{if(!e||!r){t(void 0),s(false);return}s(true),createPapiSigner(r,e).then(i=>t(i)).catch(()=>t(void 0)).finally(()=>s(false));},[e,r]),{data:o,isLoading:n}}var Lt=()=>{let{currentApi:e,isApiReady:r,currentChainId:n}=c();return useQuery({queryKey:["luno","runtimeVersion",n],queryFn:async()=>await e.getRuntimeVersion(),enabled:!!e&&r&&!!n})};function Dt(e){let{activeConnector:r,currentApi:n,isApiReady:s}=c(),{account:o}=D(),[t,i]=useState("idle"),[a,d]=useState("idle"),[u,f]=useState(null),h=useCallback(async g=>{if(!n||!s)throw new Error("[useSendTransaction]: Polkadot API is not ready.");if(!r)throw new Error("[useSendTransaction]: No active connector found.");if(!o||!o.address||!o.meta?.source)throw new Error("[useSendTransaction]: No active account, address, or account metadata (source) found.");if(!g.extrinsic)throw new Error("[useSendTransaction]: No extrinsic provided to send.");let p=await r.getSigner();if(!p)throw new Error("[useSendTransaction]: Could not retrieve signer from the injector.");return i("signing"),d("idle"),new Promise((m,b$1)=>{let S;g.extrinsic.signAndSend(o.address,{signer:p},({status:y,dispatchError:x,events:E,dispatchInfo:w,txHash:I,txIndex:_})=>{let A=T=>{S&&S(),m(T);},v=T=>{S&&S(),f(T),b$1(T);};switch(y.type){case "Broadcasting":d("broadcasting");break;case "BestChainBlockIncluded":d("inBlock");break;case "Finalized":i("success"),d("finalized"),A(x?{transactionHash:I,blockHash:y.value?.blockHash,blockNumber:y.value?.blockNumber,events:E,status:"failed",dispatchError:x,errorMessage:b(n,x),dispatchInfo:w}:{transactionHash:I,blockHash:y.value?.blockHash,blockNumber:y.value?.blockNumber,events:E,status:"success",dispatchError:void 0,errorMessage:void 0,dispatchInfo:w});break;case "Invalid":i("failed"),d("invalid"),v(new Error(`Transaction invalid: ${I}`));break;case "Drop":i("failed"),d("dropped"),v(new Error(`Transaction dropped: ${I}`));break}}).then(y=>{S=y;}).catch(y=>{i("failed"),console.error("[useSendTransaction]: Error in signAndSend promise:",y?.message||y),f(y),b$1(y);});})},[n,s,r,o,i,d]),l=L(h,e);return {sendTransaction:l.mutate,sendTransactionAsync:l.mutateAsync,data:l.data,error:u||l.error,isError:!!u||l.isError,isIdle:l.isIdle,isPending:l.isPending,isSuccess:l.isSuccess,reset:l.reset,status:l.status,variables:l.variables,txStatus:t,detailedStatus:a}}function Ot(e){let{account:r,activeConnector:n,currentApi:s,isApiReady:o}=c(),[t,i]=useState(null),a=useCallback(async u=>{if(!s||!o)throw new Error("[useSendTransactionHash]: Polkadot API is not ready.");if(!n)throw new Error("[useSendTransactionHash]: No active connector found.");if(!r||!r.address||!r.meta?.source)throw new Error("[useSendTransactionHash]: No active account, address, or account metadata (source) found.");if(!u.extrinsic)throw new Error("[useSendTransactionHash]: No extrinsic provided to send.");let f=await n.getSigner();if(!f)throw new Error("[useSendTransactionHash]: Could not retrieve signer from the injector.");try{return await u.extrinsic.signAndSend(r.address,{signer:f}).catch(l=>{throw l})}catch(h){throw i(h),h}},[s,o,n,r]),d=L(a,e);return {sendTransaction:d.mutate,sendTransactionAsync:d.mutateAsync,data:d.data,error:t||d.error,isError:!!t||d.isError,isIdle:d.isIdle,isPending:d.isPending,isSuccess:d.isSuccess,reset:d.reset,status:d.status,variables:d.variables}}function _t(e){let{activeConnector:r,account:n,accounts:s}=c(),t=L(async i=>{if(!r)throw new Error("[useSignMessage]: No active connector found to sign the message.");if(!n||!n.address||!n.meta?.source)throw new Error("[useSignMessage]: No address provided for signing.");if(!s.some(u=>u.address===n.address))throw new Error(`[useSignMessage]: Address ${n.address} is not managed by ${r.id}.`);if(!i.message)throw new Error("[useSignMessage]: No message provided for signing.");let a=s.find(u=>isSameAddress(u.address,n.address));if(!a)throw new Error("[useSignMessage]: Invalid account address.");let d=await r.signMessage(i.message,a.address);if(!d)throw new Error("[useSignMessage]: Signature was not obtained. The user may have cancelled the request or the connector failed.");return {signature:d,rawMessage:i.message,addressUsed:n.address}},e);return {signMessage:t.mutate,signMessageAsync:t.mutateAsync,data:t.data,error:t.error,isError:t.isError,isIdle:t.isIdle,isPending:t.isPending,isSuccess:t.isSuccess,reset:t.reset,status:t.status,variables:t.variables}}var j=42,zt=()=>{let{currentApi:e,isApiReady:r,currentChain:n}=c(),s=n?.ss58Format!==void 0?n.ss58Format:j;return useMemo(()=>{if(e&&r){let o;try{let t=e.consts.system.ss58Prefix;o=isNumber(t)?t:j;}catch(t){console.error("[useSs58Format] Error fetching chainSS58:",t),o=s;}return {data:o,isLoading:false}}else return {data:void 0,isLoading:true}},[e,r,s])};var Gt=()=>{let{status:e}=c();return e};var Xt=e=>{let{switchChain:r,config:n,currentChain:s,currentChainId:o}=c(),i=L(async a=>{await r(a.chainId);},e);return {switchChain:i.mutate,switchChainAsync:i.mutateAsync,chains:n?.chains?[...n.chains]:[],currentChain:s,currentChainId:o,data:i.data,error:i.error,isError:i.isError,isIdle:i.isIdle,isPending:i.isPending,isSuccess:i.isSuccess,reset:i.reset,variables:i.variables}};export{te as LunoProvider,D as useAccount,pn as useAccounts,gn as useActiveConnector,yn as useApi,In as useBalance,Pn as useBlockNumber,kn as useChain,Hn as useChains,_n as useConfig,Jn as useConnect,jn as useConnectors,et as useDisconnect,st as useEstimatePaymentInfo,ut as useGenesisHash,bt as usePapiSigner,Lt as useRuntimeVersion,Dt as useSendTransaction,Ot as useSendTransactionHash,_t as useSignMessage,G as useSigner,zt as useSs58Format,Gt as useStatus,V as useSubscription,Xt as useSwitchChain};//# sourceMappingURL=index.js.map
1
+ import {a,c,b}from'./chunk-A6LYVRYZ.js';export{a as ConnectionStatus}from'./chunk-62JXEP3B.js';export*from'@luno-kit/core';import Z,{useCallback,useEffect,useMemo,useState,useRef,useContext}from'react';import {isSameAddress,convertAddress,formatBalance,createPapiSigner}from'@luno-kit/core/utils';import {create}from'zustand';import {jsx}from'react/jsx-runtime';import {useQueryClient,useQuery,useMutation}from'@tanstack/react-query';import {isNumber}from'dedot/utils';var y={LAST_CONNECTOR_ID:"lastConnectorId",LAST_CHAIN_ID:"lastChainId",LAST_SELECTED_ACCOUNT_INFO:"lastSelectedAccountInfo",RECENT_SELECTED_ACCOUNT_INFO:"recentSelectedAccountInfo",RECENT_CONNECTOR_ID:"recentConnectorId"};var $=()=>{let e=useRef(false);return {isInitialized:e.current,markAsInitialized:()=>{e.current=true;}}};var K=[],D=()=>{K.forEach(e=>{try{e();}catch(r){console.warn("[LunoStore] Error during listener cleanup:",r);}}),K=[];},q=create((e,r)=>({config:void 0,status:"disconnected",activeConnector:void 0,accounts:[],account:void 0,currentChainId:void 0,currentChain:void 0,currentApi:void 0,isApiReady:false,apiError:null,_setConfig:async n=>{D();let s=null;try{s=await n.storage.getItem(y.LAST_CHAIN_ID);}catch(a){console.warn("[LunoStore] Failed to read stored chain ID from storage:",a);}let t=s?.toLowerCase(),o=t&&n.chains.some(a=>a.genesisHash.toLowerCase()===t)?t:n.chains[0]?.genesisHash,i=o?n.chains.find(a=>a.genesisHash.toLowerCase()===o):void 0;e({config:n,status:"disconnected",activeConnector:void 0,accounts:[],currentChainId:o,currentChain:i});},_setApi:n=>{e({currentApi:n});},_setIsApiReady:n=>{e({isApiReady:n});},setAccount:async n=>{if(!n)return;let{accounts:s,config:t}=r(),o=typeof n=="string"?n.toLowerCase():n.publicKey?.toLowerCase(),i=s.find(a=>a.publicKey?.toLowerCase()===o);if(!i)throw new Error("[LunoStore] setAccount: The provided account or address is not in the current accounts list. Ignored.");if(e({account:i}),t)try{let a={publicKey:i.publicKey,address:i.address,name:i.name,source:i.meta?.source};await t.storage.setItem(y.LAST_SELECTED_ACCOUNT_INFO,JSON.stringify(a)),await t.storage.setItem(y.RECENT_SELECTED_ACCOUNT_INFO,JSON.stringify(a)),console.log(`[LunoStore] Persisted selected account: ${i.address}`);}catch(a){console.error("[LunoStore] Failed to persist selected account:",a);}},connect:async(n,s)=>{let t=r().config;if(!t)throw e({status:"disconnected"}),new Error("[LunoStore] LunoConfig has not been initialized. Cannot connect.");let o=t.connectors.find(a=>a.id===n);if(!o)throw e({status:"disconnected"}),new Error(`[LunoStore] Connector with ID "${n}" not found in LunoConfig.`);e({status:"connecting"});let i=r().activeConnector;i&&i.id!==o.id?(console.log(`[LunoStore] Switching connector. Cleaning up listeners for old connector: ${i.id}`),D()):i&&i.id===o.id&&(console.log(`[LunoStore] Attempting to reconnect with the same connector: ${o.id}. Cleaning up existing listeners.`),D());try{let a=s||r().currentChainId||t.chains[0]?.genesisHash,d=await o.connect(t.appName,t.chains,a);if(!d||d?.length===0)throw new Error("[LunoStore] No accounts found from wallet");let c=d[0];try{let p=await t.storage.getItem(y.LAST_SELECTED_ACCOUNT_INFO),h=await t.storage.getItem(y.RECENT_SELECTED_ACCOUNT_INFO),f=p||h;if(f){let A=JSON.parse(f),C=d.find(S=>isSameAddress(S.address,A.address));C?(c=C,console.log(`[LunoStore] Restored previously selected account: ${c.address}`)):console.log("[LunoStore] Previously selected account not found in current accounts list, using first account");}}catch(p){console.warn("[LunoStore] Failed to restore selected account from storage:",p);}e({activeConnector:o,accounts:d,status:"connected",account:c});let m={publicKey:c.publicKey,address:c.address,name:c.name,source:c.meta?.source};try{t.storage.setItem(y.LAST_CONNECTOR_ID,o.id),t.storage.setItem(y.RECENT_CONNECTOR_ID,o.id),t.storage.setItem(y.LAST_SELECTED_ACCOUNT_INFO,JSON.stringify(m)),t.storage.setItem(y.RECENT_SELECTED_ACCOUNT_INFO,JSON.stringify(m)),console.log(`[LunoStore] Persisted connectorId: ${o.id}`);}catch(p){console.error("[LunoStore] Failed to persist connectorId to storage:",p);}let g=r().currentChainId,l=s||g||t.chains[0]?.genesisHash;if(l){let p=t.chains.find(h=>h.genesisHash===l);if(p){(l!==g||!r().currentApi)&&e({currentChainId:l,currentChain:p,currentApi:void 0});try{t.storage.setItem(y.LAST_CHAIN_ID,l),console.log(`[LunoStore] Persisted chainId: ${l}`);}catch(h){console.error("[LunoStore] Failed to persist chainId to storage:",h);}}else console.warn(`[LunoStore] After connection, target chain ID "${l}" was not found in config. Current chain state might not have changed. Not persisting chainId.`);}}catch(a){throw D(),e({status:"disconnected",activeConnector:void 0,accounts:[]}),new Error(`[LunoStore] Error connecting with ${o.name}: ${a?.message||a}`)}},disconnect:async()=>{let{activeConnector:n,status:s,config:t}=r();if(!n||s==="disconnecting"||s==="disconnected"){console.log("[LunoStore] No active connector or already disconnected/disconnecting. Disconnect action aborted.");return}e({status:"disconnecting"});try{if(await n.disconnect(),t)try{console.log("[LunoStore] Attempting to remove persisted connection info due to user disconnect action..."),await t.storage.removeItem(y.LAST_CONNECTOR_ID),await t.storage.removeItem(y.LAST_CHAIN_ID),await t.storage.removeItem(y.LAST_SELECTED_ACCOUNT_INFO),console.log("[LunoStore] Removed persisted connection info from storage.");}catch(o){console.error("[LunoStore] Failed to remove connection info from storage during disconnect action:",o);}D(),e({status:"disconnected",activeConnector:void 0,accounts:[],account:void 0}),r().status!=="disconnected"&&console.warn("[LunoStore] disconnect method called, but status is not yet 'disconnected' (event handler might be delayed or did not fire). Check connector events.");}catch(o){throw e({status:"connected"}),new Error(`[LunoStore] Error disconnecting from ${n.name}: ${o?.message||o}`)}},switchChain:async n=>{let{config:s,currentChainId:t,currentApi:o,activeConnector:i,account:a$1,accounts:d}=r();if(!s)throw new Error("[LunoStore] LunoConfig has not been initialized. Cannot switch chain.");if(n===t){console.log(`[LunoStore] Already on chain ${n}. No switch needed.`);return}let c=s.chains.find(m=>m.genesisHash===n);if(!c)throw new Error(`[LunoStore] Chain with ID "${n}" not found in LunoConfig.`);try{try{o&&o.status==="connected"&&await o.disconnect();}catch(g){console.warn("[LunoStore] Failed to disconnect from previous chain:",g);}console.log(`[LunoStore] Attempting to switch chain to ${c.name} (ID: ${n})`),e({currentChainId:n,currentChain:c,currentApi:void 0,isApiReady:!1,apiError:null});let m=await a({config:s,chainId:n});e({currentApi:m,isApiReady:!0}),await s.storage.setItem(y.LAST_CHAIN_ID,n);}catch(m){e({apiError:m,isApiReady:false});}},_setApiError:n=>{e({apiError:n});}}));var M=Z.createContext({});var te=({config:e,children:r})=>{let{_setConfig:n,_setApi:s,_setIsApiReady:t,_setApiError:o,setAccount:i,currentChainId:a$1,config:d,currentApi:c$1,connect:m,status:g,activeConnector:l,accounts:p,account:h,currentChain:f,isApiReady:A,apiError:C,disconnect:S,switchChain:v}=q(),{markAsInitialized:x,isInitialized:w}=$(),I=useCallback(()=>{s(void 0),t(false);},[s,t]);useEffect(()=>{e&&(console.log("[LunoProvider] Setting config to store:",e),n(e));},[e]),useEffect(()=>{if(w)return;if(!e||!a$1){c$1&&c$1.status==="connected"&&c$1.disconnect().catch(console.error),I();return}let b=e.chains.find(L=>L.genesisHash===a$1),T=e.transports[a$1];if(!b||!T){c$1&&c$1.status==="connected"&&c$1.disconnect().catch(console.error),I();return}c$1&&c$1.status==="connected"&&(console.log("[LunoProvider]: Disconnecting API from previous render cycle:",c$1.runtimeVersion.specName),c$1.disconnect().catch(L=>console.error("[LunoProvider] Error disconnecting previous API:",L))),I(),a({config:e,chainId:a$1}).then(L=>{s(L),t(true);}).catch(L=>{I(),o(L);}).finally(()=>x());},[e,a$1]),useEffect(()=>{e&&(async()=>{if(await c(500),!e.autoConnect){console.log("[LunoProvider]: AutoConnect disabled or config not set.");return}if(!e.storage){console.warn("[LunoProvider]: AutoConnect Storage not available, cannot auto-connect.");return}try{let T=await e.storage.getItem(y.LAST_CONNECTOR_ID),L=await e.storage.getItem(y.LAST_CHAIN_ID);T?(console.log(`[LunoProvider]: AutoConnect Found persisted session: Connector ID "${T}", Chain ID "${L}"`),await m(T,L||void 0)):console.log("[LunoProvider]: AutoConnect No persisted session found or missing data.");}catch(T){console.error("[LunoProvider]: AutoConnect Error during auto-connect process:",T);}})();},[e]),useEffect(()=>{if(A&&c$1&&f&&f.ss58Format!==void 0&&f.ss58Format!==null)try{let b=c$1.consts.system.ss58Prefix;b!=null&&b!==f.ss58Format?console.error(`[LunoProvider]: SS58 Format Mismatch for chain "${f.name}" (genesisHash: ${f.genesisHash}):
2
+ - Configured SS58Format: ${f.ss58Format}
3
+ - Node Runtime SS58Format: ${b}
4
+ Please verify your Luno configuration for this chain to ensure correct address display and interaction.`):b==null&&console.warn(`[LunoProvider]: Could not determine SS58 format from the API for chain "${f.name}". Cannot validate configured SS58Format (${f.ss58Format}). The application will use the configured value.`);}catch(b){console.error(`[LunoProvider]: Error retrieving SS58 format from API for chain "${f.name}" while attempting validation:`,b);}},[A,c$1,f]);let P=useMemo(()=>({config:d,status:g,activeConnector:l,accounts:p,account:h,setAccount:i,currentChainId:a$1,currentChain:f,currentApi:c$1,isApiReady:A,connect:m,disconnect:S,switchChain:v,apiError:C}),[d,g,l,p,h,a$1,f,c$1,A,C,m,S,v,i]);return jsx(M.Provider,{value:P,children:r})};var u=()=>{let e=useContext(M);if(e===void 0)throw new Error("useLuno must be used within a LunoProvider");return e};var R=()=>{let{account:e,currentChain:r}=u(),n=useMemo(()=>{if(e){if(!r||r?.ss58Format===void 0)return e;try{let s=convertAddress(e.address,r.ss58Format);return {...e,address:s}}catch(s){return console.error(`[useAccount]: Failed to re-format address for account ${e.address}:`,s),{...e}}}},[e,r,r?.ss58Format]);return {account:n,address:n?.address}};var ln=()=>{let{accounts:e,setAccount:r,currentChain:n}=u();return {accounts:useMemo(()=>!n||n?.ss58Format===void 0?e??[]:(e||[]).map(t=>{try{let o=convertAddress(t.address,n.ss58Format);return {...t,address:o}}catch(o){return console.error(`[useAccounts]: Failed to re-format address for account ${t.address}:`,o),{...t}}}),[e,n,n?.ss58Format]),selectAccount:r}};var fn=()=>{let{activeConnector:e}=u();return e};var hn=()=>{let{currentApi:e,isApiReady:r,apiError:n}=u();return {api:e,isApiReady:r,apiError:n}};var fe=e=>e,k=({queryKey:e,factory:r,params:n,options:s={}})=>{let[t,o]=useState(void 0),{currentApi:i,isApiReady:a}=u(),d=useQueryClient(),{enabled:c=true,transform:m=fe,defaultValue:g}=s,l=useRef(null),p=useMemo(()=>{if(!(!n||!i||!a))return typeof n=="function"?[n(i)]:n},[n,i,a]),h=useMemo(()=>[e,p,i?.genesisHash],[e,p,i?.genesisHash]);useEffect(()=>{if(l.current&&(l.current(),l.current=null),!(!c||!r||!i||!p||!a)){try{let C=r(i),S=typeof C=="function"?C.bind(i):C,v=x=>{try{let w=m(x);d.setQueryData(h,w),o(void 0);}catch(w){o(new Error(`[useSubscription]: ${w}`));}};S(...p,v).then(x=>{l.current=x;}).catch(x=>{o(new Error(`[useSubscription]: ${x}`));});}catch(C){o(new Error(`[useSubscription]: ${C}`));}return ()=>{l.current&&(l.current(),l.current=null,o(void 0));}}},[JSON.stringify(h),c,d]);let{data:f,isLoading:A}=useQuery({queryKey:h,queryFn:()=>Promise.resolve(g),enabled:false,initialData:g});return {data:f,error:t,isLoading:!!(c&&a&&!f)}};var ge=10,Se=(e,r)=>{let n=e[0],s=e[1],t=n.data.free,o=n.data.reserved,i=n.data.frozen,a=BigInt(t)+BigInt(o),d=t>i?BigInt(t)-BigInt(i):0n;return {free:t,total:a,reserved:o,transferable:d,formattedTransferable:formatBalance(d,r.tokenDecimals),formattedTotal:formatBalance(a,r.tokenDecimals),locks:s.map(c=>({id:c.id,amount:c.amount,reason:c.reasons,lockHuman:formatBalance(c.amount,r.tokenDecimals)}))}},In=({address:e})=>{let{currentApi:r,isApiReady:n,currentChain:s}=u();return k({queryKey:"/native-balance",factory:t=>t.queryMulti,params:t=>[{fn:t.query.system.account,args:[e]},{fn:t.query.balances.locks,args:[e]}],options:{enabled:!!r&&n&&!!e,transform:t=>{let o={tokenDecimals:s?.nativeCurrency?.decimals??ge,tokenSymbol:s?.nativeCurrency?.symbol,ss58Format:s?.ss58Format};return Se(t,o)}}})};var Dn=()=>{let{currentApi:e,isApiReady:r}=u();return k({queryKey:"/block-number",factory:s=>s.query.system.number,params:[],options:{enabled:!!e&&r,transform:s=>s}})};var On=()=>{let{currentChain:e,currentChainId:r}=u();return {chain:e,chainId:r}};var kn=()=>{let{config:e}=u();return e?.chains?[...e.chains]:[]};var Hn=()=>{let{config:e}=u();return e};function E(e,r){let n={};r?.onSuccess&&(n.onSuccess=r.onSuccess),r?.onError&&(n.onError=r.onError),r?.onSettled&&(n.onSettled=r.onSettled);let s=useMutation({mutationFn:e,retry:false,throwOnError:false,...n});return {mutate:(t,o)=>{s.mutate(t,o);},mutateAsync:(t,o)=>s.mutateAsync(t,o),data:s.data,error:s.error,isError:s.isError,isIdle:s.isIdle,isPending:s.isPending,isSuccess:s.isSuccess,reset:s.reset,status:s.status,variables:s.variables}}var Qn=e=>{let{connect:r,config:n,activeConnector:s,status:t}=u(),i=E(async a=>{await r(a.connectorId,a.targetChainId),await c();},e);return {connect:i.mutate,connectAsync:i.mutateAsync,connectors:n?.connectors?[...n.connectors]:[],activeConnector:s,status:t,data:i.data,error:i.error,isError:i.isError,isIdle:i.isIdle,isPending:i.isPending,isSuccess:i.isSuccess,reset:i.reset,variables:i.variables}};var Yn=()=>{let{config:e}=u();return e?.connectors?[...e.connectors]:[]};var Zn=e=>{let{disconnect:r,status:n}=u(),t=E(async()=>{await r();},e);return {disconnect:o=>t.mutate(void 0,o),disconnectAsync:o=>t.mutateAsync(void 0,o),status:n,data:t.data,error:t.error,isError:t.isError,isIdle:t.isIdle,isPending:t.isPending,isSuccess:t.isSuccess,reset:t.reset}};function rt(){let{account:e,currentChain:r}=u(),[n,s]=useState(null),[t,o]=useState(false),[i,a]=useState(null),d=useCallback(async(c,m)=>{let g=m||e?.address;if(!(!c||!g||!r)){o(true),a(null);try{let l=await c.paymentInfo(g),p=r.nativeCurrency.decimals,h={...l,partialFeeFormatted:formatBalance(l.partialFee,p)};return s(h),h}catch(l){let p=l instanceof Error?l:new Error("Failed to estimate payment info");a(p);}finally{o(false);}}},[e?.address,r]);return {data:n,isLoading:t,error:i,estimate:d}}var ct=()=>{let{currentApi:e,currentChainId:r,isApiReady:n}=u(),{data:s,isLoading:t,error:o}=useQuery({queryKey:["/genesis-hash",r],queryFn:async()=>await e.rpc.chain_getBlockHash(0),enabled:!!e&&n&&!!r,staleTime:1/0,gcTime:1/0,retry:false});return {data:s,isLoading:t,error:o}};var J=()=>{let{activeConnector:e}=u(),{account:r}=R(),[n,s]=useState(void 0),[t,o]=useState(false);return useEffect(()=>{if(!e||!r?.address){s(void 0),o(false);return}o(true),e.getSigner().then(i=>s(i)).catch(()=>s(void 0)).finally(()=>o(false));},[e,r?.address]),{data:n,isLoading:t}};function yt(){let{data:e}=J(),{address:r}=R(),[n,s]=useState(false),[t,o]=useState(void 0);return useEffect(()=>{if(!e||!r){o(void 0),s(false);return}s(true),createPapiSigner(r,e).then(i=>o(i)).catch(()=>o(void 0)).finally(()=>s(false));},[e,r]),{data:t,isLoading:n}}var Et=()=>{let{currentApi:e,isApiReady:r,currentChainId:n}=u();return useQuery({queryKey:["luno","runtimeVersion",n],queryFn:async()=>await e.getRuntimeVersion(),enabled:!!e&&r&&!!n})};function Rt(e){let{activeConnector:r,currentApi:n,isApiReady:s}=u(),{account:t}=R(),[o,i]=useState("idle"),[a,d]=useState("idle"),[c,m]=useState(null),g=useCallback(async p=>{if(!n||!s)throw new Error("[useSendTransaction]: Polkadot API is not ready.");if(!r)throw new Error("[useSendTransaction]: No active connector found.");if(!t||!t.address||!t.meta?.source)throw new Error("[useSendTransaction]: No active account, address, or account metadata (source) found.");if(!p.extrinsic)throw new Error("[useSendTransaction]: No extrinsic provided to send.");let h=await r.getSigner();if(!h)throw new Error("[useSendTransaction]: Could not retrieve signer from the injector.");return i("signing"),d("idle"),new Promise((f,A)=>{let C;p.extrinsic.signAndSend(t.address,{signer:h},({status:S,dispatchError:v,events:x,dispatchInfo:w,txHash:I})=>{let P=T=>{C&&C(),f(T);},b$1=T=>{C&&C(),m(T),A(T);};switch(S.type){case "Broadcasting":d("broadcasting");break;case "BestChainBlockIncluded":d("inBlock");break;case "Finalized":i("success"),d("finalized"),P(v?{transactionHash:I,blockHash:S.value?.blockHash,blockNumber:S.value?.blockNumber,events:x,status:"failed",dispatchError:v,errorMessage:b(n,v),dispatchInfo:w}:{transactionHash:I,blockHash:S.value?.blockHash,blockNumber:S.value?.blockNumber,events:x,status:"success",dispatchError:void 0,errorMessage:void 0,dispatchInfo:w});break;case "Invalid":i("failed"),d("invalid"),b$1(new Error(`Transaction invalid: ${I}`));break;case "Drop":i("failed"),d("dropped"),b$1(new Error(`Transaction dropped: ${I}`));break}}).then(S=>{C=S;}).catch(S=>{i("failed"),console.error("[useSendTransaction]: Error in signAndSend promise:",S?.message||S),m(S),A(S);});})},[n,s,r,t,i,d]),l=E(g,e);return {sendTransaction:l.mutate,sendTransactionAsync:l.mutateAsync,data:l.data,error:c||l.error,isError:!!c||l.isError,isIdle:l.isIdle,isPending:l.isPending,isSuccess:l.isSuccess,reset:l.reset,status:l.status,variables:l.variables,txStatus:o,detailedStatus:a}}function Mt(e){let{account:r,activeConnector:n,currentApi:s,isApiReady:t}=u(),[o,i]=useState(null),a=useCallback(async c=>{if(!s||!t)throw new Error("[useSendTransactionHash]: Polkadot API is not ready.");if(!n)throw new Error("[useSendTransactionHash]: No active connector found.");if(!r||!r.address||!r.meta?.source)throw new Error("[useSendTransactionHash]: No active account, address, or account metadata (source) found.");if(!c.extrinsic)throw new Error("[useSendTransactionHash]: No extrinsic provided to send.");let m=await n.getSigner();if(!m)throw new Error("[useSendTransactionHash]: Could not retrieve signer from the injector.");try{return await c.extrinsic.signAndSend(r.address,{signer:m}).catch(l=>{throw l})}catch(g){throw i(g),g}},[s,t,n,r]),d=E(a,e);return {sendTransaction:d.mutate,sendTransactionAsync:d.mutateAsync,data:d.data,error:o||d.error,isError:!!o||d.isError,isIdle:d.isIdle,isPending:d.isPending,isSuccess:d.isSuccess,reset:d.reset,status:d.status,variables:d.variables}}function Ht(e){let{activeConnector:r,account:n,accounts:s}=u(),o=E(async i=>{if(!r)throw new Error("[useSignMessage]: No active connector found to sign the message.");if(!n||!n.address||!n.meta?.source)throw new Error("[useSignMessage]: No address provided for signing.");if(!s.some(c=>c.address===n.address))throw new Error(`[useSignMessage]: Address ${n.address} is not managed by ${r.id}.`);if(!i.message)throw new Error("[useSignMessage]: No message provided for signing.");let a=s.find(c=>isSameAddress(c.address,n.address));if(!a)throw new Error("[useSignMessage]: Invalid account address.");let d=await r.signMessage(i.message,a.address);if(!d)throw new Error("[useSignMessage]: Signature was not obtained. The user may have cancelled the request or the connector failed.");return {signature:d,rawMessage:i.message,addressUsed:n.address}},e);return {signMessage:o.mutate,signMessageAsync:o.mutateAsync,data:o.data,error:o.error,isError:o.isError,isIdle:o.isIdle,isPending:o.isPending,isSuccess:o.isSuccess,reset:o.reset,status:o.status,variables:o.variables}}var Y=42,qt=()=>{let{currentApi:e,isApiReady:r,currentChain:n}=u(),s=n?.ss58Format!==void 0?n.ss58Format:Y;return useMemo(()=>{if(e&&r){let t;try{let o=e.consts.system.ss58Prefix;t=isNumber(o)?o:Y;}catch(o){console.error("[useSs58Format] Error fetching chainSS58:",o),t=s;}return {data:t,isLoading:false}}else return {data:void 0,isLoading:true}},[e,r,s])};var Jt=()=>{let{status:e}=u();return e};var Wt=e=>{let{switchChain:r,config:n,currentChain:s,currentChainId:t}=u(),i=E(async a=>{await r(a.chainId);},e);return {switchChain:i.mutate,switchChainAsync:i.mutateAsync,chains:n?.chains?[...n.chains]:[],currentChain:s,currentChainId:t,data:i.data,error:i.error,isError:i.isError,isIdle:i.isIdle,isPending:i.isPending,isSuccess:i.isSuccess,reset:i.reset,variables:i.variables}};export{te as LunoProvider,R as useAccount,ln as useAccounts,fn as useActiveConnector,hn as useApi,In as useBalance,Dn as useBlockNumber,On as useChain,kn as useChains,Hn as useConfig,Qn as useConnect,Yn as useConnectors,Zn as useDisconnect,rt as useEstimatePaymentInfo,ct as useGenesisHash,yt as usePapiSigner,Et as useRuntimeVersion,Rt as useSendTransaction,Mt as useSendTransactionHash,Ht as useSignMessage,J as useSigner,qt as useSs58Format,Jt as useStatus,k as useSubscription,Wt as useSwitchChain};//# sourceMappingURL=index.js.map
5
5
  //# sourceMappingURL=index.js.map