From cfa7466b948c718c6c173a4595dd4a0fac53f3c3 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Tue, 9 Jan 2024 19:18:49 -0700 Subject: [PATCH] show users when there's an error on the import page --- src/views/ImportAccountView.vue | 67 +++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/src/views/ImportAccountView.vue b/src/views/ImportAccountView.vue index 8334fe4..c96df32 100644 --- a/src/views/ImportAccountView.vue +++ b/src/views/ImportAccountView.vue @@ -72,12 +72,21 @@ import { import { accountsDB, db } from "@/db/index"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; +interface Notification { + group: string; + type: string; + title: string; + text: string; +} + @Component({ components: {}, }) export default class ImportAccountView extends Vue { UPORT_DERIVATION_PATH = "m/7696500'/0'/0'/0'"; // for legacy imports, likely never used + $notify!: (notification: Notification, timeout?: number) => void; + mnemonic = ""; address = ""; privateHex = ""; @@ -91,7 +100,7 @@ export default class ImportAccountView extends Vue { public async from_mnemonic() { const mne: string = this.mnemonic.trim().toLowerCase(); - if (this.mnemonic.trim().length > 0) { + try { [this.address, this.privateHex, this.publicHex] = deriveAddress( mne, this.derivationPath, @@ -104,25 +113,45 @@ export default class ImportAccountView extends Vue { this.derivationPath, ); - try { - await accountsDB.open(); - await accountsDB.accounts.add({ - dateCreated: new Date().toISOString(), - derivationPath: this.derivationPath, - did: newId.did, - identity: JSON.stringify(newId), - mnemonic: mne, - publicKeyHex: newId.keys[0].publicKeyHex, - }); + await accountsDB.open(); + await accountsDB.accounts.add({ + dateCreated: new Date().toISOString(), + derivationPath: this.derivationPath, + did: newId.did, + identity: JSON.stringify(newId), + mnemonic: mne, + publicKeyHex: newId.keys[0].publicKeyHex, + }); - // record that as the active DID - await db.open(); - db.settings.update(MASTER_SETTINGS_KEY, { - activeDid: newId.did, - }); - this.$router.push({ name: "account" }); - } catch (err) { - console.error("Error saving mnemonic & updating settings:", err); + // record that as the active DID + await db.open(); + db.settings.update(MASTER_SETTINGS_KEY, { + activeDid: newId.did, + }); + this.$router.push({ name: "account" }); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (err: any) { + console.error("Error saving mnemonic & updating settings:", err); + if (err == "Error: invalid mnemonic") { + this.$notify( + { + group: "alert", + type: "danger", + title: "Invalid Mnemonic", + text: "Please check your mnemonic and try again.", + }, + -1, + ); + } else { + this.$notify( + { + group: "alert", + type: "danger", + title: "Error", + text: "Got an error creating that identity.", + }, + -1, + ); } } }