Updated on 2026-08-14
This commit is contained in:
parent
1474d83756
commit
725705ecf2
9 changed files with 64 additions and 36 deletions
|
|
@ -0,0 +1,20 @@
|
|||
package com.tangem.tap.features.wallet.data
|
||||
|
||||
import com.tangem.datasource.api.tangemTech.TangemTechApi
|
||||
import com.tangem.datasource.api.tangemTech.models.CurrenciesResponse
|
||||
import com.tangem.tap.features.wallet.domain.WalletRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* Implementation of repository for Wallet feature
|
||||
*
|
||||
* @property tangemTechApi API for server requests
|
||||
*/
|
||||
class WalletRepositoryImpl(private val tangemTechApi: TangemTechApi) : WalletRepository {
|
||||
|
||||
override suspend fun getCurrencyList(): CurrenciesResponse =
|
||||
withContext(Dispatchers.IO) { // TODO("After adding DI") replace with CoroutineDispatcherProvider
|
||||
tangemTechApi.getCurrencyList()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.tangem.tap.features.wallet.domain
|
||||
|
||||
import com.tangem.datasource.api.tangemTech.models.CurrenciesResponse
|
||||
|
||||
/** Repository for Wallet feature */
|
||||
interface WalletRepository {
|
||||
|
||||
/** Get list of currency */
|
||||
suspend fun getCurrencyList(): CurrenciesResponse
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
package com.tangem.tap.features.wallet.redux.middlewares
|
||||
|
||||
import com.tangem.common.services.Result
|
||||
import com.tangem.datasource.api.tangemTech.CurrenciesResponse
|
||||
import com.tangem.datasource.api.tangemTech.TangemTechService
|
||||
import com.tangem.datasource.api.tangemTech.models.Currency
|
||||
import com.tangem.tap.common.analytics.Analytics
|
||||
import com.tangem.tap.common.analytics.events.AnalyticsParam
|
||||
import com.tangem.tap.common.analytics.events.MainScreen
|
||||
|
|
@ -11,6 +9,7 @@ import com.tangem.tap.common.extensions.dispatchDialogShow
|
|||
import com.tangem.tap.common.redux.global.GlobalAction
|
||||
import com.tangem.tap.domain.TapWalletManager
|
||||
import com.tangem.tap.features.details.redux.DetailsAction
|
||||
import com.tangem.tap.features.wallet.domain.WalletRepository
|
||||
import com.tangem.tap.features.wallet.redux.WalletAction
|
||||
import com.tangem.tap.features.wallet.redux.models.WalletDialog
|
||||
import com.tangem.tap.features.walletSelector.redux.WalletSelectorAction
|
||||
|
|
@ -21,7 +20,7 @@ import com.tangem.tap.userWalletsListManager
|
|||
import kotlinx.coroutines.launch
|
||||
|
||||
class AppCurrencyMiddleware(
|
||||
private val tangemTechService: TangemTechService,
|
||||
private val walletRepository: WalletRepository,
|
||||
private val tapWalletManager: TapWalletManager,
|
||||
private val fiatCurrenciesPrefStorage: FiatCurrenciesPrefStorage,
|
||||
private val appCurrencyProvider: () -> FiatCurrency,
|
||||
|
|
@ -45,12 +44,10 @@ class AppCurrencyMiddleware(
|
|||
}
|
||||
|
||||
scope.launch {
|
||||
when (val result = tangemTechService.currencies()) {
|
||||
is Result.Success -> {
|
||||
val currenciesList = result.data.currencies
|
||||
if (currenciesList.isNotEmpty() &&
|
||||
currenciesList.toSet() != storedFiatCurrencies.toSet()
|
||||
) {
|
||||
runCatching { walletRepository.getCurrencyList() }
|
||||
.onSuccess {
|
||||
val currenciesList = it.currencies
|
||||
if (currenciesList.isNotEmpty() && !currenciesList.toSet().equals(storedFiatCurrencies.toSet())) {
|
||||
fiatCurrenciesPrefStorage.save(currenciesList)
|
||||
store.dispatchDialogShow(
|
||||
WalletDialog.CurrencySelectionDialog(
|
||||
|
|
@ -60,8 +57,6 @@ class AppCurrencyMiddleware(
|
|||
)
|
||||
}
|
||||
}
|
||||
is Result.Failure -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +77,7 @@ class AppCurrencyMiddleware(
|
|||
}
|
||||
}
|
||||
|
||||
private fun List<CurrenciesResponse.Currency>.mapToUiModel(): List<FiatCurrency> {
|
||||
private fun List<Currency>.mapToUiModel(): List<FiatCurrency> {
|
||||
return this.map {
|
||||
FiatCurrency(
|
||||
code = it.code,
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import com.tangem.tap.domain.model.WalletStoreModel
|
|||
import com.tangem.tap.features.demo.DemoHelper
|
||||
import com.tangem.tap.features.home.redux.HomeAction
|
||||
import com.tangem.tap.features.send.redux.PrepareSendScreen
|
||||
import com.tangem.tap.features.wallet.data.WalletRepositoryImpl
|
||||
import com.tangem.tap.features.wallet.models.Currency
|
||||
import com.tangem.tap.features.wallet.models.PendingTransactionType
|
||||
import com.tangem.tap.features.wallet.models.filterByCoin
|
||||
|
|
@ -72,7 +73,8 @@ class WalletMiddleware {
|
|||
private val walletDialogMiddleware = WalletDialogsMiddleware()
|
||||
private val appCurrencyMiddleware by lazy(mode = LazyThreadSafetyMode.NONE) {
|
||||
AppCurrencyMiddleware(
|
||||
tangemTechService = store.state.domainNetworks.tangemTechService,
|
||||
// TODO("After adding DI") get dependencies by DI
|
||||
walletRepository = WalletRepositoryImpl(store.state.domainNetworks.tangemTechService.api),
|
||||
tapWalletManager = store.state.globalState.tapWalletManager,
|
||||
fiatCurrenciesPrefStorage = preferencesStorage.fiatCurrenciesPrefStorage,
|
||||
appCurrencyProvider = { store.state.globalState.appCurrency },
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package com.tangem.tap.persistence
|
|||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import com.tangem.common.json.MoshiJsonConverter
|
||||
import com.tangem.datasource.api.tangemTech.CurrenciesResponse
|
||||
import com.tangem.datasource.api.tangemTech.models.Currency
|
||||
import com.tangem.tap.common.entities.FiatCurrency
|
||||
|
||||
/**
|
||||
|
|
@ -32,14 +32,14 @@ class FiatCurrenciesPrefStorage(
|
|||
preferences.edit { putString(APP_CURRENCY_KEY, json) }
|
||||
}
|
||||
|
||||
fun save(currencies: List<CurrenciesResponse.Currency>) {
|
||||
fun save(currencies: List<Currency>) {
|
||||
val json: String = converter.toJson(currencies)
|
||||
return preferences.edit().putString(FIAT_CURRENCIES_KEY, json).apply()
|
||||
}
|
||||
|
||||
fun restore(): List<CurrenciesResponse.Currency> {
|
||||
fun restore(): List<Currency> {
|
||||
val json = preferences.getString(FIAT_CURRENCIES_KEY, "")
|
||||
val type = converter.typedList(CurrenciesResponse.Currency::class.java)
|
||||
val type = converter.typedList(Currency::class.java)
|
||||
if (json.isNullOrBlank()) return emptyList()
|
||||
|
||||
return converter.fromJson(json, type) ?: emptyList()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue