handle cash-in errors
This commit is contained in:
parent
48dd23c11d
commit
86adfd0a63
7 changed files with 40 additions and 24 deletions
|
|
@ -1,4 +1,5 @@
|
|||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
|
||||
const NAME = 'FakeWallet'
|
||||
|
||||
|
|
@ -18,12 +19,18 @@ function balance (account, cryptoCode) {
|
|||
})
|
||||
}
|
||||
|
||||
function isInsufficient (cryptoCode) {
|
||||
if (cryptoCode === 'BTC') return BN(1e5 * 10)
|
||||
if (cryptoCode === 'ETH') return BN(1e18 * 0.25)
|
||||
throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||
}
|
||||
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
console.log('[%s] DEBUG: Mock wallet sending %s cryptoAtoms to %s',
|
||||
cryptoCode, cryptoAtoms.toString(), toAddress)
|
||||
resolve('<txHash>')
|
||||
if (isInsufficient(cryptoCode)) return reject(new E.InsufficientFundsError())
|
||||
return resolve('<txHash>')
|
||||
}, 2000)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue