Updated on 2026-08-14
This commit is contained in:
parent
e03f078120
commit
a3cc0001f4
34 changed files with 489 additions and 283 deletions
|
|
@ -1,9 +1,9 @@
|
|||
package com.tangem.tap.common.redux
|
||||
|
||||
import com.tangem.tap.common.redux.global.globalReducer
|
||||
import com.tangem.tap.common.redux.navigation.navigationReducer
|
||||
import com.tangem.tap.common.redux.navigation.NavigationReducer
|
||||
import com.tangem.tap.features.send.redux.SendReducer
|
||||
import com.tangem.tap.features.wallet.redux.walletReducer
|
||||
import com.tangem.tap.features.wallet.redux.WalletReducer
|
||||
import org.rekotlin.Action
|
||||
|
||||
fun appReducer(action: Action, state: AppState?): AppState {
|
||||
|
|
@ -11,9 +11,9 @@ fun appReducer(action: Action, state: AppState?): AppState {
|
|||
if (action is AppAction.RestoreState) return action.state
|
||||
|
||||
return AppState(
|
||||
navigationState = navigationReducer(action, state),
|
||||
navigationState = NavigationReducer.reduce(action, state),
|
||||
globalState = globalReducer(action, state),
|
||||
walletState = walletReducer(action, state),
|
||||
walletState = WalletReducer.reduce(action, state),
|
||||
sendState = SendReducer.reduce(action, state.sendState)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
package com.tangem.tap.common.redux.global
|
||||
|
||||
import com.tangem.blockchain.common.WalletManager
|
||||
import com.tangem.commands.Card
|
||||
import com.tangem.tap.domain.tasks.ScanNoteResponse
|
||||
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 SaveScanNoteResponse(val scanNoteResponse: ScanNoteResponse) : GlobalAction()
|
||||
data class SetFiatRate(val fiatRates: Pair<String, BigDecimal>) : GlobalAction()
|
||||
}
|
||||
|
|
@ -10,15 +10,13 @@ fun globalReducer(action: Action, state: AppState): GlobalState {
|
|||
var newState = state.globalState
|
||||
|
||||
when (action) {
|
||||
is GlobalAction.LoadCard -> newState = newState.copy(card = action.card)
|
||||
is GlobalAction.SaveScanNoteResponse ->
|
||||
newState = newState.copy(scanNoteResponse = action.scanNoteResponse)
|
||||
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)
|
||||
|
||||
}
|
||||
return newState
|
||||
}
|
||||
|
|
@ -1,14 +1,12 @@
|
|||
package com.tangem.tap.common.redux.global
|
||||
|
||||
import com.tangem.blockchain.common.WalletManager
|
||||
import com.tangem.commands.Card
|
||||
import com.tangem.tap.domain.TapWalletManager
|
||||
import com.tangem.tap.domain.tasks.ScanNoteResponse
|
||||
import org.rekotlin.StateType
|
||||
import java.math.BigDecimal
|
||||
|
||||
data class GlobalState(
|
||||
val card: Card? = null,
|
||||
val walletManager: WalletManager? = null,
|
||||
val scanNoteResponse: ScanNoteResponse? = null,
|
||||
val tapWalletManager: TapWalletManager = TapWalletManager(),
|
||||
val fiatRates: FiatRates = FiatRates(emptyMap()),
|
||||
) : StateType
|
||||
|
|
|
|||
|
|
@ -4,7 +4,13 @@ import com.tangem.tap.common.extensions.getPreviousScreen
|
|||
import com.tangem.tap.common.redux.AppState
|
||||
import org.rekotlin.Action
|
||||
|
||||
fun navigationReducer(action: Action, state: AppState): NavigationState {
|
||||
class NavigationReducer {
|
||||
companion object {
|
||||
fun reduce(action: Action, state: AppState): NavigationState = internalReduce(action, state)
|
||||
}
|
||||
}
|
||||
|
||||
private fun internalReduce(action: Action, state: AppState): NavigationState {
|
||||
|
||||
val navigationAction = action as? NavigationAction ?: return state.navigationState
|
||||
val navState = state.navigationState
|
||||
|
|
@ -15,7 +21,7 @@ fun navigationReducer(action: Action, state: AppState): NavigationState {
|
|||
}
|
||||
is NavigationAction.PopBackTo -> {
|
||||
val screen =
|
||||
navigationAction.screen ?: navState.activity?.get()?.getPreviousScreen()
|
||||
navigationAction.screen ?: navState.activity?.get()?.getPreviousScreen()
|
||||
val index = navState.backStack.lastIndexOf(screen) + 1
|
||||
state.navigationState.copy(backStack = navState.backStack.subList(0, index))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue