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 axios = require('axios')
|
||||||
const NAME = 'LN'
|
const NAME = 'LN'
|
||||||
const SUPPORTED_COINS = ['LN', 'BTC']
|
const SUPPORTED_COINS = ['LN', 'BTC']
|
||||||
const PHONE = '+3500000000000'
|
const TX_PENDING = 'PENDING'
|
||||||
const TEST_AUTH_TOKEN = ''
|
|
||||||
|
|
||||||
const URI = 'https://api.staging.galoy.io/graphql'
|
const URI = 'https://api.staging.galoy.io/graphql'
|
||||||
|
|
||||||
|
|
@ -211,7 +210,7 @@ function sendFundsLN (walletId, invoice, token) {
|
||||||
}
|
}
|
||||||
return request(sendLN, token)
|
return request(sendLN, token)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
return result.data.onChainPaymentSend
|
return result.data.lnInvoicePaymentSend
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err
|
||||||
|
|
@ -330,15 +329,19 @@ function newFunding (account, cryptoCode, settings, operatorId) {
|
||||||
// Has to be a regular BTC address
|
// Has to be a regular BTC address
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
// .then(() => fetchAuthToken({ phone: PHONE }))
|
// .then(() => fetchAuthToken({ phone: PHONE }))
|
||||||
.then(authToken => [getGaloyAccount(authToken), authToken])
|
.then(authToken => Promise.all([getGaloyAccount(authToken), authToken]))
|
||||||
.then(([account, 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)
|
return newOnChainAddress(wallet.id, authToken)
|
||||||
.then(onChainAddress => [onChainAddress, wallet.balance])
|
.then(onChainAddress => [onChainAddress, wallet.balance, pendingBalance])
|
||||||
})
|
})
|
||||||
.then(([onChainAddress, balance]) => {
|
.then(([onChainAddress, balance, pendingBalance]) => {
|
||||||
// Missing pending balance
|
|
||||||
return {
|
return {
|
||||||
|
fundingPendingBalance: new BN(pendingBalance),
|
||||||
fundingConfirmedBalance: new BN(balance),
|
fundingConfirmedBalance: new BN(balance),
|
||||||
fundingAddress: onChainAddress
|
fundingAddress: onChainAddress
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue