Fix offer fulfillment detection + consistencies between ClaimView and ConfirmGiftView #167
@@ -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 (
|
||||
|
||||
@@ -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
|
||||
this.detailsForGive?.fullClaim?.fulfills
|
||||
);
|
||||
}
|
||||
|
||||
// =================================================
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user
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 otherfulfillsvariables.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: Offerand@type: DonateAction. Gives that fulfill person offers always have@type: Offerand@type: DonateAction.You will have to create one by hand. I'll show how in the issue https://app.clickup.com/t/86b027guj
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.