Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
SeniorZhai committed Mar 10, 2025
1 parent 8aa281e commit d2f4e4f
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 18 deletions.
36 changes: 34 additions & 2 deletions app/schemas/one.mixin.android.db.WalletDatabase/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "51cf7da879edf0166cf06a9a69309897",
"identityHash": "69d4923113a46f7447c751579c04b26b",
"entities": [
{
"tableName": "tokens",
Expand Down Expand Up @@ -353,12 +353,44 @@
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "properties",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `value` TEXT NOT NULL, `updated_at` TEXT NOT NULL, PRIMARY KEY(`key`))",
"fields": [
{
"fieldPath": "key",
"columnName": "key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "value",
"columnName": "value",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "updatedAt",
"columnName": "updated_at",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"key"
]
},
"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, '51cf7da879edf0166cf06a9a69309897')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '69d4923113a46f7447c751579c04b26b')"
]
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/one/mixin/android/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ object Constants {

const val FTS_DB_NAME = "fts.db"
const val PENDING_DB_NAME = "pending.db"
const val WEB3_DB_NAME = "web3.db"
const val WALLET_DB_NAME = "wallet.db"
}

object Storage {
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/one/mixin/android/db/WalletDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import one.mixin.android.db.web3.vo.Web3Token
import one.mixin.android.db.web3.vo.Web3TokensExtra
import one.mixin.android.db.web3.vo.Web3Transaction
import one.mixin.android.util.database.dbDir
import one.mixin.android.vo.Chain
import one.mixin.android.vo.Property
import java.io.File

@Database(
Expand All @@ -32,6 +32,7 @@ import java.io.File
Web3Address::class,
Web3TokensExtra::class,
Web3Chain::class,
Property::class
],
version = 1,
)
Expand All @@ -52,7 +53,7 @@ abstract class WalletDatabase : RoomDatabase() {
Room.databaseBuilder(
context,
WalletDatabase::class.java,
File(dir, Constants.DataBase.WEB3_DB_NAME).absolutePath,
File(dir, Constants.DataBase.WALLET_DB_NAME).absolutePath,
).addCallback(
object : Callback() {
override fun onOpen(db: SupportSQLiteDatabase) {
Expand All @@ -75,6 +76,7 @@ abstract class WalletDatabase : RoomDatabase() {
abstract fun web3AddressDao(): Web3AddressDao
abstract fun web3TokensExtraDao(): Web3TokensExtraDao
abstract fun web3ChainDao(): Web3ChainDao
abstract fun web3PropertyDao(): Web3PropertyDao

override fun close() {
super.close()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package one.mixin.android.db.property

import one.mixin.android.MixinApplication
import one.mixin.android.db.WalletDatabase
import one.mixin.android.extension.nowInUtc
import one.mixin.android.vo.Property

object Web3PropertyHelper {

suspend fun updateKeyValue(
key: String,
value: String,
) {
val propertyDao = WalletDatabase.getDatabase(MixinApplication.appContext).web3PropertyDao()
propertyDao.insertSuspend(Property(key, value, nowInUtc()))
}

suspend fun updateKeyValue(
key: String,
value: Long,
) {
updateKeyValue(key, value.toString())
}

suspend fun updateKeyValue(
key: String,
value: Int,
) {
updateKeyValue(key, value.toString())
}

suspend fun updateKeyValue(
key: String,
value: Boolean,
) {
updateKeyValue(key, value.toString())
}

suspend fun deleteKeyValue(key: String) {
val propertyDao = WalletDatabase.getDatabase(MixinApplication.appContext).web3PropertyDao()
propertyDao.deletePropertyByKey(key)
}

suspend fun <T> findValueByKey(
key: String,
default: T,
): T {
val propertyDao = WalletDatabase.getDatabase(MixinApplication.appContext).web3PropertyDao()
val value = propertyDao.findValueByKey(key) ?: return default
return try {
when (default) {
is Int -> {
value.toIntOrNull() ?: default
}
is Long -> {
value.toIntOrNull() ?: default
}
is Boolean -> {
value.toBooleanStrictOrNull() ?: default
}
else -> {
value
}
} as T
} catch (e: Exception) {
default
}
}

}
25 changes: 25 additions & 0 deletions app/src/main/java/one/mixin/android/db/web3/Web3PropertyDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package one.mixin.android.db

import androidx.room.Dao
import androidx.room.Query
import one.mixin.android.extension.nowInUtc
import one.mixin.android.vo.Property

@Dao
interface Web3PropertyDao : BaseDao<Property> {
@Query("SELECT * FROM properties WHERE `key` = :key")
suspend fun findByKey(key: String): Property?

@Query("SELECT value FROM properties WHERE `key` = :key")
suspend fun findValueByKey(key: String): String?

@Query("UPDATE properties SET value = :value, updated_at = :updatedAt WHERE `key` = :key")
suspend fun updateValueByKey(
key: String,
value: String,
updatedAt: String = nowInUtc(),
)

@Query("DELETE FROM properties WHERE `key` = :key")
suspend fun deletePropertyByKey(key: String)
}
3 changes: 3 additions & 0 deletions app/src/main/java/one/mixin/android/di/BaseDbModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,7 @@ internal object BaseDbModule {
@Provides
fun provideWeb3ChainDao(db: WalletDatabase) = db.web3ChainDao()

@Singleton
fun provideWeb3PropertyDao(db: WalletDatabase) = db.web3PropertyDao()

}
1 change: 0 additions & 1 deletion app/src/main/java/one/mixin/android/job/BaseJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import one.mixin.android.api.LocalJobException
import one.mixin.android.api.NetworkException
import one.mixin.android.api.ServerErrorException
import one.mixin.android.api.WebSocketException
import one.mixin.android.db.web3.vo.Web3Address
import one.mixin.android.api.service.AccountService
import one.mixin.android.api.service.AddressService
import one.mixin.android.api.service.AssetService
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/one/mixin/android/job/RefreshFcmJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ package one.mixin.android.job

import android.annotation.SuppressLint
import com.birbit.android.jobqueue.Params
import com.google.android.gms.tasks.Tasks
import com.google.firebase.messaging.FirebaseMessaging
import kotlinx.coroutines.runBlocking
import okhttp3.internal.wait
import one.mixin.android.api.request.SessionRequest
import timber.log.Timber

class RefreshFcmJob(
private val notificationToken: String? = null,
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/one/mixin/android/job/RefreshWeb3Job.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import one.mixin.android.Constants
import one.mixin.android.Constants.Account.ChainAddress.EVM_ADDRESS
import one.mixin.android.Constants.Account.ChainAddress.SOLANA_ADDRESS
import one.mixin.android.Constants.RouteConfig.ROUTE_BOT_USER_ID
import one.mixin.android.api.request.web3.Web3AddressRequest
import one.mixin.android.api.request.web3.WalletRequest
import one.mixin.android.db.web3.vo.Web3Wallet
import one.mixin.android.api.request.web3.Web3AddressRequest
import one.mixin.android.db.property.PropertyHelper
import one.mixin.android.db.web3.vo.Web3Chain
import one.mixin.android.db.web3.vo.Web3Wallet
import one.mixin.android.ui.wallet.fiatmoney.requestRouteAPI
import timber.log.Timber

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package one.mixin.android.job
import com.birbit.android.jobqueue.Params
import kotlinx.coroutines.runBlocking
import one.mixin.android.Constants.RouteConfig.ROUTE_BOT_USER_ID
import one.mixin.android.db.property.PropertyHelper
import one.mixin.android.db.web3.vo.Web3Address
import one.mixin.android.db.property.Web3PropertyHelper
import one.mixin.android.db.web3.vo.Web3Transaction
import one.mixin.android.ui.wallet.fiatmoney.requestRouteAPI
import timber.log.Timber
Expand Down Expand Up @@ -76,10 +75,10 @@ class RefreshWeb3TransactionJob(
}

private suspend fun saveLastCreatedAt(addressId: String, timestamp: String) {
PropertyHelper.updateKeyValue(addressId, timestamp)
Web3PropertyHelper.updateKeyValue(addressId, timestamp)
}

private suspend fun getLastCreatedAt(addressId: String): String? {
return PropertyHelper.findValueByKey(addressId, null)
return Web3PropertyHelper.findValueByKey(addressId, null)
}
}

0 comments on commit d2f4e4f

Please sign in to comment.