Chore: refactor generic wallet and wallet plugins

This commit is contained in:
csrapr 2021-03-16 18:41:44 +00:00 committed by Josh Harvey
parent d2b7224c73
commit b6d91f94bf
11 changed files with 110 additions and 87 deletions

View file

@ -53,12 +53,13 @@ function formatToGetStatus (address, cryptoCode) {
return part2 || part1
}
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
function sendCoins (account, tx, settings, operatorId) {
const { toAddress, cryptoAtoms, cryptoCode } = tx
return checkCryptoCode(cryptoCode)
.then(() => getWallet(account, cryptoCode))
.then(wallet => {
const params = {
address: getLegacyAddress(address, cryptoCode),
address: getLegacyAddress(toAddress, cryptoCode),
amount: cryptoAtoms.toNumber(),
walletPassphrase: account[`${cryptoCode}WalletPassphrase`],
enforceMinConfirmsForChange: false
@ -77,13 +78,13 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
})
}
function balance (account, cryptoCode) {
function balance (account, cryptoCode, settings, operatorId) {
return checkCryptoCode(cryptoCode)
.then(() => getWallet(account, cryptoCode))
.then(wallet => BN(wallet._wallet.spendableBalanceString))
}
function newAddress (account, info) {
function newAddress (account, info, tx, settings, operatorId) {
return checkCryptoCode(info.cryptoCode)
.then(() => getWallet(account, info.cryptoCode))
.then(wallet => {
@ -102,7 +103,8 @@ function newAddress (account, info) {
})
}
function getStatus (account, toAddress, requested, cryptoCode) {
function getStatus (account, tx, requested, settings, operatorId) {
const { toAddress, cryptoCode } = tx
return checkCryptoCode(cryptoCode)
.then(() => getWallet(account, cryptoCode))
.then(wallet => wallet.transfers({
@ -131,7 +133,7 @@ function getStatus (account, toAddress, requested, cryptoCode) {
})
}
function newFunding (account, cryptoCode) {
function newFunding (account, cryptoCode, settings, operatorId) {
return checkCryptoCode(cryptoCode)
.then(() => {
return getWallet(account, cryptoCode)
@ -150,7 +152,7 @@ function newFunding (account, cryptoCode) {
})
}
function cryptoNetwork (account, cryptoCode) {
function cryptoNetwork (account, cryptoCode, settings, operatorId) {
return checkCryptoCode(cryptoCode)
.then(() => account.environment === 'test' ? 'test' : 'main')
}