Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Etherscan requests optimization #7687

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package io.horizontalsystems.bankwallet.core.managers

import android.os.Handler
import android.os.Looper
import android.util.Log
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.core.UnsupportedAccountException
import io.horizontalsystems.bankwallet.core.supportedNftTypes
import io.horizontalsystems.bankwallet.entities.Account
import io.horizontalsystems.bankwallet.entities.AccountType
import io.horizontalsystems.core.BackgroundManager
Expand All @@ -20,7 +20,6 @@ import io.horizontalsystems.ethereumkit.models.RpcSource
import io.horizontalsystems.ethereumkit.models.TransactionData
import io.horizontalsystems.marketkit.models.BlockchainType
import io.horizontalsystems.nftkit.core.NftKit
import io.horizontalsystems.nftkit.models.NftType
import io.horizontalsystems.oneinchkit.OneInchKit
import io.horizontalsystems.uniswapkit.TokenFactory.UnsupportedChainError
import io.horizontalsystems.uniswapkit.UniswapKit
Expand Down Expand Up @@ -145,24 +144,25 @@ class EvmKitManager(
}
OneInchKit.addDecorators(evmKit)

var nftKit: NftKit? = null
val supportedNftTypes = blockchainType.supportedNftTypes
if (supportedNftTypes.isNotEmpty()) {
val nftKitInstance = NftKit.getInstance(App.instance, evmKit)
supportedNftTypes.forEach {
when (it) {
NftType.Eip721 -> {
nftKitInstance.addEip721TransactionSyncer()
nftKitInstance.addEip721Decorators()
}
NftType.Eip1155 -> {
nftKitInstance.addEip1155TransactionSyncer()
nftKitInstance.addEip1155Decorators()
}
}
}
nftKit = nftKitInstance
}
val nftKit: NftKit? = null
// var nftKit: NftKit? = null
// val supportedNftTypes = blockchainType.supportedNftTypes
// if (supportedNftTypes.isNotEmpty()) {
// val nftKitInstance = NftKit.getInstance(App.instance, evmKit)
// supportedNftTypes.forEach {
// when (it) {
// NftType.Eip721 -> {
// nftKitInstance.addEip721TransactionSyncer()
// nftKitInstance.addEip721Decorators()
// }
// NftType.Eip1155 -> {
// nftKitInstance.addEip1155TransactionSyncer()
// nftKitInstance.addEip1155Decorators()
// }
// }
// }
// nftKit = nftKitInstance
// }

evmKit.start()

Expand All @@ -175,6 +175,7 @@ class EvmKitManager(
useCount -= 1

if (useCount < 1) {
Log.d("AAA", "stopEvmKit()")
stopEvmKit()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,37 @@ class NftAdapterManager(

@Synchronized
private fun initAdapters(wallets: List<Wallet>) {
val currentAdapters = adaptersMap.toMap()
val currentAdapters = adaptersMap.toMutableMap()
adaptersMap.clear()

val nftKeys = wallets.map { NftKey(it.account, it.token.blockchainType) }.distinct()

for (nftKey in nftKeys) {
if (nftKey.blockchainType.supportedNftTypes.isEmpty()) continue

val adapter = currentAdapters[nftKey]
val adapter = currentAdapters.remove(nftKey)

if (adapter != null) {
adaptersMap[nftKey] = adapter
} else if (evmBlockchainManager.getBlockchain(nftKey.blockchainType) != null) {
val evmKitWrapper =
evmBlockchainManager.getEvmKitManager(nftKey.blockchainType).getEvmKitWrapper(nftKey.account, nftKey.blockchainType)
val evmKitManager = evmBlockchainManager.getEvmKitManager(nftKey.blockchainType)
val evmKitWrapper = evmKitManager.getEvmKitWrapper(nftKey.account, nftKey.blockchainType)

evmKitWrapper.nftKit?.let { nftKit ->
val nftKit = evmKitWrapper.nftKit
if (nftKit != null) {
adaptersMap[nftKey] = EvmNftAdapter(nftKey.blockchainType, nftKit, evmKitWrapper.evmKit.receiveAddress)
} else {
evmKitManager.unlink(nftKey.account)
}
} else {
// Init other blockchain adapter here (e.g. Solana)
}
}

currentAdapters.forEach { (nftKey, _) ->
evmBlockchainManager.getEvmKitManager(nftKey.blockchainType).unlink(nftKey.account)
}

_adaptersUpdatedFlow.update { adaptersMap.toMap() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,13 @@ private fun getFactory(nftUidString: String): SendNftModule.Factory? {

val evmNftRecord = (nftRecord as? EvmNftRecord) ?: return null

val evmKitWrapper = App.evmBlockchainManager
.getEvmKitManager(nftUid.blockchainType)
.getEvmKitWrapper(account, nftUid.blockchainType)

return SendNftModule.Factory(
evmNftRecord,
nftUid,
nftRecord.balance,
adapter,
SendEvmAddressService(),
App.nftMetadataManager,
evmKitWrapper
App.nftMetadataManager
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.horizontalsystems.bankwallet.modules.nft.send
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import io.horizontalsystems.bankwallet.core.adapters.nft.INftAdapter
import io.horizontalsystems.bankwallet.core.managers.EvmKitWrapper
import io.horizontalsystems.bankwallet.core.managers.NftMetadataManager
import io.horizontalsystems.bankwallet.core.utils.AddressUriParser
import io.horizontalsystems.bankwallet.entities.DataState
Expand All @@ -21,8 +20,7 @@ object SendNftModule {
val nftBalance: Int,
private val adapter: INftAdapter,
private val sendEvmAddressService: SendEvmAddressService,
private val nftMetadataManager: NftMetadataManager,
private val evmKitWrapper: EvmKitWrapper
private val nftMetadataManager: NftMetadataManager
) : ViewModelProvider.Factory {

override fun <T : ViewModel> create(modelClass: Class<T>): T {
Expand Down
Loading