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]) }, [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_,

View File

@ -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()