diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index 735252f7..cdc516b1 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -1140,6 +1140,28 @@ export const capitalizeAndInsertSpacesBeforeCaps = (text: string) => { : text[0].toUpperCase() + text.substr(1).replace(/([A-Z])/g, " $1"); }; +/** + * Formats type string for display by adding spaces before capitals + * and optionally adds an appropriate article prefix (a/an) + * + * @param text - Text to format + * @returns Formatted string with article prefix + */ +export const capitalizeAndInsertSpacesBeforeCapsWithAPrefix = ( + text: string, +): string => { + const word = capitalizeAndInsertSpacesBeforeCaps(text); + if (word) { + // if the word starts with a vowel, use "an" instead of "a" + const firstLetter = word[0].toLowerCase(); + const vowels = ["a", "e", "i", "o", "u"]; + const particle = vowels.includes(firstLetter) ? "an" : "a"; + return particle + " " + word; + } else { + return ""; + } +}; + /** return readable summary of claim, or something generic diff --git a/src/views/ClaimView.vue b/src/views/ClaimView.vue index f594dc9b..3653861d 100644 --- a/src/views/ClaimView.vue +++ b/src/views/ClaimView.vue @@ -24,7 +24,9 @@

{{ - capitalizeAndInsertSpacesBeforeCaps(veriClaim.claimType || "") + serverUtil.capitalizeAndInsertSpacesBeforeCaps( + veriClaim.claimType || "", + ) }}

@@ -556,6 +572,17 @@ export default class ClaimView extends Vue { fulfillsPlanHandleId?: string; fulfillsType?: string; fulfillsHandleId?: string; + fullClaim?: { + fulfills?: Array<{ + "@type": string; + identifier?: string; + }>; + }; + } | null = null; + // Additional offer information extracted from the fulfills array + detailsForGiveOfferFulfillment: { + offerHandleId?: string; + offerType?: string; } | null = null; detailsForOffer: { fulfillsPlanHandleId?: string } | null = null; // Project information for fulfillsPlanHandleId @@ -689,6 +716,7 @@ export default class ClaimView extends Vue { this.confsVisibleToIdList = []; this.detailsForGive = null; this.detailsForOffer = null; + this.detailsForGiveOfferFulfillment = null; this.projectInfo = null; this.fullClaim = null; this.fullClaimDump = ""; @@ -701,6 +729,33 @@ export default class ClaimView extends Vue { this.veriClaimDidsVisible = {}; } + /** + * Extract offer fulfillment information from the fulfills array + */ + extractOfferFulfillment() { + if (!this.detailsForGive?.fullClaim?.fulfills) { + this.detailsForGiveOfferFulfillment = null; + return; + } + + const fulfills = this.detailsForGive.fullClaim.fulfills; + if (!Array.isArray(fulfills)) { + this.detailsForGiveOfferFulfillment = null; + return; + } + + // Find the Offer in the fulfills array + const offerFulfill = fulfills.find((item) => item["@type"] === "Offer"); + if (offerFulfill) { + this.detailsForGiveOfferFulfillment = { + offerHandleId: offerFulfill.identifier, + offerType: offerFulfill["@type"], + }; + } else { + this.detailsForGiveOfferFulfillment = null; + } + } + // ================================================= // UTILITY METHODS // ================================================= @@ -758,13 +813,6 @@ export default class ClaimView extends Vue { this.canShare = !!navigator.share; } - // insert a space before any capital letters except the initial letter - // (and capitalize initial letter, just in case) - capitalizeAndInsertSpacesBeforeCaps(text: string): string { - if (!text) return ""; - return text[0].toUpperCase() + text.substr(1).replace(/([A-Z])/g, " $1"); - } - totalConfirmers() { return ( this.numConfsNotVisible + @@ -821,6 +869,8 @@ export default class ClaimView extends Vue { }); if (giveResp.status === 200 && giveResp.data.data?.length > 0) { this.detailsForGive = giveResp.data.data[0]; + // Extract offer information from the fulfills array + this.extractOfferFulfillment(); } else { await this.$logError( "Error getting detailed give info: " + JSON.stringify(giveResp), diff --git a/src/views/ConfirmGiftView.vue b/src/views/ConfirmGiftView.vue index c2274dab..6fa5428a 100644 --- a/src/views/ConfirmGiftView.vue +++ b/src/views/ConfirmGiftView.vue @@ -96,50 +96,50 @@ +
+ +
+ + This fulfills a bigger plan + + +
- -
- - This fulfills a bigger plan - - -
- -
- - - This fulfills - {{ - capitalizeAndInsertSpacesBeforeCapsWithAPrefix( - giveDetails?.fulfillsType || "", - ) - }} - - + +
+ + + This fulfills + {{ + serverUtil.capitalizeAndInsertSpacesBeforeCapsWithAPrefix( + giveDetailsOfferFulfillment.offerType || "Offer", + ) + }} + + +
@@ -493,6 +493,11 @@ export default class ConfirmGiftView extends Vue { confsVisibleErrorMessage = ""; confsVisibleToIdList: string[] = []; // list of DIDs that can see any confirmer giveDetails?: GiveSummaryRecord; + // Additional offer information extracted from the fulfills array + giveDetailsOfferFulfillment: { + offerHandleId?: string; + offerType?: string; + } | null = null; giverName = ""; issuerName = ""; isLoading = false; @@ -648,6 +653,8 @@ export default class ConfirmGiftView extends Vue { if (resp.status === 200) { this.giveDetails = resp.data.data[0]; + // Extract offer information from the fulfills array + this.extractOfferFulfillment(); } else { throw new Error("Error getting detailed give info: " + resp.status); } @@ -707,6 +714,33 @@ export default class ConfirmGiftView extends Vue { } } + /** + * Extract offer fulfillment information from the fulfills array + */ + private extractOfferFulfillment() { + if (!this.giveDetails?.fullClaim?.fulfills) { + this.giveDetailsOfferFulfillment = null; + return; + } + + const fulfills = this.giveDetails.fullClaim.fulfills; + if (!Array.isArray(fulfills)) { + this.giveDetailsOfferFulfillment = null; + return; + } + + // Find the Offer in the fulfills array + const offerFulfill = fulfills.find((item) => item["@type"] === "Offer"); + if (offerFulfill) { + this.giveDetailsOfferFulfillment = { + offerHandleId: offerFulfill.identifier, + offerType: offerFulfill["@type"], + }; + } else { + this.giveDetailsOfferFulfillment = null; + } + } + /** * Fetches confirmer information for the claim */ @@ -849,27 +883,6 @@ export default class ConfirmGiftView extends Vue { ); } - /** - * Formats type string for display by adding spaces before capitals - * Optionally adds a prefix - * - * @param text - Text to format - * @param prefix - Optional prefix to add - * @returns Formatted string - */ - capitalizeAndInsertSpacesBeforeCapsWithAPrefix(text: string): string { - const word = this.capitalizeAndInsertSpacesBeforeCaps(text); - if (word) { - // if the word starts with a vowel, use "an" instead of "a" - const firstLetter = word[0].toLowerCase(); - const vowels = ["a", "e", "i", "o", "u"]; - const particle = vowels.includes(firstLetter) ? "an" : "a"; - return particle + " " + word; - } else { - return ""; - } - } - /** * Initiates sharing of claim information * Handles share functionality based on platform capabilities @@ -894,11 +907,5 @@ export default class ConfirmGiftView extends Vue { this.veriClaim = serverUtil.BLANK_GENERIC_SERVER_RECORD; this.veriClaimDump = ""; } - - capitalizeAndInsertSpacesBeforeCaps(text: string) { - return !text - ? "" - : text[0].toUpperCase() + text.substr(1).replace(/([A-Z])/g, " $1"); - } }