From a899db408c8e4f31e084dbcae364cda3a3fec7d6 Mon Sep 17 00:00:00 2001 From: Rafael Muhamedzyanov Date: Mon, 9 Oct 2023 15:26:58 +0600 Subject: [PATCH] Show status info for Evm, Solana, Binance chains --- app/build.gradle | 2 +- .../core/adapters/BaseEvmAdapter.kt | 3 + .../core/adapters/BaseSolanaAdapter.kt | 3 + .../settings/appstatus/AppStatusModule.kt | 4 + .../settings/appstatus/AppStatusViewModel.kt | 115 ++++++++++++------ 5 files changed, 88 insertions(+), 39 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 444a7040f64..bdd0dead572 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -271,7 +271,7 @@ dependencies { implementation 'com.github.horizontalsystems:blockchain-fee-rate-kit-android:1d3bd49' implementation 'com.github.horizontalsystems:binance-chain-kit-android:7e4d7c0' implementation 'com.github.horizontalsystems:market-kit-android:0b065d2' - implementation 'com.github.horizontalsystems:solana-kit-android:f9d9f4a' + implementation 'com.github.horizontalsystems:solana-kit-android:5cc6e81' implementation 'com.github.horizontalsystems:tron-kit-android:67f8d53' // Zcash SDK implementation "cash.z.ecc.android:zcash-android-sdk:2.0.1" diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/adapters/BaseEvmAdapter.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/adapters/BaseEvmAdapter.kt index 112f5df333e..f63f2023c39 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/adapters/BaseEvmAdapter.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/adapters/BaseEvmAdapter.kt @@ -20,6 +20,9 @@ abstract class BaseEvmAdapter( override val debugInfo: String get() = evmKit.debugInfo() + val statusInfo: Map + get() = evmKit.statusInfo() + // ISendEthereumAdapter protected fun scaleDown(amount: BigDecimal, decimals: Int = decimal): BigDecimal { diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/adapters/BaseSolanaAdapter.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/adapters/BaseSolanaAdapter.kt index 380e0b4bab8..84e5180bb14 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/adapters/BaseSolanaAdapter.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/adapters/BaseSolanaAdapter.kt @@ -17,6 +17,9 @@ abstract class BaseSolanaAdapter( override val debugInfo: String get() = solanaKit.debugInfo() + val statusInfo: Map + get() = solanaKit.statusInfo() + // IReceiveAdapter override val receiveAddress: String diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appstatus/AppStatusModule.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appstatus/AppStatusModule.kt index 393c4095579..720a837d1fc 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appstatus/AppStatusModule.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appstatus/AppStatusModule.kt @@ -16,6 +16,10 @@ object AppStatusModule { App.walletManager, App.adapterManager, App.marketKit, + App.evmBlockchainManager, + App.binanceKitManager, + App.tronKitManager, + App.solanaKitManager, ) return viewModel as T } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appstatus/AppStatusViewModel.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appstatus/AppStatusViewModel.kt index 64ed9b13902..22cad482cc6 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appstatus/AppStatusViewModel.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appstatus/AppStatusViewModel.kt @@ -10,9 +10,12 @@ import io.horizontalsystems.bankwallet.core.IAccountManager import io.horizontalsystems.bankwallet.core.IAdapterManager import io.horizontalsystems.bankwallet.core.ILocalStorage import io.horizontalsystems.bankwallet.core.IWalletManager -import io.horizontalsystems.bankwallet.core.adapters.BaseTronAdapter import io.horizontalsystems.bankwallet.core.adapters.BitcoinBaseAdapter +import io.horizontalsystems.bankwallet.core.managers.BinanceKitManager +import io.horizontalsystems.bankwallet.core.managers.EvmBlockchainManager import io.horizontalsystems.bankwallet.core.managers.MarketKitWrapper +import io.horizontalsystems.bankwallet.core.managers.SolanaKitManager +import io.horizontalsystems.bankwallet.core.managers.TronKitManager import io.horizontalsystems.bankwallet.entities.Account import io.horizontalsystems.bankwallet.modules.settings.appstatus.AppStatusModule.BlockContent import io.horizontalsystems.core.ISystemInfoManager @@ -27,7 +30,11 @@ class AppStatusViewModel( private val accountManager: IAccountManager, private val walletManager: IWalletManager, private val adapterManager: IAdapterManager, - private val marketKit: MarketKitWrapper + private val marketKit: MarketKitWrapper, + private val evmBlockchainManager: EvmBlockchainManager, + private val binanceKitManager: BinanceKitManager, + private val tronKitManager: TronKitManager, + private val solanaKitManager: SolanaKitManager, ) : ViewModel() { private var blockViewItems: List = emptyList() @@ -157,7 +164,7 @@ class AppStatusViewModel( private fun getBlockchainStatus(): Map { val blockchainStatus = LinkedHashMap() - val blockchainTypesToDisplay = + val bitcoinLikeChains = listOf( BlockchainType.Bitcoin, BlockchainType.BitcoinCash, @@ -167,7 +174,7 @@ class AppStatusViewModel( ) walletManager.activeWallets - .filter { blockchainTypesToDisplay.contains(it.token.blockchainType) } + .filter { bitcoinLikeChains.contains(it.token.blockchainType) } .sortedBy { it.token.coin.name } .forEach { wallet -> (adapterManager.getAdapterForWallet(wallet) as? BitcoinBaseAdapter)?.let { adapter -> @@ -176,17 +183,31 @@ class AppStatusViewModel( } } - walletManager.activeWallets.firstOrNull { it.token.blockchainType == BlockchainType.Tron }?.let { wallet -> - (adapterManager.getAdapterForWallet(wallet) as? BaseTronAdapter)?.statusInfo?.let { statusInfo -> - blockchainStatus["Tron"] = statusInfo + evmBlockchainManager.allBlockchains + .forEach { blockchain -> + evmBlockchainManager.getEvmKitManager(blockchain.type).statusInfo?.let { statusInfo -> + blockchainStatus[blockchain.name] = statusInfo + } } + + binanceKitManager.statusInfo?.let { statusInfo -> + blockchainStatus["Binance Chain"] = statusInfo + } + + tronKitManager.statusInfo?.let { statusInfo -> + blockchainStatus["Tron"] = statusInfo } + + solanaKitManager.statusInfo?.let { statusInfo -> + blockchainStatus["Solana"] = statusInfo + } + return blockchainStatus } private fun getBlockchainStatusBlock(): List { val blocks = mutableListOf() - val blockchainTypesToDisplay = + val bitcoinLikeChains = listOf( BlockchainType.Bitcoin, BlockchainType.BitcoinCash, @@ -195,50 +216,68 @@ class AppStatusViewModel( BlockchainType.ECash, ) - var sectionTitleNotSet = true - walletManager.activeWallets - .filter { blockchainTypesToDisplay.contains(it.token.blockchainType) } + .filter { bitcoinLikeChains.contains(it.token.blockchainType) } .sortedBy { it.token.coin.name } - .forEach { wallet -> - val title = if (sectionTitleNotSet) "Blockchain Status" else null - (adapterManager.getAdapterForWallet(wallet) as? BitcoinBaseAdapter)?.let { adapter -> - val statusTitle = "${wallet.token.coin.name}${wallet.badge?.let { "-$it" } ?: ""}" - - val item = AppStatusModule.BlockData( + .forEach { + val wallet = it + val title = if (blocks.isEmpty()) "Blockchain Status" else null + val block = when (val adapter = adapterManager.getAdapterForWallet(wallet)) { + is BitcoinBaseAdapter -> getBlockchainInfoBlock( title, - listOf( - BlockContent.TitleValue("Blockchain", statusTitle), - BlockContent.Text(formatMapToString(adapter.statusInfo)?.trimEnd() ?: ""), - ) + "${wallet.token.coin.name}${wallet.badge?.let { "-$it" } ?: ""}", + adapter.statusInfo ) - blocks.add(item) - if (sectionTitleNotSet) { - sectionTitleNotSet = false - } + + else -> null } + block?.let { blocks.add(it) } } - walletManager.activeWallets.firstOrNull { it.token.blockchainType == BlockchainType.Tron }?.let { wallet -> - val title = if (sectionTitleNotSet) "Blockchain Status" else null - (adapterManager.getAdapterForWallet(wallet) as? BaseTronAdapter)?.statusInfo?.let { statusInfo -> - val item = AppStatusModule.BlockData( - title, - listOf( - BlockContent.TitleValue("Blockchain", "Tron"), - BlockContent.Text(formatMapToString(statusInfo)?.trimEnd() ?: ""), - ) - ) - blocks.add(item) - if (sectionTitleNotSet) { - sectionTitleNotSet = false + evmBlockchainManager.allBlockchains + .forEach { blockchain -> + evmBlockchainManager.getEvmKitManager(blockchain.type).statusInfo?.let { statusInfo -> + val title = if (blocks.isEmpty()) "Blockchain Status" else null + val block = getBlockchainInfoBlock(title, blockchain.name, statusInfo) + blocks.add(block) } } + + binanceKitManager.statusInfo?.let { statusInfo -> + val title = if (blocks.isEmpty()) "Blockchain Status" else null + val block = getBlockchainInfoBlock(title, "Binance Chain", statusInfo) + blocks.add(block) + } + + tronKitManager.statusInfo?.let { statusInfo -> + val title = if (blocks.isEmpty()) "Blockchain Status" else null + val block = getBlockchainInfoBlock(title, "Tron", statusInfo) + blocks.add(block) + } + + solanaKitManager.statusInfo?.let { + val title = if (blocks.isEmpty()) "Blockchain Status" else null + val block = getBlockchainInfoBlock(title, "Solana", it) + blocks.add(block) } return blocks } + fun getBlockchainInfoBlock( + title: String?, + blockchain: String, + statusInfo: Map + ): AppStatusModule.BlockData { + return AppStatusModule.BlockData( + title, + listOf( + BlockContent.TitleValue("Blockchain", blockchain), + BlockContent.Text(formatMapToString(statusInfo)?.trimEnd() ?: ""), + ) + ) + } + private fun getMarketLastSyncTimestamps(): Map { val syncInfo = marketKit.syncInfo() val info = LinkedHashMap()