Skip to content

Commit f660b3e

Browse files
authored
Merge pull request #1173 from soramitsu/staging
Staging to master
2 parents aff0cb4 + 6627666 commit f660b3e

File tree

17 files changed

+412
-259
lines changed

17 files changed

+412
-259
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ apply plugin: "org.sonarqube"
55
buildscript {
66
ext {
77
// App version
8-
versionName = '3.5.5'
9-
versionCode = 186
8+
versionName = '3.5.6'
9+
versionCode = 188
1010

1111
// SDK and tools
1212
compileSdkVersion = 34

common/src/main/java/jp/co/soramitsu/common/utils/KoltinExt.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ fun BigDecimal.percentageToFraction() = this / PERCENTAGE_MULTIPLIER
1616
val BigDecimal.isNonNegative: Boolean
1717
get() = signum() >= 0
1818

19+
val BigDecimal.isNegative: Boolean
20+
get() = signum() < 0
21+
1922
fun Long.daysFromMillis() = TimeUnit.MILLISECONDS.toDays(this)
2023

2124
inline fun <T> List<T>.sumByBigInteger(extractor: (T) -> BigInteger): BigInteger = fold(BigInteger.ZERO) { acc, element ->

core-db/src/main/java/jp/co/soramitsu/coredb/AppDatabase.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import jp.co.soramitsu.coredb.migrations.Migration_62_63
6969
import jp.co.soramitsu.coredb.migrations.Migration_63_64
7070
import jp.co.soramitsu.coredb.migrations.Migration_64_65
7171
import jp.co.soramitsu.coredb.migrations.Migration_65_66
72+
import jp.co.soramitsu.coredb.migrations.Migration_66_67
7273
import jp.co.soramitsu.coredb.migrations.RemoveAccountForeignKeyFromAsset_17_18
7374
import jp.co.soramitsu.coredb.migrations.RemoveLegacyData_35_36
7475
import jp.co.soramitsu.coredb.migrations.RemoveStakingRewardsTable_22_23
@@ -94,7 +95,7 @@ import jp.co.soramitsu.coredb.model.chain.FavoriteChainLocal
9495
import jp.co.soramitsu.coredb.model.chain.MetaAccountLocal
9596

9697
@Database(
97-
version = 66,
98+
version = 67,
9899
entities = [
99100
AccountLocal::class,
100101
AddressBookContact::class,
@@ -181,6 +182,7 @@ abstract class AppDatabase : RoomDatabase() {
181182
.addMigrations(Migration_63_64)
182183
.addMigrations(Migration_64_65)
183184
.addMigrations(Migration_65_66)
185+
.addMigrations(Migration_66_67)
184186
.build()
185187
}
186188
return instance!!

core-db/src/main/java/jp/co/soramitsu/coredb/dao/AssetDao.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ abstract class AssetDao : AssetReadOnlyCache {
114114
@Insert(onConflict = OnConflictStrategy.REPLACE)
115115
abstract suspend fun insertAsset(asset: AssetLocal)
116116

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

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

129+
@Query("DELETE FROM assets WHERE id in (:assetIdsToDelete)")
130+
abstract fun deleteAssets(assetIdsToDelete: List<String>)
131+
129132
open suspend fun getAssets(accountMetaId: Long, id: String): List<AssetWithToken> {
130133
return observeAssetSymbolById(id).flatMapLatest { symbol ->
131134
observeAssetsBySymbol(

core-db/src/main/java/jp/co/soramitsu/coredb/dao/ChainDao.kt

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.room.Insert
66
import androidx.room.OnConflictStrategy
77
import androidx.room.Query
88
import androidx.room.Transaction
9+
import androidx.room.Update
910
import jp.co.soramitsu.core.utils.removedXcPrefix
1011
import jp.co.soramitsu.coredb.dao.AssetDao.Companion.xcPrefix
1112
import jp.co.soramitsu.coredb.model.AssetWithToken
@@ -35,21 +36,55 @@ abstract class ChainDao {
3536

3637
deleteChains(removed)
3738

38-
deleteChains(newOrUpdated.map(JoinedChainInfo::chain)) // delete all nodes and assets associated with changed chains
39-
4039
insertChains(newOrUpdated.map(JoinedChainInfo::chain))
4140
insertChainNodes(newOrUpdated.flatMap(JoinedChainInfo::nodes))
4241
insertChainNodes(customNodes)
4342
insertChainAssets(newOrUpdated.flatMap(JoinedChainInfo::assets))
4443
insertChainExplorers(newOrUpdated.flatMap(JoinedChainInfo::explorers))
4544
}
4645

47-
@Delete()
46+
@Transaction
47+
open suspend fun updateChains(chainsToAdd: List<ChainLocal>, chainsToUpdate: List<ChainLocal>, chainsToRemove: List<ChainLocal>) {
48+
insertChains(chainsToAdd)
49+
updateChains(chainsToUpdate)
50+
deleteChains(chainsToRemove)
51+
}
52+
53+
@Transaction
54+
open suspend fun updateAssets(assetsToAdd: List<ChainAssetLocal>, assetsToUpdate: List<ChainAssetLocal>, assetsToRemove: List<ChainAssetLocal>) {
55+
insertChainAssets(assetsToAdd)
56+
updateChainAssets(assetsToUpdate)
57+
deleteChainAssets(assetsToRemove)
58+
}
59+
60+
@Transaction
61+
open suspend fun updateNodes(nodesToAdd: List<ChainNodeLocal>, nodesToUpdate: List<ChainNodeLocal>, nodesToRemove: List<ChainNodeLocal>) {
62+
insertChainNodes(nodesToAdd)
63+
updateChainNodes(nodesToUpdate)
64+
deleteChainNodes(nodesToRemove)
65+
}
66+
67+
@Transaction
68+
open suspend fun updateExplorers(
69+
explorersToAdd: MutableList<ChainExplorerLocal>,
70+
explorersToUpdate: MutableList<ChainExplorerLocal>,
71+
explorersToRemove: List<ChainExplorerLocal>
72+
) {
73+
insertChainExplorers(explorersToAdd)
74+
updateChainExplorers(explorersToAdd)
75+
deleteChainExplorers(explorersToAdd)
76+
}
77+
78+
79+
@Delete
4880
protected abstract suspend fun deleteChains(chains: List<ChainLocal>)
4981

50-
@Insert(onConflict = OnConflictStrategy.ABORT)
82+
@Insert(onConflict = OnConflictStrategy.REPLACE)
5183
protected abstract suspend fun insertChains(chains: List<ChainLocal>)
5284

85+
@Update
86+
abstract suspend fun updateChains(chains: List<ChainLocal>)
87+
5388
@Insert(onConflict = OnConflictStrategy.REPLACE)
5489
protected abstract suspend fun insertChainNodes(nodes: List<ChainNodeLocal>)
5590

@@ -88,12 +123,28 @@ abstract class ChainDao {
88123
nodeUrl: String
89124
)
90125

91-
@Insert(onConflict = OnConflictStrategy.ABORT)
126+
@Insert(onConflict = OnConflictStrategy.REPLACE)
92127
protected abstract suspend fun insertChainAssets(assets: List<ChainAssetLocal>)
93128

94-
@Insert(onConflict = OnConflictStrategy.ABORT)
129+
@Update
130+
protected abstract suspend fun updateChainAssets(assets: List<ChainAssetLocal>)
131+
@Delete
132+
protected abstract suspend fun deleteChainAssets(assets: List<ChainAssetLocal>)
133+
134+
@Update
135+
protected abstract suspend fun updateChainNodes(nodes: List<ChainNodeLocal>)
136+
@Delete
137+
protected abstract suspend fun deleteChainNodes(nodes: List<ChainNodeLocal>)
138+
139+
@Insert(onConflict = OnConflictStrategy.REPLACE)
95140
protected abstract suspend fun insertChainExplorers(explorers: List<ChainExplorerLocal>)
96141

142+
@Update
143+
protected abstract suspend fun updateChainExplorers(explorers: List<ChainExplorerLocal>)
144+
145+
@Delete
146+
protected abstract suspend fun deleteChainExplorers(explorers: List<ChainExplorerLocal>)
147+
97148
@Query("SELECT * FROM chains")
98149
@Transaction
99150
abstract suspend fun getJoinChainInfo(): List<JoinedChainInfo>

core-db/src/main/java/jp/co/soramitsu/coredb/migrations/Migrations.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ package jp.co.soramitsu.coredb.migrations
33
import androidx.room.migration.Migration
44
import androidx.sqlite.db.SupportSQLiteDatabase
55

6+
val Migration_66_67 = object : Migration(66, 67) {
7+
override fun migrate(db: SupportSQLiteDatabase) {
8+
db.execSQL("UPDATE meta_accounts SET initialized = 0")
9+
db.execSQL("UPDATE chain_accounts SET initialized = 0")
10+
db.execSQL("DELETE FROM assets")
11+
}
12+
}
13+
614
val Migration_65_66 = object : Migration(65, 66) {
715
override fun migrate(db: SupportSQLiteDatabase) {
816
db.execSQL("ALTER TABLE meta_accounts ADD COLUMN `initialized` INTEGER NOT NULL DEFAULT 0")

core-db/src/main/java/jp/co/soramitsu/coredb/model/chain/ChainLocal.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import androidx.room.Entity
55
import androidx.room.PrimaryKey
66

77
@Entity(tableName = "chains")
8-
class ChainLocal(
8+
data class ChainLocal(
99
@PrimaryKey val id: String,
1010
val paraId: String?,
1111
val parentId: String?,

feature-wallet-api/src/main/java/jp/co/soramitsu/wallet/impl/domain/model/AssetWithStatus.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package jp.co.soramitsu.wallet.impl.domain.model
22

3-
class AssetWithStatus(
3+
data class AssetWithStatus(
44
val asset: Asset,
55
val hasAccount: Boolean,
66
val hasChainAccount: Boolean

feature-wallet-impl/src/main/java/jp/co/soramitsu/wallet/impl/domain/ChainInteractor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ChainInteractor(
2525
it.sortedWith(chainDefaultSort())
2626
}
2727

28-
suspend fun getRawChainAssets(): List<Asset> {
28+
suspend fun getChainAssets(): List<Asset> {
2929
val localAssets = withContext(Dispatchers.IO) { chainDao.getAssetsConfigs() }
3030
val mapped = withContext(Dispatchers.Default) {
3131
localAssets.map {

feature-wallet-impl/src/main/java/jp/co/soramitsu/wallet/impl/domain/WalletInteractorImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ class WalletInteractorImpl(
427427
override suspend fun getChainAddressForSelectedMetaAccount(chainId: ChainId) =
428428
getSelectedMetaAccount().address(getChain(chainId))
429429

430-
override suspend fun updateAssetsHiddenState(state: List<AssetBooleanState>) {
430+
override suspend fun updateAssetsHiddenState(state: List<AssetBooleanState>) = withContext(coroutineContext) {
431431
val wallet = getSelectedMetaAccount()
432432
val updateItems = state.mapNotNull {
433433
val chain = getChain(it.chainId)

0 commit comments

Comments
 (0)