@@ -222,7 +222,7 @@ private extension WooShippingStore {
222222 guard let self else { return }
223223 switch result {
224224 case . success( let label) :
225- upsertShippingLabelInBackground ( shippingLabel: label) {
225+ upsertShippingLabelRefundInBackground ( shippingLabel: label) {
226226 completion ( . success( label) )
227227 }
228228 case . failure( let error) :
@@ -548,38 +548,28 @@ private extension WooShippingStore {
548548 storageSavedPackage. package = predefinedPackage
549549 }
550550
551- /// Updates/inserts the specified shipping label *in a background thread*.
551+ /// Updates the specified shipping label with the given refund *in a background thread*.
552552 /// `onCompletion` will be called on the main thread!
553- func upsertShippingLabelInBackground( shippingLabel: ShippingLabel ,
554- onCompletion: @escaping ( ) -> Void ) {
555- storageManager. performAndSave ( { [ weak self] storage in
556- guard let self else { return }
557- guard let storageOrder = storage. loadOrder ( siteID: shippingLabel. siteID, orderID: shippingLabel. orderID) else {
558- return
559- }
553+ func upsertShippingLabelRefundInBackground( shippingLabel: ShippingLabel ,
554+ onCompletion: @escaping ( ) -> Void ) {
555+ storageManager. performAndSave ( { storage in
560556 let storageShippingLabel = storage. loadShippingLabel ( siteID: shippingLabel. siteID,
561557 orderID: shippingLabel. orderID,
562- shippingLabelID: shippingLabel. shippingLabelID) ??
563- storage . insertNewObject ( ofType : Storage . ShippingLabel . self )
564- storageShippingLabel . update ( with : shippingLabel )
565- storageShippingLabel . order = storageOrder
558+ shippingLabelID: shippingLabel. shippingLabelID)
559+ guard let storageShippingLabel else {
560+ return
561+ }
566562
567- update ( shippingLabel: storageShippingLabel, withRefund: shippingLabel. refund, using: storage)
563+ if let refund = shippingLabel. refund {
564+ let storageRefund = storageShippingLabel. refund ?? storage. insertNewObject ( ofType: Storage . ShippingLabelRefund. self)
565+ storageRefund. update ( with: refund)
566+ storageShippingLabel. refund = storageRefund
567+ } else {
568+ storageShippingLabel. refund = nil
569+ }
568570
569571 } , completion: onCompletion, on: . main)
570572 }
571-
572- func update( shippingLabel storageShippingLabel: StorageShippingLabel ,
573- withRefund refund: ShippingLabelRefund ? ,
574- using storage: StorageType ) {
575- if let refund {
576- let storageRefund = storageShippingLabel. refund ?? storage. insertNewObject ( ofType: Storage . ShippingLabelRefund. self)
577- storageRefund. update ( with: refund)
578- storageShippingLabel. refund = storageRefund
579- } else {
580- storageShippingLabel. refund = nil
581- }
582- }
583573}
584574
585575/// Represents errors that can be returned when purchasing a shipping label
0 commit comments