Updated on 2026-08-14

This commit is contained in:
Tangem 2025-12-18 20:02:54 +05:00
parent ec59339d51
commit 9be5646b78
6 changed files with 36 additions and 68 deletions

View file

@ -139,13 +139,13 @@ internal class DefaultOnboardingRepository @Inject constructor(
response: CustomerMeResponse.Result?,
): CustomerInfo {
val card = response?.card
val balance = response?.balance
val fiatBalance = response?.balance?.fiat
val paymentAccount = response?.paymentAccount
val cardInfo = if (paymentAccount != null && card != null && balance != null) {
val cardInfo = if (paymentAccount != null && card != null && fiatBalance != null) {
CardInfo(
lastFourDigits = card.cardNumberEnd,
balance = balance.fiat.availableBalance,
currencyCode = balance.fiat.currency,
balance = fiatBalance.availableBalance,
currencyCode = fiatBalance.currency,
customerWalletAddress = paymentAccount.customerWalletAddress,
depositAddress = response.depositAddress,
)

View file

@ -52,20 +52,29 @@ internal class DefaultTangemPayCardDetailsRepository @Inject constructor(
private val storePollingMutex = Mutex()
override suspend fun getCardBalance(userWalletId: UserWalletId): Either<UniversalError, TangemPayCardBalance> {
return requestHelper.runWithErrorLogs(TAG) {
val result = requestHelper.request(userWalletId) { authHeader ->
tangemPayApi.getCardBalance(authHeader)
}.result ?: error("Cannot get card balance")
TangemPayCardBalance(
fiatBalance = result.fiat.availableBalance,
currencyCode = result.fiat.currency,
cryptoBalance = result.crypto.balance,
availableForWithdrawal = result.availableForWithdrawal.amount,
chainId = result.crypto.chainId,
depositAddress = result.crypto.depositAddress,
contractAddress = result.crypto.tokenContractAddress,
)
}
return catch(
block = {
val response = requestHelper.performRequest(userWalletId) { authHeader ->
tangemPayApi.getCardBalance(authHeader)
}.getOrNull()
val fiatBalance = requireNotNull(response?.result?.fiat) { "Cannot get card balance fiat" }
val cryptoBalance = requireNotNull(response.result?.crypto) { "Cannot get card balance crypto" }
val withdrawalAmount = requireNotNull(response.result?.availableForWithdrawal) {
"Cannot get card balance availableForWithdrawal"
}
TangemPayCardBalance(
fiatBalance = fiatBalance.availableBalance,
currencyCode = fiatBalance.currency,
cryptoBalance = cryptoBalance.balance,
availableForWithdrawal = withdrawalAmount.amount,
chainId = cryptoBalance.chainId,
depositAddress = cryptoBalance.depositAddress,
contractAddress = cryptoBalance.tokenContractAddress,
).right()
},
catch = ::catchException,
)
}
override suspend fun revealCardDetails(userWalletId: UserWalletId): Either<UniversalError, TangemPayCardDetails> {
@ -100,7 +109,7 @@ internal class DefaultTangemPayCardDetailsRepository @Inject constructor(
expirationMonth = result.expirationMonth,
).right()
},
catch = { errorConverter.convert(it).left() },
catch = ::catchException,
)
}
@ -285,6 +294,11 @@ internal class DefaultTangemPayCardDetailsRepository @Inject constructor(
}
}
private fun <T> catchException(throwable: Throwable): Either<UniversalError, T> {
Timber.tag(TAG).e(throwable)
return errorConverter.convert(throwable).left()
}
private companion object {
const val MAX_POLLING_RETRIES = 3
}