Updated on 2026-08-14

This commit is contained in:
Tangem 2022-03-23 22:33:19 +03:00
parent 8d291b4095
commit 643c12023b
4 changed files with 19 additions and 7 deletions

View file

@ -57,8 +57,19 @@ class TapWalletManager {
handleUpdateWalletResult(result, walletManager)
}
suspend fun updateWallet(walletManager: WalletManager) {
val result = walletManager.safeUpdate()
suspend fun updateWallet(walletManager: WalletManager, force: Boolean) {
val result = if (force) {
walletManager.safeUpdate()
} else {
val blockchain = walletManager.wallet.blockchain
if (walletManagersThrottler.isStillThrottled(blockchain)) {
delay(200)
Result.Success(walletManager.wallet)
} else {
walletManagersThrottler.updateThrottlingTo(blockchain)
walletManager.safeUpdate()
}
}
withContext(Dispatchers.Main) {
when (result) {
is Result.Success ->

View file

@ -74,7 +74,7 @@ sealed class WalletAction : Action {
class CheckRemainingSignatures(val remainingSignatures: Int?) : Warnings()
}
data class UpdateWallet(val blockchain: Blockchain? = null) : WalletAction() {
data class UpdateWallet(val blockchain: Blockchain? = null, val force: Boolean = true) : WalletAction() {
object ScheduleUpdatingWallet : WalletAction()
data class Success(val wallet: Wallet) : WalletAction()
data class Failure(val errorMessage: String? = null) : WalletAction()

View file

@ -99,7 +99,7 @@ class WalletMiddleware {
else -> {
globalState.tapWalletManager.loadFiatRate(
fiatCurrency = globalState.appCurrency,
currencies = walletState.wallets.mapNotNull { it.currency }
currencies = walletState.wallets.map { it.currency }
)
}
}
@ -131,13 +131,13 @@ class WalletMiddleware {
if (action.blockchain != null) {
scope.launch {
val walletManager = walletState.getWalletManager(action.blockchain)
walletManager?.let { globalState.tapWalletManager.updateWallet(it) }
walletManager?.let { globalState.tapWalletManager.updateWallet(it, action.force) }
}
} else {
scope.launch {
if (walletState.state == ProgressState.Done) {
walletState.walletManagers.map { walletManager ->
globalState.tapWalletManager.updateWallet(walletManager)
globalState.tapWalletManager.updateWallet(walletManager, action.force)
}
}
}
@ -163,6 +163,7 @@ class WalletMiddleware {
)
withMainContext { actionList.forEach { store.dispatch(it) } }
}
is Result.Failure -> {}
}
store.dispatchOnMain(WalletAction.Warnings.CheckIfNeeded)
}

View file

@ -63,7 +63,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
}.select { it.walletState }
}
walletView.setFragment(this, binding)
store.dispatch(WalletAction.UpdateWallet())
store.dispatch(WalletAction.UpdateWallet(force = false))
}
override fun onStop() {