Update Application Settings

pull/1382/head
ShahanaFarooqui 4 weeks ago
parent a6e028c71c
commit 7bcc6b359f

@ -32,6 +32,24 @@ export const maskPasswords = (obj) => {
}
return obj;
};
export const removeSensitiveData = (config) => {
delete config.rtlConfFilePath;
delete config.rtlPass;
delete config.multiPass;
delete config.multiPassHashed;
delete config.secret2FA;
config.nodes.map((node) => {
node.authentication = node.Authentication;
node.settings = node.Settings;
delete node.Authentication;
delete node.Settings;
delete node.authentication.macaroonPath;
delete node.authentication.runePath;
delete node.authentication.lnApiPassword;
return node;
});
return config;
};
export const getCurrencyRates = (req, res, next) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Getting Currency Rates..' });
options.url = 'https://blockchain.info/ticker';
@ -64,7 +82,7 @@ export const getFile = (req, res, next) => {
}
});
};
export const getRTLConfig = (req, res, next) => {
export const getApplicationSettings = (req, res, next) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Getting RTL Configuration..' });
const confFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
fs.readFile(confFile, 'utf8', (errRes, data) => {
@ -74,30 +92,16 @@ export const getRTLConfig = (req, res, next) => {
return res.status(err.statusCode).json({ message: err.error, error: err.error });
}
else {
const appConfData = JSON.parse(data);
delete appConfData.rtlConfFilePath;
delete appConfData.rtlPass;
delete appConfData.multiPass;
delete appConfData.multiPassHashed;
delete appConfData.rtlSecret2fa;
const appConfData = removeSensitiveData(JSON.parse(data));
appConfData.enable2FA = common.appConfig.enable2FA;
appConfData.selectedNodeIndex = (req.session.selectedNode && req.session.selectedNode.index ? req.session.selectedNode.index : common.selectedNode.index);
appConfData.nodes.map((node) => {
node.authentication = node.Authentication;
node.settings = node.Settings;
delete node.Authentication;
delete node.Settings;
delete node.authentication.macaroonPath;
delete node.authentication.runePath;
delete node.authentication.lnApiPassword;
return node;
});
const token = req.headers.authorization ? req.headers.authorization.split(' ')[1] : '';
jwt.verify(token, common.secret_key, (err, user) => {
if (err) {
// Delete sensitive data for initial response (without security token)
// Delete unnecessary data for initial response (without security token)
const selNodeIdx = appConfData.nodes.findIndex((node) => node.index === appConfData.selectedNodeIndex) || 0;
appConfData.SSO = new SSO();
appConfData.secret2fa = '';
appConfData.secret2FA = '';
appConfData.dbDirectoryPath = '';
appConfData.nodes[selNodeIdx].authentication = new NodeAuthentication();
delete appConfData.nodes[selNodeIdx].settings.bitcoindConfigPath;
@ -184,40 +188,21 @@ export const getConfig = (req, res, next) => {
});
};
export const updateNodeSettings = (req, res, next) => {
const { updatedSettings } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating UI Settings..' });
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Node Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
const node = config.nodes.find((node) => (node.index === req.session.selectedNode.index));
if (node && node.Settings) {
node.Settings.userPersona = updatedSettings.userPersona;
node.Settings.themeMode = updatedSettings.themeMode;
node.Settings.themeColor = updatedSettings.themeColor;
node.Settings.unannouncedChannels = updatedSettings.unannouncedChannels;
node.Settings.fiatConversion = updatedSettings.fiatConversion;
if (updatedSettings.fiatConversion) {
node.Settings.currencyUnit = updatedSettings.currencyUnit ? updatedSettings.currencyUnit : 'USD';
}
else {
delete node.Settings.currencyUnit;
}
const selectedNode = common.findNode(req.session.selectedNode.index);
selectedNode.settings.userPersona = updatedSettings.userPersona;
selectedNode.settings.themeMode = updatedSettings.themeMode;
selectedNode.settings.themeColor = updatedSettings.themeColor;
selectedNode.settings.unannouncedChannels = updatedSettings.unannouncedChannels;
selectedNode.settings.fiatConversion = updatedSettings.fiatConversion;
if (updatedSettings.fiatConversion) {
selectedNode.settings.currencyUnit = updatedSettings.currencyUnit ? updatedSettings.currencyUnit : 'USD';
}
else {
delete selectedNode.settings.currencyUnit;
}
common.replaceNode(req, selectedNode);
node.Settings = req.body;
}
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'UI Settings Updated', data: maskPasswords(config) });
const selectedNode = common.findNode(req.session.selectedNode.index);
if (selectedNode && selectedNode.settings) {
selectedNode.settings = req.body;
common.replaceNode(req, selectedNode);
}
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Node Settings Updated', data: maskPasswords(config) });
res.status(201).json({ message: 'Node Settings Updated Successfully' });
}
catch (errRes) {
@ -227,15 +212,16 @@ export const updateNodeSettings = (req, res, next) => {
}
};
export const updateApplicationSettings = (req, res, next) => {
const { defaultNodeIndex } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Default Node..' });
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Application Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
config.defaultNodeIndex = defaultNodeIndex;
try {
const config = JSON.parse(req.body);
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Default Node Updated', data: maskPasswords(config) });
res.status(201).json({ message: 'Default Node Updated Successfully' });
// config.enable2FA = common.appConfig.enable2FA;
// config.selectedNodeIndex = (req.session.selectedNode && req.session.selectedNode.index ? req.session.selectedNode.index : common.selectedNode.index);
common.appConfig = config;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Application Settings Updated', data: maskPasswords(config) });
res.status(201).json(removeSensitiveData(common.appConfig));
}
catch (errRes) {
const errMsg = 'Update Default Node Error';
@ -243,109 +229,3 @@ export const updateApplicationSettings = (req, res, next) => {
return res.status(err.statusCode).json({ message: err.error, error: err.error });
}
};
export const update2FASettings = (req, res, next) => {
const { secret2fa } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating 2FA Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
if (secret2fa && secret2fa.trim() !== '') {
config.secret2fa = secret2fa;
}
else {
delete config.secret2fa;
}
const message = secret2fa.trim() === '' ? 'Two factor authentication disabled successfully.' : 'Two factor authentication enabled successfully.';
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
common.appConfig.rtlSecret2fa = config.secret2fa;
common.appConfig.enable2FA = !!config.secret2fa;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: message });
res.status(201).json({ message: message });
}
catch (errRes) {
const errMsg = 'Update 2FA Settings Error';
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.error, error: err.error });
}
};
export const updateSSO = (req, res, next) => {
const { SSO } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating SSO Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
delete config.SSO;
config.SSO = SSO;
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'SSO Setting Updated', data: maskPasswords(config) });
res.status(201).json({ message: 'SSO Updated Successfully' });
}
catch (errRes) {
const errMsg = 'Update SSO Error';
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.error, error: err.error });
}
};
export const updateServiceSettings = (req, res, next) => {
const { service, settings } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Service Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
const selectedNode = common.findNode(req.session.selectedNode.index);
config.nodes.forEach((node) => {
if (node.index === req.session.selectedNode.index) {
switch (service) {
case 'LOOP':
if (settings.enable) {
node.Settings.swapServerUrl = settings.serverUrl;
node.Authentication.swapMacaroonPath = settings.macaroonPath;
selectedNode.settings.swapServerUrl = settings.serverUrl;
selectedNode.authentication.swapMacaroonPath = settings.macaroonPath;
}
else {
delete node.Settings.swapServerUrl;
delete node.Authentication.swapMacaroonPath;
delete selectedNode.settings.swapServerUrl;
delete selectedNode.authentication.swapMacaroonPath;
}
break;
case 'BOLTZ':
if (settings.enable) {
node.Settings.boltzServerUrl = settings.serverUrl;
node.Authentication.boltzMacaroonPath = settings.macaroonPath;
selectedNode.settings.boltzServerUrl = settings.serverUrl;
selectedNode.authentication.boltzMacaroonPath = settings.macaroonPath;
}
else {
delete node.Settings.boltzServerUrl;
delete node.Authentication.boltzMacaroonPath;
delete selectedNode.settings.boltzServerUrl;
delete selectedNode.authentication.boltzMacaroonPath;
}
break;
case 'OFFERS':
node.Settings.enableOffers = settings.enableOffers;
selectedNode.settings.enableOffers = settings.enableOffers;
break;
case 'PEERSWAP':
node.Settings.enablePeerswap = settings.enablePeerswap;
selectedNode.settings.enablePeerswap = settings.enablePeerswap;
break;
default:
break;
}
common.replaceNode(req, selectedNode);
}
return node;
});
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Service Settings Updated', data: maskPasswords(config) });
res.status(201).json({ message: 'Service Settings Updated Successfully' });
}
catch (errRes) {
const errMsg = 'Update Service Settings Error';
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.error, error: err.error });
}
};

@ -44,7 +44,7 @@ const handleMultipleFailedAttemptsError = (failed, currentTime, errMsg) => {
};
}
};
export const verifyToken = (twoFAToken) => !!(common.appConfig.rtlSecret2fa && common.appConfig.rtlSecret2fa !== '' && otplib.authenticator.check(twoFAToken, common.appConfig.rtlSecret2fa));
export const verifyToken = (twoFAToken) => !!(common.appConfig.secret2FA && common.appConfig.secret2FA !== '' && otplib.authenticator.check(twoFAToken, common.appConfig.secret2FA));
export const authenticateUser = (req, res, next) => {
const { authenticateWith, authenticationValue, twoFAToken } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'Authenticating User..' });

@ -52,7 +52,7 @@ export class SSO {
}
}
export class ApplicationConfig {
constructor(defaultNodeIndex, selectedNodeIndex, dbDirectoryPath, rtlConfFilePath, rtlPass, multiPass, multiPassHashed, allowPasswordUpdate, enable2FA, rtlSecret2fa, SSO, nodes) {
constructor(defaultNodeIndex, selectedNodeIndex, dbDirectoryPath, rtlConfFilePath, rtlPass, multiPass, multiPassHashed, allowPasswordUpdate, enable2FA, secret2FA, SSO, nodes) {
this.defaultNodeIndex = defaultNodeIndex;
this.selectedNodeIndex = selectedNodeIndex;
this.dbDirectoryPath = dbDirectoryPath;
@ -62,7 +62,7 @@ export class ApplicationConfig {
this.multiPassHashed = multiPassHashed;
this.allowPasswordUpdate = allowPasswordUpdate;
this.enable2FA = enable2FA;
this.rtlSecret2fa = rtlSecret2fa;
this.secret2FA = secret2FA;
this.SSO = SSO;
this.nodes = nodes;
}

@ -1,10 +1,10 @@
import exprs from 'express';
const { Router } = exprs;
import { isAuthenticated } from '../../utils/authCheck.js';
import { getRTLConfig, updateNodeSettings, getConfig, getFile, updateSelectedNode, updateApplicationSettings, getCurrencyRates } from '../../controllers/shared/RTLConf.js';
import { updateNodeSettings, getConfig, getFile, updateSelectedNode, updateApplicationSettings, getCurrencyRates, getApplicationSettings } from '../../controllers/shared/RTLConf.js';
const router = Router();
router.get('/', getApplicationSettings);
router.get('/rates', getCurrencyRates);
router.get('/rtlconf', getRTLConfig);
router.get('/file', isAuthenticated, getFile);
router.get('/updateSelNode/:currNodeIndex/:prevNodeIndex', updateSelectedNode);
router.get('/config/:nodeType', isAuthenticated, getConfig);

@ -10,7 +10,7 @@ export class CommonService {
this.nodes = [];
this.selectedNode = null;
this.ssoInit = { rtlSso: 0, rtlCookiePath: '', logoutRedirectLink: '', cookieValue: '' };
this.appConfig = { defaultNodeIndex: 0, selectedNodeIndex: 0, rtlConfFilePath: '', dbDirectoryPath: join(dirname(fileURLToPath(import.meta.url)), '..', '..'), rtlPass: '', allowPasswordUpdate: true, enable2FA: false, rtlSecret2fa: '', SSO: this.ssoInit, nodes: [] };
this.appConfig = { defaultNodeIndex: 0, selectedNodeIndex: 0, rtlConfFilePath: '', dbDirectoryPath: join(dirname(fileURLToPath(import.meta.url)), '..', '..'), rtlPass: '', allowPasswordUpdate: true, enable2FA: false, secret2FA: '', SSO: this.ssoInit, nodes: [] };
this.port = 3000;
this.host = '';
this.secret_key = crypto.randomBytes(64).toString('hex');

@ -129,8 +129,8 @@ export class ConfigService {
else {
this.errMsg = this.errMsg + '\nNode Authentication can be set with multiPass only. Please set multiPass in RTL-Config.json';
}
this.common.appConfig.rtlSecret2fa = config.secret2fa;
this.common.appConfig.enable2FA = !!config.secret2fa;
this.common.appConfig.secret2FA = config.secret2FA;
this.common.appConfig.enable2FA = !!config.secret2FA;
}
else {
if (process?.env?.APP_PASSWORD && process?.env?.APP_PASSWORD.trim() !== '') {

@ -36,6 +36,25 @@ export const maskPasswords = (obj) => {
return obj;
};
export const removeSensitiveData = (config) => {
delete config.rtlConfFilePath;
delete config.rtlPass;
delete config.multiPass;
delete config.multiPassHashed;
delete config.secret2FA;
config.nodes.map((node) => {
node.authentication = node.Authentication;
node.settings = node.Settings;
delete node.Authentication;
delete node.Settings;
delete node.authentication.macaroonPath;
delete node.authentication.runePath;
delete node.authentication.lnApiPassword;
return node;
});
return config;
};
export const getCurrencyRates = (req, res, next) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Getting Currency Rates..' });
options.url = 'https://blockchain.info/ticker';
@ -67,7 +86,7 @@ export const getFile = (req, res, next) => {
});
};
export const getRTLConfig = (req, res, next) => {
export const getApplicationSettings = (req, res, next) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Getting RTL Configuration..' });
const confFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
fs.readFile(confFile, 'utf8', (errRes, data) => {
@ -76,30 +95,16 @@ export const getRTLConfig = (req, res, next) => {
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.error, error: err.error });
} else {
const appConfData = JSON.parse(data);
delete appConfData.rtlConfFilePath;
delete appConfData.rtlPass;
delete appConfData.multiPass;
delete appConfData.multiPassHashed;
delete appConfData.rtlSecret2fa;
const appConfData = removeSensitiveData(JSON.parse(data));
appConfData.enable2FA = common.appConfig.enable2FA;
appConfData.selectedNodeIndex = (req.session.selectedNode && req.session.selectedNode.index ? req.session.selectedNode.index : common.selectedNode.index);
appConfData.nodes.map((node) => {
node.authentication = node.Authentication;
node.settings = node.Settings;
delete node.Authentication;
delete node.Settings;
delete node.authentication.macaroonPath;
delete node.authentication.runePath;
delete node.authentication.lnApiPassword;
return node;
});
const token = req.headers.authorization ? req.headers.authorization.split(' ')[1] : '';
jwt.verify(token, common.secret_key, (err, user) => {
if (err) {
// Delete sensitive data for initial response (without security token)
// Delete unnecessary data for initial response (without security token)
const selNodeIdx = appConfData.nodes.findIndex((node) => node.index === appConfData.selectedNodeIndex) || 0;
appConfData.SSO = new SSO();
appConfData.secret2fa = '';
appConfData.secret2FA = '';
appConfData.dbDirectoryPath = '';
appConfData.nodes[selNodeIdx].authentication = new NodeAuthentication();
delete appConfData.nodes[selNodeIdx].settings.bitcoindConfigPath;
@ -187,38 +192,21 @@ export const getConfig = (req, res, next) => {
};
export const updateNodeSettings = (req, res, next) => {
const { updatedSettings } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating UI Settings..' });
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Node Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
const node = config.nodes.find((node) => (node.index === req.session.selectedNode.index));
if (node && node.Settings) {
node.Settings.userPersona = updatedSettings.userPersona;
node.Settings.themeMode = updatedSettings.themeMode;
node.Settings.themeColor = updatedSettings.themeColor;
node.Settings.unannouncedChannels = updatedSettings.unannouncedChannels;
node.Settings.fiatConversion = updatedSettings.fiatConversion;
if (updatedSettings.fiatConversion) {
node.Settings.currencyUnit = updatedSettings.currencyUnit ? updatedSettings.currencyUnit : 'USD';
} else {
delete node.Settings.currencyUnit;
}
const selectedNode = common.findNode(req.session.selectedNode.index);
selectedNode.settings.userPersona = updatedSettings.userPersona;
selectedNode.settings.themeMode = updatedSettings.themeMode;
selectedNode.settings.themeColor = updatedSettings.themeColor;
selectedNode.settings.unannouncedChannels = updatedSettings.unannouncedChannels;
selectedNode.settings.fiatConversion = updatedSettings.fiatConversion;
if (updatedSettings.fiatConversion) {
selectedNode.settings.currencyUnit = updatedSettings.currencyUnit ? updatedSettings.currencyUnit : 'USD';
} else {
delete selectedNode.settings.currencyUnit;
}
common.replaceNode(req, selectedNode);
node.Settings = req.body;
}
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'UI Settings Updated', data: maskPasswords(config) });
const selectedNode = common.findNode(req.session.selectedNode.index);
if (selectedNode && selectedNode.settings) {
selectedNode.settings = req.body;
common.replaceNode(req, selectedNode);
}
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Node Settings Updated', data: maskPasswords(config) });
res.status(201).json({ message: 'Node Settings Updated Successfully' });
} catch (errRes) {
const errMsg = 'Update Node Settings Error';
@ -228,125 +216,19 @@ export const updateNodeSettings = (req, res, next) => {
};
export const updateApplicationSettings = (req, res, next) => {
const { defaultNodeIndex } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Default Node..' });
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Application Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
config.defaultNodeIndex = defaultNodeIndex;
try {
const config = JSON.parse(req.body);
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Default Node Updated', data: maskPasswords(config) });
res.status(201).json({ message: 'Default Node Updated Successfully' });
// config.enable2FA = common.appConfig.enable2FA;
// config.selectedNodeIndex = (req.session.selectedNode && req.session.selectedNode.index ? req.session.selectedNode.index : common.selectedNode.index);
common.appConfig = config;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Application Settings Updated', data: maskPasswords(config) });
res.status(201).json(removeSensitiveData(common.appConfig));
} catch (errRes) {
const errMsg = 'Update Default Node Error';
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.error, error: err.error });
}
};
export const update2FASettings = (req, res, next) => {
const { secret2fa } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating 2FA Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
if (secret2fa && secret2fa.trim() !== '') {
config.secret2fa = secret2fa;
} else {
delete config.secret2fa;
}
const message = secret2fa.trim() === '' ? 'Two factor authentication disabled successfully.' : 'Two factor authentication enabled successfully.';
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
common.appConfig.rtlSecret2fa = config.secret2fa;
common.appConfig.enable2FA = !!config.secret2fa;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: message });
res.status(201).json({ message: message });
} catch (errRes) {
const errMsg = 'Update 2FA Settings Error';
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.error, error: err.error });
}
};
export const updateSSO = (req, res, next) => {
const { SSO } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating SSO Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
delete config.SSO;
config.SSO = SSO;
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'SSO Setting Updated', data: maskPasswords(config) });
res.status(201).json({ message: 'SSO Updated Successfully' });
} catch (errRes) {
const errMsg = 'Update SSO Error';
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.error, error: err.error });
}
};
export const updateServiceSettings = (req, res, next) => {
const { service, settings } = req.body;
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Service Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
const selectedNode = common.findNode(req.session.selectedNode.index);
config.nodes.forEach((node) => {
if (node.index === req.session.selectedNode.index) {
switch (service) {
case 'LOOP':
if (settings.enable) {
node.Settings.swapServerUrl = settings.serverUrl;
node.Authentication.swapMacaroonPath = settings.macaroonPath;
selectedNode.settings.swapServerUrl = settings.serverUrl;
selectedNode.authentication.swapMacaroonPath = settings.macaroonPath;
} else {
delete node.Settings.swapServerUrl;
delete node.Authentication.swapMacaroonPath;
delete selectedNode.settings.swapServerUrl;
delete selectedNode.authentication.swapMacaroonPath;
}
break;
case 'BOLTZ':
if (settings.enable) {
node.Settings.boltzServerUrl = settings.serverUrl;
node.Authentication.boltzMacaroonPath = settings.macaroonPath;
selectedNode.settings.boltzServerUrl = settings.serverUrl;
selectedNode.authentication.boltzMacaroonPath = settings.macaroonPath;
} else {
delete node.Settings.boltzServerUrl;
delete node.Authentication.boltzMacaroonPath;
delete selectedNode.settings.boltzServerUrl;
delete selectedNode.authentication.boltzMacaroonPath;
}
break;
case 'OFFERS':
node.Settings.enableOffers = settings.enableOffers;
selectedNode.settings.enableOffers = settings.enableOffers;
break;
case 'PEERSWAP':
node.Settings.enablePeerswap = settings.enablePeerswap;
selectedNode.settings.enablePeerswap = settings.enablePeerswap;
break;
default:
break;
}
common.replaceNode(req, selectedNode);
}
return node;
});
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Service Settings Updated', data: maskPasswords(config) });
res.status(201).json({ message: 'Service Settings Updated Successfully' });
} catch (errRes) {
const errMsg = 'Update Service Settings Error';
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.error, error: err.error });
}
};

@ -47,7 +47,7 @@ const handleMultipleFailedAttemptsError = (failed, currentTime, errMsg) => {
}
};
export const verifyToken = (twoFAToken) => !!(common.appConfig.rtlSecret2fa && common.appConfig.rtlSecret2fa !== '' && otplib.authenticator.check(twoFAToken, common.appConfig.rtlSecret2fa));
export const verifyToken = (twoFAToken) => !!(common.appConfig.secret2FA && common.appConfig.secret2FA !== '' && otplib.authenticator.check(twoFAToken, common.appConfig.secret2FA));
export const authenticateUser = (req, res, next) => {
const { authenticateWith, authenticationValue, twoFAToken } = req.body;

@ -75,7 +75,7 @@ export class ApplicationConfig {
public multiPassHashed?: string,
public allowPasswordUpdate?: boolean,
public enable2FA?: boolean,
public rtlSecret2fa?: string,
public secret2FA?: string,
public SSO?: SSO,
public nodes?: SelectedNode[]
) {}

@ -1,12 +1,12 @@
import exprs from 'express';
const { Router } = exprs;
import { isAuthenticated } from '../../utils/authCheck.js';
import { getRTLConfig, updateNodeSettings, getConfig, getFile, updateSelectedNode, updateApplicationSettings, getCurrencyRates } from '../../controllers/shared/RTLConf.js';
import { updateNodeSettings, getConfig, getFile, updateSelectedNode, updateApplicationSettings, getCurrencyRates, getApplicationSettings } from '../../controllers/shared/RTLConf.js';
const router = Router();
router.get('/', getApplicationSettings);
router.get('/rates', getCurrencyRates);
router.get('/rtlconf', getRTLConfig);
router.get('/file', isAuthenticated, getFile);
router.get('/updateSelNode/:currNodeIndex/:prevNodeIndex', updateSelectedNode);
router.get('/config/:nodeType', isAuthenticated, getConfig);

@ -12,7 +12,7 @@ export class CommonService {
public nodes: SelectedNode[] = [];
public selectedNode: SelectedNode = null;
public ssoInit = { rtlSso: 0, rtlCookiePath: '', logoutRedirectLink: '', cookieValue: '' };
public appConfig: ApplicationConfig = { defaultNodeIndex: 0, selectedNodeIndex: 0, rtlConfFilePath: '', dbDirectoryPath: join(dirname(fileURLToPath(import.meta.url)), '..', '..'), rtlPass: '', allowPasswordUpdate: true, enable2FA: false, rtlSecret2fa: '', SSO: this.ssoInit, nodes: [] };
public appConfig: ApplicationConfig = { defaultNodeIndex: 0, selectedNodeIndex: 0, rtlConfFilePath: '', dbDirectoryPath: join(dirname(fileURLToPath(import.meta.url)), '..', '..'), rtlPass: '', allowPasswordUpdate: true, enable2FA: false, secret2FA: '', SSO: this.ssoInit, nodes: [] };
public port = 3000;
public host = '';
public secret_key = crypto.randomBytes(64).toString('hex');

@ -134,8 +134,8 @@ export class ConfigService {
} else {
this.errMsg = this.errMsg + '\nNode Authentication can be set with multiPass only. Please set multiPass in RTL-Config.json';
}
this.common.appConfig.rtlSecret2fa = config.secret2fa;
this.common.appConfig.enable2FA = !!config.secret2fa;
this.common.appConfig.secret2FA = config.secret2FA;
this.common.appConfig.enable2FA = !!config.secret2FA;
} else {
if (process?.env?.APP_PASSWORD && process?.env?.APP_PASSWORD.trim() !== '') {
this.errMsg = this.errMsg + '\nRTL Password cannot be set with SSO. Please set SSO as 0 or remove password.';

@ -98,11 +98,11 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
}
this.actions.pipe(
takeUntil(this.unSubs[4]),
filter((action) => action.type === RTLActions.SET_RTL_CONFIG || action.type === RTLActions.LOGIN || action.type === RTLActions.LOGOUT)).
filter((action) => action.type === RTLActions.FETCH_APPLICATION_SETTINGS || action.type === RTLActions.LOGIN || action.type === RTLActions.LOGOUT)).
subscribe((action: (any)) => {
if (action.type === RTLActions.SET_RTL_CONFIG) {
if (action.type === RTLActions.SET_APPLICATION_SETTINGS) {
if (!this.sessionService.getItem('token')) {
if (+action.payload.sso.rtlSSO) {
if (+action.payload.SSO.rtlSSO) {
if (!this.accessKey || this.accessKey.trim().length < 32) {
this.router.navigate(['./error'], { state: { errorCode: '406', errorMessage: 'Access key too short. It should be at least 32 characters long.' } });
} else {

@ -93,7 +93,7 @@
<ng-template #sweepAllBlock>
<div fxLayout="column">
<mat-vertical-stepper #stepper [linear]="true" (selectionChange)="stepSelectionChanged($event)">
<mat-step *ngIf="!appConfig.sso.rtlSSO" [stepControl]="passwordFormGroup" [editable]="flgEditable">
<mat-step *ngIf="!appConfig.SSO.rtlSSO" [stepControl]="passwordFormGroup" [editable]="flgEditable">
<form fxLayout="column" fxLayoutAlign="space-between" class="my-1 pr-1" [formGroup]="passwordFormGroup">
<ng-template matStepLabel>{{passwordFormLabel}}</ng-template>
<div fxLayout="row">

@ -60,7 +60,7 @@
<ng-template #sweepAllBlock>
<div fxLayout="column">
<mat-vertical-stepper #stepper [linear]="true" (selectionChange)="stepSelectionChanged($event)">
<mat-step *ngIf="!appConfig.sso.rtlSSO" [stepControl]="passwordFormGroup" [editable]="flgEditable">
<mat-step *ngIf="!appConfig.SSO.rtlSSO" [stepControl]="passwordFormGroup" [editable]="flgEditable">
<form fxLayout="column" fxLayoutAlign="space-between" class="my-1 pr-1" [formGroup]="passwordFormGroup">
<ng-template matStepLabel>{{passwordFormLabel}}</ng-template>
<div fxLayout="row">

@ -12,10 +12,9 @@ import * as sha256 from 'sha256';
import { RTLConfiguration } from '../../../models/RTLconfig';
import { AuthConfig } from '../../../models/alertData';
import { RTLEffects } from '../../../../store/rtl.effects';
import { RTLState } from '../../../../store/rtl.state';
import { isAuthorized, twoFASaveSettings } from '../../../../store/rtl.actions';
import { isAuthorized, updateApplicationSettings } from '../../../../store/rtl.actions';
@Component({
selector: 'rtl-two-factor-auth',
@ -92,7 +91,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
onVerifyToken(): boolean | void {
if (this.appConfig?.enable2FA) {
this.store.dispatch(twoFASaveSettings({ payload: { secret2fa: '' } }));
this.store.dispatch(updateApplicationSettings({ payload: { enable2FA: this.appConfig?.enable2FA, secret2FA: '' } }));
this.generateSecret();
this.isTokenValid = true;
} else {
@ -104,13 +103,10 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
this.tokenFormGroup.controls.token.setErrors({ notValid: true });
return true;
}
this.store.dispatch(twoFASaveSettings({ payload: { secret2fa: this.secretFormGroup.controls.secret.value } }));
this.store.dispatch(updateApplicationSettings({ payload: { enable2FA: this.appConfig?.enable2FA, secret2FA: this.secretFormGroup.controls.secret.value } }));
this.tokenFormGroup.controls.token.setValue('');
}
this.flgValidated = true;
if (this.appConfig) {
this.appConfig.enable2FA = !this.appConfig?.enable2FA;
}
}
stepSelectionChanged(event: any) {

@ -8,7 +8,7 @@ import { LoggerService } from '../../../services/logger.service';
import { RTLState } from '../../../../store/rtl.state';
import { rootSelectedNode } from '../../../../store/rtl.selector';
import { ConfigSettingsNode } from '../../../models/RTLconfig';
import { updateServiceSettings } from '../../../../store/rtl.actions';
import { updateNodeSettings } from '../../../../store/rtl.actions';
import { setChildNodeSettingsLND } from '../../../../lnd/store/lnd.actions';
import { setChildNodeSettingsCLN } from '../../../../cln/store/cln.actions';
import { setChildNodeSettingsECL } from '../../../../eclair/store/ecl.actions';
@ -91,25 +91,25 @@ export class ExperimentalSettingsComponent implements OnInit, OnDestroy {
this.logger.info(this.selNode);
this.selNode.settings.enableOffers = this.enableOffers;
this.features[0].enabled = this.enableOffers;
this.store.dispatch(updateServiceSettings({ payload: { uiMessage: UI_MESSAGES.UPDATE_SETTING, service: ServicesEnum.OFFERS, settings: { enableOffers: this.enableOffers } } }));
this.store.dispatch(setChildNodeSettingsLND({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.settings.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.enableOffers
}
}));
this.store.dispatch(setChildNodeSettingsCLN({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.settings.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.enableOffers
}
}));
this.store.dispatch(setChildNodeSettingsECL({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.settings.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.enableOffers
}
}));
// this.store.dispatch(updateNodeSettings({ payload: { uiMessage: UI_MESSAGES.UPDATE_SETTING, service: ServicesEnum.OFFERS, settings: { enableOffers: this.enableOffers } } }));
// this.store.dispatch(setChildNodeSettingsLND({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.settings.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.enableOffers
// }
// }));
// this.store.dispatch(setChildNodeSettingsCLN({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.settings.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.enableOffers
// }
// }));
// this.store.dispatch(setChildNodeSettingsECL({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.settings.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.enableOffers
// }
// }));
}
onUpdateFundingPolicy() {

@ -67,7 +67,7 @@ export class NodeConfigComponent implements OnInit, OnDestroy {
}
showLnConfigClicked() {
if (!this.appConfig.sso.rtlSSO) {
if (!this.appConfig.SSO.rtlSSO) {
this.store.dispatch(openAlert({
payload: {
maxWidth: '50rem',

@ -91,7 +91,7 @@
<div fxLayout="column" fxLayoutAlign="start start" class="mt-1">
<div fxLayout="row">
<button class="mr-1" mat-stroked-button color="primary" tabindex="10" (click)="onResetSettings()">Reset</button>
<button mat-flat-button color="primary" tabindex="11" (click)="onUpdateSettings()">Update</button>
<button mat-flat-button color="primary" tabindex="11" (click)="onUpdateNodeSettings()">Update</button>
</div>
</div>
</div>

@ -9,7 +9,7 @@ import { ConfigSettingsNode, Settings } from '../../../models/RTLconfig';
import { LoggerService } from '../../../services/logger.service';
import { CommonService } from '../../../services/common.service';
import { RTLState } from '../../../../store/rtl.state';
import { saveSettings, setSelectedNode } from '../../../../store/rtl.actions';
import { updateNodeSettings, setSelectedNode } from '../../../../store/rtl.actions';
import { setChildNodeSettingsECL } from '../../../../eclair/store/ecl.actions';
import { setChildNodeSettingsCLN } from '../../../../cln/store/cln.actions';
import { setChildNodeSettingsLND } from '../../../../lnd/store/lnd.actions';
@ -97,12 +97,11 @@ export class NodeSettingsComponent implements OnInit, OnDestroy {
this.selNode.settings.themeMode = this.selectedThemeMode.id;
}
onUpdateSettings(): boolean | void {
onUpdateNodeSettings(): boolean | void {
if (this.selNode.settings.fiatConversion && !this.selNode.settings.currencyUnit) {
return true;
}
this.logger.info(this.selNode.settings);
this.store.dispatch(saveSettings({ payload: { uiMessage: UI_MESSAGES.UPDATE_NODE_SETTINGS, settings: this.selNode.settings } }));
this.store.dispatch(setChildNodeSettingsLND({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath,

@ -7,7 +7,7 @@ import { ServicesEnum, UI_MESSAGES } from '../../../../services/consts-enums-fun
import { ConfigSettingsNode } from '../../../../models/RTLconfig';
import { LoggerService } from '../../../../services/logger.service';
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';
import { updateServiceSettings } from '../../../../../store/rtl.actions';
import { updateNodeSettings } from '../../../../../store/rtl.actions';
import { RTLState } from '../../../../../store/rtl.state';
import { setChildNodeSettingsLND } from '../../../../../lnd/store/lnd.actions';
import { setChildNodeSettingsCLN } from '../../../../../cln/store/cln.actions';
@ -69,25 +69,25 @@ export class BoltzServiceSettingsComponent implements OnInit, OnDestroy {
this.logger.info(this.selNode);
this.selNode.settings.boltzServerUrl = this.serverUrl;
this.selNode.authentication.boltzMacaroonPath = this.macaroonPath;
this.store.dispatch(updateServiceSettings({ payload: { uiMessage: UI_MESSAGES.UPDATE_BOLTZ_SETTINGS, service: ServicesEnum.BOLTZ, settings: { enable: this.enableBoltz, serverUrl: this.serverUrl, macaroonPath: this.macaroonPath } } }));
this.store.dispatch(setChildNodeSettingsLND({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.serverUrl, enableOffers: this.selNode.settings.enableOffers
}
}));
this.store.dispatch(setChildNodeSettingsCLN({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.serverUrl, enableOffers: this.selNode.settings.enableOffers
}
}));
this.store.dispatch(setChildNodeSettingsECL({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.serverUrl, enableOffers: this.selNode.settings.enableOffers
}
}));
// this.store.dispatch(updateNodeSettings({ payload: { uiMessage: UI_MESSAGES.UPDATE_BOLTZ_SETTINGS, service: ServicesEnum.BOLTZ, settings: { enable: this.enableBoltz, serverUrl: this.serverUrl, macaroonPath: this.macaroonPath } } }));
// this.store.dispatch(setChildNodeSettingsLND({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.serverUrl, enableOffers: this.selNode.settings.enableOffers
// }
// }));
// this.store.dispatch(setChildNodeSettingsCLN({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.serverUrl, enableOffers: this.selNode.settings.enableOffers
// }
// }));
// this.store.dispatch(setChildNodeSettingsECL({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.serverUrl, enableOffers: this.selNode.settings.enableOffers
// }
// }));
}
onReset() {

@ -7,7 +7,7 @@ import { ServicesEnum, UI_MESSAGES } from '../../../../services/consts-enums-fun
import { ConfigSettingsNode } from '../../../../models/RTLconfig';
import { LoggerService } from '../../../../services/logger.service';
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';
import { updateServiceSettings } from '../../../../../store/rtl.actions';
import { updateNodeSettings } from '../../../../../store/rtl.actions';
import { RTLState } from '../../../../../store/rtl.state';
import { setChildNodeSettingsLND } from '../../../../../lnd/store/lnd.actions';
import { setChildNodeSettingsCLN } from '../../../../../cln/store/cln.actions';
@ -57,25 +57,25 @@ export class LoopServiceSettingsComponent implements OnInit, OnDestroy {
return true;
}
this.logger.info(this.selNode);
this.store.dispatch(updateServiceSettings({ payload: { uiMessage: UI_MESSAGES.UPDATE_LOOP_SETTINGS, service: ServicesEnum.LOOP, settings: { enable: this.enableLoop, serverUrl: this.selNode.settings.swapServerUrl, macaroonPath: this.selNode.authentication.swapMacaroonPath } } }));
this.store.dispatch(setChildNodeSettingsLND({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers
}
}));
this.store.dispatch(setChildNodeSettingsCLN({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers
}
}));
this.store.dispatch(setChildNodeSettingsECL({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers
}
}));
// this.store.dispatch(updateNodeSettings({ payload: { uiMessage: UI_MESSAGES.UPDATE_LOOP_SETTINGS, service: ServicesEnum.LOOP, settings: { enable: this.enableLoop, serverUrl: this.selNode.settings.swapServerUrl, macaroonPath: this.selNode.authentication.swapMacaroonPath } } }));
// this.store.dispatch(setChildNodeSettingsLND({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers
// }
// }));
// this.store.dispatch(setChildNodeSettingsCLN({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers
// }
// }));
// this.store.dispatch(setChildNodeSettingsECL({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers
// }
// }));
}
onReset() {

@ -7,7 +7,7 @@ import { ServicesEnum, UI_MESSAGES } from '../../../../services/consts-enums-fun
import { ConfigSettingsNode } from '../../../../models/RTLconfig';
import { LoggerService } from '../../../../services/logger.service';
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';
import { updateServiceSettings } from '../../../../../store/rtl.actions';
import { updateNodeSettings } from '../../../../../store/rtl.actions';
import { RTLState } from '../../../../../store/rtl.state';
import { setChildNodeSettingsLND } from '../../../../../lnd/store/lnd.actions';
import { setChildNodeSettingsCLN } from '../../../../../cln/store/cln.actions';
@ -39,25 +39,28 @@ export class PeerswapServiceSettingsComponent implements OnInit, OnDestroy {
}
onUpdateService(): boolean | void {
this.store.dispatch(updateServiceSettings({ payload: { uiMessage: UI_MESSAGES.UPDATE_PEERSWAP_SETTINGS, service: ServicesEnum.PEERSWAP, settings: { enablePeerswap: this.enablePeerswap } } }));
this.store.dispatch(setChildNodeSettingsLND({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers, enablePeerswap: this.selNode.settings.enablePeerswap
}
}));
this.store.dispatch(setChildNodeSettingsCLN({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers, enablePeerswap: this.selNode.settings.enablePeerswap
}
}));
this.store.dispatch(setChildNodeSettingsECL({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers, enablePeerswap: this.selNode.settings.enablePeerswap
}
}));
// this.store.dispatch(updateNodeSettings({ payload: { uiMessage: UI_MESSAGES.UPDATE_PEERSWAP_SETTINGS, service: ServicesEnum.PEERSWAP, settings: { enablePeerswap: this.enablePeerswap } } }));
// this.store.dispatch(setChildNodeSettingsLND({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers, enablePeerswap:
// this.selNode.settings.enablePeerswap
// }
// }));
// this.store.dispatch(setChildNodeSettingsCLN({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers, enablePeerswap:
// this.selNode.settings.enablePeerswap
// }
// }));
// this.store.dispatch(setChildNodeSettingsECL({
// payload: {
// userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
// unannouncedChannels: this.selNode.unannouncedChannels, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl, enableOffers: this.selNode.settings.enableOffers, enablePeerswap:
// this.selNode.settings.enablePeerswap
// }
// }));
}
ngOnDestroy() {

@ -21,7 +21,7 @@
<div fxLayout="row" fxLayoutAlign="start start" class="mt-1">
<div fxLayout="row" fxLayoutAlign="start start">
<button class="mr-1" mat-stroked-button color="primary" tabindex="2" (click)="onResetSettings()">Reset</button>
<button mat-flat-button color="primary" tabindex="3" (click)="onUpdateSettings()">Update</button>
<button mat-flat-button color="primary" tabindex="3" (click)="onUpdateApplicationSettings()">Update</button>
</div>
</div>
</div>

@ -9,7 +9,7 @@ import { RTLConfiguration } from '../../../models/RTLconfig';
import { LoggerService } from '../../../services/logger.service';
import { RTLState } from '../../../../store/rtl.state';
import { saveSettings } from '../../../../store/rtl.actions';
import { updateApplicationSettings } from '../../../../store/rtl.actions';
import { rootAppConfig } from '../../../../store/rtl.selector';
@Component({
@ -40,9 +40,9 @@ export class AppSettingsComponent implements OnInit, OnDestroy {
this.logger.warn('ADD NEW NODE');
}
onUpdateSettings(): boolean | void {
onUpdateApplicationSettings(): boolean | void {
const defaultNodeIndex = (this.appConfig.defaultNodeIndex) ? this.appConfig.defaultNodeIndex : (this.appConfig && this.appConfig.nodes && this.appConfig.nodes.length && this.appConfig.nodes.length > 0 && this.appConfig.nodes[0].index) ? +this.appConfig.nodes[0].index : -1;
this.store.dispatch(saveSettings({ payload: { uiMessage: UI_MESSAGES.UPDATE_DEFAULT_NODE_SETTING, defaultNodeIndex: defaultNodeIndex } }));
this.store.dispatch(updateApplicationSettings({ payload: { defaultNodeIndex: defaultNodeIndex } }));
}
onResetSettings() {

@ -7,7 +7,7 @@
<mat-card-content fxLayout="column">
<nav mat-tab-nav-bar mat-stretch-tabs="false" mat-align-tabs="start" [tabPanel]="tabPanel">
<div tabindex="1" role="tab" mat-tab-link class="mat-tab-label" [active]="activeLink === links[0].link" routerLink="{{links[0].link}}" (click)="activeLink = links[0].link">{{links[0].name}}</div>
<div *ngIf="!+appConfig.sso.rtlSSO" tabindex="2" role="tab" mat-tab-link class="mat-tab-label" [active]="activeLink === links[1].link" routerLink="{{links[1].link}}" [state]="{ initial: false }" (click)="activeLink = links[1].link">{{links[1].name}}</div>
<div *ngIf="!+appConfig.SSO.rtlSSO" tabindex="2" role="tab" mat-tab-link class="mat-tab-label" [active]="activeLink === links[1].link" routerLink="{{links[1].link}}" [state]="{ initial: false }" (click)="activeLink = links[1].link">{{links[1].name}}</div>
<div *ngIf="showBitcoind" role="tab" tabindex="3" mat-tab-link class="mat-tab-label" [active]="activeLink === links[2].link" routerLink="{{links[2].link}}" (click)="activeLink = links[2].link">{{links[2].name}}</div>
</nav>
<mat-tab-nav-panel #tabPanel />

@ -58,8 +58,9 @@ export class RTLConfiguration {
constructor(
public defaultNodeIndex: number,
public selectedNodeIndex: number,
public sso: SSO,
public SSO: SSO,
public enable2FA: boolean,
public secret2FA: string,
public allowPasswordUpdate: boolean,
public nodes: ConfigSettingsNode[]
) { }

@ -13,9 +13,8 @@ export interface ApiCallsListRoot {
Login: ApiCallStatusPayload;
IsAuthorized: ApiCallStatusPayload;
FetchRTLConfig?: ApiCallStatusPayload;
UpdateSettings?: ApiCallStatusPayload;
UpdateServiceSettings?: ApiCallStatusPayload;
Update2FASettings?: ApiCallStatusPayload;
UpdateNodeSettings?: ApiCallStatusPayload;
UpdateApplicationSettings?: ApiCallStatusPayload;
fetchConfig?: ApiCallStatusPayload;
VerifyToken?: ApiCallStatusPayload;
ResetPassword?: ApiCallStatusPayload;

@ -1,5 +1,5 @@
import { ServicesEnum } from '../services/consts-enums-functions';
import { ConfigSettingsNode, Settings } from './RTLconfig';
import { ConfigSettingsNode, RTLConfiguration, Settings } from './RTLconfig';
export interface OpenSnackBar {
message: string;
@ -7,12 +7,6 @@ export interface OpenSnackBar {
type?: string;
}
export interface SaveSettings {
uiMessage: string;
settings?: Settings;
defaultNodeIndex?: number;
}
export interface SetSelectedNode {
uiMessage: string;
prevLnNodeIndex: number;
@ -20,10 +14,11 @@ export interface SetSelectedNode {
isInitialSetup: boolean;
}
export interface UpdateServiceSetting {
export interface UpdateNodeSettings {
uiMessage: string;
defaultNodeIndex?: number;
service: ServicesEnum;
settings: any;
settings: Settings;
}
export interface ResetPassword {

@ -357,7 +357,7 @@ export const UI_MESSAGES = {
UPDATE_LOOP_SETTINGS: 'Updating Loop Service Settings...',
UPDATE_PEERSWAP_SETTINGS: 'Updating Peerswap Service Settings...',
UPDATE_SETTING: 'Updating Setting...',
UPDATE_UI_SETTINGS: 'Updating Settings...',
UPDATE_APPLICATION_SETTINGS: 'Updating Application Settings...',
UPDATE_NODE_SETTINGS: 'Updating Node Settings...',
UPDATE_SELECTED_NODE: 'Updating Selected Node...',
OPEN_CONFIG_FILE: 'Opening Config File...',
@ -419,14 +419,13 @@ export enum RTLActions {
SHOW_CONFIG = 'SHOW_CONFIG',
FETCH_STORE = 'FETCH_STORE',
SET_STORE = 'SET_STORE',
FETCH_RTL_CONFIG = 'FETCH_RTL_CONFIG',
SET_RTL_CONFIG = 'SET_RTL_CONFIG',
SAVE_SSO = 'SAVE_SSO',
FETCH_APPLICATION_SETTINGS = 'FETCH_APPLICATION_SETTINGS',
SET_APPLICATION_SETTINGS = 'SET_APPLICATION_SETTINGS',
SAVE_SETTINGS = 'SAVE_SETTINGS',
TWO_FA_SAVE_SETTINGS = 'TWO_FA_SAVE_SETTINGS',
SET_SELECTED_NODE = 'SET_SELECTED_NODE',
UPDATE_ROOT_NODE_SETTINGS = 'UPDATE_ROOT_NODE_SETTINGS',
UPDATE_SERVICE_SETTINGS = 'UPDATE_SERVICE_SETTINGS',
UPDATE_APPLICATION_SETTINGS = 'UPDATE_APPLICATION_SETTINGS',
UPDATE_NODE_SETTINGS = 'UPDATE_NODE_SETTINGS',
SET_NODE_DATA = 'SET_NODE_DATA',
IS_AUTHORIZED = 'IS_AUTHORIZED',
IS_AUTHORIZED_RES = 'IS_AUTHORIZED_RES',

@ -2,8 +2,8 @@ import { createAction, props } from '@ngrx/store';
import { DialogConfig } from '../shared/models/alertData';
import { ApiCallStatusPayload } from '../shared/models/apiCallsPayload';
import { RTLConfiguration, ConfigSettingsNode, GetInfoRoot, SSO } from '../shared/models/RTLconfig';
import { FetchFile, Login, OpenSnackBar, ResetPassword, SaveSettings, SetSelectedNode, UpdateServiceSetting, VerifyTwoFA } from '../shared/models/rtlModels';
import { RTLConfiguration, ConfigSettingsNode, GetInfoRoot } from '../shared/models/RTLconfig';
import { FetchFile, Login, OpenSnackBar, ResetPassword, SetSelectedNode, UpdateNodeSettings, VerifyTwoFA } from '../shared/models/rtlModels';
import { RTLActions } from '../shared/services/consts-enums-functions';
export const voidAction = createAction(RTLActions.VOID);
@ -38,24 +38,18 @@ export const updateSelectedNodeOptions = createAction(RTLActions.UPDATE_SELECTED
export const resetRootStore = createAction(RTLActions.RESET_ROOT_STORE, props<{ payload: ConfigSettingsNode }>());
export const fetchRTLConfig = createAction(RTLActions.FETCH_RTL_CONFIG);
export const fetchRTLConfig = createAction(RTLActions.FETCH_APPLICATION_SETTINGS);
export const setRTLConfig = createAction(RTLActions.SET_RTL_CONFIG, props<{ payload: RTLConfiguration }>());
export const saveSettings = createAction(RTLActions.SAVE_SETTINGS, props<{ payload: SaveSettings }>());
export const twoFASaveSettings = createAction(RTLActions.TWO_FA_SAVE_SETTINGS, props<{ payload: { secret2fa: string } }>());
export const setApplicationSettings = createAction(RTLActions.SET_APPLICATION_SETTINGS, props<{ payload: RTLConfiguration }>());
export const setSelectedNode = createAction(RTLActions.SET_SELECTED_NODE, props<{ payload: SetSelectedNode }>());
export const updateRootNodeSettings = createAction(RTLActions.UPDATE_ROOT_NODE_SETTINGS, props<{ payload: UpdateServiceSetting }>());
export const updateNodeSettings = createAction(RTLActions.UPDATE_NODE_SETTINGS, props<{ payload: UpdateNodeSettings }>());
export const updateServiceSettings = createAction(RTLActions.UPDATE_SERVICE_SETTINGS, props<{ payload: UpdateServiceSetting }>());
export const updateApplicationSettings = createAction(RTLActions.UPDATE_APPLICATION_SETTINGS, props<{ payload: RTLConfiguration }>());
export const setNodeData = createAction(RTLActions.SET_NODE_DATA, props<{ payload: GetInfoRoot }>());
export const saveSSO = createAction(RTLActions.SAVE_SSO, props<{ payload: SSO }>());
export const logout = createAction(RTLActions.LOGOUT);
export const resetPassword = createAction(RTLActions.RESET_PASSWORD, props<{ payload: ResetPassword }>());

@ -14,10 +14,10 @@ import { LoggerService } from '../shared/services/logger.service';
import { SessionService } from '../shared/services/session.service';
import { CommonService } from '../shared/services/common.service';
import { DataService } from '../shared/services/data.service';
import { RTLConfiguration, Settings, ConfigSettingsNode, GetInfoRoot } from '../shared/models/RTLconfig';
import { RTLConfiguration, ConfigSettingsNode, GetInfoRoot } from '../shared/models/RTLconfig';
import { API_URL, API_END_POINTS, RTLActions, APICallStatusEnum, AuthenticateWith, CURRENCY_UNITS, ScreenSizeEnum, UI_MESSAGES } from '../shared/services/consts-enums-functions';
import { DialogConfig } from '../shared/models/alertData';
import { FetchFile, Login, OpenSnackBar, ResetPassword, SaveSettings, SetSelectedNode, UpdateServiceSetting, VerifyTwoFA } from '../shared/models/rtlModels';
import { FetchFile, Login, OpenSnackBar, ResetPassword, UpdateNodeSettings, SetSelectedNode, VerifyTwoFA } from '../shared/models/rtlModels';
import { SpinnerDialogComponent } from '../shared/components/data-modal/spinner-dialog/spinner-dialog.component';
import { AlertMessageComponent } from '../shared/components/data-modal/alert-message/alert-message.component';
@ -26,7 +26,7 @@ import { ErrorMessageComponent } from '../shared/components/data-modal/error-mes
import { ShowPubkeyComponent } from '../shared/components/data-modal/show-pubkey/show-pubkey.component';
import { RTLState } from './rtl.state';
import { resetRootStore, setNodeData, setSelectedNode, updateRootAPICallStatus, closeSpinner, openAlert, openSpinner, openSnackBar, fetchRTLConfig, closeAllDialogs, logout, updateRootNodeSettings, setRTLConfig } from './rtl.actions';
import { resetRootStore, setNodeData, setSelectedNode, updateRootAPICallStatus, closeSpinner, openAlert, openSpinner, openSnackBar, fetchRTLConfig, closeAllDialogs, logout } from './rtl.actions';
import { fetchInfoLND, resetLNDStore, fetchPageSettings as fetchPageSettingsLND } from '../lnd/store/lnd.actions';
import { fetchInfoCLN, resetCLNStore, fetchPageSettings as fetchPageSettingsCLN } from '../cln/store/cln.actions';
import { fetchInfoECL, resetECLStore, fetchPageSettings as fetchPageSettingsECL } from '../eclair/store/ecl.actions';
@ -197,7 +197,7 @@ export class RTLEffects implements OnDestroy {
appConfigFetch = createEffect(
() => this.actions.pipe(
ofType(RTLActions.FETCH_RTL_CONFIG),
ofType(RTLActions.FETCH_APPLICATION_SETTINGS),
mergeMap(() => {
this.screenSize = this.commonService.getScreenSize();
if (this.screenSize === ScreenSizeEnum.XS || this.screenSize === ScreenSizeEnum.SM) {
@ -212,12 +212,7 @@ export class RTLEffects implements OnDestroy {
}
this.store.dispatch(openSpinner({ payload: UI_MESSAGES.GET_RTL_CONFIG }));
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'FetchRTLConfig', status: APICallStatusEnum.INITIATED } }));
return this.httpClient.get<RTLConfiguration>(API_END_POINTS.CONF_API + '/rtlconf');
// if (this.sessionService.getItem('token')) {
// return this.httpClient.get<RTLConfiguration>(API_END_POINTS.CONF_API + '/rtlconf');
// } else {
// return this.httpClient.get<RTLConfiguration>(API_END_POINTS.CONF_API + '/rtlconf/true'); // Initial configuration
// }
return this.httpClient.get<RTLConfiguration>(API_END_POINTS.CONF_API);
}),
map((rtlConfig: RTLConfiguration) => {
this.logger.info(rtlConfig);
@ -233,7 +228,7 @@ export class RTLEffects implements OnDestroy {
if (searchNode) {
this.store.dispatch(setSelectedNode({ payload: { uiMessage: UI_MESSAGES.NO_SPINNER, prevLnNodeIndex: -1, currentLnNode: searchNode, isInitialSetup: true } }));
return {
type: RTLActions.SET_RTL_CONFIG,
type: RTLActions.SET_APPLICATION_SETTINGS,
payload: rtlConfig
};
} else {
@ -248,85 +243,58 @@ export class RTLEffects implements OnDestroy {
}))
);
settingSave = createEffect(
updataNodeSettings = createEffect(
() => this.actions.pipe(
ofType(RTLActions.SAVE_SETTINGS),
mergeMap((action: { type: string, payload: SaveSettings }) => {
ofType(RTLActions.UPDATE_NODE_SETTINGS),
mergeMap((action: { type: string, payload: UpdateNodeSettings }) => {
this.store.dispatch(openSpinner({ payload: action.payload.uiMessage }));
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'UpdateSettings', status: APICallStatusEnum.INITIATED } }));
let updateSettingReq = new Observable();
if (action.payload.settings && action.payload.defaultNodeIndex) {
const settingsRes = this.httpClient.post<Settings>(API_END_POINTS.CONF_API, { updatedSettings: action.payload.settings });
const defaultNodeRes = this.httpClient.post(API_END_POINTS.CONF_API + '/updateDefaultNode', { defaultNodeIndex: action.payload.defaultNodeIndex });
updateSettingReq = forkJoin([settingsRes, defaultNodeRes]);
} else if (action.payload.settings && !action.payload.defaultNodeIndex) {
updateSettingReq = this.httpClient.post(API_END_POINTS.CONF_API, { updatedSettings: action.payload.settings });
} else if (!action.payload.settings && action.payload.defaultNodeIndex) {
updateSettingReq = this.httpClient.post(API_END_POINTS.CONF_API + '/updateDefaultNode', { defaultNodeIndex: action.payload.defaultNodeIndex });
}
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'UpdateNodeSettings', status: APICallStatusEnum.INITIATED } }));
const updateSettingReq = new Observable();
// if (action.payload.settings && action.payload.defaultNodeIndex) {
// const settingsRes = this.httpClient.post<Settings>(API_END_POINTS.CONF_API, { UpdateNodeSettings: action.payload.settings });
// const defaultNodeRes = this.httpClient.post(API_END_POINTS.CONF_API + '/node', { defaultNodeIndex: action.payload.defaultNodeIndex });
// updateSettingReq = forkJoin([settingsRes, defaultNodeRes]);
// } else if (action.payload.settings && !action.payload.defaultNodeIndex) {
// updateSettingReq = this.httpClient.post(API_END_POINTS.CONF_API, { UpdateNodeSettings: action.payload.settings });
// } else if (!action.payload.settings && action.payload.defaultNodeIndex) {
// updateSettingReq = this.httpClient.post(API_END_POINTS.CONF_API + '/node', { defaultNodeIndex: action.payload.defaultNodeIndex });
// }
return updateSettingReq.pipe(map((updateStatus: any) => {
this.logger.info(updateStatus);
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'UpdateSettings', status: APICallStatusEnum.COMPLETED } }));
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'UpdateNodeSettings', status: APICallStatusEnum.COMPLETED } }));
this.store.dispatch(closeSpinner({ payload: action.payload.uiMessage }));
return {
type: RTLActions.OPEN_SNACK_BAR,
payload: (!updateStatus.length) ? updateStatus.message + '.' : updateStatus[0].message + '.'
};
}), catchError((err) => {
this.handleErrorWithAlert('UpdateSettings', action.payload.uiMessage, 'Update Settings Failed!', API_END_POINTS.CONF_API, (!err.length) ? err : err[0]);
this.handleErrorWithAlert('UpdateNodeSettings', action.payload.uiMessage, 'Update Node Settings Failed!', API_END_POINTS.CONF_API, (!err.length) ? err : err[0]);
return of({ type: RTLActions.VOID });
}));
}))
);
updateServicesettings = createEffect(
updateApplicationSettings = createEffect(
() => this.actions.pipe(
ofType(RTLActions.UPDATE_SERVICE_SETTINGS),
mergeMap((action: { type: string, payload: UpdateServiceSetting }) => {
this.store.dispatch(openSpinner({ payload: action.payload.uiMessage }));
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'UpdateServiceSettings', status: APICallStatusEnum.INITIATED } }));
return this.httpClient.post(API_END_POINTS.CONF_API + '/updateServiceSettings', action.payload).pipe(
map((updateStatus: any) => {
this.logger.info(updateStatus);
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'UpdateServiceSettings', status: APICallStatusEnum.COMPLETED } }));
this.store.dispatch(closeSpinner({ payload: action.payload.uiMessage }));
this.store.dispatch(updateRootNodeSettings({ payload: action.payload }));
ofType(RTLActions.UPDATE_APPLICATION_SETTINGS),
mergeMap((action: { type: string, payload: RTLConfiguration }) => {
this.store.dispatch(openSpinner({ payload: UI_MESSAGES.UPDATE_APPLICATION_SETTINGS }));
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'updateApplicationSettings', status: APICallStatusEnum.INITIATED } }));
return this.httpClient.post(API_END_POINTS.CONF_API + '/application', action.payload).
pipe(map((appConfig: RTLConfiguration) => {
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'updateApplicationSettings', status: APICallStatusEnum.COMPLETED } }));
this.store.dispatch(closeSpinner({ payload: UI_MESSAGES.UPDATE_APPLICATION_SETTINGS }));
return {
type: RTLActions.OPEN_SNACK_BAR,
payload: updateStatus.message + '.'
type: RTLActions.SET_APPLICATION_SETTINGS,
payload: appConfig
};
}),
catchError((err) => {
this.handleErrorWithAlert('UpdateServiceSettings', action.payload.uiMessage, 'Update Service Settings Failed!', API_END_POINTS.CONF_API, err);
}), catchError((err: any) => {
this.handleErrorWithAlert('updateApplicationSettings', UI_MESSAGES.UPDATE_APPLICATION_SETTINGS, 'Update Application Settings Failed!', API_END_POINTS.CONF_API + '/config/' + action.payload, err);
return of({ type: RTLActions.VOID });
})
);
}));
}))
);
twoFASettingSave = createEffect(
() => this.actions.pipe(
ofType(RTLActions.TWO_FA_SAVE_SETTINGS),
mergeMap((action: { type: string, payload: { secret2fa: string } }) => {
this.store.dispatch(openSpinner({ payload: UI_MESSAGES.UPDATE_UI_SETTINGS }));
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'Update2FASettings', status: APICallStatusEnum.INITIATED } }));
return this.httpClient.post(API_END_POINTS.CONF_API + '/update2FA', { secret2fa: action.payload.secret2fa });
}),
withLatestFrom(this.store.select(rootAppConfig)),
map(([updateStatus, appConfig]: [any, RTLConfiguration]) => {
this.logger.info(updateStatus);
appConfig.enable2FA = !appConfig.enable2FA;
this.store.dispatch(updateRootAPICallStatus({ payload: { action: 'Update2FASettings', status: APICallStatusEnum.COMPLETED } }));
this.store.dispatch(closeSpinner({ payload: UI_MESSAGES.UPDATE_UI_SETTINGS }));
this.store.dispatch(setRTLConfig({ payload: appConfig }));
}),
catchError((err) => {
this.handleErrorWithAlert('Update2FASettings', UI_MESSAGES.UPDATE_UI_SETTINGS, 'Update 2FA Settings Failed!', API_END_POINTS.CONF_API, err);
return of({ type: RTLActions.VOID });
})),
{ dispatch: false }
);
configFetch = createEffect(
() => this.actions.pipe(
ofType(RTLActions.FETCH_CONFIG),
@ -410,7 +378,7 @@ export class RTLEffects implements OnDestroy {
catchError((err) => {
this.logger.info('Redirecting to Login Error Page');
this.handleErrorWithoutAlert('Login', UI_MESSAGES.NO_SPINNER, err);
if (+appConfig.sso.rtlSSO) {
if (+appConfig.SSO.rtlSSO) {
this.router.navigate(['/error'], { state: { errorCode: '406', errorMessage: err.error && err.error.error ? err.error.error : 'Single Sign On Failed!' } });
} else {
this.router.navigate(['./login']);
@ -450,8 +418,8 @@ export class RTLEffects implements OnDestroy {
ofType(RTLActions.LOGOUT),
mergeMap((appConfig: RTLConfiguration) => {
this.store.dispatch(openSpinner({ payload: UI_MESSAGES.LOG_OUT }));
if (appConfig.sso && +appConfig.sso.rtlSSO) {
window.location.href = appConfig.sso.logoutRedirectLink;
if (appConfig.SSO && +appConfig.SSO.rtlSSO) {
window.location.href = appConfig.SSO.logoutRedirectLink;
} else {
this.router.navigate(['./login']);
}

@ -1,7 +1,7 @@
import { createReducer, on } from '@ngrx/store';
import { initRootState } from './rtl.state';
import { resetRootStore, setNodeData, setRTLConfig, setSelectedNode, updateRootAPICallStatus, updateRootNodeSettings } from './rtl.actions';
import { resetRootStore, setNodeData, setApplicationSettings, setSelectedNode, updateRootAPICallStatus } from './rtl.actions';
import { ServicesEnum } from '../shared/services/consts-enums-functions';
import { ConfigSettingsNode } from '../shared/models/RTLconfig';
@ -32,35 +32,11 @@ export const RootReducer = createReducer(initRootState,
...state,
selNode: payload.currentLnNode
})),
on(updateRootNodeSettings, (state, { payload }) => {
const updatedSelNode: ConfigSettingsNode = JSON.parse(JSON.stringify(state.selNode));
switch (payload.service) {
case ServicesEnum.BOLTZ:
updatedSelNode.settings.boltzServerUrl = payload.settings.boltzServerUrl;
break;
case ServicesEnum.LOOP:
updatedSelNode.settings.swapServerUrl = payload.settings.swapServerUrl;
break;
case ServicesEnum.OFFERS:
updatedSelNode.settings.enableOffers = payload.settings.enableOffers;
break;
case ServicesEnum.PEERSWAP:
updatedSelNode.settings.enablePeerswap = payload.settings.enablePeerswap;
break;
default:
break;
}
return {
...state,
selNode: updatedSelNode
};
}),
on(setNodeData, (state, { payload }) => ({
...state,
nodeData: payload
})),
on(setRTLConfig, (state, { payload }) => ({
on(setApplicationSettings, (state, { payload }) => ({
...state,
appConfig: payload
}))

@ -24,8 +24,9 @@ export const initRootState: RootState = {
appConfig: {
defaultNodeIndex: -1,
selectedNodeIndex: -1,
sso: { rtlSSO: 0, logoutRedirectLink: '' },
SSO: { rtlSSO: 0, logoutRedirectLink: '' },
enable2FA: false,
secret2FA: '',
allowPasswordUpdate: true,
nodes: [{ settings: initNodeSettings, authentication: initNodeAuthentication }]
},

Loading…
Cancel
Save