Run validation during save

This commit is contained in:
ekzyis 2024-06-21 22:32:06 +02:00
parent a5ea53dc39
commit dd47f2c02b
2 changed files with 7 additions and 18 deletions

View File

@ -39,18 +39,6 @@ export function useWallet (name) {
}
}, [wallet, config, logger])
const validate = useCallback(async (values) => {
try {
// validate should log custom INFO and OK message
// TODO: add timeout
return await wallet.validate({ logger, ...values })
} catch (err) {
const message = err.message || err.toString?.()
logger.error(message)
throw err
}
}, [wallet, logger])
const enable = useCallback(() => {
enableWallet(name, me)
logger.ok('wallet enabled')
@ -61,12 +49,15 @@ export function useWallet (name) {
logger.ok('wallet disabled')
}, [name, me, logger])
const save = useCallback((values) => {
const save = useCallback(async (values) => {
try {
// validate should log custom INFO and OK message
// TODO: add timeout
await wallet.validate({ logger, ...values })
saveConfig(values)
logger.ok('wallet attached')
} catch (err) {
const message = 'failed to attach: ' + err.message || err.toString?.()
const message = err.message || err.toString?.()
logger.error(message)
throw err
}
@ -78,7 +69,7 @@ export function useWallet (name) {
clearConfig()
logger.ok('wallet detached')
} catch (err) {
const message = 'failed to detach: ' + err.message || err.toString?.()
const message = err.message || err.toString?.()
logger.error(message)
throw err
}
@ -87,7 +78,6 @@ export function useWallet (name) {
return {
...wallet,
sendPayment,
validate,
config,
save,
delete: delete_,

View File

@ -34,8 +34,7 @@ export default function WalletSettings () {
onSubmit={async ({ enabled, ...values }) => {
try {
const newConfig = !wallet.isConfigured
await wallet.validate(values)
wallet.save(values)
await wallet.save(values)
// enable wallet if checkbox was set or if wallet was just configured
if (enabled || newConfig) wallet.enable()
else wallet.disable()