Updated on 2026-08-14
This commit is contained in:
commit
fd6a8ccc71
8 changed files with 93 additions and 35 deletions
|
|
@ -0,0 +1,23 @@
|
|||
package com.tangem.tap.domain
|
||||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import org.stellar.sdk.requests.ErrorResponse
|
||||
|
||||
|
||||
fun Blockchain.isNoAccountError(exception: Throwable): Boolean {
|
||||
return when (this) {
|
||||
Blockchain.Stellar -> {
|
||||
(exception is ErrorResponse) && (exception.code == 404)
|
||||
}
|
||||
Blockchain.XRP -> exception.message?.contains("Account not found") == true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
fun Blockchain.amountToCreateAccount(): Int? {
|
||||
return when (this) {
|
||||
Blockchain.Stellar -> 1
|
||||
Blockchain.XRP -> 20
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package com.tangem.tap.domain
|
||||
|
||||
class BlockchainManager {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ class TapWalletManager {
|
|||
suspend fun loadWalletData() {
|
||||
val walletManager = store.state.globalState.walletManager
|
||||
if (walletManager == null) {
|
||||
store.dispatch(WalletAction.LoadWallet.Failure)
|
||||
store.dispatch(WalletAction.LoadWallet.Failure())
|
||||
return
|
||||
}
|
||||
updateWallet(walletManager)
|
||||
|
|
@ -69,20 +69,30 @@ class TapWalletManager {
|
|||
} catch (exception: Exception) {
|
||||
Result.Failure(exception)
|
||||
}
|
||||
handleUpdateWalletResult(result)
|
||||
handleUpdateWalletResult(result, walletManager)
|
||||
}
|
||||
|
||||
private suspend fun handleUpdateWalletResult(result: Result<Wallet>) {
|
||||
private suspend fun handleUpdateWalletResult(result: Result<Wallet>, walletManager: WalletManager) {
|
||||
withContext(Dispatchers.Main) {
|
||||
when (result) {
|
||||
is Result.Success -> store.dispatch(WalletAction.LoadWallet.Success(result.data))
|
||||
is Result.Failure -> store.dispatch(WalletAction.LoadWallet.Failure)
|
||||
is Result.Failure -> {
|
||||
val error = result.error
|
||||
val blockchain = walletManager.wallet.blockchain
|
||||
if (error != null && blockchain.isNoAccountError(error)) {
|
||||
val amountToCreateAccount = blockchain.amountToCreateAccount()
|
||||
if (amountToCreateAccount != null) {
|
||||
store.dispatch(WalletAction.LoadWallet.NoAccount(amountToCreateAccount))
|
||||
return@withContext
|
||||
}
|
||||
}
|
||||
store.dispatch(WalletAction.LoadWallet.Failure(result.error?.localizedMessage))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private suspend fun loadPayIdIfNeeded(): Result<String?>? {
|
||||
if (!TapConfig.usePayId ||
|
||||
store.state.walletState.payIdData.payIdState == PayIdState.Disabled ||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ import org.rekotlin.Action
|
|||
import java.math.BigDecimal
|
||||
|
||||
sealed class WalletAction : Action {
|
||||
|
||||
object LoadWallet : WalletAction() {
|
||||
data class Success(val wallet: Wallet): WalletAction()
|
||||
object Failure: WalletAction()
|
||||
data class NoAccount(val amountToCreateAccount: Int): WalletAction()
|
||||
data class Failure(val errorMessage: String? = null): WalletAction()
|
||||
}
|
||||
object LoadFiatRate : WalletAction() {
|
||||
data class Success(val fiatRates: Pair<String, BigDecimal>) : WalletAction()
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ fun walletReducer(action: Action, state: AppState): WalletState {
|
|||
state = ProgressState.Done, wallet = action.wallet,
|
||||
currencyData = BalanceWidgetData(
|
||||
BalanceStatus.VerifiedOnline, action.wallet.blockchain.fullName,
|
||||
currencySymbol = action.wallet.blockchain.currency,
|
||||
amount?.toFormattedString(action.wallet.blockchain),
|
||||
token = tokenData,
|
||||
fiatAmount = fiatAmount
|
||||
|
|
@ -59,6 +60,24 @@ fun walletReducer(action: Action, state: AppState): WalletState {
|
|||
mainButton = WalletMainButton.SendButton(sendButtonEnabled)
|
||||
)
|
||||
}
|
||||
is WalletAction.LoadWallet.NoAccount -> {
|
||||
val wallet = state.globalState.walletManager?.wallet
|
||||
newState = newState.copy(
|
||||
state = ProgressState.Done, wallet = wallet,
|
||||
currencyData = BalanceWidgetData(
|
||||
BalanceStatus.NoAccount, wallet?.blockchain?.fullName,
|
||||
currencySymbol = wallet?.blockchain?.currency,
|
||||
amountToCreateAccount = action.amountToCreateAccount
|
||||
)
|
||||
)
|
||||
}
|
||||
is WalletAction.LoadWallet.Failure -> newState = newState.copy(
|
||||
state = ProgressState.Done,
|
||||
currencyData = newState.currencyData.copy(
|
||||
status = BalanceStatus.Unreachable,
|
||||
errorMessage = action.errorMessage
|
||||
)
|
||||
)
|
||||
is WalletAction.LoadFiatRate.Success -> {
|
||||
val rate = action.fiatRates.second
|
||||
val currency = action.fiatRates.first
|
||||
|
|
@ -77,10 +96,6 @@ fun walletReducer(action: Action, state: AppState): WalletState {
|
|||
token = newState.currencyData.token?.copy(fiatAmount = tokenFiatAmount)
|
||||
))
|
||||
}
|
||||
is WalletAction.LoadWallet.Failure -> newState = newState.copy(
|
||||
state = ProgressState.Done,
|
||||
currencyData = newState.currencyData.copy(status = BalanceStatus.Unreachable)
|
||||
)
|
||||
is WalletAction.ShowQrCode -> {
|
||||
newState = newState.copy(qrCode = newState.wallet?.shareUrl?.toQrCode())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,15 +21,19 @@ enum class BalanceStatus {
|
|||
VerifiedOnline,
|
||||
Unreachable,
|
||||
Loading,
|
||||
NoAccount,
|
||||
EmptyCard
|
||||
}
|
||||
|
||||
data class BalanceWidgetData(
|
||||
val status: BalanceStatus? = null,
|
||||
val currency: String? = null,
|
||||
val currencySymbol: String? = null,
|
||||
val amount: String? = null,
|
||||
val fiatAmount: String? = null,
|
||||
val token: TokenData? = null
|
||||
val token: TokenData? = null,
|
||||
val amountToCreateAccount: Int? = null,
|
||||
val errorMessage: String? = null
|
||||
)
|
||||
|
||||
data class TokenData(
|
||||
|
|
@ -87,7 +91,16 @@ class BalanceWidget(
|
|||
fragment.l_balance_error.show()
|
||||
fragment.tv_error_title.text = fragment.getText(R.string.wallet_empty_card)
|
||||
fragment.tv_error_descriptions.text = fragment.getText(R.string.wallet_empty_card_description)
|
||||
|
||||
}
|
||||
BalanceStatus.NoAccount -> {
|
||||
fragment.l_balance.hide()
|
||||
fragment.l_balance_error.show()
|
||||
fragment.tv_error_title.text = fragment.getText(R.string.wallet_no_account)
|
||||
fragment.tv_error_descriptions.text =
|
||||
fragment.getString(
|
||||
R.string.wallet_no_account_description,
|
||||
data.amountToCreateAccount?.toString(), data.currencySymbol
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<TextView
|
||||
|
|
@ -29,13 +29,13 @@
|
|||
android:paddingStart="16dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="@string/wallet_verified_balance"
|
||||
android:textColor="@color/accent"
|
||||
android:textSize="12sp"
|
||||
android:visibility="gone"
|
||||
app:drawableStartCompat="@drawable/ic_ok"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_currency"
|
||||
android:text="@string/wallet_verified_balance"
|
||||
android:visibility="gone"/>
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_currency" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_status_error"
|
||||
|
|
@ -45,13 +45,13 @@
|
|||
android:paddingStart="16dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="@string/wallet_blockchain_is_unreachable"
|
||||
android:textColor="@color/warning"
|
||||
android:textSize="12sp"
|
||||
android:visibility="gone"
|
||||
app:drawableStartCompat="@drawable/ic_baseline_error_outline_24"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_currency"
|
||||
android:text="@string/wallet_blockchain_is_unreachable"
|
||||
android:visibility="gone"/>
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_currency" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_status_loading"
|
||||
|
|
@ -61,12 +61,12 @@
|
|||
android:paddingStart="16dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="@string/wallet_balance_is_loading"
|
||||
android:textColor="@color/darkGray6"
|
||||
android:textSize="12sp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_currency"
|
||||
android:text="@string/wallet_balance_is_loading"
|
||||
android:visibility="gone"/>
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_currency" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_amount"
|
||||
|
|
@ -99,13 +99,13 @@
|
|||
<include
|
||||
android:id="@+id/l_token"
|
||||
layout="@layout/layout_token"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="35dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginTop="35dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tv_currency"
|
||||
android:visibility="gone"/>
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tv_currency" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -21,6 +21,8 @@
|
|||
<string name="wallet_account_not_created">Account is not created</string>
|
||||
<string name="wallet_empty_card">Empty Card</string>
|
||||
<string name="wallet_empty_card_description">Create wallet to start using Tangem card</string>
|
||||
<string name="wallet_no_account">Account is not created</string>
|
||||
<string name="wallet_no_account_description">Load %1s+ %2s to create account</string>
|
||||
<string name="wallet_tokens">Tokens</string>
|
||||
|
||||
<string name="wallet_dialog_pay_id_button">Create PayID</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue