Skip to content

Commit

Permalink
updating naming on error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Dudleyneedham committed Mar 19, 2021
1 parent 7232d9f commit c6ef25d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/views/ImportBackupPhrase/ImportBackupPhrase.tsx
Expand Up @@ -11,7 +11,7 @@ function isAllowed(word: string) {
return DEFAULT_WORDLIST.includes(word);
}

function ERROR_INVALID_BACKUP_PHRASE(backupPhrase: Array<string>): boolean {
function INVALID_BACKUP_PHRASE(backupPhrase: Array<string>): boolean {
try {
Identity.buildFromMnemonic(backupPhrase.join(' '));
return false;
Expand All @@ -20,15 +20,15 @@ function ERROR_INVALID_BACKUP_PHRASE(backupPhrase: Array<string>): boolean {
}
}

function ERROR_BACKUP_PHRASE_MALFORMED(backupPhrase: Array<string>): boolean {
function BACKUP_PHRASE_MALFORMED(backupPhrase: Array<string>): boolean {
const length = backupPhrase.filter(Boolean).length;
const hasNoWords = length === 0;
const hasAllWords = length === 12;
const allIsFine = hasAllWords || hasNoWords;
return !allIsFine;
}

function ERROR_INVALID_BACKUP_WORD(value: string): boolean {
function INVALID_BACKUP_WORD(value: string): boolean {
return !isAllowed(value);
}

Expand All @@ -45,8 +45,8 @@ export function ImportBackupPhrase({ onImport }: Props): JSX.Element {
Array(12).fill(''),
);

function ERROR_HAS_INVALID_WORD(backupPhrase: Array<string>): string | null {
const invalidWord = backupPhrase.find(ERROR_INVALID_BACKUP_WORD);
function HAS_INVALID_WORD(backupPhrase: Array<string>): string | null {
const invalidWord = backupPhrase.find(INVALID_BACKUP_WORD);

if (!invalidWord) {
return null;
Expand All @@ -60,12 +60,12 @@ export function ImportBackupPhrase({ onImport }: Props): JSX.Element {
}

const error = [
modified && ERROR_HAS_INVALID_WORD(backupPhrase),
modified && HAS_INVALID_WORD(backupPhrase),
modified &&
ERROR_BACKUP_PHRASE_MALFORMED(backupPhrase) &&
BACKUP_PHRASE_MALFORMED(backupPhrase) &&
t('view_ImportBackupPhrase_error_backup_phrase_length'),
modified &&
ERROR_INVALID_BACKUP_PHRASE(backupPhrase) &&
INVALID_BACKUP_PHRASE(backupPhrase) &&
t('view_ImportBackupPhrase_error_invalid_backup_phrase'),
].filter(Boolean)[0];

Expand Down

0 comments on commit c6ef25d

Please sign in to comment.