Updated on 2026-08-14
This commit is contained in:
parent
7200be9827
commit
1de486f684
6 changed files with 38 additions and 30 deletions
|
|
@ -71,7 +71,7 @@ dependencies {
|
||||||
implementation 'com.google.android.material:material:1.2.1'
|
implementation 'com.google.android.material:material:1.2.1'
|
||||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
|
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
|
||||||
|
|
||||||
implementation 'com.tangem:blockchain:1.108.0'
|
implementation 'com.tangem:blockchain:1.113.0'
|
||||||
implementation 'com.tangem:core:1.80.0'
|
implementation 'com.tangem:core:1.80.0'
|
||||||
implementation 'com.tangem:sdk:1.80.0'
|
implementation 'com.tangem:sdk:1.80.0'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.tangem.tap.domain
|
package com.tangem.tap.domain
|
||||||
|
|
||||||
|
import com.tangem.blockchain.common.Token
|
||||||
import com.tangem.blockchain.common.Wallet
|
import com.tangem.blockchain.common.Wallet
|
||||||
import com.tangem.blockchain.common.WalletManager
|
import com.tangem.blockchain.common.WalletManager
|
||||||
import com.tangem.commands.CardStatus
|
import com.tangem.commands.CardStatus
|
||||||
|
|
@ -66,17 +67,13 @@ class TapWalletManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun loadFiatRate(fiatCurrency: FiatCurrencyName) {
|
suspend fun loadFiatRate(fiatCurrency: FiatCurrencyName) {
|
||||||
val wallet = store.state.globalState.scanNoteResponse?.walletManager?.wallet
|
val wallet = store.state.globalState.scanNoteResponse?.walletManager?.wallet ?: return
|
||||||
val blockchainCurrency = wallet?.blockchain?.currency
|
|
||||||
val tokenCurrency = wallet?.token?.symbol
|
|
||||||
|
|
||||||
val blockchainRate = blockchainCurrency?.let { coinMarketCapService.getRate(it, fiatCurrency) }
|
val currencyList = wallet.getTokens().map { it.symbol }.toMutableList()
|
||||||
val tokenRate = tokenCurrency?.let { coinMarketCapService.getRate(it, fiatCurrency) }
|
currencyList.add(wallet.blockchain.currency)
|
||||||
|
|
||||||
val results = mutableListOf<Pair<CryptoCurrencyName, Result<BigDecimal>?>>()
|
val results = mutableListOf<Pair<CryptoCurrencyName, Result<BigDecimal>?>>()
|
||||||
if (blockchainCurrency != null) results.add(blockchainCurrency to blockchainRate)
|
currencyList.forEach { results.add(it to coinMarketCapService.getRate(it, fiatCurrency)) }
|
||||||
if (tokenCurrency != null) results.add(tokenCurrency to tokenRate)
|
|
||||||
|
|
||||||
handleFiatRatesResult(results)
|
handleFiatRatesResult(results)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +142,8 @@ class TapWalletManager {
|
||||||
val error = result.error
|
val error = result.error
|
||||||
val blockchain = walletManager.wallet.blockchain
|
val blockchain = walletManager.wallet.blockchain
|
||||||
if (error != null && blockchain.isNoAccountError(error)) {
|
if (error != null && blockchain.isNoAccountError(error)) {
|
||||||
val amountToCreateAccount = blockchain.amountToCreateAccount(walletManager.wallet.token)
|
val token = walletManager.wallet.getFirstToken()
|
||||||
|
val amountToCreateAccount = blockchain.amountToCreateAccount(token)
|
||||||
if (amountToCreateAccount != null) {
|
if (amountToCreateAccount != null) {
|
||||||
store.dispatch(WalletAction.LoadWallet.NoAccount(amountToCreateAccount.toString()))
|
store.dispatch(WalletAction.LoadWallet.NoAccount(amountToCreateAccount.toString()))
|
||||||
return@withContext
|
return@withContext
|
||||||
|
|
@ -210,3 +208,7 @@ class TapWalletManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Wallet.getFirstToken(): Token? {
|
||||||
|
return getTokens().toList().getOrNull(0)
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ import com.tangem.blockchain.common.AmountType
|
||||||
import com.tangem.blockchain.common.Wallet
|
import com.tangem.blockchain.common.Wallet
|
||||||
import com.tangem.tap.common.extensions.scaleToFiat
|
import com.tangem.tap.common.extensions.scaleToFiat
|
||||||
import com.tangem.tap.common.extensions.stripZeroPlainString
|
import com.tangem.tap.common.extensions.stripZeroPlainString
|
||||||
|
import com.tangem.tap.domain.getFirstToken
|
||||||
import com.tangem.tap.features.send.redux.ReceiptAction.RefreshReceipt
|
import com.tangem.tap.features.send.redux.ReceiptAction.RefreshReceipt
|
||||||
import com.tangem.tap.features.send.redux.SendScreenAction
|
import com.tangem.tap.features.send.redux.SendScreenAction
|
||||||
import com.tangem.tap.features.send.redux.states.*
|
import com.tangem.tap.features.send.redux.states.*
|
||||||
|
|
@ -179,7 +180,7 @@ class ReceiptReducer : SendInternalReducer {
|
||||||
return ReceiptSymbols(
|
return ReceiptSymbols(
|
||||||
fiat = store.state.globalState.appCurrency,
|
fiat = store.state.globalState.appCurrency,
|
||||||
crypto = wallet.blockchain.currency,
|
crypto = wallet.blockchain.currency,
|
||||||
token = wallet.amounts[AmountType.Token]?.currencySymbol
|
token = wallet.getFirstToken()?.symbol
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,12 +188,12 @@ class ReceiptReducer : SendInternalReducer {
|
||||||
return when (mainCurrencyType) {
|
return when (mainCurrencyType) {
|
||||||
MainCurrencyType.FIAT -> when (amountType) {
|
MainCurrencyType.FIAT -> when (amountType) {
|
||||||
AmountType.Coin -> ReceiptLayoutType.FIAT
|
AmountType.Coin -> ReceiptLayoutType.FIAT
|
||||||
AmountType.Token -> ReceiptLayoutType.TOKEN_FIAT
|
is AmountType.Token -> ReceiptLayoutType.TOKEN_FIAT
|
||||||
AmountType.Reserve -> ReceiptLayoutType.UNKNOWN
|
AmountType.Reserve -> ReceiptLayoutType.UNKNOWN
|
||||||
}
|
}
|
||||||
MainCurrencyType.CRYPTO -> when (amountType) {
|
MainCurrencyType.CRYPTO -> when (amountType) {
|
||||||
AmountType.Coin -> ReceiptLayoutType.CRYPTO
|
AmountType.Coin -> ReceiptLayoutType.CRYPTO
|
||||||
AmountType.Token -> ReceiptLayoutType.TOKEN_CRYPTO
|
is AmountType.Token -> ReceiptLayoutType.TOKEN_CRYPTO
|
||||||
AmountType.Reserve -> ReceiptLayoutType.UNKNOWN
|
AmountType.Reserve -> ReceiptLayoutType.UNKNOWN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,14 +78,14 @@ data class SendState(
|
||||||
|
|
||||||
fun convertFiatToExtractCrypto(fiatValue: BigDecimal): BigDecimal = when (amountState.typeOfAmount) {
|
fun convertFiatToExtractCrypto(fiatValue: BigDecimal): BigDecimal = when (amountState.typeOfAmount) {
|
||||||
AmountType.Coin -> convertFiatToCoin(fiatValue)
|
AmountType.Coin -> convertFiatToCoin(fiatValue)
|
||||||
AmountType.Token -> convertFiatToToken(fiatValue)
|
is AmountType.Token -> convertFiatToToken(fiatValue)
|
||||||
AmountType.Reserve -> fiatValue
|
AmountType.Reserve -> fiatValue
|
||||||
}
|
}
|
||||||
|
|
||||||
fun convertExtractCryptoToFiat(cryptoValue: BigDecimal, scaleWithPrecision: Boolean = false): BigDecimal {
|
fun convertExtractCryptoToFiat(cryptoValue: BigDecimal, scaleWithPrecision: Boolean = false): BigDecimal {
|
||||||
return when (amountState.typeOfAmount) {
|
return when (amountState.typeOfAmount) {
|
||||||
AmountType.Coin -> convertCoinToFiat(cryptoValue, scaleWithPrecision)
|
AmountType.Coin -> convertCoinToFiat(cryptoValue, scaleWithPrecision)
|
||||||
AmountType.Token -> convertTokenToFiat(cryptoValue, scaleWithPrecision)
|
is AmountType.Token -> convertTokenToFiat(cryptoValue, scaleWithPrecision)
|
||||||
AmountType.Reserve -> cryptoValue
|
AmountType.Reserve -> cryptoValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +103,7 @@ data class SendState(
|
||||||
fun mainCurrencyCanBeSwitched(): Boolean {
|
fun mainCurrencyCanBeSwitched(): Boolean {
|
||||||
return when (amountState.typeOfAmount) {
|
return when (amountState.typeOfAmount) {
|
||||||
AmountType.Coin -> coinIsConvertible()
|
AmountType.Coin -> coinIsConvertible()
|
||||||
AmountType.Token -> tokenIsConvertible()
|
is AmountType.Token -> tokenIsConvertible()
|
||||||
AmountType.Reserve -> false
|
AmountType.Reserve -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ class WalletMiddleware {
|
||||||
|
|
||||||
private fun prepareSendAction(amount: Amount?): Action {
|
private fun prepareSendAction(amount: Amount?): Action {
|
||||||
return if (amount != null) {
|
return if (amount != null) {
|
||||||
if (amount.type == AmountType.Token) {
|
if (amount.type is AmountType.Token) {
|
||||||
PrepareSendScreen(store.state.walletState.wallet?.amounts?.get(AmountType.Coin), amount)
|
PrepareSendScreen(store.state.walletState.wallet?.amounts?.get(AmountType.Coin), amount)
|
||||||
} else {
|
} else {
|
||||||
PrepareSendScreen(amount)
|
PrepareSendScreen(amount)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import com.tangem.tap.common.extensions.toFormattedString
|
||||||
import com.tangem.tap.common.extensions.toQrCode
|
import com.tangem.tap.common.extensions.toQrCode
|
||||||
import com.tangem.tap.common.redux.AppState
|
import com.tangem.tap.common.redux.AppState
|
||||||
import com.tangem.tap.domain.TapError
|
import com.tangem.tap.domain.TapError
|
||||||
|
import com.tangem.tap.domain.getFirstToken
|
||||||
import com.tangem.tap.features.wallet.models.removeUnknownTransactions
|
import com.tangem.tap.features.wallet.models.removeUnknownTransactions
|
||||||
import com.tangem.tap.features.wallet.models.toPendingTransactions
|
import com.tangem.tap.features.wallet.models.toPendingTransactions
|
||||||
import com.tangem.tap.features.wallet.ui.BalanceStatus
|
import com.tangem.tap.features.wallet.ui.BalanceStatus
|
||||||
|
|
@ -46,7 +47,7 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
|
||||||
val addressData = if (wallet == null) {
|
val addressData = if (wallet == null) {
|
||||||
null
|
null
|
||||||
} else {
|
} else {
|
||||||
AddressData(wallet.address, wallet.shareUrl, wallet.exploreUrl)
|
AddressData(wallet.address, wallet.getShareUri(wallet.address), wallet.getExploreUrl())
|
||||||
}
|
}
|
||||||
newState = newState.copy(
|
newState = newState.copy(
|
||||||
state = ProgressState.Error,
|
state = ProgressState.Error,
|
||||||
|
|
@ -55,7 +56,7 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
|
||||||
currencyData = BalanceWidgetData(
|
currencyData = BalanceWidgetData(
|
||||||
status = BalanceStatus.Unreachable,
|
status = BalanceStatus.Unreachable,
|
||||||
currency = wallet?.blockchain?.fullName,
|
currency = wallet?.blockchain?.fullName,
|
||||||
token = wallet?.token?.symbol?.let {
|
token = wallet?.getFirstToken()?.symbol?.let {
|
||||||
TokenData("", tokenSymbol = it)
|
TokenData("", tokenSymbol = it)
|
||||||
}),
|
}),
|
||||||
mainButton = WalletMainButton.SendButton(false),
|
mainButton = WalletMainButton.SendButton(false),
|
||||||
|
|
@ -86,11 +87,11 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
|
||||||
BalanceStatus.Loading,
|
BalanceStatus.Loading,
|
||||||
wallet.blockchain.fullName,
|
wallet.blockchain.fullName,
|
||||||
currencySymbol = wallet.blockchain.currency,
|
currencySymbol = wallet.blockchain.currency,
|
||||||
token = wallet.token?.symbol?.let {
|
token = wallet.getFirstToken()?.symbol?.let {
|
||||||
TokenData("", tokenSymbol = it)
|
TokenData("", tokenSymbol = it)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
addressData = AddressData(wallet.address, wallet.shareUrl, wallet.exploreUrl),
|
addressData = AddressData(wallet.address, wallet.getShareUri(wallet.address), wallet.getExploreUrl()),
|
||||||
mainButton = WalletMainButton.SendButton(false),
|
mainButton = WalletMainButton.SendButton(false),
|
||||||
topUpState = TopUpState(allowed = action.allowTopUp)
|
topUpState = TopUpState(allowed = action.allowTopUp)
|
||||||
)
|
)
|
||||||
|
|
@ -143,9 +144,9 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
|
||||||
} else {
|
} else {
|
||||||
newState.currencyData.fiatAmount
|
newState.currencyData.fiatAmount
|
||||||
}
|
}
|
||||||
val tokenFiatAmount = if (currency == newState.wallet?.token?.symbol) {
|
val token = newState.wallet?.getFirstToken()
|
||||||
newState.wallet?.amounts?.get(AmountType.Token)?.value
|
val tokenFiatAmount = if (currency == token?.symbol) {
|
||||||
?.toFiatString(rate, state.globalState.appCurrency)
|
newState.wallet?.getTokenAmount(token)?.value?.toFiatString(rate, state.globalState.appCurrency)
|
||||||
} else {
|
} else {
|
||||||
newState.currencyData.token?.fiatAmount
|
newState.currencyData.token?.fiatAmount
|
||||||
}
|
}
|
||||||
|
|
@ -230,13 +231,17 @@ private fun onWalletLoaded(
|
||||||
wallet: Wallet, walletState: WalletState, topUpAllowed: Boolean? = null
|
wallet: Wallet, walletState: WalletState, topUpAllowed: Boolean? = null
|
||||||
): WalletState {
|
): WalletState {
|
||||||
val fiatCurrencySymbol = store.state.globalState.appCurrency
|
val fiatCurrencySymbol = store.state.globalState.appCurrency
|
||||||
val token = wallet.amounts[AmountType.Token]
|
val token = wallet.getFirstToken()
|
||||||
val tokenData = if (token != null) {
|
val tokenData = if (token != null) {
|
||||||
val tokenFiatRate = store.state.globalState.conversionRates.getRate(token.currencySymbol)
|
val tokenAmount = wallet.getTokenAmount(token)
|
||||||
val tokenFiatAmount = tokenFiatRate?.let { token.value?.toFiatString(it, fiatCurrencySymbol) }
|
if (tokenAmount != null) {
|
||||||
TokenData(
|
val tokenFiatRate = store.state.globalState.conversionRates.getRate(tokenAmount.currencySymbol)
|
||||||
token.value?.toFormattedString(token.decimals) ?: "",
|
val tokenFiatAmount = tokenFiatRate?.let { tokenAmount.value?.toFiatString(it, fiatCurrencySymbol) }
|
||||||
token.currencySymbol, tokenFiatAmount)
|
TokenData(tokenAmount.value?.toFormattedString(tokenAmount.decimals) ?: "",
|
||||||
|
tokenAmount.currencySymbol, tokenFiatAmount)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue