From 9eb9392b8b252622c73d453d7d89f4099edac129 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Mon, 23 Jun 2025 19:18:43 +0200 Subject: [PATCH] simplify calls to updateCurrency in purchaseService --- src/services/purchaseService.ts | 34 ++++++++------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index eeef731c..56cc9ed7 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -75,18 +75,12 @@ export const handlePurchase = async ( } if (!config.dontSubtractPurchaseCreditCost) { if (offer.RegularPrice) { - combineInventoryChanges( - prePurchaseInventoryChanges, - updateCurrency(inventory, offer.RegularPrice[0], false) - ); + updateCurrency(inventory, offer.RegularPrice[0], false, prePurchaseInventoryChanges); } } if (!config.dontSubtractPurchasePlatinumCost) { if (offer.PremiumPrice) { - combineInventoryChanges( - prePurchaseInventoryChanges, - updateCurrency(inventory, offer.PremiumPrice[0], true) - ); + updateCurrency(inventory, offer.PremiumPrice[0], true, prePurchaseInventoryChanges); } } if (!config.dontSubtractPurchaseItemCost) { @@ -172,15 +166,12 @@ export const handlePurchase = async ( ); combineInventoryChanges(purchaseResponse.InventoryChanges, prePurchaseInventoryChanges); - const currencyChanges = updateCurrency( + updateCurrency( inventory, purchaseRequest.PurchaseParams.ExpectedPrice, - purchaseRequest.PurchaseParams.UsePremium + purchaseRequest.PurchaseParams.UsePremium, + prePurchaseInventoryChanges ); - purchaseResponse.InventoryChanges = { - ...currencyChanges, - ...purchaseResponse.InventoryChanges - }; switch (purchaseRequest.PurchaseParams.Source) { case PurchaseSource.VoidTrader: { @@ -192,10 +183,7 @@ export const handlePurchase = async ( ); if (offer) { if (!config.dontSubtractPurchaseCreditCost) { - combineInventoryChanges( - purchaseResponse.InventoryChanges, - updateCurrency(inventory, offer.RegularPrice, false) - ); + updateCurrency(inventory, offer.RegularPrice, false, purchaseResponse.InventoryChanges); } if (purchaseRequest.PurchaseParams.ExpectedPrice) { throw new Error(`vendor purchase should not have an expected price`); @@ -256,16 +244,10 @@ export const handlePurchase = async ( const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem); if (offer) { if (typeof offer.credits == "number" && !config.dontSubtractPurchaseCreditCost) { - combineInventoryChanges( - purchaseResponse.InventoryChanges, - updateCurrency(inventory, offer.credits, false) - ); + updateCurrency(inventory, offer.credits, false, purchaseResponse.InventoryChanges); } if (typeof offer.platinum == "number" && !config.dontSubtractPurchasePlatinumCost) { - combineInventoryChanges( - purchaseResponse.InventoryChanges, - updateCurrency(inventory, offer.platinum, true) - ); + updateCurrency(inventory, offer.platinum, true, purchaseResponse.InventoryChanges); } if (offer.itemPrices && !config.dontSubtractPurchaseItemCost) { handleItemPrices(