From 2058205150bc2ed284cb24167158b09c3babea76 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sun, 25 Feb 2024 18:38:54 -0700 Subject: [PATCH] for BVC shortcut: send attend & give actions, and list actions to confirm --- src/App.vue | 4 +- src/components/GiftedDialog.vue | 19 +--- src/components/OfferDialog.vue | 27 +----- src/libs/endorserServer.ts | 39 +++++--- src/libs/util.ts | 30 +++++- src/views/AccountViewView.vue | 2 +- src/views/ContactAmountsView.vue | 2 +- src/views/ContactGiftingView.vue | 2 +- src/views/ContactQRScanShowView.vue | 3 +- src/views/ContactsView.vue | 18 ++-- src/views/DiscoverView.vue | 8 +- src/views/HomeView.vue | 8 +- src/views/QuickActionBvcBeginView.vue | 131 +++++++++++++++++++++++--- src/views/QuickActionBvcEndView.vue | 71 +++++++++----- src/views/QuickActionBvcView.vue | 2 +- 15 files changed, 247 insertions(+), 119 deletions(-) diff --git a/src/App.vue b/src/App.vue index 0fee98a..484d015 100644 --- a/src/App.vue +++ b/src/App.vue @@ -582,7 +582,7 @@ export default class App extends Vue { } }) .catch((error) => { - console.log("Push provider server communication failed:", error); + console.error("Push provider server communication failed:", error); return false; }); @@ -597,7 +597,7 @@ export default class App extends Vue { return response.ok; }) .catch((error) => { - console.log("Push server communication failed:", error); + console.error("Push server communication failed:", error); return false; }); diff --git a/src/components/GiftedDialog.vue b/src/components/GiftedDialog.vue index 5353f9e..4d5da37 100644 --- a/src/components/GiftedDialog.vue +++ b/src/components/GiftedDialog.vue @@ -77,7 +77,6 @@ import { import * as libsUtil from "@/libs/util"; import { accountsDB, db } from "@/db/index"; import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings"; -import { Account } from "@/db/tables/accounts"; import { Contact } from "@/db/tables/contacts"; @Component @@ -206,22 +205,6 @@ export default class GiftedDialog extends Vue { }); } - public async getIdentity(activeDid: string) { - 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 Give records for DID ${activeDid} but no identifier was found", - ); - } - return identity; - } - /** * * @param giverDid may be null @@ -262,7 +245,7 @@ export default class GiftedDialog extends Vue { } try { - const identity = await this.getIdentity(this.activeDid); + const identity = await libsUtil.getIdentity(this.activeDid); const result = await createAndSubmitGive( this.axios, this.apiServer, diff --git a/src/components/OfferDialog.vue b/src/components/OfferDialog.vue index c0f2b69..6cce99d 100644 --- a/src/components/OfferDialog.vue +++ b/src/components/OfferDialog.vue @@ -72,9 +72,8 @@ import { Vue, Component, Prop } from "vue-facing-decorator"; import { NotificationIface } from "@/constants/app"; import { createAndSubmitOffer } from "@/libs/endorserServer"; import * as libsUtil from "@/libs/util"; -import { accountsDB, db } from "@/db/index"; +import { db } from "@/db/index"; import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings"; -import { Account } from "@/db/tables/accounts"; @Component export default class OfferDialog extends Vue { @@ -102,7 +101,7 @@ export default class OfferDialog extends Vue { this.activeDid = settings?.activeDid || ""; // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { - console.log("Error retrieving settings from database:", err); + console.error("Error retrieving settings from database:", err); this.$notify( { group: "alert", @@ -173,22 +172,6 @@ export default class OfferDialog extends Vue { }); } - public async getIdentity(activeDid: string) { - 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 Offer records for DID ${activeDid} but no identifier was found`, - ); - } - return identity; - } - /** * * @param description may be an empty string @@ -228,7 +211,7 @@ export default class OfferDialog extends Vue { } try { - const identity = await this.getIdentity(this.activeDid); + const identity = await libsUtil.getIdentity(this.activeDid); const result = await createAndSubmitOffer( this.axios, this.apiServer, @@ -245,7 +228,7 @@ export default class OfferDialog extends Vue { this.isOfferCreationError(result.response) ) { const errorMessage = this.getOfferCreationErrorMessage(result); - console.log("Error with offer creation result:", result); + console.error("Error with offer creation result:", result); this.$notify( { group: "alert", @@ -268,7 +251,7 @@ export default class OfferDialog extends Vue { } // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { - console.log("Error with offer recordation caught:", error); + console.error("Error with offer recordation caught:", error); const message = error.userMessage || error.response?.data?.error?.message || diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index be4865d..2d64b8a 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -229,16 +229,16 @@ export interface ErrorResponse { }; } -export interface ErrorResult { - type: "error"; - error: InternalError; -} - export interface InternalError { error: string; // for system logging userMessage?: string; // for user display } +export interface ErrorResult extends ResultWithType { + type: "error"; + error: InternalError; +} + export type CreateAndSubmitClaimResult = SuccessResult | ErrorResult; // This is used to check for hidden info. @@ -758,12 +758,23 @@ export const claimSpecialDescription = ( } }; -// from https://stackoverflow.com/a/175787/845494 -// -export function isNumeric(str: string): boolean { - return !isNaN(+str); -} - -export function numberOrZero(str: string): number { - return isNumeric(str) ? +str : 0; -} +export const BVC_MEETUPS_PROJECT_CLAIM_ID = + //"https://endorser.ch/entity/01GXYPFF7FA03NXKPYY142PY4H"; + "https://endorser.ch/entity/01HNTZYJJXTGT0EZS3VEJGX7AK"; + +export const bvcMeetingJoinClaim = (did: string, startTime: string) => { + return { + "@context": SCHEMA_ORG_CONTEXT, + "@type": "JoinAction", + agent: { + identifier: did, + }, + event: { + organizer: { + name: "Bountiful Voluntaryist Community", + }, + name: "Saturday Morning Meeting", + startTime: startTime, + }, + }; +}; diff --git a/src/libs/util.ts b/src/libs/util.ts index 822cdaa..99c51ec 100644 --- a/src/libs/util.ts +++ b/src/libs/util.ts @@ -1,14 +1,16 @@ // many of these are also found in endorser-mobile utility.ts import axios, { AxiosResponse } from "axios"; +import { IIdentifier } from "@veramo/core"; +import { useClipboard } from "@vueuse/core"; import { DEFAULT_PUSH_SERVER } from "@/constants/app"; import { accountsDB, db } from "@/db/index"; +import { Account } from "@/db/tables/accounts"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto"; import { GenericServerRecord, containsHiddenDid } from "@/libs/endorserServer"; import * as serverUtil from "@/libs/endorserServer"; -import { useClipboard } from "@vueuse/core"; // eslint-disable-next-line @typescript-eslint/no-var-requires const Buffer = require("buffer/").Buffer; @@ -55,6 +57,16 @@ export function iconForUnitCode(unitCode: string) { return UNIT_CODES[unitCode]?.faIcon || "question"; } +// from https://stackoverflow.com/a/175787/845494 +// +export function isNumeric(str: string): boolean { + return !isNaN(+str); +} + +export function numberOrZero(str: string): number { + return isNumeric(str) ? +str : 0; +} + export const isGlobalUri = (uri: string) => { return uri && uri.match(new RegExp(/^[A-Za-z][A-Za-z0-9+.-]+:/)); }; @@ -180,6 +192,22 @@ export function findAllVisibleToDids( * **/ +export const getIdentity = async (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 Offer records for DID ${activeDid} but no identifier was found`, + ); + } + return identity; +}; + /** * Generates a new identity, saves it to the database, and sets it as the active identity. * @return {Promise} with the DID of the new identity diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index 7b72d53..343871b 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -446,7 +446,7 @@ > Show Shortcut on Home PageShow BVC Shortcut on Home Page
diff --git a/src/views/ContactAmountsView.vue b/src/views/ContactAmountsView.vue index 2902174..a6fc0ff 100644 --- a/src/views/ContactAmountsView.vue +++ b/src/views/ContactAmountsView.vue @@ -179,7 +179,7 @@ export default class ContactAmountssView extends Vue { } // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { - console.log("Error retrieving settings or gives.", err); + console.error("Error retrieving settings or gives.", err); this.$notify( { group: "alert", diff --git a/src/views/ContactGiftingView.vue b/src/views/ContactGiftingView.vue index d0144f7..ac59292 100644 --- a/src/views/ContactGiftingView.vue +++ b/src/views/ContactGiftingView.vue @@ -119,7 +119,7 @@ export default class ContactGiftingView extends Vue { // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { - console.log("Error retrieving settings & contacts:", err); + console.error("Error retrieving settings & contacts:", err); this.$notify( { group: "alert", diff --git a/src/views/ContactQRScanShowView.vue b/src/views/ContactQRScanShowView.vue index f5cc186..2744121 100644 --- a/src/views/ContactQRScanShowView.vue +++ b/src/views/ContactQRScanShowView.vue @@ -180,7 +180,6 @@ export default class ContactQRScanShow extends Vue { // eslint-disable-next-line @typescript-eslint/no-explicit-any onScanDetect(content: any) { if (content[0]?.rawValue) { - //console.log("onDetect", content[0].rawValue); localStorage.setItem("contactEndorserUrl", content[0].rawValue); this.$router.push({ name: "contacts" }); } else { @@ -198,7 +197,7 @@ export default class ContactQRScanShow extends Vue { // eslint-disable-next-line @typescript-eslint/no-explicit-any onScanError(error: any) { - console.log("Scan was invalid:", error); + console.error("Scan was invalid:", error); this.$notify( { group: "alert", diff --git a/src/views/ContactsView.vue b/src/views/ContactsView.vue index 3f35399..494e537 100644 --- a/src/views/ContactsView.vue +++ b/src/views/ContactsView.vue @@ -284,6 +284,7 @@ diff --git a/src/views/QuickActionBvcEndView.vue b/src/views/QuickActionBvcEndView.vue index c86fb58..ca20e85 100644 --- a/src/views/QuickActionBvcEndView.vue +++ b/src/views/QuickActionBvcEndView.vue @@ -15,19 +15,26 @@
-

+

End of BVC Saturday Meeting

-

Confirm

-
- There are no claims today yet for you to confirm. - - (There are {{ claimCountWithHidden }} hidden claims.) +

Confirm

+
+ +
+
+ There are no claims yet today for you to confirm. + + {{ + claimCountWithHidden === 1 + ? "(There is 1 claim with hidden details.)" + : `(There are ${claimCountWithHidden} claims with hidden details.)` + }}
-
    +
    • - + {{ claimSpecialDescription( @@ -59,10 +78,10 @@
-

Anything else?

-
+

Anything else?

+
- Someone gave + Someone else gave
-
+
+
+ +
@@ -123,7 +152,9 @@ export default class QuickActionBvcBeginView extends Vue { apiServer = ""; claimCountWithHidden = 0; claimsToConfirm: GenericServerRecord[] = []; - description = ""; + claimsToConfirmSelected: string[] = []; + description = "breakfast"; + loadingConfirms = true; someoneGave = false; async created() { @@ -135,6 +166,7 @@ export default class QuickActionBvcBeginView extends Vue { } async mounted() { + this.loadingConfirms = true; let currentOrPreviousSat = DateTime.now().setZone("America/Denver"); if (currentOrPreviousSat.weekday < 6) { // it's not Saturday or Sunday, @@ -165,15 +197,7 @@ export default class QuickActionBvcBeginView extends Vue { const headers = { Authorization: "Bearer " + (await accessToken(identity)), }; - console.log("todayOrPreviousStartDate", todayOrPreviousStartDate); try { - console.log( - this.apiServer + - "/api/claim/?" + - "issuedAt_greaterThanOrEqualTo=" + - encodeURIComponent(todayOrPreviousStartDate) + - "&excludeConfirmations=true", - ); const response = await fetch( this.apiServer + "/api/claim/?" + @@ -187,7 +211,7 @@ export default class QuickActionBvcBeginView extends Vue { console.log("Bad response", response); throw new Error("Bad response when retrieving claims."); } - response.json().then((data) => { + await response.json().then((data) => { const dataByOthers = R.reject( (claim: GenericServerRecord) => claim.issuer === this.activeDid, data, @@ -212,6 +236,7 @@ export default class QuickActionBvcBeginView extends Vue { -1, ); } + this.loadingConfirms = false; } onClickLoadClaim(jwtId: string) { diff --git a/src/views/QuickActionBvcView.vue b/src/views/QuickActionBvcView.vue index 48aa859..67c5f65 100644 --- a/src/views/QuickActionBvcView.vue +++ b/src/views/QuickActionBvcView.vue @@ -15,7 +15,7 @@
-

+

Bountiful Voluntaryist Community Actions