Skip to content

Commit

Permalink
Show status info for Evm, Solana, Binance chains
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Oct 9, 2023
1 parent 203530b commit a899db4
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ abstract class BaseEvmAdapter(
override val debugInfo: String
get() = evmKit.debugInfo()

val statusInfo: Map<String, Any>
get() = evmKit.statusInfo()

// ISendEthereumAdapter

protected fun scaleDown(amount: BigDecimal, decimals: Int = decimal): BigDecimal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ abstract class BaseSolanaAdapter(
override val debugInfo: String
get() = solanaKit.debugInfo()

val statusInfo: Map<String, Any>
get() = solanaKit.statusInfo()

// IReceiveAdapter

override val receiveAddress: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ object AppStatusModule {
App.walletManager,
App.adapterManager,
App.marketKit,
App.evmBlockchainManager,
App.binanceKitManager,
App.tronKitManager,
App.solanaKitManager,
)
return viewModel as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<AppStatusModule.BlockData> = emptyList()
Expand Down Expand Up @@ -157,7 +164,7 @@ class AppStatusViewModel(

private fun getBlockchainStatus(): Map<String, Any> {
val blockchainStatus = LinkedHashMap<String, Any>()
val blockchainTypesToDisplay =
val bitcoinLikeChains =
listOf(
BlockchainType.Bitcoin,
BlockchainType.BitcoinCash,
Expand All @@ -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 ->
Expand All @@ -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<AppStatusModule.BlockData> {
val blocks = mutableListOf<AppStatusModule.BlockData>()
val blockchainTypesToDisplay =
val bitcoinLikeChains =
listOf(
BlockchainType.Bitcoin,
BlockchainType.BitcoinCash,
Expand All @@ -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<String, Any>
): AppStatusModule.BlockData {
return AppStatusModule.BlockData(
title,
listOf(
BlockContent.TitleValue("Blockchain", blockchain),
BlockContent.Text(formatMapToString(statusInfo)?.trimEnd() ?: ""),
)
)
}

private fun getMarketLastSyncTimestamps(): Map<String, Any> {
val syncInfo = marketKit.syncInfo()
val info = LinkedHashMap<String, Any>()
Expand Down

0 comments on commit a899db4

Please sign in to comment.