Updated on 2026-08-14
This commit is contained in:
parent
c4b1dceb65
commit
8ff70e4615
4 changed files with 2 additions and 38 deletions
|
|
@ -25,14 +25,6 @@ interface SwapInteractor {
|
|||
*/
|
||||
suspend fun searchTokens(networkId: String, searchQuery: String): FoundTokensStateExpress
|
||||
|
||||
/**
|
||||
* Find specific token by id, null if not found
|
||||
*
|
||||
* @param id token id
|
||||
* @return [CryptoCurrency] or null
|
||||
*/
|
||||
fun findTokenById(id: String): CryptoCurrency?
|
||||
|
||||
/**
|
||||
* Gives permission to swap, this starts scan card process
|
||||
*
|
||||
|
|
|
|||
|
|
@ -190,14 +190,6 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
@Deprecated("used in old swap mechanism")
|
||||
override fun findTokenById(id: String): CryptoCurrency? {
|
||||
val tokensInWallet = cache.getInWalletTokens()
|
||||
val loadedTokens = cache.getLoadedTokens()
|
||||
return tokensInWallet.firstOrNull { it.token.id.value == id }?.token
|
||||
?: loadedTokens.firstOrNull { it.token.id.value == id }?.token
|
||||
}
|
||||
|
||||
@Deprecated("used in old swap mechanism")
|
||||
override suspend fun givePermissionToSwap(networkId: String, permissionOptions: PermissionOptions): TxState {
|
||||
val dataToSign = if (permissionOptions.approveType == SwapApproveType.UNLIMITED) {
|
||||
|
|
|
|||
|
|
@ -7,14 +7,12 @@ import java.math.BigDecimal
|
|||
|
||||
interface SwapDataCache {
|
||||
|
||||
fun cacheAvailableToSwapTokens(networkId: String, tokens: List<Currency>)
|
||||
fun cacheInWalletTokens(tokens: List<TokenWithBalanceExpress>)
|
||||
fun cacheLoadedTokens(tokens: List<TokenWithBalanceExpress>)
|
||||
fun cacheBalances(networkId: String, derivationPath: String?, balances: Map<String, SwapAmount>)
|
||||
fun cacheLastFeeForNetwork(fee: BigDecimal, networkId: String)
|
||||
fun getAvailableTokens(networkId: String): List<Currency>
|
||||
|
||||
|
||||
fun getInWalletTokens(): List<TokenWithBalanceExpress>
|
||||
fun getLoadedTokens(): List<TokenWithBalanceExpress>
|
||||
fun getBalanceForToken(networkId: String, derivationPath: String?, symbol: String): SwapAmount?
|
||||
fun getLastFeeForNetwork(networkId: String): BigDecimal?
|
||||
}
|
||||
|
|
@ -7,16 +7,10 @@ import java.math.BigDecimal
|
|||
|
||||
class SwapDataCacheImpl : SwapDataCache {
|
||||
|
||||
private val availableTokensForNetwork: MutableMap<String, List<Currency>> = mutableMapOf()
|
||||
private val feesForNetworks: MutableMap<String, BigDecimal> = mutableMapOf()
|
||||
private val tokensBalances: MutableMap<String, Map<String, SwapAmount>> = mutableMapOf()
|
||||
private val lastInWalletTokens = mutableListOf<TokenWithBalanceExpress>()
|
||||
private val lastLoadedTokens = mutableListOf<TokenWithBalanceExpress>()
|
||||
|
||||
override fun cacheLastFeeForNetwork(fee: BigDecimal, networkId: String) {
|
||||
feesForNetworks[networkId] = fee
|
||||
}
|
||||
|
||||
override fun cacheInWalletTokens(tokens: List<TokenWithBalanceExpress>) {
|
||||
lastInWalletTokens.clear()
|
||||
lastInWalletTokens.addAll(tokens)
|
||||
|
|
@ -43,18 +37,6 @@ class SwapDataCacheImpl : SwapDataCache {
|
|||
tokensBalances[createKeyFrom(networkId, derivationPath)] = balances
|
||||
}
|
||||
|
||||
override fun cacheAvailableToSwapTokens(networkId: String, tokens: List<Currency>) {
|
||||
availableTokensForNetwork[networkId] = tokens
|
||||
}
|
||||
|
||||
override fun getLastFeeForNetwork(networkId: String): BigDecimal? {
|
||||
return feesForNetworks[networkId]
|
||||
}
|
||||
|
||||
override fun getAvailableTokens(networkId: String): List<Currency> {
|
||||
return availableTokensForNetwork.getOrElse(networkId) { emptyList() }
|
||||
}
|
||||
|
||||
private fun createKeyFrom(networkId: String, derivationPath: String?): String {
|
||||
return "$networkId;$derivationPath"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue