From bc1846a95a2e9ae6a7f0a4b9128671abf254aa81 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Thu, 11 Jul 2024 19:43:56 -0600 Subject: [PATCH] consolidate getIdentity & remove dups --- src/views/ClaimAddRawView.vue | 14 -------------- src/views/ClaimView.vue | 16 ---------------- src/views/ConfirmGiftView.vue | 16 ---------------- src/views/ContactAmountsView.vue | 19 ++----------------- src/views/ContactQRScanShowView.vue | 28 +++++----------------------- src/views/NewEditProjectView.vue | 24 ++++-------------------- src/views/ProjectViewView.vue | 10 ---------- src/views/ProjectsView.vue | 18 +----------------- 8 files changed, 12 insertions(+), 133 deletions(-) diff --git a/src/views/ClaimAddRawView.vue b/src/views/ClaimAddRawView.vue index 9dafe3d..4764f73 100644 --- a/src/views/ClaimAddRawView.vue +++ b/src/views/ClaimAddRawView.vue @@ -66,20 +66,6 @@ export default class ClaimAddRawView extends Vue { } } - public async getIdentity(activeDid: string): Promise { - await accountsDB.open(); - const account = (await accountsDB.accounts - .where("did") - .equals(activeDid) - .first()) as Account; - const identity = JSON.parse(account?.identity || "null"); - - if (!identity) { - throw new Error("Cannot submit a claim without an identifier."); - } - return identity; - } - async submitClaim() { const fullClaim = JSON.parse(this.claimStr); const result = await serverUtil.createAndSubmitClaim( diff --git a/src/views/ClaimView.vue b/src/views/ClaimView.vue index 2d48e67..6c1aedf 100644 --- a/src/views/ClaimView.vue +++ b/src/views/ClaimView.vue @@ -522,22 +522,6 @@ export default class ClaimView extends Vue { ); } - public async getIdentity(activeDid: string): Promise { - await accountsDB.open(); - const account = (await accountsDB.accounts - .where("did") - .equals(activeDid) - .first()) as Account; - const identity = JSON.parse(account?.identity || "null"); - - if (!identity) { - throw new Error( - "Attempted to load project records with no identifier available.", - ); - } - return identity; - } - // Isn't there a better way to make this available to the template? didInfo(did: string) { return serverUtil.didInfo( diff --git a/src/views/ConfirmGiftView.vue b/src/views/ConfirmGiftView.vue index 18e371e..47143ca 100644 --- a/src/views/ConfirmGiftView.vue +++ b/src/views/ConfirmGiftView.vue @@ -525,22 +525,6 @@ export default class ClaimView extends Vue { ); } - public async getIdentity(activeDid: string): Promise { - await accountsDB.open(); - const account = (await accountsDB.accounts - .where("did") - .equals(activeDid) - .first()) as Account; - const identity = JSON.parse(account?.identity || "null"); - - if (!identity) { - throw new Error( - "Attempted to load project records with no identifier available.", - ); - } - return identity; - } - // Isn't there a better way to make this available to the template? didInfo(did: string | undefined) { return serverUtil.didInfo( diff --git a/src/views/ContactAmountsView.vue b/src/views/ContactAmountsView.vue index 0482345..cefb27c 100644 --- a/src/views/ContactAmountsView.vue +++ b/src/views/ContactAmountsView.vue @@ -124,6 +124,7 @@ import { GiveVerifiableCredential, SCHEMA_ORG_CONTEXT, } from "@/libs/endorserServer"; +import * as libsUtil from "@/libs/util"; @Component({ components: { QuickNav } }) export default class ContactAmountssView extends Vue { @@ -142,22 +143,6 @@ export default class ContactAmountssView extends Vue { this.numAccounts = await accountsDB.accounts.count(); } - public async getIdentity(activeDid: string) { - await accountsDB.open(); - const account = await accountsDB.accounts - .where("did") - .equals(activeDid) - .first(); - const identity = JSON.parse((account?.identity as string) || "null"); - - if (!identity) { - throw new Error( - "Attempted to load Give records with no identifier available.", - ); - } - return identity; - } - async created() { try { await db.open(); @@ -190,7 +175,7 @@ export default class ContactAmountssView extends Vue { async loadGives(activeDid: string, contact: Contact) { try { - const identity = await this.getIdentity(this.activeDid); + const identity = await libsUtil.getIdentity(this.activeDid); let result: Array = []; const url = this.apiServer + diff --git a/src/views/ContactQRScanShowView.vue b/src/views/ContactQRScanShowView.vue index bf6c548..a748f98 100644 --- a/src/views/ContactQRScanShowView.vue +++ b/src/views/ContactQRScanShowView.vue @@ -72,7 +72,7 @@