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:
Jose Olarte III
2025-09-01 21:24:46 +08:00
parent 3e5e2cd0bb
commit 1eeb013638
3 changed files with 41 additions and 52 deletions

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(
this.detailsForGive?.fullClaim?.fulfills
);
}
// =================================================