From b12a9cc47634bdff828140a1fc92021bde6126a1 Mon Sep 17 00:00:00 2001 From: Andrea Busi Date: Thu, 24 Apr 2025 12:46:53 +0200 Subject: [PATCH] fix: Solve wrong sort in subscriptions --- .../InApp/SubscriptionsViewController.swift | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift b/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift index f64114b..2f32352 100644 --- a/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift +++ b/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift @@ -119,14 +119,21 @@ class SubscriptionsViewController: UITableViewController { let isSubscription = product.isSubscription return isPurchased && isSubscription }.sorted { lProduct, rProduct in - // if user has more than one subscriptions, - // show first the Top10k - let lIs10k = lProduct.isTop100k - let rIs10k = rProduct.isTop100k - if lIs10k { - return lIs10k + // If user has more than one subscriptions, + // show first the Top10k. + let lIs10k = lProduct.isTop10k + let rIs10k = rProduct.isTop10k + + // If left item is Top10k, order first + if lIs10k && !rIs10k { + return true + } else if !lProduct.isTop10k && rProduct.isTop10k { + // right product is Top10k, left no + return false + } else { + // both products Top10k or Top100k, keep existing order + return false } - return rIs10k } self.productSubscribed = purchased.first self.products = products.sorted(by: { $0.productIdentifier > $1.productIdentifier })