mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2024-11-19 01:40:29 +01:00
Show loop version
This commit is contained in:
parent
15080d6749
commit
656ab99f88
@ -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 });
|
||||
});
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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': '' }
|
||||
|
@ -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 });
|
||||
});
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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': '' }
|
||||
|
@ -3,7 +3,7 @@
|
||||
}
|
||||
|
||||
.info-graphics-container {
|
||||
max-height: 60rem;
|
||||
min-height: 60rem;
|
||||
max-height: 30rem;
|
||||
min-height: 30rem;
|
||||
overflow-x: hidden;
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
}
|
||||
|
||||
.info-graphics-container {
|
||||
max-height: 60rem;
|
||||
min-height: 60rem;
|
||||
max-height: 30rem;
|
||||
min-height: 30rem;
|
||||
overflow-x: hidden;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<div fxLayout="row" fxLayoutAlign="start center" class="page-title-container">
|
||||
<fa-icon class="page-title-img mr-1" [icon]="faInfinity"></fa-icon>
|
||||
<span class="page-title">Loop</span>
|
||||
<span class="page-title">Loop (v{{loopInfo?.version || ' Unknown'}})</span>
|
||||
</div>
|
||||
<div fxLayout="column" class="padding-gap-x">
|
||||
<mat-card>
|
||||
|
@ -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<Boolean | 'error'> = [true];
|
||||
public links = [{ link: 'loopout', name: 'Loop Out' }, { link: 'loopin', name: 'Loop In' }];
|
||||
public activeTab = this.links[0];
|
||||
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject(), new Subject()];
|
||||
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject(), new Subject(), new Subject(), new Subject()];
|
||||
|
||||
constructor(private router: Router, private loopService: LoopService, private store: Store<RTLState>) { }
|
||||
|
||||
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];
|
||||
|
@ -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...',
|
||||
|
@ -19,10 +19,15 @@ export class LoopService implements OnDestroy {
|
||||
private loopUrl = '';
|
||||
private swaps: LoopSwapStatus[] = [];
|
||||
public swapsChanged = new BehaviorSubject<LoopSwapStatus[]>([]);
|
||||
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject(), new Subject(), new Subject()];
|
||||
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject(), new Subject(), new Subject(), new Subject(), new Subject()];
|
||||
|
||||
constructor(private httpClient: HttpClient, private logger: LoggerService, private store: Store<RTLState>, private commonService: CommonService) { }
|
||||
|
||||
getLoopInfo() {
|
||||
this.loopUrl = API_URL + API_END_POINTS.LOOP_API + '/info';
|
||||
return this.httpClient.get<any>(this.loopUrl);
|
||||
}
|
||||
|
||||
getSwapsList() {
|
||||
return this.swaps;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user