feat: calculate pending balance
This commit is contained in:
parent
dd55cda986
commit
09cb924106
1 changed files with 11 additions and 8 deletions
|
|
@ -4,8 +4,7 @@ const _ = require('lodash/fp')
|
|||
const axios = require('axios')
|
||||
const NAME = 'LN'
|
||||
const SUPPORTED_COINS = ['LN', 'BTC']
|
||||
const PHONE = '+3500000000000'
|
||||
const TEST_AUTH_TOKEN = ''
|
||||
const TX_PENDING = 'PENDING'
|
||||
|
||||
const URI = 'https://api.staging.galoy.io/graphql'
|
||||
|
||||
|
|
@ -211,7 +210,7 @@ function sendFundsLN (walletId, invoice, token) {
|
|||
}
|
||||
return request(sendLN, token)
|
||||
.then(result => {
|
||||
return result.data.onChainPaymentSend
|
||||
return result.data.lnInvoicePaymentSend
|
||||
})
|
||||
.catch(err => {
|
||||
throw err
|
||||
|
|
@ -330,15 +329,19 @@ function newFunding (account, cryptoCode, settings, operatorId) {
|
|||
// Has to be a regular BTC address
|
||||
return checkCryptoCode(cryptoCode)
|
||||
// .then(() => fetchAuthToken({ phone: PHONE }))
|
||||
.then(authToken => [getGaloyAccount(authToken), authToken])
|
||||
.then(authToken => Promise.all([getGaloyAccount(authToken), authToken]))
|
||||
.then(([account, authToken]) => {
|
||||
const wallet = _.filter(wallet => wallet.walletCurrency === cryptoCode && wallet.id === account.defaultWalletId)(account.wallets)
|
||||
const wallet = _.head(_.filter(wallet => wallet.walletCurrency === cryptoCode && wallet.id === account.defaultWalletId)(account.wallets))
|
||||
const pendingBalance = _.sumBy(tx => {
|
||||
if (tx.node.status === TX_PENDING) return tx.node.settlementAmount
|
||||
return 0
|
||||
})(wallet.transactions.edges)
|
||||
return newOnChainAddress(wallet.id, authToken)
|
||||
.then(onChainAddress => [onChainAddress, wallet.balance])
|
||||
.then(onChainAddress => [onChainAddress, wallet.balance, pendingBalance])
|
||||
})
|
||||
.then(([onChainAddress, balance]) => {
|
||||
// Missing pending balance
|
||||
.then(([onChainAddress, balance, pendingBalance]) => {
|
||||
return {
|
||||
fundingPendingBalance: new BN(pendingBalance),
|
||||
fundingConfirmedBalance: new BN(balance),
|
||||
fundingAddress: onChainAddress
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue