fix: improve error handling and funding UX
This commit is contained in:
parent
0a591658aa
commit
d854f0580e
1 changed files with 8 additions and 2 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue