Updated on 2026-08-14
This commit is contained in:
parent
3baec6cc7e
commit
8564f21d01
9 changed files with 369 additions and 83 deletions
|
|
@ -26,7 +26,7 @@ class DefaultGaslessTransactionRepository(
|
|||
private val responseCryptoCurrenciesFactory: ResponseCryptoCurrenciesFactory,
|
||||
) : GaslessTransactionRepository {
|
||||
|
||||
private val supportedTokensState = MutableStateFlow<Set<CryptoCurrency>?>(null)
|
||||
private val supportedTokensState = MutableStateFlow<Map<Network.ID, Set<CryptoCurrency>>>(hashMapOf())
|
||||
private val gaslessTransactionRequestBuilder = GaslessTransactionRequestBuilder()
|
||||
private val signedTransactionResultConverter = GaslessSignedTransactionResultConverter()
|
||||
|
||||
|
|
@ -37,28 +37,37 @@ class DefaultGaslessTransactionRepository(
|
|||
|
||||
override suspend fun getSupportedTokens(network: Network): Set<CryptoCurrency> {
|
||||
return withContext(coroutineDispatcherProvider.io) {
|
||||
val storedTokens = supportedTokensState.value
|
||||
val storedTokens = supportedTokensState.value[network.id]
|
||||
if (storedTokens != null && storedTokens.isNotEmpty()) {
|
||||
return@withContext storedTokens
|
||||
}
|
||||
|
||||
val supportedTokensData = gaslessTxServiceApi.getSupportedTokens().getOrThrow()
|
||||
if (supportedTokensData.isSuccess) {
|
||||
val supportedTokens = supportedTokensData.result.tokens.mapNotNull { token ->
|
||||
val blockchain = Blockchain.fromChainId(token.chainId) ?: return@mapNotNull null
|
||||
responseCryptoCurrenciesFactory.createToken(
|
||||
blockchain = blockchain,
|
||||
sdkToken = Token(
|
||||
contractAddress = token.tokenAddress,
|
||||
name = token.tokenName,
|
||||
symbol = token.tokenSymbol,
|
||||
decimals = token.decimals,
|
||||
),
|
||||
network = network,
|
||||
)
|
||||
}.toSet()
|
||||
val networkBlockchain = Blockchain.fromNetworkId(network.backendId)
|
||||
?: error("Cannot determine blockchain for network id: ${network.backendId}")
|
||||
val supportedTokens = supportedTokensData.result.tokens
|
||||
.filter {
|
||||
it.chainId == networkBlockchain.getChainId()
|
||||
}
|
||||
.map { token ->
|
||||
responseCryptoCurrenciesFactory.createToken(
|
||||
blockchain = networkBlockchain,
|
||||
sdkToken = Token(
|
||||
contractAddress = token.tokenAddress,
|
||||
name = token.tokenName,
|
||||
symbol = token.tokenSymbol,
|
||||
decimals = token.decimals,
|
||||
),
|
||||
network = network,
|
||||
)
|
||||
}.toSet()
|
||||
// update local cache
|
||||
supportedTokensState.update { supportedTokens }
|
||||
supportedTokensState.update { current ->
|
||||
val newMap = current.toMutableMap()
|
||||
newMap[network.id] = supportedTokens
|
||||
newMap
|
||||
}
|
||||
return@withContext supportedTokens
|
||||
} else {
|
||||
error("Gasless service returned unsuccessful response")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class GaslessTxDataToGaslessRequestConverter : Converter<GaslessTransactionData,
|
|||
)
|
||||
}
|
||||
|
||||
private fun convertTransaction(transaction: com.tangem.domain.transaction.models.Transaction): TransactionData {
|
||||
private fun convertTransaction(transaction: GaslessTransactionData.Transaction): TransactionData {
|
||||
return TransactionData(
|
||||
to = transaction.to,
|
||||
value = transaction.value.toString(),
|
||||
|
|
@ -31,7 +31,7 @@ class GaslessTxDataToGaslessRequestConverter : Converter<GaslessTransactionData,
|
|||
)
|
||||
}
|
||||
|
||||
private fun convertFee(fee: com.tangem.domain.transaction.models.Fee): FeeData {
|
||||
private fun convertFee(fee: GaslessTransactionData.Fee): FeeData {
|
||||
return FeeData(
|
||||
feeToken = fee.feeToken,
|
||||
maxTokenFee = fee.maxTokenFee.toString(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue