Skip to content

Commit

Permalink
Fix updating of account active state for Tron
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Feb 21, 2024
1 parent 3ba1dd6 commit c2eb452
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ dependencies {
implementation 'com.github.horizontalsystems:binance-chain-kit-android:c1509a2'
implementation 'com.github.horizontalsystems:market-kit-android:2efec77'
implementation 'com.github.horizontalsystems:solana-kit-android:6401968'
implementation 'com.github.horizontalsystems:tron-kit-android:f2f7c9a'
implementation 'com.github.horizontalsystems:tron-kit-android:2e64640'
// Zcash SDK
implementation "cash.z.ecc.android:zcash-android-sdk:2.0.1"
implementation("io.github.binance:binance-connector-java:3.0.0rc2") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,9 @@ interface IReceiveAdapter {
val receiveAddress: String
val isMainNet: Boolean

val isAccountActive: Boolean
get() = true
suspend fun isAddressActive(address: String): Boolean {
return true
}

fun usedAddresses(change: Boolean): List<UsedAddress> {
return listOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ abstract class BaseTronAdapter(

// IReceiveAdapter

override val isAccountActive: Boolean
get() = tronKit.isAccountActive
override suspend fun isAddressActive(address: String): Boolean {
val tronAddress = Address.fromBase58(address)
return tronKit.isAccountActive(tronAddress)
}

override val receiveAddress: String
get() = tronKit.address.base58

override val isMainNet: Boolean
get() = tronKit.network == Network.Mainnet

// ISendTronAdapter

suspend fun isAddressActive(address: Address): Boolean = withContext(Dispatchers.IO) {
tronKit.isAccountActive(address)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import io.horizontalsystems.bankwallet.entities.Wallet
import io.horizontalsystems.bankwallet.modules.receive.ReceiveModule
import io.horizontalsystems.bankwallet.modules.receive.ReceiveModule.AdditionalData
import io.horizontalsystems.marketkit.models.TokenType
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.reactive.asFlow
import kotlinx.coroutines.withContext
import java.math.BigDecimal

class ReceiveAddressViewModel(
Expand Down Expand Up @@ -57,13 +59,15 @@ class ReceiveAddressViewModel(
private set

init {
viewModelScope.launch {
viewModelScope.launch(Dispatchers.IO) {
adapterManager.adaptersReadyObservable.asFlow()
.collect {
setData()
}
}
setData()
viewModelScope.launch(Dispatchers.IO) {
setData()
}
setNetworkName()
}

Expand Down Expand Up @@ -97,20 +101,22 @@ class ReceiveAddressViewModel(
else null
}

private fun setData() {
private suspend fun setData() {
val adapter = adapterManager.getReceiveAdapterForWallet(wallet)
if (adapter != null) {
address = adapter.receiveAddress
usedAddresses = adapter.usedAddresses(false)
usedChangeAddresses = adapter.usedAddresses(true)
uri = getUri()
accountActive = adapter.isAccountActive
accountActive = adapter.isAddressActive(adapter.receiveAddress)
mainNet = adapter.isMainNet
viewState = ViewState.Success
} else {
viewState = ViewState.Error(NullPointerException())
}
syncState()
withContext(Dispatchers.Main) {
syncState()
}
}

private fun getUri(): String {
Expand Down Expand Up @@ -164,7 +170,9 @@ class ReceiveAddressViewModel(
}

fun onErrorClick() {
setData()
viewModelScope.launch(Dispatchers.IO) {
setData()
}
}

fun setAmount(amount: BigDecimal?) {
Expand Down

0 comments on commit c2eb452

Please sign in to comment.