Updated on 2026-08-14
This commit is contained in:
parent
40ed67b0c2
commit
0331ab04ce
3 changed files with 19 additions and 10 deletions
|
|
@ -45,13 +45,20 @@ data class WalletState(
|
|||
fun getWalletManager(currencyName: CryptoCurrencyName?): WalletManager? {
|
||||
if (currencyName == null) return null
|
||||
val walletManager = walletManagers.find { it.wallet.blockchain.currency == currencyName }
|
||||
if (walletManager != null) return walletManager
|
||||
return walletManager ?: getWalletManagerForToken(currencyName)
|
||||
}
|
||||
|
||||
fun getWalletManagerForToken(currencyName: CryptoCurrencyName?): WalletManager? {
|
||||
val ethereumWalletManager = walletManagers.find { it.wallet.blockchain == Blockchain.Ethereum }
|
||||
return if (ethereumWalletManager?.presetTokens?.find { it.symbol == currencyName } != null) {
|
||||
ethereumWalletManager
|
||||
} else {
|
||||
null
|
||||
val primaryWalletManager = walletManagers.find { it.wallet.blockchain == primaryBlockchain }
|
||||
if (primaryWalletManager?.presetTokens?.find { it.symbol == currencyName } != null) {
|
||||
primaryWalletManager
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.tangem.tap.features.wallet.redux.middlewares
|
||||
|
||||
import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.Token
|
||||
import com.tangem.blockchain.common.TokenFinder
|
||||
|
|
@ -74,8 +73,7 @@ class MultiWalletMiddleware {
|
|||
}
|
||||
|
||||
private fun addToken(token: Token, walletState: WalletState?) {
|
||||
val walletManager =
|
||||
(walletState?.getWalletManager(Blockchain.Ethereum.currency) as? EthereumWalletManager)
|
||||
val walletManager = walletState?.getWalletManager(token.symbol)
|
||||
scope.launch {
|
||||
val result = walletManager?.addToken(token)
|
||||
withContext(Dispatchers.Main) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.tangem.tap.features.wallet.redux.reducers
|
||||
|
||||
import com.tangem.blockchain.common.AmountType
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.common.extensions.isZero
|
||||
import com.tangem.tap.common.extensions.toFiatString
|
||||
import com.tangem.tap.common.extensions.toFormattedCurrencyString
|
||||
|
|
@ -76,7 +75,6 @@ class MultiWalletReducer {
|
|||
}
|
||||
is WalletAction.MultiWallet.AddTokens -> {
|
||||
if (!state.isMultiwalletAllowed) return state
|
||||
val walletAddresses = createAddressList(state.getWalletManager(Blockchain.Ethereum.currency)?.wallet)
|
||||
val wallets = action.tokens.map { token ->
|
||||
WalletData(
|
||||
currencyData = BalanceWidgetData(
|
||||
|
|
@ -84,7 +82,9 @@ class MultiWalletReducer {
|
|||
currency = token.name,
|
||||
currencySymbol = token.symbol
|
||||
),
|
||||
walletAddresses = walletAddresses,
|
||||
walletAddresses = createAddressList(
|
||||
state.getWalletManagerForToken(token.symbol)?.wallet
|
||||
),
|
||||
mainButton = WalletMainButton.SendButton(false),
|
||||
topUpState = TopUpState(allowed = false),
|
||||
token = token
|
||||
|
|
@ -94,7 +94,11 @@ class MultiWalletReducer {
|
|||
}
|
||||
is WalletAction.MultiWallet.AddToken -> {
|
||||
if (!state.isMultiwalletAllowed) return state
|
||||
val walletAddresses = createAddressList(state.getWalletManager(Blockchain.Ethereum.currency)?.wallet)
|
||||
|
||||
val walletAddresses = createAddressList(
|
||||
state.getWalletManagerForToken(action.token.symbol)?.wallet
|
||||
|
||||
)
|
||||
val wallet = WalletData(
|
||||
currencyData = BalanceWidgetData(
|
||||
BalanceStatus.Loading,
|
||||
|
|
@ -110,7 +114,7 @@ class MultiWalletReducer {
|
|||
state.copy(wallets = wallets)
|
||||
}
|
||||
is WalletAction.MultiWallet.TokenLoaded -> {
|
||||
val pendingTransactions = state.getWalletManager(Blockchain.Ethereum.currency)
|
||||
val pendingTransactions = state.getWalletManagerForToken(action.amount.currencySymbol)
|
||||
?.wallet?.let { wallet ->
|
||||
wallet.recentTransactions.toPendingTransactions(wallet.address)
|
||||
} ?: emptyList()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue