mirror of
https://github.com/Ride-The-Lightning/RTL
synced 2024-11-07 15:20:31 +00:00
e45d6d598a
- Package updates Updated docker NodeJS from 10 to 14 Updated Angular from 11 to 12 Updated Material from 11 to 12 Updated Angular cli from 11 to 12 Updated Karma from 5 to 6 Updated rxjs from 6 to 7 Updated ngrx from 10 to 12 Updated angularx-qrcode from 10 to 11 Updated @angular/flex-layout from 11 to 12 Updated angular-user-idle from 2.2.4 to 2.2.5 Updated typescript from 4.0.2 to 4.2.4 Updated zone.js from 0.10.2 to 0.11.4 Migrated from TSLint to ESLint Installed save-dev crypto-browserify & stream-browserify - Mask password with fixed length #689 - CSRF Token (#696) - Route lock default password (#700) - ECL Invoice amount mislabeled #694 - ECL & LND Fee report time zone offset bug fixes #692 & #693 - Loop remove max routing fee validation #690 - Child route refresh bug - Adding Password Blacklist (#704) - Fee rate in percentage #621 (#705) - ECL Adding BaseFee and FeeRate on Channels - LND Invoice and Payment pagination fix (#707) - Keysend missing QR code bug fix - Login page XS layout fix - Reports tables load time improved (#709) - Report initial table load bug fix
129 lines
5.7 KiB
JavaScript
129 lines
5.7 KiB
JavaScript
var request = require('request-promise');
|
|
var common = require('../../routes/common');
|
|
var logger = require('../shared/logger');
|
|
var options = {};
|
|
|
|
arrangeFees = (body, current_time) => {
|
|
let fees = { daily_fee: 0, daily_txs: 0, weekly_fee: 0, weekly_txs: 0, monthly_fee: 0, monthly_txs: 0 };
|
|
let week_start_time = current_time - 604800000;
|
|
let day_start_time = current_time - 86400000;
|
|
let fee = 0;
|
|
body.relayed.forEach(relayedEle => {
|
|
fee = Math.round((relayedEle.amountIn - relayedEle.amountOut)/1000);
|
|
if (relayedEle.timestamp >= day_start_time) {
|
|
fees.daily_fee = fees.daily_fee + fee;
|
|
fees.daily_txs = fees.daily_txs + 1;
|
|
}
|
|
if (relayedEle.timestamp >= week_start_time) {
|
|
fees.weekly_fee = fees.weekly_fee + fee;
|
|
fees.weekly_txs = fees.weekly_txs + 1;
|
|
}
|
|
fees.monthly_fee = fees.monthly_fee + fee;
|
|
fees.monthly_txs = fees.monthly_txs + 1;
|
|
});
|
|
logger.log({level: 'DEBUG', fileName: 'Fees', msg: 'Arranged Fee', data: fees});
|
|
return fees;
|
|
};
|
|
|
|
arrangePayments = (body) => {
|
|
let payments = {
|
|
sent: body && body.sent ? body.sent : [],
|
|
received: body && body.received ? body.received : [],
|
|
relayed: body && body.relayed ? body.relayed : []
|
|
};
|
|
payments.sent.forEach(sentEle => {
|
|
if (sentEle.recipientAmount) { sentEle.recipientAmount = Math.round(sentEle.recipientAmount/1000); }
|
|
if (sentEle.parts && sentEle.parts.length > 0) {
|
|
sentEle.firstPartTimestamp = sentEle.parts[0].timestamp;
|
|
}
|
|
sentEle.parts.forEach(part => {
|
|
if (part.amount) { part.amount = Math.round(part.amount/1000); }
|
|
if (part.feesPaid) { part.feesPaid = Math.round(part.feesPaid/1000); }
|
|
});
|
|
});
|
|
payments.received.forEach(receivedEle => {
|
|
if (receivedEle.parts && receivedEle.parts.length > 0) {
|
|
receivedEle.firstPartTimestamp = receivedEle.parts[0].timestamp;
|
|
}
|
|
receivedEle.parts.forEach(part => {
|
|
if (part.amount) { part.amount = Math.round(part.amount/1000); }
|
|
});
|
|
});
|
|
payments.relayed.forEach(relayedEle => {
|
|
if (relayedEle.amountIn) { relayedEle.amountIn = Math.round(relayedEle.amountIn/1000); }
|
|
if (relayedEle.amountOut) { relayedEle.amountOut = Math.round(relayedEle.amountOut/1000); }
|
|
});
|
|
payments.sent = common.sortDescByKey(payments.sent, 'firstPartTimestamp');
|
|
payments.received = common.sortDescByKey(payments.received, 'firstPartTimestamp');
|
|
payments.relayed = common.sortDescByKey(payments.relayed, 'timestamp');
|
|
logger.log({level: 'DEBUG', fileName: 'Fees', msg: 'Arranged Payments', data: payments});
|
|
return payments;
|
|
};
|
|
|
|
exports.getFees = (req, res, next) => {
|
|
logger.log({level: 'INFO', fileName: 'Fees', msg: 'Getting Fees..'});
|
|
options = common.getOptions();
|
|
options.url = common.getSelLNServerUrl() + '/audit';
|
|
let today = new Date(Date.now());
|
|
let tillToday = (Math.round(today.getTime()/1000)).toString();
|
|
let fromLastMonth = (Math.round(new Date(today.getFullYear(), today.getMonth() - 1, today.getDate() + 1, 0, 0, 0).getTime()/1000)).toString();
|
|
options.form = {
|
|
from: fromLastMonth,
|
|
to: tillToday
|
|
};
|
|
logger.log({level: 'DEBUG', fileName: 'Fees', msg: 'Fee Audit Options', data: options.form});
|
|
if (common.read_dummy_data) {
|
|
common.getDummyData('Fees').then(function(data) { res.status(200).json(arrangeFees(data, Math.round((new Date().getTime())))); });
|
|
} else {
|
|
request.post(options).then((body) => {
|
|
logger.log({level: 'DEBUG', fileName: 'Fees', msg: 'Fee Response', data: body});
|
|
logger.log({level: 'INFO', fileName: 'Fees', msg: 'Fee Received'});
|
|
res.status(200).json(arrangeFees(body, Math.round((new Date().getTime()))));
|
|
})
|
|
.catch(errRes => {
|
|
let err = JSON.parse(JSON.stringify(errRes));
|
|
if (err.options && err.options.headers && err.options.headers.authorization) {
|
|
delete err.options.headers.authorization;
|
|
}
|
|
if (err.response && err.response.request && err.response.request.headers && err.response.request.headers.authorization) {
|
|
delete err.response.request.headers.authorization;
|
|
}
|
|
logger.log({level: 'ERROR', fileName: 'Fees', msg: 'Get Fees Error', error: err});
|
|
return res.status(err.statusCode ? err.statusCode : 500).json({
|
|
message: "Fetching Fees failed!",
|
|
error: err.error && err.error.error ? err.error.error : err.error ? err.error : "Unknown Server Error"
|
|
});
|
|
});
|
|
}
|
|
};
|
|
|
|
exports.getPayments = (req, res, next) => {
|
|
logger.log({level: 'INFO', fileName: 'Fees', msg: 'Getting Payments..'});
|
|
options = common.getOptions();
|
|
options.url = common.getSelLNServerUrl() + '/audit';
|
|
options.form = null;
|
|
if (common.read_dummy_data) {
|
|
common.getDummyData('Payments').then(function(data) { res.status(200).json(arrangePayments(data)); });
|
|
} else {
|
|
request.post(options).then((body) => {
|
|
logger.log({level: 'DEBUG', fileName: 'Fees', msg: 'Payments Response', data: body});
|
|
logger.log({level: 'INFO', fileName: 'Fees', msg: 'Payments Received'});
|
|
res.status(200).json(arrangePayments(body));
|
|
})
|
|
.catch(errRes => {
|
|
let err = JSON.parse(JSON.stringify(errRes));
|
|
if (err.options && err.options.headers && err.options.headers.authorization) {
|
|
delete err.options.headers.authorization;
|
|
}
|
|
if (err.response && err.response.request && err.response.request.headers && err.response.request.headers.authorization) {
|
|
delete err.response.request.headers.authorization;
|
|
}
|
|
logger.log({level: 'ERROR', fileName: 'Fees', msg: 'Get Payments Error', error: err});
|
|
return res.status(err.statusCode ? err.statusCode : 500).json({
|
|
message: "Fetching Payments failed!",
|
|
error: err.error && err.error.error ? err.error.error : err.error ? err.error : "Unknown Server Error"
|
|
});
|
|
});
|
|
}
|
|
};
|