Merge pull request #1634 from RafaelTaranto/fix/bad-graphql-usage-galoy
fix: deprecated graphql galoy usage
This commit is contained in:
commit
b76f9fa44c
1 changed files with 9 additions and 22 deletions
|
|
@ -69,14 +69,13 @@ function getTransactionsByAddress (token, endpoint, address) {
|
|||
})
|
||||
}
|
||||
|
||||
function getGaloyAccount (token, endpoint) {
|
||||
function getGaloyAccount (token, endpoint, walletId) {
|
||||
const accountInfo = {
|
||||
'operationName': 'me',
|
||||
'query': `query me {
|
||||
'query': `query me($walletId: WalletId!) {
|
||||
me {
|
||||
defaultAccount {
|
||||
defaultWalletId
|
||||
wallets {
|
||||
walletById(walletId: $walletId) {
|
||||
id
|
||||
walletCurrency
|
||||
balance
|
||||
|
|
@ -85,7 +84,7 @@ function getGaloyAccount (token, endpoint) {
|
|||
}
|
||||
}
|
||||
}`,
|
||||
'variables': {}
|
||||
'variables': { 'walletId': `${walletId}` }
|
||||
}
|
||||
return request(accountInfo, token, endpoint)
|
||||
.then(r => {
|
||||
|
|
@ -158,11 +157,9 @@ function sendCoins (account, tx, settings, operatorId) {
|
|||
const { toAddress, cryptoAtoms, cryptoCode } = tx
|
||||
const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint, account.walletId))
|
||||
.then(galoyAccount => {
|
||||
const wallet = _.find(wallet => wallet.walletCurrency === externalCryptoCode &&
|
||||
wallet.id === galoyAccount.defaultWalletId &&
|
||||
wallet.id === account.walletId)(galoyAccount.wallets)
|
||||
const wallet = galoyAccount.walletById
|
||||
if (isLightning(toAddress)) {
|
||||
return sendFundsLN(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint)
|
||||
}
|
||||
|
|
@ -237,28 +234,20 @@ function newInvoice (walletId, cryptoAtoms, token, endpoint) {
|
|||
}
|
||||
|
||||
function balance (account, cryptoCode, settings, operatorId) {
|
||||
const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
||||
.then(galoyAccount => {
|
||||
// account has a list of wallets, should we consider the balance of each one?
|
||||
// for now we'll get the first BTC wallet that matches the defaultWalletId
|
||||
const wallet = _.find(wallet => wallet.walletCurrency === externalCryptoCode &&
|
||||
wallet.id === galoyAccount.defaultWalletId &&
|
||||
wallet.id === account.walletId)(galoyAccount.wallets)
|
||||
const wallet = galoyAccount.walletByid
|
||||
return new BN(wallet.balance || 0)
|
||||
})
|
||||
}
|
||||
|
||||
function newAddress (account, info, tx, settings, operatorId) {
|
||||
const { cryptoAtoms, cryptoCode } = tx
|
||||
const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
||||
.then(galoyAccount => {
|
||||
const wallet = _.find(wallet => wallet.walletCurrency === externalCryptoCode &&
|
||||
wallet.id === galoyAccount.defaultWalletId &&
|
||||
wallet.id === account.walletId)(galoyAccount.wallets)
|
||||
const wallet = galoyAccount.walletById
|
||||
const promises = [
|
||||
newOnChainAddress(wallet.id, account.apiSecret, account.endpoint),
|
||||
newInvoice(wallet.id, cryptoAtoms, account.apiSecret, account.endpoint)
|
||||
|
|
@ -307,9 +296,7 @@ function newFunding (account, cryptoCode, settings, operatorId) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
||||
.then(galoyAccount => {
|
||||
const wallet = _.find(wallet => wallet.walletCurrency === externalCryptoCode &&
|
||||
wallet.id === galoyAccount.defaultWalletId &&
|
||||
wallet.id === account.walletId)(galoyAccount.wallets)
|
||||
const wallet = galoyAccount.walletById
|
||||
return newOnChainAddress(wallet.id, account.apiSecret, account.endpoint)
|
||||
.then(onChainAddress => [onChainAddress, wallet.balance, wallet.pendingIncomingBalance])
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue