graz 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Strangelove Ventures
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # graz
2
+
3
+ React hooks for Cosmos 🪐
4
+
5
+ ```sh
6
+ # using npm
7
+ npm install graz
8
+
9
+ # using yarn
10
+ yarn add graz
11
+ ```
12
+
13
+ Learn more about graz on the [official GitHub repository](https://github.com/strangelove-ventures/graz).
14
+
15
+ [MIT License, Copyright (c) 2022 Strangelove Ventures](./LICENSE)
package/dist/.gitkeep ADDED
File without changes
@@ -0,0 +1,90 @@
1
+ import * as _keplr_wallet_types from '@keplr-wallet/types';
2
+ import { AppCurrency, Key, ChainInfo } from '@keplr-wallet/types';
3
+ import * as _cosmjs_proto_signing from '@cosmjs/proto-signing';
4
+ import * as _cosmjs_cosmwasm_stargate from '@cosmjs/cosmwasm-stargate';
5
+ import * as react_query from 'react-query';
6
+ import * as _cosmjs_amino from '@cosmjs/amino';
7
+ import { ReactNode } from 'react';
8
+
9
+ interface GrazChain {
10
+ chainId: string;
11
+ currencies: AppCurrency[];
12
+ rest: string;
13
+ rpc: string;
14
+ }
15
+ declare function defineChains<T extends Record<string, GrazChain>>(chains: T): T;
16
+ declare const defaultChains: {
17
+ cosmos: _keplr_wallet_types.ChainInfo;
18
+ juno: _keplr_wallet_types.ChainInfo;
19
+ osmosis: _keplr_wallet_types.ChainInfo;
20
+ };
21
+
22
+ declare function reconnect(): void;
23
+
24
+ interface MutationEventArgs<TInitial = unknown, TSuccess = TInitial> {
25
+ onError?: (error: unknown, data: TInitial) => unknown;
26
+ onLoading?: (data: TInitial) => unknown;
27
+ onSuccess?: (data: TSuccess) => unknown;
28
+ }
29
+
30
+ declare function useAccount(): {
31
+ data: Key | null;
32
+ isConnected: boolean;
33
+ isConnecting: boolean;
34
+ isDisconnected: boolean;
35
+ isReconnecting: boolean;
36
+ reconnect: typeof reconnect;
37
+ status: "connected" | "connecting" | "reconnecting" | "disconnected";
38
+ };
39
+ declare function useBalances(bech32Address?: string): {
40
+ data: _cosmjs_amino.Coin[] | undefined;
41
+ error: unknown;
42
+ isLoading: boolean;
43
+ isFetching: boolean;
44
+ isRefetching: boolean;
45
+ isSuccess: boolean;
46
+ refetch: <TPageData>(options?: (react_query.RefetchOptions & react_query.RefetchQueryFilters<TPageData>) | undefined) => Promise<react_query.QueryObserverResult<_cosmjs_amino.Coin[], unknown>>;
47
+ status: "idle" | "error" | "loading" | "success";
48
+ };
49
+ declare function useCosmWasmClient(): _cosmjs_cosmwasm_stargate.SigningCosmWasmClient | null;
50
+ declare type UseConnectChainArgs = MutationEventArgs<GrazChain, Key>;
51
+ declare function useConnect({ onError, onLoading, onSuccess }?: UseConnectChainArgs): {
52
+ error: unknown;
53
+ isLoading: boolean;
54
+ isSuccess: boolean;
55
+ connect: react_query.UseMutateFunction<Key, unknown, GrazChain, unknown>;
56
+ connectAsync: react_query.UseMutateAsyncFunction<Key, unknown, GrazChain, unknown>;
57
+ status: "idle" | "error" | "loading" | "success";
58
+ };
59
+ declare function useDisconnect({ onError, onLoading, onSuccess }?: MutationEventArgs): {
60
+ error: unknown;
61
+ isLoading: boolean;
62
+ isSuccess: boolean;
63
+ disconnect: react_query.UseMutateFunction<void, unknown, unknown, unknown>;
64
+ disconnectAsync: react_query.UseMutateAsyncFunction<void, unknown, unknown, unknown>;
65
+ status: "idle" | "error" | "loading" | "success";
66
+ };
67
+ declare function useSigners(): {
68
+ signer: (_cosmjs_proto_signing.OfflineSigner & _cosmjs_proto_signing.OfflineDirectSigner) | null;
69
+ signerAmino: _cosmjs_proto_signing.OfflineSigner | null;
70
+ signerAuto: _cosmjs_proto_signing.OfflineSigner | null;
71
+ };
72
+
73
+ declare function useActiveChain(): GrazChain | null;
74
+ declare type UseSuggestChainArgs = MutationEventArgs<ChainInfo>;
75
+ declare function useSuggestChain({ onError, onLoading, onSuccess }?: UseSuggestChainArgs): {
76
+ error: unknown;
77
+ isLoading: boolean;
78
+ isSuccess: boolean;
79
+ suggest: react_query.UseMutateFunction<ChainInfo, unknown, ChainInfo, unknown>;
80
+ suggestAsync: react_query.UseMutateAsyncFunction<ChainInfo, unknown, ChainInfo, unknown>;
81
+ status: "idle" | "error" | "loading" | "success";
82
+ };
83
+
84
+ declare function getKeplr(): _keplr_wallet_types.Keplr;
85
+
86
+ declare function GrazProvider({ children }: {
87
+ children: ReactNode;
88
+ }): JSX.Element;
89
+
90
+ export { GrazChain, GrazProvider, UseConnectChainArgs, UseSuggestChainArgs, defaultChains, defineChains, getKeplr, useAccount, useActiveChain, useBalances, useConnect, useCosmWasmClient, useDisconnect, useSigners, useSuggestChain };
package/dist/index.js ADDED
@@ -0,0 +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});
package/dist/index.mjs ADDED
@@ -0,0 +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};
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "graz",
3
+ "description": "React hooks for Cosmos",
4
+ "version": "0.0.1",
5
+ "author": "Griko Nibras <griko@stranvgelove.ventures>",
6
+ "repository": "https://github.com/strangelove-ventures/graz.git",
7
+ "homepage": "https://github.com/strangelove-ventures/graz",
8
+ "bugs": "https://github.com/strangelove-ventures/graz/issues",
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.mjs",
11
+ "types": "./dist/index.d.ts",
12
+ "files": [
13
+ "dist/**/*.js",
14
+ "dist/**/*.cjs",
15
+ "dist/**/*.mjs",
16
+ "dist/**/*.d.ts"
17
+ ],
18
+ "sideEffects": false,
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "dev": "tsup --watch"
22
+ },
23
+ "dependencies": {
24
+ "@cosmjs/cosmwasm-stargate": "0.28.10",
25
+ "@cosmjs/proto-signing": "0.28.10",
26
+ "@keplr-wallet/common": "0.10.9",
27
+ "@keplr-wallet/cosmos": "0.10.9",
28
+ "@keplr-wallet/types": "0.10.9",
29
+ "react-query": "^3",
30
+ "zustand": "4.0.0-rc.1"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^16",
34
+ "@types/react": "^18",
35
+ "react": "^18",
36
+ "typescript": "^4"
37
+ },
38
+ "peerDependencies": {
39
+ "react": ">=16.8"
40
+ },
41
+ "eslintConfig": {
42
+ "extends": [
43
+ "@project/eslint-config"
44
+ ],
45
+ "ignorePatterns": [
46
+ "dist/**/*"
47
+ ],
48
+ "root": true
49
+ },
50
+ "lint-staged": {
51
+ "*.{json,md}": [
52
+ "prettier --write"
53
+ ],
54
+ "**/*.ts": [
55
+ "yarn workspace graz eslint --fix"
56
+ ]
57
+ },
58
+ "prettier": "@project/prettier-config",
59
+ "license": "MIT"
60
+ }