From dd47f2c02b5601375e4bd8ac28da67dd25c22613 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Fri, 21 Jun 2024 22:32:06 +0200 Subject: [PATCH] Run validation during save --- components/wallet/index.js | 22 ++++++---------------- pages/settings/wallets/[wallet].js | 3 +-- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/components/wallet/index.js b/components/wallet/index.js index 7a9bb3f9..0965d7a2 100644 --- a/components/wallet/index.js +++ b/components/wallet/index.js @@ -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_, diff --git a/pages/settings/wallets/[wallet].js b/pages/settings/wallets/[wallet].js index d803abc3..5007ae57 100644 --- a/pages/settings/wallets/[wallet].js +++ b/pages/settings/wallets/[wallet].js @@ -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()