Skip to content

Commit 70de58e

Browse files
authored
Merge pull request #743 from dashpay/hide-pc-in-cuba-russia
feat: hide PiggyCards for users in Russia and Cuba
2 parents 9bf4195 + 7e0bfe6 commit 70de58e

8 files changed

Lines changed: 363 additions & 24 deletions

File tree

DashWallet.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
192E5E737398F69154940D09 /* libPods-WatchApp Extension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1946AE4B077923ED5BEF70FD /* libPods-WatchApp Extension.a */; };
8787
1D267CDF2ECF86920053AD68 /* AddProviderToGiftCardsTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D267CDE2ECF86920053AD68 /* AddProviderToGiftCardsTable.swift */; };
8888
1D267CE02ECF86920053AD68 /* AddProviderToGiftCardsTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D267CDE2ECF86920053AD68 /* AddProviderToGiftCardsTable.swift */; };
89+
1DAD1B012ED4037F00C8090E /* GeoRestrictionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DAD1B002ED4037F00C8090E /* GeoRestrictionService.swift */; };
90+
1DAD1B022ED4037F00C8090E /* GeoRestrictionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DAD1B002ED4037F00C8090E /* GeoRestrictionService.swift */; };
8991
1DAD1AA92ED2037F00C8090E /* BarcodeScanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DAD1AA82ED2037F00C8090E /* BarcodeScanner.swift */; };
9092
1DAD1AAA2ED2037F00C8090E /* BarcodeScanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DAD1AA82ED2037F00C8090E /* BarcodeScanner.swift */; };
9193
1DD7BE9CD62998F12672140D /* RadioButtonRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 708B9F2B4B1E4C31B5010CDF /* RadioButtonRow.swift */; };
@@ -1793,6 +1795,7 @@
17931795
1946AE4B077923ED5BEF70FD /* libPods-WatchApp Extension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WatchApp Extension.a"; sourceTree = BUILT_PRODUCTS_DIR; };
17941796
1A13DF165F6A0780F58985AB /* Pods-DashWalletScreenshotsUITests.testnet.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DashWalletScreenshotsUITests.testnet.xcconfig"; path = "Target Support Files/Pods-DashWalletScreenshotsUITests/Pods-DashWalletScreenshotsUITests.testnet.xcconfig"; sourceTree = "<group>"; };
17951797
1D267CDE2ECF86920053AD68 /* AddProviderToGiftCardsTable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddProviderToGiftCardsTable.swift; sourceTree = "<group>"; };
1798+
1DAD1B002ED4037F00C8090E /* GeoRestrictionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeoRestrictionService.swift; sourceTree = "<group>"; };
17961799
1DAD1AA82ED2037F00C8090E /* BarcodeScanner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarcodeScanner.swift; sourceTree = "<group>"; };
17971800
1FA780FC3C067D0F6DEE9543 /* Pods-DashWalletTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DashWalletTests.debug.xcconfig"; path = "Target Support Files/Pods-DashWalletTests/Pods-DashWalletTests.debug.xcconfig"; sourceTree = "<group>"; };
17981801
222040C51C1A1940005CE1C3 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
@@ -5660,6 +5663,7 @@
56605663
47AE8B9828BFAD0000490F5E /* Services */ = {
56615664
isa = PBXGroup;
56625665
children = (
5666+
1DAD1B002ED4037F00C8090E /* GeoRestrictionService.swift */,
56635667
1DAD1AA82ED2037F00C8090E /* BarcodeScanner.swift */,
56645668
757AEBDD2E113D7B007BE8B4 /* DashSpend */,
56655669
47AE8BAC28BFAE6700490F5E /* DWLocationManager.swift */,
@@ -8700,6 +8704,7 @@
87008704
2AD1CE8A22DC9C6F00C99324 /* DWVerifySeedPhraseContentView.m in Sources */,
87018705
47A2A2E2293DCCEA00938DB7 /* Coinbase+Constants.swift in Sources */,
87028706
47AE8C0728C2274200490F5E /* PointOfUseListSearchCell.swift in Sources */,
8707+
1DAD1B012ED4037F00C8090E /* GeoRestrictionService.swift in Sources */,
87038708
1DAD1AA92ED2037F00C8090E /* BarcodeScanner.swift in Sources */,
87048709
4774DCE128F44BA4008CF87D /* ServiceDataProvider.swift in Sources */,
87058710
C9F451E72A0BA16400825057 /* PaymentButton.swift in Sources */,
@@ -9817,6 +9822,7 @@
98179822
C943B4FF2A40A54600AF23C5 /* DWDPGenericContactRequestItemView.m in Sources */,
98189823
C9D2C8402A320AA000D15901 /* DWQRScanView.m in Sources */,
98199824
75C1F0462AE26AC0006929CA /* CoinJoinLevelsViewModel.swift in Sources */,
9825+
1DAD1B022ED4037F00C8090E /* GeoRestrictionService.swift in Sources */,
98209826
1DAD1AAA2ED2037F00C8090E /* BarcodeScanner.swift in Sources */,
98219827
C9D2C8412A320AA000D15901 /* ServiceItem.swift in Sources */,
98229828
C9D2C8422A320AA000D15901 /* ErrorPresentable.swift in Sources */,

DashWallet/AppDelegate.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,23 @@ - (void)applicationWillEnterForeground:(UIApplication *)application {
158158

159159
- (void)applicationDidBecomeActive:(UIApplication *)application {
160160
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
161-
161+
162162
//
163163
// THIS IS IMPORTANT!
164164
//
165165
// When adding any logic here mind the migration process
166166
//
167167
[self.balanceNotifier updateBalance];
168+
169+
// Check geo-restriction for PiggyCards (if available)
170+
// This logs location info each time the app becomes active for debugging
171+
SEL checkGeoRestrictionSelector = NSSelectorFromString(@"checkGeoRestriction");
172+
if ([ExploreDashObjcWrapper respondsToSelector:checkGeoRestrictionSelector]) {
173+
#pragma clang diagnostic push
174+
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
175+
[ExploreDashObjcWrapper performSelector:checkGeoRestrictionSelector];
176+
#pragma clang diagnostic pop
177+
}
168178
}
169179

170180
- (void)applicationWillTerminate:(UIApplication *)application {

DashWallet/Sources/Models/Explore Dash/ExploreDash.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ public class ExploreDashObjcWrapper: NSObject {
5252
public class func configure() {
5353
do {
5454
try ExploreDash.configure()
55+
56+
#if PIGGYCARDS_ENABLED
57+
// Initialize GeoRestrictionService to detect user's country early
58+
// This enables filtering PiggyCards for users in restricted regions (Russia/Cuba)
59+
Task { @MainActor in
60+
await GeoRestrictionService.shared.checkRestriction()
61+
}
62+
#endif
5563
} catch {
5664
print(error)
5765
// Do something
@@ -73,6 +81,15 @@ public class ExploreDashObjcWrapper: NSObject {
7381
@objc public class var lastFailedSyncDate: Date? {
7482
ExploreDash.shared.lastFailedSyncDate
7583
}
84+
85+
#if PIGGYCARDS_ENABLED
86+
/// Check geo-restriction status. Call this when the app becomes active to log location info.
87+
@objc public class func checkGeoRestriction() {
88+
Task { @MainActor in
89+
await GeoRestrictionService.shared.checkRestriction()
90+
}
91+
}
92+
#endif
7693
}
7794

7895
// MARK: - ExploreDash

DashWallet/Sources/Models/Explore Dash/Infrastructure/DAO Impl/MerchantDAO.swift

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,14 @@ class MerchantDAO: PointOfUseDAO {
134134
// Using literal expression to handle cases where redeemType column might not exist
135135
queryFilter = queryFilter && Expression<Bool>(literal: "(redeemType IS NULL OR redeemType != 'url')")
136136

137-
// Filter out PiggyCards-only merchants when PIGGYCARDS_ENABLED is not defined
138-
#if !PIGGYCARDS_ENABLED
137+
// Filter out PiggyCards-only merchants when:
138+
// 1. PIGGYCARDS_ENABLED is not defined, OR
139+
// 2. PIGGYCARDS_ENABLED is defined but user is in a restricted region (Russia or Cuba)
140+
#if PIGGYCARDS_ENABLED
141+
if isPiggyCardsGeoRestricted() {
142+
queryFilter = queryFilter && Expression<Bool>(literal: "merchantId NOT IN (SELECT DISTINCT merchantId FROM gift_card_providers WHERE provider = 'PiggyCards' AND merchantId NOT IN (SELECT DISTINCT merchantId FROM gift_card_providers WHERE provider != 'PiggyCards'))")
143+
}
144+
#else
139145
queryFilter = queryFilter && Expression<Bool>(literal: "merchantId NOT IN (SELECT DISTINCT merchantId FROM gift_card_providers WHERE provider = 'PiggyCards' AND merchantId NOT IN (SELECT DISTINCT merchantId FROM gift_card_providers WHERE provider != 'PiggyCards'))")
140146
#endif
141147

@@ -202,12 +208,21 @@ class MerchantDAO: PointOfUseDAO {
202208
// Fetch gift card providers for each merchant that accepts gift cards
203209
for (index, item) in allItems.enumerated() {
204210
if let merchant = item.merchant, merchant.paymentMethod == .giftCard {
205-
// Only fetch CTX providers when PiggyCards is disabled
211+
// Only fetch CTX providers when PiggyCards is disabled or user is in restricted region
206212
#if PIGGYCARDS_ENABLED
207-
let providersQuery = """
208-
SELECT provider, savingsPercentage, denominationsType, sourceId FROM gift_card_providers
209-
WHERE merchantId = '\(merchant.merchantId)'
210-
"""
213+
let excludePiggyCards = isPiggyCardsGeoRestricted()
214+
let providersQuery: String
215+
if excludePiggyCards {
216+
providersQuery = """
217+
SELECT provider, savingsPercentage, denominationsType, sourceId FROM gift_card_providers
218+
WHERE merchantId = '\(merchant.merchantId)' AND provider != 'PiggyCards'
219+
"""
220+
} else {
221+
providersQuery = """
222+
SELECT provider, savingsPercentage, denominationsType, sourceId FROM gift_card_providers
223+
WHERE merchantId = '\(merchant.merchantId)'
224+
"""
225+
}
211226
#else
212227
let providersQuery = """
213228
SELECT provider, savingsPercentage, denominationsType FROM gift_card_providers
@@ -434,12 +449,21 @@ class MerchantDAO: PointOfUseDAO {
434449
// Fetch gift card providers for each merchant that accepts gift cards
435450
for (index, item) in items.enumerated() {
436451
if let merchant = item.merchant, merchant.paymentMethod == .giftCard {
437-
// Only fetch CTX providers when PiggyCards is disabled
452+
// Only fetch CTX providers when PiggyCards is disabled or user is in restricted region
438453
#if PIGGYCARDS_ENABLED
439-
let providersQuery = """
440-
SELECT provider, savingsPercentage, denominationsType, sourceId FROM gift_card_providers
441-
WHERE merchantId = '\(merchant.merchantId)'
442-
"""
454+
let excludePiggyCards = isPiggyCardsGeoRestricted()
455+
let providersQuery: String
456+
if excludePiggyCards {
457+
providersQuery = """
458+
SELECT provider, savingsPercentage, denominationsType, sourceId FROM gift_card_providers
459+
WHERE merchantId = '\(merchant.merchantId)' AND provider != 'PiggyCards'
460+
"""
461+
} else {
462+
providersQuery = """
463+
SELECT provider, savingsPercentage, denominationsType, sourceId FROM gift_card_providers
464+
WHERE merchantId = '\(merchant.merchantId)'
465+
"""
466+
}
443467
#else
444468
let providersQuery = """
445469
SELECT provider, savingsPercentage, denominationsType FROM gift_card_providers
@@ -629,11 +653,27 @@ extension MerchantDAO {
629653
// Fetch gift card provider information for gift card merchants
630654
for (index, item) in items.enumerated() {
631655
if let merchant = item.merchant, merchant.paymentMethod == .giftCard {
632-
// Use parameterized query to avoid SQL injection
656+
// Filter out PiggyCards providers when user is in restricted region
657+
#if PIGGYCARDS_ENABLED
658+
let excludePiggyCards = isPiggyCardsGeoRestricted()
659+
let providersQuery: String
660+
if excludePiggyCards {
661+
providersQuery = """
662+
SELECT provider, savingsPercentage, denominationsType, sourceId FROM gift_card_providers
663+
WHERE merchantId = ? AND provider != 'PiggyCards'
664+
"""
665+
} else {
666+
providersQuery = """
667+
SELECT provider, savingsPercentage, denominationsType, sourceId FROM gift_card_providers
668+
WHERE merchantId = ?
669+
"""
670+
}
671+
#else
633672
let providersQuery = """
634673
SELECT provider, savingsPercentage, denominationsType, sourceId FROM gift_card_providers
635-
WHERE merchantId = ?
674+
WHERE merchantId = ? AND provider = 'CTX'
636675
"""
676+
#endif
637677

638678
do {
639679
guard let db = wSelf.connection.db else {

0 commit comments

Comments
 (0)