Updated on 2026-08-14
This commit is contained in:
parent
f9ace58267
commit
5dec166e7c
7 changed files with 74 additions and 39 deletions
|
|
@ -1,9 +1,8 @@
|
|||
package com.tangem.lib.visa
|
||||
|
||||
import arrow.fx.coroutines.parZip
|
||||
import com.tangem.lib.visa.model.VisaBalancesAndLimits
|
||||
import com.tangem.lib.visa.model.VisaBalancesAndLimits.Balances
|
||||
import com.tangem.lib.visa.model.VisaBalancesAndLimits.Limits
|
||||
import com.tangem.lib.visa.model.VisaContractInfo
|
||||
import com.tangem.lib.visa.model.VisaContractInfo.*
|
||||
import com.tangem.lib.visa.utils.toBigDecimal
|
||||
import com.tangem.lib.visa.utils.toInstant
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
|
|
@ -21,7 +20,7 @@ internal class DefaultVisaContractInfoProvider(
|
|||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) : VisaContractInfoProvider {
|
||||
|
||||
override suspend fun getBalancesAndLimits(walletAddress: String): VisaBalancesAndLimits {
|
||||
override suspend fun getContractInfo(walletAddress: String): VisaContractInfo {
|
||||
return parZip(
|
||||
dispatchers.io,
|
||||
{ loadPaymentAccount(walletAddress) },
|
||||
|
|
@ -64,15 +63,35 @@ internal class DefaultVisaContractInfoProvider(
|
|||
private suspend fun fetchBalancesAndLimits(
|
||||
paymentAccount: TangemPaymentAccount,
|
||||
paymentToken: PaymentTokenInfo,
|
||||
): VisaBalancesAndLimits = parZip(
|
||||
): VisaContractInfo = parZip(
|
||||
dispatchers.io,
|
||||
{ fetchToken(paymentAccount) },
|
||||
{ fetchBalances(paymentAccount, paymentToken) },
|
||||
{ fetchLimits(paymentAccount, paymentToken) },
|
||||
{ balances, (oldLimit, newLimit, changeDate) ->
|
||||
VisaBalancesAndLimits(balances, oldLimit, newLimit, changeDate)
|
||||
{ token, balances, (oldLimit, newLimit, changeDate) ->
|
||||
VisaContractInfo(token, balances, oldLimit, newLimit, changeDate)
|
||||
},
|
||||
)
|
||||
|
||||
private suspend fun fetchToken(paymentAccount: TangemPaymentAccount): Token {
|
||||
val paymentTokenContractAddress = paymentAccount.paymentToken().send()
|
||||
val paymentTokenContract = ERC20.load(paymentTokenContractAddress, web3j, transactionManager, gasProvider)
|
||||
|
||||
return parZip(
|
||||
dispatchers.io,
|
||||
{ paymentTokenContract.name().send() },
|
||||
{ paymentTokenContract.symbol().send() },
|
||||
{ paymentTokenContract.decimals().send() },
|
||||
) { name, symbol, decimals ->
|
||||
Token(
|
||||
name = name,
|
||||
symbol = symbol,
|
||||
decimals = decimals.toInt(),
|
||||
address = paymentTokenContractAddress,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun fetchBalances(paymentAccount: TangemPaymentAccount, paymentToken: PaymentTokenInfo): Balances {
|
||||
return parZip(
|
||||
dispatchers.io,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package com.tangem.lib.visa
|
|||
|
||||
import com.ihsanbal.logging.Level
|
||||
import com.ihsanbal.logging.LoggingInterceptor
|
||||
import com.tangem.lib.visa.model.VisaBalancesAndLimits
|
||||
import com.tangem.lib.visa.model.VisaContractInfo
|
||||
import com.tangem.lib.visa.utils.VisaConfig
|
||||
import com.tangem.lib.visa.utils.VisaConfig.NETWORK_LOGS_TAG
|
||||
import com.tangem.lib.visa.utils.toHexString
|
||||
|
|
@ -21,7 +21,7 @@ import java.util.concurrent.TimeUnit
|
|||
|
||||
interface VisaContractInfoProvider {
|
||||
|
||||
suspend fun getBalancesAndLimits(walletAddress: String): VisaBalancesAndLimits
|
||||
suspend fun getContractInfo(walletAddress: String): VisaContractInfo
|
||||
|
||||
class Builder(
|
||||
private val isNetworkLoggingEnabled: Boolean,
|
||||
|
|
|
|||
|
|
@ -4,13 +4,21 @@ import org.joda.time.Instant
|
|||
import java.math.BigDecimal
|
||||
import java.math.BigInteger
|
||||
|
||||
data class VisaBalancesAndLimits(
|
||||
data class VisaContractInfo(
|
||||
val token: Token,
|
||||
val balances: Balances,
|
||||
val oldLimits: Limits,
|
||||
val newLimits: Limits,
|
||||
val limitsChangeDate: Instant,
|
||||
) {
|
||||
|
||||
data class Token(
|
||||
val name: String,
|
||||
val symbol: String,
|
||||
val decimals: Int,
|
||||
val address: String,
|
||||
)
|
||||
|
||||
data class Balances(
|
||||
val total: BigDecimal,
|
||||
val verified: BigDecimal,
|
||||
Loading…
Add table
Add a link
Reference in a new issue