@@ -14,7 +14,7 @@ final class AddEditCouponViewModel: ObservableObject {
1414 ///
1515 private let editingOption : EditingOption
1616
17- private let onSuccess : ( ( Result < Coupon , Error > ) -> Void )
17+ private let onSuccess : ( Coupon ) -> Void
1818
1919 /// Defines the current notice that should be shown.
2020 /// Defaults to `nil`.
@@ -191,7 +191,7 @@ final class AddEditCouponViewModel: ObservableObject {
191191 storageManager: StorageManagerType = ServiceLocator . storageManager,
192192 currencySettings: CurrencySettings = ServiceLocator . currencySettings,
193193 timezone: TimeZone = . siteTimezone,
194- onSuccess: @escaping ( ( Result < Coupon , Error > ) -> Void ) ) {
194+ onSuccess: @escaping ( Coupon ) -> Void ) {
195195 self . siteID = siteID
196196 editingOption = . creation
197197 self . discountType = discountType
@@ -219,7 +219,7 @@ final class AddEditCouponViewModel: ObservableObject {
219219 storageManager: StorageManagerType = ServiceLocator . storageManager,
220220 currencySettings: CurrencySettings = ServiceLocator . currencySettings,
221221 timezone: TimeZone = . siteTimezone,
222- onSuccess: @escaping ( ( Result < Coupon , Error > ) -> Void ) ) {
222+ onSuccess: @escaping ( Coupon ) -> Void ) {
223223 siteID = existingCoupon. siteID
224224 coupon = existingCoupon
225225 editingOption = . editing
@@ -273,7 +273,6 @@ final class AddEditCouponViewModel: ObservableObject {
273273 if let validationError = validateCouponLocally ( coupon) {
274274 notice = NoticeFactory . createCouponErrorNotice ( validationError,
275275 editingOption: editingOption)
276- onSuccess ( . failure( validationError) )
277276 return
278277 }
279278
@@ -285,7 +284,7 @@ final class AddEditCouponViewModel: ObservableObject {
285284 case . success( let coupon) :
286285 ServiceLocator . analytics. track ( . couponCreationSuccess)
287286 self . coupon = coupon
288- self . onSuccess ( result )
287+ self . onSuccess ( coupon )
289288 self . showingCouponCreationSuccess = true
290289 case . failure( let error) :
291290 DDLogError ( " ⛔️ Error creating the coupon: \( error) " )
@@ -303,7 +302,6 @@ final class AddEditCouponViewModel: ObservableObject {
303302 if let validationError = validateCouponLocally ( coupon) {
304303 notice = NoticeFactory . createCouponErrorNotice ( validationError,
305304 editingOption: editingOption)
306- onSuccess ( . failure( validationError) )
307305 return
308306 }
309307
@@ -312,9 +310,9 @@ final class AddEditCouponViewModel: ObservableObject {
312310 guard let self = self else { return }
313311 self . isLoading = false
314312 switch result {
315- case . success( _ ) :
313+ case . success( let updatedCoupon ) :
316314 ServiceLocator . analytics. track ( . couponUpdateSuccess)
317- self . onSuccess ( result )
315+ self . onSuccess ( updatedCoupon )
318316 onUpdateFinished ( )
319317 case . failure( let error) :
320318 DDLogError ( " ⛔️ Error updating the coupon: \( error) " )
0 commit comments