Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ dependencies {
implementation(Libs.okhttp)
implementation(Libs.mixpanel)

implementation(Libs.androidx_paging_runtime)

kapt(Libs.androidx_room_compiler)
implementation(Libs.sqlcipher)

Expand Down
272 changes: 272 additions & 0 deletions api/schemas/com.getcode.db.AppDatabase/8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"formatVersion": 1,
"database": {
"version": 8,
"identityHash": "45c39753eadbdaeddb35d2e002424dac",
"entities": [
{
"tableName": "CurrencyRate",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `rate` REAL NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "rate",
"columnName": "rate",
"affinity": "REAL",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "FaqItem",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` INTEGER PRIMARY KEY AUTOINCREMENT, `question` TEXT NOT NULL, `answer` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "uid",
"columnName": "uid",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "question",
"columnName": "question",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "answer",
"columnName": "answer",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"uid"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "PrefInt",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `value` INTEGER NOT NULL, PRIMARY KEY(`key`))",
"fields": [
{
"fieldPath": "key",
"columnName": "key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "value",
"columnName": "value",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"key"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "PrefString",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `value` TEXT NOT NULL, PRIMARY KEY(`key`))",
"fields": [
{
"fieldPath": "key",
"columnName": "key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "value",
"columnName": "value",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"key"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "PrefBool",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `value` INTEGER NOT NULL, PRIMARY KEY(`key`))",
"fields": [
{
"fieldPath": "key",
"columnName": "key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "value",
"columnName": "value",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"key"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "PrefDouble",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `value` REAL NOT NULL, PRIMARY KEY(`key`))",
"fields": [
{
"fieldPath": "key",
"columnName": "key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "value",
"columnName": "value",
"affinity": "REAL",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"key"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "SendLimit",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `limit` REAL NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "limit",
"columnName": "limit",
"affinity": "REAL",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "GiftCard",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `entropy` TEXT NOT NULL, `amount` INTEGER NOT NULL, `date` INTEGER NOT NULL, PRIMARY KEY(`key`))",
"fields": [
{
"fieldPath": "key",
"columnName": "key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "entropy",
"columnName": "entropy",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "amount",
"columnName": "amount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "date",
"columnName": "date",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"key"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "exchangeData",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`fiat` REAL NOT NULL, `currency` TEXT NOT NULL, `synced_at` INTEGER NOT NULL, PRIMARY KEY(`currency`))",
"fields": [
{
"fieldPath": "fx",
"columnName": "fiat",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "currency",
"columnName": "currency",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "synced",
"columnName": "synced_at",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"currency"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '45c39753eadbdaeddb35d2e002424dac')"
]
}
}
14 changes: 12 additions & 2 deletions api/src/main/java/com/getcode/db/AppDatabase.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.getcode.db

import android.content.Context
import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.DeleteTable
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.room.migration.AutoMigrationSpec
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.getcode.model.*
import com.getcode.network.repository.decodeBase64
import com.getcode.vendor.Base58
Expand All @@ -16,7 +21,6 @@ import java.io.File

@Database(
entities = [
HistoricalTransaction::class,
CurrencyRate::class,
FaqItem::class,
PrefInt::class,
Expand All @@ -27,7 +31,10 @@ import java.io.File
GiftCard::class,
ExchangeRate::class,
],
version = 7
autoMigrations = [
AutoMigration(from = 7, to = 8, spec = AppDatabase.Migration7To8::class)
],
version = 8
)
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
Expand All @@ -37,6 +44,9 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun prefDoubleDao(): PrefDoubleDao
abstract fun giftCardDao(): GiftCardDao
abstract fun exchangeDao(): ExchangeDao

@DeleteTable(tableName = "HistoricalTransaction")
class Migration7To8 : AutoMigrationSpec
}

object Database {
Expand Down
9 changes: 5 additions & 4 deletions api/src/main/java/com/getcode/manager/SessionManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import javax.inject.Singleton


@Singleton
class SessionManager @Inject constructor(
) {
class SessionManager @Inject constructor() {
data class SessionState(
val entropyB64: String? = null,
val keyPair: Ed25519.KeyPair? = null,
Expand All @@ -26,7 +25,9 @@ class SessionManager @Inject constructor(

fun set(context: Context, entropyB64: String) {
val mnemonic = MnemonicPhrase.fromEntropyB64(context, entropyB64)
if (getOrganizer()?.mnemonic?.words == mnemonic.words) return
if (getOrganizer()?.mnemonic?.words == mnemonic.words
&& getOrganizer()?.ownerKeyPair == authState.value.keyPair
) return
val organizer = Organizer.newInstance(
context = context,
mnemonic = mnemonic
Expand All @@ -37,7 +38,7 @@ class SessionManager @Inject constructor(
entropyB64 = entropyB64,
keyPair = organizer.ownerKeyPair,
isAuthenticated = true,
organizer = organizer
organizer = organizer,
)
}
}
Expand Down
22 changes: 22 additions & 0 deletions api/src/main/java/com/getcode/mapper/ChatMessageMapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.getcode.mapper


import com.codeinc.gen.chat.v1.ChatService
import com.getcode.model.ChatMessage
import com.getcode.model.MessageContent
import javax.inject.Inject
import com.codeinc.gen.chat.v1.ChatService.ChatMessage as ApiChatMessage
import com.getcode.model.ChatMessage as DomainChatMessage


class ChatMessageMapper @Inject constructor(
): Mapper<ApiChatMessage, DomainChatMessage> {
override fun map(from: ChatService.ChatMessage): ChatMessage {
return ChatMessage(
id = from.messageId.value.toByteArray().toList(),
cursor = from.cursor.value.toList(),
dateMillis = from.ts.seconds * 1_000L,
contents = from.contentList.mapNotNull { MessageContent(it) },
)
}
}
Loading