Skip to content

Commit

Permalink
Merge pull request #1197 from soramitsu/staging
Browse files Browse the repository at this point in the history
staging to master
  • Loading branch information
PankraSerg authored Aug 29, 2024
2 parents 0776bd2 + 2fa9700 commit cd73384
Show file tree
Hide file tree
Showing 49 changed files with 362 additions and 197 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ dependencies {
kapt libs.lifecycle.compiler

implementation libs.lifecycle.runtime.ktx
implementation libs.lifecycle.livedata.ktx

implementation libs.converter.gson

Expand All @@ -212,8 +213,6 @@ dependencies {

implementation libs.insetter.widgets

implementation libs.lifecycle.livedata.ktx

implementation libs.jna
implementation libs.beacon.android.sdk, withoutJna

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ class Navigator :
}

override fun <T> observeResult(key: String): Flow<T> {
@Suppress("UNCHECKED_CAST")
return observeResultInternal<T>(key)
.onStart { removeSavedStateHandle(key) }
.onCompletion { removeSavedStateHandle(key) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.co.soramitsu.app.root.presentation.stories

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.MotionEvent
import android.view.View
Expand Down Expand Up @@ -36,6 +37,7 @@ class StoryFragment : BaseFragment<StoryViewModel>(R.layout.fragment_story), Sto

private var lastActionDown = 0L

@SuppressLint("ClickableViewAccessibility")
override fun initViews() {
binding.storyCloseIcon.setOnClickListener { viewModel.backClicked() }

Expand Down
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.7.1'
versionCode = 200
versionName = '3.7.2'
versionCode = 201

// SDK and tools
compileSdkVersion = 34
Expand Down
6 changes: 3 additions & 3 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ dependencies {
implementation libs.coroutines.core
implementation libs.lifecycle.livedata.ktx
implementation libs.lifecycle.runtime.ktx

implementation libs.lifecycle.viewmodel.ktx
implementation libs.lifecycle.process
kapt libs.lifecycle.compiler

implementation libs.hilt.android
implementation libs.navigation.fragment.ktx
kapt libs.hilt.compiler

implementation libs.lifecycle.process
kapt libs.lifecycle.compiler
implementation libs.play.services.base

implementation libs.converter.gson
implementation libs.converter.scalars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import com.google.android.gms.common.GoogleApiAvailability
import jp.co.soramitsu.common.R

fun Context.getDrawableCompat(@DrawableRes drawableRes: Int) =
Expand Down Expand Up @@ -50,3 +51,8 @@ fun Context.getColorFromAttr(

@ColorInt
fun Context.getPrimaryColor() = getColorFromAttr(R.attr.colorPrimary)

fun Context.isGooglePlayServicesAvailable(): Boolean {
return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) ==
com.google.android.gms.common.ConnectionResult.SUCCESS
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fun decimalFormatterFor(pattern: String) = DecimalFormat(pattern).apply {

fun fiatAbbreviatedFormatter() = CompoundNumberFormatter(
abbreviations = listOf(
NumberAbbreviation(BigDecimal.ZERO, BigDecimal.ONE, "", fiatSmallAmountFormatter),
NumberAbbreviation(BigDecimal.ZERO, BigDecimal.ONE, "", fiatAmountFormatter),
NumberAbbreviation(BigDecimal.ONE, BigDecimal.ONE, "", fiatAmountFormatter),
NumberAbbreviation(BigDecimal("1E+3"), BigDecimal.ONE, "", fiatAmountFormatter),
NumberAbbreviation(BigDecimal("1E+6"), BigDecimal("1E+6"), "M", fiatAmountFormatter),
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 @@ -74,6 +74,7 @@ import jp.co.soramitsu.coredb.migrations.Migration_65_66
import jp.co.soramitsu.coredb.migrations.Migration_66_67
import jp.co.soramitsu.coredb.migrations.Migration_67_68
import jp.co.soramitsu.coredb.migrations.Migration_68_69
import jp.co.soramitsu.coredb.migrations.Migration_69_70
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 Down Expand Up @@ -102,7 +103,7 @@ import jp.co.soramitsu.coredb.model.chain.FavoriteChainLocal
import jp.co.soramitsu.coredb.model.chain.MetaAccountLocal

@Database(
version = 69,
version = 70,
entities = [
AccountLocal::class,
AddressBookContact::class,
Expand Down Expand Up @@ -195,6 +196,7 @@ abstract class AppDatabase : RoomDatabase() {
.addMigrations(Migration_66_67)
.addMigrations(Migration_67_68)
.addMigrations(Migration_68_69)
.addMigrations(Migration_69_70)
.build()
}
return instance!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package jp.co.soramitsu.coredb.migrations
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

val Migration_69_70 = object : Migration(69, 70) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("DELETE FROM storage")
}
}

val Migration_68_69 = object : Migration(68, 69) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fun mapMetaAccountLocalToMetaAccount(
valueTransform = {
MetaAccount.ChainAccount(
metaId = joinedMetaAccountInfo.metaAccount.id,
chain = chainsById[it.chainId],
chain = chainsById.getOrDefault(it.chainId, null),
publicKey = it.publicKey,
accountId = it.accountId,
cryptoType = it.cryptoType,
Expand All @@ -101,7 +101,7 @@ fun mapMetaAccountLocalToMetaAccount(
keySelector = FavoriteChainLocal::chainId,
valueTransform = {
MetaAccount.FavoriteChain(
chain = chainsById[it.chainId],
chain = chainsById.getOrDefault(it.chainId, null),
isFavorite = it.isFavorite
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import jp.co.soramitsu.coredb.model.chain.ChainAccountLocal
import jp.co.soramitsu.coredb.model.chain.MetaAccountPositionUpdate
import jp.co.soramitsu.runtime.multiNetwork.chain.ChainsRepository
import jp.co.soramitsu.shared_utils.runtime.AccountId
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -80,6 +81,7 @@ class AccountDataSourceImpl(
/**
* Fast lookup table for accessing account based on accountId
*/
@OptIn(DelicateCoroutinesApi::class)
override val selectedAccountMapping = selectedMetaAccountFlow.map { metaAccount ->
val mapping =
metaAccount.chainAccounts.mapValuesTo(mutableMapOf<String, Account?>()) { (_, chainAccount) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class AssetBalanceUseCaseImpl(
val chainsById = chainsRepository.getChainsById()

return assets.fold(AssetBalance.Empty) { acc, current ->
val chainAsset = chainsById.getValue(current.asset.chainId).assets
.firstOrNull { it.id == current.asset.id }
val chainAsset = chainsById.getOrDefault(current.asset.chainId, null)?.assets
?.firstOrNull { it.id == current.asset.id }
?: return@fold AssetBalance.Empty

val currentAssetTransferable = current.asset.transferableInPlanks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import jp.co.soramitsu.coredb.model.AssetWithToken
import jp.co.soramitsu.runtime.multiNetwork.chain.ChainsRepository
import jp.co.soramitsu.runtime.multiNetwork.chain.model.polkadotChainId
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flatMapLatest
Expand All @@ -43,6 +44,7 @@ class TotalBalanceUseCaseImpl(
}
}

@OptIn(ExperimentalCoroutinesApi::class)
override fun observe(metaId: Long?): Flow<TotalBalance> {
return when (metaId) {
null -> accountRepository.selectedLightMetaAccountFlow()
Expand Down Expand Up @@ -71,8 +73,8 @@ class TotalBalanceUseCaseImpl(
runCatching { fiatSymbolsInAssets.maxBy { s -> filtered.count { it.token?.fiatSymbol == s } } }.getOrNull() ?: polkadotCurrency

return filtered.fold(TotalBalance.Empty) { acc, current ->
val chainAsset = chainsById.getValue(current.asset.chainId).assets
.firstOrNull { it.id == current.asset.id }
val chainAsset = chainsById.getOrDefault(current.asset.chainId, null)?.assets
?.firstOrNull { it.id == current.asset.id }
?: return@fold TotalBalance.Empty

val total =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,11 @@ class WalletSyncService(
}
}
}

launch { metaAccountDao.markAccountsInitialized(metaAccounts.map { it.id }) }
this
}.coroutineContext.job.join()

coroutineScope {
metaAccountDao.markAccountsInitialized(metaAccounts.map { it.id })
hideEmptyAssetsIfThereAreAtLeastOnePositiveBalanceByMetaAccounts(
metaAccounts
)
}
hideEmptyAssetsIfThereAreAtLeastOnePositiveBalanceByMetaAccounts(metaAccounts)
}
}
.launchIn(scope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface BackupWalletCallback {
@Composable
internal fun BackupWalletContent(
state: BackupWalletState,
isGoogleAvailable: Boolean,
callback: BackupWalletCallback
) {

Expand Down Expand Up @@ -115,7 +116,7 @@ internal fun BackupWalletContent(
)
SettingsDivider()
}
if (state.isAuthedToGoogle) {
if (isGoogleAvailable && state.isAuthedToGoogle) {
if (state.isWalletSavedInGoogle) {
SettingsItem(
icon = painterResource(R.drawable.ic_google_24),
Expand Down Expand Up @@ -160,6 +161,7 @@ private fun PreviewBackupWalletContent() {
FearlessAppTheme {
BackupWalletContent(
state = BackupWalletState.Empty,
isGoogleAvailable = true,
callback = object : BackupWalletCallback {
override fun onBackClick() {}
override fun onShowMnemonicPhraseClick() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import dagger.hilt.android.AndroidEntryPoint
import jp.co.soramitsu.common.base.BaseComposeBottomSheetDialogFragment
import jp.co.soramitsu.common.compose.component.BottomSheetScreen
import jp.co.soramitsu.common.utils.isGooglePlayServicesAvailable
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

Expand All @@ -34,6 +35,11 @@ class BackupWalletDialog : BaseComposeBottomSheetDialogFragment<BackupWalletView
}
}

private val isGoogleAvailable: Boolean
get() {
return context?.isGooglePlayServicesAvailable() == true
}

override val viewModel: BackupWalletViewModel by viewModels()

private val launcher: ActivityResultLauncher<Intent> = registerForActivityResult(
Expand All @@ -55,6 +61,7 @@ class BackupWalletDialog : BaseComposeBottomSheetDialogFragment<BackupWalletView
BottomSheetScreen {
BackupWalletContent(
state = state,
isGoogleAvailable = isGoogleAvailable,
callback = viewModel
)
}
Expand All @@ -69,8 +76,10 @@ class BackupWalletDialog : BaseComposeBottomSheetDialogFragment<BackupWalletView
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel.requestGoogleAuth.onEach {
viewModel.authorizeGoogle(launcher = launcher)
}.launchIn(viewLifecycleOwner.lifecycleScope)
if (isGoogleAvailable) {
viewModel.requestGoogleAuth.onEach {
viewModel.authorizeGoogle(launcher = launcher)
}.launchIn(viewLifecycleOwner.lifecycleScope)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import jp.co.soramitsu.common.utils.formatFiat
import jp.co.soramitsu.feature_account_impl.R
import jp.co.soramitsu.runtime.multiNetwork.chain.model.polkadotChainId
import jp.co.soramitsu.shared_utils.encrypt.mnemonic.MnemonicCreator
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
Expand Down Expand Up @@ -88,6 +89,7 @@ class BackupWalletViewModel @Inject constructor(
private val refresh = MutableSharedFlow<Event<Unit>>()
private val isAuthedToGoogle = MutableStateFlow(false)

@OptIn(ExperimentalCoroutinesApi::class)
private val googleBackupType = refresh.flatMapLatest {
googleBackupAddressFlow.map { backupAddress ->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jp.co.soramitsu.account.impl.presentation.create_backup_password

import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -12,14 +11,12 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import jp.co.soramitsu.common.R
import jp.co.soramitsu.common.compose.component.AccentButton
Expand Down Expand Up @@ -68,7 +65,6 @@ interface CreateBackupPasswordCallback {
fun onConfirmPasswordVisibilityClick()
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
internal fun CreateBackupPasswordContent(
state: CreateBackupPasswordViewState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ interface BackupMnemonicCallback {
@Composable
internal fun BackupMnemonicContent(
state: BackupMnemonicState,
isGoogleAvailable: Boolean,
callback: BackupMnemonicCallback
) {
Column {
Expand Down Expand Up @@ -195,7 +196,8 @@ internal fun BackupMnemonicContent(
callback.onNextClick(launcher)
}
)
if (state.isFromGoogleBackup.not()) {

if (isGoogleAvailable && state.isFromGoogleBackup.not()) {
MarginVertical(8.dp)
GoogleButton(
modifier = Modifier
Expand Down Expand Up @@ -223,6 +225,7 @@ private fun PreviewBackupMnemonicContent() {
ethereumDerivationPath = "",
isFromGoogleBackup = false
),
isGoogleAvailable = true,
callback = object : BackupMnemonicCallback {
override fun onNextClick(launcher: ActivityResultLauncher<Intent>) {}
override fun onBackClick() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import jp.co.soramitsu.account.impl.presentation.view.advanced.encryption.Encryp
import jp.co.soramitsu.account.impl.presentation.view.advanced.encryption.model.CryptoTypeModel
import jp.co.soramitsu.common.base.BaseComposeBottomSheetDialogFragment
import jp.co.soramitsu.common.compose.component.BottomSheetScreen
import jp.co.soramitsu.common.utils.isGooglePlayServicesAvailable
import jp.co.soramitsu.common.view.bottomSheet.list.dynamic.DynamicListBottomSheet

@AndroidEntryPoint
Expand All @@ -26,9 +27,11 @@ class BackupMnemonicDialog : BaseComposeBottomSheetDialogFragment<BackupMnemonic
val state by viewModel.state.collectAsState()
viewModel.encryptionTypeChooserEvent.observeEvent(::showEncryptionChooser)

val isGoogleAvailable = context?.isGooglePlayServicesAvailable() == true
BottomSheetScreen {
BackupMnemonicContent(
state = state,
isGoogleAvailable = isGoogleAvailable,
callback = viewModel
)
}
Expand Down
Loading

0 comments on commit cd73384

Please sign in to comment.