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, + ); } } }