From c2dad97dc0a86b57d0a72ca184c2bad52cfb3144 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Thu, 28 Dec 2023 22:47:00 +0000 Subject: [PATCH] fix: deprecated graphql galoy usage --- lib/plugins/wallet/galoy/galoy.js | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/lib/plugins/wallet/galoy/galoy.js b/lib/plugins/wallet/galoy/galoy.js index f5422941..e27d5755 100644 --- a/lib/plugins/wallet/galoy/galoy.js +++ b/lib/plugins/wallet/galoy/galoy.js @@ -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]) })