Updated on 2026-08-14
This commit is contained in:
commit
d5d19a690d
9 changed files with 77 additions and 31 deletions
|
|
@ -8,4 +8,5 @@ sealed class TapError(@StringRes val localizedMessage: Int): Throwable() {
|
|||
object PayIdCreatingError: TapError(R.string.error_creating_payid)
|
||||
object PayIdEmptyField: TapError(R.string.wallet_create_payid_empty)
|
||||
object UnknownBlockchain: TapError(R.string.wallet_unknown_blockchain)
|
||||
object NoInternetConnection: TapError(R.string.notification_no_internet)
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package com.tangem.tap.domain
|
|||
import com.tangem.blockchain.common.Wallet
|
||||
import com.tangem.blockchain.common.WalletManager
|
||||
import com.tangem.commands.Card
|
||||
import com.tangem.commands.CardStatus
|
||||
import com.tangem.commands.common.network.Result
|
||||
import com.tangem.commands.common.network.TangemService
|
||||
import com.tangem.common.extensions.toHexString
|
||||
|
|
@ -73,7 +74,7 @@ class TapWalletManager {
|
|||
store.dispatch(GlobalAction.SaveScanNoteResponse(data))
|
||||
if (data.walletManager != null) {
|
||||
if (!NetworkConnectivity.getInstance().isOnlineOrConnecting()) {
|
||||
store.dispatch(WalletAction.LoadData.NoInternetConnection)
|
||||
store.dispatch(WalletAction.LoadData.Failure(TapError.NoInternetConnection))
|
||||
return@withContext
|
||||
}
|
||||
data.verifyResponse?.artworkInfo?.id?.let {
|
||||
|
|
@ -82,8 +83,10 @@ class TapWalletManager {
|
|||
store.dispatch(WalletAction.LoadWallet)
|
||||
store.dispatch(WalletAction.LoadFiatRate)
|
||||
store.dispatch(WalletAction.LoadPayId)
|
||||
} else {
|
||||
} else if (data.card.status == CardStatus.Empty){
|
||||
store.dispatch(WalletAction.EmptyWallet)
|
||||
} else {
|
||||
store.dispatch(WalletAction.LoadData.Failure(TapError.UnknownBlockchain))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import com.tangem.TangemSdkError
|
|||
import com.tangem.blockchain.common.WalletManager
|
||||
import com.tangem.blockchain.common.WalletManagerFactory
|
||||
import com.tangem.commands.Card
|
||||
import com.tangem.commands.CardStatus
|
||||
import com.tangem.commands.CommandResponse
|
||||
import com.tangem.commands.verifycard.VerifyCardCommand
|
||||
import com.tangem.commands.verifycard.VerifyCardResponse
|
||||
|
|
@ -24,12 +23,11 @@ class ScanNoteTask : CardSessionRunnable<ScanNoteResponse> {
|
|||
override fun run(session: CardSession, callback: (result: CompletionResult<ScanNoteResponse>) -> Unit) {
|
||||
val card = session.environment.card
|
||||
card ?: return callback(CompletionResult.Failure(TangemSdkError.CardError()))
|
||||
if (card.status == CardStatus.Empty) {
|
||||
val walletManager = try {
|
||||
WalletManagerFactory.makeWalletManager(card)
|
||||
} catch (exception: Exception) {
|
||||
return callback(CompletionResult.Success(ScanNoteResponse(null, card)))
|
||||
}
|
||||
val walletManager = WalletManagerFactory.makeWalletManager(card)
|
||||
?: return callback(CompletionResult.Failure(TangemSdkError.CardError()))
|
||||
|
||||
VerifyCardCommand(true).run(session) { result ->
|
||||
when (result) {
|
||||
is CompletionResult.Success -> {
|
||||
|
|
@ -48,10 +46,10 @@ class ScanNoteTask : CardSessionRunnable<ScanNoteResponse> {
|
|||
|
||||
fun Card?.toScanNoteCompletionResult(): CompletionResult<ScanNoteResponse> {
|
||||
this ?: return CompletionResult.Failure(TangemSdkError.CardError())
|
||||
if (this.status == CardStatus.Empty) {
|
||||
val walletManager = try {
|
||||
WalletManagerFactory.makeWalletManager(this)
|
||||
} catch (exception: Exception) {
|
||||
return CompletionResult.Success(ScanNoteResponse(null, this))
|
||||
}
|
||||
val walletManager = WalletManagerFactory.makeWalletManager(this)
|
||||
?: return CompletionResult.Failure(TangemSdkError.CardError())
|
||||
return CompletionResult.Success(ScanNoteResponse(walletManager, this))
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ import java.math.BigDecimal
|
|||
sealed class WalletAction : Action {
|
||||
|
||||
object LoadData : WalletAction() {
|
||||
object NoInternetConnection : WalletAction()
|
||||
data class Failure(val error: TapError): WalletAction()
|
||||
}
|
||||
|
||||
object LoadWallet : WalletAction() {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.tangem.tap.common.extensions.toFiatString
|
|||
import com.tangem.tap.common.extensions.toFormattedString
|
||||
import com.tangem.tap.common.extensions.toQrCode
|
||||
import com.tangem.tap.common.redux.AppState
|
||||
import com.tangem.tap.domain.TapError
|
||||
import com.tangem.tap.features.wallet.models.toPendingTransactions
|
||||
import com.tangem.tap.features.wallet.ui.BalanceStatus
|
||||
import com.tangem.tap.features.wallet.ui.BalanceWidgetData
|
||||
|
|
@ -31,22 +32,33 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
|
|||
currencyData = BalanceWidgetData(BalanceStatus.EmptyCard),
|
||||
mainButton = WalletMainButton.CreateWalletButton(true)
|
||||
)
|
||||
is WalletAction.LoadData.NoInternetConnection -> {
|
||||
val wallet = state.globalState.scanNoteResponse?.walletManager?.wallet
|
||||
val addressData = if (wallet == null) {
|
||||
null
|
||||
} else {
|
||||
AddressData(wallet.address, wallet.shareUrl, wallet.exploreUrl)
|
||||
is WalletAction.LoadData.Failure -> {
|
||||
when (action.error) {
|
||||
is TapError.NoInternetConnection -> {
|
||||
val wallet = state.globalState.scanNoteResponse?.walletManager?.wallet
|
||||
val addressData = if (wallet == null) {
|
||||
null
|
||||
} else {
|
||||
AddressData(wallet.address, wallet.shareUrl, wallet.exploreUrl)
|
||||
}
|
||||
newState = WalletState(
|
||||
state = ProgressState.Error,
|
||||
error = ErrorType.NoInternetConnection,
|
||||
addressData = addressData,
|
||||
currencyData = BalanceWidgetData(
|
||||
status = BalanceStatus.Unreachable,
|
||||
currency = wallet?.blockchain?.fullName),
|
||||
mainButton = WalletMainButton.SendButton(false)
|
||||
)
|
||||
}
|
||||
is TapError.UnknownBlockchain -> {
|
||||
newState = WalletState(
|
||||
state = ProgressState.Done,
|
||||
currencyData = BalanceWidgetData(BalanceStatus.UnknownBlockchain)
|
||||
)
|
||||
}
|
||||
}
|
||||
newState = WalletState(
|
||||
state = ProgressState.Error,
|
||||
error = ErrorType.NoInternetConnection,
|
||||
addressData = addressData,
|
||||
currencyData = BalanceWidgetData(
|
||||
status = BalanceStatus.Unreachable,
|
||||
currency = wallet?.blockchain?.fullName),
|
||||
mainButton = WalletMainButton.SendButton(false)
|
||||
)
|
||||
|
||||
}
|
||||
is WalletAction.LoadWallet -> {
|
||||
val wallet = state.globalState.scanNoteResponse?.walletManager?.wallet
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ enum class BalanceStatus {
|
|||
Unreachable,
|
||||
Loading,
|
||||
NoAccount,
|
||||
EmptyCard
|
||||
EmptyCard,
|
||||
UnknownBlockchain
|
||||
}
|
||||
|
||||
data class BalanceWidgetData(
|
||||
|
|
@ -84,8 +85,9 @@ class BalanceWidget(
|
|||
fragment.tv_currency.text = data.currency
|
||||
fragment.tv_currency_symbol.text = "-"
|
||||
fragment.tv_amount.text = ""
|
||||
fragment.tv_status_error_message.text = data.errorMessage
|
||||
|
||||
showStatus(R.id.tv_status_error)
|
||||
showStatus(R.id.group_error)
|
||||
}
|
||||
BalanceStatus.EmptyCard -> {
|
||||
fragment.l_balance.hide()
|
||||
|
|
@ -103,11 +105,18 @@ class BalanceWidget(
|
|||
data.amountToCreateAccount?.toString(), data.currencySymbol
|
||||
)
|
||||
}
|
||||
BalanceStatus.UnknownBlockchain -> {
|
||||
fragment.l_balance.hide()
|
||||
fragment.l_balance_error.show()
|
||||
fragment.tv_error_title.text = fragment.getText(R.string.wallet_unknown_blockchain_title)
|
||||
fragment.tv_error_descriptions.text =
|
||||
fragment.getString(R.string.wallet_unknown_blockchain)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showStatus(@IdRes viewRes: Int) {
|
||||
fragment.tv_status_error.show(viewRes == R.id.tv_status_error)
|
||||
fragment.group_error.show(viewRes == R.id.group_error)
|
||||
fragment.tv_status_loading.show(viewRes == R.id.tv_status_loading)
|
||||
fragment.tv_status_verified.show(viewRes == R.id.tv_status_verified)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,26 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_currency" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_status_error_message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:textColor="@color/darkGray2"
|
||||
android:textSize="12sp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_status_error" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/group_error"
|
||||
android:visibility="gone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:constraint_referenced_ids="tv_status_error, tv_status_error_message" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_status_loading"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
|||
|
|
@ -32,9 +32,11 @@
|
|||
<TextView
|
||||
android:id="@+id/tv_error_descriptions"
|
||||
app:layout_constraintStart_toEndOf="@id/iv_balance_error"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_error_title"
|
||||
app:layout_constraintHorizontal_weight="0"
|
||||
tools:text="Load10+ XLM to create account"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="4dp"
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
<string name="wallet_create_payid">Create PayID</string>
|
||||
<string name="wallet_verified_balance">Verified Balance</string>
|
||||
<string name="wallet_blockchain_is_unreachable">Blockchain is unreachable</string>
|
||||
<string name="wallet_unknown_blockchain">Uh oh!\nYour Tangem card was made to work with a different application. Please see the name and instructions on your card, and install the correct app.</string>
|
||||
<string name="wallet_unknown_blockchain">Your Tangem card was made to work with a different application. Please see the name and instructions on your card, and install the correct app.</string>
|
||||
<string name="wallet_unknown_blockchain_title">Uh oh!</string>
|
||||
<string name="wallet_balance_is_loading">Balance is loading…</string>
|
||||
<string name="wallet_account_not_created">Account is not created</string>
|
||||
<string name="wallet_empty_card">Empty Card</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue