refactor(claims): extract offer fulfillment logic to utility function
Created extractOfferFulfillment utility in libs/util.ts to handle both array and single object cases for fulfills field. Updated ClaimView and ConfirmGiftView to use the shared utility, eliminating code duplication and improving maintainability.
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
// =================================================
|
||||
|
||||
Reference in New Issue
Block a user