Run validation during save
This commit is contained in:
parent
a5ea53dc39
commit
dd47f2c02b
|
@ -39,18 +39,6 @@ export function useWallet (name) {
|
||||||
}
|
}
|
||||||
}, [wallet, config, logger])
|
}, [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(() => {
|
const enable = useCallback(() => {
|
||||||
enableWallet(name, me)
|
enableWallet(name, me)
|
||||||
logger.ok('wallet enabled')
|
logger.ok('wallet enabled')
|
||||||
|
@ -61,12 +49,15 @@ export function useWallet (name) {
|
||||||
logger.ok('wallet disabled')
|
logger.ok('wallet disabled')
|
||||||
}, [name, me, logger])
|
}, [name, me, logger])
|
||||||
|
|
||||||
const save = useCallback((values) => {
|
const save = useCallback(async (values) => {
|
||||||
try {
|
try {
|
||||||
|
// validate should log custom INFO and OK message
|
||||||
|
// TODO: add timeout
|
||||||
|
await wallet.validate({ logger, ...values })
|
||||||
saveConfig(values)
|
saveConfig(values)
|
||||||
logger.ok('wallet attached')
|
logger.ok('wallet attached')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = 'failed to attach: ' + err.message || err.toString?.()
|
const message = err.message || err.toString?.()
|
||||||
logger.error(message)
|
logger.error(message)
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
|
@ -78,7 +69,7 @@ export function useWallet (name) {
|
||||||
clearConfig()
|
clearConfig()
|
||||||
logger.ok('wallet detached')
|
logger.ok('wallet detached')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = 'failed to detach: ' + err.message || err.toString?.()
|
const message = err.message || err.toString?.()
|
||||||
logger.error(message)
|
logger.error(message)
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
|
@ -87,7 +78,6 @@ export function useWallet (name) {
|
||||||
return {
|
return {
|
||||||
...wallet,
|
...wallet,
|
||||||
sendPayment,
|
sendPayment,
|
||||||
validate,
|
|
||||||
config,
|
config,
|
||||||
save,
|
save,
|
||||||
delete: delete_,
|
delete: delete_,
|
||||||
|
|
|
@ -34,8 +34,7 @@ export default function WalletSettings () {
|
||||||
onSubmit={async ({ enabled, ...values }) => {
|
onSubmit={async ({ enabled, ...values }) => {
|
||||||
try {
|
try {
|
||||||
const newConfig = !wallet.isConfigured
|
const newConfig = !wallet.isConfigured
|
||||||
await wallet.validate(values)
|
await wallet.save(values)
|
||||||
wallet.save(values)
|
|
||||||
// enable wallet if checkbox was set or if wallet was just configured
|
// enable wallet if checkbox was set or if wallet was just configured
|
||||||
if (enabled || newConfig) wallet.enable()
|
if (enabled || newConfig) wallet.enable()
|
||||||
else wallet.disable()
|
else wallet.disable()
|
||||||
|
|
Loading…
Reference in New Issue