Browse Source

show users when there's an error on the import page

kb/add-usage-guide
Trent Larson 11 months ago
parent
commit
cfa7466b94
  1. 35
      src/views/ImportAccountView.vue

35
src/views/ImportAccountView.vue

@ -72,12 +72,21 @@ import {
import { accountsDB, db } from "@/db/index"; import { accountsDB, db } from "@/db/index";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
interface Notification {
group: string;
type: string;
title: string;
text: string;
}
@Component({ @Component({
components: {}, components: {},
}) })
export default class ImportAccountView extends Vue { export default class ImportAccountView extends Vue {
UPORT_DERIVATION_PATH = "m/7696500'/0'/0'/0'"; // for legacy imports, likely never used UPORT_DERIVATION_PATH = "m/7696500'/0'/0'/0'"; // for legacy imports, likely never used
$notify!: (notification: Notification, timeout?: number) => void;
mnemonic = ""; mnemonic = "";
address = ""; address = "";
privateHex = ""; privateHex = "";
@ -91,7 +100,7 @@ export default class ImportAccountView extends Vue {
public async from_mnemonic() { public async from_mnemonic() {
const mne: string = this.mnemonic.trim().toLowerCase(); const mne: string = this.mnemonic.trim().toLowerCase();
if (this.mnemonic.trim().length > 0) { try {
[this.address, this.privateHex, this.publicHex] = deriveAddress( [this.address, this.privateHex, this.publicHex] = deriveAddress(
mne, mne,
this.derivationPath, this.derivationPath,
@ -104,7 +113,6 @@ export default class ImportAccountView extends Vue {
this.derivationPath, this.derivationPath,
); );
try {
await accountsDB.open(); await accountsDB.open();
await accountsDB.accounts.add({ await accountsDB.accounts.add({
dateCreated: new Date().toISOString(), dateCreated: new Date().toISOString(),
@ -121,8 +129,29 @@ export default class ImportAccountView extends Vue {
activeDid: newId.did, activeDid: newId.did,
}); });
this.$router.push({ name: "account" }); this.$router.push({ name: "account" });
} catch (err) { // eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.error("Error saving mnemonic & updating settings:", err); 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,
);
} }
} }
} }

Loading…
Cancel
Save