Updated on 2026-08-14

This commit is contained in:
Tangem 2024-10-06 12:16:42 +04:00
parent 898edd2b16
commit 5516e706aa
10 changed files with 45 additions and 21 deletions

View file

@ -60,6 +60,7 @@ sealed class BackupAction : Action {
data object ErrorInBackupCard : BackupAction()
data object StartAddingPrimaryCard : BackupAction()
data object ScanPrimaryCard : BackupAction()
data class SetHasRing(val hasRing: Boolean) : BackupAction()
/**
* Check for unfinished backup of standard Wallets

View file

@ -16,6 +16,8 @@ import com.tangem.domain.common.extensions.withIOContext
import com.tangem.domain.common.extensions.withMainContext
import com.tangem.domain.common.util.cardTypesResolver
import com.tangem.domain.models.scan.CardDTO
import com.tangem.domain.models.scan.CardDTO.Companion.RING_BATCH_IDS
import com.tangem.domain.models.scan.CardDTO.Companion.RING_BATCH_PREFIX
import com.tangem.domain.models.scan.ScanResponse
import com.tangem.domain.wallets.builder.UserWalletBuilder
import com.tangem.domain.wallets.models.Artwork
@ -200,6 +202,13 @@ private fun handleWalletAction(action: Action) {
private fun handleFinishOnboardind(scanResponse: ScanResponse) {
val backupState = store.state.onboardingWalletState.backupState
val updatedScanResponse = updateScanResponseAfterBackup(scanResponse, backupState)
if (backupState.hasRing) {
scope.launch {
store.inject(DaggerGraphState::walletsRepository).setHasWalletsWithRing()
}
}
OnboardingHelper.trySaveWalletAndNavigateToWalletScreen(
scanResponse = updatedScanResponse,
accessCode = backupState.accessCode,
@ -496,11 +505,11 @@ private fun handleBackupAction(appState: () -> AppState?, action: BackupAction)
}
}
is BackupAction.WritePrimaryCard -> {
val iconScanRes = if (scanResponse?.cardTypesResolver?.isRing() == true) {
R.drawable.img_hand_scan_ring
} else {
null
}
val isRing = scanResponse?.cardTypesResolver?.isRing() == true
val iconScanRes = if (isRing) R.drawable.img_hand_scan_ring else null
store.dispatchOnMain(BackupAction.SetHasRing(hasRing = isRing))
backupService.proceedBackup(iconScanRes = iconScanRes) { result ->
when (result) {
is CompletionResult.Success -> {
@ -513,11 +522,11 @@ private fun handleBackupAction(appState: () -> AppState?, action: BackupAction)
is BackupAction.WriteBackupCard -> {
val cardIndex = if (action.cardNumber > 0) action.cardNumber - 1 else action.cardNumber
val backupCard = backupState.backupCards.getOrNull(cardIndex)
val iconScanRes = if (backupCard?.batchId?.startsWith(CardDTO.RING_BATCH_PREFIX) == true) {
R.drawable.img_hand_scan_ring
} else {
null
}
val isRing = backupCard.isRing()
val iconScanRes = if (isRing) R.drawable.img_hand_scan_ring else null
store.dispatchOnMain(BackupAction.SetHasRing(hasRing = isRing))
backupService.proceedBackup(iconScanRes = iconScanRes) { result ->
when (result) {
is CompletionResult.Success -> {
@ -636,6 +645,10 @@ private fun handleBackupAction(appState: () -> AppState?, action: BackupAction)
}
}
private fun Card?.isRing(): Boolean {
return this?.let { RING_BATCH_IDS.contains(batchId) || batchId.startsWith(RING_BATCH_PREFIX) } ?: false
}
fun updateArtworks(addedBackupCardsCount: Int, card: Card) {
mainScope.launch {
withIOContext {

View file

@ -132,6 +132,7 @@ private object BackupReducer {
is BackupAction.FinishBackup -> state.copy(backupStep = BackupStep.Finished)
BackupAction.OnAccessCodeDialogClosed -> state.copy(backupStep = BackupStep.AddBackupCards)
BackupAction.DiscardBackup -> BackupState()
is BackupAction.SetHasRing -> state.copy(hasRing = action.hasRing)
else -> state
}
}

View file

@ -78,6 +78,7 @@ data class BackupState(
val isInterruptedBackup: Boolean = false,
val showBtnLoading: Boolean = false,
val hasBackupError: Boolean = false,
val hasRing: Boolean = false,
)
enum class AccessCodeError {

View file

@ -5,10 +5,7 @@ import com.tangem.datasource.api.express.models.request.AssetsRequestBody
import com.tangem.datasource.api.express.models.request.ExchangeSentRequestBody
import com.tangem.datasource.api.express.models.request.PairsRequestBody
import com.tangem.datasource.api.express.models.response.*
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query
import retrofit2.http.*
/**
* Interface of Tangem Express API (new swap mechanism)
@ -36,6 +33,7 @@ interface TangemExpressApi {
@Query("toDecimals") toDecimals: Int,
@Query("providerId") providerId: String,
@Query("rateType") rateType: String,
@Header("refcode") refCode: String? = null,
): ApiResponse<ExchangeQuoteResponse>
@GET("exchange-data")

View file

@ -99,18 +99,13 @@ object PreferencesKeys {
val apiConfigsEnvironmentKey by lazy { stringPreferencesKey(name = "apiConfigsEnvironment") }
val IS_RING_ADDED_KEY by lazy { booleanPreferencesKey(name = "isRingAdded") }
// region Permission
fun getShouldShowPermission(permission: String) = booleanPreferencesKey("shouldShowPushPermission_$permission")
fun getShouldShowInitialPermissionScreen(permission: String) =
booleanPreferencesKey("shouldShowInitialPushPermissionScreen_$permission")
fun getIsFirstTimeAskingPermission(permission: String) =
booleanPreferencesKey("shouldAskInitialPushPermission_$permission")
fun getPermissionLaunchCount(permission: String) = intPreferencesKey("pushPermissionLaunchCount_$permission")
fun getPermissionDaysCount(permission: String) = longPreferencesKey("pushPermissionDaysCount_$permission")
// endregion
fun getUserTokensKey(userWalletId: String) = stringPreferencesKey(name = "user_tokens_$userWalletId")

View file

@ -23,4 +23,8 @@ internal class DefaultWalletsRepository(
override suspend fun saveShouldSaveUserWallets(item: Boolean) {
appPreferencesStore.store(key = PreferencesKeys.SAVE_USER_WALLETS_KEY, value = item)
}
override suspend fun setHasWalletsWithRing() {
appPreferencesStore.store(key = PreferencesKeys.IS_RING_ADDED_KEY, value = true)
}
}

View file

@ -9,4 +9,6 @@ interface WalletsRepository {
fun shouldSaveUserWallets(): Flow<Boolean>
suspend fun saveShouldSaveUserWallets(item: Boolean)
suspend fun setHasWalletsWithRing()
}

View file

@ -20,6 +20,9 @@ import com.tangem.datasource.api.express.models.response.SwapPair
import com.tangem.datasource.api.express.models.response.SwapPairsWithProviders
import com.tangem.datasource.api.express.models.response.TxDetails
import com.tangem.datasource.crypto.DataSignatureVerifier
import com.tangem.datasource.local.preferences.AppPreferencesStore
import com.tangem.datasource.local.preferences.PreferencesKeys
import com.tangem.datasource.local.preferences.utils.getSyncOrNull
import com.tangem.domain.common.util.derivationStyleProvider
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.walletmanager.WalletManagersFacade
@ -49,6 +52,7 @@ internal class DefaultSwapRepository @Inject constructor(
private val userWalletsListManager: UserWalletsListManager,
private val errorsDataConverter: ErrorsDataConverter,
private val dataSignatureVerifier: DataSignatureVerifier,
private val appPreferencesStore: AppPreferencesStore,
moshi: Moshi,
) : SwapRepository {
@ -199,6 +203,8 @@ internal class DefaultSwapRepository @Inject constructor(
): Either<DataError, QuoteModel> {
return withContext(coroutineDispatcher.io) {
try {
val isRingAdded = appPreferencesStore.getSyncOrNull(PreferencesKeys.IS_RING_ADDED_KEY)
val response = tangemExpressApi.getExchangeQuote(
fromContractAddress = fromContractAddress,
fromNetwork = fromNetwork,
@ -209,6 +215,7 @@ internal class DefaultSwapRepository @Inject constructor(
toDecimals = toDecimals,
providerId = providerId,
rateType = rateType.name.lowercase(),
refCode = if (isRingAdded == true) "ring" else null,
).getOrThrow()
QuoteModel(
toTokenAmount = createFromAmountWithOffset(response.toAmount, response.toDecimals),

View file

@ -33,6 +33,7 @@ internal class SwapDataModule {
walletManagerFacade: WalletManagersFacade,
userWalletsListManager: UserWalletsListManager,
errorsDataConverter: ErrorsDataConverter,
appPreferencesStore: AppPreferencesStore,
@NetworkMoshi moshi: Moshi,
): SwapRepository {
return DefaultSwapRepository(
@ -42,6 +43,7 @@ internal class SwapDataModule {
userWalletsListManager = userWalletsListManager,
errorsDataConverter = errorsDataConverter,
dataSignatureVerifier = dataSignature,
appPreferencesStore = appPreferencesStore,
moshi = moshi,
)
}