Updated on 2026-08-14

This commit is contained in:
Tangem 2020-09-04 13:14:28 +03:00
parent 19092b22db
commit e03f078120
7 changed files with 71 additions and 7 deletions

View file

@ -64,7 +64,7 @@ dependencies {
implementation 'com.google.android.material:material:1.2.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
implementation 'com.tangem:blockchain:1.27.0'
implementation 'com.tangem:blockchain:1.28.0'
//lifecycle
implementation "androidx.lifecycle:lifecycle-runtime:2.2.0"

View file

@ -2,7 +2,9 @@ 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.common.network.Result
import com.tangem.commands.common.network.TangemService
import com.tangem.common.extensions.toHexString
import com.tangem.tap.TapConfig
import com.tangem.tap.common.redux.global.GlobalAction
@ -19,6 +21,7 @@ import java.math.BigDecimal
class TapWalletManager {
private val payIdManager = PayIdManager()
private val coinMarketCapService = CoinMarketCapService()
private val tangemService = TangemService()
suspend fun loadWalletData() {
val walletManager = store.state.globalState.walletManager
@ -29,6 +32,19 @@ class TapWalletManager {
updateWallet(walletManager)
}
suspend fun loadArtwork(card: Card, artworkId: String) {
val result =
tangemService.getArtwork(card.cardId, card.cardPublicKey!!.toHexString(), artworkId)
withContext(Dispatchers.Main) {
when (result) {
is Result.Success -> {
store.dispatch(WalletAction.LoadArtwork.Success(result.data.byteStream().readBytes()))
}
is Result.Failure -> store.dispatch(WalletAction.LoadArtwork.Failure)
}
}
}
suspend fun loadPayId() {
val result = loadPayIdIfNeeded()
result?.let { handlePayIdResult(it) }
@ -53,6 +69,9 @@ class TapWalletManager {
store.dispatch(GlobalAction.LoadCard(data.card))
if (data.walletManager != null) {
store.dispatch(GlobalAction.LoadWalletManager(data.walletManager))
data.verifyResponse?.artworkInfo?.id?.let {
store.dispatch(WalletAction.LoadArtwork(data.card, it))
}
store.dispatch(WalletAction.LoadWallet)
store.dispatch(WalletAction.LoadFiatRate)
store.dispatch(WalletAction.LoadPayId)

View file

@ -8,11 +8,14 @@ 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
import com.tangem.common.CompletionResult
data class ScanNoteResponse(
val walletManager: WalletManager?,
val card: Card
val card: Card,
val verifyResponse: VerifyCardResponse? = null
) : CommandResponse
class ScanNoteTask : CardSessionRunnable<ScanNoteResponse> {
@ -20,7 +23,26 @@ class ScanNoteTask : CardSessionRunnable<ScanNoteResponse> {
override fun run(session: CardSession, callback: (result: CompletionResult<ScanNoteResponse>) -> Unit) {
val card = session.environment.card
callback(card.toScanNoteCompletionResult())
card ?: return callback(CompletionResult.Failure(TangemSdkError.CardError()))
if (card.status == CardStatus.Empty) {
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 -> {
callback(CompletionResult.Success(ScanNoteResponse(
walletManager, card, result.data
)))
}
is CompletionResult.Failure -> {
callback(CompletionResult.Failure(TangemSdkError.VerificationFailed()))
}
}
}
}
}

View file

@ -2,6 +2,7 @@ package com.tangem.tap.features.wallet.redux
import android.content.Context
import com.tangem.blockchain.common.Wallet
import com.tangem.commands.Card
import com.tangem.tap.common.redux.ErrorAction
import com.tangem.tap.common.redux.NotificationAction
import com.tangem.tap.domain.TapError
@ -25,6 +26,10 @@ sealed class WalletAction : Action {
object NotCreated: WalletAction()
object Failure: WalletAction()
}
data class LoadArtwork(val card: Card, val artworkId: String) : WalletAction() {
data class Success(val artwork: ByteArray) : WalletAction()
object Failure: WalletAction()
}
object Scan : WalletAction()
object Send : WalletAction()
object CreatePayId : WalletAction() {

View file

@ -38,6 +38,13 @@ val walletMiddleware: Middleware<AppState> = { dispatch, state ->
store.state.globalState.tapWalletManager.loadFiatRate()
}
}
is WalletAction.LoadArtwork -> {
scope.launch {
store.state.globalState.tapWalletManager.loadArtwork(
action.card, action.artworkId
)
}
}
is WalletAction.CreateWallet -> {
scope.launch {
val result = tangemSdkManager.createWallet()

View file

@ -2,6 +2,7 @@ package com.tangem.tap.features.wallet.redux
import com.tangem.blockchain.common.AmountType
import com.tangem.common.extensions.isZero
import com.tangem.tap.common.extensions.toBitmap
import com.tangem.tap.common.extensions.toFiatString
import com.tangem.tap.common.extensions.toFormattedString
import com.tangem.tap.common.extensions.toQrCode
@ -96,6 +97,12 @@ fun walletReducer(action: Action, state: AppState): WalletState {
token = newState.currencyData.token?.copy(fiatAmount = tokenFiatAmount)
))
}
is WalletAction.LoadArtwork -> {
newState = newState.copy(cardImage = null)
}
is WalletAction.LoadArtwork.Success -> {
newState = newState.copy(cardImage = action.artwork.toBitmap())
}
is WalletAction.ShowQrCode -> {
newState = newState.copy(qrCode = newState.wallet?.shareUrl?.toQrCode())
}

View file

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.Fragment
import com.tangem.tap.common.extensions.getDrawable
import com.tangem.tap.common.extensions.hide
import com.tangem.tap.common.extensions.show
import com.tangem.tap.common.redux.navigation.AppScreen
@ -56,9 +57,6 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
btn_scan.setOnClickListener {
store.dispatch(WalletAction.Scan)
}
btn_main.setOnClickListener {
store.dispatch(NavigationAction.NavigateTo(AppScreen.Send))
}
}
override fun newState(state: WalletState) {
@ -74,6 +72,12 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
l_address?.hide()
}
if (state.cardImage != null) {
iv_card.setImageBitmap(state.cardImage)
} else {
iv_card.setImageDrawable(getDrawable(R.drawable.card_default))
}
btn_copy.setOnClickListener { store.dispatch(WalletAction.CopyAddress(requireContext())) }
btn_show_qr.setOnClickListener { store.dispatch(WalletAction.ShowQrCode) }
@ -87,7 +91,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
btn_main.setOnClickListener {
when (state.mainButton) {
is WalletMainButton.SendButton -> TODO()
is WalletMainButton.SendButton -> store.dispatch(NavigationAction.NavigateTo(AppScreen.Send))
is WalletMainButton.CreateWalletButton -> store.dispatch(WalletAction.CreateWallet)
}
}