graz 0.0.4 → 0.0.5
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.d.ts +48 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
|
+
import * as _cosmjs_stargate from '@cosmjs/stargate';
|
|
1
2
|
import * as _keplr_wallet_types from '@keplr-wallet/types';
|
|
2
|
-
import { AppCurrency,
|
|
3
|
-
import * as _cosmjs_proto_signing from '@cosmjs/proto-signing';
|
|
3
|
+
import { AppCurrency, ChainInfo, Key } from '@keplr-wallet/types';
|
|
4
4
|
import * as _cosmjs_cosmwasm_stargate from '@cosmjs/cosmwasm-stargate';
|
|
5
|
+
import { SigningCosmWasmClientOptions } from '@cosmjs/cosmwasm-stargate';
|
|
6
|
+
import * as _cosmjs_proto_signing from '@cosmjs/proto-signing';
|
|
7
|
+
import { OfflineSigner } from '@cosmjs/proto-signing';
|
|
5
8
|
import * as react_query from 'react-query';
|
|
6
9
|
import * as _cosmjs_amino from '@cosmjs/amino';
|
|
7
10
|
import { ReactNode } from 'react';
|
|
8
11
|
|
|
12
|
+
declare type Dictionary<T = string> = Record<string, T>;
|
|
13
|
+
|
|
9
14
|
interface GrazChain {
|
|
10
15
|
chainId: string;
|
|
11
16
|
currencies: AppCurrency[];
|
|
12
17
|
rest: string;
|
|
13
18
|
rpc: string;
|
|
19
|
+
rpcHeaders?: Dictionary;
|
|
20
|
+
gas?: {
|
|
21
|
+
price: string;
|
|
22
|
+
denom: string;
|
|
23
|
+
};
|
|
14
24
|
}
|
|
15
25
|
declare function defineChains<T extends Record<string, GrazChain>>(chains: T): T;
|
|
16
26
|
declare const defaultChains: {
|
|
@@ -20,8 +30,13 @@ declare const defaultChains: {
|
|
|
20
30
|
};
|
|
21
31
|
declare const defaultChainsArray: _keplr_wallet_types.ChainInfo[];
|
|
22
32
|
|
|
33
|
+
declare function connect(chain: GrazChain, signerOpts?: SigningCosmWasmClientOptions): Promise<_keplr_wallet_types.Key>;
|
|
34
|
+
declare function disconnect(): Promise<void>;
|
|
35
|
+
declare function getBalances(bech32Address: string): Promise<_cosmjs_stargate.Coin[]>;
|
|
23
36
|
declare function reconnect(): void;
|
|
24
37
|
|
|
38
|
+
declare function suggestChain(chainInfo: ChainInfo): Promise<ChainInfo>;
|
|
39
|
+
|
|
25
40
|
interface MutationEventArgs<TInitial = unknown, TSuccess = TInitial> {
|
|
26
41
|
onError?: (error: unknown, data: TInitial) => unknown;
|
|
27
42
|
onLoading?: (data: TInitial) => unknown;
|
|
@@ -54,7 +69,6 @@ declare function useBalances(bech32Address?: string): {
|
|
|
54
69
|
refetch: <TPageData>(options?: (react_query.RefetchOptions & react_query.RefetchQueryFilters<TPageData>) | undefined) => Promise<react_query.QueryObserverResult<_cosmjs_amino.Coin[], unknown>>;
|
|
55
70
|
status: "idle" | "error" | "loading" | "success";
|
|
56
71
|
};
|
|
57
|
-
declare function useCosmWasmClient(): _cosmjs_cosmwasm_stargate.SigningCosmWasmClient | null;
|
|
58
72
|
declare type UseConnectChainArgs = MutationEventArgs<GrazChain, Key>;
|
|
59
73
|
declare function useConnect({ onError, onLoading, onSuccess }?: UseConnectChainArgs): {
|
|
60
74
|
error: unknown;
|
|
@@ -90,6 +104,36 @@ declare function useSuggestChain({ onError, onLoading, onSuccess }?: UseSuggestC
|
|
|
90
104
|
status: "idle" | "error" | "loading" | "success";
|
|
91
105
|
};
|
|
92
106
|
|
|
107
|
+
declare type CreateClientArgs = Pick<GrazChain, "rpc" | "rpcHeaders">;
|
|
108
|
+
declare type CreateSigningClientArgs = CreateClientArgs & {
|
|
109
|
+
offlineSigner: OfflineSigner;
|
|
110
|
+
signerOptions?: SigningCosmWasmClientOptions;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
declare type WithRefetchOpts<T> = T & {
|
|
114
|
+
keepRefetchBehavior?: boolean;
|
|
115
|
+
};
|
|
116
|
+
declare function useClient(args?: WithRefetchOpts<CreateClientArgs>): {
|
|
117
|
+
data: _cosmjs_cosmwasm_stargate.CosmWasmClient | null | undefined;
|
|
118
|
+
error: unknown;
|
|
119
|
+
isFetching: boolean;
|
|
120
|
+
isLoading: boolean;
|
|
121
|
+
isRefetching: boolean;
|
|
122
|
+
isSuccess: boolean;
|
|
123
|
+
refetch: <TPageData>(options?: (react_query.RefetchOptions & react_query.RefetchQueryFilters<TPageData>) | undefined) => Promise<react_query.QueryObserverResult<_cosmjs_cosmwasm_stargate.CosmWasmClient | null, unknown>>;
|
|
124
|
+
status: "idle" | "error" | "loading" | "success";
|
|
125
|
+
};
|
|
126
|
+
declare function useSigningClient(args?: WithRefetchOpts<CreateSigningClientArgs>): {
|
|
127
|
+
data: _cosmjs_cosmwasm_stargate.SigningCosmWasmClient | null | undefined;
|
|
128
|
+
error: unknown;
|
|
129
|
+
isFetching: boolean;
|
|
130
|
+
isLoading: boolean;
|
|
131
|
+
isRefetching: boolean;
|
|
132
|
+
isSuccess: boolean;
|
|
133
|
+
refetch: <TPageData>(options?: (react_query.RefetchOptions & react_query.RefetchQueryFilters<TPageData>) | undefined) => Promise<react_query.QueryObserverResult<_cosmjs_cosmwasm_stargate.SigningCosmWasmClient | null, unknown>>;
|
|
134
|
+
status: "idle" | "error" | "loading" | "success";
|
|
135
|
+
};
|
|
136
|
+
|
|
93
137
|
declare function useCheckKeplr(): boolean;
|
|
94
138
|
|
|
95
139
|
declare function getKeplr(): _keplr_wallet_types.Keplr;
|
|
@@ -100,4 +144,4 @@ declare function GrazProvider({ children }: {
|
|
|
100
144
|
children: ReactNode;
|
|
101
145
|
}): JSX.Element;
|
|
102
146
|
|
|
103
|
-
export { GrazChain, GrazProvider, UseAccountArgs, UseConnectChainArgs, UseSuggestChainArgs, defaultChains, defaultChainsArray, defineChains, getKeplr, registerKeplrNotFound, unregisterKeplrNotFound, useAccount, useActiveChain, useBalances, useCheckKeplr,
|
|
147
|
+
export { GrazChain, GrazProvider, UseAccountArgs, UseConnectChainArgs, UseSuggestChainArgs, connect, defaultChains, defaultChainsArray, defineChains, disconnect, getBalances, getKeplr, reconnect, registerKeplrNotFound, suggestChain, unregisterKeplrNotFound, useAccount, useActiveChain, useBalances, useCheckKeplr, useClient, useConnect, useDisconnect, useSigners, useSigningClient, useSuggestChain };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var R=Object.create;var l=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var X=(e,t)=>{for(var o in t)l(e,o,{get:t[o],enumerable:!0})},k=(e,t,o,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Q(t))!V.call(e,n)&&n!==o&&l(e,n,{get:()=>t[n],enumerable:!(c=H(t,n))||c.enumerable});return e};var d=(e,t,o)=>(o=e!=null?R(J(e)):{},k(t||!e||!e.__esModule?l(o,"default",{value:e,enumerable:!0}):o,e)),Y=e=>k(l({},"__esModule",{value:!0}),e);var ke={};X(ke,{GrazProvider:()=>ve,defaultChains:()=>ue,defaultChainsArray:()=>pe,defineChains:()=>me,getKeplr:()=>u,registerKeplrNotFound:()=>le,unregisterKeplrNotFound:()=>ge,useAccount:()=>B,useActiveChain:()=>we,useBalances:()=>he,useCheckKeplr:()=>v,useConnect:()=>de,useCosmWasmClient:()=>fe,useDisconnect:()=>ye,useSigners:()=>Ce,useSuggestChain:()=>Ae});module.exports=Y(ke);var i=d(require("react"));var j=require("@keplr-wallet/cosmos"),b={coinDenom:"atom",coinMinimalDenom:"uatom",coinDecimals:6,coinGeckoId:"cosmos",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},x=[b],y={rpc:"https://rpc.cosmoshub.strange.love",rest:"https://api.cosmoshub.strange.love",chainId:"cosmoshub-4",chainName:"Cosmos Hub",stakeCurrency:b,bip44:{coinType:118},bech32Config:j.Bech32Address.defaultBech32Config("cosmos"),currencies:x,feeCurrencies:x};var I=require("@keplr-wallet/cosmos"),z={coinDenom:"juno",coinMinimalDenom:"ujuno",coinDecimals:6,coinGeckoId:"juno-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"},Z={coinDenom:"neta",coinMinimalDenom:"cw20:juno168ctmpyppk90d34p3jjy658zf5a5l3w8wk35wht6ccqj4mr0yv8s4j5awr",coinDecimals:6,coinGeckoId:"neta",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/neta.png"},$={coinDenom:"marble",coinMinimalDenom:"cw20:juno1g2g7ucurum66d42g8k5twk34yegdq8c82858gz0tq2fc75zy7khssgnhjl",coinDecimals:3,coinGeckoId:"marble",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/marble.png"},ee={coinDenom:"hope",coinMinimalDenom:"cw20:juno1re3x67ppxap48ygndmrc7har2cnc7tcxtm9nplcas4v0gc3wnmvs3s807z",coinDecimals:6,coinGeckoId:"hope-galaxy",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hope.png"},ne={coinDenom:"rac",coinMinimalDenom:"cw20:juno1r4pzw8f9z0sypct5l9j906d47z998ulwvhvqe5xdwgy8wf84583sxwh0pa",coinDecimals:6,coinGeckoId:"racoon",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/rac.png"},te={coinDenom:"block",coinMinimalDenom:"cw20:juno1y9rf7ql6ffwkv02hsgd4yruz23pn4w97p75e2slsnkm0mnamhzysvqnxaq",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/block.png"},oe={coinDenom:"dhk",coinMinimalDenom:"cw20:juno1tdjwrqmnztn2j3sj2ln9xnyps5hs48q3ddwjrz7jpv6mskappjys5czd49",coinDecimals:0,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/dhk.png"},re={coinDenom:"raw",coinMinimalDenom:"cw20:juno15u3dt79t6sxxa3x3kpkhzsy56edaa5a66wvt3kxmukqjz2sx0hes5sn38g",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/raw.png",coinGeckoId:"junoswap-raw-dao"},ie={coinDenom:"asvt",coinMinimalDenom:"cw20:juno17wzaxtfdw5em7lc94yed4ylgjme63eh73lm3lutp2rhcxttyvpwsypjm4w",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/asvt.png"},se={coinDenom:"hns",coinMinimalDenom:"cw20:juno1ur4jx0sxchdevahep7fwq28yk4tqsrhshdtylz46yka3uf6kky5qllqp4k",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hns.svg"},ce={coinDenom:"joe",coinMinimalDenom:"cw20:juno1n7n7d5088qlzlj37e9mgmkhx6dfgtvt02hqxq66lcap4dxnzdhwqfmgng3",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/joe.png"},D=[z,Z,$,ee,ne,te,oe,re,ie,se,ce],C={rpc:"https://rpc.juno.strange.love",rest:"https://api.juno.strange.love",chainId:"juno-1",chainName:"Juno",stakeCurrency:z,bip44:{coinType:118},bech32Config:I.Bech32Address.defaultBech32Config("juno"),currencies:D,feeCurrencies:D};var q=require("@keplr-wallet/cosmos"),_={coinDenom:"osmo",coinMinimalDenom:"uosmo",coinDecimals:6,coinGeckoId:"osmosis",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},ae={coinDenom:"ion",coinMinimalDenom:"uion",coinDecimals:6,coinGeckoId:"ion",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/ion.png"},G=[_,ae],w={rpc:"https://rpc.osmosis.strange.love",rest:"https://api.osmosis.strange.love",chainId:"osmosis-1",chainName:"Osmosis",stakeCurrency:_,bip44:{coinType:118},bech32Config:q.Bech32Address.defaultBech32Config("osmo"),currencies:G,feeCurrencies:G};function me(e){return e}var ue={cosmos:y,juno:C,osmosis:w},pe=[y,C,w];var N=require("react"),p=require("react-query"),E=d(require("zustand/shallow"));var U=require("@cosmjs/cosmwasm-stargate");var M=d(require("zustand")),g=require("zustand/middleware"),A={account:null,activeChain:null,balances:null,client:null,signer:null,signerAmino:null,signerAuto:null,status:"disconnected",_notFoundFn:()=>null,_reconnect:!1,_supported:!1},r=(0,M.default)((0,g.subscribeWithSelector)((0,g.persist)(()=>({...A}),{name:"graz",partialize:e=>({activeChain:e.activeChain,_reconnect:e._reconnect}),version:1})));function u(){if(typeof window.keplr<"u")return window.keplr;throw r.getState()._notFoundFn(),new Error("Keplr is not defined")}function le(e){r.setState({_notFoundFn:e})}function ge(){r.setState({_notFoundFn:()=>null})}async function S(e){try{let t=u();r.setState(f=>{let W=f._reconnect;return f.activeChain&&f.activeChain.chainId!==e.chainId?{status:"connecting"}:W?{status:"reconnecting"}:{status:"connecting"}}),await t.enable(e.chainId);let o=t.getOfflineSigner(e.chainId),c=t.getOfflineSignerOnlyAmino(e.chainId),[n,s,m]=await Promise.all([await t.getKey(e.chainId),await t.getOfflineSignerAuto(e.chainId),await U.SigningCosmWasmClient.connectWithSigner(e.rpc,o)]);return r.setState({account:n,activeChain:e,client:m,signer:o,signerAuto:s,signerAmino:c,status:"connected",_reconnect:!0}),n}catch(t){throw r.getState().account===null&&r.setState({status:"disconnected"}),t}}async function K(){return r.setState(e=>({...A,_supported:e._supported})),Promise.resolve()}async function O(e){let{activeChain:t,client:o}=r.getState();if(!t||!o)throw new Error("No connected account detected");return await Promise.all(t.currencies.map(async n=>o.getBalance(e,n.coinMinimalDenom)))}function a(){let{activeChain:e}=r.getState();e&&S(e)}function v(){return r(e=>e._supported)}function B({onConnect:e,onDisconnect:t}={}){let o=r(n=>n.account),c=r(n=>n.status);return(0,N.useEffect)(()=>r.subscribe(n=>n.status,(n,s)=>{if(n==="connected"){let m=r.getState();e==null||e({account:m.account,isReconnect:s==="reconnecting"})}n==="disconnected"&&(t==null||t())}),[e,t]),{data:o,isConnected:Boolean(o),isConnecting:c==="connecting",isDisconnected:c==="disconnected",isReconnecting:c==="reconnecting",reconnect:a,status:c}}function he(e){let{data:t}=B(),o=e||(t==null?void 0:t.bech32Address),n=(0,p.useQuery)(["WADESTA_USE_BALANCES",o],({queryKey:[,s]})=>O(s),{enabled:Boolean(o)});return{data:n.data,error:n.error,isFetching:n.isFetching,isLoading:n.isLoading,isRefetching:n.isRefetching,isSuccess:n.isSuccess,refetch:n.refetch,status:n.status}}function fe(){return r(e=>e.client)}function de({onError:e,onLoading:t,onSuccess:o}={}){let n=(0,p.useMutation)(["WADESTA_USE_CONNECT",e,t,o],S,{onError:(s,m)=>Promise.resolve(e==null?void 0:e(s,m)),onMutate:t,onSuccess:s=>Promise.resolve(o==null?void 0:o(s))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,isSupported:v(),connect:n.mutate,connectAsync:n.mutateAsync,status:n.status}}function ye({onError:e,onLoading:t,onSuccess:o}={}){let n=(0,p.useMutation)(["WADESTA_USE_DISCONNECT",e,t,o],K,{onError:s=>Promise.resolve(e==null?void 0:e(s,void 0)),onMutate:t,onSuccess:()=>Promise.resolve(o==null?void 0:o(void 0))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,disconnect:n.mutate,disconnectAsync:n.mutateAsync,status:n.status}}function Ce(){return r(e=>({signer:e.signer,signerAmino:e.signerAmino,signerAuto:e.signerAuto}),E.default)}var F=require("react-query");async function T(e){return await u().experimentalSuggestChain(e),e}function we(){return r(e=>e.activeChain)}function Ae({onError:e,onLoading:t,onSuccess:o}={}){let n=(0,F.useMutation)(["WADESTA_USE_SUGGEST_CHAIN",e,t,o],T,{onError:(s,m)=>Promise.resolve(e==null?void 0:e(s,m)),onMutate:t,onSuccess:s=>Promise.resolve(o==null?void 0:o(s))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,suggest:n.mutate,suggestAsync:n.mutateAsync,status:n.status}}var h=require("react-query");var P=require("react");function L(){return(0,P.useEffect)(()=>{r.setState({_supported:typeof window.keplr<"u"});let{_reconnect:e}=r.getState();return e&&a(),window.addEventListener("focus",a),window.addEventListener("keplr_keystorechange",a),()=>{window.removeEventListener("focus",a),window.removeEventListener("keplr_keystorechange",a)}},[]),null}var Se=new h.QueryClient({defaultOptions:{queries:{notifyOnChangeProps:"tracked"}}});function ve({children:e}){return i.createElement(h.QueryClientProvider,{key:"graz-query-client",client:Se},i.createElement(L,null),e)}0&&(module.exports={GrazProvider,defaultChains,defaultChainsArray,defineChains,getKeplr,registerKeplrNotFound,unregisterKeplrNotFound,useAccount,useActiveChain,useBalances,useCheckKeplr,useConnect,useCosmWasmClient,useDisconnect,useSigners,useSuggestChain});
|
|
1
|
+
"use strict";var Y=Object.create;var l=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty;var oe=(e,o)=>{for(var t in o)l(e,t,{get:o[t],enumerable:!0})},O=(e,o,t,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of ee(o))!te.call(e,n)&&n!==t&&l(e,n,{get:()=>o[n],enumerable:!(i=Z(o,n))||i.enumerable});return e};var S=(e,o,t)=>(t=e!=null?Y(ne(e)):{},O(o||!e||!e.__esModule?l(t,"default",{value:e,enumerable:!0}):t,e)),ie=e=>O(l({},"__esModule",{value:!0}),e);var qe={};oe(qe,{GrazProvider:()=>Oe,connect:()=>y,defaultChains:()=>Se,defaultChainsArray:()=>we,defineChains:()=>Ce,disconnect:()=>k,getBalances:()=>v,getKeplr:()=>u,reconnect:()=>m,registerKeplrNotFound:()=>re,suggestChain:()=>x,unregisterKeplrNotFound:()=>se,useAccount:()=>L,useActiveChain:()=>je,useBalances:()=>Ae,useCheckKeplr:()=>I,useClient:()=>De,useConnect:()=>ke,useDisconnect:()=>ve,useSigners:()=>xe,useSigningClient:()=>Ie,useSuggestChain:()=>be});module.exports=ie(qe);var c=S(require("react"));var G=require("@cosmjs/stargate");var q=S(require("zustand")),g=require("zustand/middleware"),w={account:null,activeChain:null,balances:null,client:null,offlineSigner:null,offlineSignerAmino:null,offlineSignerAuto:null,signingClient:null,status:"disconnected",_notFoundFn:()=>null,_reconnect:!1,_supported:!1},r=(0,q.default)((0,g.subscribeWithSelector)((0,g.persist)(()=>({...w}),{name:"graz",partialize:e=>({activeChain:e.activeChain,_reconnect:e._reconnect}),version:1})));function u(){if(typeof window.keplr<"u")return window.keplr;throw r.getState()._notFoundFn(),new Error("Keplr is not defined")}function re(e){r.setState({_notFoundFn:e})}function se(){r.setState({_notFoundFn:()=>null})}var A=require("@cosmjs/cosmwasm-stargate");async function f({rpc:e,rpcHeaders:o}){let t={url:e,headers:{...o||{}}};return await A.SigningCosmWasmClient.connect(t)}async function h(e){let{rpc:o,rpcHeaders:t,offlineSigner:i,signerOptions:n={}}=e,s={url:o,headers:{...t||{}}};return await A.SigningCosmWasmClient.connectWithSigner(s,i,n)}async function y(e,o={}){try{let t=u();r.setState(C=>{let X=C._reconnect;return C.activeChain&&C.activeChain.chainId!==e.chainId?{status:"connecting"}:X?{status:"reconnecting"}:{status:"connecting"}}),await t.enable(e.chainId);let i=t.getOfflineSigner(e.chainId),n=t.getOfflineSignerOnlyAmino(e.chainId),s=e.gas?G.GasPrice.fromString(`${e.gas.price}${e.gas.denom}`):void 0,[a,J,V,$]=await Promise.all([t.getKey(e.chainId),f(e),t.getOfflineSignerAuto(e.chainId),h({...e,offlineSigner:i,signerOptions:{gasPrice:s,...o}})]);return r.setState({account:a,activeChain:e,client:J,offlineSigner:i,offlineSignerAmino:n,offlineSignerAuto:V,signingClient:$,status:"connected",_reconnect:!0}),a}catch(t){throw r.getState().account===null&&r.setState({status:"disconnected"}),t}}async function k(){return r.setState(e=>({...w,_supported:e._supported})),Promise.resolve()}async function v(e){let{activeChain:o,signingClient:t}=r.getState();if(!o||!t)throw new Error("No connected account detected");return await Promise.all(o.currencies.map(async n=>t.getBalance(e,n.coinMinimalDenom)))}function m(){let{activeChain:e}=r.getState();e&&y(e)}async function x(e){return await u().experimentalSuggestChain(e),e}var M=require("@keplr-wallet/cosmos"),U={coinDenom:"atom",coinMinimalDenom:"uatom",coinDecimals:6,coinGeckoId:"cosmos",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},K=[U],j={rpc:"https://rpc.cosmoshub.strange.love",rest:"https://api.cosmoshub.strange.love",chainId:"cosmoshub-4",chainName:"Cosmos Hub",stakeCurrency:U,bip44:{coinType:118},bech32Config:M.Bech32Address.defaultBech32Config("cosmos"),currencies:K,feeCurrencies:K};var E=require("@keplr-wallet/cosmos"),R={coinDenom:"juno",coinMinimalDenom:"ujuno",coinDecimals:6,coinGeckoId:"juno-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"},ce={coinDenom:"neta",coinMinimalDenom:"cw20:juno168ctmpyppk90d34p3jjy658zf5a5l3w8wk35wht6ccqj4mr0yv8s4j5awr",coinDecimals:6,coinGeckoId:"neta",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/neta.png"},ae={coinDenom:"marble",coinMinimalDenom:"cw20:juno1g2g7ucurum66d42g8k5twk34yegdq8c82858gz0tq2fc75zy7khssgnhjl",coinDecimals:3,coinGeckoId:"marble",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/marble.png"},me={coinDenom:"hope",coinMinimalDenom:"cw20:juno1re3x67ppxap48ygndmrc7har2cnc7tcxtm9nplcas4v0gc3wnmvs3s807z",coinDecimals:6,coinGeckoId:"hope-galaxy",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hope.png"},ue={coinDenom:"rac",coinMinimalDenom:"cw20:juno1r4pzw8f9z0sypct5l9j906d47z998ulwvhvqe5xdwgy8wf84583sxwh0pa",coinDecimals:6,coinGeckoId:"racoon",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/rac.png"},pe={coinDenom:"block",coinMinimalDenom:"cw20:juno1y9rf7ql6ffwkv02hsgd4yruz23pn4w97p75e2slsnkm0mnamhzysvqnxaq",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/block.png"},le={coinDenom:"dhk",coinMinimalDenom:"cw20:juno1tdjwrqmnztn2j3sj2ln9xnyps5hs48q3ddwjrz7jpv6mskappjys5czd49",coinDecimals:0,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/dhk.png"},ge={coinDenom:"raw",coinMinimalDenom:"cw20:juno15u3dt79t6sxxa3x3kpkhzsy56edaa5a66wvt3kxmukqjz2sx0hes5sn38g",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/raw.png",coinGeckoId:"junoswap-raw-dao"},fe={coinDenom:"asvt",coinMinimalDenom:"cw20:juno17wzaxtfdw5em7lc94yed4ylgjme63eh73lm3lutp2rhcxttyvpwsypjm4w",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/asvt.png"},he={coinDenom:"hns",coinMinimalDenom:"cw20:juno1ur4jx0sxchdevahep7fwq28yk4tqsrhshdtylz46yka3uf6kky5qllqp4k",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hns.svg"},ye={coinDenom:"joe",coinMinimalDenom:"cw20:juno1n7n7d5088qlzlj37e9mgmkhx6dfgtvt02hqxq66lcap4dxnzdhwqfmgng3",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/joe.png"},B=[R,ce,ae,me,ue,pe,le,ge,fe,he,ye],b={rpc:"https://rpc.juno.strange.love",rest:"https://api.juno.strange.love",chainId:"juno-1",chainName:"Juno",stakeCurrency:R,bip44:{coinType:118},bech32Config:E.Bech32Address.defaultBech32Config("juno"),currencies:B,feeCurrencies:B};var W=require("@keplr-wallet/cosmos"),_={coinDenom:"osmo",coinMinimalDenom:"uosmo",coinDecimals:6,coinGeckoId:"osmosis",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},de={coinDenom:"ion",coinMinimalDenom:"uion",coinDecimals:6,coinGeckoId:"ion",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/ion.png"},N=[_,de],D={rpc:"https://rpc.osmosis.strange.love",rest:"https://api.osmosis.strange.love",chainId:"osmosis-1",chainName:"Osmosis",stakeCurrency:_,bip44:{coinType:118},bech32Config:W.Bech32Address.defaultBech32Config("osmo"),currencies:N,feeCurrencies:N};function Ce(e){return e}var Se={cosmos:j,juno:b,osmosis:D},we=[j,b,D];var F=require("react"),p=require("react-query"),T=S(require("zustand/shallow"));function I(){return r(e=>e._supported)}function L({onConnect:e,onDisconnect:o}={}){let t=r(n=>n.account),i=r(n=>n.status);return(0,F.useEffect)(()=>r.subscribe(n=>n.status,(n,s)=>{if(n==="connected"){let a=r.getState();e==null||e({account:a.account,isReconnect:s==="reconnecting"})}n==="disconnected"&&(o==null||o())}),[e,o]),{data:t,isConnected:Boolean(t),isConnecting:i==="connecting",isDisconnected:i==="disconnected",isReconnecting:i==="reconnecting",reconnect:m,status:i}}function Ae(e){let{data:o}=L(),t=e||(o==null?void 0:o.bech32Address),n=(0,p.useQuery)(["WADESTA_USE_BALANCES",t],({queryKey:[,s]})=>v(s),{enabled:Boolean(t)});return{data:n.data,error:n.error,isFetching:n.isFetching,isLoading:n.isLoading,isRefetching:n.isRefetching,isSuccess:n.isSuccess,refetch:n.refetch,status:n.status}}function ke({onError:e,onLoading:o,onSuccess:t}={}){let n=(0,p.useMutation)(["WADESTA_USE_CONNECT",e,o,t],y,{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:o,onSuccess:s=>Promise.resolve(t==null?void 0:t(s))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,isSupported:I(),connect:n.mutate,connectAsync:n.mutateAsync,status:n.status}}function ve({onError:e,onLoading:o,onSuccess:t}={}){let n=(0,p.useMutation)(["WADESTA_USE_DISCONNECT",e,o,t],k,{onError:s=>Promise.resolve(e==null?void 0:e(s,void 0)),onMutate:o,onSuccess:()=>Promise.resolve(t==null?void 0:t(void 0))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,disconnect:n.mutate,disconnectAsync:n.mutateAsync,status:n.status}}function xe(){return r(e=>({signer:e.offlineSigner,signerAmino:e.offlineSignerAmino,signerAuto:e.offlineSignerAuto}),T.default)}var P=require("react-query");function je(){return r(e=>e.activeChain)}function be({onError:e,onLoading:o,onSuccess:t}={}){let n=(0,P.useMutation)(["WADESTA_USE_SUGGEST_CHAIN",e,o,t],x,{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:o,onSuccess:s=>Promise.resolve(t==null?void 0:t(s))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,suggest:n.mutate,suggestAsync:n.mutateAsync,status:n.status}}var z=require("react-query");function De(e){let o=r(n=>n.client),i=(0,z.useQuery)(["USE_CLIENT",e,o],({queryKey:[,n,s]})=>n!=null&&n.rpc?f(n):s,{refetchOnMount:Boolean(e==null?void 0:e.keepRefetchBehavior),refetchOnWindowFocus:Boolean(e==null?void 0:e.keepRefetchBehavior)});return{data:i.data,error:i.error,isFetching:i.isFetching,isLoading:i.isLoading,isRefetching:i.isRefetching,isSuccess:i.isSuccess,refetch:i.refetch,status:i.status}}function Ie(e){let o=r(n=>n.signingClient),i=(0,z.useQuery)(["USE_SIGNING_CLIENT",e,o],({queryKey:[,n,s]})=>n!=null&&n.rpc?h(n):s,{refetchOnMount:Boolean(e==null?void 0:e.keepRefetchBehavior),refetchOnWindowFocus:Boolean(e==null?void 0:e.keepRefetchBehavior)});return{data:i.data,error:i.error,isFetching:i.isFetching,isLoading:i.isLoading,isRefetching:i.isRefetching,isSuccess:i.isSuccess,refetch:i.refetch,status:i.status}}var d=require("react-query");var H=require("react");function Q(){return(0,H.useEffect)(()=>{r.setState({_supported:typeof window.keplr<"u"});let{_reconnect:e}=r.getState();return e&&m(),window.addEventListener("focus",m),window.addEventListener("keplr_keystorechange",m),()=>{window.removeEventListener("focus",m),window.removeEventListener("keplr_keystorechange",m)}},[]),null}var ze=new d.QueryClient({defaultOptions:{queries:{notifyOnChangeProps:"tracked"}}});function Oe({children:e}){return c.createElement(d.QueryClientProvider,{key:"graz-query-client",client:ze},c.createElement(Q,null),e)}0&&(module.exports={GrazProvider,connect,defaultChains,defaultChainsArray,defineChains,disconnect,getBalances,getKeplr,reconnect,registerKeplrNotFound,suggestChain,unregisterKeplrNotFound,useAccount,useActiveChain,useBalances,useCheckKeplr,useClient,useConnect,useDisconnect,useSigners,useSigningClient,useSuggestChain});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as i from"react";import{Bech32Address as G}from"@keplr-wallet/cosmos";var C={coinDenom:"atom",coinMinimalDenom:"uatom",coinDecimals:6,coinGeckoId:"cosmos",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},y=[C],l={rpc:"https://rpc.cosmoshub.strange.love",rest:"https://api.cosmoshub.strange.love",chainId:"cosmoshub-4",chainName:"Cosmos Hub",stakeCurrency:C,bip44:{coinType:118},bech32Config:G.defaultBech32Config("cosmos"),currencies:y,feeCurrencies:y};import{Bech32Address as q}from"@keplr-wallet/cosmos";var A={coinDenom:"juno",coinMinimalDenom:"ujuno",coinDecimals:6,coinGeckoId:"juno-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"},_={coinDenom:"neta",coinMinimalDenom:"cw20:juno168ctmpyppk90d34p3jjy658zf5a5l3w8wk35wht6ccqj4mr0yv8s4j5awr",coinDecimals:6,coinGeckoId:"neta",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/neta.png"},M={coinDenom:"marble",coinMinimalDenom:"cw20:juno1g2g7ucurum66d42g8k5twk34yegdq8c82858gz0tq2fc75zy7khssgnhjl",coinDecimals:3,coinGeckoId:"marble",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/marble.png"},U={coinDenom:"hope",coinMinimalDenom:"cw20:juno1re3x67ppxap48ygndmrc7har2cnc7tcxtm9nplcas4v0gc3wnmvs3s807z",coinDecimals:6,coinGeckoId:"hope-galaxy",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hope.png"},K={coinDenom:"rac",coinMinimalDenom:"cw20:juno1r4pzw8f9z0sypct5l9j906d47z998ulwvhvqe5xdwgy8wf84583sxwh0pa",coinDecimals:6,coinGeckoId:"racoon",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/rac.png"},O={coinDenom:"block",coinMinimalDenom:"cw20:juno1y9rf7ql6ffwkv02hsgd4yruz23pn4w97p75e2slsnkm0mnamhzysvqnxaq",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/block.png"},N={coinDenom:"dhk",coinMinimalDenom:"cw20:juno1tdjwrqmnztn2j3sj2ln9xnyps5hs48q3ddwjrz7jpv6mskappjys5czd49",coinDecimals:0,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/dhk.png"},E={coinDenom:"raw",coinMinimalDenom:"cw20:juno15u3dt79t6sxxa3x3kpkhzsy56edaa5a66wvt3kxmukqjz2sx0hes5sn38g",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/raw.png",coinGeckoId:"junoswap-raw-dao"},B={coinDenom:"asvt",coinMinimalDenom:"cw20:juno17wzaxtfdw5em7lc94yed4ylgjme63eh73lm3lutp2rhcxttyvpwsypjm4w",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/asvt.png"},T={coinDenom:"hns",coinMinimalDenom:"cw20:juno1ur4jx0sxchdevahep7fwq28yk4tqsrhshdtylz46yka3uf6kky5qllqp4k",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hns.svg"},F={coinDenom:"joe",coinMinimalDenom:"cw20:juno1n7n7d5088qlzlj37e9mgmkhx6dfgtvt02hqxq66lcap4dxnzdhwqfmgng3",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/joe.png"},w=[A,_,M,U,K,O,N,E,B,T,F],g={rpc:"https://rpc.juno.strange.love",rest:"https://api.juno.strange.love",chainId:"juno-1",chainName:"Juno",stakeCurrency:A,bip44:{coinType:118},bech32Config:q.defaultBech32Config("juno"),currencies:w,feeCurrencies:w};import{Bech32Address as P}from"@keplr-wallet/cosmos";var v={coinDenom:"osmo",coinMinimalDenom:"uosmo",coinDecimals:6,coinGeckoId:"osmosis",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},L={coinDenom:"ion",coinMinimalDenom:"uion",coinDecimals:6,coinGeckoId:"ion",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/ion.png"},S=[v,L],h={rpc:"https://rpc.osmosis.strange.love",rest:"https://api.osmosis.strange.love",chainId:"osmosis-1",chainName:"Osmosis",stakeCurrency:v,bip44:{coinType:118},bech32Config:P.defaultBech32Config("osmo"),currencies:S,feeCurrencies:S};function he(e){return e}var fe={cosmos:l,juno:g,osmosis:h},de=[l,g,h];import{useEffect as J}from"react";import{useMutation as b,useQuery as V}from"react-query";import X from"zustand/shallow";import{SigningCosmWasmClient as Q}from"@cosmjs/cosmwasm-stargate";import W from"zustand";import{persist as R,subscribeWithSelector as H}from"zustand/middleware";var f={account:null,activeChain:null,balances:null,client:null,signer:null,signerAmino:null,signerAuto:null,status:"disconnected",_notFoundFn:()=>null,_reconnect:!1,_supported:!1},r=W(H(R(()=>({...f}),{name:"graz",partialize:e=>({activeChain:e.activeChain,_reconnect:e._reconnect}),version:1})));function u(){if(typeof window.keplr<"u")return window.keplr;throw r.getState()._notFoundFn(),new Error("Keplr is not defined")}function ve(e){r.setState({_notFoundFn:e})}function ke(){r.setState({_notFoundFn:()=>null})}async function d(e){try{let t=u();r.setState(p=>{let z=p._reconnect;return p.activeChain&&p.activeChain.chainId!==e.chainId?{status:"connecting"}:z?{status:"reconnecting"}:{status:"connecting"}}),await t.enable(e.chainId);let o=t.getOfflineSigner(e.chainId),c=t.getOfflineSignerOnlyAmino(e.chainId),[n,s,m]=await Promise.all([await t.getKey(e.chainId),await t.getOfflineSignerAuto(e.chainId),await Q.connectWithSigner(e.rpc,o)]);return r.setState({account:n,activeChain:e,client:m,signer:o,signerAuto:s,signerAmino:c,status:"connected",_reconnect:!0}),n}catch(t){throw r.getState().account===null&&r.setState({status:"disconnected"}),t}}async function k(){return r.setState(e=>({...f,_supported:e._supported})),Promise.resolve()}async function x(e){let{activeChain:t,client:o}=r.getState();if(!t||!o)throw new Error("No connected account detected");return await Promise.all(t.currencies.map(async n=>o.getBalance(e,n.coinMinimalDenom)))}function a(){let{activeChain:e}=r.getState();e&&d(e)}function j(){return r(e=>e._supported)}function Y({onConnect:e,onDisconnect:t}={}){let o=r(n=>n.account),c=r(n=>n.status);return J(()=>r.subscribe(n=>n.status,(n,s)=>{if(n==="connected"){let m=r.getState();e==null||e({account:m.account,isReconnect:s==="reconnecting"})}n==="disconnected"&&(t==null||t())}),[e,t]),{data:o,isConnected:Boolean(o),isConnecting:c==="connecting",isDisconnected:c==="disconnected",isReconnecting:c==="reconnecting",reconnect:a,status:c}}function Ne(e){let{data:t}=Y(),o=e||(t==null?void 0:t.bech32Address),n=V(["WADESTA_USE_BALANCES",o],({queryKey:[,s]})=>x(s),{enabled:Boolean(o)});return{data:n.data,error:n.error,isFetching:n.isFetching,isLoading:n.isLoading,isRefetching:n.isRefetching,isSuccess:n.isSuccess,refetch:n.refetch,status:n.status}}function Ee(){return r(e=>e.client)}function Be({onError:e,onLoading:t,onSuccess:o}={}){let n=b(["WADESTA_USE_CONNECT",e,t,o],d,{onError:(s,m)=>Promise.resolve(e==null?void 0:e(s,m)),onMutate:t,onSuccess:s=>Promise.resolve(o==null?void 0:o(s))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,isSupported:j(),connect:n.mutate,connectAsync:n.mutateAsync,status:n.status}}function Te({onError:e,onLoading:t,onSuccess:o}={}){let n=b(["WADESTA_USE_DISCONNECT",e,t,o],k,{onError:s=>Promise.resolve(e==null?void 0:e(s,void 0)),onMutate:t,onSuccess:()=>Promise.resolve(o==null?void 0:o(void 0))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,disconnect:n.mutate,disconnectAsync:n.mutateAsync,status:n.status}}function Fe(){return r(e=>({signer:e.signer,signerAmino:e.signerAmino,signerAuto:e.signerAuto}),X)}import{useMutation as Z}from"react-query";async function D(e){return await u().experimentalSuggestChain(e),e}function Je(){return r(e=>e.activeChain)}function Ve({onError:e,onLoading:t,onSuccess:o}={}){let n=Z(["WADESTA_USE_SUGGEST_CHAIN",e,t,o],D,{onError:(s,m)=>Promise.resolve(e==null?void 0:e(s,m)),onMutate:t,onSuccess:s=>Promise.resolve(o==null?void 0:o(s))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,suggest:n.mutate,suggestAsync:n.mutateAsync,status:n.status}}import{QueryClient as ee,QueryClientProvider as ne}from"react-query";import{useEffect as $}from"react";function I(){return $(()=>{r.setState({_supported:typeof window.keplr<"u"});let{_reconnect:e}=r.getState();return e&&a(),window.addEventListener("focus",a),window.addEventListener("keplr_keystorechange",a),()=>{window.removeEventListener("focus",a),window.removeEventListener("keplr_keystorechange",a)}},[]),null}var te=new ee({defaultOptions:{queries:{notifyOnChangeProps:"tracked"}}});function on({children:e}){return i.createElement(ne,{key:"graz-query-client",client:te},i.createElement(I,null),e)}export{on as GrazProvider,fe as defaultChains,de as defaultChainsArray,he as defineChains,u as getKeplr,ve as registerKeplrNotFound,ke as unregisterKeplrNotFound,Y as useAccount,Je as useActiveChain,Ne as useBalances,j as useCheckKeplr,Be as useConnect,Ee as useCosmWasmClient,Te as useDisconnect,Fe as useSigners,Ve as useSuggestChain};
|
|
1
|
+
import*as c from"react";import{GasPrice as W}from"@cosmjs/stargate";import E from"zustand";import{persist as R,subscribeWithSelector as N}from"zustand/middleware";var f={account:null,activeChain:null,balances:null,client:null,offlineSigner:null,offlineSignerAmino:null,offlineSignerAuto:null,signingClient:null,status:"disconnected",_notFoundFn:()=>null,_reconnect:!1,_supported:!1},r=E(N(R(()=>({...f}),{name:"graz",partialize:e=>({activeChain:e.activeChain,_reconnect:e._reconnect}),version:1})));function u(){if(typeof window.keplr<"u")return window.keplr;throw r.getState()._notFoundFn(),new Error("Keplr is not defined")}function ye(e){r.setState({_notFoundFn:e})}function de(){r.setState({_notFoundFn:()=>null})}import{SigningCosmWasmClient as S}from"@cosmjs/cosmwasm-stargate";async function p({rpc:e,rpcHeaders:i}){let t={url:e,headers:{...i||{}}};return await S.connect(t)}async function l(e){let{rpc:i,rpcHeaders:t,offlineSigner:o,signerOptions:n={}}=e,s={url:i,headers:{...t||{}}};return await S.connectWithSigner(s,o,n)}async function h(e,i={}){try{let t=u();r.setState(g=>{let B=g._reconnect;return g.activeChain&&g.activeChain.chainId!==e.chainId?{status:"connecting"}:B?{status:"reconnecting"}:{status:"connecting"}}),await t.enable(e.chainId);let o=t.getOfflineSigner(e.chainId),n=t.getOfflineSignerOnlyAmino(e.chainId),s=e.gas?W.fromString(`${e.gas.price}${e.gas.denom}`):void 0,[a,K,M,U]=await Promise.all([t.getKey(e.chainId),p(e),t.getOfflineSignerAuto(e.chainId),l({...e,offlineSigner:o,signerOptions:{gasPrice:s,...i}})]);return r.setState({account:a,activeChain:e,client:K,offlineSigner:o,offlineSignerAmino:n,offlineSignerAuto:M,signingClient:U,status:"connected",_reconnect:!0}),a}catch(t){throw r.getState().account===null&&r.setState({status:"disconnected"}),t}}async function w(){return r.setState(e=>({...f,_supported:e._supported})),Promise.resolve()}async function A(e){let{activeChain:i,signingClient:t}=r.getState();if(!i||!t)throw new Error("No connected account detected");return await Promise.all(i.currencies.map(async n=>t.getBalance(e,n.coinMinimalDenom)))}function m(){let{activeChain:e}=r.getState();e&&h(e)}async function k(e){return await u().experimentalSuggestChain(e),e}import{Bech32Address as _}from"@keplr-wallet/cosmos";var x={coinDenom:"atom",coinMinimalDenom:"uatom",coinDecimals:6,coinGeckoId:"cosmos",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},v=[x],y={rpc:"https://rpc.cosmoshub.strange.love",rest:"https://api.cosmoshub.strange.love",chainId:"cosmoshub-4",chainName:"Cosmos Hub",stakeCurrency:x,bip44:{coinType:118},bech32Config:_.defaultBech32Config("cosmos"),currencies:v,feeCurrencies:v};import{Bech32Address as F}from"@keplr-wallet/cosmos";var b={coinDenom:"juno",coinMinimalDenom:"ujuno",coinDecimals:6,coinGeckoId:"juno-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"},T={coinDenom:"neta",coinMinimalDenom:"cw20:juno168ctmpyppk90d34p3jjy658zf5a5l3w8wk35wht6ccqj4mr0yv8s4j5awr",coinDecimals:6,coinGeckoId:"neta",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/neta.png"},L={coinDenom:"marble",coinMinimalDenom:"cw20:juno1g2g7ucurum66d42g8k5twk34yegdq8c82858gz0tq2fc75zy7khssgnhjl",coinDecimals:3,coinGeckoId:"marble",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/marble.png"},P={coinDenom:"hope",coinMinimalDenom:"cw20:juno1re3x67ppxap48ygndmrc7har2cnc7tcxtm9nplcas4v0gc3wnmvs3s807z",coinDecimals:6,coinGeckoId:"hope-galaxy",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hope.png"},H={coinDenom:"rac",coinMinimalDenom:"cw20:juno1r4pzw8f9z0sypct5l9j906d47z998ulwvhvqe5xdwgy8wf84583sxwh0pa",coinDecimals:6,coinGeckoId:"racoon",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/rac.png"},Q={coinDenom:"block",coinMinimalDenom:"cw20:juno1y9rf7ql6ffwkv02hsgd4yruz23pn4w97p75e2slsnkm0mnamhzysvqnxaq",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/block.png"},J={coinDenom:"dhk",coinMinimalDenom:"cw20:juno1tdjwrqmnztn2j3sj2ln9xnyps5hs48q3ddwjrz7jpv6mskappjys5czd49",coinDecimals:0,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/dhk.png"},V={coinDenom:"raw",coinMinimalDenom:"cw20:juno15u3dt79t6sxxa3x3kpkhzsy56edaa5a66wvt3kxmukqjz2sx0hes5sn38g",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/raw.png",coinGeckoId:"junoswap-raw-dao"},$={coinDenom:"asvt",coinMinimalDenom:"cw20:juno17wzaxtfdw5em7lc94yed4ylgjme63eh73lm3lutp2rhcxttyvpwsypjm4w",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/asvt.png"},X={coinDenom:"hns",coinMinimalDenom:"cw20:juno1ur4jx0sxchdevahep7fwq28yk4tqsrhshdtylz46yka3uf6kky5qllqp4k",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hns.svg"},Y={coinDenom:"joe",coinMinimalDenom:"cw20:juno1n7n7d5088qlzlj37e9mgmkhx6dfgtvt02hqxq66lcap4dxnzdhwqfmgng3",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/joe.png"},j=[b,T,L,P,H,Q,J,V,$,X,Y],d={rpc:"https://rpc.juno.strange.love",rest:"https://api.juno.strange.love",chainId:"juno-1",chainName:"Juno",stakeCurrency:b,bip44:{coinType:118},bech32Config:F.defaultBech32Config("juno"),currencies:j,feeCurrencies:j};import{Bech32Address as Z}from"@keplr-wallet/cosmos";var I={coinDenom:"osmo",coinMinimalDenom:"uosmo",coinDecimals:6,coinGeckoId:"osmosis",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},ee={coinDenom:"ion",coinMinimalDenom:"uion",coinDecimals:6,coinGeckoId:"ion",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/ion.png"},D=[I,ee],C={rpc:"https://rpc.osmosis.strange.love",rest:"https://api.osmosis.strange.love",chainId:"osmosis-1",chainName:"Osmosis",stakeCurrency:I,bip44:{coinType:118},bech32Config:Z.defaultBech32Config("osmo"),currencies:D,feeCurrencies:D};function Ee(e){return e}var Re={cosmos:y,juno:d,osmosis:C},Ne=[y,d,C];import{useEffect as ne}from"react";import{useMutation as O,useQuery as te}from"react-query";import oe from"zustand/shallow";function z(){return r(e=>e._supported)}function ie({onConnect:e,onDisconnect:i}={}){let t=r(n=>n.account),o=r(n=>n.status);return ne(()=>r.subscribe(n=>n.status,(n,s)=>{if(n==="connected"){let a=r.getState();e==null||e({account:a.account,isReconnect:s==="reconnecting"})}n==="disconnected"&&(i==null||i())}),[e,i]),{data:t,isConnected:Boolean(t),isConnecting:o==="connecting",isDisconnected:o==="disconnected",isReconnecting:o==="reconnecting",reconnect:m,status:o}}function Ve(e){let{data:i}=ie(),t=e||(i==null?void 0:i.bech32Address),n=te(["WADESTA_USE_BALANCES",t],({queryKey:[,s]})=>A(s),{enabled:Boolean(t)});return{data:n.data,error:n.error,isFetching:n.isFetching,isLoading:n.isLoading,isRefetching:n.isRefetching,isSuccess:n.isSuccess,refetch:n.refetch,status:n.status}}function $e({onError:e,onLoading:i,onSuccess:t}={}){let n=O(["WADESTA_USE_CONNECT",e,i,t],h,{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:i,onSuccess:s=>Promise.resolve(t==null?void 0:t(s))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,isSupported:z(),connect:n.mutate,connectAsync:n.mutateAsync,status:n.status}}function Xe({onError:e,onLoading:i,onSuccess:t}={}){let n=O(["WADESTA_USE_DISCONNECT",e,i,t],w,{onError:s=>Promise.resolve(e==null?void 0:e(s,void 0)),onMutate:i,onSuccess:()=>Promise.resolve(t==null?void 0:t(void 0))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,disconnect:n.mutate,disconnectAsync:n.mutateAsync,status:n.status}}function Ye(){return r(e=>({signer:e.offlineSigner,signerAmino:e.offlineSignerAmino,signerAuto:e.offlineSignerAuto}),oe)}import{useMutation as re}from"react-query";function on(){return r(e=>e.activeChain)}function rn({onError:e,onLoading:i,onSuccess:t}={}){let n=re(["WADESTA_USE_SUGGEST_CHAIN",e,i,t],k,{onError:(s,a)=>Promise.resolve(e==null?void 0:e(s,a)),onMutate:i,onSuccess:s=>Promise.resolve(t==null?void 0:t(s))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,suggest:n.mutate,suggestAsync:n.mutateAsync,status:n.status}}import{useQuery as q}from"react-query";function un(e){let i=r(n=>n.client),o=q(["USE_CLIENT",e,i],({queryKey:[,n,s]})=>n!=null&&n.rpc?p(n):s,{refetchOnMount:Boolean(e==null?void 0:e.keepRefetchBehavior),refetchOnWindowFocus:Boolean(e==null?void 0:e.keepRefetchBehavior)});return{data:o.data,error:o.error,isFetching:o.isFetching,isLoading:o.isLoading,isRefetching:o.isRefetching,isSuccess:o.isSuccess,refetch:o.refetch,status:o.status}}function pn(e){let i=r(n=>n.signingClient),o=q(["USE_SIGNING_CLIENT",e,i],({queryKey:[,n,s]})=>n!=null&&n.rpc?l(n):s,{refetchOnMount:Boolean(e==null?void 0:e.keepRefetchBehavior),refetchOnWindowFocus:Boolean(e==null?void 0:e.keepRefetchBehavior)});return{data:o.data,error:o.error,isFetching:o.isFetching,isLoading:o.isLoading,isRefetching:o.isRefetching,isSuccess:o.isSuccess,refetch:o.refetch,status:o.status}}import{QueryClient as ce,QueryClientProvider as ae}from"react-query";import{useEffect as se}from"react";function G(){return se(()=>{r.setState({_supported:typeof window.keplr<"u"});let{_reconnect:e}=r.getState();return e&&m(),window.addEventListener("focus",m),window.addEventListener("keplr_keystorechange",m),()=>{window.removeEventListener("focus",m),window.removeEventListener("keplr_keystorechange",m)}},[]),null}var me=new ce({defaultOptions:{queries:{notifyOnChangeProps:"tracked"}}});function Sn({children:e}){return c.createElement(ae,{key:"graz-query-client",client:me},c.createElement(G,null),e)}export{Sn as GrazProvider,h as connect,Re as defaultChains,Ne as defaultChainsArray,Ee as defineChains,w as disconnect,A as getBalances,u as getKeplr,m as reconnect,ye as registerKeplrNotFound,k as suggestChain,de as unregisterKeplrNotFound,ie as useAccount,on as useActiveChain,Ve as useBalances,z as useCheckKeplr,un as useClient,$e as useConnect,Xe as useDisconnect,Ye as useSigners,pn as useSigningClient,rn as useSuggestChain};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graz",
|
|
3
3
|
"description": "React hooks for Cosmos",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"author": "Griko Nibras <griko@stranvgelove.ventures>",
|
|
6
6
|
"repository": "https://github.com/strangelove-ventures/graz.git",
|
|
7
7
|
"homepage": "https://github.com/strangelove-ventures/graz",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@cosmjs/cosmwasm-stargate": "^0.28.10",
|
|
25
25
|
"@cosmjs/proto-signing": "^0.28.10",
|
|
26
|
+
"@cosmjs/stargate": "^0.28.10",
|
|
26
27
|
"@keplr-wallet/cosmos": "^0.10.10",
|
|
27
28
|
"@keplr-wallet/types": "^0.10.10",
|
|
28
29
|
"react-query": "^3",
|