Updated on 2026-08-14
This commit is contained in:
parent
f9369de36a
commit
448a472832
7 changed files with 164 additions and 40 deletions
|
|
@ -48,11 +48,14 @@ class TokenItemStateConverter(
|
|||
private val iconStateProvider: (CryptoCurrencyStatus) -> CurrencyIconState = {
|
||||
CryptoCurrencyToIconStateConverter().convert(it)
|
||||
},
|
||||
private val onApyLabelClick: ((CryptoCurrencyStatus) -> Unit)? = null,
|
||||
private val titleStateProvider: (CryptoCurrencyStatus) -> TokenItemState.TitleState = {
|
||||
createTitleState(it, yieldModuleApyMap, stakingApyMap, {
|
||||
onApyLabelClick?.invoke(it)
|
||||
})
|
||||
private val onApyLabelClick: ((CryptoCurrencyStatus, String) -> Unit)? = null,
|
||||
private val titleStateProvider: (CryptoCurrencyStatus) -> TokenItemState.TitleState = { currencyStatus ->
|
||||
createTitleState(
|
||||
currencyStatus = currencyStatus,
|
||||
yieldModuleApyMap = yieldModuleApyMap,
|
||||
stakingApyMap = stakingApyMap,
|
||||
onApyLabelClick = onApyLabelClick,
|
||||
)
|
||||
},
|
||||
private val subtitleStateProvider: (CryptoCurrencyStatus) -> TokenItemState.SubtitleState? = {
|
||||
createSubtitleState(it, appCurrency)
|
||||
|
|
@ -105,9 +108,6 @@ class TokenItemStateConverter(
|
|||
onItemLongClick = onItemLongClick?.let { onItemLongClick ->
|
||||
{ onItemLongClick(it, this) }
|
||||
},
|
||||
onApyLabelClick = onApyLabelClick?.let { onApyLabelClick ->
|
||||
{ onApyLabelClick(this) }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +166,7 @@ class TokenItemStateConverter(
|
|||
currencyStatus: CryptoCurrencyStatus,
|
||||
yieldModuleApyMap: Map<String, String>,
|
||||
stakingApyMap: Map<String, List<Yield.Validator>>,
|
||||
onApyLabelClick: () -> Unit,
|
||||
onApyLabelClick: ((CryptoCurrencyStatus, String) -> Unit)?,
|
||||
): TokenItemState.TitleState {
|
||||
return when (val value = currencyStatus.value) {
|
||||
is CryptoCurrencyStatus.Loading,
|
||||
|
|
@ -181,7 +181,7 @@ class TokenItemStateConverter(
|
|||
is CryptoCurrencyStatus.NoQuote,
|
||||
is CryptoCurrencyStatus.NoAccount,
|
||||
-> {
|
||||
val (earnApyText, isActive) = resolveEarnApy(
|
||||
val apyInfo = resolveEarnApy(
|
||||
cryptoCurrencyStatus = currencyStatus,
|
||||
yieldModuleApyMap = yieldModuleApyMap,
|
||||
stakingApyMap = stakingApyMap,
|
||||
|
|
@ -189,9 +189,13 @@ class TokenItemStateConverter(
|
|||
TokenItemState.TitleState.Content(
|
||||
text = stringReference(currencyStatus.currency.name),
|
||||
hasPending = value.hasCurrentNetworkTransactions,
|
||||
earnApy = earnApyText,
|
||||
earnApyIsActive = isActive,
|
||||
onApyLabelClick = onApyLabelClick,
|
||||
earnApy = apyInfo?.text,
|
||||
earnApyIsActive = apyInfo?.isActive == true,
|
||||
onApyLabelClick = if (apyInfo?.apy != null && onApyLabelClick != null) {
|
||||
{ onApyLabelClick.invoke(currencyStatus, apyInfo.apy) }
|
||||
} else {
|
||||
null
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -202,7 +206,7 @@ class TokenItemStateConverter(
|
|||
cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
yieldModuleApyMap: Map<String, String>,
|
||||
stakingApyMap: Map<String, List<Yield.Validator>>,
|
||||
): Pair<TextReference?, Boolean> {
|
||||
): EarnApyInfo? {
|
||||
val token = cryptoCurrencyStatus.currency as? CryptoCurrency.Token
|
||||
if (token != null && yieldModuleApyMap.isNotEmpty()) {
|
||||
val yieldSupplyApy = yieldModuleApyMap.entries.firstOrNull {
|
||||
|
|
@ -213,10 +217,14 @@ class TokenItemStateConverter(
|
|||
}?.value
|
||||
if (yieldSupplyApy != null) {
|
||||
val isActive = cryptoCurrencyStatus.value.yieldSupplyStatus?.isActive ?: false
|
||||
return resourceReference(
|
||||
R.string.yield_module_earn_badge,
|
||||
wrappedList(yieldSupplyApy),
|
||||
) to isActive
|
||||
return EarnApyInfo(
|
||||
text = resourceReference(
|
||||
R.string.yield_module_earn_badge,
|
||||
wrappedList(yieldSupplyApy),
|
||||
),
|
||||
isActive = isActive,
|
||||
apy = yieldSupplyApy,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,14 +241,19 @@ class TokenItemStateConverter(
|
|||
-> R.string.yield_module_earn_badge
|
||||
}
|
||||
if (stakingInfo.rate != null) {
|
||||
return resourceReference(
|
||||
rewardTypeRes,
|
||||
wrappedList(stakingInfo.rate.format { percent(withPercentSign = false) }),
|
||||
) to stakingInfo.isActive
|
||||
val apyString = stakingInfo.rate.format { percent(withPercentSign = false) }
|
||||
return EarnApyInfo(
|
||||
text = resourceReference(
|
||||
rewardTypeRes,
|
||||
wrappedList(apyString),
|
||||
),
|
||||
isActive = stakingInfo.isActive,
|
||||
apy = apyString,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return null to false
|
||||
return null
|
||||
}
|
||||
|
||||
private fun findStakingRate(
|
||||
|
|
@ -412,4 +425,10 @@ class TokenItemStateConverter(
|
|||
val isActive: Boolean,
|
||||
val rewardType: Yield.RewardType?,
|
||||
)
|
||||
|
||||
private data class EarnApyInfo(
|
||||
val text: TextReference?,
|
||||
val isActive: Boolean,
|
||||
val apy: String?,
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue