Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core-db/src/main/java/jp/co/soramitsu/core_db/dao/TokenDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ abstract class TokenDao {
@Query("select * from tokens where symbol = :symbol")
abstract fun observeToken(symbol: String): Flow<TokenLocal>

@Query("delete from tokens")
abstract suspend fun clearTokens()

@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract suspend fun insertToken(token: TokenLocal)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class AssetCache(
}
}

suspend fun clearTokens() = tokenDao.clearTokens()

suspend fun updateToken(
symbol: String,
builder: (local: TokenLocal) -> TokenLocal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ interface WalletInteractor {
suspend fun enableCustomAssetSorting()

suspend fun customAssetSortingEnabled(): Boolean

suspend fun clearTokens()
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,6 @@ interface WalletRepository {
suspend fun getAccountFreeBalance(chainId: ChainId, accountId: AccountId): BigInteger

suspend fun updateAssets(newItems: List<AssetUpdateItem>)

suspend fun clearTokens()
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ class WalletRepositoryImpl(
assetCache.updateAsset(newItems)
}

override suspend fun clearTokens() {
assetCache.clearTokens()
}

private fun createOperation(
hash: String,
transfer: Transfer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,8 @@ class WalletInteractorImpl(
val metaId = accountRepository.getSelectedMetaAccount().id
preferences.putBoolean("$CUSTOM_ASSET_SORTING_PREFS_KEY$metaId", true)
}

override suspend fun clearTokens() {
walletRepository.clearTokens()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import java.math.BigDecimal
val fiatRateExtractor = { item: AssetWithStateModel -> item.asset.token.fiatRate }
val recentChangeExtractor = { item: AssetWithStateModel -> item.asset.token.recentRateChange }
val totalExtractor = { item: AssetWithStateModel -> item.asset.total }
val stateExtractor = { item: AssetWithStateModel -> item.state }

class BalanceListAdapter(
private val imageLoader: ImageLoader,
Expand Down Expand Up @@ -70,6 +71,7 @@ class BalanceListAdapter(

resolvePayload(holder, position, payloads) {
when (it) {
stateExtractor -> holder.bindState(model)
fiatRateExtractor -> holder.bindFiatInfo(model)
recentChangeExtractor -> holder.bindRecentChange(model)
totalExtractor -> holder.bindTotal(model)
Expand Down Expand Up @@ -97,32 +99,20 @@ class AssetViewHolder(

fun bind(model: AssetWithStateModel, itemHandler: BalanceListAdapter.ItemAssetHandler) {
val asset = model.asset
val state = model.state

content.itemAssetImage.load(asset.token.configuration.iconUrl, imageLoader)
shimmer.itemAssetImage.load(asset.token.configuration.iconUrl, imageLoader)
content.itemAssetImage.setVisible(state.chainUpdate == false, View.INVISIBLE)
shimmer.itemAssetImage.setVisible(state.chainUpdate != false, View.INVISIBLE)

content.itemAssetNetwork.text = asset.token.configuration.name
shimmer.itemAssetNetwork.text = asset.token.configuration.name
content.itemAssetNetwork.setVisible(state.chainUpdate == false, View.INVISIBLE)
shimmer.itemAssetNetwork.setVisible(state.chainUpdate != false, View.INVISIBLE)

content.itemAssetToken.text = asset.token.configuration.symbol
shimmer.itemAssetToken.text = asset.token.configuration.symbol
content.itemAssetToken.setVisible(state.chainUpdate == false, View.INVISIBLE)
shimmer.itemAssetToken.setVisible(state.chainUpdate != false, View.INVISIBLE)

content.networkBadge.setText(asset.token.configuration.chainName)
content.networkBadge.setIcon(asset.token.configuration.chainIcon, imageLoader)
shimmer.networkBadge.setText(asset.token.configuration.chainName)
shimmer.networkBadge.setIcon(asset.token.configuration.chainIcon, imageLoader)
content.networkBadge.isVisible = !asset.token.configuration.isNative && state.chainUpdate == false
shimmer.networkBadge.isVisible = !asset.token.configuration.isNative && state.chainUpdate != false

content.testnetBadge.isVisible = asset.token.configuration.isTestNet == true && state.chainUpdate == false
shimmer.testnetBadge.isVisible = asset.token.configuration.isTestNet == true && state.chainUpdate != false

content.setOnClickListener { itemHandler.assetClicked(asset) }
shimmer.setOnClickListener { itemHandler.assetClicked(asset) }
Expand All @@ -131,6 +121,29 @@ class AssetViewHolder(
content.chainAssetNameBadge.background = content.context.getCutLeftBottomCornerDrawableFromColors()
shimmer.chainAssetNameBadge.text = asset.chainAccountName
shimmer.chainAssetNameBadge.background = content.context.getCutLeftBottomCornerDrawableFromColors()

bindState(model)
}

fun bindState(model: AssetWithStateModel) {
val asset = model.asset
val state = model.state

content.itemAssetImage.setVisible(state.chainUpdate == false, View.INVISIBLE)
shimmer.itemAssetImage.setVisible(state.chainUpdate != false, View.INVISIBLE)

content.itemAssetNetwork.setVisible(state.chainUpdate == false, View.INVISIBLE)
shimmer.itemAssetNetwork.setVisible(state.chainUpdate != false, View.INVISIBLE)

content.itemAssetToken.setVisible(state.chainUpdate == false, View.INVISIBLE)
shimmer.itemAssetToken.setVisible(state.chainUpdate != false, View.INVISIBLE)

content.networkBadge.isVisible = !asset.token.configuration.isNative && state.chainUpdate == false
shimmer.networkBadge.isVisible = !asset.token.configuration.isNative && state.chainUpdate != false

content.testnetBadge.isVisible = asset.token.configuration.isTestNet == true && state.chainUpdate == false
shimmer.testnetBadge.isVisible = asset.token.configuration.isTestNet == true && state.chainUpdate != false

content.chainAssetNameBadge.isVisible = !asset.chainAccountName.isNullOrEmpty() && state.chainUpdate == false
shimmer.chainAssetNameBadge.isVisible = !asset.chainAccountName.isNullOrEmpty() && state.chainUpdate != false

Expand Down Expand Up @@ -195,12 +208,11 @@ private object AssetDiffCallback : DiffUtil.ItemCallback<AssetWithStateModel>()
return oldItem == newItem
}

// todo restore logic
// override fun getChangePayload(oldItem: AssetWithStateModel, newItem: AssetWithStateModel): Any? {
// return AssetPayloadGenerator.diff(oldItem, newItem)
// }
override fun getChangePayload(oldItem: AssetWithStateModel, newItem: AssetWithStateModel): Any? {
return AssetPayloadGenerator.diff(oldItem, newItem)
}
}

private object AssetPayloadGenerator : PayloadGenerator<AssetWithStateModel>(
fiatRateExtractor, recentChangeExtractor, totalExtractor
fiatRateExtractor, recentChangeExtractor, totalExtractor, stateExtractor
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class BalanceListFragment : BaseFragment<BalanceListViewModel>(), BalanceListAda

private lateinit var adapter: BalanceListAdapter

private var previousFiat: String? = null

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -104,6 +106,13 @@ class BalanceListFragment : BaseFragment<BalanceListViewModel>(), BalanceListAda
walletContainer.isRefreshing = false
}

viewModel.fiatSymbolFlow.observe {
if (previousFiat != it) {
viewModel.clearTokens()
previousFiat = it
}
}

viewModel.showFiatChooser.observeEvent(::showFiatChooser)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class BalanceListViewModel(

val currentAddressModelLiveData = currentAddressModelFlow().asLiveData()

private val fiatSymbolLiveData =
combine(selectedFiat.flow(), getAvailableFiatCurrencies.flow()) { selectedFiat: String, fiatCurrencies: FiatCurrencies ->
fiatCurrencies[selectedFiat]?.symbol
}.asLiveData()
val fiatSymbolFlow = combine(selectedFiat.flow(), getAvailableFiatCurrencies.flow()) { selectedFiat: String, fiatCurrencies: FiatCurrencies ->
fiatCurrencies[selectedFiat]?.symbol
}
private val fiatSymbolLiveData = fiatSymbolFlow.asLiveData()
private val assetModelsLiveData = assetModelsFlow().asLiveData()

val balanceLiveData = mediateWith(
Expand Down Expand Up @@ -139,4 +139,10 @@ class BalanceListViewModel(
selectedFiat.set(item.id)
}
}

fun clearTokens() {
launch {
interactor.clearTokens()
}
}
}