Skip to content

Commit 562332e

Browse files
JOHNJOHN
authored andcommitted
feat: add notification throttling and release build dry-run defaults
1 parent 96c8b69 commit 562332e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

app/src/main/java/to/bitkit/paykit/PaykitFeatureFlags.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,16 @@ object PaykitFeatureFlags {
112112
private fun setDefaults() {
113113
prefs?.let { p ->
114114
if (!p.contains(ENABLED_KEY)) {
115+
// Dry-run is enabled by default only in debug builds.
116+
// In release builds, real payments execute immediately.
117+
val dryRunDefault = to.bitkit.BuildConfig.DEBUG
118+
115119
p.edit()
116120
.putBoolean(ENABLED_KEY, false) // Disabled by default until ready
117121
.putBoolean(LIGHTNING_ENABLED_KEY, true)
118122
.putBoolean(ONCHAIN_ENABLED_KEY, true)
119123
.putBoolean(RECEIPT_STORAGE_ENABLED_KEY, true)
120-
.putBoolean(DRY_RUN_KEY, true) // Dry-run enabled by default for safety
124+
.putBoolean(DRY_RUN_KEY, dryRunDefault)
121125
.apply()
122126
}
123127
}

app/src/main/java/to/bitkit/paykit/workers/SubscriptionCheckWorker.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,24 @@ class SubscriptionCheckWorker @AssistedInject constructor(
343343

344344
/**
345345
* Schedule notifications for upcoming subscription payments.
346+
* Notifications are throttled to once per subscription per billing period.
346347
*/
347348
private fun scheduleUpcomingNotifications() {
348349
val upcomingSubscriptions = getUpcomingSubscriptions(withinHours = 24)
350+
val prefs = appContext.getSharedPreferences("subscription_notifications", Context.MODE_PRIVATE)
349351

350352
for (subscription in upcomingSubscriptions) {
353+
val nextDue = subscription.nextPaymentAt ?: continue
354+
val notificationKey = "notified_${subscription.id}_${nextDue}"
355+
356+
// Check if we've already notified for this billing cycle
357+
if (prefs.getBoolean(notificationKey, false)) {
358+
continue
359+
}
360+
361+
// Send notification and mark as notified
351362
sendUpcomingPaymentNotification(subscription)
363+
prefs.edit().putBoolean(notificationKey, true).apply()
352364
}
353365
}
354366

0 commit comments

Comments
 (0)