From d854f0580e9c80c32a6bcb6074f79bf107ebfa88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Sun, 10 Apr 2022 17:07:20 +0100 Subject: [PATCH] fix: improve error handling and funding UX --- lib/plugins/wallet/bitcoind/bitcoind.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/plugins/wallet/bitcoind/bitcoind.js b/lib/plugins/wallet/bitcoind/bitcoind.js index fa22b750..66fb6ed6 100644 --- a/lib/plugins/wallet/bitcoind/bitcoind.js +++ b/lib/plugins/wallet/bitcoind/bitcoind.js @@ -28,6 +28,9 @@ function errorHandle (e) { throw new E.InsufficientFundsError() case -18: return createWallet() + case -35: + // Wallet is already loaded, just return + return default: throw e } @@ -35,16 +38,19 @@ function errorHandle (e) { function checkCryptoCode (cryptoCode) { if (cryptoCode !== 'BTC') return Promise.reject(new Error('Unsupported crypto: ' + cryptoCode)) - return Promise.resolve() + return Promise.resolve().then(loadWallet) } function createWallet () { return fetch('createwallet', ['wallet']) - .catch(errorHandle) + .then(loadWallet) } function loadWallet () { return fetch('loadwallet', ['wallet', true]) + // Catching the error here to suppress error code -35 + // This improves UX on the initial wallet load and serves as error sink + // for wallet creation/loading related issues before actual business logic runs .catch(errorHandle) }