From 6f4fbc697f85dfc25c36ebd9b030e760fc557ea5 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sun, 16 Mar 2025 17:06:01 -0600 Subject: [PATCH] fix 'give' query and restore confirmClaim method --- src/libs/util.ts | 5 +++ src/views/ConfirmGiftView.vue | 79 ++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/src/libs/util.ts b/src/libs/util.ts index 27df901..a249dca 100644 --- a/src/libs/util.ts +++ b/src/libs/util.ts @@ -99,6 +99,11 @@ export function numberOrZero(str: string): number { return isNumeric(str) ? +str : 0; } + +/** + * from https://tools.ietf.org/html/rfc3986#section-3 + * also useful is https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Definition + **/ export const isGlobalUri = (uri: string) => { return uri && uri.match(new RegExp(/^[A-Za-z][A-Za-z0-9+.-]+:/)); }; diff --git a/src/views/ConfirmGiftView.vue b/src/views/ConfirmGiftView.vue index f2e0d5d..1b39cbe 100644 --- a/src/views/ConfirmGiftView.vue +++ b/src/views/ConfirmGiftView.vue @@ -442,7 +442,7 @@ import { NotificationIface } from "../constants/app"; import { db, retrieveSettingsForActiveAccount } from "../db/index"; import { Contact } from "../db/tables/contacts"; import * as serverUtil from "../libs/endorserServer"; -import { GiveSummaryRecord } from "../interfaces"; +import { GenericVerifiableCredential, GiveSummaryRecord } from "../interfaces"; import { displayAmount } from "../libs/endorserServer"; import * as libsUtil from "../libs/util"; import { retrieveAccountDids } from "../libs/util"; @@ -621,7 +621,8 @@ export default class ConfirmGiftView extends Vue { * Fetches detailed give information */ private async fetchGiveDetails(claimId: string, userDid: string) { - const giveUrl = `${this.apiServer}/api/v2/report/gives?handleId=${encodeURIComponent(claimId)}`; + const param = libsUtil.isGlobalUri(claimId) ? "handleId" : "jwtId"; + const giveUrl = `${this.apiServer}/api/v2/report/gives?${param}=${encodeURIComponent(claimId)}`; try { const headers = await serverUtil.getHeaders(userDid); @@ -645,15 +646,10 @@ export default class ConfirmGiftView extends Vue { if (!this.giveDetails) return; this.urlForNewGive = "/gifted-details?"; - this.addGiveDetailsToUrl(); - this.processParticipantInfo(); - this.processAdditionalDetails(); - } - /** - * Adds basic give details to URL - */ - private addGiveDetailsToUrl() { + /** + * Add basic give details to URL + */ if (this.giveDetails?.amount) { this.urlForNewGive += `&amountInput=${encodeURIComponent(String(this.giveDetails.amount))}`; } @@ -663,12 +659,10 @@ export default class ConfirmGiftView extends Vue { if (this.giveDetails?.description) { this.urlForNewGive += `&description=${encodeURIComponent(this.giveDetails.description)}`; } - } - /** - * Processes participant (giver/recipient) information - */ - private processParticipantInfo() { + /** + * Add participant (giver/recipient) name & URL info + */ if (this.giveDetails?.agentDid) { this.giverName = this.didInfo(this.giveDetails.agentDid); this.urlForNewGive += `&giverDid=${encodeURIComponent(this.giveDetails.agentDid)}&giverName=${encodeURIComponent(this.giverName)}`; @@ -677,12 +671,10 @@ export default class ConfirmGiftView extends Vue { this.recipientName = this.didInfo(this.giveDetails.recipientDid); this.urlForNewGive += `&recipientDid=${encodeURIComponent(this.giveDetails.recipientDid)}&recipientName=${encodeURIComponent(this.recipientName)}`; } - } - /** - * Processes additional give details (image, offer, plan) - */ - private processAdditionalDetails() { + /** + * Add additional give details to URL (image, offer, plan) + */ if (this.giveDetails?.fullClaim.image) { this.urlForNewGive += `&image=${encodeURIComponent(this.giveDetails.fullClaim.image)}`; } @@ -803,6 +795,53 @@ export default class ConfirmGiftView extends Vue { ); } + // similar code is found in ProjectViewView + async confirmClaim() { + // similar logic is found in endorser-mobile + const goodClaim = serverUtil.removeSchemaContext( + serverUtil.removeVisibleToDids( + serverUtil.addLastClaimOrHandleAsIdIfMissing( + this.veriClaim.claim, + this.veriClaim.id, + this.veriClaim.handleId, + ), + ), + ); + const confirmationClaim: GenericVerifiableCredential = { + "@context": "https://schema.org", + "@type": "AgreeAction", + object: goodClaim, + }; + const result = await serverUtil.createAndSubmitClaim( + confirmationClaim, + this.activeDid, + this.apiServer, + this.axios, + ); + if (result.type === "success") { + this.$notify( + { + group: "alert", + type: "success", + title: "Success", + text: "Confirmation submitted.", + }, + 3000, + ); + } else { + console.error("Got error submitting the confirmation:", result); + this.$notify( + { + group: "alert", + type: "danger", + title: "Error", + text: "There was a problem submitting the confirmation.", + }, + 5000, + ); + } + } + /** * Notifies user why they cannot confirm the gift * Explains requirements or restrictions preventing confirmation