Skip to content

Commit

Permalink
mwr-638 backup not enough space error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mrZizik committed Sep 25, 2023
1 parent 6a2abb9 commit def7c79
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import java.util.Locale
import java.util.TimeZone
import javax.inject.Singleton
import jp.co.soramitsu.androidfoundation.phone.BasicClipboardManager
import jp.co.soramitsu.xbackup.BackupService
import jp.co.soramitsu.common.BuildConfig
import jp.co.soramitsu.common.account.AccountAvatarGenerator
import jp.co.soramitsu.common.data.AppStateProviderImpl
Expand Down Expand Up @@ -83,6 +82,7 @@ import jp.co.soramitsu.common.util.json_decoder.JsonAccountsEncoder
import jp.co.soramitsu.common.vibration.DeviceVibrator
import jp.co.soramitsu.crypto.ed25519.Ed25519Sha3
import jp.co.soramitsu.shared_utils.encrypt.json.JsonSeedEncoder
import jp.co.soramitsu.xbackup.BackupService
import jp.co.soramitsu.xnetworking.networkclient.SoramitsuHttpClientProvider
import jp.co.soramitsu.xnetworking.networkclient.SoramitsuHttpClientProviderImpl
import jp.co.soramitsu.xnetworking.networkclient.SoramitsuNetworkClient
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<string name="backup_password_requirments">Minimum six characters. Optionally, for better security, include uppercase letters, numbers and non-alphabetic characters.</string>
<string name="backup_password_title">Setting a password will encrypt your Google backup. You’ll need to enter this when restoring your wallet.\nMinimum password length is 6 characters.</string>
<string name="backup_password_title_2">Setting a password will encrypt your Google backup. You’ll need to enter this when restoring your wallet.</string>
<string name="backup_not_enough_space_error">Backup failed. Not enough space on your Google Drive. Free some space and try again.</string>
<string name="biometric_dialog_title">Authenticate</string>
<string name="block_id">Block hash</string>
<string name="buy_crypto_buy_xor_banner_title">Buy XOR token</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import jp.co.soramitsu.xbackup.BackupService
import jp.co.soramitsu.common.BuildConfig
import jp.co.soramitsu.common.config.BuildConfigWrapper
import jp.co.soramitsu.common.domain.OptionsProvider
Expand All @@ -51,6 +50,7 @@ import jp.co.soramitsu.common.presentation.compose.components.initSmallTitle2
import jp.co.soramitsu.common.presentation.trigger
import jp.co.soramitsu.common.presentation.viewmodel.BaseViewModel
import jp.co.soramitsu.sora.substrate.runtime.RuntimeManager
import jp.co.soramitsu.xbackup.BackupService
import kotlinx.coroutines.launch

@HiltViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package jp.co.soramitsu.feature_multiaccount_impl.presentation

import android.graphics.drawable.Drawable
import jp.co.soramitsu.xbackup.domain.models.BackupAccountMeta
import jp.co.soramitsu.common.presentation.compose.webview.WebViewState
import jp.co.soramitsu.ui_core.component.input.InputTextState
import jp.co.soramitsu.xbackup.domain.models.BackupAccountMeta

data class RecoveryState(
val recoveryType: RecoveryType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ import androidx.navigation.NavOptions
import dagger.hilt.android.lifecycle.HiltViewModel
import java.net.SocketException
import javax.inject.Inject
import jp.co.soramitsu.xbackup.BackupService
import jp.co.soramitsu.xbackup.domain.exceptions.AuthConsentException
import jp.co.soramitsu.xbackup.domain.exceptions.DecodingException
import jp.co.soramitsu.xbackup.domain.exceptions.DecryptionException
import jp.co.soramitsu.xbackup.domain.exceptions.UnauthorizedException
import jp.co.soramitsu.xbackup.domain.models.BackupAccountMeta
import jp.co.soramitsu.xbackup.domain.models.BackupAccountType
import jp.co.soramitsu.xbackup.domain.models.DecryptedBackupAccount
import jp.co.soramitsu.xbackup.domain.models.Json
import jp.co.soramitsu.xbackup.domain.models.Seed
import jp.co.soramitsu.common.R
import jp.co.soramitsu.common.account.AccountAvatarGenerator
import jp.co.soramitsu.common.account.SoraAccount
Expand All @@ -79,8 +69,18 @@ import jp.co.soramitsu.feature_multiaccount_impl.presentation.export_account.mod
import jp.co.soramitsu.feature_multiaccount_impl.presentation.export_account.model.ExportProtectionSelectableModel
import jp.co.soramitsu.ui_core.component.input.InputTextState
import jp.co.soramitsu.ui_core.resources.Dimens
import jp.co.soramitsu.xbackup.BackupService
import jp.co.soramitsu.xbackup.domain.exceptions.AuthConsentException
import jp.co.soramitsu.xbackup.domain.exceptions.DecodingException
import jp.co.soramitsu.xbackup.domain.exceptions.DecryptionException
import jp.co.soramitsu.xbackup.domain.exceptions.StorageQuotaExceeded
import jp.co.soramitsu.xbackup.domain.exceptions.UnauthorizedException
import jp.co.soramitsu.xbackup.domain.models.BackupAccountMeta
import jp.co.soramitsu.xbackup.domain.models.BackupAccountType
import jp.co.soramitsu.xbackup.domain.models.CryptoType
import jp.co.soramitsu.xbackup.domain.models.DecryptedBackupAccount
import jp.co.soramitsu.xbackup.domain.models.Json
import jp.co.soramitsu.xbackup.domain.models.Seed
import kotlin.random.Random
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand Down Expand Up @@ -646,7 +646,11 @@ class OnboardingViewModel @Inject constructor(
_consentExceptionHandler.value = e.intent
}
} catch (e: StorageQuotaExceeded) {
// TODO: add alert for storage
withContext(coroutineManager.main) {
_createBackupPasswordState.value =
createBackupPasswordState.copy(isLoading = false)
onError(R.string.backup_not_enough_space_error)
}
}
}
}
Expand Down Expand Up @@ -680,7 +684,7 @@ class OnboardingViewModel @Inject constructor(
success = !isError && confirmationDescriptionText != R.string.common_empty_string
),
setPasswordButtonIsEnabled = it.warningIsSelected &&
it.passwordConfirmation.value.text == filteredValue.text && isSecure
it.passwordConfirmation.value.text == filteredValue.text && isSecure
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import java.net.SocketException
import jp.co.soramitsu.androidfoundation.phone.BasicClipboardManager
import jp.co.soramitsu.xbackup.BackupService
import jp.co.soramitsu.xbackup.domain.exceptions.AuthConsentException
import jp.co.soramitsu.xbackup.domain.exceptions.FileNotFoundException
import jp.co.soramitsu.xbackup.domain.models.BackupAccountType
import jp.co.soramitsu.xbackup.domain.models.DecryptedBackupAccount
import jp.co.soramitsu.xbackup.domain.models.Json
import jp.co.soramitsu.xbackup.domain.models.Seed
import jp.co.soramitsu.common.R
import jp.co.soramitsu.common.account.SoraAccount
import jp.co.soramitsu.common.domain.CoroutineManager
Expand All @@ -66,8 +59,15 @@ import jp.co.soramitsu.feature_multiaccount_impl.domain.MultiaccountInteractor
import jp.co.soramitsu.feature_multiaccount_impl.presentation.CreateBackupPasswordState
import jp.co.soramitsu.feature_multiaccount_impl.presentation.export_account.model.AccountDetailsScreenState
import jp.co.soramitsu.ui_core.component.input.InputTextState
import jp.co.soramitsu.xbackup.BackupService
import jp.co.soramitsu.xbackup.domain.exceptions.AuthConsentException
import jp.co.soramitsu.xbackup.domain.exceptions.FileNotFoundException
import jp.co.soramitsu.xbackup.domain.exceptions.StorageQuotaExceeded
import jp.co.soramitsu.xbackup.domain.models.BackupAccountType
import jp.co.soramitsu.xbackup.domain.models.CryptoType
import jp.co.soramitsu.xbackup.domain.models.DecryptedBackupAccount
import jp.co.soramitsu.xbackup.domain.models.Json
import jp.co.soramitsu.xbackup.domain.models.Seed
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.debounce
Expand Down Expand Up @@ -225,7 +225,7 @@ class AccountDetailsViewModel @AssistedInject constructor(
success = !isError && confirmationDescriptionText != R.string.common_empty_string
),
setPasswordButtonIsEnabled = it.warningIsSelected &&
it.passwordConfirmation.value.text == filteredValue.text && isSecure
it.passwordConfirmation.value.text == filteredValue.text && isSecure
)
}
}
Expand Down Expand Up @@ -263,8 +263,8 @@ class AccountDetailsViewModel @AssistedInject constructor(
fun onBackupPasswordClicked() {
_createBackupPasswordState.value?.let { createBackupPasswordState ->
_createBackupPasswordState.value = createBackupPasswordState.copy(isLoading = true)
try {
viewModelScope.launch(coroutineManager.io) {
viewModelScope.launch(coroutineManager.io) {
try {
_accountDetailsScreenState.value?.let { accountDetailsScreenState ->
account?.let { account ->
val passphrase =
Expand Down Expand Up @@ -313,13 +313,19 @@ class AccountDetailsViewModel @AssistedInject constructor(
}
}
}
} catch (e: SocketException) {
withContext(coroutineManager.main) {
onError(SoraException.networkError(resourceManager, e))
}
} catch (e: AuthConsentException) {
withContext(coroutineManager.main) {
_consentExceptionHandler.value = e.intent
}
} catch (e: StorageQuotaExceeded) {
withContext(coroutineManager.main) {
onError(R.string.backup_not_enough_space_error)
}
}
} catch (e: SocketException) {
onError(SoraException.networkError(resourceManager, e))
} catch (e: AuthConsentException) {
_consentExceptionHandler.value = e.intent
} catch (e: StorageQuotaExceeded) {
// TODO: alert
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import jp.co.soramitsu.xbackup.domain.models.BackupAccountMeta
import jp.co.soramitsu.common.R
import jp.co.soramitsu.common.presentation.compose.TokenIcon
import jp.co.soramitsu.feature_multiaccount_impl.presentation.BackupAccountMetaWithIcon
Expand All @@ -69,6 +68,7 @@ import jp.co.soramitsu.ui_core.component.input.InputText
import jp.co.soramitsu.ui_core.resources.Dimens
import jp.co.soramitsu.ui_core.theme.customColors
import jp.co.soramitsu.ui_core.theme.customTypography
import jp.co.soramitsu.xbackup.domain.models.BackupAccountMeta

@Composable
fun ImportAccountPasswordScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import jp.co.soramitsu.xbackup.domain.models.BackupAccountMeta
import jp.co.soramitsu.common.R
import jp.co.soramitsu.feature_multiaccount_impl.presentation.BackupAccountMetaWithIcon
import jp.co.soramitsu.feature_multiaccount_impl.presentation.ImportAccountPasswordState
Expand All @@ -59,6 +58,7 @@ import jp.co.soramitsu.ui_core.component.card.ContentCard
import jp.co.soramitsu.ui_core.resources.Dimens
import jp.co.soramitsu.ui_core.theme.customColors
import jp.co.soramitsu.ui_core.theme.customTypography
import jp.co.soramitsu.xbackup.domain.models.BackupAccountMeta

@Composable
fun ImportAccountSuccessScreen(
Expand Down

0 comments on commit def7c79

Please sign in to comment.