Skip to content

Commit e84dc69

Browse files
authored
Merge pull request #300 from synonymdev/feat/card-pending-transactions
Progress cards
2 parents 8b64ef1 + 876e050 commit e84dc69

Some content is hidden

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

56 files changed

+350
-138
lines changed

app/src/main/java/to/bitkit/data/CacheStore.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.Flow
99
import kotlinx.coroutines.flow.first
1010
import kotlinx.coroutines.flow.map
1111
import kotlinx.serialization.Serializable
12+
import to.bitkit.data.dto.InProgressTransfer
1213
import to.bitkit.data.dto.PendingBoostActivity
1314
import to.bitkit.data.dto.TransactionMetadata
1415
import to.bitkit.data.serializers.AppCacheSerializer
@@ -130,6 +131,22 @@ class CacheStore @Inject constructor(
130131
}
131132
}
132133

134+
suspend fun addInProgressTransfer(item: InProgressTransfer) {
135+
if (item in store.data.first().inProgressTransfers) return
136+
137+
store.updateData {
138+
it.copy(inProgressTransfers = it.inProgressTransfers + item)
139+
}
140+
}
141+
142+
suspend fun removeInProgressTransfer(item: InProgressTransfer) {
143+
if (item !in store.data.first().inProgressTransfers) return
144+
145+
store.updateData {
146+
it.copy(inProgressTransfers = it.inProgressTransfers - item)
147+
}
148+
}
149+
133150
suspend fun reset() {
134151
store.updateData { AppCacheData() }
135152
Logger.info("Deleted all app cached data.")
@@ -153,4 +170,5 @@ data class AppCacheData(
153170
val activitiesPendingDelete: List<String> = listOf(),
154171
val pendingBoostActivities: List<PendingBoostActivity> = listOf(),
155172
val transactionsMetadata: List<TransactionMetadata> = listOf(),
173+
val inProgressTransfers: List<InProgressTransfer> = listOf(),
156174
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package to.bitkit.data.dto
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class InProgressTransfer(
7+
val activityId: String,
8+
val type: TransferType,
9+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package to.bitkit.data.dto
2+
3+
enum class TransferType {
4+
TO_SPENDING,
5+
TO_SAVINGS,
6+
FORCE_CLOSE,
7+
COOP_CLOSE,
8+
}

app/src/main/java/to/bitkit/models/Suggestion.kt

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,98 @@ enum class Suggestion(
1010
@StringRes val title: Int,
1111
@StringRes val description: Int,
1212
@DrawableRes val icon: Int,
13-
val color: Color
13+
val color: Color,
14+
val dismissible: Boolean = true,
1415
) {
1516
BUY(
1617
title = R.string.cards__buyBitcoin__title,
1718
description = R.string.cards__buyBitcoin__description,
18-
color = Colors.Brand,
19-
icon = R.drawable.b_emboss
19+
color = Colors.Brand24,
20+
icon = R.drawable.b_emboss,
2021
),
2122
LIGHTNING(
23+
// Lightning ready from RN
2224
title = R.string.cards__lightning__title,
2325
description = R.string.cards__lightning__description,
24-
color = Colors.Purple,
25-
icon = R.drawable.lightning
26+
color = Colors.Purple24,
27+
icon = R.drawable.lightning,
2628
),
2729
BACK_UP(
2830
title = R.string.cards__backupSeedPhrase__title,
2931
description = R.string.cards__backupSeedPhrase__description,
30-
color = Colors.Blue,
31-
icon = R.drawable.safe
32+
color = Colors.Blue24,
33+
icon = R.drawable.safe,
3234
),
3335
SECURE(
3436
title = R.string.cards__pin__title,
3537
description = R.string.cards__pin__description,
36-
color = Colors.Green,
38+
color = Colors.Green24,
3739
icon = R.drawable.shield
3840
),
3941
SUPPORT(
4042
title = R.string.cards__support__title,
4143
description = R.string.cards__support__description,
42-
color = Colors.Yellow,
44+
color = Colors.Yellow24,
4345
icon = R.drawable.lightbulb
4446
),
4547
INVITE(
4648
title = R.string.cards__invite__title,
4749
description = R.string.cards__invite__description,
48-
color = Colors.Blue,
50+
color = Colors.Blue24,
4951
icon = R.drawable.group
5052
),
5153
PROFILE(
5254
title = R.string.cards__slashtagsProfile__title,
5355
description = R.string.cards__slashtagsProfile__description,
54-
color = Colors.Brand,
56+
color = Colors.Brand24,
5557
icon = R.drawable.crown
5658
),
5759
SHOP(
5860
title = R.string.cards__shop__title,
5961
description = R.string.cards__shop__description,
60-
color = Colors.Yellow,
62+
color = Colors.Yellow24,
6163
icon = R.drawable.shopping_bag
6264
),
6365
QUICK_PAY(
6466
title = R.string.cards__quickpay__title,
6567
description = R.string.cards__quickpay__description,
66-
color = Colors.Green,
68+
color = Colors.Green24,
6769
icon = R.drawable.fast_forward
6870
),
71+
72+
/**Replaces SPEND when a LN channel is being force closed*/
73+
TRANSFER_PENDING(
74+
title = R.string.cards__lightningSettingUp__title,
75+
description = R.string.cards__transferPending__description,
76+
color = Colors.Purple24,
77+
icon = R.drawable.transfer,
78+
dismissible = false
79+
),
80+
81+
/**When the LN channel could not be cooped closed immediately*/
82+
TRANSFER_CLOSING_CHANNEL(
83+
title = R.string.cards__transferClosingChannel__title,
84+
description = R.string.cards__transferClosingChannel__description,
85+
color = Colors.Red24,
86+
icon = R.drawable.transfer,
87+
dismissible = false
88+
),
89+
90+
/**Replaces LIGHTNING when the transfer to spending balance is in progress*/
91+
LIGHTNING_SETTING_UP(
92+
title = R.string.cards__lightningSettingUp__title,
93+
description = R.string.cards__lightningSettingUp__description,
94+
color = Colors.Purple24,
95+
icon = R.drawable.transfer,
96+
dismissible = false
97+
),
98+
LIGHTNING_READY(
99+
title = R.string.cards__lightningReady__title,
100+
description = R.string.cards__lightningReady__description,
101+
color = Colors.Purple24,
102+
icon = R.drawable.transfer,
103+
dismissible = false,
104+
),
69105
}
70106

71107
fun String.toSuggestionOrNull() = Suggestion.entries.firstOrNull { it.name == this }

app/src/main/java/to/bitkit/repositories/ActivityRepo.kt

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import com.synonym.bitkitcore.SortDirection
88
import kotlinx.coroutines.CoroutineDispatcher
99
import kotlinx.coroutines.delay
1010
import kotlinx.coroutines.flow.first
11+
import kotlinx.coroutines.flow.map
1112
import kotlinx.coroutines.withContext
1213
import org.lightningdevkit.ldknode.PaymentDetails
1314
import to.bitkit.data.CacheStore
15+
import to.bitkit.data.dto.InProgressTransfer
1416
import to.bitkit.data.dto.PendingBoostActivity
17+
import to.bitkit.data.dto.TransferType
1518
import to.bitkit.di.BgDispatcher
1619
import to.bitkit.ext.matchesPaymentId
1720
import to.bitkit.ext.rawId
@@ -31,6 +34,8 @@ class ActivityRepo @Inject constructor(
3134

3235
var isSyncingLdkNodePayments = false
3336

37+
val inProgressTransfers = cacheStore.data.map { it.inProgressTransfers }
38+
3439
suspend fun syncActivities(): Result<Unit> = withContext(bgDispatcher) {
3540
Logger.debug("syncActivities called", context = TAG)
3641

@@ -49,6 +54,7 @@ class ActivityRepo @Inject constructor(
4954
syncLdkNodePayments(payments = payments)
5055
updateActivitiesMetadata()
5156
boostPendingActivities()
57+
updateInProgressTransfers()
5258
isSyncingLdkNodePayments = false
5359
return@withContext Result.success(Unit)
5460
}.onFailure { e ->
@@ -278,20 +284,33 @@ class ActivityRepo @Inject constructor(
278284

279285
when (activityToUpdate) {
280286
is Activity.Onchain -> {
287+
val onChainActivity = activityToUpdate.v1.copy(
288+
feeRate = activityMetaData.feeRate.toULong(),
289+
address = activityMetaData.address,
290+
isTransfer = activityMetaData.isTransfer,
291+
channelId = activityMetaData.channelId,
292+
transferTxId = activityMetaData.transferTxId
293+
)
281294
val updatedActivity = Onchain(
282-
v1 = activityToUpdate.v1.copy(
283-
feeRate = activityMetaData.feeRate.toULong(),
284-
address = activityMetaData.address,
285-
isTransfer = activityMetaData.isTransfer,
286-
channelId = activityMetaData.channelId,
287-
transferTxId = activityMetaData.transferTxId
288-
)
295+
v1 = onChainActivity
289296
)
290297

291298
updateActivity(
292299
id = updatedActivity.v1.id,
293300
activity = updatedActivity
294301
).onSuccess {
302+
if (onChainActivity.isTransfer && onChainActivity.doesExist) {
303+
cacheStore.addInProgressTransfer(
304+
InProgressTransfer(
305+
activityId = updatedActivity.v1.id,
306+
type = if (onChainActivity.txType == PaymentType.SENT) {
307+
TransferType.TO_SPENDING
308+
} else {
309+
TransferType.TO_SAVINGS
310+
}
311+
)
312+
)
313+
}
295314
cacheStore.removeTransactionMetadata(activityMetaData)
296315
}
297316
}
@@ -302,6 +321,18 @@ class ActivityRepo @Inject constructor(
302321
}
303322
}
304323

324+
private suspend fun updateInProgressTransfers() {
325+
cacheStore.data.first().inProgressTransfers.forEach { transfer ->
326+
getActivity(transfer.activityId).onSuccess { activity ->
327+
(activity as? Onchain)?.let { onChain ->
328+
if (onChain.v1.confirmed) {
329+
cacheStore.removeInProgressTransfer(transfer)
330+
}
331+
}
332+
}
333+
}
334+
}
335+
305336
private suspend fun boostPendingActivities() = withContext(bgDispatcher) {
306337
cacheStore.data.first().pendingBoostActivities.forEach { pendingBoostActivity ->
307338
findActivityByPaymentId(

app/src/main/java/to/bitkit/ui/components/BottomSheet.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import androidx.compose.ui.unit.Dp
2929
import androidx.compose.ui.unit.dp
3030
import to.bitkit.ui.scaffold.SheetTopBar
3131
import to.bitkit.ui.shared.modifiers.sheetHeight
32-
import to.bitkit.ui.shared.util.gradientBackground
32+
import to.bitkit.ui.shared.util.gradientLinearBackground
3333
import to.bitkit.ui.theme.AppShapes
3434
import to.bitkit.ui.theme.AppThemeSurface
3535
import to.bitkit.ui.theme.Colors
@@ -107,7 +107,7 @@ private fun Preview() {
107107
Column(
108108
modifier = Modifier
109109
.sheetHeight(isModal = true)
110-
.gradientBackground()
110+
.gradientLinearBackground()
111111
.padding(horizontal = 16.dp)
112112
) {
113113
SheetTopBar("Sheet Title")

0 commit comments

Comments
 (0)