Merge pull request #1640 from RafaelTaranto/fix/galoy-multiple-fixes
chore: use old galoy api
This commit is contained in:
commit
f029018077
3 changed files with 32 additions and 42 deletions
|
|
@ -35,17 +35,15 @@ function checkCryptoCode (cryptoCode) {
|
|||
return Promise.resolve()
|
||||
}
|
||||
|
||||
function getTransactionsByAddress (token, endpoint, address) {
|
||||
function getTransactionsByAddress (token, endpoint, walletId, address) {
|
||||
const accountInfo = {
|
||||
'operationName': 'me',
|
||||
'query': `query me {
|
||||
me {
|
||||
defaultAccount {
|
||||
defaultWalletId
|
||||
wallets {
|
||||
id
|
||||
walletCurrency
|
||||
transactionsByAddress (address: "${address}")
|
||||
transactionsByAddress (address: "${address}") {
|
||||
edges {
|
||||
node {
|
||||
direction
|
||||
|
|
@ -62,33 +60,32 @@ function getTransactionsByAddress (token, endpoint, address) {
|
|||
}
|
||||
return request(accountInfo, token, endpoint)
|
||||
.then(r => {
|
||||
return r.data.me.defaultAccount
|
||||
return _.find(it => it.id === walletId, r.data.me.defaultAccount.wallets).transactionsByAddress
|
||||
})
|
||||
.catch(err => {
|
||||
throw new Error(err)
|
||||
})
|
||||
}
|
||||
|
||||
function getGaloyAccount (token, endpoint, walletId) {
|
||||
function getGaloyWallet (token, endpoint, walletId) {
|
||||
const accountInfo = {
|
||||
'operationName': 'me',
|
||||
'query': `query me($walletId: WalletId!) {
|
||||
'query': `query me {
|
||||
me {
|
||||
defaultAccount {
|
||||
walletById(walletId: $walletId) {
|
||||
wallets {
|
||||
id
|
||||
walletCurrency
|
||||
balance
|
||||
pendingIncomingBalance
|
||||
}
|
||||
}
|
||||
}
|
||||
}`,
|
||||
'variables': { 'walletId': `${walletId}` }
|
||||
'variables': {}
|
||||
}
|
||||
return request(accountInfo, token, endpoint)
|
||||
.then(r => {
|
||||
return r.data.me.defaultAccount
|
||||
return _.find(it => it.id === walletId, r.data.me.defaultAccount.wallets)
|
||||
})
|
||||
.catch(err => {
|
||||
throw new Error(err)
|
||||
|
|
@ -157,9 +154,8 @@ 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, account.walletId))
|
||||
.then(galoyAccount => {
|
||||
const wallet = galoyAccount.walletById
|
||||
.then(() => getGaloyWallet(account.apiSecret, account.endpoint, account.walletId))
|
||||
.then(wallet => {
|
||||
if (isLightning(toAddress)) {
|
||||
return sendFundsLN(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint)
|
||||
}
|
||||
|
|
@ -235,9 +231,8 @@ function newInvoice (walletId, cryptoAtoms, token, endpoint) {
|
|||
|
||||
function balance (account, cryptoCode, settings, operatorId) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
||||
.then(galoyAccount => {
|
||||
const wallet = galoyAccount.walletById
|
||||
.then(() => getGaloyWallet(account.apiSecret, account.endpoint))
|
||||
.then(wallet => {
|
||||
return new BN(wallet.balance || 0)
|
||||
})
|
||||
}
|
||||
|
|
@ -245,9 +240,8 @@ function balance (account, cryptoCode, settings, operatorId) {
|
|||
function newAddress (account, info, tx, settings, operatorId) {
|
||||
const { cryptoAtoms, cryptoCode } = tx
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
||||
.then(galoyAccount => {
|
||||
const wallet = galoyAccount.walletById
|
||||
.then(() => getGaloyWallet(account.apiSecret, account.endpoint))
|
||||
.then(wallet => {
|
||||
const promises = [
|
||||
newOnChainAddress(wallet.id, account.apiSecret, account.endpoint),
|
||||
newInvoice(wallet.id, cryptoAtoms, account.apiSecret, account.endpoint)
|
||||
|
|
@ -275,13 +269,10 @@ function getStatus (account, tx, requested, settings, operatorId) {
|
|||
return { receivedCryptoAtoms: cryptoAtoms, status: 'confirmed' }
|
||||
}
|
||||
// On-chain and intra-ledger transactions
|
||||
return getTransactionsByAddress(account.apiSecret, account.endpoint, address)
|
||||
.then(accountInfo => {
|
||||
const transactions =
|
||||
_.find(wallet => wallet.walletCurrency === externalCryptoCode &&
|
||||
wallet.id === accountInfo.defaultWalletId &&
|
||||
wallet.id === account.walletId)(accountInfo.wallets).transactions.edges
|
||||
const { SUCCESS: confirmed, PENDING: pending } = getBalance(transactions)
|
||||
return getTransactionsByAddress(account.apiSecret, account.endpoint, account.walletId, address)
|
||||
.then(transactions => {
|
||||
const txEdges = transactions.edges
|
||||
const { SUCCESS: confirmed, PENDING: pending } = getBalance(txEdges)
|
||||
if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
|
||||
if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
|
||||
if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
|
||||
|
|
@ -294,15 +285,15 @@ function newFunding (account, cryptoCode, settings, operatorId) {
|
|||
const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
|
||||
// Regular BTC address
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => getGaloyAccount(account.apiSecret, account.endpoint))
|
||||
.then(galoyAccount => {
|
||||
const wallet = galoyAccount.walletById
|
||||
.then(() => getGaloyWallet(account.apiSecret, account.endpoint))
|
||||
.then(wallet => {
|
||||
return newOnChainAddress(wallet.id, account.apiSecret, account.endpoint)
|
||||
.then(onChainAddress => [onChainAddress, wallet.balance, wallet.pendingIncomingBalance])
|
||||
.then(onChainAddress => [onChainAddress, wallet.balance])
|
||||
})
|
||||
.then(([onChainAddress, balance, pendingIncomingBalance]) => {
|
||||
.then(([onChainAddress, balance]) => {
|
||||
return {
|
||||
fundingPendingBalance: new BN(pendingIncomingBalance),
|
||||
// with the old api is not possible to get pending balance
|
||||
fundingPendingBalance: new BN(0),
|
||||
fundingConfirmedBalance: new BN(balance),
|
||||
fundingAddress: onChainAddress
|
||||
}
|
||||
|
|
@ -328,6 +319,5 @@ module.exports = {
|
|||
newFunding,
|
||||
cryptoNetwork,
|
||||
checkBlockchainStatus,
|
||||
sendProbeRequest,
|
||||
probeLN
|
||||
}
|
||||
|
|
|
|||
14
package-lock.json
generated
14
package-lock.json
generated
|
|
@ -4040,9 +4040,9 @@
|
|||
}
|
||||
},
|
||||
"@lamassu/bolt11": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@lamassu/bolt11/-/bolt11-1.5.0.tgz",
|
||||
"integrity": "sha512-zvPbYuWuTJmvlU4nUjYBY/OtLFczHm5v/yNS9PTvFQJGSIQ2/7K3OEwl8FtTnV9KhIojoR7ue6NMSK2VHHqACA==",
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@lamassu/bolt11/-/bolt11-1.5.1.tgz",
|
||||
"integrity": "sha512-uP1FyG2cGUveX4tpcbpfs+px0aty0/cJ0O+v+yro24sSYOUvWT/N89yhZBOo/dOGEW+S3J45vzBoeH/OnK6jgA==",
|
||||
"requires": {
|
||||
"bech32": "^1.1.2",
|
||||
"bitcoinjs-lib": "4.0.3",
|
||||
|
|
@ -4065,11 +4065,11 @@
|
|||
}
|
||||
},
|
||||
"@lamassu/coins": {
|
||||
"version": "1.4.0-beta.4",
|
||||
"resolved": "https://registry.npmjs.org/@lamassu/coins/-/coins-1.4.0-beta.4.tgz",
|
||||
"integrity": "sha512-Tjy3g1FwMJWGNe8pSxSG6ZeETF70ekzTSmNQX/v5BE3l5vsCcmIyug65KU265eyHQT6/IwzUNL8p7NE6VAKakQ==",
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@lamassu/coins/-/coins-1.4.2.tgz",
|
||||
"integrity": "sha512-eMDpKn/PEUVNsQ31ErLnHxObp7Wrab2g5YANnavUlfD5IUnmmlPGBTfYwDLWy9SHB1P46WsZJPncR12EcnrGqA==",
|
||||
"requires": {
|
||||
"@lamassu/bolt11": "1.5.0",
|
||||
"@lamassu/bolt11": "1.5.1",
|
||||
"bech32": "2.0.0",
|
||||
"big-integer": "^1.6.48",
|
||||
"bignumber.js": "^9.0.0",
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
"@ethereumjs/common": "^2.6.4",
|
||||
"@ethereumjs/tx": "^3.5.1",
|
||||
"@graphql-tools/merge": "^6.2.5",
|
||||
"@lamassu/coins": "v1.4.0-beta.4",
|
||||
"@lamassu/coins": "v1.4.2",
|
||||
"@simplewebauthn/server": "^3.0.0",
|
||||
"@vonage/auth": "^1.5.0",
|
||||
"@vonage/sms": "^1.7.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue