fix: deprecated graphql galoy usage
This commit is contained in:
parent
ce0a51904d
commit
c2dad97dc0
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 = {
|
const accountInfo = {
|
||||||
'operationName': 'me',
|
'operationName': 'me',
|
||||||
'query': `query me {
|
'query': `query me($walletId: WalletId!) {
|
||||||
me {
|
me {
|
||||||
defaultAccount {
|
defaultAccount {
|
||||||
defaultWalletId
|
walletById(walletId: $walletId) {
|
||||||
wallets {
|
|
||||||
id
|
id
|
||||||
walletCurrency
|
walletCurrency
|
||||||
balance
|
balance
|
||||||
|
|
@ -85,7 +84,7 @@ function getGaloyAccount (token, endpoint) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
'variables': {}
|
'variables': { 'walletId': `${walletId}` }
|
||||||
}
|
}
|
||||||
return request(accountInfo, token, endpoint)
|
return request(accountInfo, token, endpoint)
|
||||||
.then(r => {
|
.then(r => {
|
||||||
|
|
@ -158,11 +157,9 @@ function sendCoins (account, tx, settings, operatorId) {
|
||||||
const { toAddress, cryptoAtoms, cryptoCode } = tx
|
const { toAddress, cryptoAtoms, cryptoCode } = tx
|
||||||
const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
|
const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
.then(() => getGaloyAccount(account.apiSecret, account.endpoint, account.walletId))
|
||||||
.then(galoyAccount => {
|
.then(galoyAccount => {
|
||||||
const wallet = _.find(wallet => wallet.walletCurrency === externalCryptoCode &&
|
const wallet = galoyAccount.walletById
|
||||||
wallet.id === galoyAccount.defaultWalletId &&
|
|
||||||
wallet.id === account.walletId)(galoyAccount.wallets)
|
|
||||||
if (isLightning(toAddress)) {
|
if (isLightning(toAddress)) {
|
||||||
return sendFundsLN(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint)
|
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) {
|
function balance (account, cryptoCode, settings, operatorId) {
|
||||||
const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
|
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
||||||
.then(galoyAccount => {
|
.then(galoyAccount => {
|
||||||
// account has a list of wallets, should we consider the balance of each one?
|
const wallet = galoyAccount.walletByid
|
||||||
// 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)
|
|
||||||
return new BN(wallet.balance || 0)
|
return new BN(wallet.balance || 0)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function newAddress (account, info, tx, settings, operatorId) {
|
function newAddress (account, info, tx, settings, operatorId) {
|
||||||
const { cryptoAtoms, cryptoCode } = tx
|
const { cryptoAtoms, cryptoCode } = tx
|
||||||
const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
|
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
||||||
.then(galoyAccount => {
|
.then(galoyAccount => {
|
||||||
const wallet = _.find(wallet => wallet.walletCurrency === externalCryptoCode &&
|
const wallet = galoyAccount.walletById
|
||||||
wallet.id === galoyAccount.defaultWalletId &&
|
|
||||||
wallet.id === account.walletId)(galoyAccount.wallets)
|
|
||||||
const promises = [
|
const promises = [
|
||||||
newOnChainAddress(wallet.id, account.apiSecret, account.endpoint),
|
newOnChainAddress(wallet.id, account.apiSecret, account.endpoint),
|
||||||
newInvoice(wallet.id, cryptoAtoms, 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)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
||||||
.then(galoyAccount => {
|
.then(galoyAccount => {
|
||||||
const wallet = _.find(wallet => wallet.walletCurrency === externalCryptoCode &&
|
const wallet = galoyAccount.walletById
|
||||||
wallet.id === galoyAccount.defaultWalletId &&
|
|
||||||
wallet.id === account.walletId)(galoyAccount.wallets)
|
|
||||||
return newOnChainAddress(wallet.id, account.apiSecret, account.endpoint)
|
return newOnChainAddress(wallet.id, account.apiSecret, account.endpoint)
|
||||||
.then(onChainAddress => [onChainAddress, wallet.balance, wallet.pendingIncomingBalance])
|
.then(onChainAddress => [onChainAddress, wallet.balance, wallet.pendingIncomingBalance])
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue