2021-10-28 20:34:48 +00:00
|
|
|
import { Inject, Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
|
|
|
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
2022-03-07 19:46:00 +00:00
|
|
|
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
|
2022-07-13 12:20:47 +00:00
|
|
|
import { UntypedFormBuilder, Validators, UntypedFormGroup, FormControl } from '@angular/forms';
|
2022-07-18 23:41:31 +00:00
|
|
|
import { User } from '../user.model';
|
|
|
|
import { Owner } from '../owner.model';
|
2021-10-28 20:34:48 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-settings',
|
|
|
|
templateUrl: './settings.component.html',
|
|
|
|
styleUrls: ['/settings.component.css']
|
|
|
|
})
|
|
|
|
|
|
|
|
export class SettingsComponent implements OnInit {
|
|
|
|
|
2022-07-13 12:20:47 +00:00
|
|
|
settingsForm: UntypedFormGroup;
|
2021-10-28 20:34:48 +00:00
|
|
|
owner: Owner;
|
2022-03-07 19:46:00 +00:00
|
|
|
useZats: boolean;
|
2022-07-20 01:48:52 +00:00
|
|
|
useVKey: boolean = false;
|
2021-11-22 20:37:45 +00:00
|
|
|
coins = [
|
|
|
|
{
|
|
|
|
label: 'US Dollar',
|
|
|
|
symbol: 'usd'
|
|
|
|
},{
|
|
|
|
label: 'Euro',
|
|
|
|
symbol: 'eur'
|
|
|
|
},{
|
|
|
|
label: 'British Pound',
|
|
|
|
symbol: 'gbp'
|
|
|
|
},{
|
|
|
|
label: 'Canadian Dollar',
|
|
|
|
symbol: 'cad'
|
|
|
|
},{
|
|
|
|
label: 'Australian Dollar',
|
|
|
|
symbol: 'aud'
|
|
|
|
}
|
|
|
|
];
|
2021-10-28 20:34:48 +00:00
|
|
|
|
2022-07-20 01:48:52 +00:00
|
|
|
viewkeyControl = new FormControl({ value: null, disabled: true });
|
|
|
|
|
2021-10-28 20:34:48 +00:00
|
|
|
constructor(
|
2022-07-13 12:20:47 +00:00
|
|
|
private fb: UntypedFormBuilder,
|
2021-10-28 20:34:48 +00:00
|
|
|
private dialogRef: MatDialogRef<SettingsComponent>,
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data: Owner
|
|
|
|
) {
|
2022-03-07 19:46:00 +00:00
|
|
|
this.useZats = data.zats;
|
2021-10-28 20:34:48 +00:00
|
|
|
this.settingsForm = fb.group({
|
2021-11-22 20:37:45 +00:00
|
|
|
name: [data.name, Validators.required],
|
2022-03-07 19:46:00 +00:00
|
|
|
currency: [data.currency, Validators.required],
|
2022-07-20 01:48:52 +00:00
|
|
|
useZats: [data.zats, Validators.required],
|
|
|
|
VkeyOn: [data.payconf, Validators.required],
|
|
|
|
VKey: [{value:data.viewkey, disabled: true },
|
|
|
|
Validators.required
|
|
|
|
]
|
2021-10-28 20:34:48 +00:00
|
|
|
});
|
|
|
|
this.owner = data;
|
2022-07-20 01:48:52 +00:00
|
|
|
|
2021-10-28 20:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
save() {
|
|
|
|
this.owner.name = this.settingsForm.value.name;
|
2021-11-22 20:37:45 +00:00
|
|
|
this.owner.currency = this.settingsForm.value.currency;
|
2022-07-20 01:48:52 +00:00
|
|
|
this.owner.zats = this.settingsForm.value.useZats;
|
|
|
|
this.owner.payconf = this.useVKey;
|
|
|
|
if ( this.settingsForm.value.VkeyOn ) {
|
|
|
|
this.owner.viewkey = this.settingsForm.value.VKey;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.owner.viewkey = '';
|
2021-10-28 20:34:48 +00:00
|
|
|
this.dialogRef.close(this.owner);
|
|
|
|
}
|
2022-03-07 19:46:00 +00:00
|
|
|
|
|
|
|
onChange(ob: MatSlideToggleChange) {
|
|
|
|
this.useZats = ob.checked;
|
|
|
|
}
|
2022-07-18 23:41:31 +00:00
|
|
|
|
|
|
|
onChangeVKeyOn(ob: MatSlideToggleChange) {
|
2022-07-20 01:48:52 +00:00
|
|
|
console.log("Viewing key switch is " +
|
|
|
|
( ob.checked ? "[ON]." : "[OFF]." ) );
|
|
|
|
|
|
|
|
this.useVKey = ob.checked;
|
|
|
|
|
|
|
|
if ( ob.checked )
|
|
|
|
this.viewkeyControl.enable()
|
|
|
|
else
|
|
|
|
this.viewkeyControl.disable();
|
|
|
|
|
2022-07-18 23:41:31 +00:00
|
|
|
}
|
2021-10-28 20:34:48 +00:00
|
|
|
}
|