Skip to content

Commit 5ef3c93

Browse files
committed
fix(flipcash/persistence): allow activity feed item amount rate to be inferred
drop messages table and refetch Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent f1b2168 commit 5ef3c93

7 files changed

Lines changed: 107 additions & 16 deletions

File tree

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/feed/ActivityFeedMessage.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.flipcash.app.core.feed
22

3+
import androidx.compose.runtime.derivedStateOf
4+
import androidx.compose.runtime.getValue
5+
import androidx.compose.runtime.remember
36
import com.getcode.opencode.model.core.ID
47
import com.getcode.opencode.model.financial.LocalFiat
58
import com.getcode.solana.keys.PublicKey
@@ -14,7 +17,18 @@ data class ActivityFeedMessage(
1417
val timestamp: Instant,
1518
val state: MessageState,
1619
val metadata: MessageMetadata?
17-
)
20+
) {
21+
val isTransaction: Boolean
22+
get() = amount != null
23+
24+
val canCancel: Boolean
25+
get() {
26+
metadata ?: return false
27+
val metadata =
28+
(metadata as? MessageMetadata.SentUsdc) ?: return false
29+
return metadata.canCancel
30+
}
31+
}
1832

1933
enum class MessageState {
2034
UNKNOWN,

apps/flipcash/shared/activityfeed/src/main/kotlin/com/flipcash/app/activityfeed/ActivityFeedCoordinator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ActivityFeedCoordinator @Inject constructor(
8686
queryOptions = QueryOptions(
8787
limit = count,
8888
token = latest?.id,
89-
descending = false
89+
descending = latest == null,
9090
)
9191
).onSuccess { dataSource.upsert(it) }.map { Unit }
9292
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"formatVersion": 1,
3+
"database": {
4+
"version": 2,
5+
"identityHash": "6f0e1586aaf4ec500c89b06fb990e7f2",
6+
"entities": [
7+
{
8+
"tableName": "messages",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`idBase58` TEXT NOT NULL, `text` TEXT NOT NULL, `amountUsdc` INTEGER, `amountNative` INTEGER, `nativeCurrency` TEXT, `rate` REAL, `state` TEXT NOT NULL, `timestamp` INTEGER NOT NULL, `metadata` TEXT, PRIMARY KEY(`idBase58`))",
10+
"fields": [
11+
{
12+
"fieldPath": "idBase58",
13+
"columnName": "idBase58",
14+
"affinity": "TEXT",
15+
"notNull": true
16+
},
17+
{
18+
"fieldPath": "text",
19+
"columnName": "text",
20+
"affinity": "TEXT",
21+
"notNull": true
22+
},
23+
{
24+
"fieldPath": "amountUsdc",
25+
"columnName": "amountUsdc",
26+
"affinity": "INTEGER"
27+
},
28+
{
29+
"fieldPath": "amountNative",
30+
"columnName": "amountNative",
31+
"affinity": "INTEGER"
32+
},
33+
{
34+
"fieldPath": "nativeCurrency",
35+
"columnName": "nativeCurrency",
36+
"affinity": "TEXT"
37+
},
38+
{
39+
"fieldPath": "rate",
40+
"columnName": "rate",
41+
"affinity": "REAL"
42+
},
43+
{
44+
"fieldPath": "state",
45+
"columnName": "state",
46+
"affinity": "TEXT",
47+
"notNull": true
48+
},
49+
{
50+
"fieldPath": "timestamp",
51+
"columnName": "timestamp",
52+
"affinity": "INTEGER",
53+
"notNull": true
54+
},
55+
{
56+
"fieldPath": "metadata",
57+
"columnName": "metadata",
58+
"affinity": "TEXT"
59+
}
60+
],
61+
"primaryKey": {
62+
"autoGenerate": false,
63+
"columnNames": [
64+
"idBase58"
65+
]
66+
}
67+
}
68+
],
69+
"setupQueries": [
70+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
71+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '6f0e1586aaf4ec500c89b06fb990e7f2')"
72+
]
73+
}
74+
}

apps/flipcash/shared/persistence/db/src/main/kotlin/com/flipcash/app/persistence/FlipcashDatabase.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.flipcash.app.persistence
22

33
import android.content.Context
4+
import androidx.room.AutoMigration
45
import androidx.room.Database
56
import androidx.room.Room
67
import androidx.room.RoomDatabase
8+
import androidx.room.migration.AutoMigrationSpec
9+
import androidx.room.migration.Migration
10+
import androidx.sqlite.db.SupportSQLiteDatabase
711
import com.flipcash.app.persistence.dao.MessageDao
812
import com.flipcash.app.persistence.entities.MessageEntity
913
import com.getcode.utils.TraceType
@@ -15,13 +19,22 @@ import org.kin.sdk.base.tools.subByteArray
1519
entities = [
1620
MessageEntity::class
1721
],
18-
version = 1,
22+
autoMigrations = [
23+
AutoMigration(from = 1, to = 2, spec = FlipcashDatabase.Migration1To2::class),
24+
],
25+
version = 2,
1926
)
2027
//@TypeConverters(Converters::class)
2128
abstract class FlipcashDatabase : RoomDatabase() {
2229

2330
abstract fun messageDao(): MessageDao
2431

32+
class Migration1To2 : Migration(1, 2), AutoMigrationSpec {
33+
override fun migrate(db: SupportSQLiteDatabase) {
34+
db.execSQL("DELETE FROM messages")
35+
}
36+
}
37+
2538
companion object {
2639
private var instance: FlipcashDatabase? = null
2740
fun requireInstance() = requireNotNull(instance)

apps/flipcash/shared/persistence/sources/src/main/kotlin/com/flipcash/app/persistence/sources/mapper/NotificationToEntityMapper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class SingleNotificationToEntityMapper @Inject constructor(
2626

2727
val (usdc, native, currency, fx) = from.amount?.let { amount ->
2828
AmountHolder(
29-
usdc = amount.usdc.quarks.toLong(),
30-
native = amount.converted.quarks.toLong(),
29+
usdc = amount.usdc.quarks,
30+
native = amount.converted.quarks,
3131
currency = amount.converted.currencyCode.name,
3232
fx = amount.rate.fx
3333
)

apps/flipcash/shared/persistence/sources/src/main/kotlin/com/flipcash/app/persistence/sources/mediator/FeedRemoteMediator.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class FeedRemoteMediator(
1919
private val dataSource: MessageDataSource,
2020
): RemoteMediator<Int, MessageEntity>() {
2121

22-
private var lastResult = listOf<ActivityFeedNotification>()
23-
2422
override suspend fun initialize(): InitializeAction {
2523
return InitializeAction.SKIP_INITIAL_REFRESH
2624
}
@@ -44,21 +42,14 @@ class FeedRemoteMediator(
4442

4543
val queryOptions = QueryOptions(
4644
token = loadKey,
47-
limit = state.config.pageSize
45+
limit = state.config.pageSize,
4846
)
4947

5048
val notifications = controller.queryNotificationsFor(
5149
ActivityFeedType.TransactionHistory,
5250
queryOptions
5351
).getOrNull().orEmpty()
5452

55-
if (notifications.isEmpty() || lastResult.any { it.id == notifications.firstOrNull()?.id.orEmpty() }) {
56-
lastResult = emptyList()
57-
return MediatorResult.Success(true)
58-
}
59-
60-
lastResult = notifications
61-
6253
withContext(Dispatchers.IO) {
6354
if (loadType == LoadType.REFRESH) {
6455
dataSource.clear()

services/flipcash/src/main/kotlin/com/flipcash/services/internal/domain/ActivityFeedMessageMapper.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ internal class ActivityFeedMessageMapper @Inject constructor(
2525
LocalFiat(
2626
usdc = Fiat(quarks = it.quarks),
2727
converted = Fiat(fiat = it.nativeAmount, currencyCode = CurrencyCode.tryValueOf(it.currency) ?: CurrencyCode.USD),
28-
rate = Rate.ignore
2928
)
3029
},
3130
timestamp = Instant.fromEpochSeconds(from.ts.seconds, 0),

0 commit comments

Comments
 (0)