Skip to content

Commit

Permalink
Dev metamask (#213)
Browse files Browse the repository at this point in the history
* feat: Support async connect a wallet

* chore: update versions (alpha) (#212)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: Connect is no longer invoked if wallet is connected

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 10, 2024
1 parent 9fa4d24 commit 4f1788b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-trainers-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Connect is no longer invoked if wallet is connected
8 changes: 6 additions & 2 deletions packages/walletkit/src/evm/hooks/useConnectWallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEvmConnect, UseEvmConnectReturnType } from '@/evm/hooks/useEvmConnect';
import { useWalletKit } from '../../core/providers/WalletKitProvider/context';
import { useIsConnected } from './useIsConnected';
import { useRef } from 'react';

type ConnectOptions = Partial<Parameters<UseEvmConnectReturnType['connect']>[0]> & {
walletId: string;
Expand All @@ -10,7 +11,10 @@ export function useConnectWallet() {
const { log, evmConfig } = useWalletKit();

const { connect, connectAsync, connectors } = useEvmConnect();

const isConnected = useIsConnected();
const isConnectedRef = useRef<boolean>(isConnected);
isConnectedRef.current = isConnected;

return {
connect(options: ConnectOptions) {
Expand All @@ -21,7 +25,7 @@ export function useConnectWallet() {
log(`wallet not found, walletId: ${walletId}`);
} else {
const connector = connectors.find((item) => item.id === walletId);
if (connector && wallet.isInstalled() && !isConnected)
if (connector && wallet.isInstalled() && !isConnectedRef.current)
connect({
connector,
...restOptions,
Expand All @@ -37,7 +41,7 @@ export function useConnectWallet() {
log(`wallet not found, walletId: ${walletId}`);
} else {
const connector = connectors.find((item) => item.id === walletId);
if (connector && wallet.isInstalled() && !isConnected)
if (connector && wallet.isInstalled() && !isConnectedRef.current)
await connectAsync({
connector,
...restOptions,
Expand Down

0 comments on commit 4f1788b

Please sign in to comment.