diff --git a/app/src/main/java/jp/co/soramitsu/sora/splash/domain/MigrationManager.kt b/app/src/main/java/jp/co/soramitsu/sora/splash/domain/MigrationManager.kt index 3dfabf52c..fa496df5e 100644 --- a/app/src/main/java/jp/co/soramitsu/sora/splash/domain/MigrationManager.kt +++ b/app/src/main/java/jp/co/soramitsu/sora/splash/domain/MigrationManager.kt @@ -61,7 +61,7 @@ class MigrationManager @Inject constructor( credentialsRepository.saveMnemonic(mnemonic, soraAccount) val soraKeys = credentialsRepository.retrieveKeyPair(emptySoraAccount) credentialsRepository.saveKeyPair(soraKeys, soraAccount) - userRepository.insertSoraAccount(soraAccount) + userRepository.insertSoraAccount(soraAccount, false) userRepository.setCurSoraAccount(soraAccount) FirebaseWrapper.log("Migration ma done") } diff --git a/feature_account_api/src/main/java/jp/co/soramitsu/feature_account_api/domain/interfaces/UserRepository.kt b/feature_account_api/src/main/java/jp/co/soramitsu/feature_account_api/domain/interfaces/UserRepository.kt index 4a11319e4..2425eef1f 100644 --- a/feature_account_api/src/main/java/jp/co/soramitsu/feature_account_api/domain/interfaces/UserRepository.kt +++ b/feature_account_api/src/main/java/jp/co/soramitsu/feature_account_api/domain/interfaces/UserRepository.kt @@ -51,7 +51,7 @@ interface UserRepository { suspend fun soraAccountsList(): List - suspend fun insertSoraAccount(soraAccount: SoraAccount) + suspend fun insertSoraAccount(soraAccount: SoraAccount, newAccount: Boolean) suspend fun updateAccountName(soraAccount: SoraAccount, newName: String) diff --git a/feature_account_impl/src/main/java/jp/co/soramitsu/feature_account_impl/data/repository/UserRepositoryImpl.kt b/feature_account_impl/src/main/java/jp/co/soramitsu/feature_account_impl/data/repository/UserRepositoryImpl.kt index 4af90dc4f..5d8171a56 100644 --- a/feature_account_impl/src/main/java/jp/co/soramitsu/feature_account_impl/data/repository/UserRepositoryImpl.kt +++ b/feature_account_impl/src/main/java/jp/co/soramitsu/feature_account_impl/data/repository/UserRepositoryImpl.kt @@ -130,19 +130,19 @@ class UserRepositoryImpl( return db.accountDao().getAccountsCount() } - override suspend fun insertSoraAccount(soraAccount: SoraAccount) { + override suspend fun insertSoraAccount(soraAccount: SoraAccount, newAccount: Boolean) { db.withTransaction { db.accountDao().insertSoraAccount( SoraAccountMapper.map(soraAccount) ) db.cardsHubDao().insert( - CardHubType.values() + CardHubType.entries .filter { it.boundToAccount } .mapIndexed { _, type -> CardHubLocal( cardId = type.hubName, accountAddress = soraAccount.substrateAddress, - visibility = true, + visibility = if (type == CardHubType.BACKUP) newAccount else true, sortOrder = type.order, collapsed = false, ) diff --git a/feature_account_impl/src/test/java/jp/co/soramitsu/feature_account_impl/data/repository/TestData.kt b/feature_account_impl/src/test/java/jp/co/soramitsu/feature_account_impl/data/repository/TestData.kt index 9a1a09b8e..cf033feb2 100644 --- a/feature_account_impl/src/test/java/jp/co/soramitsu/feature_account_impl/data/repository/TestData.kt +++ b/feature_account_impl/src/test/java/jp/co/soramitsu/feature_account_impl/data/repository/TestData.kt @@ -39,6 +39,13 @@ import jp.co.soramitsu.core_db.model.GlobalCardHubLocal object TestData { val CARD_HUB_LOCAL = listOf( + CardHubLocal( + cardId = CardHubType.BACKUP.hubName, + accountAddress = "accountAddress", + visibility = true, + sortOrder = CardHubType.BACKUP.order, + collapsed = false + ), CardHubLocal( cardId = CardHubType.ASSETS.hubName, accountAddress = "accountAddress", diff --git a/feature_account_impl/src/test/java/jp/co/soramitsu/feature_account_impl/data/repository/UserRepositoryTest.kt b/feature_account_impl/src/test/java/jp/co/soramitsu/feature_account_impl/data/repository/UserRepositoryTest.kt index a11d0d628..37863ff39 100644 --- a/feature_account_impl/src/test/java/jp/co/soramitsu/feature_account_impl/data/repository/UserRepositoryTest.kt +++ b/feature_account_impl/src/test/java/jp/co/soramitsu/feature_account_impl/data/repository/UserRepositoryTest.kt @@ -245,7 +245,7 @@ class UserRepositoryTest { coEvery { hubDao.insert(any()) } returns Unit val soraAccount = SoraAccount("accountAddress", "accountName") - userRepository.insertSoraAccount(soraAccount) + userRepository.insertSoraAccount(soraAccount, true) coVerify { accountDao.insertSoraAccount( @@ -271,14 +271,14 @@ class UserRepositoryTest { coEvery { hubDao.insert(TestData.CARD_HUB_LOCAL) } returns Unit mockkStatic("androidx.room.RoomDatabaseKt") mockkStatic(CardHubType::class) - every { CardHubType.values() } returns arrayOf(CardHubType.GET_SORA_CARD, CardHubType.ASSETS, CardHubType.POOLS) + //every { CardHubType.entries } returns arrayOf(CardHubType.GET_SORA_CARD, CardHubType.ASSETS, CardHubType.POOLS) val lambda = slot R>() coEvery { db.withTransaction(capture(lambda)) } coAnswers { lambda.captured.invoke() } val soraAccount = SoraAccount("accountAddress", "accountName") - userRepository.insertSoraAccount(soraAccount) + userRepository.insertSoraAccount(soraAccount, true) coVerify { hubDao.insert(TestData.CARD_HUB_LOCAL) } } diff --git a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/domain/MultiaccountInteractor.kt b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/domain/MultiaccountInteractor.kt index 8c3abb243..d06d145f0 100644 --- a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/domain/MultiaccountInteractor.kt +++ b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/domain/MultiaccountInteractor.kt @@ -68,7 +68,7 @@ class MultiaccountInteractor @Inject constructor( suspend fun accountExists(address: String) = userRepository.accountExists(address) suspend fun continueRecoverFlow(soraAccount: SoraAccount) { - insertAndSetCurAccount(soraAccount) + insertAndSetCurAccount(soraAccount, false) userRepository.saveRegistrationState(OnboardingState.REGISTRATION_FINISHED) } @@ -89,8 +89,8 @@ class MultiaccountInteractor @Inject constructor( return credentialsRepository.retrieveMnemonic(soraAccount ?: userRepository.getCurSoraAccount()) } - private suspend fun insertAndSetCurAccount(soraAccount: SoraAccount) { - userRepository.insertSoraAccount(soraAccount) + private suspend fun insertAndSetCurAccount(soraAccount: SoraAccount, newAccount: Boolean) { + userRepository.insertSoraAccount(soraAccount, newAccount) userRepository.setCurSoraAccount(soraAccount) } @@ -107,7 +107,7 @@ class MultiaccountInteractor @Inject constructor( } suspend fun createUser(soraAccount: SoraAccount) { - insertAndSetCurAccount(soraAccount) + insertAndSetCurAccount(soraAccount, true) userRepository.saveRegistrationState(OnboardingState.INITIAL) userRepository.saveNeedsMigration(false, soraAccount) userRepository.saveIsMigrationFetched(true, soraAccount) diff --git a/feature_multiaccount_impl/src/test/java/jp/co/soramitsu/feature_multiaccount_impl/domain/MultiaccountInteractorTest.kt b/feature_multiaccount_impl/src/test/java/jp/co/soramitsu/feature_multiaccount_impl/domain/MultiaccountInteractorTest.kt index c1d439a02..29531bf6e 100644 --- a/feature_multiaccount_impl/src/test/java/jp/co/soramitsu/feature_multiaccount_impl/domain/MultiaccountInteractorTest.kt +++ b/feature_multiaccount_impl/src/test/java/jp/co/soramitsu/feature_multiaccount_impl/domain/MultiaccountInteractorTest.kt @@ -93,7 +93,7 @@ class MultiaccountInteractorTest { fun setup() { coEvery { credentialsRepository.isMnemonicValid(any()) } returns true coEvery { credentialsRepository.isRawSeedValid(any()) } returns true - coEvery { userRepository.insertSoraAccount(any()) } returns Unit + coEvery { userRepository.insertSoraAccount(any(), any()) } returns Unit coEvery { userRepository.setCurSoraAccount(any()) } returns Unit coEvery { userRepository.saveRegistrationState(any()) } returns Unit coEvery { credentialsRepository.restoreUserCredentialsFromMnemonic(any(), any()) } returns account @@ -128,7 +128,7 @@ class MultiaccountInteractorTest { @Test fun `continueRecoverFlow is called`() = runTest { multiaccountInteractor.continueRecoverFlow(account) - coVerify { userRepository.insertSoraAccount(account) } + coVerify { userRepository.insertSoraAccount(account, false) } coVerify { userRepository.setCurSoraAccount(account) } coVerify { userRepository.saveRegistrationState(OnboardingState.REGISTRATION_FINISHED) } } @@ -152,7 +152,7 @@ class MultiaccountInteractorTest { @Test fun `createUser is called`() = runTest { multiaccountInteractor.createUser(account) - coVerify { userRepository.insertSoraAccount(account) } + coVerify { userRepository.insertSoraAccount(account, true) } coVerify { userRepository.setCurSoraAccount(account) } coVerify { userRepository.saveRegistrationState(OnboardingState.INITIAL) } coVerify { userRepository.saveNeedsMigration(false, account) }