2021-02-21 19:02:31 +00:00
|
|
|
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';
|
|
|
|
|
2021-12-29 23:08:41 +00:00
|
|
|
import { CURRENCY_UNITS, UserPersonaEnum, ScreenSizeEnum, FIAT_CURRENCY_UNITS, NODE_SETTINGS, UI_MESSAGES, RTLActions } from '../../../services/consts-enums-functions';
|
2021-02-21 19:02:31 +00:00
|
|
|
import { ConfigSettingsNode, Settings, RTLConfiguration, GetInfoRoot } 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';
|
2022-05-01 17:35:20 +00:00
|
|
|
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';
|
|
|
|
import { SetSelectedNode } from '../../../models/rtlModels';
|
2021-02-21 19:02:31 +00:00
|
|
|
|
|
|
|
@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
|
|
|
|
2021-02-21 19:02:31 +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>) {
|
2021-02-21 19:02:31 +00:00
|
|
|
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.selectedThemeColor = this.selNode.settings.themeColor;
|
|
|
|
if (!this.selNode.settings.fiatConversion) {
|
|
|
|
this.selNode.settings.currencyUnit = null;
|
|
|
|
}
|
|
|
|
this.previousSettings = JSON.parse(JSON.stringify(this.selNode.settings));
|
|
|
|
this.logger.info(selNode);
|
|
|
|
});
|
2021-02-21 19:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}));
|
2021-02-21 19:02:31 +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;
|
|
|
|
}
|
2021-02-21 19:02:31 +00:00
|
|
|
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
|
|
|
}));
|
2021-02-21 19:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onResetSettings() {
|
2021-12-29 23:08:41 +00:00
|
|
|
const prevIndex = this.selNode.index;
|
2021-02-21 19:02:31 +00:00
|
|
|
this.selNode.settings = this.previousSettings;
|
2021-08-28 21:03:18 +00:00
|
|
|
this.selectedThemeMode = this.themeModes.find((themeMode) => themeMode.id === this.previousSettings.themeMode);
|
2021-02-21 19:02:31 +00:00
|
|
|
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
|
|
|
}
|
2021-02-21 19:02:31 +00:00
|
|
|
|
|
|
|
ngOnDestroy() {
|
2021-08-28 21:03:18 +00:00
|
|
|
this.unSubs.forEach((unsub) => {
|
2021-02-21 19:02:31 +00:00
|
|
|
unsub.next();
|
|
|
|
unsub.complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|