Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only enable wallet when its necessary #672

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { WalletAccount } from '@talismn/connect-wallets'
import { useEffect, useState } from 'react'

export default function useAccountsFromPreferredWallet(
onError?: (err: unknown, preferredWallet: string | undefined) => void
onError?: (err: unknown, preferredWallet: string | undefined) => void,
enabled = true
) {
const preferredWallet = useMyAccount((state) => state.preferredWallet)
const setPreferredWallet = useMyAccount((state) => state.setPreferredWallet)
Expand All @@ -13,7 +14,7 @@ export default function useAccountsFromPreferredWallet(
const isInitialized = useMyAccount.use.isInitialized()

useEffect(() => {
if (!isInitialized) return
if (!isInitialized || !enabled) return

const unsub = enableWallet({
listener: (accounts) => setAccounts(accounts ?? []),
Expand All @@ -25,7 +26,7 @@ export default function useAccountsFromPreferredWallet(
return () => {
unsub.then((unsub) => unsub?.())
}
}, [preferredWallet, onErrorRef, setPreferredWallet, isInitialized])
}, [enabled, preferredWallet, onErrorRef, setPreferredWallet, isInitialized])

return { accounts, isLoading: accounts === null }
}
3 changes: 2 additions & 1 deletion src/providers/ConnectWalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ function ConnectWalletModal({ ...props }: ModalFunctionalityProps) {
description={(err as any)?.message}
/>
))
}
},
props.isOpen
)

const isFound = accounts?.find(
Expand Down
Loading