Fix wallet indicator blink via wallet loading state (#2091)
* Fix wallet indicator blink via wallet loading state * Fix 'attach wallet' button not showing up on page refresh
This commit is contained in:
parent
bc0be4f92a
commit
66d7eef617
@ -1,6 +1,6 @@
|
|||||||
import { useConfiguredWallets } from '@/wallets'
|
import { useConfiguredWallets } from '@/wallets'
|
||||||
|
|
||||||
export function useWalletIndicator () {
|
export function useWalletIndicator () {
|
||||||
const wallets = useConfiguredWallets()
|
const { wallets, loading } = useConfiguredWallets()
|
||||||
return wallets.length === 0
|
return !loading && wallets.length === 0
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import Layout from '@/components/layout'
|
|||||||
import styles from '@/styles/wallet.module.css'
|
import styles from '@/styles/wallet.module.css'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useWallets } from '@/wallets/index'
|
import { useWallets } from '@/wallets/index'
|
||||||
import { useCallback, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
import { useIsClient } from '@/components/use-client'
|
import { useIsClient } from '@/components/use-client'
|
||||||
import WalletCard from '@/components/wallet-card'
|
import WalletCard from '@/components/wallet-card'
|
||||||
import { useToast } from '@/components/toast'
|
import { useToast } from '@/components/toast'
|
||||||
@ -87,6 +87,7 @@ export default function Wallet ({ ssrData }) {
|
|||||||
|
|
||||||
const indicator = useWalletIndicator()
|
const indicator = useWalletIndicator()
|
||||||
const [showWallets, setShowWallets] = useState(!indicator)
|
const [showWallets, setShowWallets] = useState(!indicator)
|
||||||
|
useEffect(() => { setShowWallets(!indicator) }, [indicator])
|
||||||
|
|
||||||
if (indicator && !showWallets) {
|
if (indicator && !showWallets) {
|
||||||
return (
|
return (
|
||||||
|
@ -67,6 +67,7 @@ export function WalletsProvider ({ children }) {
|
|||||||
const [setWalletPriority] = useMutation(SET_WALLET_PRIORITY)
|
const [setWalletPriority] = useMutation(SET_WALLET_PRIORITY)
|
||||||
const [serverWallets, setServerWallets] = useState([])
|
const [serverWallets, setServerWallets] = useState([])
|
||||||
const client = useApolloClient()
|
const client = useApolloClient()
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
|
||||||
const { data, refetch } = useQuery(WALLETS,
|
const { data, refetch } = useQuery(WALLETS,
|
||||||
SSR ? {} : { nextFetchPolicy: 'cache-and-network' })
|
SSR ? {} : { nextFetchPolicy: 'cache-and-network' })
|
||||||
@ -102,6 +103,7 @@ export function WalletsProvider ({ children }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setServerWallets(wallets)
|
setServerWallets(wallets)
|
||||||
|
setLoading(false)
|
||||||
}
|
}
|
||||||
loadWallets()
|
loadWallets()
|
||||||
}, [data?.wallets, decrypt, isActive])
|
}, [data?.wallets, decrypt, isActive])
|
||||||
@ -198,12 +200,13 @@ export function WalletsProvider ({ children }) {
|
|||||||
// and a function to set priorities
|
// and a function to set priorities
|
||||||
const value = useMemo(() => ({
|
const value = useMemo(() => ({
|
||||||
wallets,
|
wallets,
|
||||||
|
loading,
|
||||||
reloadLocalWallets,
|
reloadLocalWallets,
|
||||||
setPriorities,
|
setPriorities,
|
||||||
onVaultKeySet: syncLocalWallets,
|
onVaultKeySet: syncLocalWallets,
|
||||||
beforeDisconnectVault: unsyncLocalWallets,
|
beforeDisconnectVault: unsyncLocalWallets,
|
||||||
removeLocalWallets
|
removeLocalWallets
|
||||||
}), [wallets, reloadLocalWallets, setPriorities, syncLocalWallets, unsyncLocalWallets, removeLocalWallets])
|
}), [wallets, loading, reloadLocalWallets, setPriorities, syncLocalWallets, unsyncLocalWallets, removeLocalWallets])
|
||||||
return (
|
return (
|
||||||
<WalletsContext.Provider value={value}>
|
<WalletsContext.Provider value={value}>
|
||||||
<RetryHandler>
|
<RetryHandler>
|
||||||
@ -223,8 +226,11 @@ export function useWallet (name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useConfiguredWallets () {
|
export function useConfiguredWallets () {
|
||||||
const { wallets } = useWallets()
|
const { wallets, loading } = useWallets()
|
||||||
return useMemo(() => wallets.filter(w => isConfigured(w)), [wallets])
|
return useMemo(() => ({
|
||||||
|
wallets: wallets.filter(w => isConfigured(w)),
|
||||||
|
loading
|
||||||
|
}), [wallets, loading])
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSendWallets () {
|
export function useSendWallets () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user