Chore: refactor generic wallet and wallet plugins
This commit is contained in:
parent
d2b7224c73
commit
b6d91f94bf
11 changed files with 110 additions and 87 deletions
|
|
@ -17,7 +17,7 @@ function _balance (cryptoCode) {
|
|||
return BN(10).shift(unitScale).round()
|
||||
}
|
||||
|
||||
function balance (account, cryptoCode) {
|
||||
function balance (account, cryptoCode, settings, operatorId) {
|
||||
return Promise.resolve()
|
||||
.then(() => _balance(cryptoCode))
|
||||
}
|
||||
|
|
@ -39,7 +39,8 @@ function isInsufficient (cryptoAtoms, cryptoCode) {
|
|||
return cryptoAtoms.gt(b.div(1000).mul(sendCount))
|
||||
}
|
||||
|
||||
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||
function sendCoins (account, tx, settings, operatorId) {
|
||||
const { toAddress, cryptoAtoms, cryptoCode } = tx
|
||||
sendCount++
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
|
|
@ -56,16 +57,16 @@ function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
|
|||
})
|
||||
}
|
||||
|
||||
function newAddress () {
|
||||
function newAddress (account, info, tx, settings, operatorId) {
|
||||
t0 = Date.now()
|
||||
return Promise.resolve('<Fake address, don\'t send>')
|
||||
}
|
||||
|
||||
function newFunding (account, cryptoCode) {
|
||||
function newFunding (account, cryptoCode, settings, operatorId) {
|
||||
const promises = [
|
||||
pendingBalance(account, cryptoCode),
|
||||
confirmedBalance(account, cryptoCode),
|
||||
newAddress(account, {cryptoCode})
|
||||
newAddress(account, { cryptoCode })
|
||||
]
|
||||
|
||||
return Promise.all(promises)
|
||||
|
|
@ -76,12 +77,13 @@ function newFunding (account, cryptoCode) {
|
|||
}))
|
||||
}
|
||||
|
||||
function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||
function getStatus (account, tx, requested, settings, operatorId) {
|
||||
const { toAddress, cryptoCode } = tx
|
||||
const elapsed = Date.now() - t0
|
||||
|
||||
if (elapsed < PUBLISH_TIME) return Promise.resolve({ receivedCryptoAtoms: BN(0), status: 'notSeen' })
|
||||
if (elapsed < AUTHORIZE_TIME) return Promise.resolve({ receivedCryptoAtoms: cryptoAtoms, status: 'published' })
|
||||
if (elapsed < CONFIRM_TIME) return Promise.resolve({ receivedCryptoAtoms: cryptoAtoms, status: 'authorized' })
|
||||
if (elapsed < AUTHORIZE_TIME) return Promise.resolve({ receivedCryptoAtoms: requested, status: 'published' })
|
||||
if (elapsed < CONFIRM_TIME) return Promise.resolve({ receivedCryptoAtoms: requested, status: 'authorized' })
|
||||
|
||||
console.log('[%s] DEBUG: Mock wallet has confirmed transaction [%s]', cryptoCode, toAddress.slice(0, 5))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue