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

Show Tron inactive address warning in Token Balance #7441

Merged
merged 1 commit into from
May 14, 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 @@ -4,7 +4,10 @@ import io.horizontalsystems.bankwallet.core.AdapterState
import io.horizontalsystems.bankwallet.core.BalanceData
import io.horizontalsystems.bankwallet.core.Clearable
import io.horizontalsystems.bankwallet.core.IAdapterManager
import io.horizontalsystems.bankwallet.core.adapters.BaseTronAdapter
import io.horizontalsystems.bankwallet.entities.Wallet
import io.horizontalsystems.bankwallet.modules.balance.BalanceModule.BalanceWarning
import io.horizontalsystems.marketkit.models.BlockchainType
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -103,6 +106,16 @@ class BalanceAdapterRepository(
return adapterManager.getBalanceAdapterForWallet(wallet)?.sendAllowed() ?: false
}

suspend fun warning(wallet: Wallet): BalanceWarning? {
if (wallet.token.blockchainType is BlockchainType.Tron) {
(adapterManager.getAdapterForWallet(wallet) as? BaseTronAdapter)?.let { adapter ->
if (!adapter.isAddressActive(adapter.receiveAddress))
return BalanceWarning.TronInactiveAccountWarning
}
}
return null
}

fun refresh() {
adapterManager.refresh()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package io.horizontalsystems.bankwallet.modules.balance

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.AdapterState
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.core.BalanceData
import io.horizontalsystems.bankwallet.core.Warning
import io.horizontalsystems.bankwallet.entities.Wallet
import io.horizontalsystems.bankwallet.modules.address.AddressHandlerFactory
import io.horizontalsystems.bankwallet.modules.balance.cex.BalanceCexRepositoryWrapper
import io.horizontalsystems.bankwallet.modules.balance.cex.BalanceCexSorter
import io.horizontalsystems.bankwallet.modules.balance.cex.BalanceCexViewModel
import io.horizontalsystems.bankwallet.ui.compose.TranslatableString
import io.horizontalsystems.marketkit.models.CoinPrice

object BalanceModule {
Expand Down Expand Up @@ -70,9 +73,22 @@ object BalanceModule {
val balanceData: BalanceData,
val state: AdapterState,
val sendAllowed: Boolean,
val coinPrice: CoinPrice? = null
val coinPrice: CoinPrice?,
val warning: BalanceWarning? = null
) {
val fiatValue get() = coinPrice?.value?.let { balanceData.available.times(it) }
val balanceFiatTotal get() = coinPrice?.value?.let { balanceData.total.times(it) }
}

sealed class BalanceWarning : Warning() {
data object TronInactiveAccountWarning : BalanceWarning()
}

val BalanceWarning.warningText: WarningText
get() = when (this) {
BalanceWarning.TronInactiveAccountWarning -> WarningText(
title = TranslatableString.ResString(R.string.Tron_TokenPage_AddressNotActive_Title),
text = TranslatableString.ResString(R.string.Tron_TokenPage_AddressNotActive_Info),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.horizontalsystems.bankwallet.core.providers.Translator
import io.horizontalsystems.bankwallet.core.swappable
import io.horizontalsystems.bankwallet.entities.Currency
import io.horizontalsystems.bankwallet.entities.Wallet
import io.horizontalsystems.bankwallet.modules.balance.BalanceModule.warningText
import io.horizontalsystems.bankwallet.modules.balance.cex.BalanceCexViewItem
import io.horizontalsystems.bankwallet.ui.compose.TranslatableString
import io.horizontalsystems.core.helpers.DateHelper
Expand Down Expand Up @@ -40,7 +41,13 @@ data class BalanceViewItem(
val swapVisible: Boolean,
val swapEnabled: Boolean = false,
val errorMessage: String?,
val isWatchAccount: Boolean
val isWatchAccount: Boolean,
val warning: WarningText?
)

data class WarningText(
val title: TranslatableString,
val text: TranslatableString
)

data class LockedValue(
Expand Down Expand Up @@ -254,7 +261,8 @@ class BalanceViewItemFactory {
swapVisible = wallet.token.swappable,
swapEnabled = state is AdapterState.Synced,
errorMessage = (state as? AdapterState.NotSynced)?.error?.message,
isWatchAccount = watchAccount
isWatchAccount = watchAccount,
warning = item.warning?.warningText
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import io.horizontalsystems.bankwallet.ui.compose.components.HsBackButton
import io.horizontalsystems.bankwallet.ui.compose.components.HsIconButton
import io.horizontalsystems.bankwallet.ui.compose.components.ListEmptyView
import io.horizontalsystems.bankwallet.ui.compose.components.RowUniversal
import io.horizontalsystems.bankwallet.ui.compose.components.TextImportantWarning
import io.horizontalsystems.bankwallet.ui.compose.components.VSpacer
import io.horizontalsystems.bankwallet.ui.compose.components.body_grey
import io.horizontalsystems.bankwallet.ui.compose.components.subhead2_grey
Expand Down Expand Up @@ -200,6 +201,15 @@ private fun TokenBalanceHeader(
VSpacer(height = 24.dp)
ButtonsRow(viewItem = balanceViewItem, navController = navController, viewModel = viewModel)
LockedBalanceSection(balanceViewItem, navController)
balanceViewItem.warning?.let {
VSpacer(height = 8.dp)
TextImportantWarning(
icon = R.drawable.ic_attention_20,
title = it.title.getString(),
text = it.text.getString()
)
}
VSpacer(height = 16.dp)
}
}

Expand All @@ -221,7 +231,6 @@ private fun LockedBalanceSection(balanceViewItem: BalanceViewItem, navController
)
}
}
VSpacer(height = 18.dp)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TokenBalanceService(
private val coroutineScope = CoroutineScope(Dispatchers.Default)
val baseCurrency by xRateRepository::baseCurrency

fun start() {
suspend fun start() {
balanceAdapterRepository.setWallet(listOf(wallet))
xRateRepository.setCoinUids(listOf(wallet.coin.uid))

Expand All @@ -44,7 +44,8 @@ class TokenBalanceService(
balanceData = balanceAdapterRepository.balanceData(wallet),
state = balanceAdapterRepository.state(wallet),
sendAllowed = balanceAdapterRepository.sendAllowed(wallet),
coinPrice = latestRates[wallet.coin.uid]
coinPrice = latestRates[wallet.coin.uid],
warning = balanceAdapterRepository.warning(wallet)
)

coroutineScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ package io.horizontalsystems.bankwallet.ui.compose.components
import androidx.annotation.DrawableRes
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -75,7 +80,8 @@ fun TextImportant(
) {
if (title != null || icon != null) {
Row(
horizontalArrangement = Arrangement.spacedBy(12.dp)
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalAlignment = Alignment.CenterVertically
) {
icon?.let {
Icon(
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@
<string name="Tron_AddressNotActive_Info">Newly created accounts on the TRON blockchain are inactive and cannot be queried or explored. They need to be activated.\n\nTransferring TRX or TRC-10 tokens to an inactive account address will activate the account. Activating a new account on the Tron chain requires a fee of 1 TRX</string>
<string name="Tron_SelfSendTrxNotAllowed">Cannot transfer TRX to yourself</string>
<string name="Tron_ZeroAmountTrxNotAllowed">Cannot transfer 0 %s</string>
<string name="Tron_TokenPage_AddressNotActive_Title">Account Not Active</string>
<string name="Tron_TokenPage_AddressNotActive_Info">New TRON wallets require a deposit of at least 1 TRX to become active. Inactive wallets can hold and receive tokens but won’t correct balances until activated.</string>

<!--WalletConnect-->
<string name="WalletConnect_Title" translatable="false">WalletConnect</string>
Expand Down
Loading