Skip to content

Commit

Permalink
Merge pull request #1173 from soramitsu/staging
Browse files Browse the repository at this point in the history
Staging to master
  • Loading branch information
Deneath authored Jul 2, 2024
2 parents aff0cb4 + 6627666 commit f660b3e
Show file tree
Hide file tree
Showing 17 changed files with 412 additions and 259 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ apply plugin: "org.sonarqube"
buildscript {
ext {
// App version
versionName = '3.5.5'
versionCode = 186
versionName = '3.5.6'
versionCode = 188

// SDK and tools
compileSdkVersion = 34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ fun BigDecimal.percentageToFraction() = this / PERCENTAGE_MULTIPLIER
val BigDecimal.isNonNegative: Boolean
get() = signum() >= 0

val BigDecimal.isNegative: Boolean
get() = signum() < 0

fun Long.daysFromMillis() = TimeUnit.MILLISECONDS.toDays(this)

inline fun <T> List<T>.sumByBigInteger(extractor: (T) -> BigInteger): BigInteger = fold(BigInteger.ZERO) { acc, element ->
Expand Down
4 changes: 3 additions & 1 deletion core-db/src/main/java/jp/co/soramitsu/coredb/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import jp.co.soramitsu.coredb.migrations.Migration_62_63
import jp.co.soramitsu.coredb.migrations.Migration_63_64
import jp.co.soramitsu.coredb.migrations.Migration_64_65
import jp.co.soramitsu.coredb.migrations.Migration_65_66
import jp.co.soramitsu.coredb.migrations.Migration_66_67
import jp.co.soramitsu.coredb.migrations.RemoveAccountForeignKeyFromAsset_17_18
import jp.co.soramitsu.coredb.migrations.RemoveLegacyData_35_36
import jp.co.soramitsu.coredb.migrations.RemoveStakingRewardsTable_22_23
Expand All @@ -94,7 +95,7 @@ import jp.co.soramitsu.coredb.model.chain.FavoriteChainLocal
import jp.co.soramitsu.coredb.model.chain.MetaAccountLocal

@Database(
version = 66,
version = 67,
entities = [
AccountLocal::class,
AddressBookContact::class,
Expand Down Expand Up @@ -181,6 +182,7 @@ abstract class AppDatabase : RoomDatabase() {
.addMigrations(Migration_63_64)
.addMigrations(Migration_64_65)
.addMigrations(Migration_65_66)
.addMigrations(Migration_66_67)
.build()
}
return instance!!
Expand Down
5 changes: 4 additions & 1 deletion core-db/src/main/java/jp/co/soramitsu/coredb/dao/AssetDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ abstract class AssetDao : AssetReadOnlyCache {
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract suspend fun insertAsset(asset: AssetLocal)

@Insert(onConflict = OnConflictStrategy.REPLACE)
@Insert(onConflict = OnConflictStrategy.IGNORE)
abstract suspend fun insertAssets(assets: List<AssetLocal>)

@Update(entity = AssetLocal::class)
Expand All @@ -126,6 +126,9 @@ abstract class AssetDao : AssetReadOnlyCache {
@Query("DELETE FROM assets WHERE metaId = :metaId AND accountId = :accountId AND chainId = :chainId AND id = :assetId")
abstract fun deleteAsset(metaId: Long, accountId: AccountId, chainId: String, assetId: String)

@Query("DELETE FROM assets WHERE id in (:assetIdsToDelete)")
abstract fun deleteAssets(assetIdsToDelete: List<String>)

open suspend fun getAssets(accountMetaId: Long, id: String): List<AssetWithToken> {
return observeAssetSymbolById(id).flatMapLatest { symbol ->
observeAssetsBySymbol(
Expand Down
63 changes: 57 additions & 6 deletions core-db/src/main/java/jp/co/soramitsu/coredb/dao/ChainDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import jp.co.soramitsu.core.utils.removedXcPrefix
import jp.co.soramitsu.coredb.dao.AssetDao.Companion.xcPrefix
import jp.co.soramitsu.coredb.model.AssetWithToken
Expand Down Expand Up @@ -35,21 +36,55 @@ abstract class ChainDao {

deleteChains(removed)

deleteChains(newOrUpdated.map(JoinedChainInfo::chain)) // delete all nodes and assets associated with changed chains

insertChains(newOrUpdated.map(JoinedChainInfo::chain))
insertChainNodes(newOrUpdated.flatMap(JoinedChainInfo::nodes))
insertChainNodes(customNodes)
insertChainAssets(newOrUpdated.flatMap(JoinedChainInfo::assets))
insertChainExplorers(newOrUpdated.flatMap(JoinedChainInfo::explorers))
}

@Delete()
@Transaction
open suspend fun updateChains(chainsToAdd: List<ChainLocal>, chainsToUpdate: List<ChainLocal>, chainsToRemove: List<ChainLocal>) {
insertChains(chainsToAdd)
updateChains(chainsToUpdate)
deleteChains(chainsToRemove)
}

@Transaction
open suspend fun updateAssets(assetsToAdd: List<ChainAssetLocal>, assetsToUpdate: List<ChainAssetLocal>, assetsToRemove: List<ChainAssetLocal>) {
insertChainAssets(assetsToAdd)
updateChainAssets(assetsToUpdate)
deleteChainAssets(assetsToRemove)
}

@Transaction
open suspend fun updateNodes(nodesToAdd: List<ChainNodeLocal>, nodesToUpdate: List<ChainNodeLocal>, nodesToRemove: List<ChainNodeLocal>) {
insertChainNodes(nodesToAdd)
updateChainNodes(nodesToUpdate)
deleteChainNodes(nodesToRemove)
}

@Transaction
open suspend fun updateExplorers(
explorersToAdd: MutableList<ChainExplorerLocal>,
explorersToUpdate: MutableList<ChainExplorerLocal>,
explorersToRemove: List<ChainExplorerLocal>
) {
insertChainExplorers(explorersToAdd)
updateChainExplorers(explorersToAdd)
deleteChainExplorers(explorersToAdd)
}


@Delete
protected abstract suspend fun deleteChains(chains: List<ChainLocal>)

@Insert(onConflict = OnConflictStrategy.ABORT)
@Insert(onConflict = OnConflictStrategy.REPLACE)
protected abstract suspend fun insertChains(chains: List<ChainLocal>)

@Update
abstract suspend fun updateChains(chains: List<ChainLocal>)

@Insert(onConflict = OnConflictStrategy.REPLACE)
protected abstract suspend fun insertChainNodes(nodes: List<ChainNodeLocal>)

Expand Down Expand Up @@ -88,12 +123,28 @@ abstract class ChainDao {
nodeUrl: String
)

@Insert(onConflict = OnConflictStrategy.ABORT)
@Insert(onConflict = OnConflictStrategy.REPLACE)
protected abstract suspend fun insertChainAssets(assets: List<ChainAssetLocal>)

@Insert(onConflict = OnConflictStrategy.ABORT)
@Update
protected abstract suspend fun updateChainAssets(assets: List<ChainAssetLocal>)
@Delete
protected abstract suspend fun deleteChainAssets(assets: List<ChainAssetLocal>)

@Update
protected abstract suspend fun updateChainNodes(nodes: List<ChainNodeLocal>)
@Delete
protected abstract suspend fun deleteChainNodes(nodes: List<ChainNodeLocal>)

@Insert(onConflict = OnConflictStrategy.REPLACE)
protected abstract suspend fun insertChainExplorers(explorers: List<ChainExplorerLocal>)

@Update
protected abstract suspend fun updateChainExplorers(explorers: List<ChainExplorerLocal>)

@Delete
protected abstract suspend fun deleteChainExplorers(explorers: List<ChainExplorerLocal>)

@Query("SELECT * FROM chains")
@Transaction
abstract suspend fun getJoinChainInfo(): List<JoinedChainInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ package jp.co.soramitsu.coredb.migrations
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

val Migration_66_67 = object : Migration(66, 67) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("UPDATE meta_accounts SET initialized = 0")
db.execSQL("UPDATE chain_accounts SET initialized = 0")
db.execSQL("DELETE FROM assets")
}
}

val Migration_65_66 = object : Migration(65, 66) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE meta_accounts ADD COLUMN `initialized` INTEGER NOT NULL DEFAULT 0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "chains")
class ChainLocal(
data class ChainLocal(
@PrimaryKey val id: String,
val paraId: String?,
val parentId: String?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package jp.co.soramitsu.wallet.impl.domain.model

class AssetWithStatus(
data class AssetWithStatus(
val asset: Asset,
val hasAccount: Boolean,
val hasChainAccount: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ChainInteractor(
it.sortedWith(chainDefaultSort())
}

suspend fun getRawChainAssets(): List<Asset> {
suspend fun getChainAssets(): List<Asset> {
val localAssets = withContext(Dispatchers.IO) { chainDao.getAssetsConfigs() }
val mapped = withContext(Dispatchers.Default) {
localAssets.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class WalletInteractorImpl(
override suspend fun getChainAddressForSelectedMetaAccount(chainId: ChainId) =
getSelectedMetaAccount().address(getChain(chainId))

override suspend fun updateAssetsHiddenState(state: List<AssetBooleanState>) {
override suspend fun updateAssetsHiddenState(state: List<AssetBooleanState>) = withContext(coroutineContext) {
val wallet = getSelectedMetaAccount()
val updateItems = state.mapNotNull {
val chain = getChain(it.chainId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,28 @@ object AssetListHelper {
val chainsWithIssuesIds = symbolAssets.filter { it.hasAccount.not() }.map { it.asset.token.configuration.chainId }
.plus(networkIssues.map { it.chainId })

val tokenChains = filteredChains.getWithToken(symbol).filter { chain ->
chain.id !in chainsWithIssuesIds
}
val tokenChains = filteredChains.asSequence()
.filter { chain ->
symbolAssets.any { it.asset.token.configuration.chainId == chain.id }
}
.filter { chain ->
chain.assets.any { it.symbol == symbol }
}.filter { chain ->
chain.id !in chainsWithIssuesIds
}.toList()


if (tokenChains.isEmpty()) return@forEach

val mainChain = tokenChains.sortedWith(
compareByDescending<Chain> {
it.assets.firstOrNull { it.symbol == symbol }?.isUtility ?: false
compareByDescending<Chain> { chain ->
chain.assets.firstOrNull { it.symbol == symbol }?.isUtility ?: false
}.thenByDescending { it.parentId == null }
).firstOrNull()

val showChain = tokenChains.firstOrNull { it.id == selectedChainId } ?: mainChain
val showChainAsset =
showChain?.assets?.firstOrNull { it.symbol == symbol } ?: return@forEach

val assetIdsWithBalance = symbolAssets.filter {
it.asset.total.orZero() > BigDecimal.ZERO
}.groupBy(
Expand Down
Loading

0 comments on commit f660b3e

Please sign in to comment.