diff --git a/components/wallet/index.js b/components/wallet/index.js index 2af01989..ad748c59 100644 --- a/components/wallet/index.js +++ b/components/wallet/index.js @@ -59,13 +59,36 @@ export function useWallet (name) { logger.ok('wallet disabled') }, [name, me, logger]) + const save = useCallback((values) => { + try { + saveConfig(values) + logger.ok('wallet attached') + } catch (err) { + const message = 'failed to attach: ' + err.message || err.toString?.() + logger.error(message) + throw err + } + }, [saveConfig, logger]) + + // delete is a reserved keyword + const delete_ = useCallback(() => { + try { + clearConfig() + logger.ok('wallet detached') + } catch (err) { + const message = 'failed to detach: ' + err.message || err.toString?.() + logger.error(message) + throw err + } + }, [clearConfig, logger]) + return { ...wallet, sendPayment, validate, config, - saveConfig, - clearConfig, + save, + delete: delete_, enable, disable, isConfigured: !!config, diff --git a/pages/settings/wallets/[wallet].js b/pages/settings/wallets/[wallet].js index 0f077415..3a184b31 100644 --- a/pages/settings/wallets/[wallet].js +++ b/pages/settings/wallets/[wallet].js @@ -38,7 +38,7 @@ export default function WalletSettings () { try { const newConfig = !wallet.isConfigured await wallet.validate(values) - wallet.saveConfig(values) + wallet.save(values) // enable wallet if checkbox was set or if wallet was just configured if (enabled || newConfig) wallet.enable() else wallet.disable() @@ -61,13 +61,12 @@ export default function WalletSettings () { { try { - wallet.clearConfig() + wallet.delete() toaster.success('saved settings') router.push('/settings/wallets') } catch (err) { console.error(err) const message = 'failed to detach: ' + err.message || err.toString?.() - wallet.logger.error(message) toaster.danger(message) } }}