graz 0.0.44 → 0.0.45-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1 +1,2953 @@
1
- import{a as Rt,b as Ut,c as R}from"./chunk-HBC2VYPF.mjs";var Xe=Rt((oo,Ye)=>{"use strict";Ye.exports=S;var O=null;try{O=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}function S(t,e,n){this.low=t|0,this.high=e|0,this.unsigned=!!n}S.prototype.__isLong__;Object.defineProperty(S.prototype,"__isLong__",{value:!0});function D(t){return(t&&t.__isLong__)===!0}S.isLong=D;var Ge={},Le={};function P(t,e){var n,r,o;return e?(t>>>=0,(o=0<=t&&t<256)&&(r=Le[t],r)?r:(n=w(t,(t|0)<0?-1:0,!0),o&&(Le[t]=n),n)):(t|=0,(o=-128<=t&&t<128)&&(r=Ge[t],r)?r:(n=w(t,t<0?-1:0,!1),o&&(Ge[t]=n),n))}S.fromInt=P;function j(t,e){if(isNaN(t))return e?U:F;if(e){if(t<0)return U;if(t>=He)return Ze}else{if(t<=-Ke)return v;if(t+1>=Ke)return $e}return t<0?j(-t,e).neg():w(t%K|0,t/K|0,e)}S.fromNumber=j;function w(t,e,n){return new S(t,e,n)}S.fromBits=w;var ne=Math.pow;function ce(t,e,n){if(t.length===0)throw Error("empty string");if(t==="NaN"||t==="Infinity"||t==="+Infinity"||t==="-Infinity")return F;if(typeof e=="number"?(n=e,e=!1):e=!!e,n=n||10,n<2||36<n)throw RangeError("radix");var r;if((r=t.indexOf("-"))>0)throw Error("interior hyphen");if(r===0)return ce(t.substring(1),e,n).neg();for(var o=j(ne(n,8)),s=F,i=0;i<t.length;i+=8){var a=Math.min(8,t.length-i),c=parseInt(t.substring(i,i+a),n);if(a<8){var g=j(ne(n,a));s=s.mul(g).add(j(c))}else s=s.mul(o),s=s.add(j(c))}return s.unsigned=e,s}S.fromString=ce;function k(t,e){return typeof t=="number"?j(t,e):typeof t=="string"?ce(t,e):w(t.low,t.high,typeof e=="boolean"?e:t.unsigned)}S.fromValue=k;var ze=65536,Qt=1<<24,K=ze*ze,He=K*K,Ke=He/2,Qe=P(Qt),F=P(0);S.ZERO=F;var U=P(0,!0);S.UZERO=U;var z=P(1);S.ONE=z;var Ve=P(1,!0);S.UONE=Ve;var ie=P(-1);S.NEG_ONE=ie;var $e=w(-1,2147483647,!1);S.MAX_VALUE=$e;var Ze=w(-1,-1,!0);S.MAX_UNSIGNED_VALUE=Ze;var v=w(0,-2147483648,!1);S.MIN_VALUE=v;var u=S.prototype;u.toInt=function(){return this.unsigned?this.low>>>0:this.low};u.toNumber=function(){return this.unsigned?(this.high>>>0)*K+(this.low>>>0):this.high*K+(this.low>>>0)};u.toString=function(e){if(e=e||10,e<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative())if(this.eq(v)){var n=j(e),r=this.div(n),o=r.mul(n).sub(this);return r.toString(e)+o.toInt().toString(e)}else return"-"+this.neg().toString(e);for(var s=j(ne(e,6),this.unsigned),i=this,a="";;){var c=i.div(s),g=i.sub(c.mul(s)).toInt()>>>0,d=g.toString(e);if(i=c,i.isZero())return d+a;for(;d.length<6;)d="0"+d;a=""+d+a}};u.getHighBits=function(){return this.high};u.getHighBitsUnsigned=function(){return this.high>>>0};u.getLowBits=function(){return this.low};u.getLowBitsUnsigned=function(){return this.low>>>0};u.getNumBitsAbs=function(){if(this.isNegative())return this.eq(v)?64:this.neg().getNumBitsAbs();for(var e=this.high!=0?this.high:this.low,n=31;n>0&&!(e&1<<n);n--);return this.high!=0?n+33:n+1};u.isZero=function(){return this.high===0&&this.low===0};u.eqz=u.isZero;u.isNegative=function(){return!this.unsigned&&this.high<0};u.isPositive=function(){return this.unsigned||this.high>=0};u.isOdd=function(){return(this.low&1)===1};u.isEven=function(){return(this.low&1)===0};u.equals=function(e){return D(e)||(e=k(e)),this.unsigned!==e.unsigned&&this.high>>>31===1&&e.high>>>31===1?!1:this.high===e.high&&this.low===e.low};u.eq=u.equals;u.notEquals=function(e){return!this.eq(e)};u.neq=u.notEquals;u.ne=u.notEquals;u.lessThan=function(e){return this.comp(e)<0};u.lt=u.lessThan;u.lessThanOrEqual=function(e){return this.comp(e)<=0};u.lte=u.lessThanOrEqual;u.le=u.lessThanOrEqual;u.greaterThan=function(e){return this.comp(e)>0};u.gt=u.greaterThan;u.greaterThanOrEqual=function(e){return this.comp(e)>=0};u.gte=u.greaterThanOrEqual;u.ge=u.greaterThanOrEqual;u.compare=function(e){if(D(e)||(e=k(e)),this.eq(e))return 0;var n=this.isNegative(),r=e.isNegative();return n&&!r?-1:!n&&r?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1};u.comp=u.compare;u.negate=function(){return!this.unsigned&&this.eq(v)?v:this.not().add(z)};u.neg=u.negate;u.add=function(e){D(e)||(e=k(e));var n=this.high>>>16,r=this.high&65535,o=this.low>>>16,s=this.low&65535,i=e.high>>>16,a=e.high&65535,c=e.low>>>16,g=e.low&65535,d=0,x=0,C=0,E=0;return E+=s+g,C+=E>>>16,E&=65535,C+=o+c,x+=C>>>16,C&=65535,x+=r+a,d+=x>>>16,x&=65535,d+=n+i,d&=65535,w(C<<16|E,d<<16|x,this.unsigned)};u.subtract=function(e){return D(e)||(e=k(e)),this.add(e.neg())};u.sub=u.subtract;u.multiply=function(e){if(this.isZero())return F;if(D(e)||(e=k(e)),O){var n=O.mul(this.low,this.high,e.low,e.high);return w(n,O.get_high(),this.unsigned)}if(e.isZero())return F;if(this.eq(v))return e.isOdd()?v:F;if(e.eq(v))return this.isOdd()?v:F;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(Qe)&&e.lt(Qe))return j(this.toNumber()*e.toNumber(),this.unsigned);var r=this.high>>>16,o=this.high&65535,s=this.low>>>16,i=this.low&65535,a=e.high>>>16,c=e.high&65535,g=e.low>>>16,d=e.low&65535,x=0,C=0,E=0,_=0;return _+=i*d,E+=_>>>16,_&=65535,E+=s*d,C+=E>>>16,E&=65535,E+=i*g,C+=E>>>16,E&=65535,C+=o*d,x+=C>>>16,C&=65535,C+=s*g,x+=C>>>16,C&=65535,C+=i*c,x+=C>>>16,C&=65535,x+=r*d+o*g+s*c+i*a,x&=65535,w(E<<16|_,x<<16|C,this.unsigned)};u.mul=u.multiply;u.divide=function(e){if(D(e)||(e=k(e)),e.isZero())throw Error("division by zero");if(O){if(!this.unsigned&&this.high===-2147483648&&e.low===-1&&e.high===-1)return this;var n=(this.unsigned?O.div_u:O.div_s)(this.low,this.high,e.low,e.high);return w(n,O.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?U:F;var r,o,s;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return U;if(e.gt(this.shru(1)))return Ve;s=U}else{if(this.eq(v)){if(e.eq(z)||e.eq(ie))return v;if(e.eq(v))return z;var i=this.shr(1);return r=i.div(e).shl(1),r.eq(F)?e.isNegative()?z:ie:(o=this.sub(e.mul(r)),s=r.add(o.div(e)),s)}else if(e.eq(v))return this.unsigned?U:F;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();s=F}for(o=this;o.gte(e);){r=Math.max(1,Math.floor(o.toNumber()/e.toNumber()));for(var a=Math.ceil(Math.log(r)/Math.LN2),c=a<=48?1:ne(2,a-48),g=j(r),d=g.mul(e);d.isNegative()||d.gt(o);)r-=c,g=j(r,this.unsigned),d=g.mul(e);g.isZero()&&(g=z),s=s.add(g),o=o.sub(d)}return s};u.div=u.divide;u.modulo=function(e){if(D(e)||(e=k(e)),O){var n=(this.unsigned?O.rem_u:O.rem_s)(this.low,this.high,e.low,e.high);return w(n,O.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))};u.mod=u.modulo;u.rem=u.modulo;u.not=function(){return w(~this.low,~this.high,this.unsigned)};u.and=function(e){return D(e)||(e=k(e)),w(this.low&e.low,this.high&e.high,this.unsigned)};u.or=function(e){return D(e)||(e=k(e)),w(this.low|e.low,this.high|e.high,this.unsigned)};u.xor=function(e){return D(e)||(e=k(e)),w(this.low^e.low,this.high^e.high,this.unsigned)};u.shiftLeft=function(e){return D(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?w(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):w(0,this.low<<e-32,this.unsigned)};u.shl=u.shiftLeft;u.shiftRight=function(e){return D(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?w(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):w(this.high>>e-32,this.high>=0?0:-1,this.unsigned)};u.shr=u.shiftRight;u.shiftRightUnsigned=function(e){if(D(e)&&(e=e.toInt()),e&=63,e===0)return this;var n=this.high;if(e<32){var r=this.low;return w(r>>>e|n<<32-e,n>>>e,this.unsigned)}else return e===32?w(n,0,this.unsigned):w(n>>>e-32,0,this.unsigned)};u.shru=u.shiftRightUnsigned;u.shr_u=u.shiftRightUnsigned;u.toSigned=function(){return this.unsigned?w(this.low,this.high,!1):this};u.toUnsigned=function(){return this.unsigned?this:w(this.low,this.high,!0)};u.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()};u.toBytesLE=function(){var e=this.high,n=this.low;return[n&255,n>>>8&255,n>>>16&255,n>>>24,e&255,e>>>8&255,e>>>16&255,e>>>24]};u.toBytesBE=function(){var e=this.high,n=this.low;return[e>>>24,e>>>16&255,e>>>8&255,e&255,n>>>24,n>>>16&255,n>>>8&255,n&255]};S.fromBytes=function(e,n,r){return r?S.fromBytesLE(e,n):S.fromBytesBE(e,n)};S.fromBytesLE=function(e,n){return new S(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,n)};S.fromBytesBE=function(e,n){return new S(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],n)}});import{GasPrice as Xt}from"@cosmjs/stargate";import{create as Be}from"zustand";import{createJSONStorage as Pt}from"zustand/middleware";import{persist as Ne,subscribeWithSelector as We}from"zustand/middleware";var Fe=(c=>(c.KEPLR="keplr",c.LEAP="leap",c.VECTIS="vectis",c.COSMOSTATION="cosmostation",c.WALLETCONNECT="walletconnect",c.WC_KEPLR_MOBILE="wc_keplr_mobile",c.WC_LEAP_MOBILE="wc_leap_mobile",c.WC_COSMOSTATION_MOBILE="wc_cosmostation_mobile",c))(Fe||{}),ke=["keplr","leap","vectis","cosmostation","walletconnect","wc_keplr_mobile","wc_leap_mobile","wc_cosmostation_mobile"];var qt={recentChain:null,defaultChain:null,defaultSigningClient:"stargate",walletType:"keplr",walletConnect:{options:null,web3Modal:null},_notFoundFn:()=>null,_onReconnectFailed:()=>null,_reconnect:!1,_reconnectConnector:null},$={account:null,activeChain:null,balances:null,clients:null,offlineSigner:null,offlineSignerAmino:null,offlineSignerAuto:null,signingClients:null,status:"disconnected",wcSignClient:null},Gt={name:"graz-session",version:1,partialize:t=>({account:t.account,activeChain:t.activeChain}),storage:Pt(()=>sessionStorage)},Lt={name:"graz-internal",partialize:t=>({recentChain:t.recentChain,_reconnect:t._reconnect,_reconnectConnector:t._reconnectConnector}),version:1},m=Be(We(Ne(()=>$,Gt))),y=Be(We(Ne(()=>qt,Lt)));import{SigningCosmWasmClient as Pe}from"@cosmjs/cosmwasm-stargate";import{SigningStargateClient as qe}from"@cosmjs/stargate";import{Tendermint34Client as Kt}from"@cosmjs/tendermint-rpc";import{QueryClient as zt}from"@cosmjs/stargate";import{assert as Me,isNonNullObject as Re}from"@cosmjs/utils";var Ue=(...t)=>{let{tendermint:e}=m.getState().clients,n=new zt(e),r=t.map(o=>o(n));for(let o of r){Me(Re(o),"Extension must be a non-null object");for(let[s,i]of Object.entries(o)){Me(Re(i),`Module must be a non-null object. Found type ${typeof i} for module "${s}".`);let a=n[s]||{};n[s]={...a,...i}}}return n};var ee=async({rpc:t,rpcHeaders:e})=>{let n={url:t,headers:{...e||{}}},[r,o,s]=await Promise.all([Pe.connect(n),qe.connect(n),Kt.connect(t)]);return{cosmWasm:r,stargate:o,tendermint:s}},te=async t=>{let{rpc:e,rpcHeaders:n,offlineSignerAuto:r,cosmWasmSignerOptions:o={},stargateSignerOptions:s={}}=t,i={url:e,headers:{...n||{}}},[a,c]=await Promise.all([Pe.connectWithSigner(i,r,o),qe.connectWithSigner(i,r,s)]);return{cosmWasm:a,stargate:c}};var ue=Ut(Xe());import{fromBech32 as tt}from"@cosmjs/encoding";import{SignClient as Ht}from"@walletconnect/sign-client";import{getSdkError as Vt}from"@walletconnect/utils";var q=()=>typeof window<"u"?!!(window.matchMedia("(pointer:coarse)").matches||/Android|webOS|iPhone|iPad|iPod|BlackBerry|Opera Mini/u.test(navigator.userAgent)):!1,Je=()=>q()&&navigator.userAgent.toLowerCase().includes("android"),et=()=>q()&&(navigator.userAgent.toLowerCase().includes("iphone")||navigator.userAgent.toLowerCase().includes("ipad"));var ae=(t,e,n=new Error("Promise timed out"))=>{let r=new Promise((o,s)=>{setTimeout(()=>{s(n)},e)});return Promise.race([t,r])};var Q=(t=y.getState().walletType)=>{try{return Z(t),!0}catch{return!1}},W=()=>{window.sessionStorage.removeItem(R),m.setState($)},le=()=>{if(typeof window.keplr<"u"){let t=window.keplr;return Object.assign(t,{subscription:r=>(window.addEventListener("keplr_keystorechange",()=>{W(),r()}),()=>{window.removeEventListener("keplr_keystorechange",()=>{W(),r()})})})}throw y.getState()._notFoundFn(),new Error("window.keplr is not defined")},pe=()=>{if(typeof window.leap<"u"){let t=window.leap;return Object.assign(t,{subscription:r=>(window.addEventListener("leap_keystorechange",()=>{W(),r()}),()=>{window.removeEventListener("leap_keystorechange",()=>{W(),r()})})})}throw y.getState()._notFoundFn(),new Error("window.leap is not defined")},me=()=>{if(typeof window.cosmostation.providers.keplr<"u"){let t=window.cosmostation.providers.keplr;return Object.assign(t,{subscription:r=>(window.cosmostation.cosmos.on("accountChanged",()=>{W(),r()}),()=>{window.cosmostation.cosmos.off("accountChanged",()=>{W(),r()})})})}throw y.getState()._notFoundFn(),new Error("window.cosmostation.providers.keplr is not defined")},ge=()=>{if(typeof window.vectis<"u"){let t=window.vectis.cosmos;return{enable:a=>t.enable(a),getOfflineSigner:a=>t.getOfflineSigner(a),getOfflineSignerAuto:a=>t.getOfflineSignerAuto(a),getKey:async a=>{let c=await t.getKey(a);return{address:tt(c.address).data,algo:c.algo,bech32Address:c.address,name:c.name,pubKey:c.pubKey,isKeystone:!1,isNanoLedger:c.isNanoLedger}},subscription:a=>(window.addEventListener("vectis_accountChanged",()=>{W(),a()}),()=>{window.removeEventListener("vectis_accountChanged",()=>{W(),a()})}),getOfflineSignerOnlyAmino:(...a)=>t.getOfflineSignerAmino(...a),experimentalSuggestChain:async(...a)=>{let[c]=a,g={...c,rpcUrl:c.rpc,restUrl:c.rest,prettyName:c.chainName.replace(" ",""),bech32Prefix:c.bech32Config.bech32PrefixAccAddr};return t.suggestChains([g])},signDirect:async(...a)=>{var d;let{1:c,2:g}=a;return t.signDirect(c,{bodyBytes:g.bodyBytes||Uint8Array.from([]),authInfoBytes:g.authInfoBytes||Uint8Array.from([]),accountNumber:ue.default.fromString(((d=g.accountNumber)==null?void 0:d.toString())||"",!1),chainId:g.chainId||""})},signAmino:async(...a)=>{let{1:c,2:g}=a;return t.signAmino(c,g)}}}throw y.getState()._notFoundFn(),new Error("window.vectis is not defined")},H=t=>{var De,_e,Oe;if(!((Oe=(_e=(De=y.getState().walletConnect)==null?void 0:De.options)==null?void 0:_e.projectId)!=null&&Oe.trim()))throw new Error("walletConnect.options.projectId is not defined");let e=(t==null?void 0:t.encoding)||"base64",n=p=>{if(!t)return;let{appUrl:l,formatNativeUrl:f}=t;if(q()){if(Je())if(!p)window.open(l.mobile.android,"_self","noreferrer noopener");else{let h=f(l.mobile.android,p,"android");window.open(h,"_self","noreferrer noopener")}if(et())if(!p)window.open(l.mobile.ios,"_self","noreferrer noopener");else{let h=f(l.mobile.ios,p,"ios");window.open(h,"_self","noreferrer noopener")}}},r=()=>{let{wcSignClient:p}=m.getState();if(!p)throw new Error("walletConnect.signClient is not defined");W(),y.setState({_reconnect:!1,_reconnectConnector:null,recentChain:null})},o=async p=>{let{wcSignClient:l}=m.getState();if(!l)throw new Error("walletConnect.signClient is not defined");if(!p)throw new Error("No wallet connect session");await l.disconnect({topic:p,reason:Vt("USER_DISCONNECTED")}),await a(l),r()},s=p=>{var l,f;try{let{wcSignClient:h}=m.getState();if(!h)throw new Error("walletConnect.signClient is not defined");let A=h.session.getAll().at(-1);if(!A)return;let b=(f=(l=h.session.getAll().at(-1))==null?void 0:l.namespaces.cosmos)==null?void 0:f.accounts.find(I=>I.startsWith(`cosmos:${p}`));if(!(A.expiry*1e3>Date.now()+1e3))throw o(A.topic),new Error("invalid session");if(!b)try{let I=h.find({requiredNamespaces:{cosmos:{methods:["cosmos_getAccounts","cosmos_signAmino","cosmos_signDirect"],chains:[`cosmos:${p}`],events:["chainChanged","accountsChanged"]}}});if(!I.length)throw new Error("no session");return I.at(-1)}catch(I){if(!I.message.toLowerCase().includes("no matching key"))throw I}return A}catch(h){if(!h.message.toLowerCase().includes("no matching key"))throw h}},i=p=>{try{return s(p)}catch{return}},a=async p=>{try{let l=p.core.pairing.pairings.getAll({active:!1});if(!l.length)return;await Promise.all(l.map(async f=>{await p.core.pairing.pairings.delete(f.topic,{code:7001,message:"clear pairing"})}))}catch(l){if(!l.message.toLowerCase().includes("no matching key"))throw l}},c=async()=>{let{walletConnect:p}=y.getState();if(!(p!=null&&p.options))throw new Error("walletConnect.options is not defined");let{wcSignClient:l}=m.getState();if(l)return m.setState({wcSignClient:l}),l;let f=await Ht.init(p.options);return m.setState({wcSignClient:f}),f},g=p=>{let{wcSignClient:l}=m.getState();if(l)return l.events.on("session_delete",f=>{r()}),l.events.on("session_expire",f=>{r()}),l.events.on("session_event",f=>{var h,A;if(f.params.event.name==="accountsChanged"&&((h=f.params.event.data)==null?void 0:h[0])!==((A=m.getState().account)==null?void 0:A.bech32Address)){let b=f.params.chainId.split(":")[1];b&&d(b)}else p()}),()=>{l.events.off("session_delete",f=>{r()}),l.events.off("session_expire",f=>{r()}),l.events.off("session_event",f=>{var h,A;if(f.params.event.name==="accountsChanged"&&((h=f.params.event.data)==null?void 0:h[0])!==((A=m.getState().account)==null?void 0:A.bech32Address)){let b=f.params.chainId.split(":")[1];b&&d(b)}else p()})}},d=async p=>{var X;let{wcSignClient:l}=m.getState();if(!l)throw new Error("enable walletConnect.signClient is not defined");let{walletConnect:f}=y.getState();if(!((X=f==null?void 0:f.options)!=null&&X.projectId))throw new Error("walletConnect.options.projectId is not defined");let{Web3Modal:h}=await import("@web3modal/standalone"),A=new h({projectId:f.options.projectId,walletConnectVersion:2,enableExplorer:!1,explorerRecommendedWalletIds:"NONE",...f.web3Modal}),{account:b,activeChain:N}=m.getState(),I=i(p);if((N==null?void 0:N.chainId)!==p&&!I||!b){let{uri:T,approval:J}=await l.connect({requiredNamespaces:{cosmos:{methods:["cosmos_getAccounts","cosmos_signAmino","cosmos_signDirect"],chains:[`cosmos:${p}`],events:["chainChanged","accountsChanged"]}}});if(!T)throw new Error("No wallet connect uri");t?n(T):await A.openModal({uri:T});try{await ae((async()=>{await J()})(),4e4,new Error("Modal approval timeout"))}catch(je){if(A.closeModal(),!je.message.toLowerCase().includes("no matching key"))return Promise.reject(je)}return t||A.closeModal(),Promise.resolve()}try{await ae((async()=>{let T=await C(p);m.setState({account:T})})(),1e4,new Error("Connection timeout"))}catch(T){if(o(I==null?void 0:I.topic),!T.message.toLowerCase().includes("no matching key"))throw T}},x=async p=>{var A;let{wcSignClient:l}=m.getState();if(!l)throw new Error("walletConnect.signClient is not defined");let f=(A=s(p))==null?void 0:A.topic;if(!f)throw new Error("No wallet connect session");n();let h=await l.request({topic:f,chainId:`cosmos:${p}`,request:{method:"cosmos_getAccounts",params:{}}});if(!h[0])throw new Error("No wallet connect account");return{address:h[0].address,algo:h[0].algo,pubkey:new Uint8Array(Buffer.from(h[0].pubkey,e))}},C=async p=>{let{address:l,algo:f,pubkey:h}=await x(p);return{address:tt(l).data,algo:f,bech32Address:l,name:"",pubKey:h,isKeystone:!1,isNanoLedger:!1}},E=async(...p)=>{var T,J;let[l,f,h]=p,{account:A,wcSignClient:b}=m.getState();if(!b)throw new Error("walletConnect.signClient is not defined");if(!A)throw new Error("account is not defined");let N=(T=s(l))==null?void 0:T.topic;if(!N)throw new Error("No wallet connect session");if(!h.bodyBytes)throw new Error("No bodyBytes");if(!h.authInfoBytes)throw new Error("No authInfoBytes");let I={topic:N,chainId:`cosmos:${l}`,request:{method:"cosmos_signDirect",params:{signerAddress:f,signDoc:{...h,bodyBytes:Buffer.from(h.bodyBytes).toString(e),authInfoBytes:Buffer.from(h.authInfoBytes).toString(e),accountNumber:(J=h.accountNumber)==null?void 0:J.toString()}}}};return n(),await b.request(I)},_=async(...p)=>{let[l,f,h]=p,{signature:A,signed:b}=await E(l,f,h);return{signed:{chainId:b.chainId,accountNumber:ue.default.fromString(b.accountNumber,!1),authInfoBytes:new Uint8Array(Buffer.from(b.authInfoBytes,e)),bodyBytes:new Uint8Array(Buffer.from(b.bodyBytes,e))},signature:A}},L=async(...p)=>{var T;let[l,f,h,A]=p,{wcSignClient:b}=m.getState(),{account:N}=m.getState();if(!b)throw new Error("walletConnect.signClient is not defined");if(!N)throw new Error("account is not defined");let I=(T=s(l))==null?void 0:T.topic;if(!I)throw new Error("No wallet connect session");return n(),await b.request({topic:I,chainId:`cosmos:${l}`,request:{method:"cosmos_signDirect",params:{signerAddress:f,signDoc:h}}})},V=async(...p)=>{let[l,f,h,A]=p;return await L(l,f,h)},se=p=>({getAccounts:async()=>[await x(p)],signDirect:(l,f)=>_(p,l,f)}),M=p=>({getAccounts:async()=>[await x(p)],signAmino:(l,f)=>V(p,l,f)});return{enable:d,experimentalSuggestChain:async(...p)=>{await Promise.reject(new Error("WalletConnect does not support experimentalSuggestChain"))},getKey:C,getOfflineSigner:p=>({getAccounts:async()=>[await x(p)],signDirect:(l,f)=>_(p,l,f),signAmino:(l,f)=>V(p,l,f)}),getOfflineSignerAuto:async p=>(await C(p)).isNanoLedger?M(p):se(p),getOfflineSignerOnlyAmino:M,signAmino:V,signDirect:_,subscription:g,init:c}},$t=()=>{var e,n,r;if(!((r=(n=(e=y.getState().walletConnect)==null?void 0:e.options)==null?void 0:n.projectId)!=null&&r.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!q())throw new Error("WalletConnect Keplr mobile is only supported in mobile");let t={encoding:"base64",appUrl:{mobile:{ios:"keplrwallet://",android:"intent://"}},walletType:"wc_keplr_mobile",formatNativeUrl:(o,s,i)=>{let a=o.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(s);switch(i){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 H(t)},Zt=()=>{var e,n,r;if(!((r=(n=(e=y.getState().walletConnect)==null?void 0:e.options)==null?void 0:n.projectId)!=null&&r.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!q())throw new Error("WalletConnect Leap mobile is only supported in mobile");let t={encoding:"base64",appUrl:{mobile:{ios:"leapcosmos://",android:"intent://"}},walletType:"wc_leap_mobile",formatNativeUrl:(o,s,i)=>{let a=o.replaceAll("/","").replaceAll(":",""),c=encodeURIComponent(s);switch(i){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 H(t)},Yt=()=>{var e,n,r;if(!((r=(n=(e=y.getState().walletConnect)==null?void 0:e.options)==null?void 0:n.projectId)!=null&&r.trim()))throw new Error("walletConnect.options.projectId is not defined");if(!q())throw new Error("WalletConnect Leap mobile is only supported in mobile");let t={encoding:"hex",appUrl:{mobile:{ios:"cosmostation://",android:"cosmostation://"}},walletType:"wc_leap_mobile",formatNativeUrl:(o,s,i)=>`${o.replaceAll("/","").replaceAll(":","")}://wc?${s}`};return H(t)},Z=(t=y.getState().walletType)=>{switch(t){case"keplr":return le();case"leap":return pe();case"cosmostation":return me();case"vectis":return ge();case"walletconnect":return H();case"wc_keplr_mobile":return $t();case"wc_leap_mobile":return Zt();case"wc_cosmostation_mobile":return Yt();default:throw new Error("Unknown wallet type")}},fo=()=>Object.fromEntries(ke.map(t=>[t,Q(t)]));var Y=async t=>{var e;try{let{defaultChain:n,recentChain:r,walletType:o}=y.getState(),s=(t==null?void 0:t.walletType)||o;if(!Q(s))throw new Error(`${s} is not available`);let a=Z(s),c=(t==null?void 0:t.chain)||r||n;if(!c)throw new Error("No last known connected chain, connect action requires chain info");m.setState(M=>{let ve=y.getState()._reconnect||!!y.getState()._reconnectConnector||!!c;return M.activeChain&&M.activeChain.chainId!==c.chainId?{status:"connecting"}:ve?{status:"reconnecting"}:{status:"connecting"}});let{account:g,activeChain:d}=m.getState();if(await((e=a.init)==null?void 0:e.call(a)),!g||(d==null?void 0:d.chainId)!==c.chainId){await a.enable(c.chainId);let M=await a.getKey(c.chainId);m.setState({account:M})}let x=a.getOfflineSigner(c.chainId),C=a.getOfflineSignerOnlyAmino(c.chainId),E=await a.getOfflineSignerAuto(c.chainId),_=c.gas?Xt.fromString(`${c.gas.price}${c.gas.denom}`):void 0,[L,V]=await Promise.all([ee(c),te({...c,offlineSignerAuto:E,cosmWasmSignerOptions:{gasPrice:_,...(t==null?void 0:t.signerOpts)||{}}})]);y.setState({recentChain:c,walletType:s,_reconnect:!!(t!=null&&t.autoReconnect),_reconnectConnector:s}),m.setState({activeChain:c,clients:L,offlineSigner:x,offlineSignerAmino:C,offlineSignerAuto:E,signingClients:V,status:"connected"}),typeof window<"u"&&window.sessionStorage.setItem(R,"Active");let{account:se}=m.getState();return{account:se,walletType:s,chain:c}}catch(n){throw console.error("connect ",n),m.getState().account===null&&m.setState({status:"disconnected"}),m.getState().account&&m.getState().activeChain&&m.setState({status:"connected"}),n}},fe=async(t=!1)=>(typeof window<"u"&&window.sessionStorage.removeItem(R),m.setState($),y.setState(e=>({_reconnect:!1,_reconnectConnector:null,recentChain:t?null:e.recentChain})),Promise.resolve()),B=async t=>{var o;let{recentChain:e,_reconnectConnector:n,_reconnect:r}=y.getState();try{let s=Q(n||void 0);if(e&&s&&n)return await Y({chain:e,walletType:n,autoReconnect:r})}catch(s){(o=t==null?void 0:t.onError)==null||o.call(t,s),fe()}};var nt=()=>{y.setState({recentChain:null})},ot=t=>{let{activeChain:e}=m.getState();return e==null?void 0:e.currencies.find(n=>n.coinMinimalDenom===t)},To=()=>y.getState().recentChain,de=async t=>(await Z().experimentalSuggestChain(t),t),rt=async({chainInfo:t,rpcHeaders:e,gas:n,path:r,...o})=>{let s=await de(t);return{...await Y({chain:{chainId:t.chainId,currencies:t.currencies,rest:t.rest,rpc:t.rpc,rpcHeaders:e,gas:n,path:r},...o}),chain:s}};var st=(t={})=>(y.setState(e=>({defaultChain:t.defaultChain||e.defaultChain,defaultSigningClient:t.defaultSigningClient||e.defaultSigningClient,walletConnect:t.walletConnect||e.walletConnect,walletType:t.defaultWallet||e.walletType,_notFoundFn:t.onNotFound||e._notFoundFn,_onReconnectFailed:t.onReconnectFailed||e._onReconnectFailed,_reconnect:t.autoReconnect===void 0?!0:t.autoReconnect||e._reconnect})),t);var it=async t=>{let{activeChain:e,signingClients:n}=m.getState();if(!e||!n)throw new Error("No connected account detected");let{defaultSigningClient:r}=y.getState();return await Promise.all(e.currencies.map(async s=>{let i=s.coinMinimalDenom.startsWith("cw20:");return n[r].getBalance(t,i?s.coinMinimalDenom.replace("cw20:",""):s.coinMinimalDenom)}))},ct=async t=>{let{clients:e}=m.getState();if(!(e!=null&&e.stargate))throw new Error("Stargate client is not ready");return e.stargate.getBalanceStaked(t)},at=async({senderAddress:t,recipientAddress:e,amount:n,fee:r,memo:o})=>{let{defaultSigningClient:s}=y.getState(),{signingClients:i}=m.getState();if(!i)throw new Error("No connected account detected");if(!t)throw new Error("senderAddress is not defined");return i[s].sendTokens(t,e,n,r,o)},ut=async({senderAddress:t,recipientAddress:e,transferAmount:n,sourcePort:r,sourceChannel:o,timeoutHeight:s,timeoutTimestamp:i,fee:a,memo:c})=>{let{signingClients:g}=m.getState();if(!(g!=null&&g.stargate))throw new Error("Stargate signing client is not ready");if(!t)throw new Error("senderAddress is not defined");return g.stargate.sendIbcTokens(t,e,n,r,o,s,i,a,c)},lt=async({senderAddress:t,msg:e,fee:n,options:r,label:o,codeId:s})=>{let{signingClients:i}=m.getState();if(!(i!=null&&i.cosmWasm))throw new Error("CosmWasm signing client is not ready");return i.cosmWasm.instantiate(t,s,e,o,n,r)},pt=async({senderAddress:t,msg:e,fee:n,contractAddress:r,funds:o,memo:s})=>{let{signingClients:i}=m.getState();if(!(i!=null&&i.cosmWasm))throw new Error("CosmWasm signing client is not ready");return i.cosmWasm.execute(t,r,e,n,s,o)},mt=async(t,e)=>{let{clients:n}=m.getState();if(!(n!=null&&n.cosmWasm))throw new Error("CosmWasm client is not ready");return await n.cosmWasm.queryContractSmart(t,e)},gt=(t,e)=>{let{clients:n}=m.getState();if(!(n!=null&&n.cosmWasm))throw new Error("CosmWasm client is not ready");let r=new TextEncoder().encode(e);return n.cosmWasm.queryContractRaw(t,r)};import{Bech32Address as Jt}from"@keplr-wallet/cosmos";var dt={coinDenom:"axl",coinMinimalDenom:"uaxl",coinDecimals:6,coinGeckoId:"axelar-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axl.png"},en={coinDenom:"usdc",coinMinimalDenom:"uusdc",coinDecimals:6,coinGeckoId:"usd-coin",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/usdc.png"},tn={coinDenom:"dai",coinMinimalDenom:"dai-wei",coinDecimals:18,coinGeckoId:"dai",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/dai.png"},nn={coinDenom:"usdt",coinMinimalDenom:"uusdt",coinDecimals:6,coinGeckoId:"tether",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/usdt.png"},on={coinDenom:"weth-wei",coinMinimalDenom:"weth",coinDecimals:18,coinGeckoId:"weth",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/weth.png"},rn={coinDenom:"wbtc-satoshi",coinMinimalDenom:"wbtc",coinDecimals:8,coinGeckoId:"wrapped-bitcoin",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/wbtc.png"},ft=[dt,en,tn,nn,on,rn],he={rpc:"https://rpc.axelar.strange.love",rest:"https://api.axelar.strange.love",chainId:"axelar-dojo-1",chainName:"Axelar",stakeCurrency:dt,bip44:{coinType:118},bech32Config:Jt.defaultBech32Config("axelar"),currencies:ft,feeCurrencies:ft};import{Bech32Address as sn}from"@keplr-wallet/cosmos";var yt={coinDenom:"atom",coinMinimalDenom:"uatom",coinDecimals:6,coinGeckoId:"cosmos",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},ht=[yt],ye={rpc:"https://rpc.cosmoshub.strange.love",rest:"https://api.cosmoshub.strange.love",chainId:"cosmoshub-4",chainName:"Cosmos Hub",stakeCurrency:yt,bip44:{coinType:118},bech32Config:sn.defaultBech32Config("cosmos"),currencies:ht,feeCurrencies:ht};import{Bech32Address as cn}from"@keplr-wallet/cosmos";var St={coinDenom:"juno",coinMinimalDenom:"ujuno",coinDecimals:6,coinGeckoId:"juno-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"},an={coinDenom:"neta",coinMinimalDenom:"cw20:juno168ctmpyppk90d34p3jjy658zf5a5l3w8wk35wht6ccqj4mr0yv8s4j5awr",coinDecimals:6,coinGeckoId:"neta",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/neta.png"},un={coinDenom:"marble",coinMinimalDenom:"cw20:juno1g2g7ucurum66d42g8k5twk34yegdq8c82858gz0tq2fc75zy7khssgnhjl",coinDecimals:3,coinGeckoId:"marble",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/marble.png"},ln={coinDenom:"hope",coinMinimalDenom:"cw20:juno1re3x67ppxap48ygndmrc7har2cnc7tcxtm9nplcas4v0gc3wnmvs3s807z",coinDecimals:6,coinGeckoId:"hope-galaxy",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hope.png"},pn={coinDenom:"rac",coinMinimalDenom:"cw20:juno1r4pzw8f9z0sypct5l9j906d47z998ulwvhvqe5xdwgy8wf84583sxwh0pa",coinDecimals:6,coinGeckoId:"racoon",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/rac.png"},mn={coinDenom:"block",coinMinimalDenom:"cw20:juno1y9rf7ql6ffwkv02hsgd4yruz23pn4w97p75e2slsnkm0mnamhzysvqnxaq",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/block.png"},gn={coinDenom:"dhk",coinMinimalDenom:"cw20:juno1tdjwrqmnztn2j3sj2ln9xnyps5hs48q3ddwjrz7jpv6mskappjys5czd49",coinDecimals:0,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/dhk.png"},fn={coinDenom:"raw",coinMinimalDenom:"cw20:juno15u3dt79t6sxxa3x3kpkhzsy56edaa5a66wvt3kxmukqjz2sx0hes5sn38g",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/raw.png",coinGeckoId:"junoswap-raw-dao"},dn={coinDenom:"asvt",coinMinimalDenom:"cw20:juno17wzaxtfdw5em7lc94yed4ylgjme63eh73lm3lutp2rhcxttyvpwsypjm4w",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/asvt.png"},hn={coinDenom:"hns",coinMinimalDenom:"cw20:juno1ur4jx0sxchdevahep7fwq28yk4tqsrhshdtylz46yka3uf6kky5qllqp4k",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hns.svg"},yn={coinDenom:"joe",coinMinimalDenom:"cw20:juno1n7n7d5088qlzlj37e9mgmkhx6dfgtvt02hqxq66lcap4dxnzdhwqfmgng3",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/joe.png"},Ct=[St,an,un,ln,pn,mn,gn,fn,dn,hn,yn],Ce={rpc:"https://rpc.juno.strange.love",rest:"https://api.juno.strange.love",chainId:"juno-1",chainName:"Juno",stakeCurrency:St,bip44:{coinType:118},bech32Config:cn.defaultBech32Config("juno"),currencies:Ct,feeCurrencies:Ct};import{Bech32Address as Cn}from"@keplr-wallet/cosmos";var At={coinDenom:"osmo",coinMinimalDenom:"uosmo",coinDecimals:6,coinGeckoId:"osmosis",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},Sn={coinDenom:"ion",coinMinimalDenom:"uion",coinDecimals:6,coinGeckoId:"ion",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/ion.png"},wt=[At,Sn],Se={rpc:"https://rpc.osmosis.strange.love",rest:"https://api.osmosis.strange.love",chainId:"osmosis-1",chainName:"Osmosis",stakeCurrency:At,bip44:{coinType:118},bech32Config:Cn.defaultBech32Config("osmo"),currencies:wt,feeCurrencies:wt};import{Bech32Address as wn}from"@keplr-wallet/cosmos";var Et={coinDenom:"somm",coinMinimalDenom:"usomm",coinDecimals:6,coinGeckoId:"sommelier",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/sommelier/images/somm.png"},xt=[Et],we={rpc:"https://rpc.sommelier.strange.love",rest:"https://api.sommelier.strange.love",chainId:"sommelier-3",chainName:"Sommelier",stakeCurrency:Et,bip44:{coinType:118},bech32Config:wn.defaultBech32Config("somm"),currencies:xt,feeCurrencies:xt};import{Bech32Address as An}from"@keplr-wallet/cosmos";var It={coinDenom:"CRE",coinMinimalDenom:"ucre",coinDecimals:6,coinGeckoId:"crescent",coinImageUrl:"https://raw.githubusercontent.com/crescent-network/asset/main/images/coin/CRE.png"},bt=[It],Ae={rpc:"https://testnet-endpoint.crescent.network/rpc/crescent",rest:"https://testnet-endpoint.crescent.network/api/crescent",chainId:"mooncat-1-1",chainName:"Crescent Testnet",bip44:{coinType:118},bech32Config:An.defaultBech32Config("CRE"),currencies:bt,feeCurrencies:bt,stakeCurrency:It,coinType:118};import{Bech32Address as xn}from"@keplr-wallet/cosmos";var xe={coinDenom:"junox",coinMinimalDenom:"ujunox",coinDecimals:6,coinGeckoId:"juno-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"},En=[xe],Ee={rpc:"https://rpc.uni.junonetwork.io",rest:"https://api.uni.junonetwork.io",chainId:"uni-5",chainName:"Juno Testnet",stakeCurrency:xe,bip44:{coinType:118},bech32Config:xn.defaultBech32Config("juno"),currencies:En,feeCurrencies:[xe],coinType:118};import{Bech32Address as bn}from"@keplr-wallet/cosmos";var be={coinDenom:"osmo",coinMinimalDenom:"uosmo",coinDecimals:6,coinGeckoId:"osmosis",coinImageUrl:"https://dhj8dql1kzq2v.cloudfront.net/white/osmo.png"},In=[be],Ie={rpc:"https://testnet-rpc.osmosis.zone",rest:"https://testnet-rest.osmosis.zone",chainId:"osmo-test-4",chainName:"Osmosis Testnet",stakeCurrency:be,bip44:{coinType:118},bech32Config:bn.defaultBech32Config("osmo"),currencies:In,feeCurrencies:[be],coinType:118};var Tt=t=>t,or=t=>t,rr=t=>t,sr=Tt({axelar:he,cosmoshub:ye,juno:Ce,osmosis:Se,sommelier:we}),ir=[he,ye,Ce,Se,we],cr=Tt({crescent:Ae,juno:Ee,osmosis:Ie}),ar=[Ae,Ee,Ie];import{useMutation as vt,useQuery as Te}from"@tanstack/react-query";import{useEffect as Dn}from"react";import{shallow as _n}from"zustand/shallow";import{useQuery as Tn}from"@tanstack/react-query";import{shallow as vn}from"zustand/shallow";var fr=()=>y(t=>({walletType:t.walletType,isCosmostation:t.walletType==="cosmostation",isCosmostationMobile:t.walletType==="wc_cosmostation_mobile",isKeplr:t.walletType==="keplr",isKeplrMobile:t.walletType==="wc_keplr_mobile",isLeap:t.walletType==="leap",isLeapMobile:t.walletType==="wc_leap_mobile",isVectis:t.walletType==="vectis",isWalletConnect:t.walletType==="walletconnect"}),vn),oe=t=>{let n=["USE_CHECK_WALLET",y(o=>t||o.walletType)];return Tn(n,({queryKey:[,o]})=>Q(o))};var G=({onConnect:t,onDisconnect:e}={})=>{let n=m(o=>o.account),r=m(o=>o.status);return Dn(()=>m.subscribe(o=>o.status,(o,s)=>{if(o==="connected"){let{account:i,activeChain:a}=m.getState(),{walletType:c}=y.getState();t==null||t({account:i,chain:a,walletType:c,isReconnect:s==="reconnecting"})}o==="disconnected"&&(e==null||e())}),[t,e]),{data:n,isConnected:!!n,isConnecting:r==="connecting",isDisconnected:r==="disconnected",isReconnecting:r==="reconnecting",isLoading:r==="connecting"||r==="reconnecting",reconnect:B,status:r}},On=t=>{let{data:e}=G(),n=t||(e==null?void 0:e.bech32Address);return Te(["USE_BALANCES",n],({queryKey:[,s]})=>it(s),{enabled:!!n,refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!1})},Er=(t,e)=>{let{data:n}=On(e);return Te(["USE_BALANCE",n,t,e],({queryKey:[,s]})=>s==null?void 0:s.find(i=>i.denom===t),{enabled:!!n})},br=({onError:t,onLoading:e,onSuccess:n}={})=>{let o=vt(["USE_CONNECT",t,e,n],Y,{onError:(i,a)=>Promise.resolve(t==null?void 0:t(i,a)),onMutate:e,onSuccess:i=>Promise.resolve(n==null?void 0:n(i))}),{data:s}=oe();return{connect:i=>o.mutate(i),connectAsync:i=>o.mutateAsync(i),error:o.error,isLoading:o.isLoading,isSuccess:o.isSuccess,isSupported:!!s,status:o.status}},Ir=({onError:t,onLoading:e,onSuccess:n}={})=>{let o=vt(["USE_DISCONNECT",t,e,n],fe,{onError:s=>Promise.resolve(t==null?void 0:t(s,void 0)),onMutate:e,onSuccess:()=>Promise.resolve(n==null?void 0:n(void 0))});return{disconnect:s=>o.mutate(s),disconnectAsync:s=>o.mutateAsync(s),error:o.error,isLoading:o.isLoading,isSuccess:o.isSuccess,status:o.status}},jn=()=>m(t=>({signer:t.offlineSigner,signerAmino:t.offlineSignerAmino,signerAuto:t.offlineSignerAuto}),_n),Tr=()=>jn(),vr=t=>{let{data:e}=G(),n=t||(e==null?void 0:e.bech32Address);return Te(["USE_BALANCE_STAKED",n],({queryKey:[,s]})=>ct(n),{enabled:!!n})};import{useMutation as Dt,useQuery as _t}from"@tanstack/react-query";var kr=()=>m(t=>t.activeChain),Br=t=>_t(["USE_ACTIVE_CHAIN_CURRENCY",t],({queryKey:[,r]})=>ot(r)),Nr=(t,e="BOND_STATUS_BONDED")=>_t(["USE_ACTIVE_CHAIN_VALIDATORS",t,e],({queryKey:[,o,s]})=>o.staking.validators(s),{enabled:typeof t<"u"}),Wr=()=>({data:y(e=>e.recentChain),clear:nt}),Mr=({onError:t,onLoading:e,onSuccess:n}={})=>{let o=Dt(["USE_SUGGEST_CHAIN",t,e,n],de,{onError:(s,i)=>Promise.resolve(t==null?void 0:t(s,i)),onMutate:e,onSuccess:s=>Promise.resolve(n==null?void 0:n(s))});return{error:o.error,isLoading:o.isLoading,isSuccess:o.isSuccess,suggest:o.mutate,suggestAsync:o.mutateAsync,status:o.status}},Rr=({onError:t,onLoading:e,onSuccess:n}={})=>{let o=Dt(["USE_SUGGEST_CHAIN_AND_CONNECT",t,e,n],rt,{onError:(i,a)=>Promise.resolve(t==null?void 0:t(i,a)),onMutate:i=>e==null?void 0:e(i),onSuccess:i=>Promise.resolve(n==null?void 0:n(i))}),{data:s}=oe();return{error:o.error,isLoading:o.isLoading,isSuccess:o.isSuccess,isSupported:!!s,status:o.status,suggestAndConnect:o.mutate,suggestAndConnectAsync:o.mutateAsync}};import{useQuery as Ot}from"@tanstack/react-query";var zr=t=>{let e=m(o=>o.clients);return Ot(["USE_CLIENTS",t,e],({queryKey:[,o,s]})=>o!=null&&o.rpc?ee(o):s,{refetchOnMount:!1,refetchOnWindowFocus:!1,onSuccess:o=>{m.setState({clients:o})},initialData:e})},Kr=t=>{let e=m(o=>o.signingClients);return Ot(["USE_SIGNING_CLIENTS",t,e],({queryKey:[,o,s]})=>o!=null&&o.rpc?te(o):s,{refetchOnMount:!1,refetchOnWindowFocus:!1,onSuccess:o=>{m.setState({signingClients:o})},initialData:e})};import{useQuery as Fn}from"@tanstack/react-query";var $r=(...t)=>{let e=["USE_QUERY_CLIENT",...t];return Fn(e,({queryKey:[,...r]})=>Ue(...t),{refetchOnMount:!1,refetchOnWindowFocus:!1})};import{useMutation as re,useQuery as jt}from"@tanstack/react-query";var es=({onError:t,onLoading:e,onSuccess:n}={})=>{let{data:r}=G(),o=r==null?void 0:r.bech32Address,i=re(["USE_SEND_TOKENS",t,e,n,o],a=>at({senderAddress:o,...a}),{onError:(a,c)=>Promise.resolve(t==null?void 0:t(a,c)),onMutate:e,onSuccess:a=>Promise.resolve(n==null?void 0:n(a))});return{error:i.error,isLoading:i.isLoading,isSuccess:i.isSuccess,sendTokens:i.mutate,sendTokensAsync:i.mutateAsync,status:i.status}},ts=({onError:t,onLoading:e,onSuccess:n}={})=>{let{data:r}=G(),o=r==null?void 0:r.bech32Address,i=re(["USE_SEND_IBC_TOKENS",t,e,n,o],a=>ut({senderAddress:o,...a}),{onError:(a,c)=>Promise.resolve(t==null?void 0:t(a,c)),onMutate:e,onSuccess:a=>Promise.resolve(n==null?void 0:n(a))});return{error:i.error,isLoading:i.isLoading,isSuccess:i.isSuccess,sendIbcTokens:i.mutate,sendIbcTokensAsync:i.mutateAsync,status:i.status}},ns=({codeId:t,onError:e,onLoading:n,onSuccess:r})=>{let{data:o}=G(),s=o==null?void 0:o.bech32Address,c=re(["USE_INSTANTIATE_CONTRACT",e,n,r,t,s],g=>{if(!s)throw new Error("senderAddress is undefined");let d={...g,fee:g.fee??"auto",senderAddress:s,codeId:t};return lt(d)},{onError:(g,d)=>Promise.resolve(e==null?void 0:e(g,d)),onMutate:n,onSuccess:g=>Promise.resolve(r==null?void 0:r(g))});return{error:c.error,isLoading:c.isLoading,isSuccess:c.isSuccess,instantiateContract:c.mutate,instantiateContractAsync:c.mutateAsync,status:c.status}},os=({contractAddress:t,onError:e,onLoading:n,onSuccess:r})=>{let{data:o}=G(),s=o==null?void 0:o.bech32Address,c=re(["USE_EXECUTE_CONTRACT",e,n,r,t,s],g=>{if(!s)throw new Error("senderAddress is undefined");let d={...g,fee:g.fee??"auto",senderAddress:s,contractAddress:t,memo:g.memo??"",funds:g.funds??[]};return pt(d)},{onError:(g,d)=>Promise.resolve(e==null?void 0:e(g,d)),onMutate:n,onSuccess:g=>Promise.resolve(r==null?void 0:r(g))});return{error:c.error,isLoading:c.isLoading,isSuccess:c.isSuccess,executeContract:c.mutate,executeContractAsync:c.mutateAsync,status:c.status}},rs=(t,e)=>jt(["USE_QUERY_SMART",t,e],({queryKey:[,o]})=>{if(!t||!e)throw new Error("address or queryMsg undefined");return mt(t,e)},{enabled:!!t&&!!e}),ss=(t,e)=>jt(["USE_QUERY_RAW",e,t],({queryKey:[,o]})=>{if(!t||!e)throw new Error("address or key undefined");return gt(t,e)},{enabled:!!t&&!!e});import{QueryClient as Rn,QueryClientProvider as Un}from"@tanstack/react-query";import{ReactQueryDevtools as Pn}from"@tanstack/react-query-devtools";import{useEffect as kn,useState as Bn}from"react";import{Fragment as Nn,jsx as Wn}from"react/jsx-runtime";var Ft=({children:t})=>{let[e,n]=Bn(!1);return kn(()=>{n(!0)},[]),Wn(Nn,{children:e?t:null})};import{useEffect as kt}from"react";var Mn=()=>{let t=typeof window<"u"&&window.sessionStorage.getItem(R)==="Active",{_reconnect:e,_onReconnectFailed:n,_reconnectConnector:r}=y(),{activeChain:o,wcSignClient:s}=m();return kt(()=>{r&&(t&&o?B({onError:n}):!t&&e&&B({onError:n}))},[]),kt(()=>{var i,a,c,g,d,x,C,E,_,L;r&&(r==="cosmostation"&&((a=(i=me()).subscription)==null||a.call(i,()=>{B({onError:n})})),r==="keplr"&&((g=(c=le()).subscription)==null||g.call(c,()=>{B({onError:n})})),r==="leap"&&((x=(d=pe()).subscription)==null||x.call(d,()=>{B({onError:n})})),r==="vectis"&&((E=(C=ge()).subscription)==null||E.call(C,()=>{B({onError:n})})),r==="walletconnect"&&s&&((L=(_=H()).subscription)==null||L.call(_,()=>{B({onError:n})})))},[r,s]),null},Bt=()=>(Mn(),null);import{jsx as Nt,jsxs as Wt}from"react/jsx-runtime";var qn=new Rn({}),As=({children:t,grazOptions:e,debug:n,...r})=>(e&&st(e),Wt(Un,{client:qn,...r,children:[Wt(Ft,{children:[Nt(Bt,{}),t]}),n?Nt(Pn,{initialIsOpen:!1,position:"bottom-right"}):null]},"graz-provider"));export{Bt as GrazEvents,As as GrazProvider,ke as WALLET_TYPES,Fe as WalletType,Q as checkWallet,nt as clearRecentChain,st as configureGraz,Y as connect,ee as createClients,Ue as createQueryClient,te as createSigningClients,or as defineChain,rr as defineChainInfo,Tt as defineChains,fe as disconnect,pt as executeContract,ot as getActiveChainCurrency,fo as getAvailableWallets,ct as getBalanceStaked,it as getBalances,me as getCosmostation,le as getKeplr,pe as getLeap,gt as getQueryRaw,mt as getQuerySmart,To as getRecentChain,ge as getVectis,Yt as getWCCosmostation,$t as getWCKeplr,Zt as getWCLeap,Z as getWallet,H as getWalletConnect,lt as instantiateContract,sr as mainnetChains,ir as mainnetChainsArray,B as reconnect,ut as sendIbcTokens,at as sendTokens,de as suggestChain,rt as suggestChainAndConnect,cr as testnetChains,ar as testnetChainsArray,G as useAccount,kr as useActiveChain,Br as useActiveChainCurrency,Nr as useActiveChainValidators,fr as useActiveWalletType,Er as useBalance,vr as useBalanceStaked,On as useBalances,oe as useCheckWallet,zr as useClients,br as useConnect,Ir as useDisconnect,os as useExecuteContract,Mn as useGrazEvents,ns as useInstantiateContract,jn as useOfflineSigners,$r as useQueryClient,ss as useQueryRaw,rs as useQuerySmart,Wr as useRecentChain,ts as useSendIbcTokens,es as useSendTokens,Tr as useSigners,Kr as useSigningClients,Mr as useSuggestChain,Rr as useSuggestChainAndConnect};
1
+ import {
2
+ RECONNECT_SESSION_KEY,
3
+ __commonJS,
4
+ __toESM
5
+ } from "./chunk-PLO5KV6X.mjs";
6
+
7
+ // ../../node_modules/.pnpm/long@4.0.0/node_modules/long/src/long.js
8
+ var require_long = __commonJS({
9
+ "../../node_modules/.pnpm/long@4.0.0/node_modules/long/src/long.js"(exports, module) {
10
+ "use strict";
11
+ module.exports = Long2;
12
+ var wasm = null;
13
+ try {
14
+ wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
15
+ 0,
16
+ 97,
17
+ 115,
18
+ 109,
19
+ 1,
20
+ 0,
21
+ 0,
22
+ 0,
23
+ 1,
24
+ 13,
25
+ 2,
26
+ 96,
27
+ 0,
28
+ 1,
29
+ 127,
30
+ 96,
31
+ 4,
32
+ 127,
33
+ 127,
34
+ 127,
35
+ 127,
36
+ 1,
37
+ 127,
38
+ 3,
39
+ 7,
40
+ 6,
41
+ 0,
42
+ 1,
43
+ 1,
44
+ 1,
45
+ 1,
46
+ 1,
47
+ 6,
48
+ 6,
49
+ 1,
50
+ 127,
51
+ 1,
52
+ 65,
53
+ 0,
54
+ 11,
55
+ 7,
56
+ 50,
57
+ 6,
58
+ 3,
59
+ 109,
60
+ 117,
61
+ 108,
62
+ 0,
63
+ 1,
64
+ 5,
65
+ 100,
66
+ 105,
67
+ 118,
68
+ 95,
69
+ 115,
70
+ 0,
71
+ 2,
72
+ 5,
73
+ 100,
74
+ 105,
75
+ 118,
76
+ 95,
77
+ 117,
78
+ 0,
79
+ 3,
80
+ 5,
81
+ 114,
82
+ 101,
83
+ 109,
84
+ 95,
85
+ 115,
86
+ 0,
87
+ 4,
88
+ 5,
89
+ 114,
90
+ 101,
91
+ 109,
92
+ 95,
93
+ 117,
94
+ 0,
95
+ 5,
96
+ 8,
97
+ 103,
98
+ 101,
99
+ 116,
100
+ 95,
101
+ 104,
102
+ 105,
103
+ 103,
104
+ 104,
105
+ 0,
106
+ 0,
107
+ 10,
108
+ 191,
109
+ 1,
110
+ 6,
111
+ 4,
112
+ 0,
113
+ 35,
114
+ 0,
115
+ 11,
116
+ 36,
117
+ 1,
118
+ 1,
119
+ 126,
120
+ 32,
121
+ 0,
122
+ 173,
123
+ 32,
124
+ 1,
125
+ 173,
126
+ 66,
127
+ 32,
128
+ 134,
129
+ 132,
130
+ 32,
131
+ 2,
132
+ 173,
133
+ 32,
134
+ 3,
135
+ 173,
136
+ 66,
137
+ 32,
138
+ 134,
139
+ 132,
140
+ 126,
141
+ 34,
142
+ 4,
143
+ 66,
144
+ 32,
145
+ 135,
146
+ 167,
147
+ 36,
148
+ 0,
149
+ 32,
150
+ 4,
151
+ 167,
152
+ 11,
153
+ 36,
154
+ 1,
155
+ 1,
156
+ 126,
157
+ 32,
158
+ 0,
159
+ 173,
160
+ 32,
161
+ 1,
162
+ 173,
163
+ 66,
164
+ 32,
165
+ 134,
166
+ 132,
167
+ 32,
168
+ 2,
169
+ 173,
170
+ 32,
171
+ 3,
172
+ 173,
173
+ 66,
174
+ 32,
175
+ 134,
176
+ 132,
177
+ 127,
178
+ 34,
179
+ 4,
180
+ 66,
181
+ 32,
182
+ 135,
183
+ 167,
184
+ 36,
185
+ 0,
186
+ 32,
187
+ 4,
188
+ 167,
189
+ 11,
190
+ 36,
191
+ 1,
192
+ 1,
193
+ 126,
194
+ 32,
195
+ 0,
196
+ 173,
197
+ 32,
198
+ 1,
199
+ 173,
200
+ 66,
201
+ 32,
202
+ 134,
203
+ 132,
204
+ 32,
205
+ 2,
206
+ 173,
207
+ 32,
208
+ 3,
209
+ 173,
210
+ 66,
211
+ 32,
212
+ 134,
213
+ 132,
214
+ 128,
215
+ 34,
216
+ 4,
217
+ 66,
218
+ 32,
219
+ 135,
220
+ 167,
221
+ 36,
222
+ 0,
223
+ 32,
224
+ 4,
225
+ 167,
226
+ 11,
227
+ 36,
228
+ 1,
229
+ 1,
230
+ 126,
231
+ 32,
232
+ 0,
233
+ 173,
234
+ 32,
235
+ 1,
236
+ 173,
237
+ 66,
238
+ 32,
239
+ 134,
240
+ 132,
241
+ 32,
242
+ 2,
243
+ 173,
244
+ 32,
245
+ 3,
246
+ 173,
247
+ 66,
248
+ 32,
249
+ 134,
250
+ 132,
251
+ 129,
252
+ 34,
253
+ 4,
254
+ 66,
255
+ 32,
256
+ 135,
257
+ 167,
258
+ 36,
259
+ 0,
260
+ 32,
261
+ 4,
262
+ 167,
263
+ 11,
264
+ 36,
265
+ 1,
266
+ 1,
267
+ 126,
268
+ 32,
269
+ 0,
270
+ 173,
271
+ 32,
272
+ 1,
273
+ 173,
274
+ 66,
275
+ 32,
276
+ 134,
277
+ 132,
278
+ 32,
279
+ 2,
280
+ 173,
281
+ 32,
282
+ 3,
283
+ 173,
284
+ 66,
285
+ 32,
286
+ 134,
287
+ 132,
288
+ 130,
289
+ 34,
290
+ 4,
291
+ 66,
292
+ 32,
293
+ 135,
294
+ 167,
295
+ 36,
296
+ 0,
297
+ 32,
298
+ 4,
299
+ 167,
300
+ 11
301
+ ])), {}).exports;
302
+ } catch (e) {
303
+ }
304
+ function Long2(low, high, unsigned) {
305
+ this.low = low | 0;
306
+ this.high = high | 0;
307
+ this.unsigned = !!unsigned;
308
+ }
309
+ Long2.prototype.__isLong__;
310
+ Object.defineProperty(Long2.prototype, "__isLong__", { value: true });
311
+ function isLong(obj) {
312
+ return (obj && obj["__isLong__"]) === true;
313
+ }
314
+ Long2.isLong = isLong;
315
+ var INT_CACHE = {};
316
+ var UINT_CACHE = {};
317
+ function fromInt(value, unsigned) {
318
+ var obj, cachedObj, cache;
319
+ if (unsigned) {
320
+ value >>>= 0;
321
+ if (cache = 0 <= value && value < 256) {
322
+ cachedObj = UINT_CACHE[value];
323
+ if (cachedObj)
324
+ return cachedObj;
325
+ }
326
+ obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true);
327
+ if (cache)
328
+ UINT_CACHE[value] = obj;
329
+ return obj;
330
+ } else {
331
+ value |= 0;
332
+ if (cache = -128 <= value && value < 128) {
333
+ cachedObj = INT_CACHE[value];
334
+ if (cachedObj)
335
+ return cachedObj;
336
+ }
337
+ obj = fromBits(value, value < 0 ? -1 : 0, false);
338
+ if (cache)
339
+ INT_CACHE[value] = obj;
340
+ return obj;
341
+ }
342
+ }
343
+ Long2.fromInt = fromInt;
344
+ function fromNumber(value, unsigned) {
345
+ if (isNaN(value))
346
+ return unsigned ? UZERO : ZERO;
347
+ if (unsigned) {
348
+ if (value < 0)
349
+ return UZERO;
350
+ if (value >= TWO_PWR_64_DBL)
351
+ return MAX_UNSIGNED_VALUE;
352
+ } else {
353
+ if (value <= -TWO_PWR_63_DBL)
354
+ return MIN_VALUE;
355
+ if (value + 1 >= TWO_PWR_63_DBL)
356
+ return MAX_VALUE;
357
+ }
358
+ if (value < 0)
359
+ return fromNumber(-value, unsigned).neg();
360
+ return fromBits(value % TWO_PWR_32_DBL | 0, value / TWO_PWR_32_DBL | 0, unsigned);
361
+ }
362
+ Long2.fromNumber = fromNumber;
363
+ function fromBits(lowBits, highBits, unsigned) {
364
+ return new Long2(lowBits, highBits, unsigned);
365
+ }
366
+ Long2.fromBits = fromBits;
367
+ var pow_dbl = Math.pow;
368
+ function fromString(str, unsigned, radix) {
369
+ if (str.length === 0)
370
+ throw Error("empty string");
371
+ if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
372
+ return ZERO;
373
+ if (typeof unsigned === "number") {
374
+ radix = unsigned, unsigned = false;
375
+ } else {
376
+ unsigned = !!unsigned;
377
+ }
378
+ radix = radix || 10;
379
+ if (radix < 2 || 36 < radix)
380
+ throw RangeError("radix");
381
+ var p;
382
+ if ((p = str.indexOf("-")) > 0)
383
+ throw Error("interior hyphen");
384
+ else if (p === 0) {
385
+ return fromString(str.substring(1), unsigned, radix).neg();
386
+ }
387
+ var radixToPower = fromNumber(pow_dbl(radix, 8));
388
+ var result = ZERO;
389
+ for (var i = 0; i < str.length; i += 8) {
390
+ var size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
391
+ if (size < 8) {
392
+ var power = fromNumber(pow_dbl(radix, size));
393
+ result = result.mul(power).add(fromNumber(value));
394
+ } else {
395
+ result = result.mul(radixToPower);
396
+ result = result.add(fromNumber(value));
397
+ }
398
+ }
399
+ result.unsigned = unsigned;
400
+ return result;
401
+ }
402
+ Long2.fromString = fromString;
403
+ function fromValue(val, unsigned) {
404
+ if (typeof val === "number")
405
+ return fromNumber(val, unsigned);
406
+ if (typeof val === "string")
407
+ return fromString(val, unsigned);
408
+ return fromBits(val.low, val.high, typeof unsigned === "boolean" ? unsigned : val.unsigned);
409
+ }
410
+ Long2.fromValue = fromValue;
411
+ var TWO_PWR_16_DBL = 1 << 16;
412
+ var TWO_PWR_24_DBL = 1 << 24;
413
+ var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
414
+ var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
415
+ var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
416
+ var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
417
+ var ZERO = fromInt(0);
418
+ Long2.ZERO = ZERO;
419
+ var UZERO = fromInt(0, true);
420
+ Long2.UZERO = UZERO;
421
+ var ONE = fromInt(1);
422
+ Long2.ONE = ONE;
423
+ var UONE = fromInt(1, true);
424
+ Long2.UONE = UONE;
425
+ var NEG_ONE = fromInt(-1);
426
+ Long2.NEG_ONE = NEG_ONE;
427
+ var MAX_VALUE = fromBits(4294967295 | 0, 2147483647 | 0, false);
428
+ Long2.MAX_VALUE = MAX_VALUE;
429
+ var MAX_UNSIGNED_VALUE = fromBits(4294967295 | 0, 4294967295 | 0, true);
430
+ Long2.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
431
+ var MIN_VALUE = fromBits(0, 2147483648 | 0, false);
432
+ Long2.MIN_VALUE = MIN_VALUE;
433
+ var LongPrototype = Long2.prototype;
434
+ LongPrototype.toInt = function toInt() {
435
+ return this.unsigned ? this.low >>> 0 : this.low;
436
+ };
437
+ LongPrototype.toNumber = function toNumber() {
438
+ if (this.unsigned)
439
+ return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
440
+ return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
441
+ };
442
+ LongPrototype.toString = function toString(radix) {
443
+ radix = radix || 10;
444
+ if (radix < 2 || 36 < radix)
445
+ throw RangeError("radix");
446
+ if (this.isZero())
447
+ return "0";
448
+ if (this.isNegative()) {
449
+ if (this.eq(MIN_VALUE)) {
450
+ var radixLong = fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
451
+ return div.toString(radix) + rem1.toInt().toString(radix);
452
+ } else
453
+ return "-" + this.neg().toString(radix);
454
+ }
455
+ var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), rem = this;
456
+ var result = "";
457
+ while (true) {
458
+ var remDiv = rem.div(radixToPower), intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, digits = intval.toString(radix);
459
+ rem = remDiv;
460
+ if (rem.isZero())
461
+ return digits + result;
462
+ else {
463
+ while (digits.length < 6)
464
+ digits = "0" + digits;
465
+ result = "" + digits + result;
466
+ }
467
+ }
468
+ };
469
+ LongPrototype.getHighBits = function getHighBits() {
470
+ return this.high;
471
+ };
472
+ LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
473
+ return this.high >>> 0;
474
+ };
475
+ LongPrototype.getLowBits = function getLowBits() {
476
+ return this.low;
477
+ };
478
+ LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
479
+ return this.low >>> 0;
480
+ };
481
+ LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
482
+ if (this.isNegative())
483
+ return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
484
+ var val = this.high != 0 ? this.high : this.low;
485
+ for (var bit = 31; bit > 0; bit--)
486
+ if ((val & 1 << bit) != 0)
487
+ break;
488
+ return this.high != 0 ? bit + 33 : bit + 1;
489
+ };
490
+ LongPrototype.isZero = function isZero() {
491
+ return this.high === 0 && this.low === 0;
492
+ };
493
+ LongPrototype.eqz = LongPrototype.isZero;
494
+ LongPrototype.isNegative = function isNegative() {
495
+ return !this.unsigned && this.high < 0;
496
+ };
497
+ LongPrototype.isPositive = function isPositive() {
498
+ return this.unsigned || this.high >= 0;
499
+ };
500
+ LongPrototype.isOdd = function isOdd() {
501
+ return (this.low & 1) === 1;
502
+ };
503
+ LongPrototype.isEven = function isEven() {
504
+ return (this.low & 1) === 0;
505
+ };
506
+ LongPrototype.equals = function equals(other) {
507
+ if (!isLong(other))
508
+ other = fromValue(other);
509
+ if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
510
+ return false;
511
+ return this.high === other.high && this.low === other.low;
512
+ };
513
+ LongPrototype.eq = LongPrototype.equals;
514
+ LongPrototype.notEquals = function notEquals(other) {
515
+ return !this.eq(
516
+ /* validates */
517
+ other
518
+ );
519
+ };
520
+ LongPrototype.neq = LongPrototype.notEquals;
521
+ LongPrototype.ne = LongPrototype.notEquals;
522
+ LongPrototype.lessThan = function lessThan(other) {
523
+ return this.comp(
524
+ /* validates */
525
+ other
526
+ ) < 0;
527
+ };
528
+ LongPrototype.lt = LongPrototype.lessThan;
529
+ LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
530
+ return this.comp(
531
+ /* validates */
532
+ other
533
+ ) <= 0;
534
+ };
535
+ LongPrototype.lte = LongPrototype.lessThanOrEqual;
536
+ LongPrototype.le = LongPrototype.lessThanOrEqual;
537
+ LongPrototype.greaterThan = function greaterThan(other) {
538
+ return this.comp(
539
+ /* validates */
540
+ other
541
+ ) > 0;
542
+ };
543
+ LongPrototype.gt = LongPrototype.greaterThan;
544
+ LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
545
+ return this.comp(
546
+ /* validates */
547
+ other
548
+ ) >= 0;
549
+ };
550
+ LongPrototype.gte = LongPrototype.greaterThanOrEqual;
551
+ LongPrototype.ge = LongPrototype.greaterThanOrEqual;
552
+ LongPrototype.compare = function compare(other) {
553
+ if (!isLong(other))
554
+ other = fromValue(other);
555
+ if (this.eq(other))
556
+ return 0;
557
+ var thisNeg = this.isNegative(), otherNeg = other.isNegative();
558
+ if (thisNeg && !otherNeg)
559
+ return -1;
560
+ if (!thisNeg && otherNeg)
561
+ return 1;
562
+ if (!this.unsigned)
563
+ return this.sub(other).isNegative() ? -1 : 1;
564
+ return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
565
+ };
566
+ LongPrototype.comp = LongPrototype.compare;
567
+ LongPrototype.negate = function negate() {
568
+ if (!this.unsigned && this.eq(MIN_VALUE))
569
+ return MIN_VALUE;
570
+ return this.not().add(ONE);
571
+ };
572
+ LongPrototype.neg = LongPrototype.negate;
573
+ LongPrototype.add = function add(addend) {
574
+ if (!isLong(addend))
575
+ addend = fromValue(addend);
576
+ var a48 = this.high >>> 16;
577
+ var a32 = this.high & 65535;
578
+ var a16 = this.low >>> 16;
579
+ var a00 = this.low & 65535;
580
+ var b48 = addend.high >>> 16;
581
+ var b32 = addend.high & 65535;
582
+ var b16 = addend.low >>> 16;
583
+ var b00 = addend.low & 65535;
584
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
585
+ c00 += a00 + b00;
586
+ c16 += c00 >>> 16;
587
+ c00 &= 65535;
588
+ c16 += a16 + b16;
589
+ c32 += c16 >>> 16;
590
+ c16 &= 65535;
591
+ c32 += a32 + b32;
592
+ c48 += c32 >>> 16;
593
+ c32 &= 65535;
594
+ c48 += a48 + b48;
595
+ c48 &= 65535;
596
+ return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
597
+ };
598
+ LongPrototype.subtract = function subtract(subtrahend) {
599
+ if (!isLong(subtrahend))
600
+ subtrahend = fromValue(subtrahend);
601
+ return this.add(subtrahend.neg());
602
+ };
603
+ LongPrototype.sub = LongPrototype.subtract;
604
+ LongPrototype.multiply = function multiply(multiplier) {
605
+ if (this.isZero())
606
+ return ZERO;
607
+ if (!isLong(multiplier))
608
+ multiplier = fromValue(multiplier);
609
+ if (wasm) {
610
+ var low = wasm.mul(
611
+ this.low,
612
+ this.high,
613
+ multiplier.low,
614
+ multiplier.high
615
+ );
616
+ return fromBits(low, wasm.get_high(), this.unsigned);
617
+ }
618
+ if (multiplier.isZero())
619
+ return ZERO;
620
+ if (this.eq(MIN_VALUE))
621
+ return multiplier.isOdd() ? MIN_VALUE : ZERO;
622
+ if (multiplier.eq(MIN_VALUE))
623
+ return this.isOdd() ? MIN_VALUE : ZERO;
624
+ if (this.isNegative()) {
625
+ if (multiplier.isNegative())
626
+ return this.neg().mul(multiplier.neg());
627
+ else
628
+ return this.neg().mul(multiplier).neg();
629
+ } else if (multiplier.isNegative())
630
+ return this.mul(multiplier.neg()).neg();
631
+ if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
632
+ return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
633
+ var a48 = this.high >>> 16;
634
+ var a32 = this.high & 65535;
635
+ var a16 = this.low >>> 16;
636
+ var a00 = this.low & 65535;
637
+ var b48 = multiplier.high >>> 16;
638
+ var b32 = multiplier.high & 65535;
639
+ var b16 = multiplier.low >>> 16;
640
+ var b00 = multiplier.low & 65535;
641
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
642
+ c00 += a00 * b00;
643
+ c16 += c00 >>> 16;
644
+ c00 &= 65535;
645
+ c16 += a16 * b00;
646
+ c32 += c16 >>> 16;
647
+ c16 &= 65535;
648
+ c16 += a00 * b16;
649
+ c32 += c16 >>> 16;
650
+ c16 &= 65535;
651
+ c32 += a32 * b00;
652
+ c48 += c32 >>> 16;
653
+ c32 &= 65535;
654
+ c32 += a16 * b16;
655
+ c48 += c32 >>> 16;
656
+ c32 &= 65535;
657
+ c32 += a00 * b32;
658
+ c48 += c32 >>> 16;
659
+ c32 &= 65535;
660
+ c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
661
+ c48 &= 65535;
662
+ return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
663
+ };
664
+ LongPrototype.mul = LongPrototype.multiply;
665
+ LongPrototype.divide = function divide(divisor) {
666
+ if (!isLong(divisor))
667
+ divisor = fromValue(divisor);
668
+ if (divisor.isZero())
669
+ throw Error("division by zero");
670
+ if (wasm) {
671
+ if (!this.unsigned && this.high === -2147483648 && divisor.low === -1 && divisor.high === -1) {
672
+ return this;
673
+ }
674
+ var low = (this.unsigned ? wasm.div_u : wasm.div_s)(
675
+ this.low,
676
+ this.high,
677
+ divisor.low,
678
+ divisor.high
679
+ );
680
+ return fromBits(low, wasm.get_high(), this.unsigned);
681
+ }
682
+ if (this.isZero())
683
+ return this.unsigned ? UZERO : ZERO;
684
+ var approx, rem, res;
685
+ if (!this.unsigned) {
686
+ if (this.eq(MIN_VALUE)) {
687
+ if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
688
+ return MIN_VALUE;
689
+ else if (divisor.eq(MIN_VALUE))
690
+ return ONE;
691
+ else {
692
+ var halfThis = this.shr(1);
693
+ approx = halfThis.div(divisor).shl(1);
694
+ if (approx.eq(ZERO)) {
695
+ return divisor.isNegative() ? ONE : NEG_ONE;
696
+ } else {
697
+ rem = this.sub(divisor.mul(approx));
698
+ res = approx.add(rem.div(divisor));
699
+ return res;
700
+ }
701
+ }
702
+ } else if (divisor.eq(MIN_VALUE))
703
+ return this.unsigned ? UZERO : ZERO;
704
+ if (this.isNegative()) {
705
+ if (divisor.isNegative())
706
+ return this.neg().div(divisor.neg());
707
+ return this.neg().div(divisor).neg();
708
+ } else if (divisor.isNegative())
709
+ return this.div(divisor.neg()).neg();
710
+ res = ZERO;
711
+ } else {
712
+ if (!divisor.unsigned)
713
+ divisor = divisor.toUnsigned();
714
+ if (divisor.gt(this))
715
+ return UZERO;
716
+ if (divisor.gt(this.shru(1)))
717
+ return UONE;
718
+ res = UZERO;
719
+ }
720
+ rem = this;
721
+ while (rem.gte(divisor)) {
722
+ approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
723
+ var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = log2 <= 48 ? 1 : pow_dbl(2, log2 - 48), approxRes = fromNumber(approx), approxRem = approxRes.mul(divisor);
724
+ while (approxRem.isNegative() || approxRem.gt(rem)) {
725
+ approx -= delta;
726
+ approxRes = fromNumber(approx, this.unsigned);
727
+ approxRem = approxRes.mul(divisor);
728
+ }
729
+ if (approxRes.isZero())
730
+ approxRes = ONE;
731
+ res = res.add(approxRes);
732
+ rem = rem.sub(approxRem);
733
+ }
734
+ return res;
735
+ };
736
+ LongPrototype.div = LongPrototype.divide;
737
+ LongPrototype.modulo = function modulo(divisor) {
738
+ if (!isLong(divisor))
739
+ divisor = fromValue(divisor);
740
+ if (wasm) {
741
+ var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(
742
+ this.low,
743
+ this.high,
744
+ divisor.low,
745
+ divisor.high
746
+ );
747
+ return fromBits(low, wasm.get_high(), this.unsigned);
748
+ }
749
+ return this.sub(this.div(divisor).mul(divisor));
750
+ };
751
+ LongPrototype.mod = LongPrototype.modulo;
752
+ LongPrototype.rem = LongPrototype.modulo;
753
+ LongPrototype.not = function not() {
754
+ return fromBits(~this.low, ~this.high, this.unsigned);
755
+ };
756
+ LongPrototype.and = function and(other) {
757
+ if (!isLong(other))
758
+ other = fromValue(other);
759
+ return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
760
+ };
761
+ LongPrototype.or = function or(other) {
762
+ if (!isLong(other))
763
+ other = fromValue(other);
764
+ return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
765
+ };
766
+ LongPrototype.xor = function xor(other) {
767
+ if (!isLong(other))
768
+ other = fromValue(other);
769
+ return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
770
+ };
771
+ LongPrototype.shiftLeft = function shiftLeft(numBits) {
772
+ if (isLong(numBits))
773
+ numBits = numBits.toInt();
774
+ if ((numBits &= 63) === 0)
775
+ return this;
776
+ else if (numBits < 32)
777
+ return fromBits(this.low << numBits, this.high << numBits | this.low >>> 32 - numBits, this.unsigned);
778
+ else
779
+ return fromBits(0, this.low << numBits - 32, this.unsigned);
780
+ };
781
+ LongPrototype.shl = LongPrototype.shiftLeft;
782
+ LongPrototype.shiftRight = function shiftRight(numBits) {
783
+ if (isLong(numBits))
784
+ numBits = numBits.toInt();
785
+ if ((numBits &= 63) === 0)
786
+ return this;
787
+ else if (numBits < 32)
788
+ return fromBits(this.low >>> numBits | this.high << 32 - numBits, this.high >> numBits, this.unsigned);
789
+ else
790
+ return fromBits(this.high >> numBits - 32, this.high >= 0 ? 0 : -1, this.unsigned);
791
+ };
792
+ LongPrototype.shr = LongPrototype.shiftRight;
793
+ LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
794
+ if (isLong(numBits))
795
+ numBits = numBits.toInt();
796
+ numBits &= 63;
797
+ if (numBits === 0)
798
+ return this;
799
+ else {
800
+ var high = this.high;
801
+ if (numBits < 32) {
802
+ var low = this.low;
803
+ return fromBits(low >>> numBits | high << 32 - numBits, high >>> numBits, this.unsigned);
804
+ } else if (numBits === 32)
805
+ return fromBits(high, 0, this.unsigned);
806
+ else
807
+ return fromBits(high >>> numBits - 32, 0, this.unsigned);
808
+ }
809
+ };
810
+ LongPrototype.shru = LongPrototype.shiftRightUnsigned;
811
+ LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
812
+ LongPrototype.toSigned = function toSigned() {
813
+ if (!this.unsigned)
814
+ return this;
815
+ return fromBits(this.low, this.high, false);
816
+ };
817
+ LongPrototype.toUnsigned = function toUnsigned() {
818
+ if (this.unsigned)
819
+ return this;
820
+ return fromBits(this.low, this.high, true);
821
+ };
822
+ LongPrototype.toBytes = function toBytes(le) {
823
+ return le ? this.toBytesLE() : this.toBytesBE();
824
+ };
825
+ LongPrototype.toBytesLE = function toBytesLE() {
826
+ var hi = this.high, lo = this.low;
827
+ return [
828
+ lo & 255,
829
+ lo >>> 8 & 255,
830
+ lo >>> 16 & 255,
831
+ lo >>> 24,
832
+ hi & 255,
833
+ hi >>> 8 & 255,
834
+ hi >>> 16 & 255,
835
+ hi >>> 24
836
+ ];
837
+ };
838
+ LongPrototype.toBytesBE = function toBytesBE() {
839
+ var hi = this.high, lo = this.low;
840
+ return [
841
+ hi >>> 24,
842
+ hi >>> 16 & 255,
843
+ hi >>> 8 & 255,
844
+ hi & 255,
845
+ lo >>> 24,
846
+ lo >>> 16 & 255,
847
+ lo >>> 8 & 255,
848
+ lo & 255
849
+ ];
850
+ };
851
+ Long2.fromBytes = function fromBytes(bytes, unsigned, le) {
852
+ return le ? Long2.fromBytesLE(bytes, unsigned) : Long2.fromBytesBE(bytes, unsigned);
853
+ };
854
+ Long2.fromBytesLE = function fromBytesLE(bytes, unsigned) {
855
+ return new Long2(
856
+ bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24,
857
+ bytes[4] | bytes[5] << 8 | bytes[6] << 16 | bytes[7] << 24,
858
+ unsigned
859
+ );
860
+ };
861
+ Long2.fromBytesBE = function fromBytesBE(bytes, unsigned) {
862
+ return new Long2(
863
+ bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7],
864
+ bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3],
865
+ unsigned
866
+ );
867
+ };
868
+ }
869
+ });
870
+
871
+ // src/store/index.ts
872
+ import { create } from "zustand";
873
+ import { createJSONStorage } from "zustand/middleware";
874
+ import { persist, subscribeWithSelector } from "zustand/middleware";
875
+
876
+ // src/types/wallet.ts
877
+ var WalletType = /* @__PURE__ */ ((WalletType2) => {
878
+ WalletType2["KEPLR"] = "keplr";
879
+ WalletType2["LEAP"] = "leap";
880
+ WalletType2["VECTIS"] = "vectis";
881
+ WalletType2["COSMOSTATION"] = "cosmostation";
882
+ WalletType2["WALLETCONNECT"] = "walletconnect";
883
+ WalletType2["WC_KEPLR_MOBILE"] = "wc_keplr_mobile";
884
+ WalletType2["WC_LEAP_MOBILE"] = "wc_leap_mobile";
885
+ WalletType2["WC_COSMOSTATION_MOBILE"] = "wc_cosmostation_mobile";
886
+ return WalletType2;
887
+ })(WalletType || {});
888
+ var WALLET_TYPES = [
889
+ "keplr" /* KEPLR */,
890
+ "leap" /* LEAP */,
891
+ "vectis" /* VECTIS */,
892
+ "cosmostation" /* COSMOSTATION */,
893
+ "walletconnect" /* WALLETCONNECT */,
894
+ "wc_keplr_mobile" /* WC_KEPLR_MOBILE */,
895
+ "wc_leap_mobile" /* WC_LEAP_MOBILE */,
896
+ "wc_cosmostation_mobile" /* WC_COSMOSTATION_MOBILE */
897
+ ];
898
+
899
+ // src/store/index.ts
900
+ var grazInternalDefaultValues = {
901
+ chains: null,
902
+ recentChains: null,
903
+ defaultClient: "stargate",
904
+ defaultSigningClient: "stargate",
905
+ walletType: "keplr" /* KEPLR */,
906
+ walletConnect: {
907
+ options: null,
908
+ web3Modal: null
909
+ },
910
+ _notFoundFn: () => null,
911
+ _onReconnectFailed: () => null,
912
+ _reconnect: false,
913
+ _reconnectConnector: null
914
+ };
915
+ var grazSessionDefaultValues = {
916
+ sessions: null,
917
+ wcSignClient: null
918
+ };
919
+ var sessionOptions = {
920
+ name: "graz-session",
921
+ version: 2,
922
+ partialize: (x) => ({
923
+ sessions: x.sessions
924
+ }),
925
+ storage: createJSONStorage(() => sessionStorage)
926
+ };
927
+ var persistOptions = {
928
+ name: "graz-internal",
929
+ partialize: (x) => ({
930
+ recentChains: x.recentChains,
931
+ _reconnect: x._reconnect,
932
+ _reconnectConnector: x._reconnectConnector
933
+ }),
934
+ version: 2
935
+ };
936
+ var useGrazSessionStore = create(
937
+ subscribeWithSelector(persist(() => grazSessionDefaultValues, sessionOptions))
938
+ );
939
+ var useGrazInternalStore = create(
940
+ subscribeWithSelector(persist(() => grazInternalDefaultValues, persistOptions))
941
+ );
942
+
943
+ // src/utils/mergeSessions.ts
944
+ var mergeSessions = ({ prev, next }) => {
945
+ if (!prev)
946
+ return next;
947
+ const prevKeys = prev.map((v) => v.chainId);
948
+ const nextKeys = next.map((v) => v.chainId);
949
+ const keys = [...prevKeys, ...nextKeys].filter((item, i, ar) => ar.indexOf(item) === i);
950
+ const result = keys.map((key) => {
951
+ const prevValue = prev.find((v) => v.chainId === key);
952
+ const nextValue = next.find((v) => v.chainId === key);
953
+ const value = nextValue || prevValue;
954
+ return {
955
+ ...value,
956
+ chainId: key
957
+ };
958
+ });
959
+ return result;
960
+ };
961
+
962
+ // src/actions/wallet.ts
963
+ var import_long = __toESM(require_long());
964
+ import { fromBech32 } from "@cosmjs/encoding";
965
+ import { SignClient } from "@walletconnect/sign-client";
966
+ import { getSdkError } from "@walletconnect/utils";
967
+
968
+ // src/utils/os.ts
969
+ var isMobile = () => {
970
+ if (typeof window !== "undefined") {
971
+ return Boolean(
972
+ window.matchMedia("(pointer:coarse)").matches || /Android|webOS|iPhone|iPad|iPod|BlackBerry|Opera Mini/u.test(navigator.userAgent)
973
+ );
974
+ }
975
+ return false;
976
+ };
977
+ var isAndroid = () => {
978
+ return isMobile() && navigator.userAgent.toLowerCase().includes("android");
979
+ };
980
+ var isIos = () => {
981
+ return isMobile() && (navigator.userAgent.toLowerCase().includes("iphone") || navigator.userAgent.toLowerCase().includes("ipad"));
982
+ };
983
+
984
+ // src/utils/timeout.ts
985
+ var promiseWithTimeout = (promise, ms, timeoutError = new Error("Promise timed out")) => {
986
+ const timeout = new Promise((_, reject) => {
987
+ setTimeout(() => {
988
+ reject(timeoutError);
989
+ }, ms);
990
+ });
991
+ return Promise.race([promise, timeout]);
992
+ };
993
+
994
+ // src/actions/wallet.ts
995
+ var checkWallet = (type = useGrazInternalStore.getState().walletType) => {
996
+ try {
997
+ getWallet(type);
998
+ return true;
999
+ } catch (error) {
1000
+ return false;
1001
+ }
1002
+ };
1003
+ var clearSession = () => {
1004
+ window.sessionStorage.removeItem(RECONNECT_SESSION_KEY);
1005
+ useGrazSessionStore.setState(grazSessionDefaultValues);
1006
+ };
1007
+ var getKeplr = () => {
1008
+ if (typeof window.keplr !== "undefined") {
1009
+ const keplr = window.keplr;
1010
+ const subscription = (reconnect2) => {
1011
+ window.addEventListener("keplr_keystorechange", () => {
1012
+ clearSession();
1013
+ reconnect2();
1014
+ });
1015
+ return () => {
1016
+ window.removeEventListener("keplr_keystorechange", () => {
1017
+ clearSession();
1018
+ reconnect2();
1019
+ });
1020
+ };
1021
+ };
1022
+ const res = Object.assign(keplr, {
1023
+ subscription
1024
+ });
1025
+ return res;
1026
+ }
1027
+ useGrazInternalStore.getState()._notFoundFn();
1028
+ throw new Error("window.keplr is not defined");
1029
+ };
1030
+ var getLeap = () => {
1031
+ if (typeof window.leap !== "undefined") {
1032
+ const leap = window.leap;
1033
+ const subscription = (reconnect2) => {
1034
+ window.addEventListener("leap_keystorechange", () => {
1035
+ clearSession();
1036
+ reconnect2();
1037
+ });
1038
+ return () => {
1039
+ window.removeEventListener("leap_keystorechange", () => {
1040
+ clearSession();
1041
+ reconnect2();
1042
+ });
1043
+ };
1044
+ };
1045
+ const res = Object.assign(leap, {
1046
+ subscription
1047
+ });
1048
+ return res;
1049
+ }
1050
+ useGrazInternalStore.getState()._notFoundFn();
1051
+ throw new Error("window.leap is not defined");
1052
+ };
1053
+ var getCosmostation = () => {
1054
+ if (typeof window.cosmostation.providers.keplr !== "undefined") {
1055
+ const cosmostation = window.cosmostation.providers.keplr;
1056
+ const subscription = (reconnect2) => {
1057
+ window.cosmostation.cosmos.on("accountChanged", () => {
1058
+ clearSession();
1059
+ reconnect2();
1060
+ });
1061
+ return () => {
1062
+ window.cosmostation.cosmos.off("accountChanged", () => {
1063
+ clearSession();
1064
+ reconnect2();
1065
+ });
1066
+ };
1067
+ };
1068
+ const res = Object.assign(cosmostation, {
1069
+ subscription
1070
+ });
1071
+ return res;
1072
+ }
1073
+ useGrazInternalStore.getState()._notFoundFn();
1074
+ throw new Error("window.cosmostation.providers.keplr is not defined");
1075
+ };
1076
+ var getVectis = () => {
1077
+ if (typeof window.vectis !== "undefined") {
1078
+ const vectis = window.vectis.cosmos;
1079
+ const subscription = (reconnect2) => {
1080
+ window.addEventListener("vectis_accountChanged", () => {
1081
+ clearSession();
1082
+ reconnect2();
1083
+ });
1084
+ return () => {
1085
+ window.removeEventListener("vectis_accountChanged", () => {
1086
+ clearSession();
1087
+ reconnect2();
1088
+ });
1089
+ };
1090
+ };
1091
+ const getOfflineSignerOnlyAmino = (...args) => {
1092
+ return vectis.getOfflineSignerAmino(...args);
1093
+ };
1094
+ const experimentalSuggestChain = async (...args) => {
1095
+ const [chainInfo] = args;
1096
+ const adaptChainInfo = {
1097
+ ...chainInfo,
1098
+ rpcUrl: chainInfo.rpc,
1099
+ restUrl: chainInfo.rest,
1100
+ prettyName: chainInfo.chainName.replace(" ", ""),
1101
+ bech32Prefix: chainInfo.bech32Config.bech32PrefixAccAddr
1102
+ };
1103
+ return vectis.suggestChains([adaptChainInfo]);
1104
+ };
1105
+ const getKey = async (chainId) => {
1106
+ const key = await vectis.getKey(chainId);
1107
+ return {
1108
+ address: fromBech32(key.address).data,
1109
+ algo: key.algo,
1110
+ bech32Address: key.address,
1111
+ name: key.name,
1112
+ pubKey: key.pubKey,
1113
+ isKeystone: false,
1114
+ isNanoLedger: key.isNanoLedger
1115
+ };
1116
+ };
1117
+ const signDirect = async (...args) => {
1118
+ var _a;
1119
+ const { 1: signer, 2: signDoc } = args;
1120
+ return vectis.signDirect(signer, {
1121
+ bodyBytes: signDoc.bodyBytes || Uint8Array.from([]),
1122
+ authInfoBytes: signDoc.authInfoBytes || Uint8Array.from([]),
1123
+ accountNumber: import_long.default.fromString(((_a = signDoc.accountNumber) == null ? void 0 : _a.toString()) || "", false),
1124
+ chainId: signDoc.chainId || ""
1125
+ });
1126
+ };
1127
+ const signAmino = async (...args) => {
1128
+ const { 1: signer, 2: signDoc } = args;
1129
+ return vectis.signAmino(signer, signDoc);
1130
+ };
1131
+ return {
1132
+ enable: (chainId) => vectis.enable(chainId),
1133
+ getOfflineSigner: (chainId) => vectis.getOfflineSigner(chainId),
1134
+ getOfflineSignerAuto: (chainId) => vectis.getOfflineSignerAuto(chainId),
1135
+ getKey,
1136
+ subscription,
1137
+ getOfflineSignerOnlyAmino,
1138
+ experimentalSuggestChain,
1139
+ signDirect,
1140
+ signAmino
1141
+ };
1142
+ }
1143
+ useGrazInternalStore.getState()._notFoundFn();
1144
+ throw new Error("window.vectis is not defined");
1145
+ };
1146
+ var getWalletConnect = (params) => {
1147
+ var _a, _b, _c;
1148
+ if (!((_c = (_b = (_a = useGrazInternalStore.getState().walletConnect) == null ? void 0 : _a.options) == null ? void 0 : _b.projectId) == null ? void 0 : _c.trim())) {
1149
+ throw new Error("walletConnect.options.projectId is not defined");
1150
+ }
1151
+ const encoding = (params == null ? void 0 : params.encoding) || "base64";
1152
+ const redirectToApp = (wcUri) => {
1153
+ if (!params)
1154
+ return;
1155
+ const { appUrl, formatNativeUrl } = params;
1156
+ if (!isMobile())
1157
+ return;
1158
+ if (isAndroid()) {
1159
+ if (!wcUri) {
1160
+ window.open(appUrl.mobile.android, "_self", "noreferrer noopener");
1161
+ } else {
1162
+ const href = formatNativeUrl(appUrl.mobile.android, wcUri, "android");
1163
+ window.open(href, "_self", "noreferrer noopener");
1164
+ }
1165
+ }
1166
+ if (isIos()) {
1167
+ if (!wcUri) {
1168
+ window.open(appUrl.mobile.ios, "_self", "noreferrer noopener");
1169
+ } else {
1170
+ const href = formatNativeUrl(appUrl.mobile.ios, wcUri, "ios");
1171
+ window.open(href, "_self", "noreferrer noopener");
1172
+ }
1173
+ }
1174
+ };
1175
+ const _disconnect = () => {
1176
+ const { wcSignClient } = useGrazSessionStore.getState();
1177
+ if (!wcSignClient)
1178
+ throw new Error("walletConnect.signClient is not defined");
1179
+ clearSession();
1180
+ useGrazInternalStore.setState({
1181
+ _reconnect: false,
1182
+ _reconnectConnector: null,
1183
+ recentChains: null
1184
+ });
1185
+ };
1186
+ const wcDisconnect = async (topic) => {
1187
+ const { wcSignClient } = useGrazSessionStore.getState();
1188
+ if (!wcSignClient)
1189
+ throw new Error("walletConnect.signClient is not defined");
1190
+ if (!topic)
1191
+ throw new Error("No wallet connect session");
1192
+ await wcSignClient.disconnect({
1193
+ topic,
1194
+ reason: getSdkError("USER_DISCONNECTED")
1195
+ });
1196
+ await deleteInactivePairings(wcSignClient);
1197
+ _disconnect();
1198
+ };
1199
+ const getSession = (chainId) => {
1200
+ try {
1201
+ const { wcSignClient } = useGrazSessionStore.getState();
1202
+ if (!wcSignClient)
1203
+ throw new Error("walletConnect.signClient is not defined");
1204
+ const lastSession = wcSignClient.session.getAll().at(-1);
1205
+ if (!lastSession)
1206
+ return;
1207
+ const isValid = lastSession.expiry * 1e3 > Date.now() + 1e3;
1208
+ if (!isValid) {
1209
+ void wcDisconnect(lastSession.topic);
1210
+ throw new Error("invalid session");
1211
+ }
1212
+ try {
1213
+ const chainSession = wcSignClient.find({
1214
+ requiredNamespaces: {
1215
+ cosmos: {
1216
+ methods: ["cosmos_getAccounts", "cosmos_signAmino", "cosmos_signDirect"],
1217
+ chains: chainId.map((i) => `cosmos:${i}`),
1218
+ events: ["chainChanged", "accountsChanged"]
1219
+ }
1220
+ }
1221
+ });
1222
+ if (!chainSession.length) {
1223
+ throw new Error("no session");
1224
+ }
1225
+ return chainSession.at(-1);
1226
+ } catch (error) {
1227
+ if (!error.message.toLowerCase().includes("no matching key"))
1228
+ throw error;
1229
+ }
1230
+ return lastSession;
1231
+ } catch (error) {
1232
+ if (!error.message.toLowerCase().includes("no matching key"))
1233
+ throw error;
1234
+ }
1235
+ };
1236
+ const checkSession = (chainId) => {
1237
+ try {
1238
+ const lastSession = getSession(chainId);
1239
+ return lastSession;
1240
+ } catch (error) {
1241
+ return void 0;
1242
+ }
1243
+ };
1244
+ const deleteInactivePairings = async (signClient) => {
1245
+ try {
1246
+ const pairings = signClient.core.pairing.pairings.getAll({ active: false });
1247
+ if (!pairings.length)
1248
+ return;
1249
+ await Promise.all(
1250
+ pairings.map(async (pairing) => {
1251
+ await signClient.core.pairing.pairings.delete(pairing.topic, {
1252
+ code: 7001,
1253
+ message: "clear pairing"
1254
+ });
1255
+ })
1256
+ );
1257
+ } catch (error) {
1258
+ if (!error.message.toLowerCase().includes("no matching key"))
1259
+ throw error;
1260
+ }
1261
+ };
1262
+ const init = async () => {
1263
+ const { walletConnect } = useGrazInternalStore.getState();
1264
+ if (!(walletConnect == null ? void 0 : walletConnect.options))
1265
+ throw new Error("walletConnect.options is not defined");
1266
+ const { wcSignClient } = useGrazSessionStore.getState();
1267
+ if (wcSignClient) {
1268
+ useGrazSessionStore.setState({ wcSignClient });
1269
+ return wcSignClient;
1270
+ }
1271
+ const signClient = await SignClient.init(walletConnect.options);
1272
+ useGrazSessionStore.setState({ wcSignClient: signClient });
1273
+ return signClient;
1274
+ };
1275
+ const subscription = (reconnect2) => {
1276
+ const { wcSignClient } = useGrazSessionStore.getState();
1277
+ if (!wcSignClient)
1278
+ return;
1279
+ wcSignClient.events.on("session_delete", (_) => {
1280
+ _disconnect();
1281
+ });
1282
+ wcSignClient.events.on("session_expire", (_) => {
1283
+ _disconnect();
1284
+ });
1285
+ wcSignClient.events.on("session_event", (args) => {
1286
+ var _a2, _b2;
1287
+ if (args.params.event.name === "accountsChanged" && !((_b2 = useGrazSessionStore.getState().sessions) == null ? void 0 : _b2.map((i) => {
1288
+ var _a3;
1289
+ return (_a3 = i.account) == null ? void 0 : _a3.bech32Address;
1290
+ }).includes((_a2 = args.params.event.data) == null ? void 0 : _a2[0]))) {
1291
+ const chainId = args.params.chainId.split(":")[1];
1292
+ chainId && void enable([chainId]);
1293
+ } else {
1294
+ reconnect2();
1295
+ }
1296
+ });
1297
+ return () => {
1298
+ wcSignClient.events.off("session_delete", (_) => {
1299
+ _disconnect();
1300
+ });
1301
+ wcSignClient.events.off("session_expire", (_) => {
1302
+ _disconnect();
1303
+ });
1304
+ wcSignClient.events.off("session_event", (args) => {
1305
+ var _a2, _b2;
1306
+ if (args.params.event.name === "accountsChanged" && !((_b2 = useGrazSessionStore.getState().sessions) == null ? void 0 : _b2.map((i) => {
1307
+ var _a3;
1308
+ return (_a3 = i.account) == null ? void 0 : _a3.bech32Address;
1309
+ }).includes((_a2 = args.params.event.data) == null ? void 0 : _a2[0]))) {
1310
+ const chainId = args.params.chainId.split(":")[1];
1311
+ chainId && void enable([chainId]);
1312
+ } else {
1313
+ reconnect2();
1314
+ }
1315
+ });
1316
+ };
1317
+ };
1318
+ const enable = async (chainId) => {
1319
+ var _a2;
1320
+ const { wcSignClient: signClient } = useGrazSessionStore.getState();
1321
+ if (!signClient)
1322
+ throw new Error("enable walletConnect.signClient is not defined");
1323
+ const { walletConnect } = useGrazInternalStore.getState();
1324
+ if (!((_a2 = walletConnect == null ? void 0 : walletConnect.options) == null ? void 0 : _a2.projectId))
1325
+ throw new Error("walletConnect.options.projectId is not defined");
1326
+ const { Web3Modal } = await import("@web3modal/standalone");
1327
+ const web3Modal = new Web3Modal({
1328
+ projectId: walletConnect.options.projectId,
1329
+ walletConnectVersion: 2,
1330
+ enableExplorer: false,
1331
+ explorerRecommendedWalletIds: "NONE",
1332
+ ...walletConnect.web3Modal
1333
+ // explorerRecommendedWalletIds: [
1334
+ // https://walletconnect.com/explorer?type=wallet&version=2&chains=cosmos%3Acosmoshub-4
1335
+ // keplr doesn't have complete app object better hide it for now and use getKeplr
1336
+ // "6adb6082c909901b9e7189af3a4a0223102cd6f8d5c39e39f3d49acb92b578bb",
1337
+ // "3ed8cc046c6211a798dc5ec70f1302b43e07db9639fd287de44a9aa115a21ed6",
1338
+ // "feb6ff1fb426db18110f5a80c7adbde846d0a7e96b2bc53af4b73aaf32552bea",
1339
+ // "afbd95522f4041c71dd4f1a065f971fd32372865b416f95a0b1db759ae33f2a7",
1340
+ // "85db431492aa2e8672e93f4ea7acf10c88b97b867b0d373107af63dc4880f041",
1341
+ // "7674bb4e353bf52886768a3ddc2a4562ce2f4191c80831291218ebd90f5f5e26",
1342
+ // "0b415a746fb9ee99cce155c2ceca0c6f6061b1dbca2d722b3ba16381d0562150",
1343
+ // "022e8ff84519e427bff394b3a58308bc9838196a8efb45158da0ab7c3228abfb",
1344
+ // "f896cbca30cd6dc414712d3d6fcc2f8f7d35d5bd30e3b1fc5d60cf6c8926f98f",
1345
+ // ],
1346
+ });
1347
+ const lastSession = checkSession(chainId);
1348
+ if (!lastSession) {
1349
+ const { uri, approval } = await signClient.connect({
1350
+ requiredNamespaces: {
1351
+ cosmos: {
1352
+ methods: ["cosmos_getAccounts", "cosmos_signAmino", "cosmos_signDirect"],
1353
+ chains: chainId.map((i) => `cosmos:${i}`),
1354
+ events: ["chainChanged", "accountsChanged"]
1355
+ }
1356
+ }
1357
+ });
1358
+ if (!uri)
1359
+ throw new Error("No wallet connect uri");
1360
+ if (!params) {
1361
+ await web3Modal.openModal({ uri });
1362
+ } else {
1363
+ redirectToApp(uri);
1364
+ }
1365
+ try {
1366
+ await promiseWithTimeout(
1367
+ (async () => {
1368
+ await approval();
1369
+ })(),
1370
+ 4e4,
1371
+ new Error("Modal approval timeout")
1372
+ );
1373
+ } catch (error) {
1374
+ web3Modal.closeModal();
1375
+ if (!error.message.toLowerCase().includes("no matching key"))
1376
+ return Promise.reject(error);
1377
+ }
1378
+ if (!params) {
1379
+ web3Modal.closeModal();
1380
+ }
1381
+ return Promise.resolve();
1382
+ }
1383
+ try {
1384
+ await promiseWithTimeout(
1385
+ (async () => {
1386
+ const sessions = await Promise.all(
1387
+ chainId.map(async (i) => {
1388
+ const wcAccount = await getKey(i);
1389
+ return { account: wcAccount, chainId: i, status: "connected" };
1390
+ })
1391
+ );
1392
+ useGrazSessionStore.setState((prev) => ({
1393
+ sessions: mergeSessions({ prev: prev.sessions, next: sessions })
1394
+ }));
1395
+ })(),
1396
+ 1e4 * chainId.length,
1397
+ new Error("Connection timeout")
1398
+ );
1399
+ } catch (error) {
1400
+ void wcDisconnect(lastSession.topic);
1401
+ if (!error.message.toLowerCase().includes("no matching key"))
1402
+ throw error;
1403
+ }
1404
+ };
1405
+ const getAccount = async (chainId) => {
1406
+ var _a2;
1407
+ const { wcSignClient } = useGrazSessionStore.getState();
1408
+ if (!wcSignClient)
1409
+ throw new Error("walletConnect.signClient is not defined");
1410
+ const topic = (_a2 = getSession([chainId])) == null ? void 0 : _a2.topic;
1411
+ if (!topic)
1412
+ throw new Error("No wallet connect session");
1413
+ redirectToApp();
1414
+ const result = await wcSignClient.request({
1415
+ topic,
1416
+ chainId: `cosmos:${chainId}`,
1417
+ request: {
1418
+ method: "cosmos_getAccounts",
1419
+ params: {}
1420
+ }
1421
+ });
1422
+ if (!result[0])
1423
+ throw new Error("No wallet connect account");
1424
+ return {
1425
+ address: result[0].address,
1426
+ algo: result[0].algo,
1427
+ pubkey: new Uint8Array(Buffer.from(result[0].pubkey, encoding))
1428
+ };
1429
+ };
1430
+ const getKey = async (chainId) => {
1431
+ const { address, algo, pubkey } = await getAccount(chainId);
1432
+ return {
1433
+ address: fromBech32(address).data,
1434
+ algo,
1435
+ bech32Address: address,
1436
+ name: "",
1437
+ pubKey: pubkey,
1438
+ isKeystone: false,
1439
+ isNanoLedger: false
1440
+ };
1441
+ };
1442
+ const wcSignDirect = async (...args) => {
1443
+ var _a2, _b2;
1444
+ const [chainId, signer, signDoc] = args;
1445
+ const { wcSignClient } = useGrazSessionStore.getState();
1446
+ if (!wcSignClient)
1447
+ throw new Error("walletConnect.signClient is not defined");
1448
+ const topic = (_a2 = getSession([chainId])) == null ? void 0 : _a2.topic;
1449
+ if (!topic)
1450
+ throw new Error("No wallet connect session");
1451
+ if (!signDoc.bodyBytes)
1452
+ throw new Error("No bodyBytes");
1453
+ if (!signDoc.authInfoBytes)
1454
+ throw new Error("No authInfoBytes");
1455
+ const req = {
1456
+ topic,
1457
+ chainId: `cosmos:${chainId}`,
1458
+ request: {
1459
+ method: "cosmos_signDirect",
1460
+ params: {
1461
+ signerAddress: signer,
1462
+ signDoc: {
1463
+ ...signDoc,
1464
+ bodyBytes: Buffer.from(signDoc.bodyBytes).toString(encoding),
1465
+ authInfoBytes: Buffer.from(signDoc.authInfoBytes).toString(encoding),
1466
+ accountNumber: (_b2 = signDoc.accountNumber) == null ? void 0 : _b2.toString()
1467
+ }
1468
+ }
1469
+ }
1470
+ };
1471
+ redirectToApp();
1472
+ const result = await wcSignClient.request(req);
1473
+ return result;
1474
+ };
1475
+ const signDirect = async (...args) => {
1476
+ const [chainId, signer, signDoc] = args;
1477
+ const { signature, signed } = await wcSignDirect(chainId, signer, signDoc);
1478
+ return {
1479
+ signed: {
1480
+ chainId: signed.chainId,
1481
+ accountNumber: import_long.default.fromString(signed.accountNumber, false),
1482
+ authInfoBytes: new Uint8Array(Buffer.from(signed.authInfoBytes, encoding)),
1483
+ bodyBytes: new Uint8Array(Buffer.from(signed.bodyBytes, encoding))
1484
+ },
1485
+ signature
1486
+ };
1487
+ };
1488
+ const wcSignAmino = async (...args) => {
1489
+ var _a2;
1490
+ const [chainId, signer, signDoc, _signOptions] = args;
1491
+ const { wcSignClient } = useGrazSessionStore.getState();
1492
+ if (!wcSignClient)
1493
+ throw new Error("walletConnect.signClient is not defined");
1494
+ const topic = (_a2 = getSession([chainId])) == null ? void 0 : _a2.topic;
1495
+ if (!topic)
1496
+ throw new Error("No wallet connect session");
1497
+ redirectToApp();
1498
+ const result = await wcSignClient.request({
1499
+ topic,
1500
+ chainId: `cosmos:${chainId}`,
1501
+ request: {
1502
+ method: "cosmos_signDirect",
1503
+ params: {
1504
+ signerAddress: signer,
1505
+ signDoc
1506
+ }
1507
+ }
1508
+ });
1509
+ return result;
1510
+ };
1511
+ const signAmino = async (...args) => {
1512
+ const [chainId, signer, signDoc, _signOptions] = args;
1513
+ const result = await wcSignAmino(chainId, signer, signDoc);
1514
+ return result;
1515
+ };
1516
+ const getOfflineSignerDirect = (chainId) => {
1517
+ return {
1518
+ getAccounts: async () => [await getAccount(chainId)],
1519
+ signDirect: (signerAddress, signDoc) => signDirect(chainId, signerAddress, signDoc)
1520
+ };
1521
+ };
1522
+ const getOfflineSignerOnlyAmino = (chainId) => {
1523
+ return {
1524
+ getAccounts: async () => [await getAccount(chainId)],
1525
+ signAmino: (signerAddress, signDoc) => signAmino(chainId, signerAddress, signDoc)
1526
+ };
1527
+ };
1528
+ const getOfflineSigner = (chainId) => {
1529
+ return {
1530
+ getAccounts: async () => [await getAccount(chainId)],
1531
+ signDirect: (signerAddress, signDoc) => signDirect(chainId, signerAddress, signDoc),
1532
+ signAmino: (signerAddress, signDoc) => signAmino(chainId, signerAddress, signDoc)
1533
+ };
1534
+ };
1535
+ const getOfflineSignerAuto = async (chainId) => {
1536
+ const key = await getKey(chainId);
1537
+ if (key.isNanoLedger)
1538
+ return getOfflineSignerOnlyAmino(chainId);
1539
+ return getOfflineSignerDirect(chainId);
1540
+ };
1541
+ const experimentalSuggestChain = async (..._args) => {
1542
+ await Promise.reject(new Error("WalletConnect does not support experimentalSuggestChain"));
1543
+ };
1544
+ return {
1545
+ enable,
1546
+ experimentalSuggestChain,
1547
+ getKey,
1548
+ getOfflineSigner,
1549
+ getOfflineSignerAuto,
1550
+ getOfflineSignerOnlyAmino,
1551
+ signAmino,
1552
+ signDirect,
1553
+ subscription,
1554
+ init
1555
+ };
1556
+ };
1557
+ var getWCKeplr = () => {
1558
+ var _a, _b, _c;
1559
+ if (!((_c = (_b = (_a = useGrazInternalStore.getState().walletConnect) == null ? void 0 : _a.options) == null ? void 0 : _b.projectId) == null ? void 0 : _c.trim())) {
1560
+ throw new Error("walletConnect.options.projectId is not defined");
1561
+ }
1562
+ if (!isMobile())
1563
+ throw new Error("WalletConnect Keplr mobile is only supported in mobile");
1564
+ const params = {
1565
+ encoding: "base64",
1566
+ appUrl: {
1567
+ mobile: {
1568
+ ios: "keplrwallet://",
1569
+ android: "intent://"
1570
+ }
1571
+ },
1572
+ walletType: "wc_keplr_mobile" /* WC_KEPLR_MOBILE */,
1573
+ formatNativeUrl: (appUrl, wcUri, os) => {
1574
+ const plainAppUrl = appUrl.replaceAll("/", "").replaceAll(":", "");
1575
+ const encoded = encodeURIComponent(wcUri);
1576
+ switch (os) {
1577
+ case "ios":
1578
+ return `${plainAppUrl}://wcV2?${encoded}`;
1579
+ case "android":
1580
+ return `${plainAppUrl}://wcV2?${encoded}#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;`;
1581
+ default:
1582
+ return `${plainAppUrl}://wc?uri=${encoded}`;
1583
+ }
1584
+ }
1585
+ };
1586
+ return getWalletConnect(params);
1587
+ };
1588
+ var getWCLeap = () => {
1589
+ var _a, _b, _c;
1590
+ if (!((_c = (_b = (_a = useGrazInternalStore.getState().walletConnect) == null ? void 0 : _a.options) == null ? void 0 : _b.projectId) == null ? void 0 : _c.trim())) {
1591
+ throw new Error("walletConnect.options.projectId is not defined");
1592
+ }
1593
+ if (!isMobile())
1594
+ throw new Error("WalletConnect Leap mobile is only supported in mobile");
1595
+ const params = {
1596
+ encoding: "base64",
1597
+ appUrl: {
1598
+ mobile: {
1599
+ ios: "leapcosmos://",
1600
+ android: "intent://"
1601
+ }
1602
+ },
1603
+ walletType: "wc_leap_mobile" /* WC_LEAP_MOBILE */,
1604
+ formatNativeUrl: (appUrl, wcUri, os) => {
1605
+ const plainAppUrl = appUrl.replaceAll("/", "").replaceAll(":", "");
1606
+ const encoded = encodeURIComponent(wcUri);
1607
+ switch (os) {
1608
+ case "ios":
1609
+ return `${plainAppUrl}://wcV2?${encoded}`;
1610
+ case "android":
1611
+ return `${plainAppUrl}://wcV2?${encoded}#Intent;package=io.leapwallet.cosmos;scheme=leapwallet;end;`;
1612
+ default:
1613
+ return `${plainAppUrl}://wc?uri=${encoded}`;
1614
+ }
1615
+ }
1616
+ };
1617
+ return getWalletConnect(params);
1618
+ };
1619
+ var getWCCosmostation = () => {
1620
+ var _a, _b, _c;
1621
+ if (!((_c = (_b = (_a = useGrazInternalStore.getState().walletConnect) == null ? void 0 : _a.options) == null ? void 0 : _b.projectId) == null ? void 0 : _c.trim())) {
1622
+ throw new Error("walletConnect.options.projectId is not defined");
1623
+ }
1624
+ if (!isMobile())
1625
+ throw new Error("WalletConnect Leap mobile is only supported in mobile");
1626
+ const params = {
1627
+ encoding: "hex",
1628
+ appUrl: {
1629
+ mobile: {
1630
+ ios: "cosmostation://",
1631
+ android: "cosmostation://"
1632
+ }
1633
+ },
1634
+ walletType: "wc_leap_mobile" /* WC_LEAP_MOBILE */,
1635
+ formatNativeUrl: (appUrl, wcUri, _os) => {
1636
+ const plainAppUrl = appUrl.replaceAll("/", "").replaceAll(":", "");
1637
+ return `${plainAppUrl}://wc?${wcUri}`;
1638
+ }
1639
+ };
1640
+ return getWalletConnect(params);
1641
+ };
1642
+ var getWallet = (type = useGrazInternalStore.getState().walletType) => {
1643
+ switch (type) {
1644
+ case "keplr" /* KEPLR */: {
1645
+ return getKeplr();
1646
+ }
1647
+ case "leap" /* LEAP */: {
1648
+ return getLeap();
1649
+ }
1650
+ case "cosmostation" /* COSMOSTATION */: {
1651
+ return getCosmostation();
1652
+ }
1653
+ case "vectis" /* VECTIS */: {
1654
+ return getVectis();
1655
+ }
1656
+ case "walletconnect" /* WALLETCONNECT */: {
1657
+ return getWalletConnect();
1658
+ }
1659
+ case "wc_keplr_mobile" /* WC_KEPLR_MOBILE */: {
1660
+ return getWCKeplr();
1661
+ }
1662
+ case "wc_leap_mobile" /* WC_LEAP_MOBILE */: {
1663
+ return getWCLeap();
1664
+ }
1665
+ case "wc_cosmostation_mobile" /* WC_COSMOSTATION_MOBILE */: {
1666
+ return getWCCosmostation();
1667
+ }
1668
+ default: {
1669
+ throw new Error("Unknown wallet type");
1670
+ }
1671
+ }
1672
+ };
1673
+ var getAvailableWallets = () => {
1674
+ return Object.fromEntries(WALLET_TYPES.map((type) => [type, checkWallet(type)]));
1675
+ };
1676
+
1677
+ // src/actions/account.ts
1678
+ var connect = async (args) => {
1679
+ var _a, _b;
1680
+ try {
1681
+ const { recentChains, walletType } = useGrazInternalStore.getState();
1682
+ if ((args == null ? void 0 : args.walletType) && args.walletType !== walletType) {
1683
+ await disconnect();
1684
+ }
1685
+ const currentWalletType = (args == null ? void 0 : args.walletType) || walletType;
1686
+ const isWalletAvailable = checkWallet(currentWalletType);
1687
+ if (!isWalletAvailable) {
1688
+ throw new Error(`${currentWalletType} is not available`);
1689
+ }
1690
+ const wallet = getWallet(currentWalletType);
1691
+ const chainId = (args == null ? void 0 : args.chainId) || recentChains;
1692
+ if (!chainId) {
1693
+ throw new Error("No last known connected chain, connect action requires chain id");
1694
+ }
1695
+ await ((_a = wallet.init) == null ? void 0 : _a.call(wallet));
1696
+ await wallet.enable(chainId);
1697
+ const { sessions: _sessions } = useGrazSessionStore.getState();
1698
+ const sessions = await Promise.all(
1699
+ chainId.map(async (i) => {
1700
+ const account = await wallet.getKey(i);
1701
+ return { account, chainId: i, status: "connected" };
1702
+ })
1703
+ );
1704
+ useGrazSessionStore.setState((prev) => ({ sessions: mergeSessions({ prev: prev.sessions, next: sessions }) }));
1705
+ useGrazInternalStore.setState({
1706
+ recentChains: (_b = useGrazSessionStore.getState().sessions) == null ? void 0 : _b.map((session) => session.chainId),
1707
+ walletType: currentWalletType,
1708
+ _reconnect: Boolean(args == null ? void 0 : args.autoReconnect),
1709
+ _reconnectConnector: currentWalletType
1710
+ });
1711
+ typeof window !== "undefined" && window.sessionStorage.setItem(RECONNECT_SESSION_KEY, "Active");
1712
+ return { walletType: currentWalletType, sessions };
1713
+ } catch (error) {
1714
+ console.error("connect ", error);
1715
+ useGrazSessionStore.setState((prev) => {
1716
+ var _a2;
1717
+ return {
1718
+ sessions: (_a2 = prev.sessions) == null ? void 0 : _a2.map(
1719
+ (item) => item.account ? { ...item, status: "connected" } : {
1720
+ ...item,
1721
+ status: "disconnected"
1722
+ }
1723
+ )
1724
+ };
1725
+ });
1726
+ throw error;
1727
+ }
1728
+ };
1729
+ var getOfflineSigners = async (args) => {
1730
+ if (!(args == null ? void 0 : args.chainId))
1731
+ throw new Error("chainId is required");
1732
+ const { walletType } = useGrazInternalStore.getState();
1733
+ const currentWalletType = args.walletType || walletType;
1734
+ const isWalletAvailable = checkWallet(currentWalletType);
1735
+ if (!isWalletAvailable) {
1736
+ throw new Error(`${currentWalletType} is not available`);
1737
+ }
1738
+ const wallet = getWallet(currentWalletType);
1739
+ const offlineSigner = wallet.getOfflineSigner(args.chainId);
1740
+ const offlineSignerAmino = wallet.getOfflineSignerOnlyAmino(args.chainId);
1741
+ const offlineSignerAuto = await wallet.getOfflineSignerAuto(args.chainId);
1742
+ return { offlineSigner, offlineSignerAmino, offlineSignerAuto };
1743
+ };
1744
+ var disconnect = async (args) => {
1745
+ typeof window !== "undefined" && window.sessionStorage.removeItem(RECONNECT_SESSION_KEY);
1746
+ if (args == null ? void 0 : args.chainId) {
1747
+ useGrazSessionStore.setState((x) => {
1748
+ var _a;
1749
+ return {
1750
+ sessions: (_a = x.sessions) == null ? void 0 : _a.filter((item) => {
1751
+ var _a2;
1752
+ return !((_a2 = args.chainId) == null ? void 0 : _a2.includes(item.chainId));
1753
+ })
1754
+ };
1755
+ });
1756
+ useGrazInternalStore.setState((x) => {
1757
+ var _a;
1758
+ return {
1759
+ _reconnect: false,
1760
+ _reconnectConnector: null,
1761
+ recentChains: (_a = x.recentChains) == null ? void 0 : _a.filter((item) => {
1762
+ var _a2;
1763
+ return !((_a2 = args.chainId) == null ? void 0 : _a2.includes(item));
1764
+ })
1765
+ };
1766
+ });
1767
+ } else {
1768
+ useGrazSessionStore.setState(grazSessionDefaultValues);
1769
+ useGrazInternalStore.setState({
1770
+ _reconnect: false,
1771
+ _reconnectConnector: null,
1772
+ recentChains: null
1773
+ });
1774
+ }
1775
+ return Promise.resolve();
1776
+ };
1777
+ var reconnect = async (args) => {
1778
+ var _a;
1779
+ const { recentChains, _reconnectConnector, _reconnect } = useGrazInternalStore.getState();
1780
+ try {
1781
+ const isWalletReady = checkWallet(_reconnectConnector || void 0);
1782
+ if (recentChains && isWalletReady && _reconnectConnector) {
1783
+ const key = await connect({
1784
+ chainId: recentChains,
1785
+ walletType: _reconnectConnector,
1786
+ autoReconnect: _reconnect
1787
+ });
1788
+ return key;
1789
+ }
1790
+ } catch (error) {
1791
+ (_a = args == null ? void 0 : args.onError) == null ? void 0 : _a.call(args, error);
1792
+ void disconnect();
1793
+ }
1794
+ };
1795
+
1796
+ // src/actions/chains.ts
1797
+ var clearRecentChain = () => {
1798
+ useGrazInternalStore.setState({ recentChains: null });
1799
+ };
1800
+ var getRecentChains = () => {
1801
+ return useGrazInternalStore.getState().recentChains;
1802
+ };
1803
+ var suggestChain = async (chainInfo) => {
1804
+ const wallet = getWallet();
1805
+ await wallet.experimentalSuggestChain(chainInfo);
1806
+ return chainInfo;
1807
+ };
1808
+ var suggestChainAndConnect = async (args) => {
1809
+ await suggestChain(args.chainInfo);
1810
+ const result = await connect({
1811
+ chainId: [args.chainInfo.chainId],
1812
+ autoReconnect: args.autoReconnect,
1813
+ walletType: args.walletType
1814
+ });
1815
+ return result;
1816
+ };
1817
+
1818
+ // src/actions/clients.ts
1819
+ import { CosmWasmClient, SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
1820
+ import { SigningStargateClient, StargateClient } from "@cosmjs/stargate";
1821
+ import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
1822
+ var connectClient = async ({ rpc, rpcHeaders, client }) => {
1823
+ const endpoint = { url: rpc, headers: { ...rpcHeaders || {} } };
1824
+ const result = await (async () => {
1825
+ switch (client) {
1826
+ case "cosmWasm":
1827
+ return CosmWasmClient.connect(endpoint);
1828
+ case "stargate":
1829
+ return StargateClient.connect(endpoint);
1830
+ case "tendermint":
1831
+ return Tendermint34Client.connect(rpc);
1832
+ default:
1833
+ throw new Error(`Unknown client: ${client}`);
1834
+ }
1835
+ })();
1836
+ return result;
1837
+ };
1838
+ var connectSigningClient = async (args) => {
1839
+ const { rpc, rpcHeaders, offlineSignerAuto, client, options = {} } = args;
1840
+ const endpoint = { url: rpc, headers: { ...rpcHeaders || {} } };
1841
+ const result = await (async () => {
1842
+ switch (client) {
1843
+ case "cosmWasm":
1844
+ return SigningCosmWasmClient.connectWithSigner(
1845
+ endpoint,
1846
+ offlineSignerAuto,
1847
+ options
1848
+ );
1849
+ case "stargate":
1850
+ return SigningStargateClient.connectWithSigner(endpoint, offlineSignerAuto, options);
1851
+ default:
1852
+ throw new Error(`Unknown client: ${client}`);
1853
+ }
1854
+ })();
1855
+ return result;
1856
+ };
1857
+
1858
+ // src/actions/configure.ts
1859
+ var configureGraz = (args) => {
1860
+ useGrazInternalStore.setState((prev) => ({
1861
+ chains: args.chains || prev.chains,
1862
+ defaultClient: args.defaultClient || prev.defaultClient,
1863
+ defaultSigningClient: args.defaultSigningClient || prev.defaultSigningClient,
1864
+ walletConnect: args.walletConnect || prev.walletConnect,
1865
+ walletType: args.defaultWallet || prev.walletType,
1866
+ _notFoundFn: args.onNotFound || prev._notFoundFn,
1867
+ _onReconnectFailed: args.onReconnectFailed || prev._onReconnectFailed,
1868
+ _reconnect: args.autoReconnect === void 0 ? true : args.autoReconnect || prev._reconnect
1869
+ }));
1870
+ return args;
1871
+ };
1872
+
1873
+ // src/actions/methods.ts
1874
+ var getBalances = async ({
1875
+ bech32Address,
1876
+ client,
1877
+ currencies: currencies9
1878
+ }) => {
1879
+ const balances = await Promise.all(
1880
+ currencies9.filter((i) => !i.coinMinimalDenom.startsWith("cw20:")).map(async (item) => {
1881
+ return client.getBalance(bech32Address, item.coinMinimalDenom);
1882
+ })
1883
+ );
1884
+ return balances;
1885
+ };
1886
+ var getBalanceStaked = async ({
1887
+ bech32Address,
1888
+ client
1889
+ }) => {
1890
+ return client.getBalanceStaked(bech32Address);
1891
+ };
1892
+ var sendTokens = async ({
1893
+ senderAddress,
1894
+ recipientAddress,
1895
+ amount,
1896
+ fee,
1897
+ memo,
1898
+ signingClient
1899
+ }) => {
1900
+ return signingClient.sendTokens(senderAddress, recipientAddress, amount, fee, memo);
1901
+ };
1902
+ var sendIbcTokens = async ({
1903
+ signingClient,
1904
+ senderAddress,
1905
+ recipientAddress,
1906
+ transferAmount,
1907
+ sourcePort,
1908
+ sourceChannel,
1909
+ timeoutHeight,
1910
+ timeoutTimestamp,
1911
+ fee,
1912
+ memo
1913
+ }) => {
1914
+ return signingClient.sendIbcTokens(
1915
+ senderAddress,
1916
+ recipientAddress,
1917
+ transferAmount,
1918
+ sourcePort,
1919
+ sourceChannel,
1920
+ timeoutHeight,
1921
+ timeoutTimestamp,
1922
+ fee,
1923
+ memo
1924
+ );
1925
+ };
1926
+ var instantiateContract = async ({
1927
+ signingClient,
1928
+ senderAddress,
1929
+ msg,
1930
+ fee,
1931
+ options,
1932
+ label,
1933
+ codeId
1934
+ }) => {
1935
+ return signingClient.instantiate(senderAddress, codeId, msg, label, fee, options);
1936
+ };
1937
+ var executeContract = async ({
1938
+ signingClient,
1939
+ senderAddress,
1940
+ msg,
1941
+ fee,
1942
+ contractAddress,
1943
+ funds,
1944
+ memo
1945
+ }) => {
1946
+ return signingClient.execute(senderAddress, contractAddress, msg, fee, memo, funds);
1947
+ };
1948
+ var getQuerySmart = async ({
1949
+ client,
1950
+ address,
1951
+ queryMsg
1952
+ }) => {
1953
+ const result = await client.queryContractSmart(address, queryMsg);
1954
+ return result;
1955
+ };
1956
+ var getQueryRaw = ({
1957
+ client,
1958
+ address,
1959
+ keyStr
1960
+ }) => {
1961
+ const key = new TextEncoder().encode(keyStr);
1962
+ return client.queryContractRaw(address, key);
1963
+ };
1964
+
1965
+ // src/chains/mainnet/axelar.ts
1966
+ import { Bech32Address } from "@keplr-wallet/cosmos";
1967
+ var AXL = {
1968
+ coinDenom: "axl",
1969
+ coinMinimalDenom: "uaxl",
1970
+ coinDecimals: 6,
1971
+ coinGeckoId: "axelar-network",
1972
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axl.png"
1973
+ };
1974
+ var USDC = {
1975
+ coinDenom: "usdc",
1976
+ coinMinimalDenom: "uusdc",
1977
+ coinDecimals: 6,
1978
+ coinGeckoId: "usd-coin",
1979
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/usdc.png"
1980
+ };
1981
+ var FRAX = {
1982
+ coinDenom: "dai",
1983
+ coinMinimalDenom: "dai-wei",
1984
+ coinDecimals: 18,
1985
+ coinGeckoId: "dai",
1986
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/dai.png"
1987
+ };
1988
+ var USDT = {
1989
+ coinDenom: "usdt",
1990
+ coinMinimalDenom: "uusdt",
1991
+ coinDecimals: 6,
1992
+ coinGeckoId: "tether",
1993
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/usdt.png"
1994
+ };
1995
+ var WETH = {
1996
+ coinDenom: "weth-wei",
1997
+ coinMinimalDenom: "weth",
1998
+ coinDecimals: 18,
1999
+ coinGeckoId: "weth",
2000
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/weth.png"
2001
+ };
2002
+ var WBTC = {
2003
+ coinDenom: "wbtc-satoshi",
2004
+ coinMinimalDenom: "wbtc",
2005
+ coinDecimals: 8,
2006
+ coinGeckoId: "wrapped-bitcoin",
2007
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/wbtc.png"
2008
+ };
2009
+ var currencies = [AXL, USDC, FRAX, USDT, WETH, WBTC];
2010
+ var axelar = {
2011
+ rpc: "https://rpc.axelar.strange.love",
2012
+ rest: "https://api.axelar.strange.love",
2013
+ chainId: "axelar-dojo-1",
2014
+ chainName: "Axelar",
2015
+ stakeCurrency: AXL,
2016
+ bip44: {
2017
+ coinType: 118
2018
+ },
2019
+ bech32Config: Bech32Address.defaultBech32Config("axelar"),
2020
+ currencies,
2021
+ feeCurrencies: currencies
2022
+ };
2023
+
2024
+ // src/chains/mainnet/cosmoshub.ts
2025
+ import { Bech32Address as Bech32Address2 } from "@keplr-wallet/cosmos";
2026
+ var ATOM = {
2027
+ coinDenom: "atom",
2028
+ coinMinimalDenom: "uatom",
2029
+ coinDecimals: 6,
2030
+ coinGeckoId: "cosmos",
2031
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"
2032
+ };
2033
+ var currencies2 = [ATOM];
2034
+ var cosmoshub = {
2035
+ rpc: "https://rpc.cosmoshub.strange.love",
2036
+ rest: "https://api.cosmoshub.strange.love",
2037
+ chainId: "cosmoshub-4",
2038
+ chainName: "Cosmos Hub",
2039
+ stakeCurrency: ATOM,
2040
+ bip44: {
2041
+ coinType: 118
2042
+ },
2043
+ bech32Config: Bech32Address2.defaultBech32Config("cosmos"),
2044
+ currencies: currencies2,
2045
+ feeCurrencies: currencies2
2046
+ };
2047
+
2048
+ // src/chains/mainnet/juno.ts
2049
+ import { Bech32Address as Bech32Address3 } from "@keplr-wallet/cosmos";
2050
+ var JUNO = {
2051
+ coinDenom: "juno",
2052
+ coinMinimalDenom: "ujuno",
2053
+ coinDecimals: 6,
2054
+ coinGeckoId: "juno-network",
2055
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"
2056
+ };
2057
+ var NETA = {
2058
+ coinDenom: "neta",
2059
+ coinMinimalDenom: "cw20:juno168ctmpyppk90d34p3jjy658zf5a5l3w8wk35wht6ccqj4mr0yv8s4j5awr",
2060
+ coinDecimals: 6,
2061
+ coinGeckoId: "neta",
2062
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/neta.png"
2063
+ };
2064
+ var MARBLE = {
2065
+ coinDenom: "marble",
2066
+ coinMinimalDenom: "cw20:juno1g2g7ucurum66d42g8k5twk34yegdq8c82858gz0tq2fc75zy7khssgnhjl",
2067
+ coinDecimals: 3,
2068
+ coinGeckoId: "marble",
2069
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/marble.png"
2070
+ };
2071
+ var HOPE = {
2072
+ coinDenom: "hope",
2073
+ coinMinimalDenom: "cw20:juno1re3x67ppxap48ygndmrc7har2cnc7tcxtm9nplcas4v0gc3wnmvs3s807z",
2074
+ coinDecimals: 6,
2075
+ coinGeckoId: "hope-galaxy",
2076
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hope.png"
2077
+ };
2078
+ var RAC = {
2079
+ coinDenom: "rac",
2080
+ coinMinimalDenom: "cw20:juno1r4pzw8f9z0sypct5l9j906d47z998ulwvhvqe5xdwgy8wf84583sxwh0pa",
2081
+ coinDecimals: 6,
2082
+ coinGeckoId: "racoon",
2083
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/rac.png"
2084
+ };
2085
+ var BLOCK = {
2086
+ coinDenom: "block",
2087
+ coinMinimalDenom: "cw20:juno1y9rf7ql6ffwkv02hsgd4yruz23pn4w97p75e2slsnkm0mnamhzysvqnxaq",
2088
+ coinDecimals: 6,
2089
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/block.png"
2090
+ };
2091
+ var DHK = {
2092
+ coinDenom: "dhk",
2093
+ coinMinimalDenom: "cw20:juno1tdjwrqmnztn2j3sj2ln9xnyps5hs48q3ddwjrz7jpv6mskappjys5czd49",
2094
+ coinDecimals: 0,
2095
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/dhk.png"
2096
+ };
2097
+ var RAW = {
2098
+ coinDenom: "raw",
2099
+ coinMinimalDenom: "cw20:juno15u3dt79t6sxxa3x3kpkhzsy56edaa5a66wvt3kxmukqjz2sx0hes5sn38g",
2100
+ coinDecimals: 6,
2101
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/raw.png",
2102
+ coinGeckoId: "junoswap-raw-dao"
2103
+ };
2104
+ var ASVT = {
2105
+ coinDenom: "asvt",
2106
+ coinMinimalDenom: "cw20:juno17wzaxtfdw5em7lc94yed4ylgjme63eh73lm3lutp2rhcxttyvpwsypjm4w",
2107
+ coinDecimals: 6,
2108
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/asvt.png"
2109
+ };
2110
+ var HNS = {
2111
+ coinDenom: "hns",
2112
+ coinMinimalDenom: "cw20:juno1ur4jx0sxchdevahep7fwq28yk4tqsrhshdtylz46yka3uf6kky5qllqp4k",
2113
+ coinDecimals: 6,
2114
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hns.svg"
2115
+ };
2116
+ var JOE = {
2117
+ coinDenom: "joe",
2118
+ coinMinimalDenom: "cw20:juno1n7n7d5088qlzlj37e9mgmkhx6dfgtvt02hqxq66lcap4dxnzdhwqfmgng3",
2119
+ coinDecimals: 6,
2120
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/joe.png"
2121
+ };
2122
+ var currencies3 = [JUNO, NETA, MARBLE, HOPE, RAC, BLOCK, DHK, RAW, ASVT, HNS, JOE];
2123
+ var juno = {
2124
+ rpc: "https://rpc.juno.strange.love",
2125
+ rest: "https://api.juno.strange.love",
2126
+ chainId: "juno-1",
2127
+ chainName: "Juno",
2128
+ stakeCurrency: JUNO,
2129
+ bip44: {
2130
+ coinType: 118
2131
+ },
2132
+ bech32Config: Bech32Address3.defaultBech32Config("juno"),
2133
+ currencies: currencies3,
2134
+ feeCurrencies: currencies3
2135
+ };
2136
+
2137
+ // src/chains/mainnet/osmosis.ts
2138
+ import { Bech32Address as Bech32Address4 } from "@keplr-wallet/cosmos";
2139
+ var OSMO = {
2140
+ coinDenom: "osmo",
2141
+ coinMinimalDenom: "uosmo",
2142
+ coinDecimals: 6,
2143
+ coinGeckoId: "osmosis",
2144
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"
2145
+ };
2146
+ var ION = {
2147
+ coinDenom: "ion",
2148
+ coinMinimalDenom: "uion",
2149
+ coinDecimals: 6,
2150
+ coinGeckoId: "ion",
2151
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/ion.png"
2152
+ };
2153
+ var currencies4 = [OSMO, ION];
2154
+ var osmosis = {
2155
+ rpc: "https://rpc.osmosis.strange.love",
2156
+ rest: "https://api.osmosis.strange.love",
2157
+ chainId: "osmosis-1",
2158
+ chainName: "Osmosis",
2159
+ stakeCurrency: OSMO,
2160
+ bip44: {
2161
+ coinType: 118
2162
+ },
2163
+ bech32Config: Bech32Address4.defaultBech32Config("osmo"),
2164
+ currencies: currencies4,
2165
+ feeCurrencies: currencies4
2166
+ };
2167
+
2168
+ // src/chains/mainnet/sommelier.ts
2169
+ import { Bech32Address as Bech32Address5 } from "@keplr-wallet/cosmos";
2170
+ var SOMM = {
2171
+ coinDenom: "somm",
2172
+ coinMinimalDenom: "usomm",
2173
+ coinDecimals: 6,
2174
+ coinGeckoId: "sommelier",
2175
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/sommelier/images/somm.png"
2176
+ };
2177
+ var currencies5 = [SOMM];
2178
+ var sommelier = {
2179
+ rpc: "https://rpc.sommelier.strange.love",
2180
+ rest: "https://api.sommelier.strange.love",
2181
+ chainId: "sommelier-3",
2182
+ chainName: "Sommelier",
2183
+ stakeCurrency: SOMM,
2184
+ bip44: {
2185
+ coinType: 118
2186
+ },
2187
+ bech32Config: Bech32Address5.defaultBech32Config("somm"),
2188
+ currencies: currencies5,
2189
+ feeCurrencies: currencies5
2190
+ };
2191
+
2192
+ // src/chains/testnet/crescent.ts
2193
+ import { Bech32Address as Bech32Address6 } from "@keplr-wallet/cosmos";
2194
+ var CRE = {
2195
+ coinDenom: "CRE",
2196
+ coinMinimalDenom: "ucre",
2197
+ coinDecimals: 6,
2198
+ coinGeckoId: "crescent",
2199
+ coinImageUrl: "https://raw.githubusercontent.com/crescent-network/asset/main/images/coin/CRE.png"
2200
+ };
2201
+ var currencies6 = [CRE];
2202
+ var crescentTestnet = {
2203
+ rpc: "https://testnet-endpoint.crescent.network/rpc/crescent",
2204
+ rest: "https://testnet-endpoint.crescent.network/api/crescent",
2205
+ chainId: "mooncat-1-1",
2206
+ chainName: "Crescent Testnet",
2207
+ bip44: {
2208
+ coinType: 118
2209
+ },
2210
+ bech32Config: Bech32Address6.defaultBech32Config("CRE"),
2211
+ currencies: currencies6,
2212
+ feeCurrencies: currencies6,
2213
+ stakeCurrency: CRE,
2214
+ coinType: 118
2215
+ };
2216
+
2217
+ // src/chains/testnet/juno.ts
2218
+ import { Bech32Address as Bech32Address7 } from "@keplr-wallet/cosmos";
2219
+ var JUNO2 = {
2220
+ coinDenom: "junox",
2221
+ coinMinimalDenom: "ujunox",
2222
+ coinDecimals: 6,
2223
+ coinGeckoId: "juno-network",
2224
+ coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"
2225
+ };
2226
+ var currencies7 = [JUNO2];
2227
+ var junoTestnet = {
2228
+ rpc: "https://rpc.uni.junonetwork.io",
2229
+ rest: "https://api.uni.junonetwork.io",
2230
+ chainId: "uni-5",
2231
+ chainName: "Juno Testnet",
2232
+ stakeCurrency: JUNO2,
2233
+ bip44: {
2234
+ coinType: 118
2235
+ },
2236
+ bech32Config: Bech32Address7.defaultBech32Config("juno"),
2237
+ currencies: currencies7,
2238
+ feeCurrencies: [JUNO2],
2239
+ coinType: 118
2240
+ };
2241
+
2242
+ // src/chains/testnet/osmosis.ts
2243
+ import { Bech32Address as Bech32Address8 } from "@keplr-wallet/cosmos";
2244
+ var OSMO2 = {
2245
+ coinDenom: "osmo",
2246
+ coinMinimalDenom: "uosmo",
2247
+ coinDecimals: 6,
2248
+ coinGeckoId: "osmosis",
2249
+ coinImageUrl: "https://dhj8dql1kzq2v.cloudfront.net/white/osmo.png"
2250
+ };
2251
+ var currencies8 = [OSMO2];
2252
+ var osmosisTestnet = {
2253
+ rpc: "https://testnet-rpc.osmosis.zone",
2254
+ rest: "https://testnet-rest.osmosis.zone",
2255
+ chainId: "osmo-test-4",
2256
+ chainName: "Osmosis Testnet",
2257
+ stakeCurrency: OSMO2,
2258
+ bip44: {
2259
+ coinType: 118
2260
+ },
2261
+ bech32Config: Bech32Address8.defaultBech32Config("osmo"),
2262
+ currencies: currencies8,
2263
+ feeCurrencies: [OSMO2],
2264
+ coinType: 118
2265
+ };
2266
+
2267
+ // src/chains/index.ts
2268
+ var defineChains = (chains) => {
2269
+ return chains;
2270
+ };
2271
+ var defineChain = (chain) => {
2272
+ return chain;
2273
+ };
2274
+ var defineChainInfo = (chain) => {
2275
+ return chain;
2276
+ };
2277
+ var mainnetChains = defineChains({
2278
+ axelar,
2279
+ cosmoshub,
2280
+ juno,
2281
+ osmosis,
2282
+ sommelier
2283
+ });
2284
+ var mainnetChainsArray = [axelar, cosmoshub, juno, osmosis, sommelier];
2285
+ var testnetChains = defineChains({
2286
+ crescent: crescentTestnet,
2287
+ juno: junoTestnet,
2288
+ osmosis: osmosisTestnet
2289
+ });
2290
+ var testnetChainsArray = [crescentTestnet, junoTestnet, osmosisTestnet];
2291
+
2292
+ // src/hooks/account.ts
2293
+ import { useMutation, useQuery as useQuery2 } from "@tanstack/react-query";
2294
+ import { useEffect, useMemo } from "react";
2295
+
2296
+ // src/hooks/wallet.ts
2297
+ import { useQuery } from "@tanstack/react-query";
2298
+ import { shallow } from "zustand/shallow";
2299
+ var useActiveWalletType = () => {
2300
+ return useGrazInternalStore(
2301
+ (x) => ({
2302
+ walletType: x.walletType,
2303
+ isCosmostation: x.walletType === "cosmostation" /* COSMOSTATION */,
2304
+ isCosmostationMobile: x.walletType === "wc_cosmostation_mobile" /* WC_COSMOSTATION_MOBILE */,
2305
+ isKeplr: x.walletType === "keplr" /* KEPLR */,
2306
+ isKeplrMobile: x.walletType === "wc_keplr_mobile" /* WC_KEPLR_MOBILE */,
2307
+ isLeap: x.walletType === "leap" /* LEAP */,
2308
+ isLeapMobile: x.walletType === "wc_leap_mobile" /* WC_LEAP_MOBILE */,
2309
+ isVectis: x.walletType === "vectis" /* VECTIS */,
2310
+ isWalletConnect: x.walletType === "walletconnect" /* WALLETCONNECT */
2311
+ }),
2312
+ shallow
2313
+ );
2314
+ };
2315
+ var useCheckWallet = (type) => {
2316
+ const walletType = useGrazInternalStore((x) => type || x.walletType);
2317
+ const queryKey = ["USE_CHECK_WALLET", walletType];
2318
+ const query = useQuery(queryKey, ({ queryKey: [, _type] }) => checkWallet(_type));
2319
+ return query;
2320
+ };
2321
+
2322
+ // src/hooks/account.ts
2323
+ var useAccount = (args) => {
2324
+ const sessions = useGrazSessionStore((x) => x.sessions);
2325
+ useEffect(() => {
2326
+ return useGrazSessionStore.subscribe(
2327
+ (x) => x.sessions,
2328
+ (stat, prevStat) => {
2329
+ stat == null ? void 0 : stat.forEach((i) => {
2330
+ var _a, _b, _c, _d;
2331
+ if (((_a = prevStat == null ? void 0 : prevStat.find((y) => y.chainId === i.chainId)) == null ? void 0 : _a.status) !== "connected" && i.status === "connected") {
2332
+ (_c = args == null ? void 0 : args.onConnect) == null ? void 0 : _c.call(args, {
2333
+ account: i.account,
2334
+ chainId: i.chainId,
2335
+ status: i.status,
2336
+ isReconnect: ((_b = prevStat == null ? void 0 : prevStat.find((j) => j.chainId === i.chainId)) == null ? void 0 : _b.status) === "reconnecting"
2337
+ });
2338
+ }
2339
+ if (i.status === "disconnected") {
2340
+ (_d = args == null ? void 0 : args.onDisconnect) == null ? void 0 : _d.call(args);
2341
+ }
2342
+ });
2343
+ }
2344
+ );
2345
+ }, [args, args == null ? void 0 : args.onConnect, args == null ? void 0 : args.onDisconnect]);
2346
+ const res = useMemo(() => {
2347
+ if (args == null ? void 0 : args.chainId) {
2348
+ const singleChainRes = sessions == null ? void 0 : sessions.find((i) => i.chainId === args.chainId);
2349
+ return {
2350
+ data: singleChainRes,
2351
+ isConnected: Boolean(singleChainRes == null ? void 0 : singleChainRes.account),
2352
+ isConnecting: (singleChainRes == null ? void 0 : singleChainRes.status) === "connecting",
2353
+ isDisconnected: (singleChainRes == null ? void 0 : singleChainRes.status) === "disconnected",
2354
+ isReconnecting: (singleChainRes == null ? void 0 : singleChainRes.status) === "reconnecting",
2355
+ isLoading: (singleChainRes == null ? void 0 : singleChainRes.status) === "connecting" || status === "reconnecting",
2356
+ status: singleChainRes == null ? void 0 : singleChainRes.status
2357
+ };
2358
+ }
2359
+ if (!sessions)
2360
+ return void 0;
2361
+ const multiChainRes = {};
2362
+ sessions.forEach((i) => {
2363
+ multiChainRes[i.chainId] = {
2364
+ data: i,
2365
+ isConnected: Boolean(i.account),
2366
+ isConnecting: i.status === "connecting",
2367
+ isDisconnected: i.status === "disconnected",
2368
+ isReconnecting: i.status === "reconnecting",
2369
+ isLoading: i.status === "connecting" || status === "reconnecting",
2370
+ status: i.status
2371
+ };
2372
+ });
2373
+ return multiChainRes;
2374
+ }, [args == null ? void 0 : args.chainId, sessions]);
2375
+ return res;
2376
+ };
2377
+ var useConnect = ({ onError, onLoading, onSuccess } = {}) => {
2378
+ const queryKey = ["USE_CONNECT", onError, onLoading, onSuccess];
2379
+ const mutation = useMutation(queryKey, connect, {
2380
+ onError: (err, args) => Promise.resolve(onError == null ? void 0 : onError(err, args)),
2381
+ onMutate: onLoading,
2382
+ onSuccess: (connectResult) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(connectResult))
2383
+ });
2384
+ const { data: isSupported } = useCheckWallet();
2385
+ return {
2386
+ connect: (args) => mutation.mutate(args),
2387
+ connectAsync: (args) => mutation.mutateAsync(args),
2388
+ error: mutation.error,
2389
+ isLoading: mutation.isLoading,
2390
+ isSuccess: mutation.isSuccess,
2391
+ isSupported: Boolean(isSupported),
2392
+ status: mutation.status
2393
+ };
2394
+ };
2395
+ var useDisconnect = ({ onError, onLoading, onSuccess } = {}) => {
2396
+ const queryKey = ["USE_DISCONNECT", onError, onLoading, onSuccess];
2397
+ const mutation = useMutation(queryKey, disconnect, {
2398
+ onError: (err) => Promise.resolve(onError == null ? void 0 : onError(err, void 0)),
2399
+ onMutate: onLoading,
2400
+ onSuccess: () => Promise.resolve(onSuccess == null ? void 0 : onSuccess(void 0))
2401
+ });
2402
+ return {
2403
+ disconnect: (args) => mutation.mutate({
2404
+ chainId: args == null ? void 0 : args.chainid
2405
+ }),
2406
+ disconnectAsync: (args) => mutation.mutateAsync({ chainId: args == null ? void 0 : args.chainid }),
2407
+ error: mutation.error,
2408
+ isLoading: mutation.isLoading,
2409
+ isSuccess: mutation.isSuccess,
2410
+ status: mutation.status
2411
+ };
2412
+ };
2413
+ var useOfflineSigners = (args) => {
2414
+ const accounts = useAccount();
2415
+ const { data } = useQuery2(
2416
+ ["OFFLINE_SIGNERS", { accounts }],
2417
+ async () => {
2418
+ if (!accounts)
2419
+ return void 0;
2420
+ const connectedChainIds = Object.values(accounts).map((i) => {
2421
+ var _a;
2422
+ return (_a = i.data) == null ? void 0 : _a.chainId;
2423
+ }).filter((i) => i);
2424
+ const res = {};
2425
+ await Promise.all(
2426
+ connectedChainIds.map(async (_chainId) => {
2427
+ const signers = await getOfflineSigners({
2428
+ chainId: _chainId
2429
+ });
2430
+ res[_chainId] = signers;
2431
+ })
2432
+ );
2433
+ return res;
2434
+ },
2435
+ {
2436
+ enabled: Boolean(accounts)
2437
+ }
2438
+ );
2439
+ const query = useQuery2(
2440
+ [
2441
+ "USE_OFFLINE_SIGNERS",
2442
+ {
2443
+ args,
2444
+ offlineSigners: data
2445
+ }
2446
+ ],
2447
+ async () => {
2448
+ if (!data)
2449
+ return void 0;
2450
+ const connectedChainIds = Object.keys(data).map(([chainId]) => chainId).filter((i) => i);
2451
+ if (args == null ? void 0 : args.chainId) {
2452
+ const offlineSigners = await getOfflineSigners({
2453
+ chainId: args.chainId
2454
+ });
2455
+ return offlineSigners;
2456
+ }
2457
+ const res = {};
2458
+ await Promise.all(
2459
+ connectedChainIds.map(async (_chainId) => {
2460
+ const signers = await getOfflineSigners({
2461
+ chainId: _chainId
2462
+ });
2463
+ res[_chainId] = signers;
2464
+ })
2465
+ );
2466
+ return res;
2467
+ },
2468
+ { enabled: Boolean(data), refetchOnMount: false, refetchOnWindowFocus: false }
2469
+ );
2470
+ return query;
2471
+ };
2472
+
2473
+ // src/hooks/chains.ts
2474
+ import { useMutation as useMutation2, useQuery as useQuery3 } from "@tanstack/react-query";
2475
+ var useActiveChainValidators = (queryClient2, status2 = "BOND_STATUS_BONDED") => {
2476
+ const queryKey = ["USE_ACTIVE_CHAIN_VALIDATORS", queryClient2, status2];
2477
+ const query = useQuery3(
2478
+ queryKey,
2479
+ ({ queryKey: [, _queryClient, _status] }) => {
2480
+ return _queryClient.staking.validators(_status);
2481
+ },
2482
+ {
2483
+ enabled: typeof queryClient2 !== "undefined"
2484
+ }
2485
+ );
2486
+ return query;
2487
+ };
2488
+ var useRecentChain = () => {
2489
+ const recentChains = useGrazInternalStore((x) => x.recentChains);
2490
+ return { data: recentChains, clear: clearRecentChain };
2491
+ };
2492
+ var useSuggestChain = ({ onError, onLoading, onSuccess } = {}) => {
2493
+ const queryKey = ["USE_SUGGEST_CHAIN", onError, onLoading, onSuccess];
2494
+ const mutation = useMutation2(queryKey, suggestChain, {
2495
+ onError: (err, chainInfo) => Promise.resolve(onError == null ? void 0 : onError(err, chainInfo)),
2496
+ onMutate: onLoading,
2497
+ onSuccess: (chainInfo) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(chainInfo))
2498
+ });
2499
+ return {
2500
+ error: mutation.error,
2501
+ isLoading: mutation.isLoading,
2502
+ isSuccess: mutation.isSuccess,
2503
+ suggest: mutation.mutate,
2504
+ suggestAsync: mutation.mutateAsync,
2505
+ status: mutation.status
2506
+ };
2507
+ };
2508
+ var useSuggestChainAndConnect = ({ onError, onLoading, onSuccess } = {}) => {
2509
+ const queryKey = ["USE_SUGGEST_CHAIN_AND_CONNECT", onError, onLoading, onSuccess];
2510
+ const mutation = useMutation2(queryKey, suggestChainAndConnect, {
2511
+ onError: (err, args) => Promise.resolve(onError == null ? void 0 : onError(err, args)),
2512
+ onMutate: (args) => onLoading == null ? void 0 : onLoading(args),
2513
+ onSuccess: (res) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(res))
2514
+ });
2515
+ const { data: isSupported } = useCheckWallet();
2516
+ return {
2517
+ error: mutation.error,
2518
+ isLoading: mutation.isLoading,
2519
+ isSuccess: mutation.isSuccess,
2520
+ isSupported: Boolean(isSupported),
2521
+ status: mutation.status,
2522
+ suggestAndConnect: mutation.mutate,
2523
+ suggestAndConnectAsync: mutation.mutateAsync
2524
+ };
2525
+ };
2526
+
2527
+ // src/hooks/clients.ts
2528
+ import { GasPrice } from "@cosmjs/stargate";
2529
+ import { useQuery as useQuery4 } from "@tanstack/react-query";
2530
+ var useConnectClient = (args) => {
2531
+ var _a;
2532
+ const _client = (args == null ? void 0 : args.client) ?? useGrazInternalStore.getState().defaultClient;
2533
+ const _chains = useGrazInternalStore.getState().chains;
2534
+ const sessionChainIds = (_a = useGrazSessionStore.getState().sessions) == null ? void 0 : _a.map((i) => i.chainId);
2535
+ const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === (args == null ? void 0 : args.chainId));
2536
+ const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
2537
+ const chains = (args == null ? void 0 : args.onlyConnectedChains) ? sessionChains : _chains;
2538
+ const query = useQuery4(
2539
+ [
2540
+ "USE_CLIENTS",
2541
+ {
2542
+ client: _client,
2543
+ chainId: args == null ? void 0 : args.chainId,
2544
+ onlyConnectedChains: args == null ? void 0 : args.onlyConnectedChains
2545
+ }
2546
+ ],
2547
+ async () => {
2548
+ if (singleChain) {
2549
+ const client = await connectClient({
2550
+ client: _client,
2551
+ rpc: singleChain.rpc,
2552
+ rpcHeaders: singleChain.rpcHeaders
2553
+ });
2554
+ return client;
2555
+ }
2556
+ const res = {};
2557
+ if (!chains)
2558
+ return void 0;
2559
+ await Promise.all(
2560
+ chains.map(async (chain) => {
2561
+ const client = await connectClient({
2562
+ client: _client,
2563
+ rpc: chain.rpc,
2564
+ rpcHeaders: chain.rpcHeaders
2565
+ });
2566
+ res[chain.chainId] = client;
2567
+ })
2568
+ );
2569
+ return res;
2570
+ },
2571
+ {
2572
+ enabled: (args == null ? void 0 : args.enabled) !== void 0 ? args.enabled && Boolean(_chains) : Boolean(_chains),
2573
+ refetchOnMount: false,
2574
+ refetchOnWindowFocus: false
2575
+ }
2576
+ );
2577
+ return query;
2578
+ };
2579
+ var useConnectSigningClient = (args) => {
2580
+ var _a;
2581
+ const _client = (args == null ? void 0 : args.client) ?? useGrazInternalStore.getState().defaultClient;
2582
+ const _chains = useGrazInternalStore.getState().chains;
2583
+ const sessionChainIds = (_a = useGrazSessionStore.getState().sessions) == null ? void 0 : _a.map((i) => i.chainId);
2584
+ const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === (args == null ? void 0 : args.chainId));
2585
+ const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
2586
+ const queryKey = [
2587
+ "USE_SIGNING_CLIENTS",
2588
+ { client: _client, chainId: args == null ? void 0 : args.chainId, options: args == null ? void 0 : args.options }
2589
+ ];
2590
+ const query = useQuery4(
2591
+ queryKey,
2592
+ async () => {
2593
+ if (singleChain) {
2594
+ const { offlineSignerAuto } = await getOfflineSigners({
2595
+ chainId: singleChain.chainId
2596
+ });
2597
+ const gasPrice = singleChain.gas ? GasPrice.fromString(`${singleChain.gas.price}${singleChain.gas.denom}`) : void 0;
2598
+ const options = _client === "cosmWasm" ? { gasPrice, ...(args == null ? void 0 : args.options) || {} } : args == null ? void 0 : args.options;
2599
+ const client = await connectSigningClient({
2600
+ client: _client,
2601
+ rpc: singleChain.rpc,
2602
+ rpcHeaders: singleChain.rpcHeaders,
2603
+ offlineSignerAuto,
2604
+ options
2605
+ });
2606
+ return client;
2607
+ }
2608
+ const res = {};
2609
+ if (!sessionChains)
2610
+ return void 0;
2611
+ await Promise.all(
2612
+ sessionChains.map(async (chain) => {
2613
+ var _a2, _b;
2614
+ const { offlineSignerAuto } = await getOfflineSigners({ chainId: chain.chainId });
2615
+ const gasPrice = chain.gas ? GasPrice.fromString(`${chain.gas.price}${chain.gas.denom}`) : void 0;
2616
+ const options = _client === "cosmWasm" ? (
2617
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2618
+ // @ts-expect-error
2619
+ { gasPrice, ...((_a2 = args == null ? void 0 : args.options) == null ? void 0 : _a2[chain.chainId]) || {} }
2620
+ ) : (
2621
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2622
+ // @ts-expect-error
2623
+ (_b = args == null ? void 0 : args.options) == null ? void 0 : _b[chain.chainId]
2624
+ );
2625
+ const client = await connectSigningClient({
2626
+ client: _client,
2627
+ rpc: chain.rpc,
2628
+ rpcHeaders: chain.rpcHeaders,
2629
+ offlineSignerAuto,
2630
+ options
2631
+ });
2632
+ res[chain.chainId] = client;
2633
+ })
2634
+ );
2635
+ return res;
2636
+ },
2637
+ {
2638
+ enabled: Boolean(_chains),
2639
+ refetchOnMount: false,
2640
+ refetchOnWindowFocus: false
2641
+ }
2642
+ );
2643
+ return query;
2644
+ };
2645
+
2646
+ // src/hooks/methods.ts
2647
+ import { fromBech32 as fromBech322, toBech32 } from "@cosmjs/encoding";
2648
+ import { useMutation as useMutation3, useQuery as useQuery5 } from "@tanstack/react-query";
2649
+ var useBalances = (args) => {
2650
+ const _client = args.client ?? useGrazInternalStore.getState().defaultClient;
2651
+ const _chains = useGrazInternalStore.getState().chains;
2652
+ const { data: singleClient } = useConnectClient({
2653
+ client: _client,
2654
+ chainId: args.chainId,
2655
+ enabled: Boolean(args.chainId)
2656
+ });
2657
+ const { data: multiClient } = useConnectClient({
2658
+ client: _client,
2659
+ enabled: !args.chainId
2660
+ });
2661
+ const query = useQuery5(
2662
+ [
2663
+ "USE_BALANCES",
2664
+ {
2665
+ singleClient,
2666
+ multiClient,
2667
+ ...args,
2668
+ _chains
2669
+ }
2670
+ ],
2671
+ async () => {
2672
+ if (args.chainId && singleClient) {
2673
+ const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
2674
+ const res = await getBalances({
2675
+ client: singleClient,
2676
+ bech32Address: toBech32(singleChain.bech32Config.bech32PrefixAccAddr, fromBech322(args.bech32Address).data),
2677
+ currencies: singleChain.currencies
2678
+ });
2679
+ return res;
2680
+ }
2681
+ if (!args.chainId && multiClient) {
2682
+ const multiChain = Object.entries(multiClient);
2683
+ const res = {};
2684
+ await Promise.all(
2685
+ multiChain.map(async ([chainId, client]) => {
2686
+ const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
2687
+ if (!chain)
2688
+ return;
2689
+ const _res = await getBalances({
2690
+ client,
2691
+ bech32Address: toBech32(chain.bech32Config.bech32PrefixAccAddr, fromBech322(args.bech32Address).data),
2692
+ currencies: chain.currencies
2693
+ });
2694
+ res[chainId] = _res;
2695
+ })
2696
+ );
2697
+ return res;
2698
+ }
2699
+ return void 0;
2700
+ },
2701
+ {
2702
+ enabled: Boolean(args.bech32Address) && Boolean(_chains) && (Boolean(singleClient) || Boolean(multiClient)),
2703
+ refetchOnMount: false,
2704
+ refetchOnReconnect: true,
2705
+ refetchOnWindowFocus: false
2706
+ }
2707
+ );
2708
+ return query;
2709
+ };
2710
+ var useBalanceStaked = (args) => {
2711
+ const _chains = useGrazInternalStore.getState().chains;
2712
+ const { data: singleClient } = useConnectClient({
2713
+ client: "stargate",
2714
+ chainId: args.chainId,
2715
+ enabled: Boolean(args.chainId)
2716
+ });
2717
+ const { data: multiClient } = useConnectClient({
2718
+ client: "stargate",
2719
+ enabled: !args.chainId
2720
+ });
2721
+ const query = useQuery5(
2722
+ [
2723
+ "USE_BALANCE_STAKED",
2724
+ {
2725
+ singleClient,
2726
+ multiClient,
2727
+ ...args,
2728
+ _chains
2729
+ }
2730
+ ],
2731
+ async () => {
2732
+ if (args.chainId && singleClient) {
2733
+ const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
2734
+ if (!singleChain)
2735
+ throw new Error(`${args.chainId} Chain not found`);
2736
+ const res = await getBalanceStaked({
2737
+ client: singleClient,
2738
+ bech32Address: toBech32(singleChain.bech32Config.bech32PrefixAccAddr, fromBech322(args.bech32Address).data)
2739
+ });
2740
+ return res;
2741
+ }
2742
+ if (!args.chainId && multiClient) {
2743
+ const multiChain = Object.entries(multiClient);
2744
+ const res = {};
2745
+ await Promise.all(
2746
+ multiChain.map(async ([chainId, client]) => {
2747
+ const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
2748
+ if (!chain)
2749
+ return;
2750
+ const _res = await getBalanceStaked({
2751
+ client,
2752
+ bech32Address: toBech32(chain.bech32Config.bech32PrefixAccAddr, fromBech322(args.bech32Address).data)
2753
+ });
2754
+ res[chainId] = _res;
2755
+ })
2756
+ );
2757
+ return res;
2758
+ }
2759
+ return void 0;
2760
+ },
2761
+ {
2762
+ enabled: Boolean(args.bech32Address) && Boolean(_chains) && (Boolean(singleClient) || Boolean(multiClient)),
2763
+ refetchOnMount: false,
2764
+ refetchOnReconnect: true,
2765
+ refetchOnWindowFocus: false
2766
+ }
2767
+ );
2768
+ return query;
2769
+ };
2770
+ var useSendTokens = ({
2771
+ signingClient,
2772
+ signingClientOptions,
2773
+ chainId,
2774
+ onError,
2775
+ onLoading,
2776
+ onSuccess
2777
+ }) => {
2778
+ const _client = signingClient ?? useGrazInternalStore.getState().defaultSigningClient;
2779
+ const { data: _signingClient } = useConnectSigningClient({
2780
+ chainId,
2781
+ client: _client,
2782
+ options: signingClientOptions
2783
+ });
2784
+ const queryKey = ["USE_SEND_TOKENS", { onError, onLoading, onSuccess, chainId }];
2785
+ const mutation = useMutation3(
2786
+ queryKey,
2787
+ async (args) => {
2788
+ if (!_signingClient)
2789
+ throw new Error("Signing client is not available");
2790
+ const res = await sendTokens({ signingClient: _signingClient, ...args });
2791
+ return res;
2792
+ },
2793
+ {
2794
+ onError: (err, data) => Promise.resolve(onError == null ? void 0 : onError(err, data)),
2795
+ onMutate: onLoading,
2796
+ onSuccess: (txResponse) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(txResponse))
2797
+ }
2798
+ );
2799
+ return {
2800
+ error: mutation.error,
2801
+ isLoading: mutation.isLoading,
2802
+ isSuccess: mutation.isSuccess,
2803
+ sendTokens: mutation.mutate,
2804
+ sendTokensAsync: mutation.mutateAsync,
2805
+ status: mutation.status
2806
+ };
2807
+ };
2808
+
2809
+ // src/provider/events.tsx
2810
+ import { useEffect as useEffect2 } from "react";
2811
+ var useGrazEvents = () => {
2812
+ const isSessionActive = typeof window !== "undefined" && window.sessionStorage.getItem(RECONNECT_SESSION_KEY) === "Active";
2813
+ const { _reconnect, _onReconnectFailed, _reconnectConnector } = useGrazInternalStore();
2814
+ const { sessions, wcSignClient } = useGrazSessionStore();
2815
+ useEffect2(() => {
2816
+ if (_reconnectConnector) {
2817
+ if (isSessionActive && Boolean(sessions)) {
2818
+ void reconnect({
2819
+ onError: _onReconnectFailed
2820
+ });
2821
+ } else if (!isSessionActive && _reconnect) {
2822
+ void reconnect({
2823
+ onError: _onReconnectFailed
2824
+ });
2825
+ }
2826
+ }
2827
+ }, []);
2828
+ useEffect2(() => {
2829
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2830
+ if (_reconnectConnector) {
2831
+ if (_reconnectConnector === "keplr" /* KEPLR */) {
2832
+ (_b = (_a = getKeplr()).subscription) == null ? void 0 : _b.call(_a, () => {
2833
+ void reconnect({ onError: _onReconnectFailed });
2834
+ });
2835
+ }
2836
+ if (_reconnectConnector === "cosmostation" /* COSMOSTATION */) {
2837
+ (_d = (_c = getCosmostation()).subscription) == null ? void 0 : _d.call(_c, () => {
2838
+ void reconnect({
2839
+ onError: _onReconnectFailed
2840
+ });
2841
+ });
2842
+ }
2843
+ if (_reconnectConnector === "leap" /* LEAP */) {
2844
+ (_f = (_e = getLeap()).subscription) == null ? void 0 : _f.call(_e, () => {
2845
+ void reconnect({ onError: _onReconnectFailed });
2846
+ });
2847
+ }
2848
+ if (_reconnectConnector === "vectis" /* VECTIS */) {
2849
+ (_h = (_g = getVectis()).subscription) == null ? void 0 : _h.call(_g, () => {
2850
+ void reconnect({ onError: _onReconnectFailed });
2851
+ });
2852
+ }
2853
+ if (_reconnectConnector === "walletconnect" /* WALLETCONNECT */) {
2854
+ if (wcSignClient) {
2855
+ (_j = (_i = getWalletConnect()).subscription) == null ? void 0 : _j.call(_i, () => {
2856
+ void reconnect({ onError: _onReconnectFailed });
2857
+ });
2858
+ }
2859
+ }
2860
+ }
2861
+ }, [_reconnectConnector, wcSignClient]);
2862
+ return null;
2863
+ };
2864
+ var GrazEvents = () => {
2865
+ useGrazEvents();
2866
+ return null;
2867
+ };
2868
+
2869
+ // src/provider/index.tsx
2870
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2871
+
2872
+ // src/provider/client-only.tsx
2873
+ import { useEffect as useEffect3, useState } from "react";
2874
+ import { Fragment, jsx } from "react/jsx-runtime";
2875
+ var ClientOnly = ({ children }) => {
2876
+ const [isHydrated, setIsHydrated] = useState(false);
2877
+ useEffect3(() => {
2878
+ setIsHydrated(true);
2879
+ }, []);
2880
+ return /* @__PURE__ */ jsx(Fragment, { children: isHydrated ? children : null });
2881
+ };
2882
+
2883
+ // src/provider/index.tsx
2884
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
2885
+ var queryClient = new QueryClient({
2886
+ //
2887
+ });
2888
+ var GrazProvider = ({ children, grazConfig, ...props }) => {
2889
+ configureGraz(grazConfig);
2890
+ return /* @__PURE__ */ jsx2(QueryClientProvider, { client: queryClient, ...props, children: /* @__PURE__ */ jsxs(ClientOnly, { children: [
2891
+ /* @__PURE__ */ jsx2(GrazEvents, {}),
2892
+ children
2893
+ ] }) }, "graz-provider");
2894
+ };
2895
+ export {
2896
+ GrazEvents,
2897
+ GrazProvider,
2898
+ WALLET_TYPES,
2899
+ WalletType,
2900
+ checkWallet,
2901
+ clearRecentChain,
2902
+ configureGraz,
2903
+ connect,
2904
+ connectClient,
2905
+ connectSigningClient,
2906
+ defineChain,
2907
+ defineChainInfo,
2908
+ defineChains,
2909
+ disconnect,
2910
+ executeContract,
2911
+ getAvailableWallets,
2912
+ getBalanceStaked,
2913
+ getBalances,
2914
+ getCosmostation,
2915
+ getKeplr,
2916
+ getLeap,
2917
+ getOfflineSigners,
2918
+ getQueryRaw,
2919
+ getQuerySmart,
2920
+ getRecentChains,
2921
+ getVectis,
2922
+ getWCCosmostation,
2923
+ getWCKeplr,
2924
+ getWCLeap,
2925
+ getWallet,
2926
+ getWalletConnect,
2927
+ instantiateContract,
2928
+ mainnetChains,
2929
+ mainnetChainsArray,
2930
+ reconnect,
2931
+ sendIbcTokens,
2932
+ sendTokens,
2933
+ suggestChain,
2934
+ suggestChainAndConnect,
2935
+ testnetChains,
2936
+ testnetChainsArray,
2937
+ useAccount,
2938
+ useActiveChainValidators,
2939
+ useActiveWalletType,
2940
+ useBalanceStaked,
2941
+ useBalances,
2942
+ useCheckWallet,
2943
+ useConnect,
2944
+ useConnectClient,
2945
+ useConnectSigningClient,
2946
+ useDisconnect,
2947
+ useGrazEvents,
2948
+ useOfflineSigners,
2949
+ useRecentChain,
2950
+ useSendTokens,
2951
+ useSuggestChain,
2952
+ useSuggestChainAndConnect
2953
+ };