Updated on 2026-08-14

This commit is contained in:
Tangem 2023-04-11 12:42:05 +03:00
parent abec0f1ee8
commit a2b3c22e53
17 changed files with 85 additions and 224 deletions

View file

@ -9,6 +9,7 @@ import com.tangem.domain.common.util.UserWalletId
import com.tangem.tap.common.analytics.converters.TopUpEventConverter
import com.tangem.tap.common.analytics.events.AnalyticsParam
import com.tangem.tap.common.extensions.copy
import com.tangem.tap.domain.model.TotalFiatBalance
import com.tangem.tap.domain.model.UserWallet
import com.tangem.tap.domain.model.WalletDataModel
import com.tangem.tap.domain.model.WalletStoreModel
@ -17,7 +18,6 @@ import com.tangem.tap.domain.tokens.models.BlockchainNetwork
import com.tangem.tap.domain.walletCurrencies.WalletCurrenciesManager
import com.tangem.tap.domain.walletStores.WalletStoresManager
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.redux.ProgressState
import com.tangem.tap.persistence.ToppedUpWalletStorage
import com.tangem.tap.scope
import kotlinx.coroutines.launch
@ -60,8 +60,8 @@ class TopUpController(
hadMissedDerivations = blockchains.isNotEmpty()
}
fun totalBalanceStateChanged(state: ProgressState) {
if (state == ProgressState.Done) tryToSend()
fun totalBalanceStateChanged(totalFiatBalance: TotalFiatBalance) {
if (totalFiatBalance is TotalFiatBalance.Loaded) tryToSend()
}
fun loadDataSuccess() {

View file

@ -12,9 +12,8 @@ import com.tangem.tap.common.TestActions
import com.tangem.tap.domain.TapError
import com.tangem.tap.domain.extensions.amountToCreateAccount
import com.tangem.tap.domain.getFirstToken
import com.tangem.tap.domain.model.WalletDataModel
import com.tangem.tap.features.demo.isDemoCard
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.redux.AddressData
import com.tangem.tap.features.wallet.redux.reducers.createAddressesData
import com.tangem.tap.network.exchangeServices.CurrencyExchangeManager
import com.tangem.tap.proxy.redux.DaggerGraphState
@ -81,7 +80,7 @@ fun WalletManager.getTopUpUrl(): String? {
)
}
fun WalletManager?.getAddressData(): AddressData? {
fun WalletManager?.getAddressData(): WalletDataModel.AddressData? {
val wallet = this?.wallet ?: return null
val addressDataList = wallet.createAddressesData()
@ -100,11 +99,6 @@ fun <T> WalletManager.Companion.stub(): T {
} as T
}
fun Wallet.getTxHistory(currency: Currency): List<TransactionData> {
return (currency as? Currency.Token)?.let { this.getTokenTxHistory(it.token) }
?: getBlockchainTxHistory()
}
fun Wallet.getBlockchainTxHistory(): List<TransactionData> {
return historyTransactions.filter {
it.contractAddress.isNullOrEmpty()

View file

@ -2,8 +2,8 @@ package com.tangem.tap.common.redux
import com.tangem.common.extensions.VoidCallback
import com.tangem.tap.common.TestAction
import com.tangem.tap.domain.model.WalletDataModel
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.redux.AddressData
/**
[REDACTED_AUTHOR]
@ -24,7 +24,7 @@ sealed class AppDialog : StateDialog {
data class AddressInfoDialog(
val currency: Currency,
val addressData: AddressData,
val addressData: WalletDataModel.AddressData,
) : AppDialog()
data class TestActionsDialog(

View file

@ -184,10 +184,6 @@ private fun getExistentialDeposit(walletManager: WalletManager?): BigDecimal? {
private fun Wallet.getWalletAddresses(): WalletDataModel.WalletAddresses? {
return this.createAddressesData()
.takeIf { it.isNotEmpty() }
?.map {
// TODO: Will be removed in next MR
with(it) { WalletDataModel.AddressData(address, type, shareUrl, exploreUrl) }
}
?.let { addresses ->
WalletDataModel.WalletAddresses(
list = addresses,

View file

@ -12,8 +12,9 @@ import com.tangem.tap.common.extensions.dispatchDialogHide
import com.tangem.tap.common.extensions.dispatchShare
import com.tangem.tap.common.extensions.dispatchToastNotification
import com.tangem.tap.common.extensions.getString
import com.tangem.tap.common.extensions.toQrCode
import com.tangem.tap.common.redux.AppDialog
import com.tangem.tap.features.wallet.redux.AddressData
import com.tangem.tap.domain.model.WalletDataModel
import com.tangem.tap.store
import com.tangem.wallet.R
import com.tangem.wallet.databinding.DialogOnboardingAddressInfoBinding
@ -46,12 +47,12 @@ class AddressInfoBottomSheetDialog(
showData(data = stateDialog.addressData)
}
private fun showData(data: AddressData) = with(binding!!) {
private fun showData(data: WalletDataModel.AddressData) = with(binding!!) {
pseudoToolbar.imvClose.setOnClickListener {
dismissWithAnimation = true
cancel()
}
imvQrCode.setImageBitmap(data.qrCode)
imvQrCode.setImageBitmap(data.shareUrl.toQrCode())
tvAddress.text = data.address
btnFlCopyAddress.setOnClickListener {
Analytics.send(Token.Receive.ButtonCopyAddress())

View file

@ -17,8 +17,8 @@ import com.tangem.tap.features.send.redux.states.ReceiptSymbols
import com.tangem.tap.features.send.redux.states.ReceiptTokenCrypto
import com.tangem.tap.features.send.redux.states.ReceiptTokenFiat
import com.tangem.tap.features.send.redux.states.SendState
import com.tangem.tap.features.wallet.redux.WalletState.Companion.CAN_BE_LOWER_SIGN
import com.tangem.tap.features.wallet.redux.WalletState.Companion.UNKNOWN_AMOUNT_SIGN
import com.tangem.tap.features.wallet.redux.utils.CAN_BE_LOWER_SIGN
import com.tangem.tap.features.wallet.redux.utils.UNKNOWN_AMOUNT_SIGN
import com.tangem.tap.store
import java.math.BigDecimal

View file

@ -38,8 +38,8 @@ import com.tangem.tap.features.send.ui.dialogs.RequestFeeErrorDialog
import com.tangem.tap.features.send.ui.dialogs.SendTransactionFailsDialog
import com.tangem.tap.features.send.ui.dialogs.TezosWarningDialog
import com.tangem.tap.features.wallet.redux.ProgressState
import com.tangem.tap.features.wallet.redux.WalletState.Companion.ROUGH_SIGN
import com.tangem.tap.features.wallet.redux.WalletState.Companion.UNKNOWN_AMOUNT_SIGN
import com.tangem.tap.features.wallet.redux.utils.ROUGH_SIGN
import com.tangem.tap.features.wallet.redux.utils.UNKNOWN_AMOUNT_SIGN
import com.tangem.tap.features.wallet.ui.adapters.WarningMessagesAdapter
import com.tangem.wallet.R

View file

@ -3,8 +3,8 @@ package com.tangem.tap.features.tokens.redux
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.DerivationStyle
import com.tangem.domain.common.ScanResponse
import com.tangem.tap.domain.model.WalletDataModel
import com.tangem.tap.domain.tokens.Currency
import com.tangem.tap.features.wallet.redux.WalletData
import org.rekotlin.Action
sealed class TokensAction : Action {
@ -23,7 +23,7 @@ sealed class TokensAction : Action {
) : TokensAction()
data class SetAddedCurrencies(
val wallets: List<WalletData>,
val wallets: List<WalletDataModel>,
val derivationStyle: DerivationStyle?,
) : TokensAction()

View file

@ -6,13 +6,13 @@ import com.tangem.blockchain.common.Token
import com.tangem.domain.common.ScanResponse
import com.tangem.domain.common.extensions.canHandleToken
import com.tangem.domain.common.extensions.fromNetworkId
import com.tangem.tap.domain.model.WalletDataModel
import com.tangem.tap.domain.tokens.Currency
import com.tangem.tap.features.wallet.redux.WalletData
import org.rekotlin.StateType
import com.tangem.tap.features.wallet.models.Currency.Token as CurrencyToken
data class TokensState(
val addedWallets: List<WalletData> = emptyList(),
val addedWallets: List<WalletDataModel> = emptyList(),
val addedTokens: List<TokenWithBlockchain> = emptyList(),
val addedBlockchains: List<Blockchain> = emptyList(),
val currencies: List<Currency> = emptyList(),
@ -31,17 +31,9 @@ data class TokensState(
typealias ContractAddress = String
fun List<WalletData>.toTokensContractAddresses(): List<ContractAddress> {
return mapNotNull { (it.currency as? CurrencyToken)?.token?.contractAddress }.distinct()
}
fun List<WalletData>.toNonCustomTokens(derivationStyle: DerivationStyle?): List<Token> {
return filter { !it.currency.isCustomCurrency(derivationStyle) }
.mapNotNull { (it.currency as? CurrencyToken)?.token }
.distinct()
}
fun List<WalletData>.toNonCustomTokensWithBlockchains(derivationStyle: DerivationStyle?): List<TokenWithBlockchain> {
fun List<WalletDataModel>.toNonCustomTokensWithBlockchains(
derivationStyle: DerivationStyle?,
): List<TokenWithBlockchain> {
return mapNotNull {
if (it.currency !is CurrencyToken) return@mapNotNull null
if (it.currency.isCustomCurrency(derivationStyle)) return@mapNotNull null
@ -49,7 +41,7 @@ fun List<WalletData>.toNonCustomTokensWithBlockchains(derivationStyle: Derivatio
}.distinct()
}
fun List<WalletData>.toNonCustomBlockchains(derivationStyle: DerivationStyle?): List<Blockchain> {
fun List<WalletDataModel>.toNonCustomBlockchains(derivationStyle: DerivationStyle?): List<Blockchain> {
return mapNotNull {
if (it.currency.isCustomCurrency(derivationStyle)) {
null

View file

@ -1,5 +1,7 @@
package com.tangem.tap.features.wallet.models
import com.tangem.tap.domain.model.WalletStoreModel
sealed class WalletWarning(val showingPosition: Int) {
data class ExistentialDeposit(
@ -15,7 +17,7 @@ sealed class WalletWarning(val showingPosition: Int) {
val blockchainSymbol: String,
) : WalletWarning(showingPosition = 30)
data class Rent(val walletRent: WalletRent) : WalletWarning(showingPosition = 40)
data class Rent(val walletRent: WalletStoreModel.WalletRent) : WalletWarning(showingPosition = 40)
}
data class WalletWarningDescription(val title: String, val message: String)

View file

@ -8,11 +8,12 @@ import com.tangem.tap.common.entities.FiatCurrency
import com.tangem.tap.common.redux.NotificationAction
import com.tangem.tap.domain.TapError
import com.tangem.tap.domain.configurable.warningMessage.WarningMessage
import com.tangem.tap.domain.model.TotalFiatBalance
import com.tangem.tap.domain.model.UserWallet
import com.tangem.tap.domain.model.WalletDataModel
import com.tangem.tap.domain.model.WalletStoreModel
import com.tangem.tap.domain.tokens.models.BlockchainNetwork
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.models.TotalBalance
import com.tangem.tap.features.wallet.redux.models.WalletDialog
import com.tangem.wallet.R
import org.rekotlin.Action
@ -38,7 +39,6 @@ sealed class WalletAction : Action {
data class RemoveWallet(val currency: Currency) : MultiWallet()
object BackupWallet : MultiWallet()
object ScheduleCheckForMissingDerivation : MultiWallet()
data class AddMissingDerivations(val blockchains: List<BlockchainNetwork>) : MultiWallet()
object ScanToGetDerivations : MultiWallet()
}
@ -78,7 +78,7 @@ sealed class WalletAction : Action {
sealed class DialogAction : WalletAction() {
data class QrCode(
val currency: Currency,
val selectedAddress: AddressData,
val selectedAddress: WalletDataModel.AddressData,
) : DialogAction()
object SignedHashesMultiWalletDialog : DialogAction()
@ -127,9 +127,7 @@ sealed class WalletAction : Action {
}
data class UserWalletChanged(val userWallet: UserWallet) : WalletAction()
data class WalletStoresChanged(val walletStores: List<WalletStoreModel>) : WalletAction() {
data class UpdateWalletStores(val reduxWalletStores: List<WalletStore>) : WalletAction()
}
data class WalletStoresChanged(val walletStores: List<WalletStoreModel>) : WalletAction()
data class TotalFiatBalanceChanged(val balance: TotalBalance) : WalletAction()
data class TotalFiatBalanceChanged(val balance: TotalFiatBalance) : WalletAction()
}

View file

@ -85,7 +85,8 @@ data class WalletData(
walletWarnings.add(WalletWarning.TransactionInProgress(currency.currencyName))
}
if (walletRent != null) {
walletWarnings.add(WalletWarning.Rent(walletRent))
// TODO: Will be removed in next MR
// walletWarnings.add(WalletWarning.Rent(walletRent))
}
}

View file

@ -9,29 +9,30 @@ import com.tangem.tap.common.extensions.toQrCode
import com.tangem.tap.common.redux.global.CryptoCurrencyName
import com.tangem.tap.common.toggleWidget.WidgetState
import com.tangem.tap.domain.configurable.warningMessage.WarningMessage
import com.tangem.tap.domain.model.TotalFiatBalance
import com.tangem.tap.domain.model.UserWallet
import com.tangem.tap.domain.model.WalletDataModel
import com.tangem.tap.domain.model.WalletStoreModel
import com.tangem.tap.domain.tokens.models.BlockchainNetwork
import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsState
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.models.TotalBalance
import com.tangem.tap.features.wallet.redux.reducers.findProgressState
import com.tangem.tap.features.wallet.ui.BalanceStatus
import com.tangem.tap.store
import org.rekotlin.StateType
import kotlin.properties.ReadOnlyProperty
data class WalletState(
val cardId: String = "",
val userWallet: UserWallet? = null,
val state: ProgressState = ProgressState.Done,
val error: ErrorType? = null,
val cardImage: Artwork? = null,
val hashesCountVerified: Boolean? = null,
val mainWarningsList: List<WarningMessage> = mutableListOf(),
val walletsStores: List<WalletStore> = listOf(),
val walletsStores: List<WalletStoreModel> = listOf(),
val isMultiwalletAllowed: Boolean = false,
val cardCurrency: CryptoCurrencyName? = null,
val selectedCurrency: Currency? = null,
val isTestnet: Boolean = false,
val totalBalance: TotalBalance? = null,
val totalBalance: TotalFiatBalance? = null,
val showBackupWarning: Boolean = false,
val missingDerivations: List<BlockchainNetwork> = emptyList(),
val loadingUserTokens: Boolean = false,
@ -39,10 +40,10 @@ data class WalletState(
val canSaveUserWallets: Boolean = false,
) : StateType {
val walletsDataFromStores: List<WalletData>
get() = walletsStores.map { it.walletsData }.flatten()
val walletsDataFromStores: List<WalletDataModel>
get() = walletsStores.flatMap { it.walletsData }
val selectedWalletData: WalletData?
val selectedWalletData: WalletDataModel?
get() = walletsDataFromStores.firstOrNull { it.currency == selectedCurrency }
// if you do not delegate - the application crashes on startup,
@ -66,7 +67,7 @@ data class WalletState(
val walletManagers: List<WalletManager>
get() = walletsStores.mapNotNull { it.walletManager }
private val primaryWalletStore: WalletStore?
private val primaryWalletStore: WalletStoreModel?
get() = if (isMultiwalletAllowed || walletsStores.isEmpty() || walletsStores.size > 1) {
null
} else {
@ -76,17 +77,15 @@ data class WalletState(
val primaryWalletManager: WalletManager?
get() = primaryWalletStore?.walletManager
val primaryWalletData: WalletData?
get() = primaryWalletStore?.walletsData?.firstOrNull()
val primaryWalletData: WalletDataModel?
get() = primaryWalletStore?.blockchainWalletData
val primaryTokenData: WalletData?
get() = primaryWalletStore?.walletsData?.toMutableList()
?.apply { remove(primaryWalletData) }
?.firstOrNull()
val primaryTokenData: WalletDataModel?
get() = primaryWalletStore?.walletsData
?.firstOrNull { it.currency !is Currency.Blockchain }
val shouldShowDetails: Boolean =
primaryWalletData?.currencyData?.status != BalanceStatus.EmptyCard &&
primaryWalletData?.currencyData?.status != BalanceStatus.UnknownBlockchain
primaryWalletData?.status !is WalletDataModel.Unreachable
fun getWalletManager(currency: Currency?): WalletManager? {
if (currency?.blockchain == null) return null
@ -94,95 +93,27 @@ data class WalletState(
}
fun getWalletManager(blockchain: BlockchainNetwork): WalletManager? {
return walletsStores.find { it.blockchainNetwork == blockchain }?.walletManager
return walletsStores.firstOrNull {
it.blockchain == blockchain.blockchain &&
it.derivationPath?.rawPath == blockchain.derivationPath
}?.walletManager
}
fun getWalletData(blockchain: BlockchainNetwork?): WalletData? {
if (blockchain == null) return null
return walletsDataFromStores.find {
it.currency is Currency.Blockchain &&
it.currency.blockchain == blockchain.blockchain &&
it.currency.derivationPath == blockchain.derivationPath
}
}
fun getWalletStore(currency: Currency?): WalletStore? {
fun getWalletStore(currency: Currency?): WalletStoreModel? {
if (currency == null) return null
return walletsStores.firstOrNull {
it.blockchainNetwork.derivationPath == currency.derivationPath &&
it.blockchainNetwork.blockchain == currency.blockchain
it.blockchain == currency.blockchain &&
it.derivationPath?.rawPath == currency.derivationPath
}
}
private fun getWalletStore(blockchainNetwork: BlockchainNetwork?): WalletStore? {
if (blockchainNetwork == null) return null
return walletsStores.firstOrNull {
it.blockchainNetwork.derivationPath == blockchainNetwork.derivationPath &&
it.blockchainNetwork.blockchain == blockchainNetwork.blockchain
}
}
fun getWalletData(currency: Currency?): WalletData? {
if (currency == null) return null
return getWalletStore(currency)?.walletsData?.firstOrNull { it.currency == currency }
}
fun updateWalletData(walletData: WalletData?): WalletState {
if (walletData == null) return this
return updateWalletsData(listOf(walletData))
}
private fun updateWalletsData(walletsData: List<WalletData>): WalletState {
val walletStores = walletsData
.map { BlockchainNetwork(it.currency.blockchain, it.currency.derivationPath, emptyList()) }
.distinct().map { getWalletStore(it) }.mapNotNull { it?.updateWallets(walletsData) }
return updateWalletsStores(walletStores)
}
private fun updateWalletsStores(walletStores: List<WalletStore>): WalletState {
val walletStoresMutable = walletStores.toMutableList()
val updatedWallets = walletsStores.map { oldWalletStore ->
val walletStore = walletStoresMutable.find {
it.blockchainNetwork == oldWalletStore.blockchainNetwork
}
if (walletStore != null) {
walletStoresMutable.remove(walletStore)
walletStore
} else {
oldWalletStore
}
}
return copy(walletsStores = updatedWallets + walletStoresMutable)
.updateProgressState()
}
private fun updateProgressState(): WalletState {
val walletsData = this.walletsStores
.flatMap(WalletStore::walletsData)
return if (walletsData.isNotEmpty()) {
val newProgressState = walletsData.findProgressState()
this.copy(
state = walletsData.findProgressState(),
error = this.error.takeIf { newProgressState == ProgressState.Error },
)
} else {
this
}
}
companion object {
const val UNKNOWN_AMOUNT_SIGN = ""
const val ROUGH_SIGN = ""
const val CAN_BE_LOWER_SIGN = "<"
}
}
enum class ProgressState : WidgetState { Loading, Refreshing, Done, Error }
enum class ErrorType { NoInternetConnection }
enum class ErrorType {
NoInternetConnection,
UnknownBlockchain,
}
sealed class WalletMainButton(enabled: Boolean) : Button(enabled) {
class SendButton(enabled: Boolean) : WalletMainButton(enabled)

View file

@ -77,7 +77,7 @@ private fun WalletDataModel.mapToReduxModel(
return WalletData(
currency = currency,
// TODO: Will be updated in next MR
// TODO: Will be updated in next MRs
walletAddresses = walletAddresses?.let { addresses ->
WalletAddresses(
selectedAddress = with(addresses.selectedAddress) {

View file

@ -32,10 +32,7 @@ import com.tangem.tap.features.send.redux.PrepareSendScreen
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.models.getSendableAmounts
import com.tangem.tap.features.wallet.redux.WalletAction
import com.tangem.tap.features.wallet.redux.WalletData
import com.tangem.tap.features.wallet.redux.WalletState
import com.tangem.tap.features.wallet.redux.WalletStore
import com.tangem.tap.features.wallet.redux.reducers.findSelectedCurrency
import com.tangem.tap.preferencesStorage
import com.tangem.tap.proxy.redux.DaggerGraphState
import com.tangem.tap.scope
@ -106,7 +103,7 @@ class WalletMiddleware {
scope.launch {
when (val result = tangemSdkManager.createWallet(globalState.scanResponse?.card?.cardId)) {
is CompletionResult.Success -> {
val selectedUserWallet = userWalletsListManager.selectedUserWalletSync.guard {
val selectedUserWallet = walletState.userWallet.guard {
Timber.e("Unable to create wallet, no user wallet selected")
return@launch
}
@ -132,7 +129,7 @@ class WalletMiddleware {
is WalletAction.LoadData,
is WalletAction.LoadData.Refresh,
-> {
val selectedWallet = userWalletsListManager.selectedUserWalletSync.guard {
val selectedWallet = walletState.userWallet.guard {
Timber.e("Unable to load/refresh wallets data, no user wallet selected")
return
}
@ -188,7 +185,6 @@ class WalletMiddleware {
is WalletAction.WalletStoresChanged -> {
// Cancel update job when new wallet stores received
updateWalletStoresJob = scope.launch(Dispatchers.Default) {
ifActive { updateWalletStores(action.walletStores, walletState) }
ifActive { fetchTotalFiatBalance(action.walletStores) }
ifActive { findMissedDerivations(action.walletStores) }
ifActive { tryToShowAppRatingWarning(action.walletStores) }
@ -227,26 +223,8 @@ class WalletMiddleware {
}
}
private fun updateWalletStores(walletsStores: List<WalletStoreModel>, state: WalletState) {
val reduxWalletStores = walletsStores.mapToReduxModels()
if (!state.isMultiwalletAllowed) {
findSelectedCurrency(
walletsStores = reduxWalletStores,
currentSelectedCurrency = null,
isMultiWalletAllowed = false,
)?.let {
store.dispatchOnMain(WalletAction.MultiWallet.SetSingleWalletCurrency(it))
}
}
store.dispatchOnMain(
WalletAction.WalletStoresChanged.UpdateWalletStores(
reduxWalletStores = reduxWalletStores,
),
)
}
private suspend fun fetchTotalFiatBalance(walletStores: List<WalletStoreModel>) {
val totalFiatBalance = totalFiatBalanceCalculator.calculateOrNull(walletStores)?.mapToReduxModel()
val totalFiatBalance = totalFiatBalanceCalculator.calculateOrNull(walletStores)
if (totalFiatBalance != null) {
store.dispatchOnMain(WalletAction.TotalFiatBalanceChanged(totalFiatBalance))
@ -300,7 +278,7 @@ class WalletMiddleware {
return if (amount != null) {
if (amount.type is AmountType.Token) {
prepareSendActionForToken(amount, state, selectedWalletData, walletStore)
prepareSendActionForToken(amount, selectedWalletData, walletStore)
} else {
PrepareSendScreen(amount, selectedWalletData?.fiatRate, walletStore?.walletManager)
}
@ -322,7 +300,6 @@ class WalletMiddleware {
?: return WalletAction.DialogAction.ChooseCurrency(amounts)
prepareSendActionForToken(
amount = amountToSend,
state = state,
selectedWalletData = selectedWalletData,
walletStore = walletStore,
)
@ -346,11 +323,10 @@ class WalletMiddleware {
private fun prepareSendActionForToken(
amount: Amount,
state: WalletState?,
selectedWalletData: WalletData?,
walletStore: WalletStore?,
selectedWalletData: WalletDataModel?,
walletStore: WalletStoreModel?,
): PrepareSendScreen {
val coinRate = state?.getWalletData(walletStore?.blockchainNetwork)?.fiatRate
val coinRate = walletStore?.blockchainWalletData?.fiatRate
val tokenRate = selectedWalletData?.fiatRate
val coinAmount = walletStore?.walletManager?.wallet?.amounts?.get(AmountType.Coin)

View file

@ -1,23 +1,18 @@
package com.tangem.tap.features.wallet.redux.reducers
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.Wallet
import com.tangem.domain.common.CardDTO
import com.tangem.domain.common.TapWorkarounds.isTestCard
import com.tangem.tap.common.redux.AppState
import com.tangem.tap.domain.TapError
import com.tangem.tap.domain.tokens.models.BlockchainNetwork
import com.tangem.tap.domain.model.WalletDataModel
import com.tangem.tap.domain.model.WalletStoreModel
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.redux.AddressData
import com.tangem.tap.features.wallet.redux.Artwork
import com.tangem.tap.features.wallet.redux.ErrorType
import com.tangem.tap.features.wallet.redux.ProgressState
import com.tangem.tap.features.wallet.redux.WalletAction
import com.tangem.tap.features.wallet.redux.WalletData
import com.tangem.tap.features.wallet.redux.WalletState
import com.tangem.tap.features.wallet.redux.WalletStore
import com.tangem.tap.features.wallet.ui.BalanceStatus
import com.tangem.tap.features.wallet.ui.BalanceWidgetData
import com.tangem.tap.proxy.AppStateHolder
import org.rekotlin.Action
@ -41,44 +36,15 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS
is WalletAction.LoadData.Failure -> {
when (action.error) {
is TapError.NoInternetConnection -> {
val wallets = newState.walletsStores
.map { store ->
store.copy(
walletsData = store.walletsData.map {
it.copy(
currencyData = it.currencyData.copy(
status = BalanceStatus.Unreachable,
),
)
},
)
}
newState = newState.copy(
state = ProgressState.Error,
error = ErrorType.NoInternetConnection,
walletsStores = wallets,
)
}
is TapError.UnknownBlockchain -> {
newState = newState.copy(
state = ProgressState.Done,
walletsStores = listOf(
WalletStore(
walletManager = null,
blockchainNetwork = BlockchainNetwork(
Blockchain.Unknown,
null,
emptyList(),
),
walletsData = listOf(
WalletData(
currencyData = BalanceWidgetData(BalanceStatus.UnknownBlockchain),
currency = Currency.Blockchain(Blockchain.Unknown, null),
),
),
),
),
state = ProgressState.Error,
error = ErrorType.UnknownBlockchain,
)
}
else -> {
@ -107,7 +73,7 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS
is WalletAction.UserWalletChanged -> with(action.userWallet) {
val card = scanResponse.card
newState = WalletState(
cardId = card.cardId,
userWallet = this,
isMultiwalletAllowed = isMultiCurrency,
cardImage = Artwork(
artworkId = artworkUrl,
@ -126,10 +92,9 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS
},
)
}
is WalletAction.WalletStoresChanged.UpdateWalletStores -> {
is WalletAction.WalletStoresChanged -> {
newState = newState.copy(
state = action.reduxWalletStores.flatMap { it.walletsData }.findProgressState(newState.state),
walletsStores = action.reduxWalletStores,
walletsStores = action.walletStores,
)
}
is WalletAction.TotalFiatBalanceChanged -> {
@ -159,7 +124,7 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS
}
fun findSelectedCurrency(
walletsStores: List<WalletStore>,
walletsStores: List<WalletStoreModel>,
currentSelectedCurrency: Currency?,
isMultiWalletAllowed: Boolean,
): Currency? = if (isMultiWalletAllowed) {
@ -175,11 +140,11 @@ private fun CardDTO.findCardsCount(): Int? {
return (this.backupStatus as? CardDTO.BackupStatus.Active)?.cardCount?.inc()
}
fun Wallet.createAddressesData(): List<AddressData> {
val listOfAddressData = mutableListOf<AddressData>()
fun Wallet.createAddressesData(): List<WalletDataModel.AddressData> {
val listOfAddressData = mutableListOf<WalletDataModel.AddressData>()
// put a defaultAddress at the first place
addresses.forEach {
val addressData = AddressData(
val addressData = WalletDataModel.AddressData(
it.value,
it.type,
getShareUri(it.value),

View file

@ -0,0 +1,5 @@
package com.tangem.tap.features.wallet.redux.utils
const val UNKNOWN_AMOUNT_SIGN = ""
const val ROUGH_SIGN = ""
const val CAN_BE_LOWER_SIGN = "<"