feat: add galoy config and UI safeguards
This commit is contained in:
parent
12ef86ebbf
commit
f870b9f563
2 changed files with 0 additions and 145 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
const invoice = require('@node-lightning/invoice')
|
const invoice = require('@node-lightning/invoice')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
|
|
@ -29,9 +28,6 @@ function request (graphqlQuery, token) {
|
||||||
if (r.error) throw r.error
|
if (r.error) throw r.error
|
||||||
return r.data
|
return r.data
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
throw new Error(err)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCryptoCode (cryptoCode) {
|
function checkCryptoCode (cryptoCode) {
|
||||||
|
|
@ -104,9 +100,6 @@ function getGaloyAccount (token) {
|
||||||
.then(r => {
|
.then(r => {
|
||||||
return r.data.me.defaultAccount
|
return r.data.me.defaultAccount
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
throw new Error(err)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLightning (address) {
|
function isLightning (address) {
|
||||||
|
|
@ -131,9 +124,6 @@ function sendFundsOnChain (walletId, address, cryptoAtoms, token) {
|
||||||
.then(result => {
|
.then(result => {
|
||||||
return result.data.onChainPaymentSend
|
return result.data.onChainPaymentSend
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
throw err
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendFundsLN (walletId, invoice, token) {
|
function sendFundsLN (walletId, invoice, token) {
|
||||||
|
|
@ -154,9 +144,6 @@ function sendFundsLN (walletId, invoice, token) {
|
||||||
.then(result => {
|
.then(result => {
|
||||||
return result.data.lnInvoicePaymentSend
|
return result.data.lnInvoicePaymentSend
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
throw err
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendCoins (account, tx, settings, operatorId) {
|
function sendCoins (account, tx, settings, operatorId) {
|
||||||
|
|
@ -180,9 +167,6 @@ function sendCoins (account, tx, settings, operatorId) {
|
||||||
return '<galoy transaction>'
|
return '<galoy transaction>'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
throw err
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function newOnChainAddress (walletId, token) {
|
function newOnChainAddress (walletId, token) {
|
||||||
|
|
@ -203,9 +187,6 @@ function newOnChainAddress (walletId, token) {
|
||||||
.then(result => {
|
.then(result => {
|
||||||
return result.data.onChainAddressCreate.address
|
return result.data.onChainAddressCreate.address
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
throw err
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function newInvoice (walletId, cryptoAtoms, token) {
|
function newInvoice (walletId, cryptoAtoms, token) {
|
||||||
|
|
@ -228,9 +209,6 @@ function newInvoice (walletId, cryptoAtoms, token) {
|
||||||
.then(result => {
|
.then(result => {
|
||||||
return result.data.lnInvoiceCreate.invoice.paymentRequest
|
return result.data.lnInvoiceCreate.invoice.paymentRequest
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
throw err
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function balance (account, cryptoCode, settings, operatorId) {
|
function balance (account, cryptoCode, settings, operatorId) {
|
||||||
|
|
@ -240,12 +218,8 @@ function balance (account, cryptoCode, settings, operatorId) {
|
||||||
// account has a list of wallets, should we consider the balance of each one?
|
// 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
|
// for now we'll get the first BTC wallet that matches the defaultWalletId
|
||||||
const wallet = _.head(_.filter(wallet => wallet.walletCurrency === cryptoCode && wallet.id === galoyAccount.defaultWalletId)(galoyAccount.wallets))
|
const wallet = _.head(_.filter(wallet => wallet.walletCurrency === cryptoCode && wallet.id === galoyAccount.defaultWalletId)(galoyAccount.wallets))
|
||||||
console.log(wallet)
|
|
||||||
return new BN(wallet.balance || 0)
|
return new BN(wallet.balance || 0)
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
throw err
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function newAddress (account, info, tx, settings, operatorId) {
|
function newAddress (account, info, tx, settings, operatorId) {
|
||||||
|
|
@ -320,64 +294,6 @@ function checkBlockchainStatus (cryptoCode) {
|
||||||
.then(() => Promise.resolve('ready'))
|
.then(() => Promise.resolve('ready'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// function fetchAuthToken (config) {
|
|
||||||
// const phone = config.phone
|
|
||||||
// // userRequestAuthCode deprecated?
|
|
||||||
// const regularRequestAuthCode = {
|
|
||||||
// 'operationName': 'userRequestAuthCode',
|
|
||||||
// 'query': `mutation userRequestAuthCode($input: UserRequestAuthCodeInput!) {
|
|
||||||
// userRequestAuthCode(input: $input) {
|
|
||||||
// errors {
|
|
||||||
// message
|
|
||||||
// path
|
|
||||||
// }
|
|
||||||
// success
|
|
||||||
// }
|
|
||||||
// }`,
|
|
||||||
// 'variables': { 'input': { 'phone': `${phone}` } }
|
|
||||||
// }
|
|
||||||
// const createCaptcha = {
|
|
||||||
// 'operationName': 'captchaCreateChallenge',
|
|
||||||
// 'query': `mutation captchaCreateChallenge {
|
|
||||||
// captchaCreateChallenge {
|
|
||||||
// errors {
|
|
||||||
// message
|
|
||||||
// path
|
|
||||||
// }
|
|
||||||
// result {
|
|
||||||
// challengeCode
|
|
||||||
// id
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }`,
|
|
||||||
// 'variables': {}
|
|
||||||
// }
|
|
||||||
// const captchaRequestAuthCode = code => ({
|
|
||||||
// 'operationName': 'captchaRequestAuthCode',
|
|
||||||
// 'query': `mutation captchaRequestAuthCode($input: CaptchaRequestAuthCodeInput!) {
|
|
||||||
// captchaRequestAuthCode(input: $input) {
|
|
||||||
// errors {
|
|
||||||
// message
|
|
||||||
// path
|
|
||||||
// }
|
|
||||||
// success
|
|
||||||
// }
|
|
||||||
// }`,
|
|
||||||
// 'variables': { 'input': { 'phone': `${phone}`, 'challengeCode': `${code.challengeCode}`, 'secCode': `${code.challengeCode.slice(0, 5)}`, 'validationCode': `${code.challengeCode.slice(0, 5)}` } }
|
|
||||||
// })
|
|
||||||
// return request(createCaptcha)
|
|
||||||
// .then(r => {
|
|
||||||
// const code = r.data.captchaCreateChallenge.result
|
|
||||||
// if (code) {
|
|
||||||
// // captchaRequestAuthCode parameters have to be processed by geetest
|
|
||||||
// return request(captchaRequestAuthCode(code))
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .catch(err => {
|
|
||||||
// throw new Error(err)
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
NAME,
|
NAME,
|
||||||
balance,
|
balance,
|
||||||
|
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
const BN = require('../../../bn')
|
|
||||||
|
|
||||||
const NAME = 'LN'
|
|
||||||
const SUPPORTED_COINS = ['BTC']
|
|
||||||
|
|
||||||
function checkCryptoCode (cryptoCode) {
|
|
||||||
if (!SUPPORTED_COINS.includes(cryptoCode)) {
|
|
||||||
return Promise.reject(new Error('Unsupported crypto: ' + cryptoCode))
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
|
|
||||||
function getWallet () {
|
|
||||||
// Create wallet instance
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendCoins (account, tx, settings, operatorId) {
|
|
||||||
// const { toAddress, cryptoAtoms, cryptoCode } = tx
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
|
|
||||||
function balance (account, cryptoCode, settings, operatorId) {
|
|
||||||
return checkCryptoCode(cryptoCode)
|
|
||||||
.then(() => getWallet(account, cryptoCode))
|
|
||||||
.then(wallet => new BN(wallet._wallet.spendableBalanceString))
|
|
||||||
}
|
|
||||||
|
|
||||||
function newAddress (account, info, tx, settings, operatorId) {
|
|
||||||
return checkCryptoCode(info.cryptoCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStatus (account, tx, requested, settings, operatorId) {
|
|
||||||
const { cryptoCode } = tx
|
|
||||||
return checkCryptoCode(cryptoCode).then(() => {})
|
|
||||||
}
|
|
||||||
|
|
||||||
function newFunding (account, cryptoCode, settings, operatorId) {
|
|
||||||
return checkCryptoCode(cryptoCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
function cryptoNetwork (account, cryptoCode, settings, operatorId) {
|
|
||||||
return checkCryptoCode(cryptoCode)
|
|
||||||
.then(() => account.environment === 'test' ? 'test' : 'main')
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkBlockchainStatus (cryptoCode) {
|
|
||||||
return checkCryptoCode(cryptoCode)
|
|
||||||
.then(() => Promise.resolve('ready'))
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
NAME,
|
|
||||||
balance,
|
|
||||||
sendCoins,
|
|
||||||
newAddress,
|
|
||||||
getStatus,
|
|
||||||
newFunding,
|
|
||||||
cryptoNetwork,
|
|
||||||
checkBlockchainStatus
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue