Add transloco test to make sure that you cannot use the language word… (#483)

* Add transloco test to make sure that you cannot use the language word set in general.account followed by space#number as the name used in Address Book.

* Fix lint error. Incorrectly using let instead of const.

* Close loophole on English (Account).

* Add parentheses for clarity and correctness.

* Changed the bracketing from ()|() to (|) which probably makes more sense, but I am no regular expressions expert.
This commit is contained in:
Andrew Higgs 2021-11-14 22:46:51 +02:00 committed by GitHub
commit c32482763d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View file

@ -551,7 +551,8 @@ export class AccountDetailsComponent implements OnInit, OnDestroy {
return;
}
if ( /^Account #\d+$/g.test(this.addressBookModel) === true ) {
const regexp = new RegExp('^(Account|' + this.translocoService.translate('general.account') + ') #\\d+$', 'g');
if ( regexp.test(this.addressBookModel) === true ) {
return this.notifications.sendError(`This name is reserved for wallet accounts without a label`);
}

View file

@ -11,6 +11,7 @@ import {BigNumber} from 'bignumber.js';
import {ApiService} from '../../services/api.service';
import {PriceService} from '../../services/price.service';
import {AppSettingsService} from '../../services/app-settings.service';
import {TranslocoService} from '@ngneat/transloco';
export interface BalanceAccount {
balance: BigNumber;
@ -65,7 +66,8 @@ export class AddressBookComponent implements OnInit, AfterViewInit, OnDestroy {
private router: Router,
private api: ApiService,
private price: PriceService,
public appSettings: AppSettingsService) { }
public appSettings: AppSettingsService,
private translocoService: TranslocoService) { }
async ngOnInit() {
this.addressBookService.loadAddressBook();
@ -274,7 +276,8 @@ export class AddressBookComponent implements OnInit, AfterViewInit, OnDestroy {
// Trim and remove duplicate spaces
this.newAddressName = this.newAddressName.trim().replace(/ +/g, ' ');
if ( /^Account #\d+$/g.test(this.newAddressName) === true ) {
const regexp = new RegExp('^(Account|' + this.translocoService.translate('general.account') + ') #\\d+$', 'g');
if ( regexp.test(this.newAddressName) === true ) {
return this.notificationService.sendError(`This name is reserved for wallet accounts without a label`);
}