Skip to content

Commit 92e26b7

Browse files
authored
Merge pull request #915 from soramitsu/fixes/FLW-3223-3323-3251
fixes/FLW-3223-3323-3251
2 parents 1d91227 + 2f2a797 commit 92e26b7

File tree

9 files changed

+72
-24
lines changed

9 files changed

+72
-24
lines changed

common/src/main/java/jp/co/soramitsu/common/compose/component/AssetListItem.kt

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.height
1212
import androidx.compose.foundation.layout.padding
1313
import androidx.compose.foundation.layout.size
1414
import androidx.compose.foundation.layout.width
15+
import androidx.compose.material.Card
1516
import androidx.compose.material.Divider
1617
import androidx.compose.material.Icon
1718
import androidx.compose.material.MaterialTheme
@@ -26,16 +27,19 @@ import androidx.compose.ui.graphics.Color
2627
import androidx.compose.ui.platform.LocalContext
2728
import androidx.compose.ui.platform.testTag
2829
import androidx.compose.ui.res.painterResource
30+
import androidx.compose.ui.res.stringResource
2931
import androidx.compose.ui.tooling.preview.Preview
3032
import androidx.compose.ui.unit.dp
3133
import coil.compose.AsyncImage
3234
import com.valentinilk.shimmer.shimmer
3335
import jp.co.soramitsu.common.R
3436
import jp.co.soramitsu.common.compose.theme.FearlessTheme
3537
import jp.co.soramitsu.common.compose.theme.alertYellow
38+
import jp.co.soramitsu.common.compose.theme.bold
3639
import jp.co.soramitsu.common.compose.theme.customColors
3740
import jp.co.soramitsu.common.compose.theme.customTypography
3841
import jp.co.soramitsu.common.compose.theme.white16
42+
import jp.co.soramitsu.common.compose.theme.white64
3943
import jp.co.soramitsu.common.compose.viewstate.AssetListItemShimmerViewState
4044
import jp.co.soramitsu.common.compose.viewstate.AssetListItemViewState
4145

@@ -88,13 +92,19 @@ fun AssetListItem(
8892
.padding(vertical = 8.dp)
8993
.align(CenterVertically)
9094
) {
91-
Text(
92-
text = state.assetName.uppercase(),
93-
style = MaterialTheme.customTypography.capsTitle2,
94-
modifier = Modifier
95-
.alpha(0.64f)
96-
.testTag("AssetListItem_${state.assetSymbol}_chain_name")
97-
)
95+
Row {
96+
Text(
97+
text = state.assetName.uppercase(),
98+
style = MaterialTheme.customTypography.capsTitle2,
99+
modifier = Modifier
100+
.alpha(0.64f)
101+
.testTag("AssetListItem_${state.assetSymbol}_chain_name")
102+
)
103+
if (state.isTestnet) {
104+
MarginHorizontal(margin = 4.dp)
105+
TestnetBadge()
106+
}
107+
}
98108
Text(
99109
text = state.displayName.uppercase(),
100110
style = MaterialTheme.customTypography.header3,
@@ -184,6 +194,31 @@ fun AssetListItem(
184194
}
185195
}
186196

197+
@Composable
198+
fun TestnetBadge() {
199+
Card(backgroundColor = white16) {
200+
Row(
201+
modifier = Modifier
202+
.padding(bottom = 2.dp, start = 2.dp, end = 4.dp),
203+
verticalAlignment = CenterVertically
204+
) {
205+
Icon(
206+
modifier = Modifier
207+
.width(16.dp)
208+
.padding(top = 1.dp),
209+
painter = painterResource(R.drawable.ic_token_testnet),
210+
tint = white64,
211+
contentDescription = null
212+
)
213+
MarginHorizontal(margin = 4.dp)
214+
Text(
215+
text = stringResource(id = R.string.label_testnet).uppercase(),
216+
style = MaterialTheme.customTypography.body3.bold().copy(color = white64)
217+
)
218+
}
219+
}
220+
}
221+
187222
@Composable
188223
fun AssetListItemShimmer(
189224
state: AssetListItemShimmerViewState,
@@ -324,13 +359,14 @@ private fun PreviewAssetListItem() {
324359
hasAccount = true,
325360
priceId = null,
326361
hasNetworkIssue = false,
327-
ecosystem = "Polkadot"
362+
ecosystem = "Polkadot",
363+
isTestnet = false
328364
)
329365
FearlessTheme {
330366
Box(modifier = Modifier.background(Color.Black)) {
331367
Column {
332368
AssetListItem(state) {}
333-
AssetListItem(state.copy(hasAccount = false)) {}
369+
AssetListItem(state.copy(hasAccount = false, isTestnet = true)) {}
334370
AssetListItemShimmer(
335371
state = AssetListItemShimmerViewState(assetIconUrl, assetChainUrlsMap.values.toList())
336372
)

common/src/main/java/jp/co/soramitsu/common/compose/component/SwipeBox.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ private fun AssetItemSwipeBoxPreview() {
186186
hasAccount = true,
187187
priceId = null,
188188
hasNetworkIssue = false,
189-
ecosystem = "Polkadot"
189+
ecosystem = "Polkadot",
190+
isTestnet = false
190191
)
191192

192193
Column(modifier = Modifier.padding(horizontal = 16.dp)) {

common/src/main/java/jp/co/soramitsu/common/compose/viewstate/AssetListItemViewState.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ data class AssetListItemViewState(
1818
val hasAccount: Boolean,
1919
val priceId: String?,
2020
val hasNetworkIssue: Boolean,
21-
val ecosystem: String?
21+
val ecosystem: String?,
22+
val isTestnet: Boolean
2223
) {
2324
val key = listOf(ecosystem, chainAssetId, chainId, isHidden).joinToString()
2425
}

common/src/main/res/drawable/ic_token_testnet.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
android:viewportWidth="16"
55
android:viewportHeight="11">
66
<path
7-
android:fillAlpha="0.64"
87
android:fillColor="#ffffff"
98
android:fillType="evenOdd"
109
android:pathData="M13.0009,5.4985L10.5314,3.0289L11.592,1.9683L15.1221,5.4985L11.592,9.0286L10.5314,7.968L13.0009,5.4985Z" />
1110
<path
12-
android:fillAlpha="0.64"
1311
android:fillColor="#ffffff"
1412
android:fillType="evenOdd"
1513
android:pathData="M3.0037,5.4984L5.4733,7.968L4.4127,9.0286L0.8825,5.4984L4.4127,1.9683L5.4733,3.0289L3.0037,5.4984Z" />
1614
<path
17-
android:fillAlpha="0.64"
1815
android:fillColor="#ffffff"
1916
android:pathData="M9.0266,0.24l1.5662,0.57l-3.6221,9.9517l-1.5662,-0.57z" />
2017
</vector>

feature-staking-impl/src/main/java/jp/co/soramitsu/staking/impl/presentation/confirm/ConfirmStakingFragment.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ import androidx.fragment.app.viewModels
55
import coil.ImageLoader
66
import dagger.hilt.android.AndroidEntryPoint
77
import dev.chrisbanes.insetter.applyInsetter
8-
import javax.inject.Inject
8+
import jp.co.soramitsu.account.api.presentation.actions.setupExternalActions
99
import jp.co.soramitsu.common.base.BaseFragment
1010
import jp.co.soramitsu.common.mixin.impl.observeRetries
1111
import jp.co.soramitsu.common.mixin.impl.observeValidations
12+
import jp.co.soramitsu.common.utils.formatCrypto
1213
import jp.co.soramitsu.common.utils.makeGone
1314
import jp.co.soramitsu.common.utils.makeVisible
1415
import jp.co.soramitsu.common.utils.setVisible
1516
import jp.co.soramitsu.common.view.setProgress
1617
import jp.co.soramitsu.common.view.viewBinding
1718
import jp.co.soramitsu.feature_staking_impl.R
1819
import jp.co.soramitsu.feature_staking_impl.databinding.FragmentConfirmStakeBinding
19-
import jp.co.soramitsu.account.api.presentation.actions.setupExternalActions
2020
import jp.co.soramitsu.wallet.api.presentation.mixin.fee.FeeViews
2121
import jp.co.soramitsu.wallet.api.presentation.mixin.fee.displayFeeStatus
22+
import javax.inject.Inject
2223

2324
@AndroidEntryPoint
2425
class ConfirmStakingFragment : BaseFragment<ConfirmStakingViewModel>(R.layout.fragment_confirm_stake) {
@@ -101,7 +102,7 @@ class ConfirmStakingFragment : BaseFragment<ConfirmStakingViewModel>(R.layout.fr
101102
viewModel.displayAmountLiveData.observe { bondedAmount ->
102103
binding.confirmStakeAmount.setVisible(bondedAmount != null)
103104

104-
bondedAmount?.let { binding.confirmStakeAmount.amountInput.setText(it.toString()) }
105+
bondedAmount?.let { binding.confirmStakeAmount.amountInput.setText(it.formatCrypto()) }
105106
}
106107

107108
viewModel.unstakingTime.observe {

feature-wallet-impl/src/main/java/jp/co/soramitsu/wallet/impl/domain/WalletInteractorImpl.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import jp.co.soramitsu.common.utils.orZero
1616
import jp.co.soramitsu.core.models.ChainId
1717
import jp.co.soramitsu.core.models.isValidAddress
1818
import jp.co.soramitsu.coredb.model.AssetUpdateItem
19+
import jp.co.soramitsu.runtime.ext.ecosystem
1920
import jp.co.soramitsu.runtime.multiNetwork.ChainRegistry
21+
import jp.co.soramitsu.runtime.multiNetwork.chain.ChainEcosystem
2022
import jp.co.soramitsu.runtime.multiNetwork.chain.model.Chain
2123
import jp.co.soramitsu.runtime.multiNetwork.chain.model.isPolkadotOrKusama
2224
import jp.co.soramitsu.runtime.multiNetwork.chain.model.polkadotChainId
@@ -307,16 +309,23 @@ class WalletInteractorImpl(
307309
val accountId = metaAccount.accountId(chain)
308310
val chainAsset = chain.assetsById[chainAssetId] ?: return
309311

310-
val tokenChains = chainRegistry.currentChains.first().filter {
311-
it.assets.any { it.symbolToShow == chainAsset.symbolToShow }
312+
val chainsWithAsset = chainRegistry.currentChains.first().filter { chainItem ->
313+
val isChainItemFromSameEcosystem = if (chain.ecosystem() == ChainEcosystem.STANDALONE) {
314+
chainItem.id == chainId
315+
} else {
316+
chainItem.ecosystem() == chain.ecosystem()
317+
}
318+
isChainItemFromSameEcosystem && chainItem.assets.any {
319+
it.symbolToShow == chainAsset.symbolToShow
320+
}
312321
}
313322

314-
val tokenChainAssets = tokenChains.map {
323+
val assetsToManage = chainsWithAsset.map {
315324
it.assets.filter { it.symbolToShow == chainAsset.symbolToShow }
316325
}.flatten()
317326

318327
accountId?.let {
319-
tokenChainAssets.forEach {
328+
assetsToManage.forEach {
320329
walletRepository.updateAssetHidden(
321330
chainAsset = it,
322331
metaId = metaAccount.id,

feature-wallet-impl/src/main/java/jp/co/soramitsu/wallet/impl/presentation/balance/list/BalanceListViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ class BalanceListViewModel @Inject constructor(
344344
hasAccount = true,
345345
priceId = chainAsset.priceId,
346346
hasNetworkIssue = false,
347-
ecosystem = ChainEcosystem.POLKADOT.name
347+
ecosystem = ChainEcosystem.POLKADOT.name,
348+
isTestnet = chain.isTestNet
348349
)
349350
}.filter { selectedChainId.value == null || selectedChainId.value == it.chainId }
350351
}

feature-wallet-impl/src/main/java/jp/co/soramitsu/wallet/impl/presentation/balance/list/WalletScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ private fun PreviewWalletScreen() {
138138
hasAccount = true,
139139
priceId = null,
140140
hasNetworkIssue = false,
141-
ecosystem = "Polkadot"
141+
ecosystem = "Polkadot",
142+
isTestnet = false
142143
)
143144
)
144145

feature-wallet-impl/src/main/java/jp/co/soramitsu/wallet/impl/presentation/balance/list/model/BalanceListItemModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ fun BalanceListItemModel.toAssetState() = AssetListItemViewState(
4343
hasAccount = !hasChainWithoutAccount,
4444
priceId = asset.priceId,
4545
hasNetworkIssue = hasNetworkIssue,
46-
ecosystem = ecosystem.name
46+
ecosystem = ecosystem.name,
47+
isTestnet = chain?.isTestNet == true
4748
)

0 commit comments

Comments
 (0)