diff --git a/src/libs/util.ts b/src/libs/util.ts index c65f2f8a..4fb0aa93 100644 --- a/src/libs/util.ts +++ b/src/libs/util.ts @@ -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 ( diff --git a/src/views/ClaimView.vue b/src/views/ClaimView.vue index 0214c438..2c441687 100644 --- a/src/views/ClaimView.vue +++ b/src/views/ClaimView.vue @@ -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( + this.detailsForGive?.fullClaim?.fulfills + ); } // ================================================= diff --git a/src/views/ConfirmGiftView.vue b/src/views/ConfirmGiftView.vue index 93832640..95632bb7 100644 --- a/src/views/ConfirmGiftView.vue +++ b/src/views/ConfirmGiftView.vue @@ -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 + ); } /**