Fix isConfigured

This commit is contained in:
ekzyis 2024-07-03 04:21:20 +02:00
parent 1f98a1a891
commit 3b0605a691
2 changed files with 20 additions and 2 deletions

View File

@ -4,12 +4,19 @@ import Plug from '@/svgs/plug.svg'
import Gear from '@/svgs/settings-5-fill.svg' import Gear from '@/svgs/settings-5-fill.svg'
import Link from 'next/link' import Link from 'next/link'
import { useWallet, Status } from './wallet' import { useWallet, Status } from './wallet'
import { useEffect, useState } from 'react'
export function WalletCard ({ name, title, badges, status }) { export function WalletCard ({ name, title, badges, status }) {
const wallet = useWallet(name) const wallet = useWallet(name)
const [mounted, setMounted] = useState(false)
useEffect(() => {
// fix mismatched className props during hydration
setMounted(true)
}, [])
let indicator = styles.disabled let indicator = styles.disabled
switch (wallet.status) { switch (mounted && wallet.status) {
case Status.Enabled: case Status.Enabled:
case true: case true:
indicator = styles.success indicator = styles.success

View File

@ -89,7 +89,7 @@ export function useWallet (name) {
delete: delete_, delete: delete_,
enable, enable,
disable, disable,
isConfigured: !!config, isConfigured: isConfigured({ ...wallet, config }),
status: config?.enabled || config?.priority ? Status.Enabled : Status.Initialized, status: config?.enabled || config?.priority ? Status.Enabled : Status.Initialized,
logger logger
} }
@ -122,6 +122,17 @@ function useConfig (wallet) {
return [config, saveConfig, clearConfig] return [config, saveConfig, clearConfig]
} }
function isConfigured (wallet) {
if (!wallet.config) return false
// a wallet is configured if all of it's required fields are set
const val = wallet.fields.every(field => {
return field.optional ? true : !!wallet.config?.[field.name]
})
return val
}
function useServerConfig (wallet) { function useServerConfig (wallet) {
const client = useApolloClient() const client = useApolloClient()
const me = useMe() const me = useMe()