Browse Source

More cleanup and application of new db loading

project-gives
Matthew Raymer 1 year ago
parent
commit
3bd55f3ad2
  1. 14
      src/views/ContactAmountsView.vue
  2. 2
      src/views/ContactsView.vue
  3. 15
      src/views/HomeView.vue
  4. 39
      src/views/NewEditProjectView.vue
  5. 18
      src/views/ProjectViewView.vue
  6. 39
      src/views/ProjectsView.vue

14
src/views/ContactAmountsView.vue

@ -142,11 +142,21 @@ export default class ContactsView extends Vue {
giveRecords: Array<GiveServerRecord> = [];
alertTitle = "";
alertMessage = "";
accounts: AccountsSchema;
numAccounts = 0;
async beforeCreate() {
accountsDB.open();
this.accounts = accountsDB.accounts;
this.numAccounts = await this.accounts.count();
}
public async getIdentity(activeDid) {
await accountsDB.open();
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === activeDid, accounts);
const account = await accountsDB.accounts
.where("did")
.equals(activeDid)
.first();
const identity = JSON.parse(account?.identity || "null");
if (!identity) {

2
src/views/ContactsView.vue

@ -578,7 +578,7 @@ export default class ContactsView extends Vue {
}
async onClickAddGive(fromDid: string, toDid: string): Promise<void> {
const identity = this.getIdentity(this.activeDid);
const identity = await this.getIdentity(this.activeDid);
// if they have unconfirmed amounts, ask to confirm those first
if (toDid == identity?.did && this.givenToMeUnconfirmed[fromDid] > 0) {

15
src/views/HomeView.vue

@ -71,7 +71,6 @@
<script lang="ts">
import { Component, Vue } from "vue-facing-decorator";
import GiftedDialog from "@/components/GiftedDialog.vue";
import { db, accountsDB } from "@/db";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
@ -97,11 +96,21 @@ export default class HomeView extends Vue {
isHiddenSpinner = true;
alertTitle = "";
alertMessage = "";
accounts: AccountsSchema;
numAccounts = 0;
async beforeCreate() {
accountsDB.open();
this.accounts = accountsDB.accounts;
this.numAccounts = await this.accounts.count();
}
public async getIdentity(activeDid) {
await accountsDB.open();
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === activeDid, accounts);
const account = await accountsDB.accounts
.where("did")
.equals(activeDid)
.first();
const identity = JSON.parse(account?.identity || "null");
if (!identity) {

39
src/views/NewEditProjectView.vue

@ -73,7 +73,6 @@
<script lang="ts">
import { AxiosError } from "axios";
import * as didJwt from "did-jwt";
import * as R from "ramda";
import { Component, Vue } from "vue-facing-decorator";
import { accountsDB, db } from "@/db";
@ -100,16 +99,26 @@ export default class NewEditProjectView extends Vue {
projectName = "";
description = "";
errorMessage = "";
accounts: AccountsSchema;
numAccounts = 0;
async beforeCreate() {
accountsDB.open();
this.accounts = accountsDB.accounts;
this.numAccounts = await this.accounts.count();
}
public async getIdentity(activeDid) {
await accountsDB.open();
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === activeDid, accounts);
const account = await accountsDB.accounts
.where("did")
.equals(activeDid)
.first();
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error(
"Attempted to load Give records with no identity available.",
"Attempted to load project records with no identity available.",
);
}
return identity;
@ -135,14 +144,10 @@ export default class NewEditProjectView extends Vue {
this.apiServer = settings?.apiServer || "";
if (this.projectId) {
await accountsDB.open();
const num_accounts = await accountsDB.accounts.count();
if (num_accounts === 0) {
if (this.numAccounts === 0) {
console.error("Error: no account was found.");
} else {
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === this.activeDid, accounts);
const identity = JSON.parse(account?.identity || "null");
const identity = await this.getIdentity(this.activeDid);
if (!identity) {
throw new Error(
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service.",
@ -272,19 +277,11 @@ export default class NewEditProjectView extends Vue {
public async onSaveProjectClick() {
this.isHiddenSave = true;
this.isHiddenSpinner = false;
await accountsDB.open();
const num_accounts = await accountsDB.accounts.count();
if (num_accounts === 0) {
if (this.numAccounts === 0) {
console.error("Error: there is no account.");
} else {
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === this.activeDid, accounts);
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error(
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service.",
);
}
const identity = await this.getIdentity(this.activeDid);
this.SaveProject(identity);
}
}

18
src/views/ProjectViewView.vue

@ -175,11 +175,21 @@ export default class ProjectViewView extends Vue {
errorMessage = "";
alertMessage = "";
alertTitle = "";
accounts: AccountsSchema;
numAccounts = 0;
async beforeCreate() {
accountsDB.open();
this.accounts = accountsDB.accounts;
this.numAccounts = await this.accounts.count();
}
public async getIdentity(activeDid) {
await accountsDB.open();
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === activeDid, accounts);
const account = await accountsDB.accounts
.where("did")
.equals(activeDid)
.first();
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
@ -263,9 +273,7 @@ export default class ProjectViewView extends Vue {
this.apiServer = settings?.apiServer || "";
this.allContacts = await db.contacts.toArray();
await accountsDB.open();
const num_accounts = await accountsDB.accounts.count();
if (num_accounts === 0) {
if (this.numAccounts === 0) {
console.error("Problem! Should have a profile!");
} else {
const accounts = await accountsDB.accounts.toArray();

39
src/views/ProjectsView.vue

@ -73,7 +73,6 @@
</template>
<script lang="ts">
import * as R from "ramda";
import { Component, Vue } from "vue-facing-decorator";
import { accountsDB, db } from "@/db";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
@ -115,6 +114,14 @@ export default class ProjectsView extends Vue {
isLoading = false;
alertTitle = "";
alertMessage = "";
accounts: AccountsSchema;
numAccounts = 0;
async beforeCreate() {
accountsDB.open();
this.accounts = accountsDB.accounts;
this.numAccounts = await this.accounts.count();
}
/**
* Core project data loader
@ -183,6 +190,22 @@ export default class ProjectsView extends Vue {
await this.dataLoader(url, token);
}
public async getIdentity(activeDid) {
await accountsDB.open();
const account = await accountsDB.accounts
.where("did")
.equals(activeDid)
.first();
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error(
"Attempted to load project records with no identity available.",
);
}
return identity;
}
/**
* 'created' hook runs when the Vue instance is first created
**/
@ -193,21 +216,13 @@ export default class ProjectsView extends Vue {
const activeDid = settings?.activeDid || "";
this.apiServer = settings?.apiServer || "";
await accountsDB.open();
const num_accounts = await accountsDB.accounts.count();
if (num_accounts === 0) {
if (this.numAccounts === 0) {
console.error("Problem! You need a profile!");
this.alertTitle = "Error!";
this.alertMessage = "Problem! You need a profile!";
} else {
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === activeDid, accounts);
const identity = JSON.parse(account?.identity || "null");
if (!identity) {
throw new Error(
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service.",
);
}
const identity = await this.getIdentity(activeDid);
console.log(identity);
this.current = identity;
this.LoadProjects(identity);
}

Loading…
Cancel
Save