forked from jsnbuchanan/crowd-funder-for-time-pwa
separate account from other data for backup/restore
This commit is contained in:
@@ -200,17 +200,17 @@
|
||||
<script lang="ts">
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
import { useClipboard } from "@vueuse/core";
|
||||
import { db } from "@/db";
|
||||
import { MASTER_SETTINGS } from "@/db/tables";
|
||||
import { db, accountsDB } from "@/db";
|
||||
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
|
||||
import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto";
|
||||
//import { testServerRegisterUser } from "../test";
|
||||
import { testServerRegisterUser } from "../test";
|
||||
|
||||
@Options({
|
||||
components: {},
|
||||
})
|
||||
export default class AccountViewView extends Vue {
|
||||
// This registers current user in vue plugin with: $vm.ctx.testRegisterUser()
|
||||
//testRegisterUser = testServerRegisterUser;
|
||||
testRegisterUser = testServerRegisterUser;
|
||||
|
||||
address = "";
|
||||
firstName = "";
|
||||
@@ -224,16 +224,17 @@ export default class AccountViewView extends Vue {
|
||||
|
||||
// 'created' hook runs when the Vue instance is first created
|
||||
async created() {
|
||||
await db.open();
|
||||
try {
|
||||
const settings = await db.settings.get(MASTER_SETTINGS);
|
||||
await db.open();
|
||||
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
|
||||
if (settings) {
|
||||
this.firstName = settings.firstName || "";
|
||||
this.lastName = settings.lastName || "";
|
||||
this.showContactGives = !!settings.showContactGivesInline;
|
||||
}
|
||||
|
||||
const numAccounts = await db.accounts.count();
|
||||
await accountsDB.open();
|
||||
const numAccounts = await accountsDB.accounts.count();
|
||||
if (numAccounts === 0) {
|
||||
let privateHex = "";
|
||||
this.mnemonic = generateSeed();
|
||||
@@ -246,7 +247,7 @@ export default class AccountViewView extends Vue {
|
||||
privateHex,
|
||||
this.derivationPath
|
||||
);
|
||||
await db.accounts.add({
|
||||
await accountsDB.accounts.add({
|
||||
dateCreated: new Date().toISOString(),
|
||||
derivationPath: this.derivationPath,
|
||||
identity: JSON.stringify(newId),
|
||||
@@ -254,6 +255,12 @@ export default class AccountViewView extends Vue {
|
||||
publicKeyHex: newId.keys[0].publicKeyHex,
|
||||
});
|
||||
}
|
||||
|
||||
const accounts = await accountsDB.accounts.toArray();
|
||||
const identity = JSON.parse(accounts[0].identity);
|
||||
this.address = identity.did;
|
||||
this.publicHex = identity.keys[0].publicKeyHex;
|
||||
this.derivationPath = identity.keys[0].meta.derivationPath;
|
||||
} catch (err) {
|
||||
this.alertMessage =
|
||||
"Clear your cache and start over (after data backup). See console log for more info.";
|
||||
@@ -261,21 +268,15 @@ export default class AccountViewView extends Vue {
|
||||
this.alertTitle = "Error Creating Account";
|
||||
this.isAlertVisible = true;
|
||||
}
|
||||
|
||||
const accounts = await db.accounts.toArray();
|
||||
const identity = JSON.parse(accounts[0].identity);
|
||||
this.address = identity.did;
|
||||
this.publicHex = identity.keys[0].publicKeyHex;
|
||||
this.derivationPath = identity.keys[0].meta.derivationPath;
|
||||
}
|
||||
|
||||
public async toggleShowContactAmounts() {
|
||||
this.showContactGives = !this.showContactGives;
|
||||
try {
|
||||
await db.open();
|
||||
const settings = await db.settings.get(MASTER_SETTINGS);
|
||||
const settings = await db.settings.get(MASTER_SETTINGS_KEY);
|
||||
if (settings) {
|
||||
db.settings.update(MASTER_SETTINGS, {
|
||||
db.settings.update(MASTER_SETTINGS_KEY, {
|
||||
showContactGivesInline: this.showContactGives,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user