Updated on 2026-08-14
This commit is contained in:
parent
ce6028142b
commit
7e2b094f13
16 changed files with 204 additions and 111 deletions
|
|
@ -2,6 +2,9 @@ package com.tangem.tap.common.extensions
|
|||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.BlockchainSdkError
|
||||
import com.tangem.blockchain.common.Token
|
||||
import com.tangem.blockchain.common.TransactionData
|
||||
import com.tangem.blockchain.common.TransactionHistoryProvider
|
||||
import com.tangem.blockchain.common.Wallet
|
||||
import com.tangem.blockchain.common.WalletManager
|
||||
import com.tangem.common.services.Result
|
||||
|
|
@ -10,6 +13,7 @@ import com.tangem.tap.domain.TapError
|
|||
import com.tangem.tap.domain.extensions.amountToCreateAccount
|
||||
import com.tangem.tap.domain.getFirstToken
|
||||
import com.tangem.tap.features.demo.isDemoCard
|
||||
import com.tangem.tap.features.wallet.models.Currency
|
||||
import com.tangem.tap.features.wallet.redux.AddressData
|
||||
import com.tangem.tap.features.wallet.redux.reducers.createAddressesData
|
||||
import com.tangem.tap.network.NetworkConnectivity
|
||||
|
|
@ -30,6 +34,9 @@ suspend fun WalletManager.safeUpdate(): Result<Wallet> = try {
|
|||
Result.Success(wallet)
|
||||
} else {
|
||||
update()
|
||||
if (wallet.blockchain == Blockchain.SaltPay && this is TransactionHistoryProvider) {
|
||||
this.getTransactionHistory(wallet.address, wallet.blockchain, wallet.getTokens())
|
||||
}
|
||||
Result.Success(wallet)
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
|
|
@ -76,10 +83,33 @@ fun WalletManager?.getAddressData(): AddressData? {
|
|||
else addressDataList[0]
|
||||
}
|
||||
|
||||
fun WalletManager.getTxHistory(currency: Currency): List<TransactionData> = wallet.getTxHistory(currency)
|
||||
|
||||
fun WalletManager.getBlockchainTxHistory(): List<TransactionData> = wallet.getBlockchainTxHistory()
|
||||
|
||||
fun WalletManager.getTokenTxHistory(token: Token): List<TransactionData> = wallet.getTokenTxHistory(token)
|
||||
|
||||
fun <T> WalletManager.Companion.stub(): T {
|
||||
val wallet = Wallet(Blockchain.Unknown, setOf(), Wallet.PublicKey(byteArrayOf(), null, null), setOf())
|
||||
return object : WalletManager(wallet) {
|
||||
override val currentHost: String = ""
|
||||
override suspend fun update() {}
|
||||
} as T
|
||||
}
|
||||
|
||||
fun Wallet.getTxHistory(currency: Currency): List<TransactionData> {
|
||||
return (currency as? Currency.Token)?.let { this.getTokenTxHistory(it.token) }
|
||||
?: getBlockchainTxHistory()
|
||||
}
|
||||
|
||||
fun Wallet.getBlockchainTxHistory(): List<TransactionData> {
|
||||
return historyTransactions.filter {
|
||||
it.contractAddress.isNullOrEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
fun Wallet.getTokenTxHistory(token: Token): List<TransactionData> {
|
||||
return historyTransactions.filter {
|
||||
it.contractAddress == token.contractAddress
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue