Browse Source

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

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

67
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,25 +113,45 @@ 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(), derivationPath: this.derivationPath,
derivationPath: this.derivationPath, did: newId.did,
did: newId.did, identity: JSON.stringify(newId),
identity: JSON.stringify(newId), mnemonic: mne,
mnemonic: mne, publicKeyHex: newId.keys[0].publicKeyHex,
publicKeyHex: newId.keys[0].publicKeyHex, });
});
// record that as the active DID // record that as the active DID
await db.open(); await db.open();
db.settings.update(MASTER_SETTINGS_KEY, { db.settings.update(MASTER_SETTINGS_KEY, {
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
console.error("Error saving mnemonic & updating settings:", err); } 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,
);
} }
} }
} }

Loading…
Cancel
Save