Updated on 2026-08-14

This commit is contained in:
Tangem 2023-04-13 15:10:55 +03:00
parent 4c9a1af7c4
commit 8751486283
4 changed files with 43 additions and 7 deletions

View file

@ -0,0 +1,36 @@
package com.tangem.tap.common.utils
import android.os.Handler
import android.os.Looper
import org.rekotlin.StoreSubscriber
private val mainLooper by lazy { Looper.getMainLooper() }
private val mainHandler by lazy { Handler(mainLooper) }
/**
* A subscriber interface for safely subscribing to state changes in a Store.
*
* @param State the type of the state in the Store
*/
interface SafeStoreSubscriber<State> : StoreSubscriber<State> {
/**
* A function that will be called when the state in the Store changes.
*
* @param state the new state in the Store
*/
override fun newState(state: State) {
if (Thread.currentThread() != mainLooper.thread) {
mainHandler.post { newStateOnMain(state) }
} else {
newStateOnMain(state)
}
}
/**
* A function that will be called on the main thread when the state in the Store changes.
*
* @param state the new state in the Store
*/
fun newStateOnMain(state: State)
}

View file

@ -41,6 +41,7 @@ import com.tangem.tap.common.extensions.show
import com.tangem.tap.common.extensions.toQrCode
import com.tangem.tap.common.recyclerView.SpaceItemDecoration
import com.tangem.tap.common.redux.navigation.NavigationAction
import com.tangem.tap.common.utils.SafeStoreSubscriber
import com.tangem.tap.domain.model.WalletDataModel
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.models.PendingTransaction
@ -72,7 +73,6 @@ import com.tangem.wallet.databinding.FragmentWalletDetailsBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.rekotlin.StoreSubscriber
import timber.log.Timber
import javax.inject.Inject
@ -80,7 +80,7 @@ import javax.inject.Inject
@AndroidEntryPoint
class WalletDetailsFragment :
Fragment(R.layout.fragment_wallet_details),
StoreSubscriber<WalletState> {
SafeStoreSubscriber<WalletState> {
@Inject
lateinit var swapInteractor: SwapInteractor
@ -227,7 +227,7 @@ class WalletDetailsFragment :
}
}
override fun newState(state: WalletState) {
override fun newStateOnMain(state: WalletState) {
if (activity == null || view == null) return
if (state.selectedWalletData == null) return
walletStateWatcher.invoke(state)

View file

@ -28,6 +28,7 @@ import com.tangem.tap.common.recyclerView.SpaceItemDecoration
import com.tangem.tap.common.redux.global.GlobalAction
import com.tangem.tap.common.redux.navigation.AppScreen
import com.tangem.tap.common.redux.navigation.NavigationAction
import com.tangem.tap.common.utils.SafeStoreSubscriber
import com.tangem.tap.domain.configurable.warningMessage.WarningMessage
import com.tangem.tap.domain.statePrinter.printScanResponseState
import com.tangem.tap.domain.statePrinter.printWalletState
@ -46,11 +47,10 @@ import com.tangem.wallet.BuildConfig
import com.tangem.wallet.R
import com.tangem.wallet.databinding.FragmentWalletBinding
import dagger.hilt.android.AndroidEntryPoint
import org.rekotlin.StoreSubscriber
import javax.inject.Inject
@AndroidEntryPoint
class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<WalletState> {
class WalletFragment : Fragment(R.layout.fragment_wallet), SafeStoreSubscriber<WalletState> {
@Inject
lateinit var swapInteractor: SwapInteractor
@ -148,7 +148,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
}
@Suppress("ComplexMethod")
override fun newState(state: WalletState) {
override fun newStateOnMain(state: WalletState) {
if (activity == null || view == null) return
val isSaltPay = store.state.globalState.scanResponse?.cardTypesResolver?.isSaltPay() == true

View file

@ -60,7 +60,7 @@ retrofitMoshiConverter = "2.6.0"
shopifyBuySdk = "12.0.0"
spongycastleCryptoCore = "1.58.0.0"
timber = "4.7.1"
viewBindingDelegate = "1.5.6"
viewBindingDelegate = "1.5.9"
xmlShimmer = "1.1.3"
zendeskChat = "3.3.5"
zendeskMessaging = "5.2.4"