2
0
mirror of https://github.com/Ride-The-Lightning/RTL synced 2024-10-31 09:20:27 +00:00
RTL/src/app/shared/components/node-config/node-settings/node-settings.component.ts

133 lines
7.2 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { faMoneyBillAlt, faPaintBrush, faInfoCircle, faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
import { CURRENCY_UNITS, UserPersonaEnum, ScreenSizeEnum, FIAT_CURRENCY_UNITS, NODE_SETTINGS, UI_MESSAGES } from '../../../services/consts-enums-functions';
import { ConfigSettingsNode, Settings } from '../../../models/RTLconfig';
import { LoggerService } from '../../../services/logger.service';
import { CommonService } from '../../../services/common.service';
2021-12-29 23:08:41 +00:00
import { RTLState } from '../../../../store/rtl.state';
import { saveSettings, setSelectedNode } from '../../../../store/rtl.actions';
import { setChildNodeSettingsECL } from '../../../../eclair/store/ecl.actions';
import { setChildNodeSettingsCL } from '../../../../cln/store/cln.actions';
2021-12-29 23:08:41 +00:00
import { setChildNodeSettingsLND } from '../../../../lnd/store/lnd.actions';
import { rootSelectedNode } from '../../../../store/rtl.selector';
@Component({
selector: 'rtl-node-settings',
templateUrl: './node-settings.component.html',
styleUrls: ['./node-settings.component.scss']
})
export class NodeSettingsComponent implements OnInit, OnDestroy {
2021-08-28 21:03:18 +00:00
public faExclamationTriangle = faExclamationTriangle;
public faMoneyBillAlt = faMoneyBillAlt;
public faPaintBrush = faPaintBrush;
public faInfoCircle = faInfoCircle;
public selNode: ConfigSettingsNode;
public userPersonas = [UserPersonaEnum.OPERATOR, UserPersonaEnum.MERCHANT];
public currencyUnits = FIAT_CURRENCY_UNITS;
public themeModes = NODE_SETTINGS.modes;
public themeColors = NODE_SETTINGS.themes;
public selectedThemeMode = NODE_SETTINGS.modes[0];
public selectedThemeColor = NODE_SETTINGS.themes[0].id;
public currencyUnit = 'BTC';
public smallerCurrencyUnit = 'Sats';
public showSettingOption = true;
public previousSettings: Settings;
public screenSize = '';
public screenSizeEnum = ScreenSizeEnum;
unSubs: Array<Subject<void>> = [new Subject(), new Subject()];
2021-12-29 23:08:41 +00:00
constructor(private logger: LoggerService, private commonService: CommonService, private store: Store<RTLState>) {
this.screenSize = this.commonService.getScreenSize();
}
ngOnInit() {
2021-12-29 23:08:41 +00:00
this.store.select(rootSelectedNode).pipe(takeUntil(this.unSubs[0])).subscribe((selNode) => {
this.selNode = selNode;
this.selectedThemeMode = this.themeModes.find((themeMode) => this.selNode.settings.themeMode === themeMode.id) || this.themeModes[0];
2021-12-29 23:08:41 +00:00
this.selectedThemeColor = this.selNode.settings.themeColor;
if (!this.selNode.settings.fiatConversion) {
this.selNode.settings.currencyUnit = '';
2021-12-29 23:08:41 +00:00
}
this.previousSettings = JSON.parse(JSON.stringify(this.selNode.settings));
this.logger.info(selNode);
});
}
onCurrencyChange(event: any) {
this.selNode.settings.currencyUnits = [...CURRENCY_UNITS, event.value];
2021-12-29 23:08:41 +00:00
this.store.dispatch(setChildNodeSettingsLND({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: event.value, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
}
2021-08-28 21:03:18 +00:00
}));
2021-12-29 23:08:41 +00:00
this.store.dispatch(setChildNodeSettingsCL({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: event.value, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
}
2021-08-28 21:03:18 +00:00
}));
2021-12-29 23:08:41 +00:00
this.store.dispatch(setChildNodeSettingsECL({
payload: {
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: event.value, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
}
2021-08-28 21:03:18 +00:00
}));
}
toggleSettings(toggleField: string, event?: any) {
this.selNode.settings[toggleField] = !this.selNode.settings[toggleField];
}
changeThemeColor(newThemeColor: string) {
this.selectedThemeColor = newThemeColor;
this.selNode.settings.themeColor = newThemeColor;
}
chooseThemeMode() {
this.selNode.settings.themeMode = this.selectedThemeMode.id;
}
2021-08-28 21:03:18 +00:00
onUpdateSettings(): boolean | void {
if (this.selNode.settings.fiatConversion && !this.selNode.settings.currencyUnit) {
return true;
}
this.logger.info(this.selNode.settings);
2021-12-29 23:08:41 +00:00
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, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
}
2021-08-28 21:03:18 +00:00
}));
2021-12-29 23:08:41 +00:00
this.store.dispatch(setChildNodeSettingsCL({
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, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
}
2021-08-28 21:03:18 +00:00
}));
2021-12-29 23:08:41 +00:00
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, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
}
2021-08-28 21:03:18 +00:00
}));
}
onResetSettings() {
const prevIndex = this.selNode.index || -1;
this.selNode.settings = this.previousSettings;
this.selectedThemeMode = this.themeModes.find((themeMode) => themeMode.id === this.previousSettings.themeMode) || this.themeModes[0];
this.selectedThemeColor = this.previousSettings.themeColor;
2021-12-29 23:08:41 +00:00
this.store.dispatch(setSelectedNode({ payload: { uiMessage: UI_MESSAGES.NO_SPINNER, prevLnNodeIndex: +prevIndex, currentLnNode: this.selNode, isInitialSetup: true } }));
2021-08-28 21:03:18 +00:00
}
ngOnDestroy() {
2021-08-28 21:03:18 +00:00
this.unSubs.forEach((unsub) => {
unsub.next();
unsub.complete();
});
}
}