Skip to content

Commit ed52332

Browse files
committed
feat: Boltz Swaps
1 parent 7a3de0b commit ed52332

File tree

151 files changed

+5764
-1724
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+5764
-1724
lines changed

androidApp/proguard-rules.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@
107107
-keep class breez_sdk.** { *; }
108108
-keepclassmembers class * extends technology.breez.* { public *; }
109109
-keepclassmembers class * extends breez_sdk.** { public *; }
110+
111+
# LWK
112+
-keep class lwk.** { *; }
113+
-keepclassmembers class * extends lwk.** { public *; }

androidApp/src/main/java/com/blockstream/green/database/AppDatabase.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import com.blockstream.common.data.DeviceIdentifier
1010
import com.blockstream.common.data.EncryptedData
1111
import com.blockstream.common.gdk.JsonConverter.Companion.JsonDeserializer
1212
import com.blockstream.common.gdk.data.PinData
13-
import com.blockstream.green.utils.isDevelopmentFlavor
1413

1514
@Database(
1615
entities = [Wallet::class, LoginCredentials::class],
@@ -45,10 +44,6 @@ abstract class AppDatabase : RoomDatabase() {
4544
builder.addMigrations(MIGRATION_4_5).build()
4645
builder.addMigrations(MIGRATION_5_6).build()
4746

48-
if (isDevelopmentFlavor) {
49-
// builder.fallbackToDestructiveMigration()
50-
}
51-
5247
return builder.build()
5348
}
5449
}

androidApp/src/main/java/com/blockstream/green/di/KoinAndroid.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fun initKoinAndroid(context: Context, doOnStartup: () -> Unit = {}) {
5454
}
5555
} binds (arrayOf(CountlyBase::class, CountlyAndroid::class))
5656
single {
57-
AndroidMigrator(get(), get(), get(), get(), get(), get())
57+
AndroidMigrator(get(), get(), get(), get(), get(), get(), get())
5858
}
5959
single {
6060
QATester(get())

androidApp/src/main/java/com/blockstream/green/di/ViewModels.kt

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ import com.blockstream.common.models.addresses.SignMessageViewModel
1212
import com.blockstream.common.models.archived.ArchivedAccountsViewModel
1313
import com.blockstream.common.models.camera.CameraViewModel
1414
import com.blockstream.common.models.demo.DemoViewModel
15-
import com.blockstream.common.models.devices.DeviceInfoViewModel
16-
import com.blockstream.common.models.devices.DeviceListViewModel
17-
import com.blockstream.common.models.devices.DeviceScanViewModel
18-
import com.blockstream.common.models.devices.ImportPubKeyViewModel
19-
import com.blockstream.common.models.devices.JadeGenuineCheckViewModel
20-
import com.blockstream.common.models.devices.JadeGuideViewModel
15+
import com.blockstream.common.models.devices.*
2116
import com.blockstream.common.models.exchange.AccountExchangeViewModel
2217
import com.blockstream.common.models.exchange.OnOffRampsViewModel
2318
import com.blockstream.common.models.home.HomeViewModel
@@ -32,40 +27,17 @@ import com.blockstream.common.models.onboarding.phone.EnterRecoveryPhraseViewMod
3227
import com.blockstream.common.models.onboarding.phone.PinViewModel
3328
import com.blockstream.common.models.onboarding.watchonly.WatchOnlyMultisigViewModel
3429
import com.blockstream.common.models.onboarding.watchonly.WatchOnlySinglesigViewModel
35-
import com.blockstream.common.models.overview.AccountOverviewViewModel
36-
import com.blockstream.common.models.overview.SecurityViewModel
37-
import com.blockstream.common.models.overview.TransactViewModel
38-
import com.blockstream.common.models.overview.WalletAssetsViewModel
39-
import com.blockstream.common.models.overview.WalletOverviewViewModel
30+
import com.blockstream.common.models.overview.*
4031
import com.blockstream.common.models.promo.PromoViewModel
4132
import com.blockstream.common.models.receive.ReceiveViewModel
4233
import com.blockstream.common.models.receive.RequestAmountViewModel
4334
import com.blockstream.common.models.recovery.RecoveryCheckViewModel
4435
import com.blockstream.common.models.recovery.RecoveryIntroViewModel
4536
import com.blockstream.common.models.recovery.RecoveryPhraseViewModel
4637
import com.blockstream.common.models.recovery.RecoveryWordsViewModel
47-
import com.blockstream.common.models.send.BumpViewModel
48-
import com.blockstream.common.models.send.DenominationViewModel
49-
import com.blockstream.common.models.send.FeeViewModel
50-
import com.blockstream.common.models.send.RedepositViewModel
51-
import com.blockstream.common.models.send.SendConfirmViewModel
52-
import com.blockstream.common.models.send.SendViewModel
53-
import com.blockstream.common.models.send.SweepViewModel
54-
import com.blockstream.common.models.settings.AppSettingsViewModel
55-
import com.blockstream.common.models.settings.DenominationExchangeRateViewModel
56-
import com.blockstream.common.models.settings.TwoFactorAuthenticationViewModel
57-
import com.blockstream.common.models.settings.TwoFactorSetupViewModel
58-
import com.blockstream.common.models.settings.WalletSettingsViewModel
59-
import com.blockstream.common.models.settings.WatchOnlyCredentialsSettingsViewModel
60-
import com.blockstream.common.models.settings.WatchOnlyViewModel
61-
import com.blockstream.common.models.sheets.AnalyticsViewModel
62-
import com.blockstream.common.models.sheets.AssetDetailsViewModel
63-
import com.blockstream.common.models.sheets.JadeFirmwareUpdateViewModel
64-
import com.blockstream.common.models.sheets.LightningNodeViewModel
65-
import com.blockstream.common.models.sheets.MeldCountriesViewModel
66-
import com.blockstream.common.models.sheets.NoteViewModel
67-
import com.blockstream.common.models.sheets.RecoveryHelpViewModel
68-
import com.blockstream.common.models.sheets.TransactionDetailsViewModel
38+
import com.blockstream.common.models.send.*
39+
import com.blockstream.common.models.settings.*
40+
import com.blockstream.common.models.sheets.*
6941
import com.blockstream.common.models.support.SupportViewModel
7042
import com.blockstream.common.models.transaction.TransactionViewModel
7143
import com.blockstream.common.models.twofactor.ReEnable2FAViewModel
@@ -152,7 +124,7 @@ val viewModels = module {
152124
AccountExchangeViewModel(get(), getOrNull())
153125
}
154126
viewModel {
155-
SendViewModel(get(), getOrNull(), getOrNull(), getOrNull())
127+
SendViewModel(get(), get(), get(), get())
156128
}
157129
viewModel {
158130
SimpleGreenViewModel(getOrNull(), getOrNull(), getOrNull(), getOrNull())
@@ -185,4 +157,4 @@ val viewModels = module {
185157
// https://github.com/InsertKoinIO/koin/issues/1352
186158
RecoveryPhraseViewModel(get(), getOrNull(), getOrNull())
187159
}
188-
}
160+
}

androidApp/src/main/java/com/blockstream/green/managers/FcmAndroid.kt

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import com.blockstream.common.data.GreenWallet
55
import com.blockstream.common.di.ApplicationScope
66
import com.blockstream.common.fcm.FcmCommon
77
import com.blockstream.common.lightning.BreezNotification
8-
import com.blockstream.green.data.notifications.models.NotificationData
8+
import com.blockstream.green.data.notifications.models.BoltzNotificationSimple
9+
import com.blockstream.green.data.notifications.models.MeldNotificationData
910
import com.blockstream.green.utils.Loggable
11+
import com.blockstream.green.work.BoltzWork
1012
import com.blockstream.green.work.LightningWork
1113
import com.blockstream.green.work.MeldPendingTransactionsWorker
1214
import org.koin.core.component.inject
@@ -25,6 +27,12 @@ class FcmAndroid constructor(
2527
LightningWork.create(walletId, breezNotification, context)
2628
}
2729

30+
override fun scheduleBoltzBackgroundJob(
31+
boltzNotificationData: BoltzNotificationSimple
32+
) {
33+
BoltzWork.create(boltzNotificationData, context)
34+
}
35+
2836
override suspend fun showOpenWalletNotification(
2937
wallet: GreenWallet,
3038
breezNotification: BreezNotification
@@ -33,13 +41,23 @@ class FcmAndroid constructor(
3341
notificationManager.createOpenWalletNotification(context, wallet)
3442
}
3543

44+
override suspend fun showSwapReceiveNotification(wallet: GreenWallet) {
45+
logger.d { "showSwapReceiveNotification $wallet" }
46+
notificationManager.createSwapPaymentReceiveNotification(context, wallet)
47+
}
48+
49+
override suspend fun showSwapSendNotification(wallet: GreenWallet) {
50+
logger.d { "showSwapSendNotification $wallet" }
51+
notificationManager.createSwapSendReceiveNotification(context, wallet)
52+
}
53+
3654
override suspend fun showLightningPaymentNotification(
3755
wallet: GreenWallet,
3856
paymentHash: String,
3957
satoshi: Long,
4058
) {
4159
logger.d { "showPaymentNotification $wallet" }
42-
notificationManager.createPaymentNotification(context, wallet, paymentHash, satoshi)
60+
notificationManager.createLightningPaymentNotification(context, wallet, paymentHash, satoshi)
4361
}
4462

4563
override fun showDebugNotification(
@@ -60,14 +78,14 @@ class FcmAndroid constructor(
6078
}
6179

6280
override fun showBuyTransactionNotification(
63-
notificationData: NotificationData
81+
meldNotificationData: MeldNotificationData
6482
) {
65-
notificationManager.createBuyTransactionNotification(context, notificationData)
66-
67-
notificationData.payload?.externalCustomerId?.let { externalCustomerId ->
83+
notificationManager.createBuyTransactionNotification(context, meldNotificationData)
84+
85+
meldNotificationData.payload?.externalCustomerId?.let { externalCustomerId ->
6886
scheduleMeldBackgroundJob(externalCustomerId)
6987
}
7088
}
7189

7290
companion object : Loggable()
73-
}
91+
}

androidApp/src/main/java/com/blockstream/green/managers/NotificationManagerAndroid.kt

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import blockstream_green.common.generated.resources.id_lightning_notifications
2525
import blockstream_green.common.generated.resources.id_logout
2626
import blockstream_green.common.generated.resources.id_open_wallet_to_receive_a_payment
2727
import blockstream_green.common.generated.resources.id_payment_received
28+
import blockstream_green.common.generated.resources.id_payment_sent
29+
import blockstream_green.common.generated.resources.id_swaps_notifications
2830
import blockstream_green.common.generated.resources.id_transactions_notifications
2931
import com.blockstream.common.data.GreenWallet
3032
import com.blockstream.common.data.LogoutReason
@@ -39,7 +41,7 @@ import com.blockstream.compose.theme.md_theme_primary
3941
import com.blockstream.green.BuildConfig
4042
import com.blockstream.green.GreenActivity
4143
import com.blockstream.green.R
42-
import com.blockstream.green.data.notifications.models.NotificationData
44+
import com.blockstream.green.data.notifications.models.MeldNotificationData
4345
import com.blockstream.green.utils.Loggable
4446
import kotlinx.coroutines.CoroutineScope
4547
import kotlinx.coroutines.SupervisorJob
@@ -167,6 +169,10 @@ class NotificationManagerAndroid constructor(
167169
LIGHTNING_CHANNEL_ID,
168170
getString(Res.string.id_lightning_notifications),
169171
NotificationManager.IMPORTANCE_HIGH
172+
), NotificationChannel(
173+
SWAPS_CHANNEL_ID,
174+
getString(Res.string.id_swaps_notifications),
175+
NotificationManager.IMPORTANCE_DEFAULT
170176
), NotificationChannel(
171177
TRANSACTION_CHANNEL_ID,
172178
getString(Res.string.id_transactions_notifications),
@@ -252,7 +258,7 @@ class NotificationManagerAndroid constructor(
252258
}
253259
}
254260

255-
suspend fun createPaymentNotification(
261+
suspend fun createLightningPaymentNotification(
256262
context: Context, wallet: GreenWallet, paymentHash: String, satoshi: Long
257263
): Notification {
258264
val intent = Intent(context, GreenActivity::class.java).also {
@@ -271,17 +277,67 @@ class NotificationManagerAndroid constructor(
271277
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build().also {
272278
androidNotificationManager.notify(
273279
notificationId(
274-
wallet, NotificationType.PAYMENT_RECEIVED, paymentHash
280+
wallet, NotificationType.LIGHTNING_PAYMENT_RECEIVED, paymentHash
281+
), it
282+
)
283+
}
284+
}
285+
286+
suspend fun createSwapPaymentReceiveNotification(
287+
context: Context, wallet: GreenWallet
288+
): Notification {
289+
val intent = Intent(context, GreenActivity::class.java).also {
290+
it.action = GreenActivity.OPEN_WALLET
291+
it.putExtra(GreenActivity.WALLET, wallet.toJson())
292+
}
293+
val pendingIntent = PendingIntent.getActivity(
294+
context, requestCode(wallet), intent, PendingIntent.FLAG_IMMUTABLE
295+
)
296+
297+
return NotificationCompat.Builder(context, SWAPS_CHANNEL_ID)
298+
.setSmallIcon(R.drawable.ic_stat_green).setContentTitle(wallet.name)
299+
.setContentText(getString(Res.string.id_payment_received))
300+
.setContentIntent(pendingIntent).setColorized(true).setColor(md_theme_primary.toArgb())
301+
.setPriority(NotificationCompat.PRIORITY_DEFAULT).setAutoCancel(true)
302+
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build().also {
303+
androidNotificationManager.notify(
304+
notificationId(
305+
wallet, NotificationType.SWAPS_PAYMENT_RECEIVED
306+
), it
307+
)
308+
}
309+
}
310+
311+
suspend fun createSwapSendReceiveNotification(
312+
context: Context, wallet: GreenWallet
313+
): Notification {
314+
val intent = Intent(context, GreenActivity::class.java).also {
315+
it.action = GreenActivity.OPEN_WALLET
316+
it.putExtra(GreenActivity.WALLET, wallet.toJson())
317+
}
318+
val pendingIntent = PendingIntent.getActivity(
319+
context, requestCode(wallet), intent, PendingIntent.FLAG_IMMUTABLE
320+
)
321+
322+
return NotificationCompat.Builder(context, SWAPS_CHANNEL_ID)
323+
.setSmallIcon(R.drawable.ic_stat_green).setContentTitle(wallet.name)
324+
.setContentText(getString(Res.string.id_payment_sent))
325+
.setContentIntent(pendingIntent).setColorized(true).setColor(md_theme_primary.toArgb())
326+
.setPriority(NotificationCompat.PRIORITY_DEFAULT).setAutoCancel(true)
327+
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build().also {
328+
androidNotificationManager.notify(
329+
notificationId(
330+
wallet, NotificationType.SWAPS_PAYMENT_SENT
275331
), it
276332
)
277333
}
278334
}
279335

280336
fun createBuyTransactionNotification(
281-
context: Context, notificationData: NotificationData
337+
context: Context, meldNotificationData: MeldNotificationData
282338
): Notification {
283-
val title = notificationData.title
284-
val body = notificationData.body
339+
val title = meldNotificationData.title
340+
val body = meldNotificationData.body
285341

286342
return NotificationCompat.Builder(context, TRANSACTION_CHANNEL_ID)
287343
.setSmallIcon(R.drawable.ic_stat_green)
@@ -290,7 +346,7 @@ class NotificationManagerAndroid constructor(
290346
.setColorized(true).setColor(md_theme_primary.toArgb())
291347
.setPriority(NotificationCompat.PRIORITY_DEFAULT).setAutoCancel(true)
292348
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build().also {
293-
androidNotificationManager.notify(notificationData.hashCode(), it)
349+
androidNotificationManager.notify(meldNotificationData.hashCode(), it)
294350
}
295351
}
296352

@@ -312,14 +368,14 @@ class NotificationManagerAndroid constructor(
312368
}
313369
}
314370

315-
suspend fun createForegroundServiceNotification(context: Context): Notification {
371+
suspend fun createLightningForegroundServiceNotification(context: Context): Notification {
316372
return NotificationCompat.Builder(context, LIGHTNING_CHANNEL_ID)
317373
.setContentTitle(getString(Res.string.id_lightning))
318374
.setTicker(getString(Res.string.id_lightning)).setOngoing(true).build()
319375
}
320376

321377
enum class NotificationType {
322-
CONNECTED, OPEN_WALLET, PAYMENT_RECEIVED, ONCHAIN_TRANSACTION_CONFIRMED
378+
CONNECTED, OPEN_WALLET, LIGHTNING_PAYMENT_RECEIVED, SWAPS_PAYMENT_RECEIVED, SWAPS_PAYMENT_SENT, ONCHAIN_TRANSACTION_CONFIRMED
323379
}
324380

325381
private fun notificationId(
@@ -334,9 +390,10 @@ class NotificationManagerAndroid constructor(
334390
companion object : Loggable() {
335391
const val WALLETS_CHANNEL_ID = "${BuildConfig.APPLICATION_ID}.WALLETS_CHANNEL_ID"
336392
const val LIGHTNING_CHANNEL_ID = "${BuildConfig.APPLICATION_ID}.LIGHTNING_CHANNEL_ID"
393+
const val SWAPS_CHANNEL_ID = "${BuildConfig.APPLICATION_ID}.SWAPS_CHANNEL_ID"
337394
const val TRANSACTION_CHANNEL_ID = "${BuildConfig.APPLICATION_ID}.TRANSACTION_CHANNEL_ID"
338395

339396
const val ACTION_LOGOUT = "${BuildConfig.APPLICATION_ID}.ACTION_LOGOUT"
340397
const val WALLET_ID = "WALLET_ID"
341398
}
342-
}
399+
}

0 commit comments

Comments
 (0)