Migrate bitgo api to v2
This commit is contained in:
parent
e7bb29341d
commit
01153d0562
3 changed files with 1191 additions and 465 deletions
|
|
@ -16,7 +16,9 @@ function buildBitgo (account) {
|
|||
|
||||
function getWallet (account) {
|
||||
const bitgo = buildBitgo(account)
|
||||
return bitgo.wallets().get({ id: account.walletId })
|
||||
const coin = account.environment === 'test' ? 'tbtc' : 'btc'
|
||||
|
||||
return bitgo.coin(coin).wallets().get({ id: account.walletId })
|
||||
}
|
||||
|
||||
function checkCryptoCode (cryptoCode) {
|
||||
|
|
@ -36,13 +38,13 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
|||
amount: cryptoAtoms.toNumber(),
|
||||
walletPassphrase: account.walletPassphrase
|
||||
}
|
||||
return wallet.sendCoins(params)
|
||||
return wallet.send(params)
|
||||
})
|
||||
.then(result => {
|
||||
return result.hash
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.message === 'Insufficient funds') throw new E.InsufficientFundsError()
|
||||
if (err.message === 'insufficient funds') throw new E.InsufficientFundsError()
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
|
@ -50,7 +52,8 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
|||
function balance (account, cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => getWallet(account))
|
||||
.then(wallet => BN(wallet.wallet.spendableConfirmedBalance))
|
||||
// TODO This was previously spendableConfirmedBalance, what happened to it on v2?
|
||||
.then(wallet => BN(wallet._wallet.confirmedBalanceString))
|
||||
}
|
||||
|
||||
function newAddress (account, info) {
|
||||
|
|
@ -63,7 +66,7 @@ function newAddress (account, info) {
|
|||
|
||||
// If a label was provided, set the label
|
||||
if (info.label) {
|
||||
return wallet.setLabel({ address: address, label: info.label })
|
||||
return wallet.updateAddress({ address: address, label: info.label })
|
||||
.then(() => address)
|
||||
}
|
||||
|
||||
|
|
@ -92,10 +95,10 @@ function newFunding (account, cryptoCode) {
|
|||
return wallet.createAddress()
|
||||
.then(result => {
|
||||
const fundingAddress = result.address
|
||||
return wallet.setLabel({address: fundingAddress, label: 'Funding Address'})
|
||||
return wallet.updateAddress({address: fundingAddress, label: 'Funding Address'})
|
||||
.then(() => ({
|
||||
fundingPendingBalance: BN(wallet.wallet.balance),
|
||||
fundingConfirmedBalance: BN(wallet.wallet.confirmedBalance),
|
||||
fundingPendingBalance: BN(wallet._wallet.balanceString),
|
||||
fundingConfirmedBalance: BN(wallet._wallet.confirmedBalanceString),
|
||||
fundingAddress
|
||||
}))
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue