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? {
|
fun getWalletManager(currencyName: CryptoCurrencyName?): WalletManager? {
|
||||||
if (currencyName == null) return null
|
if (currencyName == null) return null
|
||||||
val walletManager = walletManagers.find { it.wallet.blockchain.currency == currencyName }
|
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 }
|
val ethereumWalletManager = walletManagers.find { it.wallet.blockchain == Blockchain.Ethereum }
|
||||||
return if (ethereumWalletManager?.presetTokens?.find { it.symbol == currencyName } != null) {
|
return if (ethereumWalletManager?.presetTokens?.find { it.symbol == currencyName } != null) {
|
||||||
ethereumWalletManager
|
ethereumWalletManager
|
||||||
} else {
|
} 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
|
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.Blockchain
|
||||||
import com.tangem.blockchain.common.Token
|
import com.tangem.blockchain.common.Token
|
||||||
import com.tangem.blockchain.common.TokenFinder
|
import com.tangem.blockchain.common.TokenFinder
|
||||||
|
|
@ -74,8 +73,7 @@ class MultiWalletMiddleware {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addToken(token: Token, walletState: WalletState?) {
|
private fun addToken(token: Token, walletState: WalletState?) {
|
||||||
val walletManager =
|
val walletManager = walletState?.getWalletManager(token.symbol)
|
||||||
(walletState?.getWalletManager(Blockchain.Ethereum.currency) as? EthereumWalletManager)
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val result = walletManager?.addToken(token)
|
val result = walletManager?.addToken(token)
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.tangem.tap.features.wallet.redux.reducers
|
package com.tangem.tap.features.wallet.redux.reducers
|
||||||
|
|
||||||
import com.tangem.blockchain.common.AmountType
|
import com.tangem.blockchain.common.AmountType
|
||||||
import com.tangem.blockchain.common.Blockchain
|
|
||||||
import com.tangem.common.extensions.isZero
|
import com.tangem.common.extensions.isZero
|
||||||
import com.tangem.tap.common.extensions.toFiatString
|
import com.tangem.tap.common.extensions.toFiatString
|
||||||
import com.tangem.tap.common.extensions.toFormattedCurrencyString
|
import com.tangem.tap.common.extensions.toFormattedCurrencyString
|
||||||
|
|
@ -76,7 +75,6 @@ class MultiWalletReducer {
|
||||||
}
|
}
|
||||||
is WalletAction.MultiWallet.AddTokens -> {
|
is WalletAction.MultiWallet.AddTokens -> {
|
||||||
if (!state.isMultiwalletAllowed) return state
|
if (!state.isMultiwalletAllowed) return state
|
||||||
val walletAddresses = createAddressList(state.getWalletManager(Blockchain.Ethereum.currency)?.wallet)
|
|
||||||
val wallets = action.tokens.map { token ->
|
val wallets = action.tokens.map { token ->
|
||||||
WalletData(
|
WalletData(
|
||||||
currencyData = BalanceWidgetData(
|
currencyData = BalanceWidgetData(
|
||||||
|
|
@ -84,7 +82,9 @@ class MultiWalletReducer {
|
||||||
currency = token.name,
|
currency = token.name,
|
||||||
currencySymbol = token.symbol
|
currencySymbol = token.symbol
|
||||||
),
|
),
|
||||||
walletAddresses = walletAddresses,
|
walletAddresses = createAddressList(
|
||||||
|
state.getWalletManagerForToken(token.symbol)?.wallet
|
||||||
|
),
|
||||||
mainButton = WalletMainButton.SendButton(false),
|
mainButton = WalletMainButton.SendButton(false),
|
||||||
topUpState = TopUpState(allowed = false),
|
topUpState = TopUpState(allowed = false),
|
||||||
token = token
|
token = token
|
||||||
|
|
@ -94,7 +94,11 @@ class MultiWalletReducer {
|
||||||
}
|
}
|
||||||
is WalletAction.MultiWallet.AddToken -> {
|
is WalletAction.MultiWallet.AddToken -> {
|
||||||
if (!state.isMultiwalletAllowed) return state
|
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(
|
val wallet = WalletData(
|
||||||
currencyData = BalanceWidgetData(
|
currencyData = BalanceWidgetData(
|
||||||
BalanceStatus.Loading,
|
BalanceStatus.Loading,
|
||||||
|
|
@ -110,7 +114,7 @@ class MultiWalletReducer {
|
||||||
state.copy(wallets = wallets)
|
state.copy(wallets = wallets)
|
||||||
}
|
}
|
||||||
is WalletAction.MultiWallet.TokenLoaded -> {
|
is WalletAction.MultiWallet.TokenLoaded -> {
|
||||||
val pendingTransactions = state.getWalletManager(Blockchain.Ethereum.currency)
|
val pendingTransactions = state.getWalletManagerForToken(action.amount.currencySymbol)
|
||||||
?.wallet?.let { wallet ->
|
?.wallet?.let { wallet ->
|
||||||
wallet.recentTransactions.toPendingTransactions(wallet.address)
|
wallet.recentTransactions.toPendingTransactions(wallet.address)
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue