|
|
@ -15,9 +15,11 @@ import {
|
|
|
|
FormControl,
|
|
|
|
FormControl,
|
|
|
|
FormGroup,
|
|
|
|
FormGroup,
|
|
|
|
ValidationErrors,
|
|
|
|
ValidationErrors,
|
|
|
|
|
|
|
|
ValidatorFn,
|
|
|
|
Validators
|
|
|
|
Validators
|
|
|
|
} from '@angular/forms';
|
|
|
|
} from '@angular/forms';
|
|
|
|
import { MatDialogRef } from '@angular/material/dialog';
|
|
|
|
import { MatDialogRef } from '@angular/material/dialog';
|
|
|
|
|
|
|
|
import { isISO4217CurrencyCode } from 'class-validator';
|
|
|
|
import { uniq } from 'lodash';
|
|
|
|
import { uniq } from 'lodash';
|
|
|
|
import { Subject, takeUntil } from 'rxjs';
|
|
|
|
import { Subject, takeUntil } from 'rxjs';
|
|
|
|
|
|
|
|
|
|
|
@ -52,9 +54,7 @@ export class CreateAssetProfileDialog implements OnInit, OnDestroy {
|
|
|
|
this.createAssetProfileForm = this.formBuilder.group(
|
|
|
|
this.createAssetProfileForm = this.formBuilder.group(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
addCurrency: new FormControl(null, [
|
|
|
|
addCurrency: new FormControl(null, [
|
|
|
|
Validators.maxLength(3),
|
|
|
|
this.iso4217CurrencyCodeValidator()
|
|
|
|
Validators.minLength(3),
|
|
|
|
|
|
|
|
Validators.required
|
|
|
|
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
addSymbol: new FormControl(null, [Validators.required]),
|
|
|
|
addSymbol: new FormControl(null, [Validators.required]),
|
|
|
|
searchSymbol: new FormControl(null, [Validators.required])
|
|
|
|
searchSymbol: new FormControl(null, [Validators.required])
|
|
|
@ -83,11 +83,11 @@ export class CreateAssetProfileDialog implements OnInit, OnDestroy {
|
|
|
|
symbol: this.createAssetProfileForm.get('searchSymbol').value.symbol
|
|
|
|
symbol: this.createAssetProfileForm.get('searchSymbol').value.symbol
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else if (this.mode === 'currency') {
|
|
|
|
} else if (this.mode === 'currency') {
|
|
|
|
const currency = this.createAssetProfileForm
|
|
|
|
const currency = (
|
|
|
|
.get('addCurrency')
|
|
|
|
this.createAssetProfileForm.get('addCurrency').value as string
|
|
|
|
.value.toUpperCase();
|
|
|
|
).toUpperCase();
|
|
|
|
|
|
|
|
|
|
|
|
const currencies = uniq([...this.customCurrencies, currency]);
|
|
|
|
const currencies = uniq([...this.customCurrencies, currency]).sort();
|
|
|
|
|
|
|
|
|
|
|
|
this.dataService
|
|
|
|
this.dataService
|
|
|
|
.putAdminSetting(PROPERTY_CURRENCIES, {
|
|
|
|
.putAdminSetting(PROPERTY_CURRENCIES, {
|
|
|
@ -109,10 +109,7 @@ export class CreateAssetProfileDialog implements OnInit, OnDestroy {
|
|
|
|
const addCurrencyFormControl =
|
|
|
|
const addCurrencyFormControl =
|
|
|
|
this.createAssetProfileForm.get('addCurrency');
|
|
|
|
this.createAssetProfileForm.get('addCurrency');
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (addCurrencyFormControl.hasError('invalidCurrency')) {
|
|
|
|
addCurrencyFormControl.hasError('maxlength') ||
|
|
|
|
|
|
|
|
addCurrencyFormControl.hasError('minlength')
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -161,4 +158,14 @@ export class CreateAssetProfileDialog implements OnInit, OnDestroy {
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private iso4217CurrencyCodeValidator(): ValidatorFn {
|
|
|
|
|
|
|
|
return (control: AbstractControl): ValidationErrors | null => {
|
|
|
|
|
|
|
|
if (!isISO4217CurrencyCode(control.value?.toUpperCase())) {
|
|
|
|
|
|
|
|
return { invalidCurrency: true };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|