improve cash-in error handling
This commit is contained in:
parent
86adfd0a63
commit
84a93599f5
9 changed files with 263 additions and 47 deletions
|
|
@ -19,17 +19,27 @@ function balance (account, cryptoCode) {
|
|||
})
|
||||
}
|
||||
|
||||
function isInsufficient (cryptoCode) {
|
||||
if (cryptoCode === 'BTC') return BN(1e5 * 10)
|
||||
if (cryptoCode === 'ETH') return BN(1e18 * 0.25)
|
||||
// Note: This makes it easier to test insufficient funds errors
|
||||
let sendCount = 0
|
||||
|
||||
function isInsufficient (cryptoAtoms, cryptoCode) {
|
||||
if (cryptoCode === 'BTC') return cryptoAtoms.gt(1e5 * 10 * sendCount)
|
||||
if (cryptoCode === 'ETH') return cryptoAtoms.gt(1e18 * 0.25 * sendCount)
|
||||
throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||
}
|
||||
|
||||
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||
sendCount++
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
if (isInsufficient(cryptoAtoms, cryptoCode)) {
|
||||
console.log('[%s] DEBUG: Mock wallet insufficient funds: %s',
|
||||
cryptoCode, cryptoAtoms.toString())
|
||||
return reject(new E.InsufficientFundsError())
|
||||
}
|
||||
|
||||
console.log('[%s] DEBUG: Mock wallet sending %s cryptoAtoms to %s',
|
||||
cryptoCode, cryptoAtoms.toString(), toAddress)
|
||||
if (isInsufficient(cryptoCode)) return reject(new E.InsufficientFundsError())
|
||||
return resolve('<txHash>')
|
||||
}, 2000)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue