graz 0.1.28 → 0.1.29-alpha.0

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/.gitkeep CHANGED
File without changes
package/dist/index.js CHANGED
@@ -22,13 +22,13 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
22
22
 
23
23
  var rn__default = /*#__PURE__*/_interopDefault(rn);
24
24
 
25
- var Ut=Object.defineProperty,qt=Object.defineProperties;var Ft=Object.getOwnPropertyDescriptors;var ae=Object.getOwnPropertySymbols;var ze=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable;var Ge=(e,t,i)=>t in e?Ut(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,k=(e,t)=>{for(var i in t||(t={}))ze.call(t,i)&&Ge(e,i,t[i]);if(ae)for(var i of ae(t))Qe.call(t,i)&&Ge(e,i,t[i]);return e},F=(e,t)=>qt(e,Ft(t));var je=(e,t)=>{var i={};for(var o in e)ze.call(e,o)&&t.indexOf(o)<0&&(i[o]=e[o]);if(e!=null&&ae)for(var o of ae(e))t.indexOf(o)<0&&Qe.call(e,o)&&(i[o]=e[o]);return i};var l=(e,t,i)=>new Promise((o,r)=>{var n=c=>{try{a(i.next(c));}catch(f){r(f);}},s=c=>{try{a(i.throw(c));}catch(f){r(f);}},a=c=>c.done?o(c.value):Promise.resolve(c.value).then(n,s);a((i=i.apply(e,t)).next());});var X="graz-reconnect-session";var $e=(p=>(p.KEPLR="keplr",p.LEAP="leap",p.VECTIS="vectis",p.COSMOSTATION="cosmostation",p.WALLETCONNECT="walletconnect",p.WC_KEPLR_MOBILE="wc_keplr_mobile",p.WC_LEAP_MOBILE="wc_leap_mobile",p.WC_COSMOSTATION_MOBILE="wc_cosmostation_mobile",p.WC_CLOT_MOBILE="wc_clot_mobile",p.METAMASK_SNAP_LEAP="metamask_snap_leap",p.METAMASK_SNAP_COSMOS="metamask_snap_cosmos",p.STATION="station",p.XDEFI="xdefi",p.CAPSULE="capsule",p.COSMIFRAME="cosmiframe",p.COMPASS="compass",p.INITIA="initia",p.OKX="okx",p))($e||{}),He=["keplr","leap","vectis","cosmostation","walletconnect","wc_keplr_mobile","wc_leap_mobile","wc_cosmostation_mobile","wc_clot_mobile","metamask_snap_leap","station","xdefi","capsule","metamask_snap_cosmos","cosmiframe","compass","initia","okx"];var zt={iframeOptions:null,recentChainIds:null,chains:null,chainsConfig:null,capsuleConfig:null,capsuleState:null,multiChainFetchConcurrency:3,walletType:"keplr",walletConnect:{options:null,walletConnectModal:null},walletDefaultOptions:null,_notFoundFn:()=>null,_onReconnectFailed:()=>null,_reconnect:!1,_reconnectConnector:null},ie={accounts:null,activeChainIds:null,status:"disconnected",wcSignClients:new Map,capsuleClient:null},Qt={name:"graz-session",version:2,partialize:e=>({accounts:e.accounts,activeChainIds:e.activeChainIds}),storage:middleware.createJSONStorage(()=>sessionStorage)},jt={name:"graz-internal",partialize:e=>({recentChainIds:e.recentChainIds,_reconnect:e._reconnect,_reconnectConnector:e._reconnectConnector,walletType:e.walletType}),version:2},g=zustand.create(middleware.subscribeWithSelector(middleware.persist(()=>ie,Qt))),u=zustand.create(middleware.subscribeWithSelector(middleware.persist(()=>zt,jt)));var ce=()=>{var S,y;if(!((S=u.getState().capsuleConfig)!=null&&S.apiKey)||!((y=u.getState().capsuleConfig)!=null&&y.env))throw new Error("Capsule configuration is not set");let e=()=>l(void 0,null,function*(){var h,M;let m=(yield import('@leapwallet/cosmos-social-login-capsule-provider')).CapsuleProvider,C=new m({apiKey:(h=u.getState().capsuleConfig)==null?void 0:h.apiKey,env:(M=u.getState().capsuleConfig)==null?void 0:M.env});return g.setState({capsuleClient:C}),C});return {init:e,enable:m=>l(void 0,null,function*(){let C=typeof m=="string"?[m]:m,h=g.getState().capsuleClient;h||(h=yield e()),u.setState({capsuleState:{showModal:!0,chainId:C}});}),onAfterLoginSuccessful:()=>l(void 0,null,function*(){var p;let m=g.getState().capsuleClient,{chains:C}=u.getState();if(!m)throw new Error("Capsule client is not initialized");if(!C)throw new Error("Chains are not set");yield m.enable();let h=(p=u.getState().capsuleState)==null?void 0:p.chainId;if(!h)throw new Error("Chain ids are not set");let M=Object.fromEntries(yield Promise.all(h.map(I=>l(void 0,null,function*(){let b=yield m.getAccount(I);return [I,{address:encoding.fromBech32(b.address).data,bech32Address:b.address,algo:b.algo,name:b.username||"",pubKey:b.pubkey,isKeystone:!1,isNanoLedger:!1}]}))));g.setState(I=>({accounts:k(k({},I.accounts||{}),M)})),u.setState(I=>({recentChainIds:[...I.recentChainIds||[],...h].filter((b,W,D)=>D.indexOf(b)===W)})),g.setState(I=>({activeChainIds:[...I.activeChainIds||[],...h].filter((b,W,D)=>D.indexOf(b)===W)})),u.setState({walletType:"capsule",_reconnect:!1,_reconnectConnector:"capsule"}),g.setState({status:"connected"}),typeof window!="undefined"&&window.sessionStorage.setItem(X,"Active"),u.setState({capsuleState:null});}),getKey:m=>l(void 0,null,function*(){let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");let h=yield C.getAccount(m);return {address:encoding.fromBech32(h.address).data,bech32Address:h.address,algo:h.algo,name:h.username||"",pubKey:h.pubkey,isKeystone:!1,isNanoLedger:!1}}),getOfflineSignerAuto:m=>l(void 0,null,function*(){let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerDirect(m)}),getOfflineSignerDirect:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerDirect(m)},signDirect:(...m)=>l(void 0,null,function*(){let[C,h,M]=m,p=g.getState().capsuleClient;if(!p)throw new Error("Capsule client is not initialized");return p.signDirect(C,h,{bodyBytes:M.bodyBytes,authInfoBytes:M.authInfoBytes,chainId:M.chainId,accountNumber:M.accountNumber})}),signAmino:(...m)=>l(void 0,null,function*(){let[C,h,M,p]=m,I=g.getState().capsuleClient;if(!I)throw new Error("Capsule client is not initialized");return I.signAmino(C,h,M,p)}),signArbitrary:(m,C,h)=>l(void 0,null,function*(){let M=g.getState().capsuleClient;if(!M)throw new Error("Capsule client is not initialized");let p=yield M.getAccount(m);if(!p)throw new Error(`Wallet not connected to account ${C}`);let I=(()=>{switch(p.algo){case"secp256k1":return amino.encodeSecp256k1Pubkey(p.pubkey);case"ed25519":return amino.encodeEd25519Pubkey(p.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {signature:yield M.signArbitrary(m,C,h),pub_key:{type:p.algo==="secp256k1"?amino.pubkeyType.secp256k1:amino.pubkeyType.ed25519,value:I.value}}}),experimentalSuggestChain:(...m)=>l(void 0,null,function*(){yield Promise.reject(new Error("Capsule does not support experimentalSuggestChain"));}),getOfflineSigner:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSigner(m)},getOfflineSignerAmino:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerAmino(m)}}};var le=()=>{if(typeof window.compass!="undefined"){let e=window.compass;return Object.assign(e,{subscription:r=>{let n=()=>{_(),r();};return window.addEventListener("leap_keystorechange",n),()=>{window.removeEventListener("leap_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.leap is not defined")};var ue=()=>{let e=u.getState();if(!e.iframeOptions)throw e._notFoundFn(),new Error("no iframe options set");if(!cosmiframe.isInIframe())throw e._notFoundFn(),new Error("not in iframe");if(!e.iframeOptions.allowedIframeParentOrigins.length)throw e._notFoundFn(),new Error("no iframe allowed origins");let t=new cosmiframe.Cosmiframe(e.iframeOptions.allowedIframeParentOrigins).getKeplrClient();return {enable:t.enable.bind(t),getKey:t.getKey.bind(t),getOfflineSigner:t.getOfflineSigner.bind(t),getOfflineSignerAuto:t.getOfflineSignerAuto.bind(t),getOfflineSignerOnlyAmino:t.getOfflineSignerOnlyAmino.bind(t),experimentalSuggestChain:t.experimentalSuggestChain.bind(t),signDirect:t.signDirect.bind(t),signAmino:t.signAmino.bind(t)}};var nt={},it=()=>{let e=window.ethereum,t=window.cosmos;if(e)return {init:()=>l(void 0,null,function*(){var A;let n=yield e.request({method:"web3_clientVersion"});if(!n.includes("MetaMask"))throw new Error("Metamask is not installed");if(typeof window.okxwallet!="undefined"&&window.okxwallet.isOkxWallet)throw new Error("You have OKX Wallet installed. Please disable and reload the page to use Metamask Snap.");let a=(A=n.split("MetaMask/v")[1])==null?void 0:A.split(".")[0];if(!(Number(a)>=11))throw new Error("Metamask Snap is not supported in this version");return (yield snapper.isSnapInstalled())||(yield snapper.installSnap()),window.cosmos=new snapper.CosmosSnap,t=window.cosmos,!0}),enable:n=>l(void 0,null,function*(){(yield snapper.isSnapInstalled())||(yield snapper.installSnap());}),getOfflineSigner:n=>t.getOfflineSigner(n),experimentalSuggestChain:n=>l(void 0,null,function*(){if(!n.bech32Config)throw new Error("Bech32Config is required");if(!n.stakeCurrency)throw new Error("StakeCurrency is required");yield t.experimentalSuggestChain(F(k({},n),{stakeCurrency:n.stakeCurrency,bech32Config:n.bech32Config}));}),signAmino:(n,s,a)=>l(void 0,null,function*(){return t.signAmino(n,s,a)}),getKey:n=>l(void 0,null,function*(){return typeof nt[n]!="undefined"?nt[n]:t.getKey(n)}),getOfflineSignerAuto:n=>l(void 0,null,function*(){return (yield t.getKey(n)).isNanoLedger?t.getOfflineSignerOnlyAmino(n):t.getOfflineSigner(n)}),getOfflineSignerOnlyAmino:n=>t.getOfflineSignerOnlyAmino(n),signDirect:(n,s,a)=>l(void 0,null,function*(){return t.signDirect(n,s,a)}),signArbitrary:(n,s,a)=>l(void 0,null,function*(){return t.signArbitrary(n,s,a)}),disable:n=>l(void 0,null,function*(){n&&(yield t.deleteChain(n));})};throw u.getState()._notFoundFn(),new Error("window.ethereum is not defined")};var pe=()=>{var e;if(typeof((e=window.cosmostation)==null?void 0:e.providers.keplr)!="undefined"){let t=window.cosmostation.providers.keplr;return Object.assign(t,{subscription:n=>{let s=()=>{_(),n();};return window.addEventListener("cosmostation_keystorechange",s),()=>{window.removeEventListener("cosmostation_keystorechange",s);}},setDefaultOptions:n=>{t.defaultOptions=n;}})}throw u.getState()._notFoundFn(),new Error("window.cosmostation.providers.keplr is not defined")};var nn=e=>{let{bodyBytes:t,authInfoBytes:i,chainId:o,accountNumber:r}=e;if(!t||!i||!o||!r)throw new Error("Invalid sign doc");return {bodyBytes:t,authInfoBytes:i,chainId:o,accountNumber:r}},on=e=>`${e.slice(0,6)}...${e.slice(-6)}`,rt=()=>{if(typeof window.initia!="undefined"){let e=window.initia;return {enable:()=>l(void 0,null,function*(){yield e.getAddress();}),getKey:d=>l(void 0,null,function*(){let S=e.getOfflineSigner(d),[y]=yield S.getAccounts();if(!y)throw new Error("Wallet connection failed");let m=(()=>{switch(y.algo){case"secp256k1":return amino.rawSecp256k1PubkeyToRawAddress(y.pubkey);case"ed25519":return amino.rawEd25519PubkeyToRawAddress(y.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {name:on(y.address),algo:y.algo,pubKey:y.pubkey,bech32Address:y.address,address:m,isNanoLedger:!1,isKeystone:!1}}),getOfflineSigner:d=>{let S=e.getOfflineSigner(d),y=e.getOfflineSignerOnlyAmino(d);return {getAccounts:S.getAccounts.bind(S),signDirect:S.signDirect.bind(S),signAmino:y.signAmino.bind(y)}},getOfflineSignerAuto:d=>Promise.resolve(e.getOfflineSigner(d)),getOfflineSignerOnlyAmino:d=>e.getOfflineSignerOnlyAmino(d),experimentalSuggestChain:d=>e.requestAddInitiaLayer({chain_id:d.chainId,chain_name:d.chainName,bech32_prefix:"init",bech32_config:d.bech32Config,slip44:d.bip44.coinType,logo_URIs:{png:d.chainSymbolImageUrl},fees:{fee_tokens:d.feeCurrencies.map(S=>{var y,m,C;return {denom:S.coinDenom,amount:S.coinMinimalDenom,low_gas_price:(y=S.gasPriceStep)==null?void 0:y.low,average_gas_price:(m=S.gasPriceStep)==null?void 0:m.average,high_gas_price:(C=S.gasPriceStep)==null?void 0:C.high}})},apis:{rpc:[{address:d.rpc}],rest:[{address:d.rest}]}}),signDirect:(...d)=>{let[S,y,m]=d;return e.getOfflineSigner(S).signDirect(y,nn(m))},signAmino:(...d)=>{let[S,y,m]=d;return e.getOfflineSignerOnlyAmino(S).signAmino(y,m)},signArbitrary:(d,S,y)=>l(void 0,null,function*(){let h=(yield e.getOfflineSigner(d).getAccounts()).find(I=>I.address===S);if(!h)throw new Error(`Wallet not connected to account ${S}`);let M=(()=>{switch(h.algo){case"secp256k1":return amino.encodeSecp256k1Pubkey(h.pubkey);case"ed25519":return amino.encodeEd25519Pubkey(h.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {signature:yield e.signArbitrary(y),pub_key:{type:h.algo==="secp256k1"?amino.pubkeyType.secp256k1:amino.pubkeyType.ed25519,value:M.value}}}),subscription:d=>{let S=()=>{_(),d();};return window.addEventListener("initia_keystorechange",S),()=>{window.removeEventListener("initia_keystorechange",S);}}}}throw u.getState()._notFoundFn(),new Error("window.initia is not defined")};var me=()=>{if(typeof window.keplr!="undefined"){let e=window.keplr;return Object.assign(e,{subscription:r=>{let n=()=>{_(),r();};return window.addEventListener("keplr_keystorechange",n),()=>{window.removeEventListener("keplr_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.keplr is not defined")};var de=()=>{if(typeof window.leap!="undefined"){let e=window.leap;return Object.assign(e,{subscription:r=>{let n=()=>{_(),r();};return window.addEventListener("leap_keystorechange",n),()=>{window.removeEventListener("leap_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.leap is not defined")};var fe={},st=e=>{let t=window.ethereum;if(t&&e){let i=()=>l(void 0,null,function*(){return yield t.request({method:"wallet_getSnaps"})}),o=p=>l(void 0,null,function*(){try{let I=yield i();return Object.values(I).find(b=>b.id===e.id&&(!p||b.version===p))}catch(I){return}}),r=()=>l(void 0,null,function*(){yield t.request({method:"wallet_requestSnaps",params:{[e.id]:e.params||{}}});}),n=()=>l(void 0,null,function*(){var K;let p=yield t.request({method:"web3_clientVersion"});if(!p.includes("MetaMask"))throw new Error("Metamask is not installed");if(typeof window.okxwallet!="undefined"&&window.okxwallet.isOkxWallet)throw new Error("You have OKX Wallet installed. Please disable and reload the page to use Metamask Snap.");let b=(K=p.split("MetaMask/v")[1])==null?void 0:K.split(".")[0];if(!(Number(b)>=11))throw new Error("Metamask Snap is not supported in this version");return (yield o())||(yield r()),!0}),s=p=>l(void 0,null,function*(){(yield o())||(yield r());}),a=(p,I,b)=>l(void 0,null,function*(){let W=yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"signDirect",params:{chainId:p,signerAddress:I,signDoc:b}}}}),D=b.accountNumber,K=new rn__default.default(D.low,D.high,D.unsigned);return {signature:W.signature,signed:F(k({},W.signed),{accountNumber:`${K.toString()}`,authInfoBytes:new Uint8Array(Object.values(W.signed.authInfoBytes)),bodyBytes:new Uint8Array(Object.values(W.signed.bodyBytes))})}}),c=(p,I,b)=>l(void 0,null,function*(){return yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"signAmino",params:{chainId:p,signerAddress:I,signDoc:b}}}})}),f=p=>l(void 0,null,function*(){if(typeof fe[p]!="undefined")return fe[p];let I=yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"getKey",params:{chainId:p}}}});if(!I)throw new Error("No response from Metamask");return I.pubKey=Uint8Array.from(Object.values(I.pubkey)),delete I.pubkey,fe[p]=I,fe[p]}),A=p=>l(void 0,null,function*(){let I=yield f(p);return {address:I.bech32Address,algo:I.algo,pubkey:I.pubKey}}),d=(...p)=>l(void 0,null,function*(){let[I,b,W,D]=p;return yield c(I,b,W)}),S=(...p)=>l(void 0,null,function*(){let[I,b,W]=p;return yield a(I,b,W)}),m=p=>({getAccounts:()=>l(void 0,null,function*(){return [yield A(p)]}),signAmino:(I,b)=>d(p,I,b)});return {enable:s,experimentalSuggestChain:(...p)=>l(void 0,null,function*(){yield n(),yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"suggestChain",params:{chainInfo:p[0]}}}});}),getKey:f,getOfflineSigner:p=>({getAccounts:()=>l(void 0,null,function*(){return [yield A(p)]}),signDirect:(I,b)=>S(p,I,b),signAmino:(I,b)=>d(p,I,b)}),getOfflineSignerAuto:p=>l(void 0,null,function*(){return m(p)}),getOfflineSignerOnlyAmino:m,init:n,signAmino:d,signDirect:S}}throw u.getState()._notFoundFn(),new Error("window.ethereum is not defined")};var at=()=>st({id:"npm:@leapwallet/metamask-cosmos-snap"});var ge=()=>{var e;if(typeof((e=window.okxwallet)==null?void 0:e.keplr)!="undefined"){let t=window.okxwallet.keplr;return Object.assign(t,{subscription:n=>{var a;let s=()=>{_(),n();};return (a=window.okxwallet)==null||a.on("accountsChanged",s),()=>{var c;(c=window.okxwallet)==null||c.removeListener("accountsChanged",s);}},setDefaultOptions:n=>{t.defaultOptions=n;}})}throw u.getState()._notFoundFn(),new Error("window.okxwallet.keplr is not defined")};var ye=()=>{if(typeof window.station!="undefined"){let e=window.station.keplr;return {subscription:n=>{let s=()=>{_(),n();};return window.addEventListener("station_wallet_change",s),()=>{window.removeEventListener("station_wallet_change",s);}},getKey:n=>l(void 0,null,function*(){let s=yield e.getKey(n);return k({isKeystone:!1},s)}),getOfflineSigner:n=>{try{let s=e.getOfflineSignerOnlyAmino(n);return Object.assign(s,{signDirect:(f,A)=>{throw new Error("signDirect not supported by Station")}})}catch(s){throw console.error(s),s}},experimentalSuggestChain:n=>l(void 0,null,function*(){try{if(!n.bech32Config)throw new Error("Bech32Config is required");if(!n.stakeCurrency)throw new Error("StakeCurrency is required");let s=Object.assign(n,{bech32Config:n.bech32Config,chainSymbolImageUrl:n.chainSymbolImageUrl||"",stakeCurrency:{coinDecimals:n.stakeCurrency.coinDecimals,coinDenom:n.stakeCurrency.coinDenom,coinImageUrl:n.stakeCurrency.coinImageUrl||"",coinMinimalDenom:n.stakeCurrency.coinMinimalDenom},currencies:n.currencies.map(a=>({coinDecimals:a.coinDecimals,coinDenom:a.coinDenom,coinImageUrl:a.coinImageUrl||"",coinMinimalDenom:a.coinMinimalDenom})),feeCurrencies:n.feeCurrencies.map(a=>{var c,f,A;return {coinDecimals:a.coinDecimals,coinDenom:a.coinDenom,coinImageUrl:a.coinImageUrl||"",coinMinimalDenom:a.coinMinimalDenom,gasPriceStep:{average:((c=a.gasPriceStep)==null?void 0:c.average)||0,high:((f=a.gasPriceStep)==null?void 0:f.high)||0,low:((A=a.gasPriceStep)==null?void 0:A.low)||0}}})});yield e.experimentalSuggestChain(s);}catch(s){throw console.error(s),s}}),enable:n=>e.enable(n),disable:n=>e.disable(n),getOfflineSignerAuto:n=>e.getOfflineSignerAuto(n),getOfflineSignerOnlyAmino:n=>e.getOfflineSignerOnlyAmino(n),signDirect:()=>e.signDirect(),signAmino:(n,s,a,c)=>e.signAmino(n,s,a)}}throw u.getState()._notFoundFn(),new Error("window.station is not defined")};var Ce=()=>{if(typeof window.vectis!="undefined"){let e=window.vectis.cosmos;return {enable:a=>e.enable(a),getOfflineSigner:a=>e.getOfflineSigner(a),getOfflineSignerAuto:a=>e.getOfflineSignerAuto(a),getKey:a=>l(void 0,null,function*(){let c=yield e.getKey(a);return {address:encoding.fromBech32(c.address).data,algo:c.algo,bech32Address:c.address,name:c.name,pubKey:c.pubKey,isKeystone:!1,isNanoLedger:c.isNanoLedger}}),subscription:a=>{let c=()=>{_(),a();};return window.addEventListener("vectis_accountChanged",c),()=>{window.removeEventListener("vectis_accountChanged",c);}},getOfflineSignerOnlyAmino:(...a)=>{let c=a[0];return e.getOfflineSignerAmino(c)},experimentalSuggestChain:(...a)=>l(void 0,null,function*(){var A;let[c]=a;if(!c.bech32Config)throw new Error("Bech32Config is required");if(!c.stakeCurrency)throw new Error("StakeCurrency is required");let f={rpcUrl:c.rpc,restUrl:c.rest,prettyName:c.chainName.replace(" ",""),bech32Prefix:(A=c.bech32Config)==null?void 0:A.bech32PrefixAccAddr,currencies:c.currencies,feeCurrencies:c.feeCurrencies,chainId:c.chainId,chainName:c.chainName,bip44:c.bip44,stakeCurrency:c.stakeCurrency,features:c.features};return e.suggestChains([f])}),signDirect:(...a)=>l(void 0,null,function*(){var A;let{1:c,2:f}=a;return e.signDirect(c,{bodyBytes:f.bodyBytes||Uint8Array.from([]),authInfoBytes:f.authInfoBytes||Uint8Array.from([]),accountNumber:rn__default.default.fromString(((A=f.accountNumber)==null?void 0:A.toString())||"",!1),chainId:f.chainId||""})}),signAmino:(...a)=>l(void 0,null,function*(){let{1:c,2:f}=a;return e.signAmino(c,f)})}}throw u.getState()._notFoundFn(),new Error("window.vectis is not defined")};var z=()=>{if(typeof window!="undefined"){let e=navigator.userAgent;return !!(/android/i.test(e)||/iPad|iPhone|iPod/.test(e))}return !1},ct=()=>z()&&navigator.userAgent.toLowerCase().includes("android"),lt=()=>z()&&(navigator.userAgent.toLowerCase().includes("iphone")||navigator.userAgent.toLowerCase().includes("ipad"));var xe=(e,t,i=new Error("Promise timed out"))=>{let o=new Promise((r,n)=>{setTimeout(()=>{n(i);},t);});return Promise.race([e,o])};var Q=e=>{var K,Z,oe;if(!((oe=(Z=(K=u.getState().walletConnect)==null?void 0:K.options)==null?void 0:Z.projectId)!=null&&oe.trim()))throw new Error("walletConnect.options.projectId is not defined");let t=(e==null?void 0:e.walletType)||"walletconnect",i=(e==null?void 0:e.encoding)||"base64",o=w=>{if(!e)return;let{appUrl:O,formatNativeUrl:E}=e;if(z()){if(ct())if(!w)window.open(O.mobile.android,"_self","noreferrer noopener");else {let x=E(O.mobile.android,w,"android");window.open(x,"_self","noreferrer noopener");}if(lt())if(!w)window.open(O.mobile.ios,"_self","noreferrer noopener");else {let x=E(O.mobile.ios,w,"ios");window.open(x,"_self","noreferrer noopener");}}},r=()=>{let{wcSignClients:w}=g.getState();if(!w.get(t))throw new Error("walletConnect.signClient is not defined");w.delete(t),g.setState({wcSignClients:w}),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null});},n=w=>l(void 0,null,function*(){let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");if(!w)throw new Error("No wallet connect session");yield E.disconnect({topic:w,reason:utils.getSdkError("USER_DISCONNECTED")}),yield c(E);}),s=w=>{try{let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");let x=E.session.getAll(),v=x.at(-1);if(!v)return;if(!(v.expiry*1e3>Date.now()+1e3))throw n(v.topic),new Error("invalid session");try{let N=x.find(j=>{var $,ee;return (ee=($=j.requiredNamespaces.cosmos)==null?void 0:$.chains)==null?void 0:ee.includes(`cosmos:${w}`)});if(!N)throw new Error("no session");return N}catch(N){if(!N.message.toLowerCase().includes("no matching key"))throw N}return v}catch(O){if(!O.message.toLowerCase().includes("no matching key"))throw O}},a=w=>{try{return s(w)}catch(O){return}},c=w=>l(void 0,null,function*(){try{let O=w.core.pairing.pairings.getAll({active:!1});if(!O.length)return;yield Promise.all(O.map(E=>l(void 0,null,function*(){yield w.core.pairing.pairings.delete(E.topic,{code:7001,message:"clear pairing"});})));}catch(O){if(!O.message.toLowerCase().includes("no matching key"))throw O}}),f=()=>l(void 0,null,function*(){let{walletConnect:w}=u.getState();if(!(w!=null&&w.options))throw new Error("walletConnect.options is not defined");let{wcSignClients:O}=g.getState(),E=O.get(t);if(E)return E;let x=yield signClient.SignClient.init(w.options);return O.set(t,x),g.setState({wcSignClients:O}),x}),A=w=>{let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)return ()=>{};let x=v=>{let P=g.getState().accounts;if(v.params.event.name==="accountsChanged"&&P&&!Object.values(P).map(N=>N.bech32Address).includes(v.params.event.data[0])){let N=v.params.chainId.split(":")[1];N&&d([N]);}else w();};return E.events.on("session_delete",r),E.events.on("session_expire",r),E.events.on("session_event",x),()=>{E.events.off("session_delete",r),E.events.off("session_expire",r),E.events.off("session_event",x);}},d=w=>l(void 0,null,function*(){var ee;let O=typeof w=="string"?[w]:w,{wcSignClients:E,activeChainIds:x}=g.getState(),v=E.get(t);if(!v)throw new Error("enable walletConnect.signClient is not defined");let{walletConnect:P,chains:N}=u.getState();if(!((ee=P==null?void 0:P.options)!=null&&ee.projectId))throw new Error("walletConnect.options.projectId is not defined");let j=new modal.WalletConnectModal(k({projectId:P.options.projectId,enableExplorer:!1,explorerRecommendedWalletIds:"NONE"},P.walletConnectModal)),$=a(O);if(!$){let{uri:q,approval:te}=yield xe(v.connect({requiredNamespaces:{cosmos:{methods:["cosmos_getAccounts","cosmos_signAmino","cosmos_signDirect"],chains:O.map(H=>`cosmos:${H}`),events:["chainChanged","accountsChanged"]}}}),15e3,new Error("Connection timeout"));if(!q)throw new Error("No wallet connect uri");e?o(q):yield j.openModal({uri:q});let se=H=>l(void 0,null,function*(){return H.aborted?Promise.reject(new Error("User closed wallet connect")):new Promise((Me,ne)=>{te().then(Ue=>{let qe=Ue.sessionProperties;if(!qe)return ne(new Error("No session properties"));let ke=JSON.parse(String(qe.keys));if(ke.length===0)return ne(new Error("No accounts"));if(!ke[0])return ne(new Error("No accounts"));let Fe={};return ke.forEach(V=>{Fe[V.chainId]={address:V.address,algo:V.algo,bech32Address:V.bech32Address,isNanoLedger:V.isNanoLedger,isKeystone:V.isKeystone,name:V.name,pubKey:V.pubKey};}),g.setState(V=>({accounts:k(k({},V.accounts||{}),Fe)})),Me(Ue)}).catch(ne),H.addEventListener("abort",()=>{ne(new Error("User closed wallet connect"));},{once:!0});})});try{let H=new AbortController,Me=H.signal;j.subscribeModal(ne=>{ne.open||H.abort();}),yield se(Me);}catch(H){if(j.closeModal(),!H.message.toLowerCase().includes("no matching key"))return Promise.reject(H)}return e||j.closeModal(),Promise.resolve()}try{yield xe((()=>l(void 0,null,function*(){var te;let q=Object.fromEntries(yield Promise.all((te=x||O)==null?void 0:te.map(se=>l(void 0,null,function*(){return [se,yield y(se)]}))));g.setState({accounts:q});}))(),15e3,new Error("Connection timeout"));}catch(q){if(n($.topic),!q.message.toLowerCase().includes("no matching key"))throw q}}),S=w=>l(void 0,null,function*(){var P;let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");let x=(P=s([w]))==null?void 0:P.topic;if(!x)throw new Error("No wallet connect session");let v=yield E.request({topic:x,chainId:`cosmos:${w}`,request:{method:"cosmos_getAccounts",params:{}}});if(!v[0])throw new Error("No wallet connect account");return {address:v[0].address,algo:v[0].algo,pubkey:new Uint8Array(Buffer.from(v[0].pubkey,i))}}),y=w=>l(void 0,null,function*(){let O=s([w]);if(!(O!=null&&O.topic))throw new Error("No wallet connect session");let E=O.sessionProperties&&JSON.parse(String(O.sessionProperties.keys));if(!E)throw new Error("No wallet connect key");if(E.length===0)throw new Error("No wallet connect session");let x=E.find(v=>v.chainId===w);if(!x)throw new Error(`No wallet connect key for chainId ${w}`);return x}),m=(...w)=>l(void 0,null,function*(){var q,te;let[O,E,x]=w,{accounts:v,wcSignClients:P}=g.getState(),N=P.get(t);if(!N)throw new Error("walletConnect.signClient is not defined");if(!v)throw new Error("account is not defined");let j=(q=s([O]))==null?void 0:q.topic;if(!j)throw new Error("No wallet connect session");if(!x.bodyBytes)throw new Error("No bodyBytes");if(!x.authInfoBytes)throw new Error("No authInfoBytes");let $={topic:j,chainId:`cosmos:${O}`,request:{method:"cosmos_signDirect",params:{signerAddress:E,signDoc:F(k({},x),{bodyBytes:Buffer.from(x.bodyBytes).toString(i),authInfoBytes:Buffer.from(x.authInfoBytes).toString(i),accountNumber:(te=x.accountNumber)==null?void 0:te.toString()})}}};return o(),yield N.request($)}),C=(...w)=>l(void 0,null,function*(){let[O,E,x]=w,{signature:v,signed:P}=yield m(O,E,x);return {signed:{chainId:P.chainId,accountNumber:rn__default.default.fromString(P.accountNumber,!1),authInfoBytes:new Uint8Array(Buffer.from(P.authInfoBytes,i)),bodyBytes:new Uint8Array(Buffer.from(P.bodyBytes,i))},signature:v}}),h=(...w)=>l(void 0,null,function*(){var q;let[O,E,x,v]=w,{wcSignClients:P}=g.getState(),N=P.get(t),{accounts:j}=g.getState();if(!N)throw new Error("walletConnect.signClient is not defined");if(!j)throw new Error("account is not defined");let $=(q=s([O]))==null?void 0:q.topic;if(!$)throw new Error("No wallet connect session");return o(),yield N.request({topic:$,chainId:`cosmos:${O}`,request:{method:"cosmos_signDirect",params:{signerAddress:E,signDoc:x}}})}),M=(...w)=>l(void 0,null,function*(){let[O,E,x,v]=w;return yield h(O,E,x)}),p=w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signDirect:(O,E)=>C(w,O,E)}),I=w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signAmino:(O,E)=>M(w,O,E)});return {enable:d,disable:w=>l(void 0,null,function*(){var x;let{wcSignClients:O}=g.getState(),E=O.get(t);if(w===void 0){let v=E==null?void 0:E.session.getAll();v!==void 0&&(yield Promise.all(v.map(P=>n(P.topic))));}else typeof w=="string"?yield n((x=s([w]))==null?void 0:x.topic):yield Promise.all(w.map(v=>{var P;return n((P=s([v]))==null?void 0:P.topic)}));(E==null?void 0:E.session.getAll().length)===0&&r();}),experimentalSuggestChain:(...w)=>l(void 0,null,function*(){yield Promise.reject(new Error("WalletConnect does not support experimentalSuggestChain"));}),getKey:y,getOfflineSigner:w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signDirect:(O,E)=>C(w,O,E),signAmino:(O,E)=>M(w,O,E)}),getOfflineSignerAuto:w=>l(void 0,null,function*(){return (yield y(w)).isNanoLedger?I(w):p(w)}),getOfflineSignerOnlyAmino:I,signAmino:M,signDirect:C,subscription:A,init:f}};var ut=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!z())throw new Error("WalletConnect Clot mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{android:"clot://",ios:"clot://"}},walletType:"wc_clot_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;default:return `${a}://wc?uri=${c}`}}};return Q(e)};var pt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!z())throw new Error("WalletConnect Cosmostation mobile is only supported in mobile");let e={encoding:"hex",appUrl:{mobile:{ios:"cosmostation://",android:"cosmostation://"}},walletType:"wc_cosmostation_mobile",formatNativeUrl:(r,n,s)=>`${r.replaceAll("/","").replaceAll(":","")}://wc?${n}`};return Q(e)};var mt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!z())throw new Error("WalletConnect Keplr mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{ios:"keplrwallet://",android:"intent://"}},walletType:"wc_keplr_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;case"android":return `${a}://wcV2?${c}#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;`;default:return `${a}://wc?uri=${c}`}}};return Q(e)};var dt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!z())throw new Error("WalletConnect Leap mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{ios:"leapcosmos://",android:"intent://"}},walletType:"wc_leap_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;case"android":return `${a}://wcV2?${c}#Intent;package=io.leapwallet.cosmos;scheme=leapwallet;end;`;default:return `${a}://wc?uri=${c}`}}};return Q(e)};var Se=()=>{var e;if(typeof((e=window.xfi)==null?void 0:e.keplr)!="undefined"){let t=window.xfi.keplr;return Object.assign(t,{subscription:r=>{let n=()=>{_(),r();};return window.addEventListener("keplr_keystorechange",n),()=>{window.removeEventListener("keplr_keystorechange",n);}}})}throw u.getState()._notFoundFn(),new Error("window.xfi.keplr is not defined")};var B=(e=u.getState().walletType)=>{try{return R(e),!0}catch(t){return !1}},_=()=>{window.sessionStorage.removeItem(X),g.setState(ie);},R=(e=u.getState().walletType)=>{var o;let t=(()=>{switch(e){case"keplr":return me();case"leap":return de();case"cosmostation":return pe();case"vectis":return Ce();case"walletconnect":return Q();case"wc_keplr_mobile":return mt();case"wc_leap_mobile":return dt();case"wc_cosmostation_mobile":return pt();case"wc_clot_mobile":return ut();case"metamask_snap_leap":return at();case"metamask_snap_cosmos":return it();case"station":return ye();case"xdefi":return Se();case"capsule":return ce();case"cosmiframe":return ue();case"compass":return le();case"initia":return rt();case"okx":return ge();default:throw new Error("Unknown wallet type")}})(),i=u.getState().walletDefaultOptions;return i&&((o=t.setDefaultOptions)==null||o.call(t,i)),t},or=()=>Object.fromEntries(He.map(e=>[e,B(e)])),ve=e=>e==="capsule",ft=e=>e==="walletconnect"||e==="wc_keplr_mobile"||e==="wc_leap_mobile"||e==="wc_cosmostation_mobile";var Y=e=>l(void 0,null,function*(){var t;try{let{recentChainIds:i,chains:o,walletType:r}=u.getState(),n=(e==null?void 0:e.walletType)||r;if(!B(n))throw new Error(`${n} is not available`);let a=R(n),c=typeof(e==null?void 0:e.chainId)=="string"?[e.chainId]:(e==null?void 0:e.chainId)||i;if(!c)throw new Error("No last known connected chain, connect action requires chain ids");let f=o==null?void 0:o.map(y=>y.chainId);c.forEach(y=>{if(!(f!=null&&f.includes(y)))throw new Error(`Chain ${y} is not provided in GrazProvider`)}),g.setState(y=>{let m=u.getState()._reconnect||!!u.getState()._reconnectConnector||!!c;return y.activeChainIds&&c.filter(h=>{var M;return !((M=y.activeChainIds)!=null&&M.includes(h))}).length>0?{status:"connecting"}:m?{status:"reconnecting"}:{status:"connecting"}});let{accounts:A}=g.getState();if(yield (t=a.init)==null?void 0:t.call(a),ve(n)&&g.getState().capsuleClient&&Object.values(g.getState().accounts||[]).length>0){let y=c.map(h=>o.find(M=>M.chainId===h)),m=g.getState().accounts;g.setState({status:"connecting"});let C=Object.fromEntries(yield Promise.all(c.map(h=>l(void 0,null,function*(){return [h,yield a.getKey(h)]}))));return g.setState(h=>({accounts:k(k({},h.accounts||{}),C)})),u.setState(h=>({recentChainIds:[...h.recentChainIds||[],...c].filter((M,p,I)=>I.indexOf(M)===p)})),g.setState(h=>({activeChainIds:[...h.activeChainIds||[],...c].filter((M,p,I)=>I.indexOf(M)===p)})),g.setState({status:"connected"}),{accounts:m,walletType:n,chains:y}}if(yield a.enable(c),ve(n)){let y=c.map(C=>o.find(h=>h.chainId===C)),m=g.getState().accounts;return g.setState({status:"connecting"}),{accounts:m,walletType:n,chains:y}}if(!ft(n)){let y=Object.fromEntries(yield Promise.all(c.map(m=>l(void 0,null,function*(){return [m,yield a.getKey(m)]}))));g.setState(m=>({accounts:k(k({},m.accounts||{}),y)}));}u.setState(y=>({recentChainIds:[...y.recentChainIds||[],...c].filter((m,C,h)=>h.indexOf(m)===C)})),g.setState(y=>({activeChainIds:[...y.activeChainIds||[],...c].filter((m,C,h)=>h.indexOf(m)===C)})),u.setState({walletType:n,_reconnect:!!(e!=null&&e.autoReconnect),_reconnectConnector:n}),g.setState({status:"connected"}),typeof window!="undefined"&&window.sessionStorage.setItem(X,"Active");let d=c.map(y=>o.find(m=>m.chainId===y));return {accounts:g.getState().accounts,walletType:n,chains:d}}catch(i){throw console.error("connect ",i),g.getState().accounts===null&&g.setState({status:"disconnected"}),g.getState().accounts&&g.getState().activeChainIds&&g.setState({status:"connected"}),i}}),re=e=>{typeof window!="undefined"&&window.sessionStorage.removeItem(X);let t=typeof(e==null?void 0:e.chainId)=="string"?[e.chainId]:e==null?void 0:e.chainId;if(t){let i=g.getState().accounts;t.forEach(r=>{i==null||delete i[r];}),Object.values(i||{}).length===0?(g.setState(ie),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null})):(g.setState(r=>{var n;return {activeChainIds:(n=r.activeChainIds)==null?void 0:n.filter(s=>!t.includes(s)),accounts:i}}),u.setState(r=>{var n;return {recentChainIds:(n=r.recentChainIds)==null?void 0:n.filter(s=>!t.includes(s))}}));}else g.setState(ie),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null});return Promise.resolve()},L=e=>l(void 0,null,function*(){var r;let{recentChainIds:t,_reconnectConnector:i,_reconnect:o}=u.getState();try{let n=B(i||void 0);if(t&&n&&i)return yield Y({chainId:t,walletType:i,autoReconnect:o})}catch(n){(r=e==null?void 0:e.onError)==null||r.call(e,n),re();}}),gt=e=>l(void 0,null,function*(){if(!(e!=null&&e.chainId))throw new Error("chainId is required");let{walletType:t}=u.getState(),i=e.walletType||t;if(!B(i))throw new Error(`${i} is not available`);let r=R(i),n=r.getOfflineSigner(e.chainId),s=r.getOfflineSignerOnlyAmino(e.chainId),a=yield r.getOfflineSignerAuto(e.chainId);return {offlineSigner:n,offlineSignerAmino:s,offlineSignerAuto:a}});var Pe=()=>{u.setState({recentChainIds:null});},yr=()=>u.getState().recentChainIds,Cr=()=>{var i;let{recentChainIds:e,chains:t}=u.getState();return (i=e==null?void 0:e.map(o=>t.find(r=>r.chainId===o)))!=null?i:null},Sr=({chainId:e})=>{var t;return (t=u.getState().chains)==null?void 0:t.find(i=>i.chainId===e)},hr=({chainId:e})=>{var t;return (t=u.getState().chains)==null?void 0:t.filter(i=>e==null?void 0:e.includes(i.chainId))},We=i=>l(void 0,[i],function*({chainInfo:e,walletType:t}){let o=R(t);return t==="capsule"?yield Y({chainId:e.chainId,walletType:t}):yield o.experimentalSuggestChain(e),e}),yt=e=>l(void 0,null,function*(){var o;let t=u.getState().walletType;return yield We({chainInfo:e.chainInfo,walletType:(o=e.walletType)!=null?o:t}),yield Y({chainId:e.chainInfo.chainId,walletType:e.walletType,autoReconnect:e.autoReconnect})});var Ct=e=>(u.setState(t=>({iframeOptions:e.iframeOptions||t.iframeOptions,walletConnect:e.walletConnect||t.walletConnect,walletType:e.defaultWallet||t.walletType,capsuleConfig:e.capsuleConfig||t.capsuleConfig,walletDefaultOptions:e.walletDefaultOptions||t.walletDefaultOptions,chains:e.chains,chainsConfig:e.chainsConfig||t.chainsConfig,multiChainFetchConcurrency:e.multiChainFetchConcurrency||t.multiChainFetchConcurrency,_notFoundFn:e.onNotFound||t._notFoundFn,_onReconnectFailed:e.onReconnectFailed||t._onReconnectFailed,_reconnect:e.autoReconnect===void 0?!0:e.autoReconnect||t._reconnect})),e);var St=s=>l(void 0,[s],function*({signingClient:e,senderAddress:t,recipientAddress:i,amount:o,fee:r,memo:n}){if(!e)throw new Error("No connected account detected");if(!t)throw new Error("senderAddress is not defined");return e.sendTokens(t,i,o,r,n)}),ht=A=>l(void 0,[A],function*({signingClient:e,senderAddress:t,recipientAddress:i,transferAmount:o,sourcePort:r,sourceChannel:n,timeoutHeight:s,timeoutTimestamp:a,fee:c,memo:f}){if(!e)throw new Error("Stargate signing client is not ready");if(!t)throw new Error("senderAddress is not defined");return e.sendIbcTokens(t,i,o,r,n,s,a,c,f)}),wt=a=>l(void 0,[a],function*({signingClient:e,senderAddress:t,msg:i,fee:o,options:r,label:n,codeId:s}){if(!e)throw new Error("CosmWasm signing client is not ready");return e.instantiate(t,s,i,n,o,r)}),At=a=>l(void 0,[a],function*({signingClient:e,senderAddress:t,msg:i,fee:o,contractAddress:r,funds:n,memo:s}){if(!e)throw new Error("CosmWasm signing client is not ready");return e.execute(t,r,i,o,s,n)}),It=(e,t,i)=>l(void 0,null,function*(){if(!i)throw new Error("CosmWasm client is not ready");return yield i.queryContractSmart(e,t)}),Ot=(e,t,i)=>{if(!i)throw new Error("CosmWasm client is not ready");let o=new TextEncoder().encode(t);return i.queryContractRaw(e,o)};var xr=e=>e,vr=e=>e;var he=e=>e?Object.keys(e).length===0:!0;var Re=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t;}},Et=e=>globalThis.DOMException===void 0?new Re(e):new DOMException(e),bt=e=>{let t=e.reason===void 0?Et("This operation was aborted."):e.reason;return t instanceof Error?t:Et(t)};function De(n,s){return l(this,arguments,function*(e,t,{concurrency:i=Number.POSITIVE_INFINITY,stopOnError:o=!0,signal:r}={}){return new Promise((a,c)=>{if(e[Symbol.iterator]===void 0&&e[Symbol.asyncIterator]===void 0)throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof e})`);if(typeof t!="function")throw new TypeError("Mapper function is required");if(!((Number.isSafeInteger(i)||i===Number.POSITIVE_INFINITY)&&i>=1))throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${i}\` (${typeof i})`);let f=[],A=[],d=new Map,S=!1,y=!1,m=!1,C=0,h=0,M=e[Symbol.iterator]===void 0?e[Symbol.asyncIterator]():e[Symbol.iterator](),p=b=>{S=!0,y=!0,c(b);};r&&(r.aborted&&p(bt(r)),r.addEventListener("abort",()=>{p(bt(r));}));let I=()=>l(this,null,function*(){if(y)return;let b=yield M.next(),W=h;if(h++,b.done){if(m=!0,C===0&&!y){if(!o&&A.length>0){p(new AggregateError(A));return}if(y=!0,d.size===0){a(f);return}let D=[];for(let[K,Z]of f.entries())d.get(K)!==Tt&&D.push(Z);a(D);}return}C++,l(this,null,function*(){try{let D=yield b.value;if(y)return;let K=yield t(D,W);K===Tt&&d.set(W,K),f[W]=K,C--,yield I();}catch(D){if(o)p(D);else {A.push(D),C--;try{yield I();}catch(K){p(K);}}}});});l(this,null,function*(){for(let b=0;b<i;b++){try{yield I();}catch(W){p(W);break}if(m||S)break}});})})}var Tt=Symbol("skip");var U=({chainId:e,multiChain:t})=>{let i=u(r=>r.chains);if(!i)throw new Error("No chains found in GrazProvider");let o=typeof e=="string"?[e]:e;switch(!0){case(!!t&&!!o):return o.map(r=>i.find(n=>n.chainId===r)).filter(Boolean);case(!t&&!!o):return [o.map(r=>i.find(n=>n.chainId===r)).filter(Boolean)[0]];case(!!t&&!o):return i;default:return [i[0]]}},G=(e,t,i)=>l(void 0,null,function*(){let o=u.getState().multiChainFetchConcurrency;if(e){let n=yield De(t,i,{concurrency:o});return Object.fromEntries(n.map((s,a)=>[t[a].chainId,s]))}return yield i(t[0])}),Mt=(e,t,i)=>{if(e){let r=t.map(i);return Object.fromEntries(r.map((n,s)=>[t[s].chainId,n]))}return i(t[0])};var Ne=e=>{let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=react.useMemo(()=>["USE_STARGATE_CLIENT",t],[t]);return reactQuery.useQuery({queryKey:i,queryFn:r=>l(void 0,[r],function*({queryKey:[,o]}){if(o.length<1)throw new Error("No chains found");return yield G(!!(e!=null&&e.multiChain),o,s=>l(void 0,null,function*(){var A;let a=(A=u.getState().chainsConfig)==null?void 0:A[s.chainId],c={url:s.rpc,headers:k({},(a==null?void 0:a.rpcHeaders)||{})};return yield stargate.StargateClient.connect(c)}))}),enabled:!!t&&t.length>0&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})},Be=e=>{let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=react.useMemo(()=>["USE_COSMWASM_CLIENT",t],[t]);return reactQuery.useQuery({queryKey:i,queryFn:r=>l(void 0,[r],function*({queryKey:[,o]}){if(o.length<1)throw new Error("No chains found");return yield G(!!(e!=null&&e.multiChain),o,s=>l(void 0,null,function*(){var A;let a=(A=u.getState().chainsConfig)==null?void 0:A[s.chainId],c={url:s.rpc,headers:k({},(a==null?void 0:a.rpcHeaders)||{})};return yield cosmwasmStargate.CosmWasmClient.connect(c)}))}),enabled:!!t&&t.length>0&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})},we=({type:e,chainId:t,multiChain:i,enabled:o})=>{let r=U({chainId:t,multiChain:i}),n=react.useMemo(()=>["USE_TENDERMINT_CLIENT",e,r],[e,r]);return reactQuery.useQuery({queryKey:n,queryFn:c=>l(void 0,[c],function*({queryKey:[,s,a]}){if(a.length<1)throw new Error("No chains found");return yield G(!!i,a,A=>l(void 0,null,function*(){var C;let d=(C=u.getState().chainsConfig)==null?void 0:C[A.chainId],S={url:A.rpc,headers:k({},(d==null?void 0:d.rpcHeaders)||{})};return yield (s==="tm37"?tendermintRpc.Tendermint37Client:tendermintRpc.Tendermint34Client).connect(S)}))}),enabled:!!r&&r.length>0&&(o!==void 0?!!o:!0),refetchOnWindowFocus:!1})};var is=()=>u(e=>({walletType:e.walletType,isCosmostation:e.walletType==="cosmostation",isCosmostationMobile:e.walletType==="wc_cosmostation_mobile",isKeplr:e.walletType==="keplr",isKeplrMobile:e.walletType==="wc_keplr_mobile",isLeap:e.walletType==="leap",isLeapMobile:e.walletType==="wc_leap_mobile",isVectis:e.walletType==="vectis",isWalletConnect:e.walletType==="walletconnect",isMetamaskSnapLeap:e.walletType==="metamask_snap_leap",isStation:e.walletType==="station",isCapsule:e.walletType==="capsule",isCosmiframe:e.walletType==="cosmiframe"}),shallow.shallow),Ae=e=>{let i=["USE_CHECK_WALLET",u(r=>e||r.walletType)];return reactQuery.useQuery(i,({queryKey:[,r]})=>B(r))};var J=e=>{let t=u(a=>a.walletType),i=g(a=>a.activeChainIds),o=U({chainId:e!=null&&e.chainId?e.chainId:i||void 0,multiChain:e==null?void 0:e.multiChain}),r=g(a=>a.accounts),n=g(a=>a.status);return react.useEffect(()=>g.subscribe(a=>a.status,(a,c)=>{var f,A,d;if(a==="connected"){let{accounts:S,activeChainIds:y}=g.getState(),{chains:m}=u.getState(),{walletType:C}=u.getState();if(!S||!y||!m)return (f=e==null?void 0:e.onDisconnect)==null?void 0:f.call(e);(A=e==null?void 0:e.onConnect)==null||A.call(e,{accounts:S,chains:y.map(h=>m.find(M=>M.chainId===h)),walletType:C,isReconnect:c==="reconnecting"});}a==="disconnected"&&((d=e==null?void 0:e.onDisconnect)==null||d.call(e));}),[e]),{data:react.useMemo(()=>r?Mt(!!(e!=null&&e.multiChain),o,a=>r[a.chainId]):void 0,[r,o,e==null?void 0:e.multiChain]),isConnected:n==="connected",isConnecting:n==="connecting",isDisconnected:n==="disconnected",isReconnecting:n==="reconnecting",isLoading:n==="connecting"||n==="reconnecting",walletType:n==="connected"?t:void 0,reconnect:L,status:n}},hn=e=>{let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),{data:i}=J(),o=(e==null?void 0:e.bech32Address)||(i==null?void 0:i.bech32Address),{data:r}=Ne({chainId:t.map(s=>s.chainId),multiChain:!0,enabled:((e==null?void 0:e.enabled)===void 0?!0:e.enabled)&&!!o}),n=react.useMemo(()=>["USE_ALL_BALANCES",r,t,o,e==null?void 0:e.chainId],[o,e==null?void 0:e.chainId,t,r]);return reactQuery.useQuery(n,f=>l(void 0,[f],function*({queryKey:[,s,a,c]}){if(!c)throw new Error("address is not defined");return yield G(!!(e!=null&&e.multiChain),a,d=>l(void 0,null,function*(){var m;let S=s==null?void 0:s[d.chainId];if(!S)throw new Error(`Client is not ready ${d.chainId}`);if(!((m=d.bech32Config)!=null&&m.bech32PrefixAccAddr))throw new Error(`Bech32Config is missing ${d.chainId}`);return yield S.getAllBalances(encoding.toBech32(d.bech32Config.bech32PrefixAccAddr,encoding.fromBech32(c).data))}))}),{enabled:!!o&&!!t&&t.length>0&&!he(r)&&((e==null?void 0:e.enabled)===void 0?!0:e.enabled),refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!1})},ys=e=>{let t=U({chainId:e.chainId}),{data:i}=J({chainId:e.chainId}),o=e.bech32Address||(i==null?void 0:i.bech32Address),{data:r,refetch:n}=hn({chainId:t.map(c=>c.chainId),bech32Address:o,enabled:!!o&&(e.enabled===void 0?!0:e.enabled)}),s=["USE_BALANCE",e.denom,r,t,o,e.chainId],a=reactQuery.useQuery(s,({queryKey:[,c,f]})=>f==null?void 0:f.find(A=>A.denom===c),{enabled:!!e.denom&&!!r&&!!(r!=null&&r.length)&&(e.enabled===void 0?!0:e.enabled)});return F(k({},a),{refetch:c=>l(void 0,null,function*(){return yield n(),a.refetch(c)})})},Cs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=reactQuery.useMutation(["USE_CONNECT",e,t,i],Y,{onError:(s,a)=>e==null?void 0:e(s,a),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))}),{data:n}=Ae();return {connect:s=>r.mutate(s),connectAsync:s=>r.mutateAsync(s),error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,isSupported:!!n,status:r.status}},Ss=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=reactQuery.useMutation(["USE_DISCONNECT",e,t,i],re,{onError:n=>Promise.resolve(e==null?void 0:e(n,void 0)),onMutate:t,onSuccess:()=>Promise.resolve(i==null?void 0:i(void 0))});return {disconnect:n=>r.mutate(n),disconnectAsync:n=>r.mutateAsync(n),error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,status:r.status}},hs=e=>{let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(r=>r.walletType),o=react.useMemo(()=>["USE_OFFLINE_SIGNERS",t,i],[t,i]);return reactQuery.useQuery({queryKey:o,queryFn:s=>l(void 0,[s],function*({queryKey:[,r,n]}){if(r.length<1)throw new Error("No chain found");if(!B(n))throw new Error(`${n} is not available`);return yield G(!!(e!=null&&e.multiChain),r,f=>l(void 0,null,function*(){return yield gt({chainId:f.chainId,walletType:n})}))}),enabled:!!t&&t.length>0&&!!i,refetchOnWindowFocus:!1})},ws=e=>{let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),{data:i}=J(),{data:o}=Ne({chainId:t.map(s=>s.chainId),multiChain:!0}),r=(e==null?void 0:e.bech32Address)||(i==null?void 0:i.bech32Address),n=react.useMemo(()=>["USE_BALANCE_STAKED",o,t,r],[t,r,o]);return reactQuery.useQuery(n,f=>l(void 0,[f],function*({queryKey:[,s,a,c]}){if(!c)throw new Error("address is not defined");return yield G(!!(e!=null&&e.multiChain),a,d=>l(void 0,null,function*(){var y,m;if(!s)throw new Error("Client is not ready");if(!((y=d.bech32Config)!=null&&y.bech32PrefixAccAddr))throw new Error(`Bech32Config is missing ${d.chainId}`);return yield (m=s[d.chainId])==null?void 0:m.getBalanceStaked(encoding.toBech32(d.bech32Config.bech32PrefixAccAddr,encoding.fromBech32(c).data))}))}),{enabled:!!r&&!!t&&t.length>0&&!!o,refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!1})};var Ms=()=>{let e=u(o=>o.capsuleState),t=g(o=>o.capsuleClient),i=ce();return {setModalState:o=>{u.setState(r=>{var n;return {capsuleState:{showModal:o,chainId:(n=r.capsuleState)==null?void 0:n.chainId}}});},modalState:!!(e!=null&&e.showModal),client:t,onAfterLoginSuccessful:i.onAfterLoginSuccessful,onLoginFailure:()=>{re();}}};var Ds=()=>g(e=>e.activeChainIds),wn=()=>{var e;return (e=g(t=>t.activeChainIds))==null?void 0:e.map(t=>{var o;let i=(o=u.getState().chains)==null?void 0:o.find(r=>r.chainId===t);if(i)return i}).filter(Boolean)},Ks=({chainId:e})=>{var t;return (t=u().chains)==null?void 0:t.find(i=>i.chainId===e)},_s=({chainId:e})=>{var t;return (t=u().chains)==null?void 0:t.filter(i=>e==null?void 0:e.includes(i.chainId))},Ns=({denom:e})=>{let t=wn();return reactQuery.useQuery(["USE_ACTIVE_CHAIN_CURRENCY",e],({queryKey:[,r]})=>{var n;return (n=t==null?void 0:t.find(s=>s.currencies.find(a=>a.coinMinimalDenom===r)))==null?void 0:n.currencies.find(s=>s)})},Bs=e=>{var r;let t=(r=e.status)!=null?r:"BOND_STATUS_BONDED",i=["USE_ACTIVE_CHAIN_VALIDATORS",e.queryClient,t];return reactQuery.useQuery(i,a=>l(void 0,[a],function*({queryKey:[,n,s]}){if(!n)throw new Error("Query client is not defined");return yield n.staking.validators(s)}),{enabled:typeof e.queryClient!="undefined"})},Ls=()=>({data:u(t=>t.recentChainIds),clear:Pe}),Us=()=>{var t;return {data:(t=u(i=>i.recentChainIds))==null?void 0:t.map(i=>{var r;let o=(r=u.getState().chains)==null?void 0:r.find(n=>n.chainId===i);if(o)return o}).filter(Boolean),clear:Pe}},qs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=reactQuery.useMutation(["USE_SUGGEST_CHAIN",e,t,i],We,{onError:(n,s)=>Promise.resolve(e==null?void 0:e(n,s.chainInfo)),onMutate:n=>t==null?void 0:t(n.chainInfo),onSuccess:n=>Promise.resolve(i==null?void 0:i(n))});return {error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,suggest:r.mutate,suggestAsync:r.mutateAsync,status:r.status}},Fs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=reactQuery.useMutation(["USE_SUGGEST_CHAIN_AND_CONNECT",e,t,i],yt,{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:s=>t==null?void 0:t(s),onSuccess:s=>Promise.resolve(i==null?void 0:i(s))}),{data:n}=Ae();return {error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,isSupported:!!n,status:r.status,suggestAndConnect:r.mutate,suggestAndConnectAsync:r.mutateAsync}};var Xs=({onError:e,onLoading:t,onSuccess:i}={})=>{let{data:o}=J(),r=o==null?void 0:o.bech32Address,n=reactQuery.useMutation(["USE_SEND_TOKENS",e,t,i,r],s=>St(k({senderAddress:r},s)),{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))});return {error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,sendTokens:n.mutate,sendTokensAsync:n.mutateAsync,status:n.status}},Ys=({onError:e,onLoading:t,onSuccess:i}={})=>{let{data:o}=J(),r=o==null?void 0:o.bech32Address,n=reactQuery.useMutation(["USE_SEND_IBC_TOKENS",e,t,i,r],s=>ht(k({senderAddress:r},s)),{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))});return {error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,sendIbcTokens:n.mutate,sendIbcTokensAsync:n.mutateAsync,status:n.status}},Js=({codeId:e,onError:t,onLoading:i,onSuccess:o})=>{let{data:r}=J(),n=r==null?void 0:r.bech32Address,a=reactQuery.useMutation(["USE_INSTANTIATE_CONTRACT",t,i,o,e,n],c=>{var A;if(!n)throw new Error("senderAddress is undefined");let f=F(k({},c),{fee:(A=c.fee)!=null?A:"auto",senderAddress:n,codeId:e});return wt(f)},{onError:(c,f)=>Promise.resolve(t==null?void 0:t(c,f)),onMutate:i,onSuccess:c=>Promise.resolve(o==null?void 0:o(c))});return {error:a.error,isLoading:a.isLoading,isSuccess:a.isSuccess,instantiateContract:a.mutate,instantiateContractAsync:a.mutateAsync,status:a.status}},Zs=({contractAddress:e,onError:t,onLoading:i,onSuccess:o})=>{let{data:r}=J(),n=r==null?void 0:r.bech32Address,a=reactQuery.useMutation(["USE_EXECUTE_CONTRACT",t,i,o,e,n],c=>{var A,d,S;if(!n)throw new Error("senderAddress is undefined");let f=F(k({},c),{fee:(A=c.fee)!=null?A:"auto",senderAddress:n,contractAddress:e,memo:(d=c.memo)!=null?d:"",funds:(S=c.funds)!=null?S:[]});return At(f)},{onError:(c,f)=>Promise.resolve(t==null?void 0:t(c,f)),onMutate:i,onSuccess:c=>Promise.resolve(o==null?void 0:o(c))});return {error:a.error,isLoading:a.isLoading,isSuccess:a.isSuccess,executeContract:a.mutate,executeContractAsync:a.mutateAsync,status:a.status}},ea=e=>{let{data:t}=Be();return reactQuery.useQuery(["USE_QUERY_SMART",e==null?void 0:e.address,e==null?void 0:e.queryMsg,t],({queryKey:[,o]})=>{if(!(e!=null&&e.address)||!e.queryMsg)throw new Error("address or queryMsg undefined");return It(e.address,e.queryMsg,t)},{enabled:!!(e!=null&&e.address)&&!!(e!=null&&e.queryMsg)&&!!t})},ta=e=>{let{data:t}=Be(),i=["USE_QUERY_RAW",e==null?void 0:e.key,e==null?void 0:e.address,t];return reactQuery.useQuery(i,({queryKey:[,r]})=>{if(!(e!=null&&e.address)||!e.key)throw new Error("address or key undefined");return Ot(e.address,e.key,t)},{enabled:!!(e!=null&&e.address)&&!!(e!=null&&e.key)&&!!t})};function fa(e){let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(n=>n.walletType),o=g(n=>n.activeChainIds),r=react.useMemo(()=>["USE_STARGATE_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]);return reactQuery.useQuery({queryKey:r,queryFn:a=>l(this,[a],function*({queryKey:[,n,s]}){if(n.length<1)throw new Error("No chains found");return yield G(!!(e!=null&&e.multiChain),n,f=>l(this,null,function*(){var C,h;if(!(o!=null&&o.includes(f.chainId)))return null;if(!B(s))throw new Error(`${s} is not available`);let d=yield (()=>l(this,null,function*(){switch(e==null?void 0:e.offlineSigner){case"offlineSigner":return R(s).getOfflineSigner(f.chainId);case"offlineSignerAuto":return R(s).getOfflineSignerAuto(f.chainId);case"offlineSignerOnlyAmino":return R(s).getOfflineSignerOnlyAmino(f.chainId);default:return R(s).getOfflineSignerAuto(f.chainId)}}))(),S=(C=u.getState().chainsConfig)==null?void 0:C[f.chainId],y={url:f.rpc,headers:k({},(S==null?void 0:S.rpcHeaders)||{})};return (e==null?void 0:e.multiChain)===!0&&e.opts,yield stargate.SigningStargateClient.connectWithSigner(y,d,e!=null&&e.multiChain?(h=e.opts)==null?void 0:h[f.chainId]:e==null?void 0:e.opts)}))}),enabled:!!t&&t.length>0&&!!i&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function ga(e){let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(n=>n.walletType),o=g(n=>n.activeChainIds),r=react.useMemo(()=>["USE_COSMWASM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]);return reactQuery.useQuery({queryKey:r,queryFn:a=>l(this,[a],function*({queryKey:[,n,s]}){if(n.length<1)throw new Error("No chains found");return yield G(!!(e!=null&&e.multiChain),n,f=>l(this,null,function*(){var h,M;if(!(o!=null&&o.includes(f.chainId)))return null;if(!B(s))throw new Error(`${s} is not available`);let d=yield (()=>l(this,null,function*(){switch(e==null?void 0:e.offlineSigner){case"offlineSigner":return R(s).getOfflineSigner(f.chainId);case"offlineSignerAuto":return R(s).getOfflineSignerAuto(f.chainId);case"offlineSignerOnlyAmino":return R(s).getOfflineSignerOnlyAmino(f.chainId);default:return R(s).getOfflineSignerAuto(f.chainId)}}))(),S=(h=u.getState().chainsConfig)==null?void 0:h[f.chainId],y={url:f.rpc,headers:k({},(S==null?void 0:S.rpcHeaders)||{})},m=S!=null&&S.gas?stargate.GasPrice.fromString(`${S.gas.price}${S.gas.denom}`):void 0;return yield cosmwasmStargate.SigningCosmWasmClient.connectWithSigner(y,d,k({gasPrice:m},e!=null&&e.multiChain?(M=e.opts)==null?void 0:M[f.chainId]:(e==null?void 0:e.opts)||{}))}))}),enabled:!!t&&t.length>0&&!!i&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function ya(e){let t=U({chainId:e.chainId,multiChain:e.multiChain}),i=u(s=>s.walletType),o=g(s=>s.activeChainIds),r=react.useMemo(()=>["USE_STARGATE_TM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]),{data:n}=we({type:e.type,chainId:e.chainId,multiChain:e.multiChain});return reactQuery.useQuery({queryKey:r,queryFn:c=>l(this,[c],function*({queryKey:[,s,a]}){if(s.length<1)throw new Error("No chains found");return yield G(!!e.multiChain,s,A=>l(this,null,function*(){var C;if(!(o!=null&&o.includes(A.chainId)))return null;if(!B(a))throw new Error(`${a} is not available`);if(!n)throw new Error("No tendermint client found");let S=yield (()=>l(this,null,function*(){switch(e.offlineSigner){case"offlineSigner":return R(a).getOfflineSigner(A.chainId);case"offlineSignerAuto":return R(a).getOfflineSignerAuto(A.chainId);case"offlineSignerOnlyAmino":return R(a).getOfflineSignerOnlyAmino(A.chainId);default:return R(a).getOfflineSignerAuto(A.chainId)}}))(),y=e.multiChain?n[A.chainId]:n;return yield stargate.SigningStargateClient.createWithSigner(y,S,e.multiChain?(C=e.opts)==null?void 0:C[A.chainId]:e.opts)}))}),enabled:!!t&&t.length>0&&!!i&&!!n&&(e.enabled!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function Ca(e){let t=U({chainId:e.chainId,multiChain:e.multiChain}),i=u(a=>a.walletType),o=g(a=>a.activeChainIds),r=react.useMemo(()=>["USE_COSMWASM_TM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]),{data:n}=we({type:e.type,chainId:e.chainId,multiChain:!1,enabled:!e.multiChain}),{data:s}=we({type:e.type,chainId:e.chainId,multiChain:!0,enabled:!!e.multiChain});return reactQuery.useQuery({queryKey:r,queryFn:f=>l(this,[f],function*({queryKey:[,a,c]}){if(a.length<1)throw new Error("No chains found");return yield G(!!e.multiChain,a,d=>l(this,null,function*(){var p,I;if(!(o!=null&&o.includes(d.chainId)))return null;if(!B(c))throw new Error(`${c} is not available`);let y=yield (()=>l(this,null,function*(){switch(e.offlineSigner){case"offlineSigner":return R(c).getOfflineSigner(d.chainId);case"offlineSignerAuto":return R(c).getOfflineSignerAuto(d.chainId);case"offlineSignerOnlyAmino":return R(c).getOfflineSignerOnlyAmino(d.chainId);default:return R(c).getOfflineSignerAuto(d.chainId)}}))(),m=(p=u.getState().chainsConfig)==null?void 0:p[d.chainId],C=m!=null&&m.gas?stargate.GasPrice.fromString(`${m.gas.price}${m.gas.denom}`):void 0,h=e.multiChain?s==null?void 0:s[d.chainId]:n;if(!h)throw new Error("No tendermint client found");return yield cosmwasmStargate.SigningCosmWasmClient.createWithSigner(h,y,k({gasPrice:C},e.multiChain?(I=e.opts)==null?void 0:I[d.chainId]:e.opts||{}))}))}),enabled:!!t&&t.length>0&&!!i&&(!!n||!he(s))&&(e.enabled!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}var Nt=({children:e})=>{let[t,i]=react.useState(!1);return react.useEffect(()=>{i(!0);},[]),jsxRuntime.jsx(jsxRuntime.Fragment,{children:t?e:null})};var Tn=()=>{let e=typeof window!="undefined"&&window.sessionStorage.getItem(X)==="Active",{_reconnect:t,_onReconnectFailed:i,_reconnectConnector:o,iframeOptions:r,chains:n}=u(),{activeChainIds:s,wcSignClients:a}=g(),c=B(o||void 0);return react.useEffect(()=>{if(!r||r.autoConnect===!1||!r.allowedIframeParentOrigins.length||!n)return;new cosmiframe.Cosmiframe(r.allowedIframeParentOrigins).isReady().then(A=>{if(A)return Y({chainId:n.map(d=>d.chainId),walletType:"cosmiframe"})});},[r]),react.useEffect(()=>{if(o){if(!c)return;e&&s?L({onError:i}):!e&&t&&L({onError:i});}},[c]),react.useEffect(()=>{var f,A,d,S,y,m,C,h,M,p,I,b,W,D,K,Z,oe,w,O,E;if(o){if(!c)return;o==="cosmostation"&&((A=(f=pe()).subscription)==null||A.call(f,()=>{L({onError:i});})),o==="keplr"&&((S=(d=me()).subscription)==null||S.call(d,()=>{L({onError:i});})),o==="leap"&&((m=(y=de()).subscription)==null||m.call(y,()=>{L({onError:i});})),o==="compass"&&((h=(C=le()).subscription)==null||h.call(C,()=>{L({onError:i});})),o==="vectis"&&((p=(M=Ce()).subscription)==null||p.call(M,()=>{L({onError:i});})),o==="walletconnect"&&a.has("walletconnect")&&((b=(I=Q()).subscription)==null||b.call(I,()=>{L({onError:i});})),o==="station"&&((D=(W=ye()).subscription)==null||D.call(W,()=>{L({onError:i});})),o==="xdefi"&&((Z=(K=Se()).subscription)==null||Z.call(K,()=>{L({onError:i});})),o==="cosmiframe"&&((w=(oe=ue()).subscription)==null||w.call(oe,()=>{L({onError:i});})),o==="okx"&&((E=(O=ge()).subscription)==null||E.call(O,()=>{L({onError:i});}));}},[o,a,c]),null},Bt=()=>(Tn(),null);var vn=new reactQuery.QueryClient({}),Ha=o=>{var r=o,{children:e,grazOptions:t}=r,i=je(r,["children","grazOptions"]);return react.useEffect(()=>{Ct(t);},[t]),jsxRuntime.jsx(reactQuery.QueryClientProvider,F(k({client:vn},i),{children:jsxRuntime.jsxs(Nt,{children:[e,jsxRuntime.jsx(Bt,{})]})}),"graz-provider")};
25
+ var Ut=Object.defineProperty,qt=Object.defineProperties;var Ft=Object.getOwnPropertyDescriptors;var ae=Object.getOwnPropertySymbols;var ze=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable;var Ge=(e,t,i)=>t in e?Ut(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,k=(e,t)=>{for(var i in t||(t={}))ze.call(t,i)&&Ge(e,i,t[i]);if(ae)for(var i of ae(t))Qe.call(t,i)&&Ge(e,i,t[i]);return e},F=(e,t)=>qt(e,Ft(t));var je=(e,t)=>{var i={};for(var o in e)ze.call(e,o)&&t.indexOf(o)<0&&(i[o]=e[o]);if(e!=null&&ae)for(var o of ae(e))t.indexOf(o)<0&&Qe.call(e,o)&&(i[o]=e[o]);return i};var l=(e,t,i)=>new Promise((o,r)=>{var n=c=>{try{a(i.next(c));}catch(f){r(f);}},s=c=>{try{a(i.throw(c));}catch(f){r(f);}},a=c=>c.done?o(c.value):Promise.resolve(c.value).then(n,s);a((i=i.apply(e,t)).next());});var X="graz-reconnect-session";var $e=(p=>(p.KEPLR="keplr",p.LEAP="leap",p.VECTIS="vectis",p.COSMOSTATION="cosmostation",p.WALLETCONNECT="walletconnect",p.WC_KEPLR_MOBILE="wc_keplr_mobile",p.WC_LEAP_MOBILE="wc_leap_mobile",p.WC_COSMOSTATION_MOBILE="wc_cosmostation_mobile",p.WC_CLOT_MOBILE="wc_clot_mobile",p.METAMASK_SNAP_LEAP="metamask_snap_leap",p.METAMASK_SNAP_COSMOS="metamask_snap_cosmos",p.STATION="station",p.XDEFI="xdefi",p.CAPSULE="capsule",p.COSMIFRAME="cosmiframe",p.COMPASS="compass",p.INITIA="initia",p.OKX="okx",p))($e||{}),He=["keplr","leap","vectis","cosmostation","walletconnect","wc_keplr_mobile","wc_leap_mobile","wc_cosmostation_mobile","wc_clot_mobile","metamask_snap_leap","station","xdefi","capsule","metamask_snap_cosmos","cosmiframe","compass","initia","okx"];var zt={iframeOptions:null,recentChainIds:null,chains:null,chainsConfig:null,capsuleConfig:null,capsuleState:null,multiChainFetchConcurrency:3,walletType:"keplr",walletConnect:{options:null,walletConnectModal:null},walletDefaultOptions:null,_notFoundFn:()=>null,_onReconnectFailed:()=>null,_reconnect:!1,_reconnectConnector:null},ie={accounts:null,activeChainIds:null,status:"disconnected",wcSignClients:new Map,capsuleClient:null},Qt={name:"graz-session",version:2,partialize:e=>({accounts:e.accounts,activeChainIds:e.activeChainIds}),storage:middleware.createJSONStorage(()=>sessionStorage)},jt={name:"graz-internal",partialize:e=>({recentChainIds:e.recentChainIds,_reconnect:e._reconnect,_reconnectConnector:e._reconnectConnector,walletType:e.walletType}),version:2},g=zustand.create(middleware.subscribeWithSelector(middleware.persist(()=>ie,Qt))),u=zustand.create(middleware.subscribeWithSelector(middleware.persist(()=>zt,jt)));var ce=()=>{var S,y;if(!((S=u.getState().capsuleConfig)!=null&&S.apiKey)||!((y=u.getState().capsuleConfig)!=null&&y.env))throw new Error("Capsule configuration is not set");let e=()=>l(void 0,null,function*(){var h,M;let m=(yield import('@leapwallet/cosmos-social-login-capsule-provider')).CapsuleProvider,C=new m({apiKey:(h=u.getState().capsuleConfig)==null?void 0:h.apiKey,env:(M=u.getState().capsuleConfig)==null?void 0:M.env});return g.setState({capsuleClient:C}),C});return {init:e,enable:m=>l(void 0,null,function*(){let C=typeof m=="string"?[m]:m,h=g.getState().capsuleClient;h||(h=yield e()),u.setState({capsuleState:{showModal:!0,chainId:C}});}),onAfterLoginSuccessful:()=>l(void 0,null,function*(){var p;let m=g.getState().capsuleClient,{chains:C}=u.getState();if(!m)throw new Error("Capsule client is not initialized");if(!C)throw new Error("Chains are not set");yield m.enable();let h=(p=u.getState().capsuleState)==null?void 0:p.chainId;if(!h)throw new Error("Chain ids are not set");let M=Object.fromEntries(yield Promise.all(h.map(I=>l(void 0,null,function*(){let b=yield m.getAccount(I);return [I,{address:encoding.fromBech32(b.address).data,bech32Address:b.address,algo:b.algo,name:b.username||"",pubKey:b.pubkey,isKeystone:!1,isNanoLedger:!1}]}))));g.setState(I=>({accounts:k(k({},I.accounts||{}),M)})),u.setState(I=>({recentChainIds:[...I.recentChainIds||[],...h].filter((b,W,D)=>D.indexOf(b)===W)})),g.setState(I=>({activeChainIds:[...I.activeChainIds||[],...h].filter((b,W,D)=>D.indexOf(b)===W)})),u.setState({walletType:"capsule",_reconnect:!1,_reconnectConnector:"capsule"}),g.setState({status:"connected"}),typeof window!="undefined"&&window.sessionStorage.setItem(X,"Active"),u.setState({capsuleState:null});}),getKey:m=>l(void 0,null,function*(){let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");let h=yield C.getAccount(m);return {address:encoding.fromBech32(h.address).data,bech32Address:h.address,algo:h.algo,name:h.username||"",pubKey:h.pubkey,isKeystone:!1,isNanoLedger:!1}}),getOfflineSignerAuto:m=>l(void 0,null,function*(){let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerDirect(m)}),getOfflineSignerDirect:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerDirect(m)},signDirect:(...m)=>l(void 0,null,function*(){let[C,h,M]=m,p=g.getState().capsuleClient;if(!p)throw new Error("Capsule client is not initialized");return p.signDirect(C,h,{bodyBytes:M.bodyBytes,authInfoBytes:M.authInfoBytes,chainId:M.chainId,accountNumber:M.accountNumber})}),signAmino:(...m)=>l(void 0,null,function*(){let[C,h,M,p]=m,I=g.getState().capsuleClient;if(!I)throw new Error("Capsule client is not initialized");return I.signAmino(C,h,M,p)}),signArbitrary:(m,C,h)=>l(void 0,null,function*(){let M=g.getState().capsuleClient;if(!M)throw new Error("Capsule client is not initialized");let p=yield M.getAccount(m);if(!p)throw new Error(`Wallet not connected to account ${C}`);let I=(()=>{switch(p.algo){case"secp256k1":return amino.encodeSecp256k1Pubkey(p.pubkey);case"ed25519":return amino.encodeEd25519Pubkey(p.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {signature:yield M.signArbitrary(m,C,h),pub_key:{type:p.algo==="secp256k1"?amino.pubkeyType.secp256k1:amino.pubkeyType.ed25519,value:I.value}}}),experimentalSuggestChain:(...m)=>l(void 0,null,function*(){yield Promise.reject(new Error("Capsule does not support experimentalSuggestChain"));}),getOfflineSigner:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSigner(m)},getOfflineSignerAmino:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerAmino(m)}}};var le=()=>{if(typeof window.compass!="undefined"){let e=window.compass;return Object.assign(e,{subscription:r=>{let n=()=>{_(),r();};return window.addEventListener("leap_keystorechange",n),()=>{window.removeEventListener("leap_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.leap is not defined")};var ue=()=>{let e=u.getState();if(!e.iframeOptions)throw e._notFoundFn(),new Error("no iframe options set");if(!cosmiframe.isInIframe())throw e._notFoundFn(),new Error("not in iframe");if(!e.iframeOptions.allowedIframeParentOrigins.length)throw e._notFoundFn(),new Error("no iframe allowed origins");let t=new cosmiframe.Cosmiframe(e.iframeOptions.allowedIframeParentOrigins).getKeplrClient();return {enable:t.enable.bind(t),getKey:t.getKey.bind(t),getOfflineSigner:t.getOfflineSigner.bind(t),getOfflineSignerAuto:t.getOfflineSignerAuto.bind(t),getOfflineSignerOnlyAmino:t.getOfflineSignerOnlyAmino.bind(t),experimentalSuggestChain:t.experimentalSuggestChain.bind(t),signDirect:t.signDirect.bind(t),signAmino:t.signAmino.bind(t)}};var nt={},it=()=>{let e=window.ethereum,t=window.cosmos;if(e)return {init:()=>l(void 0,null,function*(){var A;let n=yield e.request({method:"web3_clientVersion"});if(!n.includes("MetaMask"))throw new Error("Metamask is not installed");if(typeof window.okxwallet!="undefined"&&window.okxwallet.isOkxWallet)throw new Error("You have OKX Wallet installed. Please disable and reload the page to use Metamask Snap.");let a=(A=n.split("MetaMask/v")[1])==null?void 0:A.split(".")[0];if(!(Number(a)>=11))throw new Error("Metamask Snap is not supported in this version");return (yield snapper.isSnapInstalled())||(yield snapper.installSnap()),window.cosmos=new snapper.CosmosSnap,t=window.cosmos,!0}),enable:n=>l(void 0,null,function*(){(yield snapper.isSnapInstalled())||(yield snapper.installSnap());}),getOfflineSigner:n=>t.getOfflineSigner(n),experimentalSuggestChain:n=>l(void 0,null,function*(){if(!n.bech32Config)throw new Error("Bech32Config is required");if(!n.stakeCurrency)throw new Error("StakeCurrency is required");yield t.experimentalSuggestChain(F(k({},n),{stakeCurrency:n.stakeCurrency,bech32Config:n.bech32Config}));}),signAmino:(n,s,a)=>l(void 0,null,function*(){return t.signAmino(n,s,a)}),getKey:n=>l(void 0,null,function*(){return typeof nt[n]!="undefined"?nt[n]:t.getKey(n)}),getOfflineSignerAuto:n=>l(void 0,null,function*(){return (yield t.getKey(n)).isNanoLedger?t.getOfflineSignerOnlyAmino(n):t.getOfflineSigner(n)}),getOfflineSignerOnlyAmino:n=>t.getOfflineSignerOnlyAmino(n),signDirect:(n,s,a)=>l(void 0,null,function*(){return t.signDirect(n,s,a)}),signArbitrary:(n,s,a)=>l(void 0,null,function*(){return t.signArbitrary(n,s,a)}),disable:n=>l(void 0,null,function*(){n&&(yield t.deleteChain(n));})};throw u.getState()._notFoundFn(),new Error("window.ethereum is not defined")};var pe=()=>{var e;if(typeof((e=window.cosmostation)==null?void 0:e.providers.keplr)!="undefined"){let t=window.cosmostation.providers.keplr;return Object.assign(t,{subscription:n=>{let s=()=>{_(),n();};return window.addEventListener("cosmostation_keystorechange",s),()=>{window.removeEventListener("cosmostation_keystorechange",s);}},setDefaultOptions:n=>{t.defaultOptions=n;}})}throw u.getState()._notFoundFn(),new Error("window.cosmostation.providers.keplr is not defined")};var nn=e=>{let{bodyBytes:t,authInfoBytes:i,chainId:o,accountNumber:r}=e;if(!t||!i||!o||!r)throw new Error("Invalid sign doc");return {bodyBytes:t,authInfoBytes:i,chainId:o,accountNumber:r}},on=e=>`${e.slice(0,6)}...${e.slice(-6)}`,rt=()=>{if(typeof window.initia!="undefined"){let e=window.initia;return {enable:()=>l(void 0,null,function*(){yield e.getAddress();}),getKey:d=>l(void 0,null,function*(){let S=e.getOfflineSigner(d),[y]=yield S.getAccounts();if(!y)throw new Error("Wallet connection failed");let m=(()=>{switch(y.algo){case"secp256k1":return amino.rawSecp256k1PubkeyToRawAddress(y.pubkey);case"ed25519":return amino.rawEd25519PubkeyToRawAddress(y.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {name:on(y.address),algo:y.algo,pubKey:y.pubkey,bech32Address:y.address,address:m,isNanoLedger:!1,isKeystone:!1}}),getOfflineSigner:d=>{let S=e.getOfflineSigner(d),y=e.getOfflineSignerOnlyAmino(d);return {getAccounts:S.getAccounts.bind(S),signDirect:S.signDirect.bind(S),signAmino:y.signAmino.bind(y)}},getOfflineSignerAuto:d=>Promise.resolve(e.getOfflineSigner(d)),getOfflineSignerOnlyAmino:d=>e.getOfflineSignerOnlyAmino(d),experimentalSuggestChain:d=>e.requestAddInitiaLayer({chain_id:d.chainId,chain_name:d.chainName,bech32_prefix:"init",bech32_config:d.bech32Config,slip44:d.bip44.coinType,logo_URIs:{png:d.chainSymbolImageUrl},fees:{fee_tokens:d.feeCurrencies.map(S=>{var y,m,C;return {denom:S.coinDenom,amount:S.coinMinimalDenom,low_gas_price:(y=S.gasPriceStep)==null?void 0:y.low,average_gas_price:(m=S.gasPriceStep)==null?void 0:m.average,high_gas_price:(C=S.gasPriceStep)==null?void 0:C.high}})},apis:{rpc:[{address:d.rpc}],rest:[{address:d.rest}]}}),signDirect:(...d)=>{let[S,y,m]=d;return e.getOfflineSigner(S).signDirect(y,nn(m))},signAmino:(...d)=>{let[S,y,m]=d;return e.getOfflineSignerOnlyAmino(S).signAmino(y,m)},signArbitrary:(d,S,y)=>l(void 0,null,function*(){let h=(yield e.getOfflineSigner(d).getAccounts()).find(I=>I.address===S);if(!h)throw new Error(`Wallet not connected to account ${S}`);let M=(()=>{switch(h.algo){case"secp256k1":return amino.encodeSecp256k1Pubkey(h.pubkey);case"ed25519":return amino.encodeEd25519Pubkey(h.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {signature:yield e.signArbitrary(y),pub_key:{type:h.algo==="secp256k1"?amino.pubkeyType.secp256k1:amino.pubkeyType.ed25519,value:M.value}}}),subscription:d=>{let S=()=>{_(),d();};return window.addEventListener("initia_keystorechange",S),()=>{window.removeEventListener("initia_keystorechange",S);}}}}throw u.getState()._notFoundFn(),new Error("window.initia is not defined")};var me=()=>{if(typeof window.keplr!="undefined"){let e=window.keplr;return Object.assign(e,{subscription:r=>{let n=()=>{_(),r();};return window.addEventListener("keplr_keystorechange",n),()=>{window.removeEventListener("keplr_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.keplr is not defined")};var de=()=>{if(typeof window.leap!="undefined"){let e=window.leap;return Object.assign(e,{subscription:r=>{let n=()=>{_(),r();};return window.addEventListener("leap_keystorechange",n),()=>{window.removeEventListener("leap_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.leap is not defined")};var fe={},st=e=>{let t=window.ethereum;if(t&&e){let i=()=>l(void 0,null,function*(){return yield t.request({method:"wallet_getSnaps"})}),o=p=>l(void 0,null,function*(){try{let I=yield i();return Object.values(I).find(b=>b.id===e.id&&(!p||b.version===p))}catch(I){return}}),r=()=>l(void 0,null,function*(){yield t.request({method:"wallet_requestSnaps",params:{[e.id]:e.params||{}}});}),n=()=>l(void 0,null,function*(){var K;let p=yield t.request({method:"web3_clientVersion"});if(!p.includes("MetaMask"))throw new Error("Metamask is not installed");if(typeof window.okxwallet!="undefined"&&window.okxwallet.isOkxWallet)throw new Error("You have OKX Wallet installed. Please disable and reload the page to use Metamask Snap.");let b=(K=p.split("MetaMask/v")[1])==null?void 0:K.split(".")[0];if(!(Number(b)>=11))throw new Error("Metamask Snap is not supported in this version");return (yield o())||(yield r()),!0}),s=p=>l(void 0,null,function*(){(yield o())||(yield r());}),a=(p,I,b)=>l(void 0,null,function*(){let W=yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"signDirect",params:{chainId:p,signerAddress:I,signDoc:b}}}}),D=b.accountNumber,K=new rn__default.default(D.low,D.high,D.unsigned);return {signature:W.signature,signed:F(k({},W.signed),{accountNumber:`${K.toString()}`,authInfoBytes:new Uint8Array(Object.values(W.signed.authInfoBytes)),bodyBytes:new Uint8Array(Object.values(W.signed.bodyBytes))})}}),c=(p,I,b)=>l(void 0,null,function*(){return yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"signAmino",params:{chainId:p,signerAddress:I,signDoc:b}}}})}),f=p=>l(void 0,null,function*(){if(typeof fe[p]!="undefined")return fe[p];let I=yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"getKey",params:{chainId:p}}}});if(!I)throw new Error("No response from Metamask");return I.pubKey=Uint8Array.from(Object.values(I.pubkey)),delete I.pubkey,fe[p]=I,fe[p]}),A=p=>l(void 0,null,function*(){let I=yield f(p);return {address:I.bech32Address,algo:I.algo,pubkey:I.pubKey}}),d=(...p)=>l(void 0,null,function*(){let[I,b,W,D]=p;return yield c(I,b,W)}),S=(...p)=>l(void 0,null,function*(){let[I,b,W]=p;return yield a(I,b,W)}),m=p=>({getAccounts:()=>l(void 0,null,function*(){return [yield A(p)]}),signAmino:(I,b)=>d(p,I,b)});return {enable:s,experimentalSuggestChain:(...p)=>l(void 0,null,function*(){yield n(),yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"suggestChain",params:{chainInfo:p[0]}}}});}),getKey:f,getOfflineSigner:p=>({getAccounts:()=>l(void 0,null,function*(){return [yield A(p)]}),signDirect:(I,b)=>S(p,I,b),signAmino:(I,b)=>d(p,I,b)}),getOfflineSignerAuto:p=>l(void 0,null,function*(){return m(p)}),getOfflineSignerOnlyAmino:m,init:n,signAmino:d,signDirect:S}}throw u.getState()._notFoundFn(),new Error("window.ethereum is not defined")};var at=()=>st({id:"npm:@leapwallet/metamask-cosmos-snap"});var ge=()=>{var e;if(typeof((e=window.okxwallet)==null?void 0:e.keplr)!="undefined"){let t=window.okxwallet.keplr;return Object.assign(t,{subscription:n=>{var a;let s=()=>{_(),n();};return (a=window.okxwallet)==null||a.on("accountsChanged",s),()=>{var c;(c=window.okxwallet)==null||c.removeListener("accountsChanged",s);}},setDefaultOptions:n=>{t.defaultOptions=n;}})}throw u.getState()._notFoundFn(),new Error("window.okxwallet.keplr is not defined")};var ye=()=>{if(typeof window.station!="undefined"){let e=window.station.keplr;return {subscription:n=>{let s=()=>{_(),n();};return window.addEventListener("station_wallet_change",s),()=>{window.removeEventListener("station_wallet_change",s);}},getKey:n=>l(void 0,null,function*(){let s=yield e.getKey(n);return k({isKeystone:!1},s)}),getOfflineSigner:n=>{try{let s=e.getOfflineSignerOnlyAmino(n);return Object.assign(s,{signDirect:(f,A)=>{throw new Error("signDirect not supported by Station")}})}catch(s){throw console.error(s),s}},experimentalSuggestChain:n=>l(void 0,null,function*(){try{if(!n.bech32Config)throw new Error("Bech32Config is required");if(!n.stakeCurrency)throw new Error("StakeCurrency is required");let s=Object.assign(n,{bech32Config:n.bech32Config,chainSymbolImageUrl:n.chainSymbolImageUrl||"",stakeCurrency:{coinDecimals:n.stakeCurrency.coinDecimals,coinDenom:n.stakeCurrency.coinDenom,coinImageUrl:n.stakeCurrency.coinImageUrl||"",coinMinimalDenom:n.stakeCurrency.coinMinimalDenom},currencies:n.currencies.map(a=>({coinDecimals:a.coinDecimals,coinDenom:a.coinDenom,coinImageUrl:a.coinImageUrl||"",coinMinimalDenom:a.coinMinimalDenom})),feeCurrencies:n.feeCurrencies.map(a=>{var c,f,A;return {coinDecimals:a.coinDecimals,coinDenom:a.coinDenom,coinImageUrl:a.coinImageUrl||"",coinMinimalDenom:a.coinMinimalDenom,gasPriceStep:{average:((c=a.gasPriceStep)==null?void 0:c.average)||0,high:((f=a.gasPriceStep)==null?void 0:f.high)||0,low:((A=a.gasPriceStep)==null?void 0:A.low)||0}}})});yield e.experimentalSuggestChain(s);}catch(s){throw console.error(s),s}}),enable:n=>e.enable(n),disable:n=>e.disable(n),getOfflineSignerAuto:n=>e.getOfflineSignerAuto(n),getOfflineSignerOnlyAmino:n=>e.getOfflineSignerOnlyAmino(n),signDirect:()=>e.signDirect(),signAmino:(n,s,a,c)=>e.signAmino(n,s,a)}}throw u.getState()._notFoundFn(),new Error("window.station is not defined")};var Ce=()=>{if(typeof window.vectis!="undefined"){let e=window.vectis.cosmos;return {enable:a=>e.enable(a),getOfflineSigner:a=>e.getOfflineSigner(a),getOfflineSignerAuto:a=>e.getOfflineSignerAuto(a),getKey:a=>l(void 0,null,function*(){let c=yield e.getKey(a);return {address:encoding.fromBech32(c.address).data,algo:c.algo,bech32Address:c.address,name:c.name,pubKey:c.pubKey,isKeystone:!1,isNanoLedger:c.isNanoLedger}}),subscription:a=>{let c=()=>{_(),a();};return window.addEventListener("vectis_accountChanged",c),()=>{window.removeEventListener("vectis_accountChanged",c);}},getOfflineSignerOnlyAmino:(...a)=>{let c=a[0];return e.getOfflineSignerAmino(c)},experimentalSuggestChain:(...a)=>l(void 0,null,function*(){var A;let[c]=a;if(!c.bech32Config)throw new Error("Bech32Config is required");if(!c.stakeCurrency)throw new Error("StakeCurrency is required");let f={rpcUrl:c.rpc,restUrl:c.rest,prettyName:c.chainName.replace(" ",""),bech32Prefix:(A=c.bech32Config)==null?void 0:A.bech32PrefixAccAddr,currencies:c.currencies,feeCurrencies:c.feeCurrencies,chainId:c.chainId,chainName:c.chainName,bip44:c.bip44,stakeCurrency:c.stakeCurrency,features:c.features};return e.suggestChains([f])}),signDirect:(...a)=>l(void 0,null,function*(){var A;let{1:c,2:f}=a;return e.signDirect(c,{bodyBytes:f.bodyBytes||Uint8Array.from([]),authInfoBytes:f.authInfoBytes||Uint8Array.from([]),accountNumber:rn__default.default.fromString(((A=f.accountNumber)==null?void 0:A.toString())||"",!1),chainId:f.chainId||""})}),signAmino:(...a)=>l(void 0,null,function*(){let{1:c,2:f}=a;return e.signAmino(c,f)})}}throw u.getState()._notFoundFn(),new Error("window.vectis is not defined")};var z=()=>{if(typeof window!="undefined"){let e=navigator.userAgent;return !!(/android/i.test(e)||/iPad|iPhone|iPod/.test(e))}return !1},ct=()=>z()&&navigator.userAgent.toLowerCase().includes("android"),lt=()=>z()&&(navigator.userAgent.toLowerCase().includes("iphone")||navigator.userAgent.toLowerCase().includes("ipad"));var xe=(e,t,i=new Error("Promise timed out"))=>{let o=new Promise((r,n)=>{setTimeout(()=>{n(i);},t);});return Promise.race([e,o])};var Q=e=>{var K,Z,oe;if(!((oe=(Z=(K=u.getState().walletConnect)==null?void 0:K.options)==null?void 0:Z.projectId)!=null&&oe.trim()))throw new Error("walletConnect.options.projectId is not defined");let t=(e==null?void 0:e.walletType)||"walletconnect",i=(e==null?void 0:e.encoding)||"base64",o=w=>{if(!e)return;let{appUrl:O,formatNativeUrl:E}=e;if(z()){if(ct())if(!w)window.open(O.mobile.android,"_self","noreferrer noopener");else {let x=E(O.mobile.android,w,"android");window.open(x,"_self","noreferrer noopener");}if(lt())if(!w)window.open(O.mobile.ios,"_self","noreferrer noopener");else {let x=E(O.mobile.ios,w,"ios");window.open(x,"_self","noreferrer noopener");}}},r=()=>{let{wcSignClients:w}=g.getState();if(!w.get(t))throw new Error("walletConnect.signClient is not defined");w.delete(t),g.setState({wcSignClients:w}),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null});},n=w=>l(void 0,null,function*(){let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");if(!w)throw new Error("No wallet connect session");yield E.disconnect({topic:w,reason:utils.getSdkError("USER_DISCONNECTED")}),yield c(E);}),s=w=>{try{let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");let x=E.session.getAll(),v=x.at(-1);if(!v)return;if(!(v.expiry*1e3>Date.now()+1e3))throw n(v.topic),new Error("invalid session");try{let U=x.find(j=>{var $,ee;return (ee=($=j.requiredNamespaces.cosmos)==null?void 0:$.chains)==null?void 0:ee.includes(`cosmos:${w}`)});if(!U)throw new Error("no session");return U}catch(U){if(!U.message.toLowerCase().includes("no matching key"))throw U}return v}catch(O){if(!O.message.toLowerCase().includes("no matching key"))throw O}},a=w=>{try{return s(w)}catch(O){return}},c=w=>l(void 0,null,function*(){try{let O=w.core.pairing.pairings.getAll({active:!1});if(!O.length)return;yield Promise.all(O.map(E=>l(void 0,null,function*(){yield w.core.pairing.pairings.delete(E.topic,{code:7001,message:"clear pairing"});})));}catch(O){if(!O.message.toLowerCase().includes("no matching key"))throw O}}),f=()=>l(void 0,null,function*(){let{walletConnect:w}=u.getState();if(!(w!=null&&w.options))throw new Error("walletConnect.options is not defined");let{wcSignClients:O}=g.getState(),E=O.get(t);if(E)return E;let x=yield signClient.SignClient.init(w.options);return O.set(t,x),g.setState({wcSignClients:O}),x}),A=w=>{let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)return ()=>{};let x=v=>{let P=g.getState().accounts;v.params.event.name==="accountsChanged"&&P&&!Object.values(P).map(U=>U.bech32Address).includes(v.params.event.data[0])&&w();};return E.events.on("session_delete",r),E.events.on("session_expire",r),E.events.on("session_event",x),()=>{E.events.off("session_delete",r),E.events.off("session_expire",r),E.events.off("session_event",x);}},d=w=>l(void 0,null,function*(){var ee;let O=typeof w=="string"?[w]:w,{wcSignClients:E,activeChainIds:x}=g.getState(),v=E.get(t);if(!v)throw new Error("enable walletConnect.signClient is not defined");let{walletConnect:P,chains:U}=u.getState();if(!((ee=P==null?void 0:P.options)!=null&&ee.projectId))throw new Error("walletConnect.options.projectId is not defined");let j=new modal.WalletConnectModal(k({projectId:P.options.projectId,enableExplorer:!1,explorerRecommendedWalletIds:"NONE"},P.walletConnectModal)),$=a(O);if(!$){let{uri:q,approval:te}=yield xe(v.connect({requiredNamespaces:{cosmos:{methods:["cosmos_getAccounts","cosmos_signAmino","cosmos_signDirect"],chains:O.map(H=>`cosmos:${H}`),events:["chainChanged","accountsChanged"]}}}),15e3,new Error("Connection timeout"));if(!q)throw new Error("No wallet connect uri");e?o(q):yield j.openModal({uri:q});let se=H=>l(void 0,null,function*(){return H.aborted?Promise.reject(new Error("User closed wallet connect")):new Promise((Me,ne)=>{te().then(Ue=>{let qe=Ue.sessionProperties;if(!qe)return ne(new Error("No session properties"));let ke=JSON.parse(String(qe.keys));if(ke.length===0)return ne(new Error("No accounts"));if(!ke[0])return ne(new Error("No accounts"));let Fe={};return ke.forEach(V=>{Fe[V.chainId]={address:V.address,algo:V.algo,bech32Address:V.bech32Address,isNanoLedger:V.isNanoLedger,isKeystone:V.isKeystone,name:V.name,pubKey:V.pubKey};}),g.setState(V=>({accounts:k(k({},V.accounts||{}),Fe)})),Me(Ue)}).catch(ne),H.addEventListener("abort",()=>{ne(new Error("User closed wallet connect"));},{once:!0});})});try{let H=new AbortController,Me=H.signal;j.subscribeModal(ne=>{ne.open||H.abort();}),yield se(Me);}catch(H){if(j.closeModal(),!H.message.toLowerCase().includes("no matching key"))return Promise.reject(H)}return e||j.closeModal(),Promise.resolve()}try{yield xe((()=>l(void 0,null,function*(){var te;let q=Object.fromEntries(yield Promise.all((te=x||O)==null?void 0:te.map(se=>l(void 0,null,function*(){return [se,yield y(se)]}))));g.setState({accounts:q});}))(),15e3,new Error("Connection timeout"));}catch(q){if(n($.topic),!q.message.toLowerCase().includes("no matching key"))throw q}}),S=w=>l(void 0,null,function*(){var P;let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");let x=(P=s([w]))==null?void 0:P.topic;if(!x)throw new Error("No wallet connect session");let v=yield E.request({topic:x,chainId:`cosmos:${w}`,request:{method:"cosmos_getAccounts",params:{}}});if(!v[0])throw new Error("No wallet connect account");return {address:v[0].address,algo:v[0].algo,pubkey:new Uint8Array(Buffer.from(v[0].pubkey,i))}}),y=w=>l(void 0,null,function*(){let O=s([w]);if(!(O!=null&&O.topic))throw new Error("No wallet connect session");let E=O.sessionProperties&&JSON.parse(String(O.sessionProperties.keys));if(!E)throw new Error("No wallet connect key");if(E.length===0)throw new Error("No wallet connect session");let x=E.find(v=>v.chainId===w);if(!x)throw new Error(`No wallet connect key for chainId ${w}`);return x}),m=(...w)=>l(void 0,null,function*(){var q,te;let[O,E,x]=w,{accounts:v,wcSignClients:P}=g.getState(),U=P.get(t);if(!U)throw new Error("walletConnect.signClient is not defined");if(!v)throw new Error("account is not defined");let j=(q=s([O]))==null?void 0:q.topic;if(!j)throw new Error("No wallet connect session");if(!x.bodyBytes)throw new Error("No bodyBytes");if(!x.authInfoBytes)throw new Error("No authInfoBytes");let $={topic:j,chainId:`cosmos:${O}`,request:{method:"cosmos_signDirect",params:{signerAddress:E,signDoc:F(k({},x),{bodyBytes:Buffer.from(x.bodyBytes).toString(i),authInfoBytes:Buffer.from(x.authInfoBytes).toString(i),accountNumber:(te=x.accountNumber)==null?void 0:te.toString()})}}};return o(),yield U.request($)}),C=(...w)=>l(void 0,null,function*(){let[O,E,x]=w,{signature:v,signed:P}=yield m(O,E,x);return {signed:{chainId:P.chainId,accountNumber:rn__default.default.fromString(P.accountNumber,!1),authInfoBytes:new Uint8Array(Buffer.from(P.authInfoBytes,i)),bodyBytes:new Uint8Array(Buffer.from(P.bodyBytes,i))},signature:v}}),h=(...w)=>l(void 0,null,function*(){var q;let[O,E,x,v]=w,{wcSignClients:P}=g.getState(),U=P.get(t),{accounts:j}=g.getState();if(!U)throw new Error("walletConnect.signClient is not defined");if(!j)throw new Error("account is not defined");let $=(q=s([O]))==null?void 0:q.topic;if(!$)throw new Error("No wallet connect session");return o(),yield U.request({topic:$,chainId:`cosmos:${O}`,request:{method:"cosmos_signDirect",params:{signerAddress:E,signDoc:x}}})}),M=(...w)=>l(void 0,null,function*(){let[O,E,x,v]=w;return yield h(O,E,x)}),p=w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signDirect:(O,E)=>C(w,O,E)}),I=w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signAmino:(O,E)=>M(w,O,E)});return {enable:d,disable:w=>l(void 0,null,function*(){var x;let{wcSignClients:O}=g.getState(),E=O.get(t);if(w===void 0){let v=E==null?void 0:E.session.getAll();v!==void 0&&(yield Promise.all(v.map(P=>n(P.topic))));}else typeof w=="string"?yield n((x=s([w]))==null?void 0:x.topic):yield Promise.all(w.map(v=>{var P;return n((P=s([v]))==null?void 0:P.topic)}));(E==null?void 0:E.session.getAll().length)===0&&r();}),experimentalSuggestChain:(...w)=>l(void 0,null,function*(){yield Promise.reject(new Error("WalletConnect does not support experimentalSuggestChain"));}),getKey:y,getOfflineSigner:w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signDirect:(O,E)=>C(w,O,E),signAmino:(O,E)=>M(w,O,E)}),getOfflineSignerAuto:w=>l(void 0,null,function*(){return (yield y(w)).isNanoLedger?I(w):p(w)}),getOfflineSignerOnlyAmino:I,signAmino:M,signDirect:C,subscription:A,init:f}};var ut=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!z())throw new Error("WalletConnect Clot mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{android:"clot://",ios:"clot://"}},walletType:"wc_clot_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;default:return `${a}://wc?uri=${c}`}}};return Q(e)};var pt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!z())throw new Error("WalletConnect Cosmostation mobile is only supported in mobile");let e={encoding:"hex",appUrl:{mobile:{ios:"cosmostation://",android:"cosmostation://"}},walletType:"wc_cosmostation_mobile",formatNativeUrl:(r,n,s)=>`${r.replaceAll("/","").replaceAll(":","")}://wc?${n}`};return Q(e)};var mt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!z())throw new Error("WalletConnect Keplr mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{ios:"keplrwallet://",android:"intent://"}},walletType:"wc_keplr_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;case"android":return `${a}://wcV2?${c}#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;`;default:return `${a}://wc?uri=${c}`}}};return Q(e)};var dt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!z())throw new Error("WalletConnect Leap mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{ios:"leapcosmos://",android:"intent://"}},walletType:"wc_leap_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;case"android":return `${a}://wcV2?${c}#Intent;package=io.leapwallet.cosmos;scheme=leapwallet;end;`;default:return `${a}://wc?uri=${c}`}}};return Q(e)};var Se=()=>{var e;if(typeof((e=window.xfi)==null?void 0:e.keplr)!="undefined"){let t=window.xfi.keplr;return Object.assign(t,{subscription:r=>{let n=()=>{_(),r();};return window.addEventListener("keplr_keystorechange",n),()=>{window.removeEventListener("keplr_keystorechange",n);}}})}throw u.getState()._notFoundFn(),new Error("window.xfi.keplr is not defined")};var N=(e=u.getState().walletType)=>{try{return R(e),!0}catch(t){return !1}},_=()=>{window.sessionStorage.removeItem(X),g.setState(ie);},R=(e=u.getState().walletType)=>{var o;let t=(()=>{switch(e){case"keplr":return me();case"leap":return de();case"cosmostation":return pe();case"vectis":return Ce();case"walletconnect":return Q();case"wc_keplr_mobile":return mt();case"wc_leap_mobile":return dt();case"wc_cosmostation_mobile":return pt();case"wc_clot_mobile":return ut();case"metamask_snap_leap":return at();case"metamask_snap_cosmos":return it();case"station":return ye();case"xdefi":return Se();case"capsule":return ce();case"cosmiframe":return ue();case"compass":return le();case"initia":return rt();case"okx":return ge();default:throw new Error("Unknown wallet type")}})(),i=u.getState().walletDefaultOptions;return i&&((o=t.setDefaultOptions)==null||o.call(t,i)),t},or=()=>Object.fromEntries(He.map(e=>[e,N(e)])),ve=e=>e==="capsule",ft=e=>e==="walletconnect"||e==="wc_keplr_mobile"||e==="wc_leap_mobile"||e==="wc_cosmostation_mobile";var Y=e=>l(void 0,null,function*(){var t;try{let{recentChainIds:i,chains:o,walletType:r}=u.getState(),n=(e==null?void 0:e.walletType)||r;if(!N(n))throw new Error(`${n} is not available`);let a=R(n),c=typeof(e==null?void 0:e.chainId)=="string"?[e.chainId]:(e==null?void 0:e.chainId)||i;if(!c)throw new Error("No last known connected chain, connect action requires chain ids");let f=o==null?void 0:o.map(y=>y.chainId);c.forEach(y=>{if(!(f!=null&&f.includes(y)))throw new Error(`Chain ${y} is not provided in GrazProvider`)}),g.setState(y=>{let m=u.getState()._reconnect||!!u.getState()._reconnectConnector||!!c;return y.activeChainIds&&c.filter(h=>{var M;return !((M=y.activeChainIds)!=null&&M.includes(h))}).length>0?{status:"connecting"}:m?{status:"reconnecting"}:{status:"connecting"}});let{accounts:A}=g.getState();if(yield (t=a.init)==null?void 0:t.call(a),ve(n)&&g.getState().capsuleClient&&Object.values(g.getState().accounts||[]).length>0){let y=c.map(h=>o.find(M=>M.chainId===h)),m=g.getState().accounts;g.setState({status:"connecting"});let C=Object.fromEntries(yield Promise.all(c.map(h=>l(void 0,null,function*(){return [h,yield a.getKey(h)]}))));return g.setState(h=>({accounts:k(k({},h.accounts||{}),C)})),u.setState(h=>({recentChainIds:[...h.recentChainIds||[],...c].filter((M,p,I)=>I.indexOf(M)===p)})),g.setState(h=>({activeChainIds:[...h.activeChainIds||[],...c].filter((M,p,I)=>I.indexOf(M)===p)})),g.setState({status:"connected"}),{accounts:m,walletType:n,chains:y}}if(yield a.enable(c),ve(n)){let y=c.map(C=>o.find(h=>h.chainId===C)),m=g.getState().accounts;return g.setState({status:"connecting"}),{accounts:m,walletType:n,chains:y}}if(!ft(n)){let y=Object.fromEntries(yield Promise.all(c.map(m=>l(void 0,null,function*(){return [m,yield a.getKey(m)]}))));g.setState(m=>({accounts:k(k({},m.accounts||{}),y)}));}u.setState(y=>({recentChainIds:[...y.recentChainIds||[],...c].filter((m,C,h)=>h.indexOf(m)===C)})),g.setState(y=>({activeChainIds:[...y.activeChainIds||[],...c].filter((m,C,h)=>h.indexOf(m)===C)})),u.setState({walletType:n,_reconnect:!!(e!=null&&e.autoReconnect),_reconnectConnector:n}),g.setState({status:"connected"}),typeof window!="undefined"&&window.sessionStorage.setItem(X,"Active");let d=c.map(y=>o.find(m=>m.chainId===y));return {accounts:g.getState().accounts,walletType:n,chains:d}}catch(i){throw console.error("connect ",i),g.getState().accounts===null&&g.setState({status:"disconnected"}),g.getState().accounts&&g.getState().activeChainIds&&g.setState({status:"connected"}),i}}),re=e=>{typeof window!="undefined"&&window.sessionStorage.removeItem(X);let t=typeof(e==null?void 0:e.chainId)=="string"?[e.chainId]:e==null?void 0:e.chainId;if(t){let i=g.getState().accounts;t.forEach(r=>{i==null||delete i[r];}),Object.values(i||{}).length===0?(g.setState(ie),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null})):(g.setState(r=>{var n;return {activeChainIds:(n=r.activeChainIds)==null?void 0:n.filter(s=>!t.includes(s)),accounts:i}}),u.setState(r=>{var n;return {recentChainIds:(n=r.recentChainIds)==null?void 0:n.filter(s=>!t.includes(s))}}));}else g.setState(ie),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null});return Promise.resolve()},B=e=>l(void 0,null,function*(){var r;let{recentChainIds:t,_reconnectConnector:i,_reconnect:o}=u.getState();try{let n=N(i||void 0);if(t&&n&&i)return yield Y({chainId:t,walletType:i,autoReconnect:o})}catch(n){(r=e==null?void 0:e.onError)==null||r.call(e,n),re();}}),gt=e=>l(void 0,null,function*(){if(!(e!=null&&e.chainId))throw new Error("chainId is required");let{walletType:t}=u.getState(),i=e.walletType||t;if(!N(i))throw new Error(`${i} is not available`);let r=R(i),n=r.getOfflineSigner(e.chainId),s=r.getOfflineSignerOnlyAmino(e.chainId),a=yield r.getOfflineSignerAuto(e.chainId);return {offlineSigner:n,offlineSignerAmino:s,offlineSignerAuto:a}});var Pe=()=>{u.setState({recentChainIds:null});},yr=()=>u.getState().recentChainIds,Cr=()=>{var i;let{recentChainIds:e,chains:t}=u.getState();return (i=e==null?void 0:e.map(o=>t.find(r=>r.chainId===o)))!=null?i:null},Sr=({chainId:e})=>{var t;return (t=u.getState().chains)==null?void 0:t.find(i=>i.chainId===e)},hr=({chainId:e})=>{var t;return (t=u.getState().chains)==null?void 0:t.filter(i=>e==null?void 0:e.includes(i.chainId))},We=i=>l(void 0,[i],function*({chainInfo:e,walletType:t}){let o=R(t);return t==="capsule"?yield Y({chainId:e.chainId,walletType:t}):yield o.experimentalSuggestChain(e),e}),yt=e=>l(void 0,null,function*(){var o;let t=u.getState().walletType;return yield We({chainInfo:e.chainInfo,walletType:(o=e.walletType)!=null?o:t}),yield Y({chainId:e.chainInfo.chainId,walletType:e.walletType,autoReconnect:e.autoReconnect})});var Ct=e=>(u.setState(t=>({iframeOptions:e.iframeOptions||t.iframeOptions,walletConnect:e.walletConnect||t.walletConnect,walletType:e.defaultWallet||t.walletType,capsuleConfig:e.capsuleConfig||t.capsuleConfig,walletDefaultOptions:e.walletDefaultOptions||t.walletDefaultOptions,chains:e.chains,chainsConfig:e.chainsConfig||t.chainsConfig,multiChainFetchConcurrency:e.multiChainFetchConcurrency||t.multiChainFetchConcurrency,_notFoundFn:e.onNotFound||t._notFoundFn,_onReconnectFailed:e.onReconnectFailed||t._onReconnectFailed,_reconnect:e.autoReconnect===void 0?!0:e.autoReconnect||t._reconnect})),e);var St=s=>l(void 0,[s],function*({signingClient:e,senderAddress:t,recipientAddress:i,amount:o,fee:r,memo:n}){if(!e)throw new Error("No connected account detected");if(!t)throw new Error("senderAddress is not defined");return e.sendTokens(t,i,o,r,n)}),ht=A=>l(void 0,[A],function*({signingClient:e,senderAddress:t,recipientAddress:i,transferAmount:o,sourcePort:r,sourceChannel:n,timeoutHeight:s,timeoutTimestamp:a,fee:c,memo:f}){if(!e)throw new Error("Stargate signing client is not ready");if(!t)throw new Error("senderAddress is not defined");return e.sendIbcTokens(t,i,o,r,n,s,a,c,f)}),wt=a=>l(void 0,[a],function*({signingClient:e,senderAddress:t,msg:i,fee:o,options:r,label:n,codeId:s}){if(!e)throw new Error("CosmWasm signing client is not ready");return e.instantiate(t,s,i,n,o,r)}),At=a=>l(void 0,[a],function*({signingClient:e,senderAddress:t,msg:i,fee:o,contractAddress:r,funds:n,memo:s}){if(!e)throw new Error("CosmWasm signing client is not ready");return e.execute(t,r,i,o,s,n)}),It=(e,t,i)=>l(void 0,null,function*(){if(!i)throw new Error("CosmWasm client is not ready");return yield i.queryContractSmart(e,t)}),Ot=(e,t,i)=>{if(!i)throw new Error("CosmWasm client is not ready");let o=new TextEncoder().encode(t);return i.queryContractRaw(e,o)};var xr=e=>e,vr=e=>e;var he=e=>e?Object.keys(e).length===0:!0;var Re=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t;}},Et=e=>globalThis.DOMException===void 0?new Re(e):new DOMException(e),bt=e=>{let t=e.reason===void 0?Et("This operation was aborted."):e.reason;return t instanceof Error?t:Et(t)};function De(n,s){return l(this,arguments,function*(e,t,{concurrency:i=Number.POSITIVE_INFINITY,stopOnError:o=!0,signal:r}={}){return new Promise((a,c)=>{if(e[Symbol.iterator]===void 0&&e[Symbol.asyncIterator]===void 0)throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof e})`);if(typeof t!="function")throw new TypeError("Mapper function is required");if(!((Number.isSafeInteger(i)||i===Number.POSITIVE_INFINITY)&&i>=1))throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${i}\` (${typeof i})`);let f=[],A=[],d=new Map,S=!1,y=!1,m=!1,C=0,h=0,M=e[Symbol.iterator]===void 0?e[Symbol.asyncIterator]():e[Symbol.iterator](),p=b=>{S=!0,y=!0,c(b);};r&&(r.aborted&&p(bt(r)),r.addEventListener("abort",()=>{p(bt(r));}));let I=()=>l(this,null,function*(){if(y)return;let b=yield M.next(),W=h;if(h++,b.done){if(m=!0,C===0&&!y){if(!o&&A.length>0){p(new AggregateError(A));return}if(y=!0,d.size===0){a(f);return}let D=[];for(let[K,Z]of f.entries())d.get(K)!==Tt&&D.push(Z);a(D);}return}C++,l(this,null,function*(){try{let D=yield b.value;if(y)return;let K=yield t(D,W);K===Tt&&d.set(W,K),f[W]=K,C--,yield I();}catch(D){if(o)p(D);else {A.push(D),C--;try{yield I();}catch(K){p(K);}}}});});l(this,null,function*(){for(let b=0;b<i;b++){try{yield I();}catch(W){p(W);break}if(m||S)break}});})})}var Tt=Symbol("skip");var L=({chainId:e,multiChain:t})=>{let i=u(r=>r.chains);if(!i)throw new Error("No chains found in GrazProvider");let o=typeof e=="string"?[e]:e;switch(!0){case(!!t&&!!o):return o.map(r=>i.find(n=>n.chainId===r)).filter(Boolean);case(!t&&!!o):return [o.map(r=>i.find(n=>n.chainId===r)).filter(Boolean)[0]];case(!!t&&!o):return i;default:return [i[0]]}},G=(e,t,i)=>l(void 0,null,function*(){let o=u.getState().multiChainFetchConcurrency;if(e){let n=yield De(t,i,{concurrency:o});return Object.fromEntries(n.map((s,a)=>[t[a].chainId,s]))}return yield i(t[0])}),Mt=(e,t,i)=>{if(e){let r=t.map(i);return Object.fromEntries(r.map((n,s)=>[t[s].chainId,n]))}return i(t[0])};var Ne=e=>{let t=L({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=react.useMemo(()=>["USE_STARGATE_CLIENT",t],[t]);return reactQuery.useQuery({queryKey:i,queryFn:r=>l(void 0,[r],function*({queryKey:[,o]}){if(o.length<1)throw new Error("No chains found");return yield G(!!(e!=null&&e.multiChain),o,s=>l(void 0,null,function*(){var A;let a=(A=u.getState().chainsConfig)==null?void 0:A[s.chainId],c={url:s.rpc,headers:k({},(a==null?void 0:a.rpcHeaders)||{})};return yield stargate.StargateClient.connect(c)}))}),enabled:!!t&&t.length>0&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})},Be=e=>{let t=L({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=react.useMemo(()=>["USE_COSMWASM_CLIENT",t],[t]);return reactQuery.useQuery({queryKey:i,queryFn:r=>l(void 0,[r],function*({queryKey:[,o]}){if(o.length<1)throw new Error("No chains found");return yield G(!!(e!=null&&e.multiChain),o,s=>l(void 0,null,function*(){var A;let a=(A=u.getState().chainsConfig)==null?void 0:A[s.chainId],c={url:s.rpc,headers:k({},(a==null?void 0:a.rpcHeaders)||{})};return yield cosmwasmStargate.CosmWasmClient.connect(c)}))}),enabled:!!t&&t.length>0&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})},we=({type:e,chainId:t,multiChain:i,enabled:o})=>{let r=L({chainId:t,multiChain:i}),n=react.useMemo(()=>["USE_TENDERMINT_CLIENT",e,r],[e,r]);return reactQuery.useQuery({queryKey:n,queryFn:c=>l(void 0,[c],function*({queryKey:[,s,a]}){if(a.length<1)throw new Error("No chains found");return yield G(!!i,a,A=>l(void 0,null,function*(){var C;let d=(C=u.getState().chainsConfig)==null?void 0:C[A.chainId],S={url:A.rpc,headers:k({},(d==null?void 0:d.rpcHeaders)||{})};return yield (s==="tm37"?tendermintRpc.Tendermint37Client:tendermintRpc.Tendermint34Client).connect(S)}))}),enabled:!!r&&r.length>0&&(o!==void 0?!!o:!0),refetchOnWindowFocus:!1})};var is=()=>u(e=>({walletType:e.walletType,isCosmostation:e.walletType==="cosmostation",isCosmostationMobile:e.walletType==="wc_cosmostation_mobile",isKeplr:e.walletType==="keplr",isKeplrMobile:e.walletType==="wc_keplr_mobile",isLeap:e.walletType==="leap",isLeapMobile:e.walletType==="wc_leap_mobile",isVectis:e.walletType==="vectis",isWalletConnect:e.walletType==="walletconnect",isMetamaskSnapLeap:e.walletType==="metamask_snap_leap",isStation:e.walletType==="station",isCapsule:e.walletType==="capsule",isCosmiframe:e.walletType==="cosmiframe"}),shallow.shallow),Ae=e=>{let i=["USE_CHECK_WALLET",u(r=>e||r.walletType)];return reactQuery.useQuery(i,({queryKey:[,r]})=>N(r))};var J=e=>{let t=u(a=>a.walletType),i=g(a=>a.activeChainIds),o=L({chainId:e!=null&&e.chainId?e.chainId:i||void 0,multiChain:e==null?void 0:e.multiChain}),r=g(a=>a.accounts),n=g(a=>a.status);return react.useEffect(()=>g.subscribe(a=>a.status,(a,c)=>{var f,A,d;if(a==="connected"){let{accounts:S,activeChainIds:y}=g.getState(),{chains:m}=u.getState(),{walletType:C}=u.getState();if(!S||!y||!m)return (f=e==null?void 0:e.onDisconnect)==null?void 0:f.call(e);(A=e==null?void 0:e.onConnect)==null||A.call(e,{accounts:S,chains:y.map(h=>m.find(M=>M.chainId===h)),walletType:C,isReconnect:c==="reconnecting"});}a==="disconnected"&&((d=e==null?void 0:e.onDisconnect)==null||d.call(e));}),[e]),{data:react.useMemo(()=>r?Mt(!!(e!=null&&e.multiChain),o,a=>r[a.chainId]):void 0,[r,o,e==null?void 0:e.multiChain]),isConnected:n==="connected",isConnecting:n==="connecting",isDisconnected:n==="disconnected",isReconnecting:n==="reconnecting",isLoading:n==="connecting"||n==="reconnecting",walletType:n==="connected"?t:void 0,reconnect:B,status:n}},hn=e=>{let t=L({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),{data:i}=J(),o=(e==null?void 0:e.bech32Address)||(i==null?void 0:i.bech32Address),{data:r}=Ne({chainId:t.map(s=>s.chainId),multiChain:!0,enabled:((e==null?void 0:e.enabled)===void 0?!0:e.enabled)&&!!o}),n=react.useMemo(()=>["USE_ALL_BALANCES",r,t,o,e==null?void 0:e.chainId],[o,e==null?void 0:e.chainId,t,r]);return reactQuery.useQuery(n,f=>l(void 0,[f],function*({queryKey:[,s,a,c]}){if(!c)throw new Error("address is not defined");return yield G(!!(e!=null&&e.multiChain),a,d=>l(void 0,null,function*(){var m;let S=s==null?void 0:s[d.chainId];if(!S)throw new Error(`Client is not ready ${d.chainId}`);if(!((m=d.bech32Config)!=null&&m.bech32PrefixAccAddr))throw new Error(`Bech32Config is missing ${d.chainId}`);return yield S.getAllBalances(encoding.toBech32(d.bech32Config.bech32PrefixAccAddr,encoding.fromBech32(c).data))}))}),{enabled:!!o&&!!t&&t.length>0&&!he(r)&&((e==null?void 0:e.enabled)===void 0?!0:e.enabled),refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!1})},ys=e=>{let t=L({chainId:e.chainId}),{data:i}=J({chainId:e.chainId}),o=e.bech32Address||(i==null?void 0:i.bech32Address),{data:r,refetch:n}=hn({chainId:t.map(c=>c.chainId),bech32Address:o,enabled:!!o&&(e.enabled===void 0?!0:e.enabled)}),s=["USE_BALANCE",e.denom,r,t,o,e.chainId],a=reactQuery.useQuery(s,({queryKey:[,c,f]})=>f==null?void 0:f.find(A=>A.denom===c),{enabled:!!e.denom&&!!r&&!!(r!=null&&r.length)&&(e.enabled===void 0?!0:e.enabled)});return F(k({},a),{refetch:c=>l(void 0,null,function*(){return yield n(),a.refetch(c)})})},Cs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=reactQuery.useMutation(["USE_CONNECT",e,t,i],Y,{onError:(s,a)=>e==null?void 0:e(s,a),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))}),{data:n}=Ae();return {connect:s=>r.mutate(s),connectAsync:s=>r.mutateAsync(s),error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,isSupported:!!n,status:r.status}},Ss=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=reactQuery.useMutation(["USE_DISCONNECT",e,t,i],re,{onError:n=>Promise.resolve(e==null?void 0:e(n,void 0)),onMutate:t,onSuccess:()=>Promise.resolve(i==null?void 0:i(void 0))});return {disconnect:n=>r.mutate(n),disconnectAsync:n=>r.mutateAsync(n),error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,status:r.status}},hs=e=>{let t=L({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(r=>r.walletType),o=react.useMemo(()=>["USE_OFFLINE_SIGNERS",t,i],[t,i]);return reactQuery.useQuery({queryKey:o,queryFn:s=>l(void 0,[s],function*({queryKey:[,r,n]}){if(r.length<1)throw new Error("No chain found");if(!N(n))throw new Error(`${n} is not available`);return yield G(!!(e!=null&&e.multiChain),r,f=>l(void 0,null,function*(){return yield gt({chainId:f.chainId,walletType:n})}))}),enabled:!!t&&t.length>0&&!!i,refetchOnWindowFocus:!1})},ws=e=>{let t=L({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),{data:i}=J(),{data:o}=Ne({chainId:t.map(s=>s.chainId),multiChain:!0}),r=(e==null?void 0:e.bech32Address)||(i==null?void 0:i.bech32Address),n=react.useMemo(()=>["USE_BALANCE_STAKED",o,t,r],[t,r,o]);return reactQuery.useQuery(n,f=>l(void 0,[f],function*({queryKey:[,s,a,c]}){if(!c)throw new Error("address is not defined");return yield G(!!(e!=null&&e.multiChain),a,d=>l(void 0,null,function*(){var y,m;if(!s)throw new Error("Client is not ready");if(!((y=d.bech32Config)!=null&&y.bech32PrefixAccAddr))throw new Error(`Bech32Config is missing ${d.chainId}`);return yield (m=s[d.chainId])==null?void 0:m.getBalanceStaked(encoding.toBech32(d.bech32Config.bech32PrefixAccAddr,encoding.fromBech32(c).data))}))}),{enabled:!!r&&!!t&&t.length>0&&!!o,refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!1})};var Ms=()=>{let e=u(o=>o.capsuleState),t=g(o=>o.capsuleClient),i=ce();return {setModalState:o=>{u.setState(r=>{var n;return {capsuleState:{showModal:o,chainId:(n=r.capsuleState)==null?void 0:n.chainId}}});},modalState:!!(e!=null&&e.showModal),client:t,onAfterLoginSuccessful:i.onAfterLoginSuccessful,onLoginFailure:()=>{re();}}};var Ds=()=>g(e=>e.activeChainIds),wn=()=>{var e;return (e=g(t=>t.activeChainIds))==null?void 0:e.map(t=>{var o;let i=(o=u.getState().chains)==null?void 0:o.find(r=>r.chainId===t);if(i)return i}).filter(Boolean)},Ks=({chainId:e})=>{var t;return (t=u().chains)==null?void 0:t.find(i=>i.chainId===e)},_s=({chainId:e})=>{var t;return (t=u().chains)==null?void 0:t.filter(i=>e==null?void 0:e.includes(i.chainId))},Ns=({denom:e})=>{let t=wn();return reactQuery.useQuery(["USE_ACTIVE_CHAIN_CURRENCY",e],({queryKey:[,r]})=>{var n;return (n=t==null?void 0:t.find(s=>s.currencies.find(a=>a.coinMinimalDenom===r)))==null?void 0:n.currencies.find(s=>s)})},Bs=e=>{var r;let t=(r=e.status)!=null?r:"BOND_STATUS_BONDED",i=["USE_ACTIVE_CHAIN_VALIDATORS",e.queryClient,t];return reactQuery.useQuery(i,a=>l(void 0,[a],function*({queryKey:[,n,s]}){if(!n)throw new Error("Query client is not defined");return yield n.staking.validators(s)}),{enabled:typeof e.queryClient!="undefined"})},Ls=()=>({data:u(t=>t.recentChainIds),clear:Pe}),Us=()=>{var t;return {data:(t=u(i=>i.recentChainIds))==null?void 0:t.map(i=>{var r;let o=(r=u.getState().chains)==null?void 0:r.find(n=>n.chainId===i);if(o)return o}).filter(Boolean),clear:Pe}},qs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=reactQuery.useMutation(["USE_SUGGEST_CHAIN",e,t,i],We,{onError:(n,s)=>Promise.resolve(e==null?void 0:e(n,s.chainInfo)),onMutate:n=>t==null?void 0:t(n.chainInfo),onSuccess:n=>Promise.resolve(i==null?void 0:i(n))});return {error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,suggest:r.mutate,suggestAsync:r.mutateAsync,status:r.status}},Fs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=reactQuery.useMutation(["USE_SUGGEST_CHAIN_AND_CONNECT",e,t,i],yt,{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:s=>t==null?void 0:t(s),onSuccess:s=>Promise.resolve(i==null?void 0:i(s))}),{data:n}=Ae();return {error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,isSupported:!!n,status:r.status,suggestAndConnect:r.mutate,suggestAndConnectAsync:r.mutateAsync}};var Xs=({onError:e,onLoading:t,onSuccess:i}={})=>{let{data:o}=J(),r=o==null?void 0:o.bech32Address,n=reactQuery.useMutation(["USE_SEND_TOKENS",e,t,i,r],s=>St(k({senderAddress:r},s)),{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))});return {error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,sendTokens:n.mutate,sendTokensAsync:n.mutateAsync,status:n.status}},Ys=({onError:e,onLoading:t,onSuccess:i}={})=>{let{data:o}=J(),r=o==null?void 0:o.bech32Address,n=reactQuery.useMutation(["USE_SEND_IBC_TOKENS",e,t,i,r],s=>ht(k({senderAddress:r},s)),{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))});return {error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,sendIbcTokens:n.mutate,sendIbcTokensAsync:n.mutateAsync,status:n.status}},Js=({codeId:e,onError:t,onLoading:i,onSuccess:o})=>{let{data:r}=J(),n=r==null?void 0:r.bech32Address,a=reactQuery.useMutation(["USE_INSTANTIATE_CONTRACT",t,i,o,e,n],c=>{var A;if(!n)throw new Error("senderAddress is undefined");let f=F(k({},c),{fee:(A=c.fee)!=null?A:"auto",senderAddress:n,codeId:e});return wt(f)},{onError:(c,f)=>Promise.resolve(t==null?void 0:t(c,f)),onMutate:i,onSuccess:c=>Promise.resolve(o==null?void 0:o(c))});return {error:a.error,isLoading:a.isLoading,isSuccess:a.isSuccess,instantiateContract:a.mutate,instantiateContractAsync:a.mutateAsync,status:a.status}},Zs=({contractAddress:e,onError:t,onLoading:i,onSuccess:o})=>{let{data:r}=J(),n=r==null?void 0:r.bech32Address,a=reactQuery.useMutation(["USE_EXECUTE_CONTRACT",t,i,o,e,n],c=>{var A,d,S;if(!n)throw new Error("senderAddress is undefined");let f=F(k({},c),{fee:(A=c.fee)!=null?A:"auto",senderAddress:n,contractAddress:e,memo:(d=c.memo)!=null?d:"",funds:(S=c.funds)!=null?S:[]});return At(f)},{onError:(c,f)=>Promise.resolve(t==null?void 0:t(c,f)),onMutate:i,onSuccess:c=>Promise.resolve(o==null?void 0:o(c))});return {error:a.error,isLoading:a.isLoading,isSuccess:a.isSuccess,executeContract:a.mutate,executeContractAsync:a.mutateAsync,status:a.status}},ea=e=>{let{data:t}=Be();return reactQuery.useQuery(["USE_QUERY_SMART",e==null?void 0:e.address,e==null?void 0:e.queryMsg,t],({queryKey:[,o]})=>{if(!(e!=null&&e.address)||!e.queryMsg)throw new Error("address or queryMsg undefined");return It(e.address,e.queryMsg,t)},{enabled:!!(e!=null&&e.address)&&!!(e!=null&&e.queryMsg)&&!!t})},ta=e=>{let{data:t}=Be(),i=["USE_QUERY_RAW",e==null?void 0:e.key,e==null?void 0:e.address,t];return reactQuery.useQuery(i,({queryKey:[,r]})=>{if(!(e!=null&&e.address)||!e.key)throw new Error("address or key undefined");return Ot(e.address,e.key,t)},{enabled:!!(e!=null&&e.address)&&!!(e!=null&&e.key)&&!!t})};function fa(e){let t=L({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(n=>n.walletType),o=g(n=>n.activeChainIds),r=react.useMemo(()=>["USE_STARGATE_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]);return reactQuery.useQuery({queryKey:r,queryFn:a=>l(this,[a],function*({queryKey:[,n,s]}){if(n.length<1)throw new Error("No chains found");return yield G(!!(e!=null&&e.multiChain),n,f=>l(this,null,function*(){var C,h;if(!(o!=null&&o.includes(f.chainId)))return null;if(!N(s))throw new Error(`${s} is not available`);let d=yield (()=>l(this,null,function*(){switch(e==null?void 0:e.offlineSigner){case"offlineSigner":return R(s).getOfflineSigner(f.chainId);case"offlineSignerAuto":return R(s).getOfflineSignerAuto(f.chainId);case"offlineSignerOnlyAmino":return R(s).getOfflineSignerOnlyAmino(f.chainId);default:return R(s).getOfflineSignerAuto(f.chainId)}}))(),S=(C=u.getState().chainsConfig)==null?void 0:C[f.chainId],y={url:f.rpc,headers:k({},(S==null?void 0:S.rpcHeaders)||{})};return (e==null?void 0:e.multiChain)===!0&&e.opts,yield stargate.SigningStargateClient.connectWithSigner(y,d,e!=null&&e.multiChain?(h=e.opts)==null?void 0:h[f.chainId]:e==null?void 0:e.opts)}))}),enabled:!!t&&t.length>0&&!!i&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function ga(e){let t=L({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(n=>n.walletType),o=g(n=>n.activeChainIds),r=react.useMemo(()=>["USE_COSMWASM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]);return reactQuery.useQuery({queryKey:r,queryFn:a=>l(this,[a],function*({queryKey:[,n,s]}){if(n.length<1)throw new Error("No chains found");return yield G(!!(e!=null&&e.multiChain),n,f=>l(this,null,function*(){var h,M;if(!(o!=null&&o.includes(f.chainId)))return null;if(!N(s))throw new Error(`${s} is not available`);let d=yield (()=>l(this,null,function*(){switch(e==null?void 0:e.offlineSigner){case"offlineSigner":return R(s).getOfflineSigner(f.chainId);case"offlineSignerAuto":return R(s).getOfflineSignerAuto(f.chainId);case"offlineSignerOnlyAmino":return R(s).getOfflineSignerOnlyAmino(f.chainId);default:return R(s).getOfflineSignerAuto(f.chainId)}}))(),S=(h=u.getState().chainsConfig)==null?void 0:h[f.chainId],y={url:f.rpc,headers:k({},(S==null?void 0:S.rpcHeaders)||{})},m=S!=null&&S.gas?stargate.GasPrice.fromString(`${S.gas.price}${S.gas.denom}`):void 0;return yield cosmwasmStargate.SigningCosmWasmClient.connectWithSigner(y,d,k({gasPrice:m},e!=null&&e.multiChain?(M=e.opts)==null?void 0:M[f.chainId]:(e==null?void 0:e.opts)||{}))}))}),enabled:!!t&&t.length>0&&!!i&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function ya(e){let t=L({chainId:e.chainId,multiChain:e.multiChain}),i=u(s=>s.walletType),o=g(s=>s.activeChainIds),r=react.useMemo(()=>["USE_STARGATE_TM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]),{data:n}=we({type:e.type,chainId:e.chainId,multiChain:e.multiChain});return reactQuery.useQuery({queryKey:r,queryFn:c=>l(this,[c],function*({queryKey:[,s,a]}){if(s.length<1)throw new Error("No chains found");return yield G(!!e.multiChain,s,A=>l(this,null,function*(){var C;if(!(o!=null&&o.includes(A.chainId)))return null;if(!N(a))throw new Error(`${a} is not available`);if(!n)throw new Error("No tendermint client found");let S=yield (()=>l(this,null,function*(){switch(e.offlineSigner){case"offlineSigner":return R(a).getOfflineSigner(A.chainId);case"offlineSignerAuto":return R(a).getOfflineSignerAuto(A.chainId);case"offlineSignerOnlyAmino":return R(a).getOfflineSignerOnlyAmino(A.chainId);default:return R(a).getOfflineSignerAuto(A.chainId)}}))(),y=e.multiChain?n[A.chainId]:n;return yield stargate.SigningStargateClient.createWithSigner(y,S,e.multiChain?(C=e.opts)==null?void 0:C[A.chainId]:e.opts)}))}),enabled:!!t&&t.length>0&&!!i&&!!n&&(e.enabled!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function Ca(e){let t=L({chainId:e.chainId,multiChain:e.multiChain}),i=u(a=>a.walletType),o=g(a=>a.activeChainIds),r=react.useMemo(()=>["USE_COSMWASM_TM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]),{data:n}=we({type:e.type,chainId:e.chainId,multiChain:!1,enabled:!e.multiChain}),{data:s}=we({type:e.type,chainId:e.chainId,multiChain:!0,enabled:!!e.multiChain});return reactQuery.useQuery({queryKey:r,queryFn:f=>l(this,[f],function*({queryKey:[,a,c]}){if(a.length<1)throw new Error("No chains found");return yield G(!!e.multiChain,a,d=>l(this,null,function*(){var p,I;if(!(o!=null&&o.includes(d.chainId)))return null;if(!N(c))throw new Error(`${c} is not available`);let y=yield (()=>l(this,null,function*(){switch(e.offlineSigner){case"offlineSigner":return R(c).getOfflineSigner(d.chainId);case"offlineSignerAuto":return R(c).getOfflineSignerAuto(d.chainId);case"offlineSignerOnlyAmino":return R(c).getOfflineSignerOnlyAmino(d.chainId);default:return R(c).getOfflineSignerAuto(d.chainId)}}))(),m=(p=u.getState().chainsConfig)==null?void 0:p[d.chainId],C=m!=null&&m.gas?stargate.GasPrice.fromString(`${m.gas.price}${m.gas.denom}`):void 0,h=e.multiChain?s==null?void 0:s[d.chainId]:n;if(!h)throw new Error("No tendermint client found");return yield cosmwasmStargate.SigningCosmWasmClient.createWithSigner(h,y,k({gasPrice:C},e.multiChain?(I=e.opts)==null?void 0:I[d.chainId]:e.opts||{}))}))}),enabled:!!t&&t.length>0&&!!i&&(!!n||!he(s))&&(e.enabled!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}var Nt=({children:e})=>{let[t,i]=react.useState(!1);return react.useEffect(()=>{i(!0);},[]),jsxRuntime.jsx(jsxRuntime.Fragment,{children:t?e:null})};var Tn=()=>{let e=typeof window!="undefined"&&window.sessionStorage.getItem(X)==="Active",{_reconnect:t,_onReconnectFailed:i,_reconnectConnector:o,iframeOptions:r,chains:n}=u(),{activeChainIds:s,wcSignClients:a}=g(),c=N(o||void 0);return react.useEffect(()=>{if(!r||r.autoConnect===!1||!r.allowedIframeParentOrigins.length||!n)return;new cosmiframe.Cosmiframe(r.allowedIframeParentOrigins).isReady().then(A=>{if(A)return Y({chainId:n.map(d=>d.chainId),walletType:"cosmiframe"})});},[r]),react.useEffect(()=>{if(o){if(!c)return;e&&s?B({onError:i}):!e&&t&&B({onError:i});}},[c]),react.useEffect(()=>{var f,A,d,S,y,m,C,h,M,p,I,b,W,D,K,Z,oe,w,O,E;if(o){if(!c)return;o==="cosmostation"&&((A=(f=pe()).subscription)==null||A.call(f,()=>{B({onError:i});})),o==="keplr"&&((S=(d=me()).subscription)==null||S.call(d,()=>{B({onError:i});})),o==="leap"&&((m=(y=de()).subscription)==null||m.call(y,()=>{B({onError:i});})),o==="compass"&&((h=(C=le()).subscription)==null||h.call(C,()=>{B({onError:i});})),o==="vectis"&&((p=(M=Ce()).subscription)==null||p.call(M,()=>{B({onError:i});})),o==="walletconnect"&&a.has("walletconnect")&&((b=(I=Q()).subscription)==null||b.call(I,()=>{B({onError:i});})),o==="station"&&((D=(W=ye()).subscription)==null||D.call(W,()=>{B({onError:i});})),o==="xdefi"&&((Z=(K=Se()).subscription)==null||Z.call(K,()=>{B({onError:i});})),o==="cosmiframe"&&((w=(oe=ue()).subscription)==null||w.call(oe,()=>{B({onError:i});})),o==="okx"&&((E=(O=ge()).subscription)==null||E.call(O,()=>{B({onError:i});}));}},[o,a,c]),null},Bt=()=>(Tn(),null);var vn=new reactQuery.QueryClient({}),Ha=o=>{var r=o,{children:e,grazOptions:t}=r,i=je(r,["children","grazOptions"]);return react.useEffect(()=>{Ct(t);},[t]),jsxRuntime.jsx(reactQuery.QueryClientProvider,F(k({client:vn},i),{children:jsxRuntime.jsxs(Nt,{children:[e,jsxRuntime.jsx(Bt,{})]})}),"graz-provider")};
26
26
 
27
27
  exports.GrazEvents = Bt;
28
28
  exports.GrazProvider = Ha;
29
29
  exports.WALLET_TYPES = He;
30
30
  exports.WalletType = $e;
31
- exports.checkWallet = B;
31
+ exports.checkWallet = N;
32
32
  exports.clearRecentChain = Pe;
33
33
  exports.clearSession = _;
34
34
  exports.configureGraz = Ct;
@@ -58,7 +58,7 @@ exports.getWalletConnect = Q;
58
58
  exports.instantiateContract = wt;
59
59
  exports.isCapsule = ve;
60
60
  exports.isWalletConnect = ft;
61
- exports.reconnect = L;
61
+ exports.reconnect = B;
62
62
  exports.sendIbcTokens = ht;
63
63
  exports.sendTokens = St;
64
64
  exports.suggestChain = We;
package/dist/index.mjs CHANGED
@@ -16,6 +16,6 @@ import { Tendermint37Client, Tendermint34Client } from '@cosmjs/tendermint-rpc';
16
16
  import { shallow } from 'zustand/shallow';
17
17
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
18
18
 
19
- var qt=Object.defineProperty,Ft=Object.defineProperties;var Gt=Object.getOwnPropertyDescriptors;var ce=Object.getOwnPropertySymbols;var Qe=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable;var ze=(e,t,i)=>t in e?qt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,x=(e,t)=>{for(var i in t||(t={}))Qe.call(t,i)&&ze(e,i,t[i]);if(ce)for(var i of ce(t))je.call(t,i)&&ze(e,i,t[i]);return e},G=(e,t)=>Ft(e,Gt(t));var $e=(e,t)=>{var i={};for(var o in e)Qe.call(e,o)&&t.indexOf(o)<0&&(i[o]=e[o]);if(e!=null&&ce)for(var o of ce(e))t.indexOf(o)<0&&je.call(e,o)&&(i[o]=e[o]);return i};var l=(e,t,i)=>new Promise((o,r)=>{var n=c=>{try{a(i.next(c));}catch(f){r(f);}},s=c=>{try{a(i.throw(c));}catch(f){r(f);}},a=c=>c.done?o(c.value):Promise.resolve(c.value).then(n,s);a((i=i.apply(e,t)).next());});var Y="graz-reconnect-session";var He=(p=>(p.KEPLR="keplr",p.LEAP="leap",p.VECTIS="vectis",p.COSMOSTATION="cosmostation",p.WALLETCONNECT="walletconnect",p.WC_KEPLR_MOBILE="wc_keplr_mobile",p.WC_LEAP_MOBILE="wc_leap_mobile",p.WC_COSMOSTATION_MOBILE="wc_cosmostation_mobile",p.WC_CLOT_MOBILE="wc_clot_mobile",p.METAMASK_SNAP_LEAP="metamask_snap_leap",p.METAMASK_SNAP_COSMOS="metamask_snap_cosmos",p.STATION="station",p.XDEFI="xdefi",p.CAPSULE="capsule",p.COSMIFRAME="cosmiframe",p.COMPASS="compass",p.INITIA="initia",p.OKX="okx",p))(He||{}),Ve=["keplr","leap","vectis","cosmostation","walletconnect","wc_keplr_mobile","wc_leap_mobile","wc_cosmostation_mobile","wc_clot_mobile","metamask_snap_leap","station","xdefi","capsule","metamask_snap_cosmos","cosmiframe","compass","initia","okx"];var Qt={iframeOptions:null,recentChainIds:null,chains:null,chainsConfig:null,capsuleConfig:null,capsuleState:null,multiChainFetchConcurrency:3,walletType:"keplr",walletConnect:{options:null,walletConnectModal:null},walletDefaultOptions:null,_notFoundFn:()=>null,_onReconnectFailed:()=>null,_reconnect:!1,_reconnectConnector:null},oe={accounts:null,activeChainIds:null,status:"disconnected",wcSignClients:new Map,capsuleClient:null},jt={name:"graz-session",version:2,partialize:e=>({accounts:e.accounts,activeChainIds:e.activeChainIds}),storage:createJSONStorage(()=>sessionStorage)},$t={name:"graz-internal",partialize:e=>({recentChainIds:e.recentChainIds,_reconnect:e._reconnect,_reconnectConnector:e._reconnectConnector,walletType:e.walletType}),version:2},g=create(subscribeWithSelector(persist(()=>oe,jt))),u=create(subscribeWithSelector(persist(()=>Qt,$t)));var le=()=>{var S,y;if(!((S=u.getState().capsuleConfig)!=null&&S.apiKey)||!((y=u.getState().capsuleConfig)!=null&&y.env))throw new Error("Capsule configuration is not set");let e=()=>l(void 0,null,function*(){var h,k;let m=(yield import('@leapwallet/cosmos-social-login-capsule-provider')).CapsuleProvider,C=new m({apiKey:(h=u.getState().capsuleConfig)==null?void 0:h.apiKey,env:(k=u.getState().capsuleConfig)==null?void 0:k.env});return g.setState({capsuleClient:C}),C});return {init:e,enable:m=>l(void 0,null,function*(){let C=typeof m=="string"?[m]:m,h=g.getState().capsuleClient;h||(h=yield e()),u.setState({capsuleState:{showModal:!0,chainId:C}});}),onAfterLoginSuccessful:()=>l(void 0,null,function*(){var p;let m=g.getState().capsuleClient,{chains:C}=u.getState();if(!m)throw new Error("Capsule client is not initialized");if(!C)throw new Error("Chains are not set");yield m.enable();let h=(p=u.getState().capsuleState)==null?void 0:p.chainId;if(!h)throw new Error("Chain ids are not set");let k=Object.fromEntries(yield Promise.all(h.map(I=>l(void 0,null,function*(){let b=yield m.getAccount(I);return [I,{address:fromBech32(b.address).data,bech32Address:b.address,algo:b.algo,name:b.username||"",pubKey:b.pubkey,isKeystone:!1,isNanoLedger:!1}]}))));g.setState(I=>({accounts:x(x({},I.accounts||{}),k)})),u.setState(I=>({recentChainIds:[...I.recentChainIds||[],...h].filter((b,R,K)=>K.indexOf(b)===R)})),g.setState(I=>({activeChainIds:[...I.activeChainIds||[],...h].filter((b,R,K)=>K.indexOf(b)===R)})),u.setState({walletType:"capsule",_reconnect:!1,_reconnectConnector:"capsule"}),g.setState({status:"connected"}),typeof window!="undefined"&&window.sessionStorage.setItem(Y,"Active"),u.setState({capsuleState:null});}),getKey:m=>l(void 0,null,function*(){let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");let h=yield C.getAccount(m);return {address:fromBech32(h.address).data,bech32Address:h.address,algo:h.algo,name:h.username||"",pubKey:h.pubkey,isKeystone:!1,isNanoLedger:!1}}),getOfflineSignerAuto:m=>l(void 0,null,function*(){let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerDirect(m)}),getOfflineSignerDirect:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerDirect(m)},signDirect:(...m)=>l(void 0,null,function*(){let[C,h,k]=m,p=g.getState().capsuleClient;if(!p)throw new Error("Capsule client is not initialized");return p.signDirect(C,h,{bodyBytes:k.bodyBytes,authInfoBytes:k.authInfoBytes,chainId:k.chainId,accountNumber:k.accountNumber})}),signAmino:(...m)=>l(void 0,null,function*(){let[C,h,k,p]=m,I=g.getState().capsuleClient;if(!I)throw new Error("Capsule client is not initialized");return I.signAmino(C,h,k,p)}),signArbitrary:(m,C,h)=>l(void 0,null,function*(){let k=g.getState().capsuleClient;if(!k)throw new Error("Capsule client is not initialized");let p=yield k.getAccount(m);if(!p)throw new Error(`Wallet not connected to account ${C}`);let I=(()=>{switch(p.algo){case"secp256k1":return encodeSecp256k1Pubkey(p.pubkey);case"ed25519":return encodeEd25519Pubkey(p.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {signature:yield k.signArbitrary(m,C,h),pub_key:{type:p.algo==="secp256k1"?pubkeyType.secp256k1:pubkeyType.ed25519,value:I.value}}}),experimentalSuggestChain:(...m)=>l(void 0,null,function*(){yield Promise.reject(new Error("Capsule does not support experimentalSuggestChain"));}),getOfflineSigner:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSigner(m)},getOfflineSignerAmino:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerAmino(m)}}};var ue=()=>{if(typeof window.compass!="undefined"){let e=window.compass;return Object.assign(e,{subscription:r=>{let n=()=>{N(),r();};return window.addEventListener("leap_keystorechange",n),()=>{window.removeEventListener("leap_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.leap is not defined")};var pe=()=>{let e=u.getState();if(!e.iframeOptions)throw e._notFoundFn(),new Error("no iframe options set");if(!isInIframe())throw e._notFoundFn(),new Error("not in iframe");if(!e.iframeOptions.allowedIframeParentOrigins.length)throw e._notFoundFn(),new Error("no iframe allowed origins");let t=new Cosmiframe(e.iframeOptions.allowedIframeParentOrigins).getKeplrClient();return {enable:t.enable.bind(t),getKey:t.getKey.bind(t),getOfflineSigner:t.getOfflineSigner.bind(t),getOfflineSignerAuto:t.getOfflineSignerAuto.bind(t),getOfflineSignerOnlyAmino:t.getOfflineSignerOnlyAmino.bind(t),experimentalSuggestChain:t.experimentalSuggestChain.bind(t),signDirect:t.signDirect.bind(t),signAmino:t.signAmino.bind(t)}};var it={},ot=()=>{let e=window.ethereum,t=window.cosmos;if(e)return {init:()=>l(void 0,null,function*(){var A;let n=yield e.request({method:"web3_clientVersion"});if(!n.includes("MetaMask"))throw new Error("Metamask is not installed");if(typeof window.okxwallet!="undefined"&&window.okxwallet.isOkxWallet)throw new Error("You have OKX Wallet installed. Please disable and reload the page to use Metamask Snap.");let a=(A=n.split("MetaMask/v")[1])==null?void 0:A.split(".")[0];if(!(Number(a)>=11))throw new Error("Metamask Snap is not supported in this version");return (yield isSnapInstalled())||(yield installSnap()),window.cosmos=new CosmosSnap,t=window.cosmos,!0}),enable:n=>l(void 0,null,function*(){(yield isSnapInstalled())||(yield installSnap());}),getOfflineSigner:n=>t.getOfflineSigner(n),experimentalSuggestChain:n=>l(void 0,null,function*(){if(!n.bech32Config)throw new Error("Bech32Config is required");if(!n.stakeCurrency)throw new Error("StakeCurrency is required");yield t.experimentalSuggestChain(G(x({},n),{stakeCurrency:n.stakeCurrency,bech32Config:n.bech32Config}));}),signAmino:(n,s,a)=>l(void 0,null,function*(){return t.signAmino(n,s,a)}),getKey:n=>l(void 0,null,function*(){return typeof it[n]!="undefined"?it[n]:t.getKey(n)}),getOfflineSignerAuto:n=>l(void 0,null,function*(){return (yield t.getKey(n)).isNanoLedger?t.getOfflineSignerOnlyAmino(n):t.getOfflineSigner(n)}),getOfflineSignerOnlyAmino:n=>t.getOfflineSignerOnlyAmino(n),signDirect:(n,s,a)=>l(void 0,null,function*(){return t.signDirect(n,s,a)}),signArbitrary:(n,s,a)=>l(void 0,null,function*(){return t.signArbitrary(n,s,a)}),disable:n=>l(void 0,null,function*(){n&&(yield t.deleteChain(n));})};throw u.getState()._notFoundFn(),new Error("window.ethereum is not defined")};var me=()=>{var e;if(typeof((e=window.cosmostation)==null?void 0:e.providers.keplr)!="undefined"){let t=window.cosmostation.providers.keplr;return Object.assign(t,{subscription:n=>{let s=()=>{N(),n();};return window.addEventListener("cosmostation_keystorechange",s),()=>{window.removeEventListener("cosmostation_keystorechange",s);}},setDefaultOptions:n=>{t.defaultOptions=n;}})}throw u.getState()._notFoundFn(),new Error("window.cosmostation.providers.keplr is not defined")};var on=e=>{let{bodyBytes:t,authInfoBytes:i,chainId:o,accountNumber:r}=e;if(!t||!i||!o||!r)throw new Error("Invalid sign doc");return {bodyBytes:t,authInfoBytes:i,chainId:o,accountNumber:r}},rn=e=>`${e.slice(0,6)}...${e.slice(-6)}`,st=()=>{if(typeof window.initia!="undefined"){let e=window.initia;return {enable:()=>l(void 0,null,function*(){yield e.getAddress();}),getKey:d=>l(void 0,null,function*(){let S=e.getOfflineSigner(d),[y]=yield S.getAccounts();if(!y)throw new Error("Wallet connection failed");let m=(()=>{switch(y.algo){case"secp256k1":return rawSecp256k1PubkeyToRawAddress(y.pubkey);case"ed25519":return rawEd25519PubkeyToRawAddress(y.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {name:rn(y.address),algo:y.algo,pubKey:y.pubkey,bech32Address:y.address,address:m,isNanoLedger:!1,isKeystone:!1}}),getOfflineSigner:d=>{let S=e.getOfflineSigner(d),y=e.getOfflineSignerOnlyAmino(d);return {getAccounts:S.getAccounts.bind(S),signDirect:S.signDirect.bind(S),signAmino:y.signAmino.bind(y)}},getOfflineSignerAuto:d=>Promise.resolve(e.getOfflineSigner(d)),getOfflineSignerOnlyAmino:d=>e.getOfflineSignerOnlyAmino(d),experimentalSuggestChain:d=>e.requestAddInitiaLayer({chain_id:d.chainId,chain_name:d.chainName,bech32_prefix:"init",bech32_config:d.bech32Config,slip44:d.bip44.coinType,logo_URIs:{png:d.chainSymbolImageUrl},fees:{fee_tokens:d.feeCurrencies.map(S=>{var y,m,C;return {denom:S.coinDenom,amount:S.coinMinimalDenom,low_gas_price:(y=S.gasPriceStep)==null?void 0:y.low,average_gas_price:(m=S.gasPriceStep)==null?void 0:m.average,high_gas_price:(C=S.gasPriceStep)==null?void 0:C.high}})},apis:{rpc:[{address:d.rpc}],rest:[{address:d.rest}]}}),signDirect:(...d)=>{let[S,y,m]=d;return e.getOfflineSigner(S).signDirect(y,on(m))},signAmino:(...d)=>{let[S,y,m]=d;return e.getOfflineSignerOnlyAmino(S).signAmino(y,m)},signArbitrary:(d,S,y)=>l(void 0,null,function*(){let h=(yield e.getOfflineSigner(d).getAccounts()).find(I=>I.address===S);if(!h)throw new Error(`Wallet not connected to account ${S}`);let k=(()=>{switch(h.algo){case"secp256k1":return encodeSecp256k1Pubkey(h.pubkey);case"ed25519":return encodeEd25519Pubkey(h.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {signature:yield e.signArbitrary(y),pub_key:{type:h.algo==="secp256k1"?pubkeyType.secp256k1:pubkeyType.ed25519,value:k.value}}}),subscription:d=>{let S=()=>{N(),d();};return window.addEventListener("initia_keystorechange",S),()=>{window.removeEventListener("initia_keystorechange",S);}}}}throw u.getState()._notFoundFn(),new Error("window.initia is not defined")};var de=()=>{if(typeof window.keplr!="undefined"){let e=window.keplr;return Object.assign(e,{subscription:r=>{let n=()=>{N(),r();};return window.addEventListener("keplr_keystorechange",n),()=>{window.removeEventListener("keplr_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.keplr is not defined")};var fe=()=>{if(typeof window.leap!="undefined"){let e=window.leap;return Object.assign(e,{subscription:r=>{let n=()=>{N(),r();};return window.addEventListener("leap_keystorechange",n),()=>{window.removeEventListener("leap_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.leap is not defined")};var ge={},at=e=>{let t=window.ethereum;if(t&&e){let i=()=>l(void 0,null,function*(){return yield t.request({method:"wallet_getSnaps"})}),o=p=>l(void 0,null,function*(){try{let I=yield i();return Object.values(I).find(b=>b.id===e.id&&(!p||b.version===p))}catch(I){return}}),r=()=>l(void 0,null,function*(){yield t.request({method:"wallet_requestSnaps",params:{[e.id]:e.params||{}}});}),n=()=>l(void 0,null,function*(){var _;let p=yield t.request({method:"web3_clientVersion"});if(!p.includes("MetaMask"))throw new Error("Metamask is not installed");if(typeof window.okxwallet!="undefined"&&window.okxwallet.isOkxWallet)throw new Error("You have OKX Wallet installed. Please disable and reload the page to use Metamask Snap.");let b=(_=p.split("MetaMask/v")[1])==null?void 0:_.split(".")[0];if(!(Number(b)>=11))throw new Error("Metamask Snap is not supported in this version");return (yield o())||(yield r()),!0}),s=p=>l(void 0,null,function*(){(yield o())||(yield r());}),a=(p,I,b)=>l(void 0,null,function*(){let R=yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"signDirect",params:{chainId:p,signerAddress:I,signDoc:b}}}}),K=b.accountNumber,_=new sn(K.low,K.high,K.unsigned);return {signature:R.signature,signed:G(x({},R.signed),{accountNumber:`${_.toString()}`,authInfoBytes:new Uint8Array(Object.values(R.signed.authInfoBytes)),bodyBytes:new Uint8Array(Object.values(R.signed.bodyBytes))})}}),c=(p,I,b)=>l(void 0,null,function*(){return yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"signAmino",params:{chainId:p,signerAddress:I,signDoc:b}}}})}),f=p=>l(void 0,null,function*(){if(typeof ge[p]!="undefined")return ge[p];let I=yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"getKey",params:{chainId:p}}}});if(!I)throw new Error("No response from Metamask");return I.pubKey=Uint8Array.from(Object.values(I.pubkey)),delete I.pubkey,ge[p]=I,ge[p]}),A=p=>l(void 0,null,function*(){let I=yield f(p);return {address:I.bech32Address,algo:I.algo,pubkey:I.pubKey}}),d=(...p)=>l(void 0,null,function*(){let[I,b,R,K]=p;return yield c(I,b,R)}),S=(...p)=>l(void 0,null,function*(){let[I,b,R]=p;return yield a(I,b,R)}),m=p=>({getAccounts:()=>l(void 0,null,function*(){return [yield A(p)]}),signAmino:(I,b)=>d(p,I,b)});return {enable:s,experimentalSuggestChain:(...p)=>l(void 0,null,function*(){yield n(),yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"suggestChain",params:{chainInfo:p[0]}}}});}),getKey:f,getOfflineSigner:p=>({getAccounts:()=>l(void 0,null,function*(){return [yield A(p)]}),signDirect:(I,b)=>S(p,I,b),signAmino:(I,b)=>d(p,I,b)}),getOfflineSignerAuto:p=>l(void 0,null,function*(){return m(p)}),getOfflineSignerOnlyAmino:m,init:n,signAmino:d,signDirect:S}}throw u.getState()._notFoundFn(),new Error("window.ethereum is not defined")};var ct=()=>at({id:"npm:@leapwallet/metamask-cosmos-snap"});var ye=()=>{var e;if(typeof((e=window.okxwallet)==null?void 0:e.keplr)!="undefined"){let t=window.okxwallet.keplr;return Object.assign(t,{subscription:n=>{var a;let s=()=>{N(),n();};return (a=window.okxwallet)==null||a.on("accountsChanged",s),()=>{var c;(c=window.okxwallet)==null||c.removeListener("accountsChanged",s);}},setDefaultOptions:n=>{t.defaultOptions=n;}})}throw u.getState()._notFoundFn(),new Error("window.okxwallet.keplr is not defined")};var Ce=()=>{if(typeof window.station!="undefined"){let e=window.station.keplr;return {subscription:n=>{let s=()=>{N(),n();};return window.addEventListener("station_wallet_change",s),()=>{window.removeEventListener("station_wallet_change",s);}},getKey:n=>l(void 0,null,function*(){let s=yield e.getKey(n);return x({isKeystone:!1},s)}),getOfflineSigner:n=>{try{let s=e.getOfflineSignerOnlyAmino(n);return Object.assign(s,{signDirect:(f,A)=>{throw new Error("signDirect not supported by Station")}})}catch(s){throw console.error(s),s}},experimentalSuggestChain:n=>l(void 0,null,function*(){try{if(!n.bech32Config)throw new Error("Bech32Config is required");if(!n.stakeCurrency)throw new Error("StakeCurrency is required");let s=Object.assign(n,{bech32Config:n.bech32Config,chainSymbolImageUrl:n.chainSymbolImageUrl||"",stakeCurrency:{coinDecimals:n.stakeCurrency.coinDecimals,coinDenom:n.stakeCurrency.coinDenom,coinImageUrl:n.stakeCurrency.coinImageUrl||"",coinMinimalDenom:n.stakeCurrency.coinMinimalDenom},currencies:n.currencies.map(a=>({coinDecimals:a.coinDecimals,coinDenom:a.coinDenom,coinImageUrl:a.coinImageUrl||"",coinMinimalDenom:a.coinMinimalDenom})),feeCurrencies:n.feeCurrencies.map(a=>{var c,f,A;return {coinDecimals:a.coinDecimals,coinDenom:a.coinDenom,coinImageUrl:a.coinImageUrl||"",coinMinimalDenom:a.coinMinimalDenom,gasPriceStep:{average:((c=a.gasPriceStep)==null?void 0:c.average)||0,high:((f=a.gasPriceStep)==null?void 0:f.high)||0,low:((A=a.gasPriceStep)==null?void 0:A.low)||0}}})});yield e.experimentalSuggestChain(s);}catch(s){throw console.error(s),s}}),enable:n=>e.enable(n),disable:n=>e.disable(n),getOfflineSignerAuto:n=>e.getOfflineSignerAuto(n),getOfflineSignerOnlyAmino:n=>e.getOfflineSignerOnlyAmino(n),signDirect:()=>e.signDirect(),signAmino:(n,s,a,c)=>e.signAmino(n,s,a)}}throw u.getState()._notFoundFn(),new Error("window.station is not defined")};var Se=()=>{if(typeof window.vectis!="undefined"){let e=window.vectis.cosmos;return {enable:a=>e.enable(a),getOfflineSigner:a=>e.getOfflineSigner(a),getOfflineSignerAuto:a=>e.getOfflineSignerAuto(a),getKey:a=>l(void 0,null,function*(){let c=yield e.getKey(a);return {address:fromBech32(c.address).data,algo:c.algo,bech32Address:c.address,name:c.name,pubKey:c.pubKey,isKeystone:!1,isNanoLedger:c.isNanoLedger}}),subscription:a=>{let c=()=>{N(),a();};return window.addEventListener("vectis_accountChanged",c),()=>{window.removeEventListener("vectis_accountChanged",c);}},getOfflineSignerOnlyAmino:(...a)=>{let c=a[0];return e.getOfflineSignerAmino(c)},experimentalSuggestChain:(...a)=>l(void 0,null,function*(){var A;let[c]=a;if(!c.bech32Config)throw new Error("Bech32Config is required");if(!c.stakeCurrency)throw new Error("StakeCurrency is required");let f={rpcUrl:c.rpc,restUrl:c.rest,prettyName:c.chainName.replace(" ",""),bech32Prefix:(A=c.bech32Config)==null?void 0:A.bech32PrefixAccAddr,currencies:c.currencies,feeCurrencies:c.feeCurrencies,chainId:c.chainId,chainName:c.chainName,bip44:c.bip44,stakeCurrency:c.stakeCurrency,features:c.features};return e.suggestChains([f])}),signDirect:(...a)=>l(void 0,null,function*(){var A;let{1:c,2:f}=a;return e.signDirect(c,{bodyBytes:f.bodyBytes||Uint8Array.from([]),authInfoBytes:f.authInfoBytes||Uint8Array.from([]),accountNumber:sn.fromString(((A=f.accountNumber)==null?void 0:A.toString())||"",!1),chainId:f.chainId||""})}),signAmino:(...a)=>l(void 0,null,function*(){let{1:c,2:f}=a;return e.signAmino(c,f)})}}throw u.getState()._notFoundFn(),new Error("window.vectis is not defined")};var Q=()=>{if(typeof window!="undefined"){let e=navigator.userAgent;return !!(/android/i.test(e)||/iPad|iPhone|iPod/.test(e))}return !1},lt=()=>Q()&&navigator.userAgent.toLowerCase().includes("android"),ut=()=>Q()&&(navigator.userAgent.toLowerCase().includes("iphone")||navigator.userAgent.toLowerCase().includes("ipad"));var ve=(e,t,i=new Error("Promise timed out"))=>{let o=new Promise((r,n)=>{setTimeout(()=>{n(i);},t);});return Promise.race([e,o])};var j=e=>{var _,ee,re;if(!((re=(ee=(_=u.getState().walletConnect)==null?void 0:_.options)==null?void 0:ee.projectId)!=null&&re.trim()))throw new Error("walletConnect.options.projectId is not defined");let t=(e==null?void 0:e.walletType)||"walletconnect",i=(e==null?void 0:e.encoding)||"base64",o=w=>{if(!e)return;let{appUrl:O,formatNativeUrl:E}=e;if(Q()){if(lt())if(!w)window.open(O.mobile.android,"_self","noreferrer noopener");else {let v=E(O.mobile.android,w,"android");window.open(v,"_self","noreferrer noopener");}if(ut())if(!w)window.open(O.mobile.ios,"_self","noreferrer noopener");else {let v=E(O.mobile.ios,w,"ios");window.open(v,"_self","noreferrer noopener");}}},r=()=>{let{wcSignClients:w}=g.getState();if(!w.get(t))throw new Error("walletConnect.signClient is not defined");w.delete(t),g.setState({wcSignClients:w}),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null});},n=w=>l(void 0,null,function*(){let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");if(!w)throw new Error("No wallet connect session");yield E.disconnect({topic:w,reason:getSdkError("USER_DISCONNECTED")}),yield c(E);}),s=w=>{try{let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");let v=E.session.getAll(),P=v.at(-1);if(!P)return;if(!(P.expiry*1e3>Date.now()+1e3))throw n(P.topic),new Error("invalid session");try{let B=v.find($=>{var H,te;return (te=(H=$.requiredNamespaces.cosmos)==null?void 0:H.chains)==null?void 0:te.includes(`cosmos:${w}`)});if(!B)throw new Error("no session");return B}catch(B){if(!B.message.toLowerCase().includes("no matching key"))throw B}return P}catch(O){if(!O.message.toLowerCase().includes("no matching key"))throw O}},a=w=>{try{return s(w)}catch(O){return}},c=w=>l(void 0,null,function*(){try{let O=w.core.pairing.pairings.getAll({active:!1});if(!O.length)return;yield Promise.all(O.map(E=>l(void 0,null,function*(){yield w.core.pairing.pairings.delete(E.topic,{code:7001,message:"clear pairing"});})));}catch(O){if(!O.message.toLowerCase().includes("no matching key"))throw O}}),f=()=>l(void 0,null,function*(){let{walletConnect:w}=u.getState();if(!(w!=null&&w.options))throw new Error("walletConnect.options is not defined");let{wcSignClients:O}=g.getState(),E=O.get(t);if(E)return E;let v=yield SignClient.init(w.options);return O.set(t,v),g.setState({wcSignClients:O}),v}),A=w=>{let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)return ()=>{};let v=P=>{let W=g.getState().accounts;if(P.params.event.name==="accountsChanged"&&W&&!Object.values(W).map(B=>B.bech32Address).includes(P.params.event.data[0])){let B=P.params.chainId.split(":")[1];B&&d([B]);}else w();};return E.events.on("session_delete",r),E.events.on("session_expire",r),E.events.on("session_event",v),()=>{E.events.off("session_delete",r),E.events.off("session_expire",r),E.events.off("session_event",v);}},d=w=>l(void 0,null,function*(){var te;let O=typeof w=="string"?[w]:w,{wcSignClients:E,activeChainIds:v}=g.getState(),P=E.get(t);if(!P)throw new Error("enable walletConnect.signClient is not defined");let{walletConnect:W,chains:B}=u.getState();if(!((te=W==null?void 0:W.options)!=null&&te.projectId))throw new Error("walletConnect.options.projectId is not defined");let $=new WalletConnectModal(x({projectId:W.options.projectId,enableExplorer:!1,explorerRecommendedWalletIds:"NONE"},W.walletConnectModal)),H=a(O);if(!H){let{uri:F,approval:ne}=yield ve(P.connect({requiredNamespaces:{cosmos:{methods:["cosmos_getAccounts","cosmos_signAmino","cosmos_signDirect"],chains:O.map(V=>`cosmos:${V}`),events:["chainChanged","accountsChanged"]}}}),15e3,new Error("Connection timeout"));if(!F)throw new Error("No wallet connect uri");e?o(F):yield $.openModal({uri:F});let ae=V=>l(void 0,null,function*(){return V.aborted?Promise.reject(new Error("User closed wallet connect")):new Promise((ke,ie)=>{ne().then(qe=>{let Fe=qe.sessionProperties;if(!Fe)return ie(new Error("No session properties"));let xe=JSON.parse(String(Fe.keys));if(xe.length===0)return ie(new Error("No accounts"));if(!xe[0])return ie(new Error("No accounts"));let Ge={};return xe.forEach(X=>{Ge[X.chainId]={address:X.address,algo:X.algo,bech32Address:X.bech32Address,isNanoLedger:X.isNanoLedger,isKeystone:X.isKeystone,name:X.name,pubKey:X.pubKey};}),g.setState(X=>({accounts:x(x({},X.accounts||{}),Ge)})),ke(qe)}).catch(ie),V.addEventListener("abort",()=>{ie(new Error("User closed wallet connect"));},{once:!0});})});try{let V=new AbortController,ke=V.signal;$.subscribeModal(ie=>{ie.open||V.abort();}),yield ae(ke);}catch(V){if($.closeModal(),!V.message.toLowerCase().includes("no matching key"))return Promise.reject(V)}return e||$.closeModal(),Promise.resolve()}try{yield ve((()=>l(void 0,null,function*(){var ne;let F=Object.fromEntries(yield Promise.all((ne=v||O)==null?void 0:ne.map(ae=>l(void 0,null,function*(){return [ae,yield y(ae)]}))));g.setState({accounts:F});}))(),15e3,new Error("Connection timeout"));}catch(F){if(n(H.topic),!F.message.toLowerCase().includes("no matching key"))throw F}}),S=w=>l(void 0,null,function*(){var W;let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");let v=(W=s([w]))==null?void 0:W.topic;if(!v)throw new Error("No wallet connect session");let P=yield E.request({topic:v,chainId:`cosmos:${w}`,request:{method:"cosmos_getAccounts",params:{}}});if(!P[0])throw new Error("No wallet connect account");return {address:P[0].address,algo:P[0].algo,pubkey:new Uint8Array(Buffer.from(P[0].pubkey,i))}}),y=w=>l(void 0,null,function*(){let O=s([w]);if(!(O!=null&&O.topic))throw new Error("No wallet connect session");let E=O.sessionProperties&&JSON.parse(String(O.sessionProperties.keys));if(!E)throw new Error("No wallet connect key");if(E.length===0)throw new Error("No wallet connect session");let v=E.find(P=>P.chainId===w);if(!v)throw new Error(`No wallet connect key for chainId ${w}`);return v}),m=(...w)=>l(void 0,null,function*(){var F,ne;let[O,E,v]=w,{accounts:P,wcSignClients:W}=g.getState(),B=W.get(t);if(!B)throw new Error("walletConnect.signClient is not defined");if(!P)throw new Error("account is not defined");let $=(F=s([O]))==null?void 0:F.topic;if(!$)throw new Error("No wallet connect session");if(!v.bodyBytes)throw new Error("No bodyBytes");if(!v.authInfoBytes)throw new Error("No authInfoBytes");let H={topic:$,chainId:`cosmos:${O}`,request:{method:"cosmos_signDirect",params:{signerAddress:E,signDoc:G(x({},v),{bodyBytes:Buffer.from(v.bodyBytes).toString(i),authInfoBytes:Buffer.from(v.authInfoBytes).toString(i),accountNumber:(ne=v.accountNumber)==null?void 0:ne.toString()})}}};return o(),yield B.request(H)}),C=(...w)=>l(void 0,null,function*(){let[O,E,v]=w,{signature:P,signed:W}=yield m(O,E,v);return {signed:{chainId:W.chainId,accountNumber:sn.fromString(W.accountNumber,!1),authInfoBytes:new Uint8Array(Buffer.from(W.authInfoBytes,i)),bodyBytes:new Uint8Array(Buffer.from(W.bodyBytes,i))},signature:P}}),h=(...w)=>l(void 0,null,function*(){var F;let[O,E,v,P]=w,{wcSignClients:W}=g.getState(),B=W.get(t),{accounts:$}=g.getState();if(!B)throw new Error("walletConnect.signClient is not defined");if(!$)throw new Error("account is not defined");let H=(F=s([O]))==null?void 0:F.topic;if(!H)throw new Error("No wallet connect session");return o(),yield B.request({topic:H,chainId:`cosmos:${O}`,request:{method:"cosmos_signDirect",params:{signerAddress:E,signDoc:v}}})}),k=(...w)=>l(void 0,null,function*(){let[O,E,v,P]=w;return yield h(O,E,v)}),p=w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signDirect:(O,E)=>C(w,O,E)}),I=w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signAmino:(O,E)=>k(w,O,E)});return {enable:d,disable:w=>l(void 0,null,function*(){var v;let{wcSignClients:O}=g.getState(),E=O.get(t);if(w===void 0){let P=E==null?void 0:E.session.getAll();P!==void 0&&(yield Promise.all(P.map(W=>n(W.topic))));}else typeof w=="string"?yield n((v=s([w]))==null?void 0:v.topic):yield Promise.all(w.map(P=>{var W;return n((W=s([P]))==null?void 0:W.topic)}));(E==null?void 0:E.session.getAll().length)===0&&r();}),experimentalSuggestChain:(...w)=>l(void 0,null,function*(){yield Promise.reject(new Error("WalletConnect does not support experimentalSuggestChain"));}),getKey:y,getOfflineSigner:w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signDirect:(O,E)=>C(w,O,E),signAmino:(O,E)=>k(w,O,E)}),getOfflineSignerAuto:w=>l(void 0,null,function*(){return (yield y(w)).isNanoLedger?I(w):p(w)}),getOfflineSignerOnlyAmino:I,signAmino:k,signDirect:C,subscription:A,init:f}};var pt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!Q())throw new Error("WalletConnect Clot mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{android:"clot://",ios:"clot://"}},walletType:"wc_clot_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;default:return `${a}://wc?uri=${c}`}}};return j(e)};var mt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!Q())throw new Error("WalletConnect Cosmostation mobile is only supported in mobile");let e={encoding:"hex",appUrl:{mobile:{ios:"cosmostation://",android:"cosmostation://"}},walletType:"wc_cosmostation_mobile",formatNativeUrl:(r,n,s)=>`${r.replaceAll("/","").replaceAll(":","")}://wc?${n}`};return j(e)};var dt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!Q())throw new Error("WalletConnect Keplr mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{ios:"keplrwallet://",android:"intent://"}},walletType:"wc_keplr_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;case"android":return `${a}://wcV2?${c}#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;`;default:return `${a}://wc?uri=${c}`}}};return j(e)};var ft=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!Q())throw new Error("WalletConnect Leap mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{ios:"leapcosmos://",android:"intent://"}},walletType:"wc_leap_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;case"android":return `${a}://wcV2?${c}#Intent;package=io.leapwallet.cosmos;scheme=leapwallet;end;`;default:return `${a}://wc?uri=${c}`}}};return j(e)};var he=()=>{var e;if(typeof((e=window.xfi)==null?void 0:e.keplr)!="undefined"){let t=window.xfi.keplr;return Object.assign(t,{subscription:r=>{let n=()=>{N(),r();};return window.addEventListener("keplr_keystorechange",n),()=>{window.removeEventListener("keplr_keystorechange",n);}}})}throw u.getState()._notFoundFn(),new Error("window.xfi.keplr is not defined")};var L=(e=u.getState().walletType)=>{try{return D(e),!0}catch(t){return !1}},N=()=>{window.sessionStorage.removeItem(Y),g.setState(oe);},D=(e=u.getState().walletType)=>{var o;let t=(()=>{switch(e){case"keplr":return de();case"leap":return fe();case"cosmostation":return me();case"vectis":return Se();case"walletconnect":return j();case"wc_keplr_mobile":return dt();case"wc_leap_mobile":return ft();case"wc_cosmostation_mobile":return mt();case"wc_clot_mobile":return pt();case"metamask_snap_leap":return ct();case"metamask_snap_cosmos":return ot();case"station":return Ce();case"xdefi":return he();case"capsule":return le();case"cosmiframe":return pe();case"compass":return ue();case"initia":return st();case"okx":return ye();default:throw new Error("Unknown wallet type")}})(),i=u.getState().walletDefaultOptions;return i&&((o=t.setDefaultOptions)==null||o.call(t,i)),t},rr=()=>Object.fromEntries(Ve.map(e=>[e,L(e)])),Pe=e=>e==="capsule",gt=e=>e==="walletconnect"||e==="wc_keplr_mobile"||e==="wc_leap_mobile"||e==="wc_cosmostation_mobile";var J=e=>l(void 0,null,function*(){var t;try{let{recentChainIds:i,chains:o,walletType:r}=u.getState(),n=(e==null?void 0:e.walletType)||r;if(!L(n))throw new Error(`${n} is not available`);let a=D(n),c=typeof(e==null?void 0:e.chainId)=="string"?[e.chainId]:(e==null?void 0:e.chainId)||i;if(!c)throw new Error("No last known connected chain, connect action requires chain ids");let f=o==null?void 0:o.map(y=>y.chainId);c.forEach(y=>{if(!(f!=null&&f.includes(y)))throw new Error(`Chain ${y} is not provided in GrazProvider`)}),g.setState(y=>{let m=u.getState()._reconnect||!!u.getState()._reconnectConnector||!!c;return y.activeChainIds&&c.filter(h=>{var k;return !((k=y.activeChainIds)!=null&&k.includes(h))}).length>0?{status:"connecting"}:m?{status:"reconnecting"}:{status:"connecting"}});let{accounts:A}=g.getState();if(yield (t=a.init)==null?void 0:t.call(a),Pe(n)&&g.getState().capsuleClient&&Object.values(g.getState().accounts||[]).length>0){let y=c.map(h=>o.find(k=>k.chainId===h)),m=g.getState().accounts;g.setState({status:"connecting"});let C=Object.fromEntries(yield Promise.all(c.map(h=>l(void 0,null,function*(){return [h,yield a.getKey(h)]}))));return g.setState(h=>({accounts:x(x({},h.accounts||{}),C)})),u.setState(h=>({recentChainIds:[...h.recentChainIds||[],...c].filter((k,p,I)=>I.indexOf(k)===p)})),g.setState(h=>({activeChainIds:[...h.activeChainIds||[],...c].filter((k,p,I)=>I.indexOf(k)===p)})),g.setState({status:"connected"}),{accounts:m,walletType:n,chains:y}}if(yield a.enable(c),Pe(n)){let y=c.map(C=>o.find(h=>h.chainId===C)),m=g.getState().accounts;return g.setState({status:"connecting"}),{accounts:m,walletType:n,chains:y}}if(!gt(n)){let y=Object.fromEntries(yield Promise.all(c.map(m=>l(void 0,null,function*(){return [m,yield a.getKey(m)]}))));g.setState(m=>({accounts:x(x({},m.accounts||{}),y)}));}u.setState(y=>({recentChainIds:[...y.recentChainIds||[],...c].filter((m,C,h)=>h.indexOf(m)===C)})),g.setState(y=>({activeChainIds:[...y.activeChainIds||[],...c].filter((m,C,h)=>h.indexOf(m)===C)})),u.setState({walletType:n,_reconnect:!!(e!=null&&e.autoReconnect),_reconnectConnector:n}),g.setState({status:"connected"}),typeof window!="undefined"&&window.sessionStorage.setItem(Y,"Active");let d=c.map(y=>o.find(m=>m.chainId===y));return {accounts:g.getState().accounts,walletType:n,chains:d}}catch(i){throw console.error("connect ",i),g.getState().accounts===null&&g.setState({status:"disconnected"}),g.getState().accounts&&g.getState().activeChainIds&&g.setState({status:"connected"}),i}}),se=e=>{typeof window!="undefined"&&window.sessionStorage.removeItem(Y);let t=typeof(e==null?void 0:e.chainId)=="string"?[e.chainId]:e==null?void 0:e.chainId;if(t){let i=g.getState().accounts;t.forEach(r=>{i==null||delete i[r];}),Object.values(i||{}).length===0?(g.setState(oe),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null})):(g.setState(r=>{var n;return {activeChainIds:(n=r.activeChainIds)==null?void 0:n.filter(s=>!t.includes(s)),accounts:i}}),u.setState(r=>{var n;return {recentChainIds:(n=r.recentChainIds)==null?void 0:n.filter(s=>!t.includes(s))}}));}else g.setState(oe),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null});return Promise.resolve()},U=e=>l(void 0,null,function*(){var r;let{recentChainIds:t,_reconnectConnector:i,_reconnect:o}=u.getState();try{let n=L(i||void 0);if(t&&n&&i)return yield J({chainId:t,walletType:i,autoReconnect:o})}catch(n){(r=e==null?void 0:e.onError)==null||r.call(e,n),se();}}),yt=e=>l(void 0,null,function*(){if(!(e!=null&&e.chainId))throw new Error("chainId is required");let{walletType:t}=u.getState(),i=e.walletType||t;if(!L(i))throw new Error(`${i} is not available`);let r=D(i),n=r.getOfflineSigner(e.chainId),s=r.getOfflineSignerOnlyAmino(e.chainId),a=yield r.getOfflineSignerAuto(e.chainId);return {offlineSigner:n,offlineSignerAmino:s,offlineSignerAuto:a}});var We=()=>{u.setState({recentChainIds:null});},Cr=()=>u.getState().recentChainIds,Sr=()=>{var i;let{recentChainIds:e,chains:t}=u.getState();return (i=e==null?void 0:e.map(o=>t.find(r=>r.chainId===o)))!=null?i:null},hr=({chainId:e})=>{var t;return (t=u.getState().chains)==null?void 0:t.find(i=>i.chainId===e)},wr=({chainId:e})=>{var t;return (t=u.getState().chains)==null?void 0:t.filter(i=>e==null?void 0:e.includes(i.chainId))},Re=i=>l(void 0,[i],function*({chainInfo:e,walletType:t}){let o=D(t);return t==="capsule"?yield J({chainId:e.chainId,walletType:t}):yield o.experimentalSuggestChain(e),e}),Ct=e=>l(void 0,null,function*(){var o;let t=u.getState().walletType;return yield Re({chainInfo:e.chainInfo,walletType:(o=e.walletType)!=null?o:t}),yield J({chainId:e.chainInfo.chainId,walletType:e.walletType,autoReconnect:e.autoReconnect})});var St=e=>(u.setState(t=>({iframeOptions:e.iframeOptions||t.iframeOptions,walletConnect:e.walletConnect||t.walletConnect,walletType:e.defaultWallet||t.walletType,capsuleConfig:e.capsuleConfig||t.capsuleConfig,walletDefaultOptions:e.walletDefaultOptions||t.walletDefaultOptions,chains:e.chains,chainsConfig:e.chainsConfig||t.chainsConfig,multiChainFetchConcurrency:e.multiChainFetchConcurrency||t.multiChainFetchConcurrency,_notFoundFn:e.onNotFound||t._notFoundFn,_onReconnectFailed:e.onReconnectFailed||t._onReconnectFailed,_reconnect:e.autoReconnect===void 0?!0:e.autoReconnect||t._reconnect})),e);var ht=s=>l(void 0,[s],function*({signingClient:e,senderAddress:t,recipientAddress:i,amount:o,fee:r,memo:n}){if(!e)throw new Error("No connected account detected");if(!t)throw new Error("senderAddress is not defined");return e.sendTokens(t,i,o,r,n)}),wt=A=>l(void 0,[A],function*({signingClient:e,senderAddress:t,recipientAddress:i,transferAmount:o,sourcePort:r,sourceChannel:n,timeoutHeight:s,timeoutTimestamp:a,fee:c,memo:f}){if(!e)throw new Error("Stargate signing client is not ready");if(!t)throw new Error("senderAddress is not defined");return e.sendIbcTokens(t,i,o,r,n,s,a,c,f)}),At=a=>l(void 0,[a],function*({signingClient:e,senderAddress:t,msg:i,fee:o,options:r,label:n,codeId:s}){if(!e)throw new Error("CosmWasm signing client is not ready");return e.instantiate(t,s,i,n,o,r)}),It=a=>l(void 0,[a],function*({signingClient:e,senderAddress:t,msg:i,fee:o,contractAddress:r,funds:n,memo:s}){if(!e)throw new Error("CosmWasm signing client is not ready");return e.execute(t,r,i,o,s,n)}),Ot=(e,t,i)=>l(void 0,null,function*(){if(!i)throw new Error("CosmWasm client is not ready");return yield i.queryContractSmart(e,t)}),Et=(e,t,i)=>{if(!i)throw new Error("CosmWasm client is not ready");let o=new TextEncoder().encode(t);return i.queryContractRaw(e,o)};var vr=e=>e,Pr=e=>e;var we=e=>e?Object.keys(e).length===0:!0;var De=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t;}},bt=e=>globalThis.DOMException===void 0?new De(e):new DOMException(e),Tt=e=>{let t=e.reason===void 0?bt("This operation was aborted."):e.reason;return t instanceof Error?t:bt(t)};function Ke(n,s){return l(this,arguments,function*(e,t,{concurrency:i=Number.POSITIVE_INFINITY,stopOnError:o=!0,signal:r}={}){return new Promise((a,c)=>{if(e[Symbol.iterator]===void 0&&e[Symbol.asyncIterator]===void 0)throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof e})`);if(typeof t!="function")throw new TypeError("Mapper function is required");if(!((Number.isSafeInteger(i)||i===Number.POSITIVE_INFINITY)&&i>=1))throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${i}\` (${typeof i})`);let f=[],A=[],d=new Map,S=!1,y=!1,m=!1,C=0,h=0,k=e[Symbol.iterator]===void 0?e[Symbol.asyncIterator]():e[Symbol.iterator](),p=b=>{S=!0,y=!0,c(b);};r&&(r.aborted&&p(Tt(r)),r.addEventListener("abort",()=>{p(Tt(r));}));let I=()=>l(this,null,function*(){if(y)return;let b=yield k.next(),R=h;if(h++,b.done){if(m=!0,C===0&&!y){if(!o&&A.length>0){p(new AggregateError(A));return}if(y=!0,d.size===0){a(f);return}let K=[];for(let[_,ee]of f.entries())d.get(_)!==Mt&&K.push(ee);a(K);}return}C++,l(this,null,function*(){try{let K=yield b.value;if(y)return;let _=yield t(K,R);_===Mt&&d.set(R,_),f[R]=_,C--,yield I();}catch(K){if(o)p(K);else {A.push(K),C--;try{yield I();}catch(_){p(_);}}}});});l(this,null,function*(){for(let b=0;b<i;b++){try{yield I();}catch(R){p(R);break}if(m||S)break}});})})}var Mt=Symbol("skip");var q=({chainId:e,multiChain:t})=>{let i=u(r=>r.chains);if(!i)throw new Error("No chains found in GrazProvider");let o=typeof e=="string"?[e]:e;switch(!0){case(!!t&&!!o):return o.map(r=>i.find(n=>n.chainId===r)).filter(Boolean);case(!t&&!!o):return [o.map(r=>i.find(n=>n.chainId===r)).filter(Boolean)[0]];case(!!t&&!o):return i;default:return [i[0]]}},z=(e,t,i)=>l(void 0,null,function*(){let o=u.getState().multiChainFetchConcurrency;if(e){let n=yield Ke(t,i,{concurrency:o});return Object.fromEntries(n.map((s,a)=>[t[a].chainId,s]))}return yield i(t[0])}),kt=(e,t,i)=>{if(e){let r=t.map(i);return Object.fromEntries(r.map((n,s)=>[t[s].chainId,n]))}return i(t[0])};var Be=e=>{let t=q({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=useMemo(()=>["USE_STARGATE_CLIENT",t],[t]);return useQuery({queryKey:i,queryFn:r=>l(void 0,[r],function*({queryKey:[,o]}){if(o.length<1)throw new Error("No chains found");return yield z(!!(e!=null&&e.multiChain),o,s=>l(void 0,null,function*(){var A;let a=(A=u.getState().chainsConfig)==null?void 0:A[s.chainId],c={url:s.rpc,headers:x({},(a==null?void 0:a.rpcHeaders)||{})};return yield StargateClient.connect(c)}))}),enabled:!!t&&t.length>0&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})},Le=e=>{let t=q({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=useMemo(()=>["USE_COSMWASM_CLIENT",t],[t]);return useQuery({queryKey:i,queryFn:r=>l(void 0,[r],function*({queryKey:[,o]}){if(o.length<1)throw new Error("No chains found");return yield z(!!(e!=null&&e.multiChain),o,s=>l(void 0,null,function*(){var A;let a=(A=u.getState().chainsConfig)==null?void 0:A[s.chainId],c={url:s.rpc,headers:x({},(a==null?void 0:a.rpcHeaders)||{})};return yield CosmWasmClient.connect(c)}))}),enabled:!!t&&t.length>0&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})},Ae=({type:e,chainId:t,multiChain:i,enabled:o})=>{let r=q({chainId:t,multiChain:i}),n=useMemo(()=>["USE_TENDERMINT_CLIENT",e,r],[e,r]);return useQuery({queryKey:n,queryFn:c=>l(void 0,[c],function*({queryKey:[,s,a]}){if(a.length<1)throw new Error("No chains found");return yield z(!!i,a,A=>l(void 0,null,function*(){var C;let d=(C=u.getState().chainsConfig)==null?void 0:C[A.chainId],S={url:A.rpc,headers:x({},(d==null?void 0:d.rpcHeaders)||{})};return yield (s==="tm37"?Tendermint37Client:Tendermint34Client).connect(S)}))}),enabled:!!r&&r.length>0&&(o!==void 0?!!o:!0),refetchOnWindowFocus:!1})};var os=()=>u(e=>({walletType:e.walletType,isCosmostation:e.walletType==="cosmostation",isCosmostationMobile:e.walletType==="wc_cosmostation_mobile",isKeplr:e.walletType==="keplr",isKeplrMobile:e.walletType==="wc_keplr_mobile",isLeap:e.walletType==="leap",isLeapMobile:e.walletType==="wc_leap_mobile",isVectis:e.walletType==="vectis",isWalletConnect:e.walletType==="walletconnect",isMetamaskSnapLeap:e.walletType==="metamask_snap_leap",isStation:e.walletType==="station",isCapsule:e.walletType==="capsule",isCosmiframe:e.walletType==="cosmiframe"}),shallow),Ie=e=>{let i=["USE_CHECK_WALLET",u(r=>e||r.walletType)];return useQuery(i,({queryKey:[,r]})=>L(r))};var Z=e=>{let t=u(a=>a.walletType),i=g(a=>a.activeChainIds),o=q({chainId:e!=null&&e.chainId?e.chainId:i||void 0,multiChain:e==null?void 0:e.multiChain}),r=g(a=>a.accounts),n=g(a=>a.status);return useEffect(()=>g.subscribe(a=>a.status,(a,c)=>{var f,A,d;if(a==="connected"){let{accounts:S,activeChainIds:y}=g.getState(),{chains:m}=u.getState(),{walletType:C}=u.getState();if(!S||!y||!m)return (f=e==null?void 0:e.onDisconnect)==null?void 0:f.call(e);(A=e==null?void 0:e.onConnect)==null||A.call(e,{accounts:S,chains:y.map(h=>m.find(k=>k.chainId===h)),walletType:C,isReconnect:c==="reconnecting"});}a==="disconnected"&&((d=e==null?void 0:e.onDisconnect)==null||d.call(e));}),[e]),{data:useMemo(()=>r?kt(!!(e!=null&&e.multiChain),o,a=>r[a.chainId]):void 0,[r,o,e==null?void 0:e.multiChain]),isConnected:n==="connected",isConnecting:n==="connecting",isDisconnected:n==="disconnected",isReconnecting:n==="reconnecting",isLoading:n==="connecting"||n==="reconnecting",walletType:n==="connected"?t:void 0,reconnect:U,status:n}},wn=e=>{let t=q({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),{data:i}=Z(),o=(e==null?void 0:e.bech32Address)||(i==null?void 0:i.bech32Address),{data:r}=Be({chainId:t.map(s=>s.chainId),multiChain:!0,enabled:((e==null?void 0:e.enabled)===void 0?!0:e.enabled)&&!!o}),n=useMemo(()=>["USE_ALL_BALANCES",r,t,o,e==null?void 0:e.chainId],[o,e==null?void 0:e.chainId,t,r]);return useQuery(n,f=>l(void 0,[f],function*({queryKey:[,s,a,c]}){if(!c)throw new Error("address is not defined");return yield z(!!(e!=null&&e.multiChain),a,d=>l(void 0,null,function*(){var m;let S=s==null?void 0:s[d.chainId];if(!S)throw new Error(`Client is not ready ${d.chainId}`);if(!((m=d.bech32Config)!=null&&m.bech32PrefixAccAddr))throw new Error(`Bech32Config is missing ${d.chainId}`);return yield S.getAllBalances(toBech32(d.bech32Config.bech32PrefixAccAddr,fromBech32(c).data))}))}),{enabled:!!o&&!!t&&t.length>0&&!we(r)&&((e==null?void 0:e.enabled)===void 0?!0:e.enabled),refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!1})},Cs=e=>{let t=q({chainId:e.chainId}),{data:i}=Z({chainId:e.chainId}),o=e.bech32Address||(i==null?void 0:i.bech32Address),{data:r,refetch:n}=wn({chainId:t.map(c=>c.chainId),bech32Address:o,enabled:!!o&&(e.enabled===void 0?!0:e.enabled)}),s=["USE_BALANCE",e.denom,r,t,o,e.chainId],a=useQuery(s,({queryKey:[,c,f]})=>f==null?void 0:f.find(A=>A.denom===c),{enabled:!!e.denom&&!!r&&!!(r!=null&&r.length)&&(e.enabled===void 0?!0:e.enabled)});return G(x({},a),{refetch:c=>l(void 0,null,function*(){return yield n(),a.refetch(c)})})},Ss=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=useMutation(["USE_CONNECT",e,t,i],J,{onError:(s,a)=>e==null?void 0:e(s,a),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))}),{data:n}=Ie();return {connect:s=>r.mutate(s),connectAsync:s=>r.mutateAsync(s),error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,isSupported:!!n,status:r.status}},hs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=useMutation(["USE_DISCONNECT",e,t,i],se,{onError:n=>Promise.resolve(e==null?void 0:e(n,void 0)),onMutate:t,onSuccess:()=>Promise.resolve(i==null?void 0:i(void 0))});return {disconnect:n=>r.mutate(n),disconnectAsync:n=>r.mutateAsync(n),error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,status:r.status}},ws=e=>{let t=q({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(r=>r.walletType),o=useMemo(()=>["USE_OFFLINE_SIGNERS",t,i],[t,i]);return useQuery({queryKey:o,queryFn:s=>l(void 0,[s],function*({queryKey:[,r,n]}){if(r.length<1)throw new Error("No chain found");if(!L(n))throw new Error(`${n} is not available`);return yield z(!!(e!=null&&e.multiChain),r,f=>l(void 0,null,function*(){return yield yt({chainId:f.chainId,walletType:n})}))}),enabled:!!t&&t.length>0&&!!i,refetchOnWindowFocus:!1})},As=e=>{let t=q({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),{data:i}=Z(),{data:o}=Be({chainId:t.map(s=>s.chainId),multiChain:!0}),r=(e==null?void 0:e.bech32Address)||(i==null?void 0:i.bech32Address),n=useMemo(()=>["USE_BALANCE_STAKED",o,t,r],[t,r,o]);return useQuery(n,f=>l(void 0,[f],function*({queryKey:[,s,a,c]}){if(!c)throw new Error("address is not defined");return yield z(!!(e!=null&&e.multiChain),a,d=>l(void 0,null,function*(){var y,m;if(!s)throw new Error("Client is not ready");if(!((y=d.bech32Config)!=null&&y.bech32PrefixAccAddr))throw new Error(`Bech32Config is missing ${d.chainId}`);return yield (m=s[d.chainId])==null?void 0:m.getBalanceStaked(toBech32(d.bech32Config.bech32PrefixAccAddr,fromBech32(c).data))}))}),{enabled:!!r&&!!t&&t.length>0&&!!o,refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!1})};var ks=()=>{let e=u(o=>o.capsuleState),t=g(o=>o.capsuleClient),i=le();return {setModalState:o=>{u.setState(r=>{var n;return {capsuleState:{showModal:o,chainId:(n=r.capsuleState)==null?void 0:n.chainId}}});},modalState:!!(e!=null&&e.showModal),client:t,onAfterLoginSuccessful:i.onAfterLoginSuccessful,onLoginFailure:()=>{se();}}};var Ks=()=>g(e=>e.activeChainIds),An=()=>{var e;return (e=g(t=>t.activeChainIds))==null?void 0:e.map(t=>{var o;let i=(o=u.getState().chains)==null?void 0:o.find(r=>r.chainId===t);if(i)return i}).filter(Boolean)},_s=({chainId:e})=>{var t;return (t=u().chains)==null?void 0:t.find(i=>i.chainId===e)},Ns=({chainId:e})=>{var t;return (t=u().chains)==null?void 0:t.filter(i=>e==null?void 0:e.includes(i.chainId))},Bs=({denom:e})=>{let t=An();return useQuery(["USE_ACTIVE_CHAIN_CURRENCY",e],({queryKey:[,r]})=>{var n;return (n=t==null?void 0:t.find(s=>s.currencies.find(a=>a.coinMinimalDenom===r)))==null?void 0:n.currencies.find(s=>s)})},Ls=e=>{var r;let t=(r=e.status)!=null?r:"BOND_STATUS_BONDED",i=["USE_ACTIVE_CHAIN_VALIDATORS",e.queryClient,t];return useQuery(i,a=>l(void 0,[a],function*({queryKey:[,n,s]}){if(!n)throw new Error("Query client is not defined");return yield n.staking.validators(s)}),{enabled:typeof e.queryClient!="undefined"})},Us=()=>({data:u(t=>t.recentChainIds),clear:We}),qs=()=>{var t;return {data:(t=u(i=>i.recentChainIds))==null?void 0:t.map(i=>{var r;let o=(r=u.getState().chains)==null?void 0:r.find(n=>n.chainId===i);if(o)return o}).filter(Boolean),clear:We}},Fs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=useMutation(["USE_SUGGEST_CHAIN",e,t,i],Re,{onError:(n,s)=>Promise.resolve(e==null?void 0:e(n,s.chainInfo)),onMutate:n=>t==null?void 0:t(n.chainInfo),onSuccess:n=>Promise.resolve(i==null?void 0:i(n))});return {error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,suggest:r.mutate,suggestAsync:r.mutateAsync,status:r.status}},Gs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=useMutation(["USE_SUGGEST_CHAIN_AND_CONNECT",e,t,i],Ct,{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:s=>t==null?void 0:t(s),onSuccess:s=>Promise.resolve(i==null?void 0:i(s))}),{data:n}=Ie();return {error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,isSupported:!!n,status:r.status,suggestAndConnect:r.mutate,suggestAndConnectAsync:r.mutateAsync}};var Ys=({onError:e,onLoading:t,onSuccess:i}={})=>{let{data:o}=Z(),r=o==null?void 0:o.bech32Address,n=useMutation(["USE_SEND_TOKENS",e,t,i,r],s=>ht(x({senderAddress:r},s)),{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))});return {error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,sendTokens:n.mutate,sendTokensAsync:n.mutateAsync,status:n.status}},Js=({onError:e,onLoading:t,onSuccess:i}={})=>{let{data:o}=Z(),r=o==null?void 0:o.bech32Address,n=useMutation(["USE_SEND_IBC_TOKENS",e,t,i,r],s=>wt(x({senderAddress:r},s)),{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))});return {error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,sendIbcTokens:n.mutate,sendIbcTokensAsync:n.mutateAsync,status:n.status}},Zs=({codeId:e,onError:t,onLoading:i,onSuccess:o})=>{let{data:r}=Z(),n=r==null?void 0:r.bech32Address,a=useMutation(["USE_INSTANTIATE_CONTRACT",t,i,o,e,n],c=>{var A;if(!n)throw new Error("senderAddress is undefined");let f=G(x({},c),{fee:(A=c.fee)!=null?A:"auto",senderAddress:n,codeId:e});return At(f)},{onError:(c,f)=>Promise.resolve(t==null?void 0:t(c,f)),onMutate:i,onSuccess:c=>Promise.resolve(o==null?void 0:o(c))});return {error:a.error,isLoading:a.isLoading,isSuccess:a.isSuccess,instantiateContract:a.mutate,instantiateContractAsync:a.mutateAsync,status:a.status}},ea=({contractAddress:e,onError:t,onLoading:i,onSuccess:o})=>{let{data:r}=Z(),n=r==null?void 0:r.bech32Address,a=useMutation(["USE_EXECUTE_CONTRACT",t,i,o,e,n],c=>{var A,d,S;if(!n)throw new Error("senderAddress is undefined");let f=G(x({},c),{fee:(A=c.fee)!=null?A:"auto",senderAddress:n,contractAddress:e,memo:(d=c.memo)!=null?d:"",funds:(S=c.funds)!=null?S:[]});return It(f)},{onError:(c,f)=>Promise.resolve(t==null?void 0:t(c,f)),onMutate:i,onSuccess:c=>Promise.resolve(o==null?void 0:o(c))});return {error:a.error,isLoading:a.isLoading,isSuccess:a.isSuccess,executeContract:a.mutate,executeContractAsync:a.mutateAsync,status:a.status}},ta=e=>{let{data:t}=Le();return useQuery(["USE_QUERY_SMART",e==null?void 0:e.address,e==null?void 0:e.queryMsg,t],({queryKey:[,o]})=>{if(!(e!=null&&e.address)||!e.queryMsg)throw new Error("address or queryMsg undefined");return Ot(e.address,e.queryMsg,t)},{enabled:!!(e!=null&&e.address)&&!!(e!=null&&e.queryMsg)&&!!t})},na=e=>{let{data:t}=Le(),i=["USE_QUERY_RAW",e==null?void 0:e.key,e==null?void 0:e.address,t];return useQuery(i,({queryKey:[,r]})=>{if(!(e!=null&&e.address)||!e.key)throw new Error("address or key undefined");return Et(e.address,e.key,t)},{enabled:!!(e!=null&&e.address)&&!!(e!=null&&e.key)&&!!t})};function ga(e){let t=q({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(n=>n.walletType),o=g(n=>n.activeChainIds),r=useMemo(()=>["USE_STARGATE_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]);return useQuery({queryKey:r,queryFn:a=>l(this,[a],function*({queryKey:[,n,s]}){if(n.length<1)throw new Error("No chains found");return yield z(!!(e!=null&&e.multiChain),n,f=>l(this,null,function*(){var C,h;if(!(o!=null&&o.includes(f.chainId)))return null;if(!L(s))throw new Error(`${s} is not available`);let d=yield (()=>l(this,null,function*(){switch(e==null?void 0:e.offlineSigner){case"offlineSigner":return D(s).getOfflineSigner(f.chainId);case"offlineSignerAuto":return D(s).getOfflineSignerAuto(f.chainId);case"offlineSignerOnlyAmino":return D(s).getOfflineSignerOnlyAmino(f.chainId);default:return D(s).getOfflineSignerAuto(f.chainId)}}))(),S=(C=u.getState().chainsConfig)==null?void 0:C[f.chainId],y={url:f.rpc,headers:x({},(S==null?void 0:S.rpcHeaders)||{})};return (e==null?void 0:e.multiChain)===!0&&e.opts,yield SigningStargateClient.connectWithSigner(y,d,e!=null&&e.multiChain?(h=e.opts)==null?void 0:h[f.chainId]:e==null?void 0:e.opts)}))}),enabled:!!t&&t.length>0&&!!i&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function ya(e){let t=q({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(n=>n.walletType),o=g(n=>n.activeChainIds),r=useMemo(()=>["USE_COSMWASM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]);return useQuery({queryKey:r,queryFn:a=>l(this,[a],function*({queryKey:[,n,s]}){if(n.length<1)throw new Error("No chains found");return yield z(!!(e!=null&&e.multiChain),n,f=>l(this,null,function*(){var h,k;if(!(o!=null&&o.includes(f.chainId)))return null;if(!L(s))throw new Error(`${s} is not available`);let d=yield (()=>l(this,null,function*(){switch(e==null?void 0:e.offlineSigner){case"offlineSigner":return D(s).getOfflineSigner(f.chainId);case"offlineSignerAuto":return D(s).getOfflineSignerAuto(f.chainId);case"offlineSignerOnlyAmino":return D(s).getOfflineSignerOnlyAmino(f.chainId);default:return D(s).getOfflineSignerAuto(f.chainId)}}))(),S=(h=u.getState().chainsConfig)==null?void 0:h[f.chainId],y={url:f.rpc,headers:x({},(S==null?void 0:S.rpcHeaders)||{})},m=S!=null&&S.gas?GasPrice.fromString(`${S.gas.price}${S.gas.denom}`):void 0;return yield SigningCosmWasmClient.connectWithSigner(y,d,x({gasPrice:m},e!=null&&e.multiChain?(k=e.opts)==null?void 0:k[f.chainId]:(e==null?void 0:e.opts)||{}))}))}),enabled:!!t&&t.length>0&&!!i&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function Ca(e){let t=q({chainId:e.chainId,multiChain:e.multiChain}),i=u(s=>s.walletType),o=g(s=>s.activeChainIds),r=useMemo(()=>["USE_STARGATE_TM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]),{data:n}=Ae({type:e.type,chainId:e.chainId,multiChain:e.multiChain});return useQuery({queryKey:r,queryFn:c=>l(this,[c],function*({queryKey:[,s,a]}){if(s.length<1)throw new Error("No chains found");return yield z(!!e.multiChain,s,A=>l(this,null,function*(){var C;if(!(o!=null&&o.includes(A.chainId)))return null;if(!L(a))throw new Error(`${a} is not available`);if(!n)throw new Error("No tendermint client found");let S=yield (()=>l(this,null,function*(){switch(e.offlineSigner){case"offlineSigner":return D(a).getOfflineSigner(A.chainId);case"offlineSignerAuto":return D(a).getOfflineSignerAuto(A.chainId);case"offlineSignerOnlyAmino":return D(a).getOfflineSignerOnlyAmino(A.chainId);default:return D(a).getOfflineSignerAuto(A.chainId)}}))(),y=e.multiChain?n[A.chainId]:n;return yield SigningStargateClient.createWithSigner(y,S,e.multiChain?(C=e.opts)==null?void 0:C[A.chainId]:e.opts)}))}),enabled:!!t&&t.length>0&&!!i&&!!n&&(e.enabled!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function Sa(e){let t=q({chainId:e.chainId,multiChain:e.multiChain}),i=u(a=>a.walletType),o=g(a=>a.activeChainIds),r=useMemo(()=>["USE_COSMWASM_TM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]),{data:n}=Ae({type:e.type,chainId:e.chainId,multiChain:!1,enabled:!e.multiChain}),{data:s}=Ae({type:e.type,chainId:e.chainId,multiChain:!0,enabled:!!e.multiChain});return useQuery({queryKey:r,queryFn:f=>l(this,[f],function*({queryKey:[,a,c]}){if(a.length<1)throw new Error("No chains found");return yield z(!!e.multiChain,a,d=>l(this,null,function*(){var p,I;if(!(o!=null&&o.includes(d.chainId)))return null;if(!L(c))throw new Error(`${c} is not available`);let y=yield (()=>l(this,null,function*(){switch(e.offlineSigner){case"offlineSigner":return D(c).getOfflineSigner(d.chainId);case"offlineSignerAuto":return D(c).getOfflineSignerAuto(d.chainId);case"offlineSignerOnlyAmino":return D(c).getOfflineSignerOnlyAmino(d.chainId);default:return D(c).getOfflineSignerAuto(d.chainId)}}))(),m=(p=u.getState().chainsConfig)==null?void 0:p[d.chainId],C=m!=null&&m.gas?GasPrice.fromString(`${m.gas.price}${m.gas.denom}`):void 0,h=e.multiChain?s==null?void 0:s[d.chainId]:n;if(!h)throw new Error("No tendermint client found");return yield SigningCosmWasmClient.createWithSigner(h,y,x({gasPrice:C},e.multiChain?(I=e.opts)==null?void 0:I[d.chainId]:e.opts||{}))}))}),enabled:!!t&&t.length>0&&!!i&&(!!n||!we(s))&&(e.enabled!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}var Bt=({children:e})=>{let[t,i]=useState(!1);return useEffect(()=>{i(!0);},[]),jsx(Fragment,{children:t?e:null})};var Mn=()=>{let e=typeof window!="undefined"&&window.sessionStorage.getItem(Y)==="Active",{_reconnect:t,_onReconnectFailed:i,_reconnectConnector:o,iframeOptions:r,chains:n}=u(),{activeChainIds:s,wcSignClients:a}=g(),c=L(o||void 0);return useEffect(()=>{if(!r||r.autoConnect===!1||!r.allowedIframeParentOrigins.length||!n)return;new Cosmiframe(r.allowedIframeParentOrigins).isReady().then(A=>{if(A)return J({chainId:n.map(d=>d.chainId),walletType:"cosmiframe"})});},[r]),useEffect(()=>{if(o){if(!c)return;e&&s?U({onError:i}):!e&&t&&U({onError:i});}},[c]),useEffect(()=>{var f,A,d,S,y,m,C,h,k,p,I,b,R,K,_,ee,re,w,O,E;if(o){if(!c)return;o==="cosmostation"&&((A=(f=me()).subscription)==null||A.call(f,()=>{U({onError:i});})),o==="keplr"&&((S=(d=de()).subscription)==null||S.call(d,()=>{U({onError:i});})),o==="leap"&&((m=(y=fe()).subscription)==null||m.call(y,()=>{U({onError:i});})),o==="compass"&&((h=(C=ue()).subscription)==null||h.call(C,()=>{U({onError:i});})),o==="vectis"&&((p=(k=Se()).subscription)==null||p.call(k,()=>{U({onError:i});})),o==="walletconnect"&&a.has("walletconnect")&&((b=(I=j()).subscription)==null||b.call(I,()=>{U({onError:i});})),o==="station"&&((K=(R=Ce()).subscription)==null||K.call(R,()=>{U({onError:i});})),o==="xdefi"&&((ee=(_=he()).subscription)==null||ee.call(_,()=>{U({onError:i});})),o==="cosmiframe"&&((w=(re=pe()).subscription)==null||w.call(re,()=>{U({onError:i});})),o==="okx"&&((E=(O=ye()).subscription)==null||E.call(O,()=>{U({onError:i});}));}},[o,a,c]),null},Lt=()=>(Mn(),null);var Pn=new QueryClient({}),Va=o=>{var r=o,{children:e,grazOptions:t}=r,i=$e(r,["children","grazOptions"]);return useEffect(()=>{St(t);},[t]),jsx(QueryClientProvider,G(x({client:Pn},i),{children:jsxs(Bt,{children:[e,jsx(Lt,{})]})}),"graz-provider")};
19
+ var qt=Object.defineProperty,Ft=Object.defineProperties;var Gt=Object.getOwnPropertyDescriptors;var ce=Object.getOwnPropertySymbols;var Qe=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable;var ze=(e,t,i)=>t in e?qt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,x=(e,t)=>{for(var i in t||(t={}))Qe.call(t,i)&&ze(e,i,t[i]);if(ce)for(var i of ce(t))je.call(t,i)&&ze(e,i,t[i]);return e},G=(e,t)=>Ft(e,Gt(t));var $e=(e,t)=>{var i={};for(var o in e)Qe.call(e,o)&&t.indexOf(o)<0&&(i[o]=e[o]);if(e!=null&&ce)for(var o of ce(e))t.indexOf(o)<0&&je.call(e,o)&&(i[o]=e[o]);return i};var l=(e,t,i)=>new Promise((o,r)=>{var n=c=>{try{a(i.next(c));}catch(f){r(f);}},s=c=>{try{a(i.throw(c));}catch(f){r(f);}},a=c=>c.done?o(c.value):Promise.resolve(c.value).then(n,s);a((i=i.apply(e,t)).next());});var Y="graz-reconnect-session";var He=(p=>(p.KEPLR="keplr",p.LEAP="leap",p.VECTIS="vectis",p.COSMOSTATION="cosmostation",p.WALLETCONNECT="walletconnect",p.WC_KEPLR_MOBILE="wc_keplr_mobile",p.WC_LEAP_MOBILE="wc_leap_mobile",p.WC_COSMOSTATION_MOBILE="wc_cosmostation_mobile",p.WC_CLOT_MOBILE="wc_clot_mobile",p.METAMASK_SNAP_LEAP="metamask_snap_leap",p.METAMASK_SNAP_COSMOS="metamask_snap_cosmos",p.STATION="station",p.XDEFI="xdefi",p.CAPSULE="capsule",p.COSMIFRAME="cosmiframe",p.COMPASS="compass",p.INITIA="initia",p.OKX="okx",p))(He||{}),Ve=["keplr","leap","vectis","cosmostation","walletconnect","wc_keplr_mobile","wc_leap_mobile","wc_cosmostation_mobile","wc_clot_mobile","metamask_snap_leap","station","xdefi","capsule","metamask_snap_cosmos","cosmiframe","compass","initia","okx"];var Qt={iframeOptions:null,recentChainIds:null,chains:null,chainsConfig:null,capsuleConfig:null,capsuleState:null,multiChainFetchConcurrency:3,walletType:"keplr",walletConnect:{options:null,walletConnectModal:null},walletDefaultOptions:null,_notFoundFn:()=>null,_onReconnectFailed:()=>null,_reconnect:!1,_reconnectConnector:null},oe={accounts:null,activeChainIds:null,status:"disconnected",wcSignClients:new Map,capsuleClient:null},jt={name:"graz-session",version:2,partialize:e=>({accounts:e.accounts,activeChainIds:e.activeChainIds}),storage:createJSONStorage(()=>sessionStorage)},$t={name:"graz-internal",partialize:e=>({recentChainIds:e.recentChainIds,_reconnect:e._reconnect,_reconnectConnector:e._reconnectConnector,walletType:e.walletType}),version:2},g=create(subscribeWithSelector(persist(()=>oe,jt))),u=create(subscribeWithSelector(persist(()=>Qt,$t)));var le=()=>{var S,y;if(!((S=u.getState().capsuleConfig)!=null&&S.apiKey)||!((y=u.getState().capsuleConfig)!=null&&y.env))throw new Error("Capsule configuration is not set");let e=()=>l(void 0,null,function*(){var h,k;let m=(yield import('@leapwallet/cosmos-social-login-capsule-provider')).CapsuleProvider,C=new m({apiKey:(h=u.getState().capsuleConfig)==null?void 0:h.apiKey,env:(k=u.getState().capsuleConfig)==null?void 0:k.env});return g.setState({capsuleClient:C}),C});return {init:e,enable:m=>l(void 0,null,function*(){let C=typeof m=="string"?[m]:m,h=g.getState().capsuleClient;h||(h=yield e()),u.setState({capsuleState:{showModal:!0,chainId:C}});}),onAfterLoginSuccessful:()=>l(void 0,null,function*(){var p;let m=g.getState().capsuleClient,{chains:C}=u.getState();if(!m)throw new Error("Capsule client is not initialized");if(!C)throw new Error("Chains are not set");yield m.enable();let h=(p=u.getState().capsuleState)==null?void 0:p.chainId;if(!h)throw new Error("Chain ids are not set");let k=Object.fromEntries(yield Promise.all(h.map(I=>l(void 0,null,function*(){let b=yield m.getAccount(I);return [I,{address:fromBech32(b.address).data,bech32Address:b.address,algo:b.algo,name:b.username||"",pubKey:b.pubkey,isKeystone:!1,isNanoLedger:!1}]}))));g.setState(I=>({accounts:x(x({},I.accounts||{}),k)})),u.setState(I=>({recentChainIds:[...I.recentChainIds||[],...h].filter((b,R,K)=>K.indexOf(b)===R)})),g.setState(I=>({activeChainIds:[...I.activeChainIds||[],...h].filter((b,R,K)=>K.indexOf(b)===R)})),u.setState({walletType:"capsule",_reconnect:!1,_reconnectConnector:"capsule"}),g.setState({status:"connected"}),typeof window!="undefined"&&window.sessionStorage.setItem(Y,"Active"),u.setState({capsuleState:null});}),getKey:m=>l(void 0,null,function*(){let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");let h=yield C.getAccount(m);return {address:fromBech32(h.address).data,bech32Address:h.address,algo:h.algo,name:h.username||"",pubKey:h.pubkey,isKeystone:!1,isNanoLedger:!1}}),getOfflineSignerAuto:m=>l(void 0,null,function*(){let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerDirect(m)}),getOfflineSignerDirect:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerDirect(m)},signDirect:(...m)=>l(void 0,null,function*(){let[C,h,k]=m,p=g.getState().capsuleClient;if(!p)throw new Error("Capsule client is not initialized");return p.signDirect(C,h,{bodyBytes:k.bodyBytes,authInfoBytes:k.authInfoBytes,chainId:k.chainId,accountNumber:k.accountNumber})}),signAmino:(...m)=>l(void 0,null,function*(){let[C,h,k,p]=m,I=g.getState().capsuleClient;if(!I)throw new Error("Capsule client is not initialized");return I.signAmino(C,h,k,p)}),signArbitrary:(m,C,h)=>l(void 0,null,function*(){let k=g.getState().capsuleClient;if(!k)throw new Error("Capsule client is not initialized");let p=yield k.getAccount(m);if(!p)throw new Error(`Wallet not connected to account ${C}`);let I=(()=>{switch(p.algo){case"secp256k1":return encodeSecp256k1Pubkey(p.pubkey);case"ed25519":return encodeEd25519Pubkey(p.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {signature:yield k.signArbitrary(m,C,h),pub_key:{type:p.algo==="secp256k1"?pubkeyType.secp256k1:pubkeyType.ed25519,value:I.value}}}),experimentalSuggestChain:(...m)=>l(void 0,null,function*(){yield Promise.reject(new Error("Capsule does not support experimentalSuggestChain"));}),getOfflineSigner:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSigner(m)},getOfflineSignerAmino:m=>{let C=g.getState().capsuleClient;if(!C)throw new Error("Capsule client is not initialized");return C.getOfflineSignerAmino(m)}}};var ue=()=>{if(typeof window.compass!="undefined"){let e=window.compass;return Object.assign(e,{subscription:r=>{let n=()=>{N(),r();};return window.addEventListener("leap_keystorechange",n),()=>{window.removeEventListener("leap_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.leap is not defined")};var pe=()=>{let e=u.getState();if(!e.iframeOptions)throw e._notFoundFn(),new Error("no iframe options set");if(!isInIframe())throw e._notFoundFn(),new Error("not in iframe");if(!e.iframeOptions.allowedIframeParentOrigins.length)throw e._notFoundFn(),new Error("no iframe allowed origins");let t=new Cosmiframe(e.iframeOptions.allowedIframeParentOrigins).getKeplrClient();return {enable:t.enable.bind(t),getKey:t.getKey.bind(t),getOfflineSigner:t.getOfflineSigner.bind(t),getOfflineSignerAuto:t.getOfflineSignerAuto.bind(t),getOfflineSignerOnlyAmino:t.getOfflineSignerOnlyAmino.bind(t),experimentalSuggestChain:t.experimentalSuggestChain.bind(t),signDirect:t.signDirect.bind(t),signAmino:t.signAmino.bind(t)}};var it={},ot=()=>{let e=window.ethereum,t=window.cosmos;if(e)return {init:()=>l(void 0,null,function*(){var A;let n=yield e.request({method:"web3_clientVersion"});if(!n.includes("MetaMask"))throw new Error("Metamask is not installed");if(typeof window.okxwallet!="undefined"&&window.okxwallet.isOkxWallet)throw new Error("You have OKX Wallet installed. Please disable and reload the page to use Metamask Snap.");let a=(A=n.split("MetaMask/v")[1])==null?void 0:A.split(".")[0];if(!(Number(a)>=11))throw new Error("Metamask Snap is not supported in this version");return (yield isSnapInstalled())||(yield installSnap()),window.cosmos=new CosmosSnap,t=window.cosmos,!0}),enable:n=>l(void 0,null,function*(){(yield isSnapInstalled())||(yield installSnap());}),getOfflineSigner:n=>t.getOfflineSigner(n),experimentalSuggestChain:n=>l(void 0,null,function*(){if(!n.bech32Config)throw new Error("Bech32Config is required");if(!n.stakeCurrency)throw new Error("StakeCurrency is required");yield t.experimentalSuggestChain(G(x({},n),{stakeCurrency:n.stakeCurrency,bech32Config:n.bech32Config}));}),signAmino:(n,s,a)=>l(void 0,null,function*(){return t.signAmino(n,s,a)}),getKey:n=>l(void 0,null,function*(){return typeof it[n]!="undefined"?it[n]:t.getKey(n)}),getOfflineSignerAuto:n=>l(void 0,null,function*(){return (yield t.getKey(n)).isNanoLedger?t.getOfflineSignerOnlyAmino(n):t.getOfflineSigner(n)}),getOfflineSignerOnlyAmino:n=>t.getOfflineSignerOnlyAmino(n),signDirect:(n,s,a)=>l(void 0,null,function*(){return t.signDirect(n,s,a)}),signArbitrary:(n,s,a)=>l(void 0,null,function*(){return t.signArbitrary(n,s,a)}),disable:n=>l(void 0,null,function*(){n&&(yield t.deleteChain(n));})};throw u.getState()._notFoundFn(),new Error("window.ethereum is not defined")};var me=()=>{var e;if(typeof((e=window.cosmostation)==null?void 0:e.providers.keplr)!="undefined"){let t=window.cosmostation.providers.keplr;return Object.assign(t,{subscription:n=>{let s=()=>{N(),n();};return window.addEventListener("cosmostation_keystorechange",s),()=>{window.removeEventListener("cosmostation_keystorechange",s);}},setDefaultOptions:n=>{t.defaultOptions=n;}})}throw u.getState()._notFoundFn(),new Error("window.cosmostation.providers.keplr is not defined")};var on=e=>{let{bodyBytes:t,authInfoBytes:i,chainId:o,accountNumber:r}=e;if(!t||!i||!o||!r)throw new Error("Invalid sign doc");return {bodyBytes:t,authInfoBytes:i,chainId:o,accountNumber:r}},rn=e=>`${e.slice(0,6)}...${e.slice(-6)}`,st=()=>{if(typeof window.initia!="undefined"){let e=window.initia;return {enable:()=>l(void 0,null,function*(){yield e.getAddress();}),getKey:d=>l(void 0,null,function*(){let S=e.getOfflineSigner(d),[y]=yield S.getAccounts();if(!y)throw new Error("Wallet connection failed");let m=(()=>{switch(y.algo){case"secp256k1":return rawSecp256k1PubkeyToRawAddress(y.pubkey);case"ed25519":return rawEd25519PubkeyToRawAddress(y.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {name:rn(y.address),algo:y.algo,pubKey:y.pubkey,bech32Address:y.address,address:m,isNanoLedger:!1,isKeystone:!1}}),getOfflineSigner:d=>{let S=e.getOfflineSigner(d),y=e.getOfflineSignerOnlyAmino(d);return {getAccounts:S.getAccounts.bind(S),signDirect:S.signDirect.bind(S),signAmino:y.signAmino.bind(y)}},getOfflineSignerAuto:d=>Promise.resolve(e.getOfflineSigner(d)),getOfflineSignerOnlyAmino:d=>e.getOfflineSignerOnlyAmino(d),experimentalSuggestChain:d=>e.requestAddInitiaLayer({chain_id:d.chainId,chain_name:d.chainName,bech32_prefix:"init",bech32_config:d.bech32Config,slip44:d.bip44.coinType,logo_URIs:{png:d.chainSymbolImageUrl},fees:{fee_tokens:d.feeCurrencies.map(S=>{var y,m,C;return {denom:S.coinDenom,amount:S.coinMinimalDenom,low_gas_price:(y=S.gasPriceStep)==null?void 0:y.low,average_gas_price:(m=S.gasPriceStep)==null?void 0:m.average,high_gas_price:(C=S.gasPriceStep)==null?void 0:C.high}})},apis:{rpc:[{address:d.rpc}],rest:[{address:d.rest}]}}),signDirect:(...d)=>{let[S,y,m]=d;return e.getOfflineSigner(S).signDirect(y,on(m))},signAmino:(...d)=>{let[S,y,m]=d;return e.getOfflineSignerOnlyAmino(S).signAmino(y,m)},signArbitrary:(d,S,y)=>l(void 0,null,function*(){let h=(yield e.getOfflineSigner(d).getAccounts()).find(I=>I.address===S);if(!h)throw new Error(`Wallet not connected to account ${S}`);let k=(()=>{switch(h.algo){case"secp256k1":return encodeSecp256k1Pubkey(h.pubkey);case"ed25519":return encodeEd25519Pubkey(h.pubkey);default:throw new Error("sr25519 public key algorithm is not supported")}})();return {signature:yield e.signArbitrary(y),pub_key:{type:h.algo==="secp256k1"?pubkeyType.secp256k1:pubkeyType.ed25519,value:k.value}}}),subscription:d=>{let S=()=>{N(),d();};return window.addEventListener("initia_keystorechange",S),()=>{window.removeEventListener("initia_keystorechange",S);}}}}throw u.getState()._notFoundFn(),new Error("window.initia is not defined")};var de=()=>{if(typeof window.keplr!="undefined"){let e=window.keplr;return Object.assign(e,{subscription:r=>{let n=()=>{N(),r();};return window.addEventListener("keplr_keystorechange",n),()=>{window.removeEventListener("keplr_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.keplr is not defined")};var fe=()=>{if(typeof window.leap!="undefined"){let e=window.leap;return Object.assign(e,{subscription:r=>{let n=()=>{N(),r();};return window.addEventListener("leap_keystorechange",n),()=>{window.removeEventListener("leap_keystorechange",n);}},setDefaultOptions:r=>{e.defaultOptions=r;}})}throw u.getState()._notFoundFn(),new Error("window.leap is not defined")};var ge={},at=e=>{let t=window.ethereum;if(t&&e){let i=()=>l(void 0,null,function*(){return yield t.request({method:"wallet_getSnaps"})}),o=p=>l(void 0,null,function*(){try{let I=yield i();return Object.values(I).find(b=>b.id===e.id&&(!p||b.version===p))}catch(I){return}}),r=()=>l(void 0,null,function*(){yield t.request({method:"wallet_requestSnaps",params:{[e.id]:e.params||{}}});}),n=()=>l(void 0,null,function*(){var _;let p=yield t.request({method:"web3_clientVersion"});if(!p.includes("MetaMask"))throw new Error("Metamask is not installed");if(typeof window.okxwallet!="undefined"&&window.okxwallet.isOkxWallet)throw new Error("You have OKX Wallet installed. Please disable and reload the page to use Metamask Snap.");let b=(_=p.split("MetaMask/v")[1])==null?void 0:_.split(".")[0];if(!(Number(b)>=11))throw new Error("Metamask Snap is not supported in this version");return (yield o())||(yield r()),!0}),s=p=>l(void 0,null,function*(){(yield o())||(yield r());}),a=(p,I,b)=>l(void 0,null,function*(){let R=yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"signDirect",params:{chainId:p,signerAddress:I,signDoc:b}}}}),K=b.accountNumber,_=new sn(K.low,K.high,K.unsigned);return {signature:R.signature,signed:G(x({},R.signed),{accountNumber:`${_.toString()}`,authInfoBytes:new Uint8Array(Object.values(R.signed.authInfoBytes)),bodyBytes:new Uint8Array(Object.values(R.signed.bodyBytes))})}}),c=(p,I,b)=>l(void 0,null,function*(){return yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"signAmino",params:{chainId:p,signerAddress:I,signDoc:b}}}})}),f=p=>l(void 0,null,function*(){if(typeof ge[p]!="undefined")return ge[p];let I=yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"getKey",params:{chainId:p}}}});if(!I)throw new Error("No response from Metamask");return I.pubKey=Uint8Array.from(Object.values(I.pubkey)),delete I.pubkey,ge[p]=I,ge[p]}),A=p=>l(void 0,null,function*(){let I=yield f(p);return {address:I.bech32Address,algo:I.algo,pubkey:I.pubKey}}),d=(...p)=>l(void 0,null,function*(){let[I,b,R,K]=p;return yield c(I,b,R)}),S=(...p)=>l(void 0,null,function*(){let[I,b,R]=p;return yield a(I,b,R)}),m=p=>({getAccounts:()=>l(void 0,null,function*(){return [yield A(p)]}),signAmino:(I,b)=>d(p,I,b)});return {enable:s,experimentalSuggestChain:(...p)=>l(void 0,null,function*(){yield n(),yield t.request({method:"wallet_invokeSnap",params:{snapId:e.id,request:{method:"suggestChain",params:{chainInfo:p[0]}}}});}),getKey:f,getOfflineSigner:p=>({getAccounts:()=>l(void 0,null,function*(){return [yield A(p)]}),signDirect:(I,b)=>S(p,I,b),signAmino:(I,b)=>d(p,I,b)}),getOfflineSignerAuto:p=>l(void 0,null,function*(){return m(p)}),getOfflineSignerOnlyAmino:m,init:n,signAmino:d,signDirect:S}}throw u.getState()._notFoundFn(),new Error("window.ethereum is not defined")};var ct=()=>at({id:"npm:@leapwallet/metamask-cosmos-snap"});var ye=()=>{var e;if(typeof((e=window.okxwallet)==null?void 0:e.keplr)!="undefined"){let t=window.okxwallet.keplr;return Object.assign(t,{subscription:n=>{var a;let s=()=>{N(),n();};return (a=window.okxwallet)==null||a.on("accountsChanged",s),()=>{var c;(c=window.okxwallet)==null||c.removeListener("accountsChanged",s);}},setDefaultOptions:n=>{t.defaultOptions=n;}})}throw u.getState()._notFoundFn(),new Error("window.okxwallet.keplr is not defined")};var Ce=()=>{if(typeof window.station!="undefined"){let e=window.station.keplr;return {subscription:n=>{let s=()=>{N(),n();};return window.addEventListener("station_wallet_change",s),()=>{window.removeEventListener("station_wallet_change",s);}},getKey:n=>l(void 0,null,function*(){let s=yield e.getKey(n);return x({isKeystone:!1},s)}),getOfflineSigner:n=>{try{let s=e.getOfflineSignerOnlyAmino(n);return Object.assign(s,{signDirect:(f,A)=>{throw new Error("signDirect not supported by Station")}})}catch(s){throw console.error(s),s}},experimentalSuggestChain:n=>l(void 0,null,function*(){try{if(!n.bech32Config)throw new Error("Bech32Config is required");if(!n.stakeCurrency)throw new Error("StakeCurrency is required");let s=Object.assign(n,{bech32Config:n.bech32Config,chainSymbolImageUrl:n.chainSymbolImageUrl||"",stakeCurrency:{coinDecimals:n.stakeCurrency.coinDecimals,coinDenom:n.stakeCurrency.coinDenom,coinImageUrl:n.stakeCurrency.coinImageUrl||"",coinMinimalDenom:n.stakeCurrency.coinMinimalDenom},currencies:n.currencies.map(a=>({coinDecimals:a.coinDecimals,coinDenom:a.coinDenom,coinImageUrl:a.coinImageUrl||"",coinMinimalDenom:a.coinMinimalDenom})),feeCurrencies:n.feeCurrencies.map(a=>{var c,f,A;return {coinDecimals:a.coinDecimals,coinDenom:a.coinDenom,coinImageUrl:a.coinImageUrl||"",coinMinimalDenom:a.coinMinimalDenom,gasPriceStep:{average:((c=a.gasPriceStep)==null?void 0:c.average)||0,high:((f=a.gasPriceStep)==null?void 0:f.high)||0,low:((A=a.gasPriceStep)==null?void 0:A.low)||0}}})});yield e.experimentalSuggestChain(s);}catch(s){throw console.error(s),s}}),enable:n=>e.enable(n),disable:n=>e.disable(n),getOfflineSignerAuto:n=>e.getOfflineSignerAuto(n),getOfflineSignerOnlyAmino:n=>e.getOfflineSignerOnlyAmino(n),signDirect:()=>e.signDirect(),signAmino:(n,s,a,c)=>e.signAmino(n,s,a)}}throw u.getState()._notFoundFn(),new Error("window.station is not defined")};var Se=()=>{if(typeof window.vectis!="undefined"){let e=window.vectis.cosmos;return {enable:a=>e.enable(a),getOfflineSigner:a=>e.getOfflineSigner(a),getOfflineSignerAuto:a=>e.getOfflineSignerAuto(a),getKey:a=>l(void 0,null,function*(){let c=yield e.getKey(a);return {address:fromBech32(c.address).data,algo:c.algo,bech32Address:c.address,name:c.name,pubKey:c.pubKey,isKeystone:!1,isNanoLedger:c.isNanoLedger}}),subscription:a=>{let c=()=>{N(),a();};return window.addEventListener("vectis_accountChanged",c),()=>{window.removeEventListener("vectis_accountChanged",c);}},getOfflineSignerOnlyAmino:(...a)=>{let c=a[0];return e.getOfflineSignerAmino(c)},experimentalSuggestChain:(...a)=>l(void 0,null,function*(){var A;let[c]=a;if(!c.bech32Config)throw new Error("Bech32Config is required");if(!c.stakeCurrency)throw new Error("StakeCurrency is required");let f={rpcUrl:c.rpc,restUrl:c.rest,prettyName:c.chainName.replace(" ",""),bech32Prefix:(A=c.bech32Config)==null?void 0:A.bech32PrefixAccAddr,currencies:c.currencies,feeCurrencies:c.feeCurrencies,chainId:c.chainId,chainName:c.chainName,bip44:c.bip44,stakeCurrency:c.stakeCurrency,features:c.features};return e.suggestChains([f])}),signDirect:(...a)=>l(void 0,null,function*(){var A;let{1:c,2:f}=a;return e.signDirect(c,{bodyBytes:f.bodyBytes||Uint8Array.from([]),authInfoBytes:f.authInfoBytes||Uint8Array.from([]),accountNumber:sn.fromString(((A=f.accountNumber)==null?void 0:A.toString())||"",!1),chainId:f.chainId||""})}),signAmino:(...a)=>l(void 0,null,function*(){let{1:c,2:f}=a;return e.signAmino(c,f)})}}throw u.getState()._notFoundFn(),new Error("window.vectis is not defined")};var Q=()=>{if(typeof window!="undefined"){let e=navigator.userAgent;return !!(/android/i.test(e)||/iPad|iPhone|iPod/.test(e))}return !1},lt=()=>Q()&&navigator.userAgent.toLowerCase().includes("android"),ut=()=>Q()&&(navigator.userAgent.toLowerCase().includes("iphone")||navigator.userAgent.toLowerCase().includes("ipad"));var ve=(e,t,i=new Error("Promise timed out"))=>{let o=new Promise((r,n)=>{setTimeout(()=>{n(i);},t);});return Promise.race([e,o])};var j=e=>{var _,ee,re;if(!((re=(ee=(_=u.getState().walletConnect)==null?void 0:_.options)==null?void 0:ee.projectId)!=null&&re.trim()))throw new Error("walletConnect.options.projectId is not defined");let t=(e==null?void 0:e.walletType)||"walletconnect",i=(e==null?void 0:e.encoding)||"base64",o=w=>{if(!e)return;let{appUrl:O,formatNativeUrl:E}=e;if(Q()){if(lt())if(!w)window.open(O.mobile.android,"_self","noreferrer noopener");else {let v=E(O.mobile.android,w,"android");window.open(v,"_self","noreferrer noopener");}if(ut())if(!w)window.open(O.mobile.ios,"_self","noreferrer noopener");else {let v=E(O.mobile.ios,w,"ios");window.open(v,"_self","noreferrer noopener");}}},r=()=>{let{wcSignClients:w}=g.getState();if(!w.get(t))throw new Error("walletConnect.signClient is not defined");w.delete(t),g.setState({wcSignClients:w}),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null});},n=w=>l(void 0,null,function*(){let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");if(!w)throw new Error("No wallet connect session");yield E.disconnect({topic:w,reason:getSdkError("USER_DISCONNECTED")}),yield c(E);}),s=w=>{try{let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");let v=E.session.getAll(),P=v.at(-1);if(!P)return;if(!(P.expiry*1e3>Date.now()+1e3))throw n(P.topic),new Error("invalid session");try{let q=v.find($=>{var H,te;return (te=(H=$.requiredNamespaces.cosmos)==null?void 0:H.chains)==null?void 0:te.includes(`cosmos:${w}`)});if(!q)throw new Error("no session");return q}catch(q){if(!q.message.toLowerCase().includes("no matching key"))throw q}return P}catch(O){if(!O.message.toLowerCase().includes("no matching key"))throw O}},a=w=>{try{return s(w)}catch(O){return}},c=w=>l(void 0,null,function*(){try{let O=w.core.pairing.pairings.getAll({active:!1});if(!O.length)return;yield Promise.all(O.map(E=>l(void 0,null,function*(){yield w.core.pairing.pairings.delete(E.topic,{code:7001,message:"clear pairing"});})));}catch(O){if(!O.message.toLowerCase().includes("no matching key"))throw O}}),f=()=>l(void 0,null,function*(){let{walletConnect:w}=u.getState();if(!(w!=null&&w.options))throw new Error("walletConnect.options is not defined");let{wcSignClients:O}=g.getState(),E=O.get(t);if(E)return E;let v=yield SignClient.init(w.options);return O.set(t,v),g.setState({wcSignClients:O}),v}),A=w=>{let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)return ()=>{};let v=P=>{let W=g.getState().accounts;P.params.event.name==="accountsChanged"&&W&&!Object.values(W).map(q=>q.bech32Address).includes(P.params.event.data[0])&&w();};return E.events.on("session_delete",r),E.events.on("session_expire",r),E.events.on("session_event",v),()=>{E.events.off("session_delete",r),E.events.off("session_expire",r),E.events.off("session_event",v);}},d=w=>l(void 0,null,function*(){var te;let O=typeof w=="string"?[w]:w,{wcSignClients:E,activeChainIds:v}=g.getState(),P=E.get(t);if(!P)throw new Error("enable walletConnect.signClient is not defined");let{walletConnect:W,chains:q}=u.getState();if(!((te=W==null?void 0:W.options)!=null&&te.projectId))throw new Error("walletConnect.options.projectId is not defined");let $=new WalletConnectModal(x({projectId:W.options.projectId,enableExplorer:!1,explorerRecommendedWalletIds:"NONE"},W.walletConnectModal)),H=a(O);if(!H){let{uri:F,approval:ne}=yield ve(P.connect({requiredNamespaces:{cosmos:{methods:["cosmos_getAccounts","cosmos_signAmino","cosmos_signDirect"],chains:O.map(V=>`cosmos:${V}`),events:["chainChanged","accountsChanged"]}}}),15e3,new Error("Connection timeout"));if(!F)throw new Error("No wallet connect uri");e?o(F):yield $.openModal({uri:F});let ae=V=>l(void 0,null,function*(){return V.aborted?Promise.reject(new Error("User closed wallet connect")):new Promise((ke,ie)=>{ne().then(qe=>{let Fe=qe.sessionProperties;if(!Fe)return ie(new Error("No session properties"));let xe=JSON.parse(String(Fe.keys));if(xe.length===0)return ie(new Error("No accounts"));if(!xe[0])return ie(new Error("No accounts"));let Ge={};return xe.forEach(X=>{Ge[X.chainId]={address:X.address,algo:X.algo,bech32Address:X.bech32Address,isNanoLedger:X.isNanoLedger,isKeystone:X.isKeystone,name:X.name,pubKey:X.pubKey};}),g.setState(X=>({accounts:x(x({},X.accounts||{}),Ge)})),ke(qe)}).catch(ie),V.addEventListener("abort",()=>{ie(new Error("User closed wallet connect"));},{once:!0});})});try{let V=new AbortController,ke=V.signal;$.subscribeModal(ie=>{ie.open||V.abort();}),yield ae(ke);}catch(V){if($.closeModal(),!V.message.toLowerCase().includes("no matching key"))return Promise.reject(V)}return e||$.closeModal(),Promise.resolve()}try{yield ve((()=>l(void 0,null,function*(){var ne;let F=Object.fromEntries(yield Promise.all((ne=v||O)==null?void 0:ne.map(ae=>l(void 0,null,function*(){return [ae,yield y(ae)]}))));g.setState({accounts:F});}))(),15e3,new Error("Connection timeout"));}catch(F){if(n(H.topic),!F.message.toLowerCase().includes("no matching key"))throw F}}),S=w=>l(void 0,null,function*(){var W;let{wcSignClients:O}=g.getState(),E=O.get(t);if(!E)throw new Error("walletConnect.signClient is not defined");let v=(W=s([w]))==null?void 0:W.topic;if(!v)throw new Error("No wallet connect session");let P=yield E.request({topic:v,chainId:`cosmos:${w}`,request:{method:"cosmos_getAccounts",params:{}}});if(!P[0])throw new Error("No wallet connect account");return {address:P[0].address,algo:P[0].algo,pubkey:new Uint8Array(Buffer.from(P[0].pubkey,i))}}),y=w=>l(void 0,null,function*(){let O=s([w]);if(!(O!=null&&O.topic))throw new Error("No wallet connect session");let E=O.sessionProperties&&JSON.parse(String(O.sessionProperties.keys));if(!E)throw new Error("No wallet connect key");if(E.length===0)throw new Error("No wallet connect session");let v=E.find(P=>P.chainId===w);if(!v)throw new Error(`No wallet connect key for chainId ${w}`);return v}),m=(...w)=>l(void 0,null,function*(){var F,ne;let[O,E,v]=w,{accounts:P,wcSignClients:W}=g.getState(),q=W.get(t);if(!q)throw new Error("walletConnect.signClient is not defined");if(!P)throw new Error("account is not defined");let $=(F=s([O]))==null?void 0:F.topic;if(!$)throw new Error("No wallet connect session");if(!v.bodyBytes)throw new Error("No bodyBytes");if(!v.authInfoBytes)throw new Error("No authInfoBytes");let H={topic:$,chainId:`cosmos:${O}`,request:{method:"cosmos_signDirect",params:{signerAddress:E,signDoc:G(x({},v),{bodyBytes:Buffer.from(v.bodyBytes).toString(i),authInfoBytes:Buffer.from(v.authInfoBytes).toString(i),accountNumber:(ne=v.accountNumber)==null?void 0:ne.toString()})}}};return o(),yield q.request(H)}),C=(...w)=>l(void 0,null,function*(){let[O,E,v]=w,{signature:P,signed:W}=yield m(O,E,v);return {signed:{chainId:W.chainId,accountNumber:sn.fromString(W.accountNumber,!1),authInfoBytes:new Uint8Array(Buffer.from(W.authInfoBytes,i)),bodyBytes:new Uint8Array(Buffer.from(W.bodyBytes,i))},signature:P}}),h=(...w)=>l(void 0,null,function*(){var F;let[O,E,v,P]=w,{wcSignClients:W}=g.getState(),q=W.get(t),{accounts:$}=g.getState();if(!q)throw new Error("walletConnect.signClient is not defined");if(!$)throw new Error("account is not defined");let H=(F=s([O]))==null?void 0:F.topic;if(!H)throw new Error("No wallet connect session");return o(),yield q.request({topic:H,chainId:`cosmos:${O}`,request:{method:"cosmos_signDirect",params:{signerAddress:E,signDoc:v}}})}),k=(...w)=>l(void 0,null,function*(){let[O,E,v,P]=w;return yield h(O,E,v)}),p=w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signDirect:(O,E)=>C(w,O,E)}),I=w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signAmino:(O,E)=>k(w,O,E)});return {enable:d,disable:w=>l(void 0,null,function*(){var v;let{wcSignClients:O}=g.getState(),E=O.get(t);if(w===void 0){let P=E==null?void 0:E.session.getAll();P!==void 0&&(yield Promise.all(P.map(W=>n(W.topic))));}else typeof w=="string"?yield n((v=s([w]))==null?void 0:v.topic):yield Promise.all(w.map(P=>{var W;return n((W=s([P]))==null?void 0:W.topic)}));(E==null?void 0:E.session.getAll().length)===0&&r();}),experimentalSuggestChain:(...w)=>l(void 0,null,function*(){yield Promise.reject(new Error("WalletConnect does not support experimentalSuggestChain"));}),getKey:y,getOfflineSigner:w=>({getAccounts:()=>l(void 0,null,function*(){return [yield S(w)]}),signDirect:(O,E)=>C(w,O,E),signAmino:(O,E)=>k(w,O,E)}),getOfflineSignerAuto:w=>l(void 0,null,function*(){return (yield y(w)).isNanoLedger?I(w):p(w)}),getOfflineSignerOnlyAmino:I,signAmino:k,signDirect:C,subscription:A,init:f}};var pt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!Q())throw new Error("WalletConnect Clot mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{android:"clot://",ios:"clot://"}},walletType:"wc_clot_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;default:return `${a}://wc?uri=${c}`}}};return j(e)};var mt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!Q())throw new Error("WalletConnect Cosmostation mobile is only supported in mobile");let e={encoding:"hex",appUrl:{mobile:{ios:"cosmostation://",android:"cosmostation://"}},walletType:"wc_cosmostation_mobile",formatNativeUrl:(r,n,s)=>`${r.replaceAll("/","").replaceAll(":","")}://wc?${n}`};return j(e)};var dt=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!Q())throw new Error("WalletConnect Keplr mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{ios:"keplrwallet://",android:"intent://"}},walletType:"wc_keplr_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;case"android":return `${a}://wcV2?${c}#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;`;default:return `${a}://wc?uri=${c}`}}};return j(e)};var ft=()=>{var t,i,o;if(!((o=(i=(t=u.getState().walletConnect)==null?void 0:t.options)==null?void 0:i.projectId)!=null&&o.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!Q())throw new Error("WalletConnect Leap mobile is only supported in mobile");let e={encoding:"base64",appUrl:{mobile:{ios:"leapcosmos://",android:"intent://"}},walletType:"wc_leap_mobile",formatNativeUrl:(r,n,s)=>{let a=r.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(n);switch(s){case"ios":return `${a}://wcV2?${c}`;case"android":return `${a}://wcV2?${c}#Intent;package=io.leapwallet.cosmos;scheme=leapwallet;end;`;default:return `${a}://wc?uri=${c}`}}};return j(e)};var he=()=>{var e;if(typeof((e=window.xfi)==null?void 0:e.keplr)!="undefined"){let t=window.xfi.keplr;return Object.assign(t,{subscription:r=>{let n=()=>{N(),r();};return window.addEventListener("keplr_keystorechange",n),()=>{window.removeEventListener("keplr_keystorechange",n);}}})}throw u.getState()._notFoundFn(),new Error("window.xfi.keplr is not defined")};var B=(e=u.getState().walletType)=>{try{return D(e),!0}catch(t){return !1}},N=()=>{window.sessionStorage.removeItem(Y),g.setState(oe);},D=(e=u.getState().walletType)=>{var o;let t=(()=>{switch(e){case"keplr":return de();case"leap":return fe();case"cosmostation":return me();case"vectis":return Se();case"walletconnect":return j();case"wc_keplr_mobile":return dt();case"wc_leap_mobile":return ft();case"wc_cosmostation_mobile":return mt();case"wc_clot_mobile":return pt();case"metamask_snap_leap":return ct();case"metamask_snap_cosmos":return ot();case"station":return Ce();case"xdefi":return he();case"capsule":return le();case"cosmiframe":return pe();case"compass":return ue();case"initia":return st();case"okx":return ye();default:throw new Error("Unknown wallet type")}})(),i=u.getState().walletDefaultOptions;return i&&((o=t.setDefaultOptions)==null||o.call(t,i)),t},rr=()=>Object.fromEntries(Ve.map(e=>[e,B(e)])),Pe=e=>e==="capsule",gt=e=>e==="walletconnect"||e==="wc_keplr_mobile"||e==="wc_leap_mobile"||e==="wc_cosmostation_mobile";var J=e=>l(void 0,null,function*(){var t;try{let{recentChainIds:i,chains:o,walletType:r}=u.getState(),n=(e==null?void 0:e.walletType)||r;if(!B(n))throw new Error(`${n} is not available`);let a=D(n),c=typeof(e==null?void 0:e.chainId)=="string"?[e.chainId]:(e==null?void 0:e.chainId)||i;if(!c)throw new Error("No last known connected chain, connect action requires chain ids");let f=o==null?void 0:o.map(y=>y.chainId);c.forEach(y=>{if(!(f!=null&&f.includes(y)))throw new Error(`Chain ${y} is not provided in GrazProvider`)}),g.setState(y=>{let m=u.getState()._reconnect||!!u.getState()._reconnectConnector||!!c;return y.activeChainIds&&c.filter(h=>{var k;return !((k=y.activeChainIds)!=null&&k.includes(h))}).length>0?{status:"connecting"}:m?{status:"reconnecting"}:{status:"connecting"}});let{accounts:A}=g.getState();if(yield (t=a.init)==null?void 0:t.call(a),Pe(n)&&g.getState().capsuleClient&&Object.values(g.getState().accounts||[]).length>0){let y=c.map(h=>o.find(k=>k.chainId===h)),m=g.getState().accounts;g.setState({status:"connecting"});let C=Object.fromEntries(yield Promise.all(c.map(h=>l(void 0,null,function*(){return [h,yield a.getKey(h)]}))));return g.setState(h=>({accounts:x(x({},h.accounts||{}),C)})),u.setState(h=>({recentChainIds:[...h.recentChainIds||[],...c].filter((k,p,I)=>I.indexOf(k)===p)})),g.setState(h=>({activeChainIds:[...h.activeChainIds||[],...c].filter((k,p,I)=>I.indexOf(k)===p)})),g.setState({status:"connected"}),{accounts:m,walletType:n,chains:y}}if(yield a.enable(c),Pe(n)){let y=c.map(C=>o.find(h=>h.chainId===C)),m=g.getState().accounts;return g.setState({status:"connecting"}),{accounts:m,walletType:n,chains:y}}if(!gt(n)){let y=Object.fromEntries(yield Promise.all(c.map(m=>l(void 0,null,function*(){return [m,yield a.getKey(m)]}))));g.setState(m=>({accounts:x(x({},m.accounts||{}),y)}));}u.setState(y=>({recentChainIds:[...y.recentChainIds||[],...c].filter((m,C,h)=>h.indexOf(m)===C)})),g.setState(y=>({activeChainIds:[...y.activeChainIds||[],...c].filter((m,C,h)=>h.indexOf(m)===C)})),u.setState({walletType:n,_reconnect:!!(e!=null&&e.autoReconnect),_reconnectConnector:n}),g.setState({status:"connected"}),typeof window!="undefined"&&window.sessionStorage.setItem(Y,"Active");let d=c.map(y=>o.find(m=>m.chainId===y));return {accounts:g.getState().accounts,walletType:n,chains:d}}catch(i){throw console.error("connect ",i),g.getState().accounts===null&&g.setState({status:"disconnected"}),g.getState().accounts&&g.getState().activeChainIds&&g.setState({status:"connected"}),i}}),se=e=>{typeof window!="undefined"&&window.sessionStorage.removeItem(Y);let t=typeof(e==null?void 0:e.chainId)=="string"?[e.chainId]:e==null?void 0:e.chainId;if(t){let i=g.getState().accounts;t.forEach(r=>{i==null||delete i[r];}),Object.values(i||{}).length===0?(g.setState(oe),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null})):(g.setState(r=>{var n;return {activeChainIds:(n=r.activeChainIds)==null?void 0:n.filter(s=>!t.includes(s)),accounts:i}}),u.setState(r=>{var n;return {recentChainIds:(n=r.recentChainIds)==null?void 0:n.filter(s=>!t.includes(s))}}));}else g.setState(oe),u.setState({_reconnect:!1,_reconnectConnector:null,recentChainIds:null});return Promise.resolve()},L=e=>l(void 0,null,function*(){var r;let{recentChainIds:t,_reconnectConnector:i,_reconnect:o}=u.getState();try{let n=B(i||void 0);if(t&&n&&i)return yield J({chainId:t,walletType:i,autoReconnect:o})}catch(n){(r=e==null?void 0:e.onError)==null||r.call(e,n),se();}}),yt=e=>l(void 0,null,function*(){if(!(e!=null&&e.chainId))throw new Error("chainId is required");let{walletType:t}=u.getState(),i=e.walletType||t;if(!B(i))throw new Error(`${i} is not available`);let r=D(i),n=r.getOfflineSigner(e.chainId),s=r.getOfflineSignerOnlyAmino(e.chainId),a=yield r.getOfflineSignerAuto(e.chainId);return {offlineSigner:n,offlineSignerAmino:s,offlineSignerAuto:a}});var We=()=>{u.setState({recentChainIds:null});},Cr=()=>u.getState().recentChainIds,Sr=()=>{var i;let{recentChainIds:e,chains:t}=u.getState();return (i=e==null?void 0:e.map(o=>t.find(r=>r.chainId===o)))!=null?i:null},hr=({chainId:e})=>{var t;return (t=u.getState().chains)==null?void 0:t.find(i=>i.chainId===e)},wr=({chainId:e})=>{var t;return (t=u.getState().chains)==null?void 0:t.filter(i=>e==null?void 0:e.includes(i.chainId))},Re=i=>l(void 0,[i],function*({chainInfo:e,walletType:t}){let o=D(t);return t==="capsule"?yield J({chainId:e.chainId,walletType:t}):yield o.experimentalSuggestChain(e),e}),Ct=e=>l(void 0,null,function*(){var o;let t=u.getState().walletType;return yield Re({chainInfo:e.chainInfo,walletType:(o=e.walletType)!=null?o:t}),yield J({chainId:e.chainInfo.chainId,walletType:e.walletType,autoReconnect:e.autoReconnect})});var St=e=>(u.setState(t=>({iframeOptions:e.iframeOptions||t.iframeOptions,walletConnect:e.walletConnect||t.walletConnect,walletType:e.defaultWallet||t.walletType,capsuleConfig:e.capsuleConfig||t.capsuleConfig,walletDefaultOptions:e.walletDefaultOptions||t.walletDefaultOptions,chains:e.chains,chainsConfig:e.chainsConfig||t.chainsConfig,multiChainFetchConcurrency:e.multiChainFetchConcurrency||t.multiChainFetchConcurrency,_notFoundFn:e.onNotFound||t._notFoundFn,_onReconnectFailed:e.onReconnectFailed||t._onReconnectFailed,_reconnect:e.autoReconnect===void 0?!0:e.autoReconnect||t._reconnect})),e);var ht=s=>l(void 0,[s],function*({signingClient:e,senderAddress:t,recipientAddress:i,amount:o,fee:r,memo:n}){if(!e)throw new Error("No connected account detected");if(!t)throw new Error("senderAddress is not defined");return e.sendTokens(t,i,o,r,n)}),wt=A=>l(void 0,[A],function*({signingClient:e,senderAddress:t,recipientAddress:i,transferAmount:o,sourcePort:r,sourceChannel:n,timeoutHeight:s,timeoutTimestamp:a,fee:c,memo:f}){if(!e)throw new Error("Stargate signing client is not ready");if(!t)throw new Error("senderAddress is not defined");return e.sendIbcTokens(t,i,o,r,n,s,a,c,f)}),At=a=>l(void 0,[a],function*({signingClient:e,senderAddress:t,msg:i,fee:o,options:r,label:n,codeId:s}){if(!e)throw new Error("CosmWasm signing client is not ready");return e.instantiate(t,s,i,n,o,r)}),It=a=>l(void 0,[a],function*({signingClient:e,senderAddress:t,msg:i,fee:o,contractAddress:r,funds:n,memo:s}){if(!e)throw new Error("CosmWasm signing client is not ready");return e.execute(t,r,i,o,s,n)}),Ot=(e,t,i)=>l(void 0,null,function*(){if(!i)throw new Error("CosmWasm client is not ready");return yield i.queryContractSmart(e,t)}),Et=(e,t,i)=>{if(!i)throw new Error("CosmWasm client is not ready");let o=new TextEncoder().encode(t);return i.queryContractRaw(e,o)};var vr=e=>e,Pr=e=>e;var we=e=>e?Object.keys(e).length===0:!0;var De=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t;}},bt=e=>globalThis.DOMException===void 0?new De(e):new DOMException(e),Tt=e=>{let t=e.reason===void 0?bt("This operation was aborted."):e.reason;return t instanceof Error?t:bt(t)};function Ke(n,s){return l(this,arguments,function*(e,t,{concurrency:i=Number.POSITIVE_INFINITY,stopOnError:o=!0,signal:r}={}){return new Promise((a,c)=>{if(e[Symbol.iterator]===void 0&&e[Symbol.asyncIterator]===void 0)throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof e})`);if(typeof t!="function")throw new TypeError("Mapper function is required");if(!((Number.isSafeInteger(i)||i===Number.POSITIVE_INFINITY)&&i>=1))throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${i}\` (${typeof i})`);let f=[],A=[],d=new Map,S=!1,y=!1,m=!1,C=0,h=0,k=e[Symbol.iterator]===void 0?e[Symbol.asyncIterator]():e[Symbol.iterator](),p=b=>{S=!0,y=!0,c(b);};r&&(r.aborted&&p(Tt(r)),r.addEventListener("abort",()=>{p(Tt(r));}));let I=()=>l(this,null,function*(){if(y)return;let b=yield k.next(),R=h;if(h++,b.done){if(m=!0,C===0&&!y){if(!o&&A.length>0){p(new AggregateError(A));return}if(y=!0,d.size===0){a(f);return}let K=[];for(let[_,ee]of f.entries())d.get(_)!==Mt&&K.push(ee);a(K);}return}C++,l(this,null,function*(){try{let K=yield b.value;if(y)return;let _=yield t(K,R);_===Mt&&d.set(R,_),f[R]=_,C--,yield I();}catch(K){if(o)p(K);else {A.push(K),C--;try{yield I();}catch(_){p(_);}}}});});l(this,null,function*(){for(let b=0;b<i;b++){try{yield I();}catch(R){p(R);break}if(m||S)break}});})})}var Mt=Symbol("skip");var U=({chainId:e,multiChain:t})=>{let i=u(r=>r.chains);if(!i)throw new Error("No chains found in GrazProvider");let o=typeof e=="string"?[e]:e;switch(!0){case(!!t&&!!o):return o.map(r=>i.find(n=>n.chainId===r)).filter(Boolean);case(!t&&!!o):return [o.map(r=>i.find(n=>n.chainId===r)).filter(Boolean)[0]];case(!!t&&!o):return i;default:return [i[0]]}},z=(e,t,i)=>l(void 0,null,function*(){let o=u.getState().multiChainFetchConcurrency;if(e){let n=yield Ke(t,i,{concurrency:o});return Object.fromEntries(n.map((s,a)=>[t[a].chainId,s]))}return yield i(t[0])}),kt=(e,t,i)=>{if(e){let r=t.map(i);return Object.fromEntries(r.map((n,s)=>[t[s].chainId,n]))}return i(t[0])};var Be=e=>{let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=useMemo(()=>["USE_STARGATE_CLIENT",t],[t]);return useQuery({queryKey:i,queryFn:r=>l(void 0,[r],function*({queryKey:[,o]}){if(o.length<1)throw new Error("No chains found");return yield z(!!(e!=null&&e.multiChain),o,s=>l(void 0,null,function*(){var A;let a=(A=u.getState().chainsConfig)==null?void 0:A[s.chainId],c={url:s.rpc,headers:x({},(a==null?void 0:a.rpcHeaders)||{})};return yield StargateClient.connect(c)}))}),enabled:!!t&&t.length>0&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})},Le=e=>{let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=useMemo(()=>["USE_COSMWASM_CLIENT",t],[t]);return useQuery({queryKey:i,queryFn:r=>l(void 0,[r],function*({queryKey:[,o]}){if(o.length<1)throw new Error("No chains found");return yield z(!!(e!=null&&e.multiChain),o,s=>l(void 0,null,function*(){var A;let a=(A=u.getState().chainsConfig)==null?void 0:A[s.chainId],c={url:s.rpc,headers:x({},(a==null?void 0:a.rpcHeaders)||{})};return yield CosmWasmClient.connect(c)}))}),enabled:!!t&&t.length>0&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})},Ae=({type:e,chainId:t,multiChain:i,enabled:o})=>{let r=U({chainId:t,multiChain:i}),n=useMemo(()=>["USE_TENDERMINT_CLIENT",e,r],[e,r]);return useQuery({queryKey:n,queryFn:c=>l(void 0,[c],function*({queryKey:[,s,a]}){if(a.length<1)throw new Error("No chains found");return yield z(!!i,a,A=>l(void 0,null,function*(){var C;let d=(C=u.getState().chainsConfig)==null?void 0:C[A.chainId],S={url:A.rpc,headers:x({},(d==null?void 0:d.rpcHeaders)||{})};return yield (s==="tm37"?Tendermint37Client:Tendermint34Client).connect(S)}))}),enabled:!!r&&r.length>0&&(o!==void 0?!!o:!0),refetchOnWindowFocus:!1})};var os=()=>u(e=>({walletType:e.walletType,isCosmostation:e.walletType==="cosmostation",isCosmostationMobile:e.walletType==="wc_cosmostation_mobile",isKeplr:e.walletType==="keplr",isKeplrMobile:e.walletType==="wc_keplr_mobile",isLeap:e.walletType==="leap",isLeapMobile:e.walletType==="wc_leap_mobile",isVectis:e.walletType==="vectis",isWalletConnect:e.walletType==="walletconnect",isMetamaskSnapLeap:e.walletType==="metamask_snap_leap",isStation:e.walletType==="station",isCapsule:e.walletType==="capsule",isCosmiframe:e.walletType==="cosmiframe"}),shallow),Ie=e=>{let i=["USE_CHECK_WALLET",u(r=>e||r.walletType)];return useQuery(i,({queryKey:[,r]})=>B(r))};var Z=e=>{let t=u(a=>a.walletType),i=g(a=>a.activeChainIds),o=U({chainId:e!=null&&e.chainId?e.chainId:i||void 0,multiChain:e==null?void 0:e.multiChain}),r=g(a=>a.accounts),n=g(a=>a.status);return useEffect(()=>g.subscribe(a=>a.status,(a,c)=>{var f,A,d;if(a==="connected"){let{accounts:S,activeChainIds:y}=g.getState(),{chains:m}=u.getState(),{walletType:C}=u.getState();if(!S||!y||!m)return (f=e==null?void 0:e.onDisconnect)==null?void 0:f.call(e);(A=e==null?void 0:e.onConnect)==null||A.call(e,{accounts:S,chains:y.map(h=>m.find(k=>k.chainId===h)),walletType:C,isReconnect:c==="reconnecting"});}a==="disconnected"&&((d=e==null?void 0:e.onDisconnect)==null||d.call(e));}),[e]),{data:useMemo(()=>r?kt(!!(e!=null&&e.multiChain),o,a=>r[a.chainId]):void 0,[r,o,e==null?void 0:e.multiChain]),isConnected:n==="connected",isConnecting:n==="connecting",isDisconnected:n==="disconnected",isReconnecting:n==="reconnecting",isLoading:n==="connecting"||n==="reconnecting",walletType:n==="connected"?t:void 0,reconnect:L,status:n}},wn=e=>{let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),{data:i}=Z(),o=(e==null?void 0:e.bech32Address)||(i==null?void 0:i.bech32Address),{data:r}=Be({chainId:t.map(s=>s.chainId),multiChain:!0,enabled:((e==null?void 0:e.enabled)===void 0?!0:e.enabled)&&!!o}),n=useMemo(()=>["USE_ALL_BALANCES",r,t,o,e==null?void 0:e.chainId],[o,e==null?void 0:e.chainId,t,r]);return useQuery(n,f=>l(void 0,[f],function*({queryKey:[,s,a,c]}){if(!c)throw new Error("address is not defined");return yield z(!!(e!=null&&e.multiChain),a,d=>l(void 0,null,function*(){var m;let S=s==null?void 0:s[d.chainId];if(!S)throw new Error(`Client is not ready ${d.chainId}`);if(!((m=d.bech32Config)!=null&&m.bech32PrefixAccAddr))throw new Error(`Bech32Config is missing ${d.chainId}`);return yield S.getAllBalances(toBech32(d.bech32Config.bech32PrefixAccAddr,fromBech32(c).data))}))}),{enabled:!!o&&!!t&&t.length>0&&!we(r)&&((e==null?void 0:e.enabled)===void 0?!0:e.enabled),refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!1})},Cs=e=>{let t=U({chainId:e.chainId}),{data:i}=Z({chainId:e.chainId}),o=e.bech32Address||(i==null?void 0:i.bech32Address),{data:r,refetch:n}=wn({chainId:t.map(c=>c.chainId),bech32Address:o,enabled:!!o&&(e.enabled===void 0?!0:e.enabled)}),s=["USE_BALANCE",e.denom,r,t,o,e.chainId],a=useQuery(s,({queryKey:[,c,f]})=>f==null?void 0:f.find(A=>A.denom===c),{enabled:!!e.denom&&!!r&&!!(r!=null&&r.length)&&(e.enabled===void 0?!0:e.enabled)});return G(x({},a),{refetch:c=>l(void 0,null,function*(){return yield n(),a.refetch(c)})})},Ss=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=useMutation(["USE_CONNECT",e,t,i],J,{onError:(s,a)=>e==null?void 0:e(s,a),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))}),{data:n}=Ie();return {connect:s=>r.mutate(s),connectAsync:s=>r.mutateAsync(s),error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,isSupported:!!n,status:r.status}},hs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=useMutation(["USE_DISCONNECT",e,t,i],se,{onError:n=>Promise.resolve(e==null?void 0:e(n,void 0)),onMutate:t,onSuccess:()=>Promise.resolve(i==null?void 0:i(void 0))});return {disconnect:n=>r.mutate(n),disconnectAsync:n=>r.mutateAsync(n),error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,status:r.status}},ws=e=>{let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(r=>r.walletType),o=useMemo(()=>["USE_OFFLINE_SIGNERS",t,i],[t,i]);return useQuery({queryKey:o,queryFn:s=>l(void 0,[s],function*({queryKey:[,r,n]}){if(r.length<1)throw new Error("No chain found");if(!B(n))throw new Error(`${n} is not available`);return yield z(!!(e!=null&&e.multiChain),r,f=>l(void 0,null,function*(){return yield yt({chainId:f.chainId,walletType:n})}))}),enabled:!!t&&t.length>0&&!!i,refetchOnWindowFocus:!1})},As=e=>{let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),{data:i}=Z(),{data:o}=Be({chainId:t.map(s=>s.chainId),multiChain:!0}),r=(e==null?void 0:e.bech32Address)||(i==null?void 0:i.bech32Address),n=useMemo(()=>["USE_BALANCE_STAKED",o,t,r],[t,r,o]);return useQuery(n,f=>l(void 0,[f],function*({queryKey:[,s,a,c]}){if(!c)throw new Error("address is not defined");return yield z(!!(e!=null&&e.multiChain),a,d=>l(void 0,null,function*(){var y,m;if(!s)throw new Error("Client is not ready");if(!((y=d.bech32Config)!=null&&y.bech32PrefixAccAddr))throw new Error(`Bech32Config is missing ${d.chainId}`);return yield (m=s[d.chainId])==null?void 0:m.getBalanceStaked(toBech32(d.bech32Config.bech32PrefixAccAddr,fromBech32(c).data))}))}),{enabled:!!r&&!!t&&t.length>0&&!!o,refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!1})};var ks=()=>{let e=u(o=>o.capsuleState),t=g(o=>o.capsuleClient),i=le();return {setModalState:o=>{u.setState(r=>{var n;return {capsuleState:{showModal:o,chainId:(n=r.capsuleState)==null?void 0:n.chainId}}});},modalState:!!(e!=null&&e.showModal),client:t,onAfterLoginSuccessful:i.onAfterLoginSuccessful,onLoginFailure:()=>{se();}}};var Ks=()=>g(e=>e.activeChainIds),An=()=>{var e;return (e=g(t=>t.activeChainIds))==null?void 0:e.map(t=>{var o;let i=(o=u.getState().chains)==null?void 0:o.find(r=>r.chainId===t);if(i)return i}).filter(Boolean)},_s=({chainId:e})=>{var t;return (t=u().chains)==null?void 0:t.find(i=>i.chainId===e)},Ns=({chainId:e})=>{var t;return (t=u().chains)==null?void 0:t.filter(i=>e==null?void 0:e.includes(i.chainId))},Bs=({denom:e})=>{let t=An();return useQuery(["USE_ACTIVE_CHAIN_CURRENCY",e],({queryKey:[,r]})=>{var n;return (n=t==null?void 0:t.find(s=>s.currencies.find(a=>a.coinMinimalDenom===r)))==null?void 0:n.currencies.find(s=>s)})},Ls=e=>{var r;let t=(r=e.status)!=null?r:"BOND_STATUS_BONDED",i=["USE_ACTIVE_CHAIN_VALIDATORS",e.queryClient,t];return useQuery(i,a=>l(void 0,[a],function*({queryKey:[,n,s]}){if(!n)throw new Error("Query client is not defined");return yield n.staking.validators(s)}),{enabled:typeof e.queryClient!="undefined"})},Us=()=>({data:u(t=>t.recentChainIds),clear:We}),qs=()=>{var t;return {data:(t=u(i=>i.recentChainIds))==null?void 0:t.map(i=>{var r;let o=(r=u.getState().chains)==null?void 0:r.find(n=>n.chainId===i);if(o)return o}).filter(Boolean),clear:We}},Fs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=useMutation(["USE_SUGGEST_CHAIN",e,t,i],Re,{onError:(n,s)=>Promise.resolve(e==null?void 0:e(n,s.chainInfo)),onMutate:n=>t==null?void 0:t(n.chainInfo),onSuccess:n=>Promise.resolve(i==null?void 0:i(n))});return {error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,suggest:r.mutate,suggestAsync:r.mutateAsync,status:r.status}},Gs=({onError:e,onLoading:t,onSuccess:i}={})=>{let r=useMutation(["USE_SUGGEST_CHAIN_AND_CONNECT",e,t,i],Ct,{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:s=>t==null?void 0:t(s),onSuccess:s=>Promise.resolve(i==null?void 0:i(s))}),{data:n}=Ie();return {error:r.error,isLoading:r.isLoading,isSuccess:r.isSuccess,isSupported:!!n,status:r.status,suggestAndConnect:r.mutate,suggestAndConnectAsync:r.mutateAsync}};var Ys=({onError:e,onLoading:t,onSuccess:i}={})=>{let{data:o}=Z(),r=o==null?void 0:o.bech32Address,n=useMutation(["USE_SEND_TOKENS",e,t,i,r],s=>ht(x({senderAddress:r},s)),{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))});return {error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,sendTokens:n.mutate,sendTokensAsync:n.mutateAsync,status:n.status}},Js=({onError:e,onLoading:t,onSuccess:i}={})=>{let{data:o}=Z(),r=o==null?void 0:o.bech32Address,n=useMutation(["USE_SEND_IBC_TOKENS",e,t,i,r],s=>wt(x({senderAddress:r},s)),{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:t,onSuccess:s=>Promise.resolve(i==null?void 0:i(s))});return {error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,sendIbcTokens:n.mutate,sendIbcTokensAsync:n.mutateAsync,status:n.status}},Zs=({codeId:e,onError:t,onLoading:i,onSuccess:o})=>{let{data:r}=Z(),n=r==null?void 0:r.bech32Address,a=useMutation(["USE_INSTANTIATE_CONTRACT",t,i,o,e,n],c=>{var A;if(!n)throw new Error("senderAddress is undefined");let f=G(x({},c),{fee:(A=c.fee)!=null?A:"auto",senderAddress:n,codeId:e});return At(f)},{onError:(c,f)=>Promise.resolve(t==null?void 0:t(c,f)),onMutate:i,onSuccess:c=>Promise.resolve(o==null?void 0:o(c))});return {error:a.error,isLoading:a.isLoading,isSuccess:a.isSuccess,instantiateContract:a.mutate,instantiateContractAsync:a.mutateAsync,status:a.status}},ea=({contractAddress:e,onError:t,onLoading:i,onSuccess:o})=>{let{data:r}=Z(),n=r==null?void 0:r.bech32Address,a=useMutation(["USE_EXECUTE_CONTRACT",t,i,o,e,n],c=>{var A,d,S;if(!n)throw new Error("senderAddress is undefined");let f=G(x({},c),{fee:(A=c.fee)!=null?A:"auto",senderAddress:n,contractAddress:e,memo:(d=c.memo)!=null?d:"",funds:(S=c.funds)!=null?S:[]});return It(f)},{onError:(c,f)=>Promise.resolve(t==null?void 0:t(c,f)),onMutate:i,onSuccess:c=>Promise.resolve(o==null?void 0:o(c))});return {error:a.error,isLoading:a.isLoading,isSuccess:a.isSuccess,executeContract:a.mutate,executeContractAsync:a.mutateAsync,status:a.status}},ta=e=>{let{data:t}=Le();return useQuery(["USE_QUERY_SMART",e==null?void 0:e.address,e==null?void 0:e.queryMsg,t],({queryKey:[,o]})=>{if(!(e!=null&&e.address)||!e.queryMsg)throw new Error("address or queryMsg undefined");return Ot(e.address,e.queryMsg,t)},{enabled:!!(e!=null&&e.address)&&!!(e!=null&&e.queryMsg)&&!!t})},na=e=>{let{data:t}=Le(),i=["USE_QUERY_RAW",e==null?void 0:e.key,e==null?void 0:e.address,t];return useQuery(i,({queryKey:[,r]})=>{if(!(e!=null&&e.address)||!e.key)throw new Error("address or key undefined");return Et(e.address,e.key,t)},{enabled:!!(e!=null&&e.address)&&!!(e!=null&&e.key)&&!!t})};function ga(e){let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(n=>n.walletType),o=g(n=>n.activeChainIds),r=useMemo(()=>["USE_STARGATE_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]);return useQuery({queryKey:r,queryFn:a=>l(this,[a],function*({queryKey:[,n,s]}){if(n.length<1)throw new Error("No chains found");return yield z(!!(e!=null&&e.multiChain),n,f=>l(this,null,function*(){var C,h;if(!(o!=null&&o.includes(f.chainId)))return null;if(!B(s))throw new Error(`${s} is not available`);let d=yield (()=>l(this,null,function*(){switch(e==null?void 0:e.offlineSigner){case"offlineSigner":return D(s).getOfflineSigner(f.chainId);case"offlineSignerAuto":return D(s).getOfflineSignerAuto(f.chainId);case"offlineSignerOnlyAmino":return D(s).getOfflineSignerOnlyAmino(f.chainId);default:return D(s).getOfflineSignerAuto(f.chainId)}}))(),S=(C=u.getState().chainsConfig)==null?void 0:C[f.chainId],y={url:f.rpc,headers:x({},(S==null?void 0:S.rpcHeaders)||{})};return (e==null?void 0:e.multiChain)===!0&&e.opts,yield SigningStargateClient.connectWithSigner(y,d,e!=null&&e.multiChain?(h=e.opts)==null?void 0:h[f.chainId]:e==null?void 0:e.opts)}))}),enabled:!!t&&t.length>0&&!!i&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function ya(e){let t=U({chainId:e==null?void 0:e.chainId,multiChain:e==null?void 0:e.multiChain}),i=u(n=>n.walletType),o=g(n=>n.activeChainIds),r=useMemo(()=>["USE_COSMWASM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]);return useQuery({queryKey:r,queryFn:a=>l(this,[a],function*({queryKey:[,n,s]}){if(n.length<1)throw new Error("No chains found");return yield z(!!(e!=null&&e.multiChain),n,f=>l(this,null,function*(){var h,k;if(!(o!=null&&o.includes(f.chainId)))return null;if(!B(s))throw new Error(`${s} is not available`);let d=yield (()=>l(this,null,function*(){switch(e==null?void 0:e.offlineSigner){case"offlineSigner":return D(s).getOfflineSigner(f.chainId);case"offlineSignerAuto":return D(s).getOfflineSignerAuto(f.chainId);case"offlineSignerOnlyAmino":return D(s).getOfflineSignerOnlyAmino(f.chainId);default:return D(s).getOfflineSignerAuto(f.chainId)}}))(),S=(h=u.getState().chainsConfig)==null?void 0:h[f.chainId],y={url:f.rpc,headers:x({},(S==null?void 0:S.rpcHeaders)||{})},m=S!=null&&S.gas?GasPrice.fromString(`${S.gas.price}${S.gas.denom}`):void 0;return yield SigningCosmWasmClient.connectWithSigner(y,d,x({gasPrice:m},e!=null&&e.multiChain?(k=e.opts)==null?void 0:k[f.chainId]:(e==null?void 0:e.opts)||{}))}))}),enabled:!!t&&t.length>0&&!!i&&((e==null?void 0:e.enabled)!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function Ca(e){let t=U({chainId:e.chainId,multiChain:e.multiChain}),i=u(s=>s.walletType),o=g(s=>s.activeChainIds),r=useMemo(()=>["USE_STARGATE_TM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]),{data:n}=Ae({type:e.type,chainId:e.chainId,multiChain:e.multiChain});return useQuery({queryKey:r,queryFn:c=>l(this,[c],function*({queryKey:[,s,a]}){if(s.length<1)throw new Error("No chains found");return yield z(!!e.multiChain,s,A=>l(this,null,function*(){var C;if(!(o!=null&&o.includes(A.chainId)))return null;if(!B(a))throw new Error(`${a} is not available`);if(!n)throw new Error("No tendermint client found");let S=yield (()=>l(this,null,function*(){switch(e.offlineSigner){case"offlineSigner":return D(a).getOfflineSigner(A.chainId);case"offlineSignerAuto":return D(a).getOfflineSignerAuto(A.chainId);case"offlineSignerOnlyAmino":return D(a).getOfflineSignerOnlyAmino(A.chainId);default:return D(a).getOfflineSignerAuto(A.chainId)}}))(),y=e.multiChain?n[A.chainId]:n;return yield SigningStargateClient.createWithSigner(y,S,e.multiChain?(C=e.opts)==null?void 0:C[A.chainId]:e.opts)}))}),enabled:!!t&&t.length>0&&!!i&&!!n&&(e.enabled!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}function Sa(e){let t=U({chainId:e.chainId,multiChain:e.multiChain}),i=u(a=>a.walletType),o=g(a=>a.activeChainIds),r=useMemo(()=>["USE_COSMWASM_TM_SIGNING_CLIENT",t,i,e,o],[o,e,t,i]),{data:n}=Ae({type:e.type,chainId:e.chainId,multiChain:!1,enabled:!e.multiChain}),{data:s}=Ae({type:e.type,chainId:e.chainId,multiChain:!0,enabled:!!e.multiChain});return useQuery({queryKey:r,queryFn:f=>l(this,[f],function*({queryKey:[,a,c]}){if(a.length<1)throw new Error("No chains found");return yield z(!!e.multiChain,a,d=>l(this,null,function*(){var p,I;if(!(o!=null&&o.includes(d.chainId)))return null;if(!B(c))throw new Error(`${c} is not available`);let y=yield (()=>l(this,null,function*(){switch(e.offlineSigner){case"offlineSigner":return D(c).getOfflineSigner(d.chainId);case"offlineSignerAuto":return D(c).getOfflineSignerAuto(d.chainId);case"offlineSignerOnlyAmino":return D(c).getOfflineSignerOnlyAmino(d.chainId);default:return D(c).getOfflineSignerAuto(d.chainId)}}))(),m=(p=u.getState().chainsConfig)==null?void 0:p[d.chainId],C=m!=null&&m.gas?GasPrice.fromString(`${m.gas.price}${m.gas.denom}`):void 0,h=e.multiChain?s==null?void 0:s[d.chainId]:n;if(!h)throw new Error("No tendermint client found");return yield SigningCosmWasmClient.createWithSigner(h,y,x({gasPrice:C},e.multiChain?(I=e.opts)==null?void 0:I[d.chainId]:e.opts||{}))}))}),enabled:!!t&&t.length>0&&!!i&&(!!n||!we(s))&&(e.enabled!==void 0?!!e.enabled:!0),refetchOnWindowFocus:!1})}var Bt=({children:e})=>{let[t,i]=useState(!1);return useEffect(()=>{i(!0);},[]),jsx(Fragment,{children:t?e:null})};var Mn=()=>{let e=typeof window!="undefined"&&window.sessionStorage.getItem(Y)==="Active",{_reconnect:t,_onReconnectFailed:i,_reconnectConnector:o,iframeOptions:r,chains:n}=u(),{activeChainIds:s,wcSignClients:a}=g(),c=B(o||void 0);return useEffect(()=>{if(!r||r.autoConnect===!1||!r.allowedIframeParentOrigins.length||!n)return;new Cosmiframe(r.allowedIframeParentOrigins).isReady().then(A=>{if(A)return J({chainId:n.map(d=>d.chainId),walletType:"cosmiframe"})});},[r]),useEffect(()=>{if(o){if(!c)return;e&&s?L({onError:i}):!e&&t&&L({onError:i});}},[c]),useEffect(()=>{var f,A,d,S,y,m,C,h,k,p,I,b,R,K,_,ee,re,w,O,E;if(o){if(!c)return;o==="cosmostation"&&((A=(f=me()).subscription)==null||A.call(f,()=>{L({onError:i});})),o==="keplr"&&((S=(d=de()).subscription)==null||S.call(d,()=>{L({onError:i});})),o==="leap"&&((m=(y=fe()).subscription)==null||m.call(y,()=>{L({onError:i});})),o==="compass"&&((h=(C=ue()).subscription)==null||h.call(C,()=>{L({onError:i});})),o==="vectis"&&((p=(k=Se()).subscription)==null||p.call(k,()=>{L({onError:i});})),o==="walletconnect"&&a.has("walletconnect")&&((b=(I=j()).subscription)==null||b.call(I,()=>{L({onError:i});})),o==="station"&&((K=(R=Ce()).subscription)==null||K.call(R,()=>{L({onError:i});})),o==="xdefi"&&((ee=(_=he()).subscription)==null||ee.call(_,()=>{L({onError:i});})),o==="cosmiframe"&&((w=(re=pe()).subscription)==null||w.call(re,()=>{L({onError:i});})),o==="okx"&&((E=(O=ye()).subscription)==null||E.call(O,()=>{L({onError:i});}));}},[o,a,c]),null},Lt=()=>(Mn(),null);var Pn=new QueryClient({}),Va=o=>{var r=o,{children:e,grazOptions:t}=r,i=$e(r,["children","grazOptions"]);return useEffect(()=>{St(t);},[t]),jsx(QueryClientProvider,G(x({client:Pn},i),{children:jsxs(Bt,{children:[e,jsx(Lt,{})]})}),"graz-provider")};
20
20
 
21
- export { Lt as GrazEvents, Va as GrazProvider, Ve as WALLET_TYPES, He as WalletType, L as checkWallet, We as clearRecentChain, N as clearSession, St as configureGraz, J as connect, Pr as defineChainInfo, vr as defineChains, se as disconnect, It as executeContract, rr as getAvailableWallets, hr as getChainInfo, wr as getChainInfos, me as getCosmostation, de as getKeplr, fe as getLeap, ct as getMetamaskSnapLeap, yt as getOfflineSigners, Et as getQueryRaw, Ot as getQuerySmart, Cr as getRecentChainIds, Sr as getRecentChains, Se as getVectis, mt as getWCCosmostation, dt as getWCKeplr, ft as getWCLeap, D as getWallet, j as getWalletConnect, At as instantiateContract, Pe as isCapsule, gt as isWalletConnect, U as reconnect, wt as sendIbcTokens, ht as sendTokens, Re as suggestChain, Ct as suggestChainAndConnect, Z as useAccount, Bs as useActiveChainCurrency, Ks as useActiveChainIds, An as useActiveChains, os as useActiveWalletType, Cs as useBalance, As as useBalanceStaked, wn as useBalances, ks as useCapsule, _s as useChainInfo, Ns as useChainInfos, Ie as useCheckWallet, Ss as useConnect, Le as useCosmWasmClient, ya as useCosmWasmSigningClient, Sa as useCosmWasmTmSigningClient, hs as useDisconnect, ea as useExecuteContract, Mn as useGrazEvents, Zs as useInstantiateContract, ws as useOfflineSigners, Ls as useQueryClientValidators, na as useQueryRaw, ta as useQuerySmart, Us as useRecentChainIds, qs as useRecentChains, Js as useSendIbcTokens, Ys as useSendTokens, Be as useStargateClient, ga as useStargateSigningClient, Ca as useStargateTmSigningClient, Fs as useSuggestChain, Gs as useSuggestChainAndConnect, Ae as useTendermintClient };
21
+ export { Lt as GrazEvents, Va as GrazProvider, Ve as WALLET_TYPES, He as WalletType, B as checkWallet, We as clearRecentChain, N as clearSession, St as configureGraz, J as connect, Pr as defineChainInfo, vr as defineChains, se as disconnect, It as executeContract, rr as getAvailableWallets, hr as getChainInfo, wr as getChainInfos, me as getCosmostation, de as getKeplr, fe as getLeap, ct as getMetamaskSnapLeap, yt as getOfflineSigners, Et as getQueryRaw, Ot as getQuerySmart, Cr as getRecentChainIds, Sr as getRecentChains, Se as getVectis, mt as getWCCosmostation, dt as getWCKeplr, ft as getWCLeap, D as getWallet, j as getWalletConnect, At as instantiateContract, Pe as isCapsule, gt as isWalletConnect, L as reconnect, wt as sendIbcTokens, ht as sendTokens, Re as suggestChain, Ct as suggestChainAndConnect, Z as useAccount, Bs as useActiveChainCurrency, Ks as useActiveChainIds, An as useActiveChains, os as useActiveWalletType, Cs as useBalance, As as useBalanceStaked, wn as useBalances, ks as useCapsule, _s as useChainInfo, Ns as useChainInfos, Ie as useCheckWallet, Ss as useConnect, Le as useCosmWasmClient, ya as useCosmWasmSigningClient, Sa as useCosmWasmTmSigningClient, hs as useDisconnect, ea as useExecuteContract, Mn as useGrazEvents, Zs as useInstantiateContract, ws as useOfflineSigners, Ls as useQueryClientValidators, na as useQueryRaw, ta as useQuerySmart, Us as useRecentChainIds, qs as useRecentChains, Js as useSendIbcTokens, Ys as useSendTokens, Be as useStargateClient, ga as useStargateSigningClient, Ca as useStargateTmSigningClient, Fs as useSuggestChain, Gs as useSuggestChainAndConnect, Ae as useTendermintClient };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "graz",
3
3
  "description": "React hooks for Cosmos",
4
- "version": "0.1.28",
4
+ "version": "0.1.29-alpha.0",
5
5
  "author": "Griko Nibras <griko@strange.love>",
6
6
  "repository": "https://github.com/graz-sh/graz.git",
7
7
  "homepage": "https://github.com/graz-sh/graz",
@@ -33,6 +33,14 @@
33
33
  "env.d.ts"
34
34
  ],
35
35
  "sideEffects": false,
36
+ "scripts": {
37
+ "build": "tsup",
38
+ "clean": "rm -rf dist/*",
39
+ "cli": "node dist/cli.js",
40
+ "dev": "tsup --watch",
41
+ "lint": "eslint --fix \"src/**/*.{ts,tsx}\"",
42
+ "prepublishOnly": "pnpm build"
43
+ },
36
44
  "peerDependencies": {
37
45
  "@cosmjs/amino": "<=0.31.3",
38
46
  "@cosmjs/cosmwasm-stargate": "<=0.31.3",
@@ -77,12 +85,5 @@
77
85
  "graz-sh",
78
86
  "use-keplr"
79
87
  ],
80
- "license": "MIT",
81
- "scripts": {
82
- "build": "tsup",
83
- "clean": "rm -rf dist/*",
84
- "cli": "node dist/cli.js",
85
- "dev": "tsup --watch",
86
- "lint": "eslint --fix \"src/**/*.{ts,tsx}\""
87
- }
88
- }
88
+ "license": "MIT"
89
+ }