From 656ab99f883f5cc75e1f1341bbc737c34327185d Mon Sep 17 00:00:00 2001 From: ShahanaFarooqui Date: Mon, 2 Oct 2023 20:55:16 -0700 Subject: [PATCH] Show loop version --- backend/controllers/shared/loop.js | 108 ++++++------------ backend/routes/shared/loop.js | 3 +- backend/utils/common.js | 5 +- server/controllers/shared/loop.ts | 105 ++++++----------- server/routes/shared/loop.ts | 3 +- server/utils/common.ts | 5 +- .../swap-modal/swap-modal.component.scss | 4 +- .../loop/loop-modal/loop-modal.component.scss | 4 +- .../ln-services/loop/loop.component.html | 2 +- .../ln-services/loop/loop.component.ts | 22 +++- .../shared/services/consts-enums-functions.ts | 1 + src/app/shared/services/loop.service.ts | 7 +- 12 files changed, 110 insertions(+), 159 deletions(-) diff --git a/backend/controllers/shared/loop.js b/backend/controllers/shared/loop.js index 290817fb..f0160b04 100644 --- a/backend/controllers/shared/loop.js +++ b/backend/controllers/shared/loop.js @@ -6,13 +6,7 @@ const logger = Logger; const common = Common; export const loopOut = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Looping Out..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop Out Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/out'; + options.uri = '/v1/loop/out'; options.body = { amt: req.body.amount, sweep_conf_target: req.body.targetConf, @@ -41,13 +35,7 @@ export const loopOut = (req, res, next) => { }; export const loopOutTerms = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Out Terms..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop Out Terms Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/out/terms'; + options.uri = '/v1/loop/out/terms'; request(options).then((body) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Out Terms Received', data: body }); res.status(200).json(body); @@ -58,13 +46,7 @@ export const loopOutTerms = (req, res, next) => { }; export const loopOutQuote = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Out Quotes..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop Out Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/out/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + options.uri = '/v1/loop/out/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Quote URL', data: options.url }); request(options).then((quoteRes) => { quoteRes.amount = +req.params.amount; @@ -78,19 +60,13 @@ export const loopOutQuote = (req, res, next) => { }; export const loopOutTermsAndQuotes = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Out Terms & Quotes..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop Out Terms & Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/out/terms'; + options.uri = '/v1/loop/out/terms'; request(options).then((terms) => { logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Terms Received', data: terms }); - const options1 = common.getSwapServerOptions(req); - const options2 = common.getSwapServerOptions(req); - options1.url = options1.url + '/v1/loop/out/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; - options2.url = options2.url + '/v1/loop/out/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + const options1 = options; + const options2 = options; + options1.uri = '/v1/loop/out/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + options2.uri = '/v1/loop/out/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Min Quote Options', data: options1 }); logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Max Quote Options', data: options2 }); return Promise.all([request(options1), request(options2)]).then((values) => { @@ -112,13 +88,7 @@ export const loopOutTermsAndQuotes = (req, res, next) => { }; export const loopIn = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Looping In..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop In Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/in'; + options.uri = '/v1/loop/in'; options.body = { amt: req.body.amount, max_swap_fee: req.body.swapFee, @@ -136,13 +106,7 @@ export const loopIn = (req, res, next) => { }; export const loopInTerms = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop In Terms..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop In Terms Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/in/terms'; + options.uri = '/v1/loop/in/terms'; request(options).then((body) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop In Terms Received', data: body }); res.status(200).json(body); @@ -153,13 +117,7 @@ export const loopInTerms = (req, res, next) => { }; export const loopInQuote = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop In Quotes..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop In Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/in/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + options.uri = '/v1/loop/in/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Quote Options', data: options.url }); request(options).then((body) => { body.amount = +req.params.amount; @@ -173,19 +131,13 @@ export const loopInQuote = (req, res, next) => { }; export const loopInTermsAndQuotes = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop In Terms & Quotes..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop In Terms & Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/in/terms'; + options.uri = '/v1/loop/in/terms'; request(options).then((terms) => { logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Terms Received', data: terms }); - const options1 = common.getSwapServerOptions(req); - const options2 = common.getSwapServerOptions(req); - options1.url = options1.url + '/v1/loop/in/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; - options2.url = options2.url + '/v1/loop/in/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + const options1 = options; + const options2 = options; + options1.uri = '/v1/loop/in/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + options2.uri = '/v1/loop/in/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Min Quote Options', data: options1 }); logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Max Quote Options', data: options2 }); return Promise.all([request(options1), request(options2)]).then((values) => { @@ -207,13 +159,12 @@ export const loopInTermsAndQuotes = (req, res, next) => { }; export const swaps = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting List Swaps..' }); - options = common.getSwapServerOptions(req); if (options.url === '') { const errMsg = 'Loop Server URL is missing in the configuration.'; const err = common.handleError({ statusCode: 500, message: 'List Swaps Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); return res.status(err.statusCode).json({ message: err.message, error: err.error }); } - options.url = options.url + '/v1/loop/swaps'; + options.uri = '/v1/loop/swaps'; request(options).then((body) => { logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Swaps Received', data: body }); res.status(200).json(body.swaps); @@ -224,13 +175,7 @@ export const swaps = (req, res, next) => { }; export const swap = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Swap Information..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Get Swap Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/swap/' + req.params.id; + options.uri = '/v1/loop/swap/' + req.params.id; request(options).then((body) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Swap Information Received', data: body }); res.status(200).json(body); @@ -239,3 +184,20 @@ export const swap = (req, res, next) => { return res.status(err.statusCode).json({ message: err.message, error: err.error }); }); }; +export const loopInfo = (req, res, next) => { + logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Information..' }); + options = common.setSwapServerOptions(req); + if (options.url === '') { + const errMsg = 'Loop Server URL is missing in the configuration.'; + const err = common.handleError({ statusCode: 500, message: 'Get Loop Info Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); + return res.status(err.statusCode).json({ message: err.message, error: err.error }); + } + options.uri = '/v1/loop/info'; + request(options).then((body) => { + logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Information Received', data: body }); + res.status(200).json(body); + }).catch((errRes) => { + const err = common.handleError(errRes, 'Loop', 'Get Loop Info Error', req.session.selectedNode); + return res.status(err.statusCode).json({ message: err.message, error: err.error }); + }); +}; diff --git a/backend/routes/shared/loop.js b/backend/routes/shared/loop.js index 38436ef5..753e06e0 100644 --- a/backend/routes/shared/loop.js +++ b/backend/routes/shared/loop.js @@ -1,8 +1,9 @@ import exprs from 'express'; const { Router } = exprs; import { isAuthenticated } from '../../utils/authCheck.js'; -import { loopInTerms, loopInQuote, loopInTermsAndQuotes, loopIn, loopOutTerms, loopOutQuote, loopOutTermsAndQuotes, loopOut, swaps, swap } from '../../controllers/shared/loop.js'; +import { loopInfo, loopInTerms, loopInQuote, loopInTermsAndQuotes, loopIn, loopOutTerms, loopOutQuote, loopOutTermsAndQuotes, loopOut, swaps, swap } from '../../controllers/shared/loop.js'; const router = Router(); +router.get('/info', isAuthenticated, loopInfo); router.get('/in/terms', isAuthenticated, loopInTerms); router.get('/in/quote/:amount', isAuthenticated, loopInQuote); router.get('/in/termsAndQuotes', isAuthenticated, loopInTermsAndQuotes); diff --git a/backend/utils/common.js b/backend/utils/common.js index 7d15a439..24ae8243 100644 --- a/backend/utils/common.js +++ b/backend/utils/common.js @@ -29,9 +29,10 @@ export class CommonService { { name: 'JAN', days: 31 }, { name: 'FEB', days: 28 }, { name: 'MAR', days: 31 }, { name: 'APR', days: 30 }, { name: 'MAY', days: 31 }, { name: 'JUN', days: 30 }, { name: 'JUL', days: 31 }, { name: 'AUG', days: 31 }, { name: 'SEP', days: 30 }, { name: 'OCT', days: 31 }, { name: 'NOV', days: 30 }, { name: 'DEC', days: 31 } ]; - this.getSwapServerOptions = (req) => { + this.setSwapServerOptions = (req) => { const swapOptions = { - url: req.session.selectedNode.swap_server_url, + baseUrl: req.session.selectedNode.swap_server_url, + uri: '', rejectUnauthorized: false, json: true, headers: { 'Grpc-Metadata-macaroon': '' } diff --git a/server/controllers/shared/loop.ts b/server/controllers/shared/loop.ts index ab13fa5a..3f8dc76a 100644 --- a/server/controllers/shared/loop.ts +++ b/server/controllers/shared/loop.ts @@ -7,13 +7,7 @@ const common: CommonService = Common; export const loopOut = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Looping Out..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop Out Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/out'; + options.uri = '/v1/loop/out'; options.body = { amt: req.body.amount, sweep_conf_target: req.body.targetConf, @@ -39,13 +33,7 @@ export const loopOut = (req, res, next) => { export const loopOutTerms = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Out Terms..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop Out Terms Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/out/terms'; + options.uri = '/v1/loop/out/terms'; request(options).then((body) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Out Terms Received', data: body }); res.status(200).json(body); @@ -57,13 +45,7 @@ export const loopOutTerms = (req, res, next) => { export const loopOutQuote = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Out Quotes..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop Out Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/out/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + options.uri = '/v1/loop/out/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Quote URL', data: options.url }); request(options).then((quoteRes) => { quoteRes.amount = +req.params.amount; @@ -78,18 +60,12 @@ export const loopOutQuote = (req, res, next) => { export const loopOutTermsAndQuotes = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Out Terms & Quotes..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop Out Terms & Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/out/terms'; + options.uri = '/v1/loop/out/terms'; request(options).then((terms) => { logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Terms Received', data: terms }); - const options1 = common.getSwapServerOptions(req); const options2 = common.getSwapServerOptions(req); - options1.url = options1.url + '/v1/loop/out/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; - options2.url = options2.url + '/v1/loop/out/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + const options1 = options; const options2 = options; + options1.uri = '/v1/loop/out/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + options2.uri = '/v1/loop/out/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Min Quote Options', data: options1 }); logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Max Quote Options', data: options2 }); return Promise.all([request(options1), request(options2)]).then((values) => { @@ -112,13 +88,7 @@ export const loopOutTermsAndQuotes = (req, res, next) => { export const loopIn = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Looping In..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop In Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/in'; + options.uri = '/v1/loop/in'; options.body = { amt: req.body.amount, max_swap_fee: req.body.swapFee, @@ -137,13 +107,7 @@ export const loopIn = (req, res, next) => { export const loopInTerms = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop In Terms..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop In Terms Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/in/terms'; + options.uri = '/v1/loop/in/terms'; request(options).then((body) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop In Terms Received', data: body }); res.status(200).json(body); @@ -155,13 +119,7 @@ export const loopInTerms = (req, res, next) => { export const loopInQuote = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop In Quotes..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop In Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/in/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + options.uri = '/v1/loop/in/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Quote Options', data: options.url }); request(options).then((body) => { body.amount = +req.params.amount; @@ -176,18 +134,12 @@ export const loopInQuote = (req, res, next) => { export const loopInTermsAndQuotes = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop In Terms & Quotes..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Loop In Terms & Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/in/terms'; + options.uri = '/v1/loop/in/terms'; request(options).then((terms) => { logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Terms Received', data: terms }); - const options1 = common.getSwapServerOptions(req); const options2 = common.getSwapServerOptions(req); - options1.url = options1.url + '/v1/loop/in/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; - options2.url = options2.url + '/v1/loop/in/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + const options1 = options; const options2 = options; + options1.uri = '/v1/loop/in/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; + options2.uri = '/v1/loop/in/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline; logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Min Quote Options', data: options1 }); logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Max Quote Options', data: options2 }); return Promise.all([request(options1), request(options2)]).then((values) => { @@ -210,13 +162,12 @@ export const loopInTermsAndQuotes = (req, res, next) => { export const swaps = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting List Swaps..' }); - options = common.getSwapServerOptions(req); if (options.url === '') { const errMsg = 'Loop Server URL is missing in the configuration.'; const err = common.handleError({ statusCode: 500, message: 'List Swaps Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); return res.status(err.statusCode).json({ message: err.message, error: err.error }); } - options.url = options.url + '/v1/loop/swaps'; + options.uri = '/v1/loop/swaps'; request(options).then((body) => { logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Swaps Received', data: body }); res.status(200).json(body.swaps); @@ -228,13 +179,7 @@ export const swaps = (req, res, next) => { export const swap = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Swap Information..' }); - options = common.getSwapServerOptions(req); - if (options.url === '') { - const errMsg = 'Loop Server URL is missing in the configuration.'; - const err = common.handleError({ statusCode: 500, message: 'Get Swap Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - } - options.url = options.url + '/v1/loop/swap/' + req.params.id; + options.uri = '/v1/loop/swap/' + req.params.id; request(options).then((body) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Swap Information Received', data: body }); res.status(200).json(body); @@ -243,3 +188,21 @@ export const swap = (req, res, next) => { return res.status(err.statusCode).json({ message: err.message, error: err.error }); }); }; + +export const loopInfo = (req, res, next) => { + logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Information..' }); + options = common.setSwapServerOptions(req); + if (options.url === '') { + const errMsg = 'Loop Server URL is missing in the configuration.'; + const err = common.handleError({ statusCode: 500, message: 'Get Loop Info Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode); + return res.status(err.statusCode).json({ message: err.message, error: err.error }); + } + options.uri = '/v1/loop/info'; + request(options).then((body) => { + logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Information Received', data: body }); + res.status(200).json(body); + }).catch((errRes) => { + const err = common.handleError(errRes, 'Loop', 'Get Loop Info Error', req.session.selectedNode); + return res.status(err.statusCode).json({ message: err.message, error: err.error }); + }); +}; diff --git a/server/routes/shared/loop.ts b/server/routes/shared/loop.ts index 21f82ec4..ef9ef1d2 100644 --- a/server/routes/shared/loop.ts +++ b/server/routes/shared/loop.ts @@ -1,10 +1,11 @@ import exprs from 'express'; const { Router } = exprs; import { isAuthenticated } from '../../utils/authCheck.js'; -import { loopInTerms, loopInQuote, loopInTermsAndQuotes, loopIn, loopOutTerms, loopOutQuote, loopOutTermsAndQuotes, loopOut, swaps, swap } from '../../controllers/shared/loop.js'; +import { loopInfo, loopInTerms, loopInQuote, loopInTermsAndQuotes, loopIn, loopOutTerms, loopOutQuote, loopOutTermsAndQuotes, loopOut, swaps, swap } from '../../controllers/shared/loop.js'; const router = Router(); +router.get('/info', isAuthenticated, loopInfo); router.get('/in/terms', isAuthenticated, loopInTerms); router.get('/in/quote/:amount', isAuthenticated, loopInQuote); router.get('/in/termsAndQuotes', isAuthenticated, loopInTermsAndQuotes); diff --git a/server/utils/common.ts b/server/utils/common.ts index 079bf324..05834ee1 100644 --- a/server/utils/common.ts +++ b/server/utils/common.ts @@ -34,9 +34,10 @@ export class CommonService { constructor() { } - public getSwapServerOptions = (req) => { + public setSwapServerOptions = (req) => { const swapOptions = { - url: req.session.selectedNode.swap_server_url, + baseUrl: req.session.selectedNode.swap_server_url, + uri: '', rejectUnauthorized: false, json: true, headers: { 'Grpc-Metadata-macaroon': '' } diff --git a/src/app/shared/components/ln-services/boltz/swap-modal/swap-modal.component.scss b/src/app/shared/components/ln-services/boltz/swap-modal/swap-modal.component.scss index 6d6c72df..1490f5a1 100755 --- a/src/app/shared/components/ln-services/boltz/swap-modal/swap-modal.component.scss +++ b/src/app/shared/components/ln-services/boltz/swap-modal/swap-modal.component.scss @@ -3,7 +3,7 @@ } .info-graphics-container { - max-height: 60rem; - min-height: 60rem; + max-height: 30rem; + min-height: 30rem; overflow-x: hidden; } \ No newline at end of file diff --git a/src/app/shared/components/ln-services/loop/loop-modal/loop-modal.component.scss b/src/app/shared/components/ln-services/loop/loop-modal/loop-modal.component.scss index 6d6c72df..1490f5a1 100755 --- a/src/app/shared/components/ln-services/loop/loop-modal/loop-modal.component.scss +++ b/src/app/shared/components/ln-services/loop/loop-modal/loop-modal.component.scss @@ -3,7 +3,7 @@ } .info-graphics-container { - max-height: 60rem; - min-height: 60rem; + max-height: 30rem; + min-height: 30rem; overflow-x: hidden; } \ No newline at end of file diff --git a/src/app/shared/components/ln-services/loop/loop.component.html b/src/app/shared/components/ln-services/loop/loop.component.html index 92ce4a44..8c38b296 100755 --- a/src/app/shared/components/ln-services/loop/loop.component.html +++ b/src/app/shared/components/ln-services/loop/loop.component.html @@ -1,6 +1,6 @@
- Loop + Loop (v{{loopInfo?.version || ' Unknown'}})
diff --git a/src/app/shared/components/ln-services/loop/loop.component.ts b/src/app/shared/components/ln-services/loop/loop.component.ts index 6d26c2bb..31c791eb 100755 --- a/src/app/shared/components/ln-services/loop/loop.component.ts +++ b/src/app/shared/components/ln-services/loop/loop.component.ts @@ -5,13 +5,13 @@ import { takeUntil, filter } from 'rxjs/operators'; import { Store } from '@ngrx/store'; import { faInfinity } from '@fortawesome/free-solid-svg-icons'; -import { LoopTypeEnum } from '../../../services/consts-enums-functions'; +import { LoopTypeEnum, UI_MESSAGES } from '../../../services/consts-enums-functions'; import { LoopModalComponent } from './loop-modal/loop-modal.component'; import { LoopQuote, LoopSwapStatus } from '../../../models/loopModels'; import { LoopService } from '../../../services/loop.service'; import { RTLState } from '../../../../store/rtl.state'; -import { openAlert } from '../../../../store/rtl.actions'; +import { openAlert, closeSpinner, openSpinner } from '../../../../store/rtl.actions'; @Component({ selector: 'rtl-loop', @@ -21,6 +21,7 @@ import { openAlert } from '../../../../store/rtl.actions'; export class LoopComponent implements OnInit, OnDestroy { public faInfinity = faInfinity; + public loopInfo: any = null; private targetConf = 2; public inAmount = 250000; public quotes: LoopQuote[] = []; @@ -32,11 +33,26 @@ export class LoopComponent implements OnInit, OnDestroy { public flgLoading: Array = [true]; public links = [{ link: 'loopout', name: 'Loop Out' }, { link: 'loopin', name: 'Loop In' }]; public activeTab = this.links[0]; - private unSubs: Array> = [new Subject(), new Subject(), new Subject(), new Subject()]; + private unSubs: Array> = [new Subject(), new Subject(), new Subject(), new Subject(), new Subject(), new Subject()]; constructor(private router: Router, private loopService: LoopService, private store: Store) { } ngOnInit() { + this.store.dispatch(openSpinner({ payload: UI_MESSAGES.GET_LOOP_INFO })); + this.loopService.getLoopInfo().pipe(takeUntil(this.unSubs[4])). + subscribe({ + next: (loopInfoResponse: any) => { + this.store.dispatch(closeSpinner({ payload: UI_MESSAGES.GET_LOOP_INFO })); + this.loopInfo = loopInfoResponse; + if (this.loopInfo && this.loopInfo.version) { + this.loopInfo.version = this.loopInfo.version.split(' ')[0]; + } + }, + error: (err) => { + this.store.dispatch(closeSpinner({ payload: UI_MESSAGES.GET_LOOP_INFO })); + this.loopInfo.version = ' Unknown'; + } + }); this.loopService.listSwaps(); const linkFound = this.links.find((link) => this.router.url.includes(link.link)); this.activeTab = linkFound ? linkFound : this.links[0]; diff --git a/src/app/shared/services/consts-enums-functions.ts b/src/app/shared/services/consts-enums-functions.ts index 9aba3eba..eb4201ba 100644 --- a/src/app/shared/services/consts-enums-functions.ts +++ b/src/app/shared/services/consts-enums-functions.ts @@ -357,6 +357,7 @@ export const UI_MESSAGES = { VERIFY_MESSAGE: 'Verifying Message...', BUMP_FEE: 'Bumping Fee...', LEASE_UTXO: 'Leasing UTXO...', + GET_LOOP_INFO: 'Getting Loop Info...', GET_LOOP_SWAPS: 'Getting List Swaps...', GET_FORWARDING_HISTORY: 'Getting Forwarding History...', GET_LOOKUP_DETAILS: 'Getting Lookup Details...', diff --git a/src/app/shared/services/loop.service.ts b/src/app/shared/services/loop.service.ts index 38fa4a7f..a5e25beb 100644 --- a/src/app/shared/services/loop.service.ts +++ b/src/app/shared/services/loop.service.ts @@ -19,10 +19,15 @@ export class LoopService implements OnDestroy { private loopUrl = ''; private swaps: LoopSwapStatus[] = []; public swapsChanged = new BehaviorSubject([]); - private unSubs: Array> = [new Subject(), new Subject(), new Subject(), new Subject(), new Subject()]; + private unSubs: Array> = [new Subject(), new Subject(), new Subject(), new Subject(), new Subject(), new Subject(), new Subject()]; constructor(private httpClient: HttpClient, private logger: LoggerService, private store: Store, private commonService: CommonService) { } + getLoopInfo() { + this.loopUrl = API_URL + API_END_POINTS.LOOP_API + '/info'; + return this.httpClient.get(this.loopUrl); + } + getSwapsList() { return this.swaps; }