Skip to content

Commit

Permalink
0.0.49 (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki authored Aug 31, 2023
2 parents 398a299 + 29316dd commit 4a174ed
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/graz/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "graz",
"description": "React hooks for Cosmos",
"version": "0.0.48",
"version": "0.0.49",
"author": "Griko Nibras <[email protected]>",
"repository": "https://github.com/graz-sh/graz.git",
"homepage": "https://github.com/graz-sh/graz",
Expand Down
13 changes: 12 additions & 1 deletion packages/graz/src/actions/wallet/metamask-snap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,18 @@ export const getMetamaskSnap = (params?: GetMetamaskSnap): Wallet => {
};

const experimentalSuggestChain = async (..._args: Parameters<Keplr["experimentalSuggestChain"]>) => {
await Promise.reject(new Error("Metamask does not support experimentalSuggestChain"));
await ethereum.request({
method: "wallet_invokeSnap",
params: {
snapId: params.id,
request: {
method: "suggestChain",
params: {
chainInfo: _args[0],
},
},
},
});
};

return {
Expand Down
8 changes: 6 additions & 2 deletions packages/graz/src/provider/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { FC } from "react";
import { useEffect } from "react";

import { reconnect } from "../actions/account";
import { checkWallet } from "../actions/wallet";
import { getCosmostation } from "../actions/wallet/cosmostation";
import { getKeplr } from "../actions/wallet/keplr";
import { getLeap } from "../actions/wallet/leap";
Expand All @@ -21,10 +22,12 @@ export const useGrazEvents = () => {
typeof window !== "undefined" && window.sessionStorage.getItem(RECONNECT_SESSION_KEY) === "Active";
const { _reconnect, _onReconnectFailed, _reconnectConnector } = useGrazInternalStore();
const { activeChain, wcSignClient } = useGrazSessionStore();
const isReconnectConnectorReady = checkWallet(_reconnectConnector || undefined);

useEffect(() => {
// will reconnect on refresh
if (_reconnectConnector) {
if (!isReconnectConnectorReady) return;
if (isSessionActive && Boolean(activeChain)) {
void reconnect({
onError: _onReconnectFailed,
Expand All @@ -38,10 +41,11 @@ export const useGrazEvents = () => {
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [isReconnectConnectorReady]);

useEffect(() => {
if (_reconnectConnector) {
if (!isReconnectConnectorReady) return;
if (_reconnectConnector === WalletType.COSMOSTATION) {
getCosmostation().subscription?.(() => {
void reconnect({
Expand Down Expand Up @@ -74,7 +78,7 @@ export const useGrazEvents = () => {
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [_reconnectConnector, wcSignClient]);
}, [_reconnectConnector, wcSignClient, isReconnectConnectorReady]);

return null;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/graz/src/provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const GrazProvider: FC<GrazProviderProps> = ({ children, grazOptions, deb
return (
<QueryClientProvider key="graz-provider" client={queryClient} {...props}>
<ClientOnly>
<GrazEvents />
{children}
<GrazEvents />
</ClientOnly>
{debug ? <ReactQueryDevtools initialIsOpen={false} position="bottom-right" /> : null}
</QueryClientProvider>
Expand Down

0 comments on commit 4a174ed

Please sign in to comment.