Add fee rate unit preference & dropdown

This commit is contained in:
Mononaut
2023-06-15 15:15:20 -04:00
parent 408c86963b
commit a45f1fde1c
6 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
<div [formGroup]="rateUnitForm" class="text-small text-center">
<select formControlName="rateUnits" class="custom-select custom-select-sm form-control-secondary form-control mx-auto" style="width: 200px;" (change)="changeUnits()">
<option *ngFor="let unit of units" [value]="unit.name">{{ unit.label }}</option>
</select>
</div>

View File

@@ -0,0 +1,45 @@
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { StorageService } from '../../services/storage.service';
import { StateService } from '../../services/state.service';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-rate-unit-selector',
templateUrl: './rate-unit-selector.component.html',
styleUrls: ['./rate-unit-selector.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class RateUnitSelectorComponent implements OnInit, OnDestroy {
rateUnitForm: UntypedFormGroup;
rateUnitSub: Subscription;
units = [
{ name: 'vb', label: 'sat/vB' },
{ name: 'wu', label: 'sat/WU' },
];
constructor(
private formBuilder: UntypedFormBuilder,
private stateService: StateService,
private storageService: StorageService,
) { }
ngOnInit() {
this.rateUnitForm = this.formBuilder.group({
rateUnits: ['vb']
});
this.rateUnitSub = this.stateService.rateUnits$.subscribe((units) => {
this.rateUnitForm.get('rateUnits')?.setValue(units);
});
}
changeUnits() {
const newUnits = this.rateUnitForm.get('rateUnits')?.value;
this.storageService.setValue('rate-unit-preference', newUnits);
this.stateService.rateUnits$.next(newUnits);
}
ngOnDestroy(): void {
this.rateUnitSub.unsubscribe();
}
}