add settings table to store names (and other things soon)

This commit is contained in:
2023-03-18 19:56:57 -06:00
parent 315cdc0cf1
commit afc175e3e7
4 changed files with 77 additions and 35 deletions

View File

@@ -185,46 +185,47 @@
<script lang="ts">
import { Options, Vue } from "vue-class-component";
import { useClipboard } from "@vueuse/core";
import { deriveAddress, generateSeed, newIdentifier } from "../libs/crypto";
import { db } from "../db";
import { db } from "@/db";
import { MASTER_SETTINGS } from "@/db/tables";
import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto";
//import { testServerRegisterUser } from "../test";
@Options({
components: {},
})
export default class AccountViewView extends Vue {
firstName =
localStorage.getItem("firstName") === null
? "--"
: localStorage.getItem("firstName");
lastName =
localStorage.getItem("lastName") === null
? "--"
: localStorage.getItem("lastName");
mnemonic = "";
// This registers current user in vue plugin with: $vm.ctx.testRegisterUser()
//testRegisterUser = testServerRegisterUser;
address = "";
privateHex = "";
firstName = "";
lastName = "";
mnemonic = "";
publicHex = "";
derivationPath = "";
copy = useClipboard().copy;
// This registers current user in vue plugin with: $vm.ctx.testRegisterUser()
//testRegisterUser = testServerRegisterUser;
// 'created' hook runs when the Vue instance is first created
async created() {
await db.open();
const num_accounts = await db.accounts.count();
if (num_accounts === 0) {
try {
try {
const settings = await db.settings.get(MASTER_SETTINGS);
if (settings) {
this.firstName = settings.firstName || "";
this.lastName = settings.lastName || "";
}
const numAccounts = await db.accounts.count();
if (numAccounts === 0) {
let privateHex = "";
this.mnemonic = generateSeed();
[this.address, this.privateHex, this.publicHex, this.derivationPath] =
[this.address, privateHex, this.publicHex, this.derivationPath] =
deriveAddress(this.mnemonic);
const newId = newIdentifier(
this.address,
this.publicHex,
this.privateHex,
privateHex,
this.derivationPath
);
await db.accounts.add({
@@ -234,13 +235,13 @@ export default class AccountViewView extends Vue {
mnemonic: this.mnemonic,
publicKeyHex: newId.keys[0].publicKeyHex,
});
} catch (err) {
this.alertMessage =
"Clear your cache and start over. Root Cause: " + err;
this.alertTitle = "Error Creating Account";
this.isAlertVisible = true;
console.log(err);
}
} catch (err) {
this.alertMessage =
"Clear your cache and start over (after data backup). See console log for more info.";
console.log("Telling user to clear cache because:", err);
this.alertTitle = "Error Creating Account";
this.isAlertVisible = true;
}
const accounts = await db.accounts.toArray();