Updated on 2026-08-14

This commit is contained in:
Tangem 2023-09-21 18:19:46 +03:00
parent eaba6ee88d
commit 613e07734e

View file

@ -31,6 +31,7 @@ import com.tangem.tap.features.send.redux.SendAction
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.redux.WalletAction
import com.tangem.tap.features.wallet.redux.WalletState
import com.tangem.tap.features.wallet.redux.models.WalletDialog
import com.tangem.tap.network.exchangeServices.CurrencyExchangeManager
import com.tangem.tap.network.exchangeServices.buyErc20TestnetTokens
import com.tangem.tap.proxy.redux.DaggerGraphState
@ -120,14 +121,32 @@ class TradeCryptoMiddleware {
private fun proceedNewBuyAction(state: () -> AppState?, action: TradeCryptoAction.New.Buy) {
val networkAddress = action.cryptoCurrencyStatus.value.networkAddress?.defaultAddress ?: return
if (action.checkUserLocation && state()?.globalState?.userCountryCode == RUSSIA_COUNTRY_CODE) {
store.dispatchOnMain(WalletAction.DialogAction.RussianCardholdersWarningDialog())
return
}
val status = action.cryptoCurrencyStatus
val currency = status.currency
val blockchain = Blockchain.fromId(currency.network.id.value)
val exchangeManager = store.state.globalState.exchangeManager
val topUrl = exchangeManager.getUrl(
action = CurrencyExchangeManager.Action.Buy,
blockchain = blockchain,
cryptoCurrencyName = currency.symbol,
fiatCurrencyName = action.appCurrencyCode,
walletAddress = networkAddress,
)
if (action.checkUserLocation && state()?.globalState?.userCountryCode == RUSSIA_COUNTRY_CODE) {
val dialogData = topUrl?.let {
WalletDialog.RussianCardholdersWarningDialog.Data(
topUpUrl = it,
)
}
store.dispatchOnMain(
WalletAction.DialogAction.RussianCardholdersWarningDialog(
dialogData = dialogData,
),
)
return
}
if (currency is CryptoCurrency.Token && currency.network.isTestnet) {
scope.launch {
val walletManager = store.state.daggerGraphState
@ -152,14 +171,7 @@ class TradeCryptoMiddleware {
return
}
val exchangeManager = store.state.globalState.exchangeManager
exchangeManager.getUrl(
action = CurrencyExchangeManager.Action.Buy,
blockchain = blockchain,
cryptoCurrencyName = currency.symbol,
fiatCurrencyName = action.appCurrencyCode,
walletAddress = networkAddress,
)?.let {
topUrl?.let {
store.dispatchOpenUrl(it)
Analytics.send(Token.Topup.ScreenOpened())
}