Fix offer fulfillment detection + consistencies between ClaimView and ConfirmGiftView #167

Merged
jose merged 8 commits from claimview-fullfills-offer into master 2025-09-08 08:37:03 +00:00
3 changed files with 41 additions and 52 deletions
Showing only changes of commit 1eeb013638 - Show all commits

View File

@@ -159,6 +159,41 @@ export const isGiveAction = (
return isGiveClaimType(veriClaim.claimType);
};
export interface OfferFulfillment {
offerHandleId: string;
offerType: string;
}
/**
* Extract offer fulfillment information from the fulfills field
* Handles both array and single object cases
*/
export const extractOfferFulfillment = (fulfills: any): OfferFulfillment | null => {
if (!fulfills) {
return null;
}
// Handle both array and single object cases
let offerFulfill = null;
if (Array.isArray(fulfills)) {
// Find the Offer in the fulfills array
offerFulfill = fulfills.find((item) => item["@type"] === "Offer");
} else if (fulfills["@type"] === "Offer") {
// fulfills is a single Offer object
offerFulfill = fulfills;
}
if (offerFulfill) {
return {
offerHandleId: offerFulfill.identifier,
offerType: offerFulfill["@type"],
};
}
return null;
};
export const shortDid = (did: string) => {
if (did.startsWith("did:peer:")) {
return (

View File

@@ -733,32 +733,9 @@ export default class ClaimView extends Vue {
* Extract offer fulfillment information from the fulfills array
*/
extractOfferFulfillment() {
if (!this.detailsForGive?.fullClaim?.fulfills) {
this.detailsForGiveOfferFulfillment = null;
return;
}
const fulfills = this.detailsForGive.fullClaim.fulfills;
// Handle both array and single object cases
let offerFulfill = null;
if (Array.isArray(fulfills)) {
// Find the Offer in the fulfills array
offerFulfill = fulfills.find((item) => item["@type"] === "Offer");
} else if (fulfills["@type"] === "Offer") {
// fulfills is a single Offer object
offerFulfill = fulfills;
}
if (offerFulfill) {
this.detailsForGiveOfferFulfillment = {
offerHandleId: offerFulfill.identifier,
offerType: offerFulfill["@type"],
};
} else {
this.detailsForGiveOfferFulfillment = null;
}
this.detailsForGiveOfferFulfillment = libsUtil.extractOfferFulfillment(
trentlarson marked this conversation as resolved Outdated

There is one more case here: the fullClaim.fulfills can potentially be a single claim object that is not in an array. (This is the case for most of the schema.org properties: they are defined with a particular type but they could be an array of that type.) So check for fulfills["@type"] of "Offer" to set other fulfills variables.

There is one more case here: the fullClaim.fulfills can potentially be a single claim object that is not in an array. (This is the case for most of the schema.org properties: they are defined with a particular type but they could be an array of that type.) So check for `fulfills["@type"]` of "Offer" to set other `fulfills` variables.
Outdated
Review

What's a good way to recreate a claim object that has this particular structure? Gives that fulfill project offers always have @type: PlanAction, @type: Offer and @type: DonateAction. Gives that fulfill person offers always have @type: Offer and @type: DonateAction.

What's a good way to recreate a claim object that has this particular structure? Gives that fulfill project offers always have `@type: PlanAction`, `@type: Offer` and `@type: DonateAction`. Gives that fulfill person offers always have `@type: Offer` and `@type: DonateAction`.

You will have to create one by hand. I'll show how in the issue https://app.clickup.com/t/86b027guj

You will have to create one by hand. I'll show how in the issue https://app.clickup.com/t/86b027guj
Outdated
Review

Thanks, the video was very helpful! I was able to update the code block to test for both array and single-object fulfills. Now, "This fulfills an offer" shows up for both scenarios.

Since the logic is used in two places, I made a utility method for it.

Thanks, the video was very helpful! I was able to update the code block to test for both array and single-object `fulfills`. Now, "This fulfills an offer" shows up for both scenarios. Since the logic is used in two places, I made a utility method for it.
this.detailsForGive?.fullClaim?.fulfills
);
}
// =================================================

View File

@@ -718,32 +718,9 @@ 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;
// Handle both array and single object cases
let offerFulfill = null;
if (Array.isArray(fulfills)) {
// Find the Offer in the fulfills array
offerFulfill = fulfills.find((item) => item["@type"] === "Offer");
} else if (fulfills["@type"] === "Offer") {
// fulfills is a single Offer object
offerFulfill = fulfills;
}
if (offerFulfill) {
this.giveDetailsOfferFulfillment = {
offerHandleId: offerFulfill.identifier,
offerType: offerFulfill["@type"],
};
} else {
this.giveDetailsOfferFulfillment = null;
}
this.giveDetailsOfferFulfillment = libsUtil.extractOfferFulfillment(
this.giveDetails?.fullClaim?.fulfills
);
}
/**