From 2c28913d974bc4085f8a8167f9d3394bd5f42b59 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Mon, 26 Feb 2024 19:27:34 -0700 Subject: [PATCH] for BVC: finish submission of confirmations & final give --- src/libs/endorserServer.ts | 39 +++++++-- src/views/ClaimView.vue | 5 +- src/views/ProjectViewView.vue | 5 +- src/views/QuickActionBvcBeginView.vue | 4 +- src/views/QuickActionBvcEndView.vue | 119 +++++++++++++++++++++++++- 5 files changed, 152 insertions(+), 20 deletions(-) diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index 2d64b8ab2..48856114b 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -22,7 +22,7 @@ export interface AgreeVerifiableCredential { "@type": string; // "any" because arbitrary objects can be subject of agreement // eslint-disable-next-line @typescript-eslint/no-explicit-any - object: Record; + object: Record; } export interface GiverInputInfo { @@ -46,6 +46,7 @@ export interface ClaimResult { export interface GenericVerifiableCredential { "@context": string; "@type": string; + [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any } export interface GenericServerRecord extends GenericVerifiableCredential { @@ -54,7 +55,7 @@ export interface GenericServerRecord extends GenericVerifiableCredential { issuedAt: string; issuer: string; // eslint-disable-next-line @typescript-eslint/no-explicit-any - claim: Record; + claim: Record; claimType?: string; } export const BLANK_GENERIC_SERVER_RECORD: GenericServerRecord = { @@ -330,7 +331,7 @@ export function addLastClaimOrHandleAsIdIfMissing( } // return clone of object without any nested *VisibleToDids keys -// similar logic is found in endorser-mobile +// similar code is also contained in endorser-mobile // eslint-disable-next-line @typescript-eslint/no-explicit-any export function removeVisibleToDids(input: any): any { if (input instanceof Object) { @@ -340,7 +341,6 @@ export function removeVisibleToDids(input: any): any { const result: Record = {}; for (const key in input) { if (!key.endsWith("VisibleToDids")) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any result[key] = removeVisibleToDids(R.clone(input[key])); } } @@ -349,7 +349,6 @@ export function removeVisibleToDids(input: any): any { // it's an array return R.map(removeVisibleToDids, input); } - return false; } else { return input; } @@ -518,6 +517,28 @@ export async function createAndSubmitOffer( ); } +// similar logic is found in endorser-mobile +export const createAndSubmitConfirmation = async ( + identifier: IIdentifier, + claim: GenericVerifiableCredential, + lastClaimId: string, // used to set the lastClaimId + handleId: string | undefined, + apiServer: string, + axios: Axios, +) => { + const goodClaim = removeSchemaContext( + removeVisibleToDids( + addLastClaimOrHandleAsIdIfMissing(claim, lastClaimId, handleId), + ), + ); + const confirmationClaim: GenericVerifiableCredential = { + "@context": "https://schema.org", + "@type": "AgreeAction", + object: goodClaim, + }; + return createAndSubmitClaim(confirmationClaim, identifier, apiServer, axios); +}; + export async function createAndSubmitClaim( vcClaim: GenericVerifiableCredential, identity: IIdentifier, @@ -583,7 +604,7 @@ export async function createAndSubmitClaim( } // eslint-disable-next-line @typescript-eslint/no-explicit-any -export const isAccept = (claim: Record) => { +export const isAccept = (claim: Record) => { return ( claim && claim["@context"] === SCHEMA_ORG_CONTEXT && @@ -592,7 +613,7 @@ export const isAccept = (claim: Record) => { }; // eslint-disable-next-line @typescript-eslint/no-explicit-any -export const isOffer = (claim: Record) => { +export const isOffer = (claim: Record) => { return ( claim && claim["@context"] === SCHEMA_ORG_CONTEXT && @@ -622,7 +643,7 @@ export const capitalizeAndInsertSpacesBeforeCaps = (text: string) => { similar code is also contained in endorser-mobile **/ // eslint-disable-next-line @typescript-eslint/no-explicit-any -const claimSummary = (claim: Record) => { +const claimSummary = (claim: Record) => { if (!claim) { // to differentiate from "something" above return "something"; @@ -630,7 +651,7 @@ const claimSummary = (claim: Record) => { if (claim.claim) { // probably a Verified Credential // eslint-disable-next-line @typescript-eslint/no-explicit-any - claim = claim.claim as Record; + claim = claim.claim as Record; } if (Array.isArray(claim)) { if (claim.length === 1) { diff --git a/src/views/ClaimView.vue b/src/views/ClaimView.vue index f0a1b176a..df55346c9 100644 --- a/src/views/ClaimView.vue +++ b/src/views/ClaimView.vue @@ -730,10 +730,7 @@ export default class ClaimView extends Vue { ), ), ); - const confirmationClaim: serverUtil.GenericVerifiableCredential & { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - object: any; - } = { + const confirmationClaim: serverUtil.GenericVerifiableCredential = { "@context": "https://schema.org", "@type": "AgreeAction", object: goodClaim, diff --git a/src/views/ProjectViewView.vue b/src/views/ProjectViewView.vue index 317e0710a..10dc4722a 100644 --- a/src/views/ProjectViewView.vue +++ b/src/views/ProjectViewView.vue @@ -800,10 +800,7 @@ export default class ProjectViewView extends Vue { ), ), ); - const confirmationClaim: serverUtil.GenericVerifiableCredential & { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - object: any; - } = { + const confirmationClaim: serverUtil.GenericVerifiableCredential = { "@context": "https://schema.org", "@type": "AgreeAction", object: goodClaim, diff --git a/src/views/QuickActionBvcBeginView.vue b/src/views/QuickActionBvcBeginView.vue index 7cc0d9982..1aaf51c50 100644 --- a/src/views/QuickActionBvcBeginView.vue +++ b/src/views/QuickActionBvcBeginView.vue @@ -125,6 +125,7 @@ export default class QuickActionBvcBeginView extends Vue { const hoursNum = libsUtil.numberOrZero(this.hoursStr); const identity = await libsUtil.getIdentity(activeDid); + // first send the claim for time given let timeSuccess = false; if (this.gaveTime && hoursNum > 0) { const timeResult = await createAndSubmitGive( @@ -156,6 +157,7 @@ export default class QuickActionBvcBeginView extends Vue { } } + // now send the claim for attendance let attendedSuccess = false; if (this.attended) { const attendResult = await createAndSubmitClaim( @@ -208,7 +210,7 @@ export default class QuickActionBvcBeginView extends Vue { group: "alert", type: "danger", title: "Error", - text: error.userMessage || "There was an error sending those claims.", + text: error.userMessage || "There was an error sending claims.", }, -1, ); diff --git a/src/views/QuickActionBvcEndView.vue b/src/views/QuickActionBvcEndView.vue index ca20e8554..b7db14462 100644 --- a/src/views/QuickActionBvcEndView.vue +++ b/src/views/QuickActionBvcEndView.vue @@ -117,6 +117,7 @@