Updated on 2026-08-14

This commit is contained in:
Tangem 2020-09-01 12:20:32 +03:00
parent 883a652715
commit bb9d49e2e6
10 changed files with 175 additions and 1 deletions

View file

@ -3,9 +3,11 @@ package com.tangem.tap.common.redux.global
import com.tangem.blockchain.common.WalletManager
import com.tangem.commands.Card
import org.rekotlin.Action
import java.math.BigDecimal
sealed class GlobalAction : Action {
data class LoadCard(val card: Card) : GlobalAction()
data class LoadWalletManager(val walletManager: WalletManager) : GlobalAction()
data class SetFiatRate(val fiatRates: Pair<String, BigDecimal>) : GlobalAction()
}

View file

@ -11,6 +11,11 @@ fun globalReducer(action: Action, state: AppState): GlobalState {
when (action) {
is GlobalAction.LoadCard -> newState = newState.copy(card = action.card)
is GlobalAction.SetFiatRate -> {
val rates = newState.fiatRates.rates.toMutableMap()
rates[action.fiatRates.first] = action.fiatRates.second
newState = newState.copy(fiatRates = FiatRates(rates))
}
is GlobalAction.LoadWalletManager ->
newState = newState.copy(walletManager = action.walletManager)

View file

@ -3,11 +3,20 @@ package com.tangem.tap.common.redux.global
import com.tangem.blockchain.common.WalletManager
import com.tangem.commands.Card
import org.rekotlin.StateType
import java.math.BigDecimal
data class GlobalState(
val card: Card? = null,
val walletManager: WalletManager? = null,
val fiatRates: FiatRates = FiatRates(emptyMap()),
) : StateType
data class FiatRates(
val rates: Map<String, BigDecimal>
) {
fun getRateForCryptoCurrency(currency: String): BigDecimal? {
return rates[currency]
}
}