Updated on 2026-08-14

This commit is contained in:
Tangem 2022-04-21 07:44:33 +03:00
parent f8cccf4482
commit b8d5c8f4f2
5 changed files with 138 additions and 41 deletions

View file

@ -10,6 +10,7 @@ import com.tangem.blockchain.common.Blockchain
import com.tangem.common.extensions.VoidCallback
import com.tangem.domain.common.form.Field
import com.tangem.tap.common.extensions.ValueCallback
import timber.log.Timber
/**
[REDACTED_AUTHOR]
@ -27,14 +28,24 @@ fun <T> OutlinedSpinner(
isEnabled: Boolean = true,
onClose: VoidCallback = {}
) {
val compositionCounter = remember { CompositionCounter(label) }
val counter = compositionCounter.increase(label)
val rIsExpanded = remember { mutableStateOf(false) }
val rSelectedItem = remember { mutableStateOf(selectedItem.value) }
val stateSelectedItem = remember { mutableStateOf(selectedItem.value) }
osLog(label, "recompose ------------------------------------", counter)
osLog(label, "selectedItem: $selectedItem", counter)
osLog(label, "stateSelectedItem: ${stateSelectedItem.value}", counter)
if (!selectedItem.isUserInput) {
rSelectedItem.value = selectedItem.value
osLog(label, "stateSelectedItem.value: update = selectedItem.value", counter)
stateSelectedItem.value = selectedItem.value
}
osLog(label, "stateSelectedItem: ${stateSelectedItem.value}", counter)
val onDropDownItemSelectedInternal: (T) -> Unit = {
rSelectedItem.value = it
osLog(label, "onDropDownItemSelectedInternal: value: [${it.toString()}]", counter)
stateSelectedItem.value = it
osLog(label, "onDropDownItemSelectedInternal: stateSelectedItem: ${stateSelectedItem.value}", counter)
rIsExpanded.value = false
onItemSelected(it)
}
@ -51,7 +62,7 @@ fun <T> OutlinedSpinner(
modifier = modifier,
readOnly = true,
enabled = isEnabled,
value = textFieldConverter(rSelectedItem.value),
value = textFieldConverter(stateSelectedItem.value),
onValueChange = {},
label = { Text(label) },
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = rIsExpanded.value) },
@ -74,6 +85,27 @@ fun <T> OutlinedSpinner(
}
}
private fun osLog(id: String, log: String, counter: CompositionCounter) {
if (id == "Сеть") Timber.d(
"OutlinedSpinner[$id]:[${counter.count}] - $log"
)
}
class CompositionCounter(
val id: String,
count: Int = 0
) {
var count: Int = count
private set
fun increase(id: String): CompositionCounter {
if (this.id != id) return this
count += 1
return CompositionCounter(id, count)
}
}
@Preview
@Composable
fun TestSpinnerPreview() {

View file

@ -1,10 +1,7 @@
package com.tangem.tap.features.wallet.ui.test
import com.tangem.blockchain.blockchains.solana.SolanaWalletManager
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.Blockchain
import com.tangem.domain.common.ScanResponse
import com.tangem.domain.common.TapWorkarounds.isTestCard
import com.tangem.blockchain.common.WalletManager
import com.tangem.tap.common.TestAction
import com.tangem.tap.common.TestActions
import com.tangem.tap.domain.tokens.BlockchainNetwork
@ -68,7 +65,7 @@ private class SolanaRentWarningActionEmitter {
}
private fun setBalance(value: BigDecimal) {
val amount = Amount(getBlockchain()).copy(value = value)
val amount = Amount(getBlockchainNetwork().blockchain).copy(value = value)
getWalletManager().apply {
TestActions.testAmountInjectionForWalletManagerEnabled = true
wallet.setAmount(amount)
@ -76,19 +73,12 @@ private class SolanaRentWarningActionEmitter {
store.dispatch(WalletAction.LoadData)
}
private fun getWalletManager(): SolanaWalletManager {
return store.state.walletState.getWalletManager(BlockchainNetwork(
blockchain = getBlockchain(),
card = scanResponse().card
)) as SolanaWalletManager
private fun getWalletManager(): WalletManager {
return store.state.walletState.getWalletManager(getBlockchainNetwork())!!
}
private fun getBlockchain(): Blockchain = when {
scanResponse().card.isTestCard -> Blockchain.SolanaTestnet
else -> Blockchain.Solana
}
private fun scanResponse(): ScanResponse {
return store.state.globalState.scanResponse ?: throw UnsupportedOperationException()
private fun getBlockchainNetwork(): BlockchainNetwork {
val currency = store.state.walletState.getSelectedWalletData()!!.currency
return BlockchainNetwork(currency.blockchain, currency.derivationPath, listOf())
}
}