graz 0.0.2 → 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 +63 -6
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
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: {
|
|
@@ -18,16 +28,29 @@ declare const defaultChains: {
|
|
|
18
28
|
juno: _keplr_wallet_types.ChainInfo;
|
|
19
29
|
osmosis: _keplr_wallet_types.ChainInfo;
|
|
20
30
|
};
|
|
31
|
+
declare const defaultChainsArray: _keplr_wallet_types.ChainInfo[];
|
|
21
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[]>;
|
|
22
36
|
declare function reconnect(): void;
|
|
23
37
|
|
|
38
|
+
declare function suggestChain(chainInfo: ChainInfo): Promise<ChainInfo>;
|
|
39
|
+
|
|
24
40
|
interface MutationEventArgs<TInitial = unknown, TSuccess = TInitial> {
|
|
25
41
|
onError?: (error: unknown, data: TInitial) => unknown;
|
|
26
42
|
onLoading?: (data: TInitial) => unknown;
|
|
27
43
|
onSuccess?: (data: TSuccess) => unknown;
|
|
28
44
|
}
|
|
29
45
|
|
|
30
|
-
|
|
46
|
+
interface UseAccountArgs {
|
|
47
|
+
onConnect?: (args: {
|
|
48
|
+
account: Key;
|
|
49
|
+
isReconnect: boolean;
|
|
50
|
+
}) => void;
|
|
51
|
+
onDisconnect?: () => void;
|
|
52
|
+
}
|
|
53
|
+
declare function useAccount({ onConnect, onDisconnect }?: UseAccountArgs): {
|
|
31
54
|
data: Key | null;
|
|
32
55
|
isConnected: boolean;
|
|
33
56
|
isConnecting: boolean;
|
|
@@ -39,19 +62,19 @@ declare function useAccount(): {
|
|
|
39
62
|
declare function useBalances(bech32Address?: string): {
|
|
40
63
|
data: _cosmjs_amino.Coin[] | undefined;
|
|
41
64
|
error: unknown;
|
|
42
|
-
isLoading: boolean;
|
|
43
65
|
isFetching: boolean;
|
|
66
|
+
isLoading: boolean;
|
|
44
67
|
isRefetching: boolean;
|
|
45
68
|
isSuccess: boolean;
|
|
46
69
|
refetch: <TPageData>(options?: (react_query.RefetchOptions & react_query.RefetchQueryFilters<TPageData>) | undefined) => Promise<react_query.QueryObserverResult<_cosmjs_amino.Coin[], unknown>>;
|
|
47
70
|
status: "idle" | "error" | "loading" | "success";
|
|
48
71
|
};
|
|
49
|
-
declare function useCosmWasmClient(): _cosmjs_cosmwasm_stargate.SigningCosmWasmClient | null;
|
|
50
72
|
declare type UseConnectChainArgs = MutationEventArgs<GrazChain, Key>;
|
|
51
73
|
declare function useConnect({ onError, onLoading, onSuccess }?: UseConnectChainArgs): {
|
|
52
74
|
error: unknown;
|
|
53
75
|
isLoading: boolean;
|
|
54
76
|
isSuccess: boolean;
|
|
77
|
+
isSupported: boolean;
|
|
55
78
|
connect: react_query.UseMutateFunction<Key, unknown, GrazChain, unknown>;
|
|
56
79
|
connectAsync: react_query.UseMutateAsyncFunction<Key, unknown, GrazChain, unknown>;
|
|
57
80
|
status: "idle" | "error" | "loading" | "success";
|
|
@@ -81,10 +104,44 @@ declare function useSuggestChain({ onError, onLoading, onSuccess }?: UseSuggestC
|
|
|
81
104
|
status: "idle" | "error" | "loading" | "success";
|
|
82
105
|
};
|
|
83
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
|
+
|
|
137
|
+
declare function useCheckKeplr(): boolean;
|
|
138
|
+
|
|
84
139
|
declare function getKeplr(): _keplr_wallet_types.Keplr;
|
|
140
|
+
declare function registerKeplrNotFound(fn: () => void): void;
|
|
141
|
+
declare function unregisterKeplrNotFound(): void;
|
|
85
142
|
|
|
86
143
|
declare function GrazProvider({ children }: {
|
|
87
144
|
children: ReactNode;
|
|
88
145
|
}): JSX.Element;
|
|
89
146
|
|
|
90
|
-
export { GrazChain, GrazProvider, UseConnectChainArgs, UseSuggestChainArgs, defaultChains, defineChains, getKeplr, useAccount, useActiveChain, useBalances,
|
|
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 F=(e,o)=>{for(var t in o)l(e,t,{get:o[t],enumerable:!0})},C=(e,o,t,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of Q(o))!V.call(e,n)&&n!==t&&l(e,n,{get:()=>o[n],enumerable:!(i=H(o,n))||i.enumerable});return e};var f=(e,o,t)=>(t=e!=null?R(J(e)):{},C(o||!e||!e.__esModule?l(t,"default",{value:e,enumerable:!0}):t,e)),X=e=>C(l({},"__esModule",{value:!0}),e);var we={};F(we,{GrazProvider:()=>Ce,defaultChains:()=>me,defineChains:()=>ae,getKeplr:()=>u,useAccount:()=>_,useActiveChain:()=>fe,useBalances:()=>ue,useConnect:()=>le,useCosmWasmClient:()=>pe,useDisconnect:()=>ge,useSigners:()=>he,useSuggestChain:()=>ye});module.exports=X(we);var s=f(require("react"));var A=require("@keplr-wallet/cosmos"),k={coinDenom:"atom",coinMinimalDenom:"uatom",coinDecimals:6,coinGeckoId:"cosmos",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},w=[k],v={rpc:"https://rpc.cosmoshub.strange.love",rest:"https://api.cosmoshub.strange.love",chainId:"cosmoshub-4",chainName:"Cosmos Hub",stakeCurrency:k,bip44:{coinType:118},bech32Config:A.Bech32Address.defaultBech32Config("cosmos"),currencies:w,feeCurrencies:w};var D=require("@keplr-wallet/cosmos"),j={coinDenom:"juno",coinMinimalDenom:"ujuno",coinDecimals:6,coinGeckoId:"juno-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"},Y={coinDenom:"neta",coinMinimalDenom:"cw20:juno168ctmpyppk90d34p3jjy658zf5a5l3w8wk35wht6ccqj4mr0yv8s4j5awr",coinDecimals:6,coinGeckoId:"neta",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/neta.png"},Z={coinDenom:"marble",coinMinimalDenom:"cw20:juno1g2g7ucurum66d42g8k5twk34yegdq8c82858gz0tq2fc75zy7khssgnhjl",coinDecimals:3,coinGeckoId:"marble",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/marble.png"},$={coinDenom:"hope",coinMinimalDenom:"cw20:juno1re3x67ppxap48ygndmrc7har2cnc7tcxtm9nplcas4v0gc3wnmvs3s807z",coinDecimals:6,coinGeckoId:"hope-galaxy",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hope.png"},ee={coinDenom:"rac",coinMinimalDenom:"cw20:juno1r4pzw8f9z0sypct5l9j906d47z998ulwvhvqe5xdwgy8wf84583sxwh0pa",coinDecimals:6,coinGeckoId:"racoon",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/rac.png"},ne={coinDenom:"block",coinMinimalDenom:"cw20:juno1y9rf7ql6ffwkv02hsgd4yruz23pn4w97p75e2slsnkm0mnamhzysvqnxaq",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/block.png"},te={coinDenom:"dhk",coinMinimalDenom:"cw20:juno1tdjwrqmnztn2j3sj2ln9xnyps5hs48q3ddwjrz7jpv6mskappjys5czd49",coinDecimals:0,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/dhk.png"},oe={coinDenom:"raw",coinMinimalDenom:"cw20:juno15u3dt79t6sxxa3x3kpkhzsy56edaa5a66wvt3kxmukqjz2sx0hes5sn38g",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/raw.png",coinGeckoId:"junoswap-raw-dao"},re={coinDenom:"asvt",coinMinimalDenom:"cw20:juno17wzaxtfdw5em7lc94yed4ylgjme63eh73lm3lutp2rhcxttyvpwsypjm4w",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/asvt.png"},ie={coinDenom:"hns",coinMinimalDenom:"cw20:juno1ur4jx0sxchdevahep7fwq28yk4tqsrhshdtylz46yka3uf6kky5qllqp4k",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hns.svg"},se={coinDenom:"joe",coinMinimalDenom:"cw20:juno1n7n7d5088qlzlj37e9mgmkhx6dfgtvt02hqxq66lcap4dxnzdhwqfmgng3",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/joe.png"},x=[j,Y,Z,$,ee,ne,te,oe,re,ie,se],S={rpc:"https://rpc.juno.strange.love",rest:"https://api.juno.strange.love",chainId:"juno-1",chainName:"Juno",stakeCurrency:j,bip44:{coinType:118},bech32Config:D.Bech32Address.defaultBech32Config("juno"),currencies:x,feeCurrencies:x};var I=require("@keplr-wallet/cosmos"),z={coinDenom:"osmo",coinMinimalDenom:"uosmo",coinDecimals:6,coinGeckoId:"osmosis",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},ce={coinDenom:"ion",coinMinimalDenom:"uion",coinDecimals:6,coinGeckoId:"ion",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/ion.png"},b=[z,ce],q={rpc:"https://rpc.osmosis.strange.love",rest:"https://api.osmosis.strange.love",chainId:"osmosis-1",chainName:"Osmosis",stakeCurrency:z,bip44:{coinType:118},bech32Config:I.Bech32Address.defaultBech32Config("osmo"),currencies:b,feeCurrencies:b};function ae(e){return e}var me={cosmos:v,juno:S,osmosis:q};var p=require("react-query"),K=f(require("zustand/shallow"));var M=require("@cosmjs/cosmwasm-stargate");function u(){if(typeof window.keplr<"u")return window.keplr;throw new Error("Keplr is not defined")}var G=f(require("zustand")),g=require("zustand/middleware"),y={account:null,activeChain:null,balances:null,client:null,signer:null,signerAmino:null,signerAuto:null,status:"disconnected"},r=(0,G.default)((0,g.subscribeWithSelector)((0,g.persist)(()=>({...y}),{name:"graz",partialize:e=>({activeChain:e.activeChain,_reconnect:e._reconnect}),version:1})));async function d(e,o={}){let{autoConnect:t=!0}=o;try{let i=u();r.setState(W=>({status:W._reconnect?"reconnecting":"connecting"})),await i.enable(e.chainId);let n=i.getOfflineSigner(e.chainId),c=i.getOfflineSignerOnlyAmino(e.chainId),[a,P,L]=await Promise.all([await i.getKey(e.chainId),await i.getOfflineSignerAuto(e.chainId),await M.SigningCosmWasmClient.connectWithSigner(e.rpc,n)]);return r.setState({account:a,activeChain:e,client:L,signer:n,signerAuto:P,signerAmino:c,status:"connected",_reconnect:t}),a}catch(i){throw r.getState().account===null&&r.setState({status:"disconnected"}),i}}async function O(){return r.setState({...y}),Promise.resolve()}async function U(e){let{activeChain:o,client: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&&d(e)}function _(){let e=r(t=>t.account),o=r(t=>t.status);return{data:e,isConnected:o==="connected",isConnecting:o==="connecting",isDisconnected:o==="disconnected",isReconnecting:o==="reconnecting",reconnect:m,status:o}}function ue(e){var c;let o=_(),t=e||((c=o.data)==null?void 0:c.bech32Address),n=(0,p.useQuery)(["WADESTA_USE_BALANCES",t],({queryKey:[,a]})=>U(a),{enabled:Boolean(t)});return{data:n.data,error:n.error,isLoading:n.isLoading,isFetching:n.isFetching,isRefetching:n.isRefetching,isSuccess:n.isSuccess,refetch:n.refetch,status:n.status}}function pe(){return r(e=>e.client)}function le({onError:e,onLoading:o,onSuccess:t}={}){let n=(0,p.useMutation)(["WADESTA_USE_CONNECT",e,o,t],d,{onError:(c,a)=>Promise.resolve(e==null?void 0:e(c,a)),onMutate:o,onSuccess:c=>Promise.resolve(t==null?void 0:t(c))});return{error:n.error,isLoading:n.isLoading,isSuccess:n.isSuccess,connect:n.mutate,connectAsync:n.mutateAsync,status:n.status}}function ge({onError:e,onLoading:o,onSuccess:t}={}){let n=(0,p.useMutation)(["WADESTA_USE_DISCONNECT",e,o,t],O,{onError:c=>Promise.resolve(e==null?void 0:e(c,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 he(){return r(e=>({signer:e.signer,signerAmino:e.signerAmino,signerAuto:e.signerAuto}),K.default)}var N=require("react-query");async function E(e){return await u().experimentalSuggestChain(e),e}function fe(){return r(e=>e.activeChain)}function ye({onError:e,onLoading:o,onSuccess:t}={}){let n=(0,N.useMutation)(["WADESTA_USE_SUGGEST_CHAIN",e,o,t],E,{onError:(c,a)=>Promise.resolve(e==null?void 0:e(c,a)),onMutate:o,onSuccess:c=>Promise.resolve(t==null?void 0:t(c))});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 T=require("react");function B(){return(0,T.useEffect)(()=>{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 de=new h.QueryClient({defaultOptions:{queries:{notifyOnChangeProps:"tracked"}}});function Ce({children:e}){return s.createElement(h.QueryClientProvider,{key:"graz-query-client",client:de},s.createElement(B,null),e)}0&&(module.exports={GrazProvider,defaultChains,defineChains,getKeplr,useAccount,useActiveChain,useBalances,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 q}from"@keplr-wallet/cosmos";var h={coinDenom:"atom",coinMinimalDenom:"uatom",coinDecimals:6,coinGeckoId:"cosmos",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},g=[h],f={rpc:"https://rpc.cosmoshub.strange.love",rest:"https://api.cosmoshub.strange.love",chainId:"cosmoshub-4",chainName:"Cosmos Hub",stakeCurrency:h,bip44:{coinType:118},bech32Config:q.defaultBech32Config("cosmos"),currencies:g,feeCurrencies:g};import{Bech32Address as G}from"@keplr-wallet/cosmos";var d={coinDenom:"juno",coinMinimalDenom:"ujuno",coinDecimals:6,coinGeckoId:"juno-network",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/juno.png"},M={coinDenom:"neta",coinMinimalDenom:"cw20:juno168ctmpyppk90d34p3jjy658zf5a5l3w8wk35wht6ccqj4mr0yv8s4j5awr",coinDecimals:6,coinGeckoId:"neta",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/neta.png"},O={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"},_={coinDenom:"block",coinMinimalDenom:"cw20:juno1y9rf7ql6ffwkv02hsgd4yruz23pn4w97p75e2slsnkm0mnamhzysvqnxaq",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/block.png"},E={coinDenom:"dhk",coinMinimalDenom:"cw20:juno1tdjwrqmnztn2j3sj2ln9xnyps5hs48q3ddwjrz7jpv6mskappjys5czd49",coinDecimals:0,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/dhk.png"},N={coinDenom:"raw",coinMinimalDenom:"cw20:juno15u3dt79t6sxxa3x3kpkhzsy56edaa5a66wvt3kxmukqjz2sx0hes5sn38g",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/raw.png",coinGeckoId:"junoswap-raw-dao"},T={coinDenom:"asvt",coinMinimalDenom:"cw20:juno17wzaxtfdw5em7lc94yed4ylgjme63eh73lm3lutp2rhcxttyvpwsypjm4w",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/asvt.png"},B={coinDenom:"hns",coinMinimalDenom:"cw20:juno1ur4jx0sxchdevahep7fwq28yk4tqsrhshdtylz46yka3uf6kky5qllqp4k",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/hns.svg"},P={coinDenom:"joe",coinMinimalDenom:"cw20:juno1n7n7d5088qlzlj37e9mgmkhx6dfgtvt02hqxq66lcap4dxnzdhwqfmgng3",coinDecimals:6,coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/images/joe.png"},y=[d,M,O,U,K,_,E,N,T,B,P],C={rpc:"https://rpc.juno.strange.love",rest:"https://api.juno.strange.love",chainId:"juno-1",chainName:"Juno",stakeCurrency:d,bip44:{coinType:118},bech32Config:G.defaultBech32Config("juno"),currencies:y,feeCurrencies:y};import{Bech32Address as L}from"@keplr-wallet/cosmos";var A={coinDenom:"osmo",coinMinimalDenom:"uosmo",coinDecimals:6,coinGeckoId:"osmosis",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png"},W={coinDenom:"ion",coinMinimalDenom:"uion",coinDecimals:6,coinGeckoId:"ion",coinImageUrl:"https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/ion.png"},w=[A,W],k={rpc:"https://rpc.osmosis.strange.love",rest:"https://api.osmosis.strange.love",chainId:"osmosis-1",chainName:"Osmosis",stakeCurrency:A,bip44:{coinType:118},bech32Config:L.defaultBech32Config("osmo"),currencies:w,feeCurrencies:w};function le(e){return e}var ge={cosmos:f,juno:C,osmosis:k};import{useMutation as D,useQuery as V}from"react-query";import F from"zustand/shallow";import{SigningCosmWasmClient as J}from"@cosmjs/cosmwasm-stargate";function u(){if(typeof window.keplr<"u")return window.keplr;throw new Error("Keplr is not defined")}import R from"zustand";import{persist as H,subscribeWithSelector as Q}from"zustand/middleware";var p={account:null,activeChain:null,balances:null,client:null,signer:null,signerAmino:null,signerAuto:null,status:"disconnected"},r=R(Q(H(()=>({...p}),{name:"graz",partialize:e=>({activeChain:e.activeChain,_reconnect:e._reconnect}),version:1})));async function l(e,o={}){let{autoConnect:t=!0}=o;try{let c=u();r.setState(z=>({status:z._reconnect?"reconnecting":"connecting"})),await c.enable(e.chainId);let n=c.getOfflineSigner(e.chainId),s=c.getOfflineSignerOnlyAmino(e.chainId),[a,b,I]=await Promise.all([await c.getKey(e.chainId),await c.getOfflineSignerAuto(e.chainId),await J.connectWithSigner(e.rpc,n)]);return r.setState({account:a,activeChain:e,client:I,signer:n,signerAuto:b,signerAmino:s,status:"connected",_reconnect:t}),a}catch(c){throw r.getState().account===null&&r.setState({status:"disconnected"}),c}}async function v(){return r.setState({...p}),Promise.resolve()}async function x(e){let{activeChain:o,client: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&&l(e)}function X(){let e=r(t=>t.account),o=r(t=>t.status);return{data:e,isConnected:o==="connected",isConnecting:o==="connecting",isDisconnected:o==="disconnected",isReconnecting:o==="reconnecting",reconnect:m,status:o}}function be(e){var s;let o=X(),t=e||((s=o.data)==null?void 0:s.bech32Address),n=V(["WADESTA_USE_BALANCES",t],({queryKey:[,a]})=>x(a),{enabled:Boolean(t)});return{data:n.data,error:n.error,isLoading:n.isLoading,isFetching:n.isFetching,isRefetching:n.isRefetching,isSuccess:n.isSuccess,refetch:n.refetch,status:n.status}}function Ie(){return r(e=>e.client)}function ze({onError:e,onLoading:o,onSuccess:t}={}){let n=D(["WADESTA_USE_CONNECT",e,o,t],l,{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,connect:n.mutate,connectAsync:n.mutateAsync,status:n.status}}function qe({onError:e,onLoading:o,onSuccess:t}={}){let n=D(["WADESTA_USE_DISCONNECT",e,o,t],v,{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 Ge(){return r(e=>({signer:e.signer,signerAmino:e.signerAmino,signerAuto:e.signerAuto}),F)}import{useMutation as Y}from"react-query";async function j(e){return await u().experimentalSuggestChain(e),e}function Ne(){return r(e=>e.activeChain)}function Te({onError:e,onLoading:o,onSuccess:t}={}){let n=Y(["WADESTA_USE_SUGGEST_CHAIN",e,o,t],j,{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}}import{QueryClient as $,QueryClientProvider as ee}from"react-query";import{useEffect as Z}from"react";function S(){return Z(()=>{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 ne=new $({defaultOptions:{queries:{notifyOnChangeProps:"tracked"}}});function Je({children:e}){return i.createElement(ee,{key:"graz-query-client",client:ne},i.createElement(S,null),e)}export{Je as GrazProvider,ge as defaultChains,le as defineChains,u as getKeplr,X as useAccount,Ne as useActiveChain,be as useBalances,ze as useConnect,Ie as useCosmWasmClient,qe as useDisconnect,Ge as useSigners,Te 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",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsup",
|
|
21
|
-
"dev": "tsup --watch"
|
|
22
|
-
"prepublish": "yarn build"
|
|
21
|
+
"dev": "tsup --watch"
|
|
23
22
|
},
|
|
24
23
|
"dependencies": {
|
|
25
24
|
"@cosmjs/cosmwasm-stargate": "^0.28.10",
|
|
26
25
|
"@cosmjs/proto-signing": "^0.28.10",
|
|
26
|
+
"@cosmjs/stargate": "^0.28.10",
|
|
27
27
|
"@keplr-wallet/cosmos": "^0.10.10",
|
|
28
28
|
"@keplr-wallet/types": "^0.10.10",
|
|
29
29
|
"react-query": "^3",
|