handle cash-in errors

This commit is contained in:
Josh Harvey 2017-04-23 13:44:36 +03:00
parent 48dd23c11d
commit 86adfd0a63
7 changed files with 40 additions and 24 deletions

View file

@ -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)
})
}