From c1afd030f309a360f77170a22778f7a5b3d46c10 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 23 Aug 2023 13:25:24 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../viewmodels/AddCustomTokenViewModel.kt | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/viewmodels/AddCustomTokenViewModel.kt b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/viewmodels/AddCustomTokenViewModel.kt index 3b5e96c9e9..0a5151fd23 100644 --- a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/viewmodels/AddCustomTokenViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/viewmodels/AddCustomTokenViewModel.kt @@ -145,6 +145,7 @@ internal class AddCustomTokenViewModel @Inject constructor( fun createDerivationPathSelectorAdditionalItem( blockchain: Blockchain, type: DerivationPathSelectorType = DerivationPathSelectorType.BLOCKCHAIN, + derivationStyle: DerivationStyle?, ): SelectorItem.TitleWithSubtitle { return when (type) { DerivationPathSelectorType.DEFAULT -> SelectorItem.TitleWithSubtitle( @@ -160,7 +161,9 @@ internal class AddCustomTokenViewModel @Inject constructor( type = DerivationPathSelectorType.CUSTOM, ) DerivationPathSelectorType.BLOCKCHAIN -> SelectorItem.TitleWithSubtitle( - title = blockchain.derivationPath(DerivationStyle.LEGACY)?.rawPath?.let(TextReference::Str) + title = blockchain.derivationPath( + style = derivationStyle, + )?.rawPath?.let(TextReference::Str) ?: TextReference.Res(R.string.custom_token_derivation_path_default), subtitle = TextReference.Str(blockchain.fullName), blockchain = blockchain, @@ -251,9 +254,11 @@ internal class AddCustomTokenViewModel @Inject constructor( } private fun createDerivationPathsSelectorField(): AddCustomTokenSelectorField.DerivationPath? { - if (reduxStateHolder.scanResponse?.card?.settings?.isHDWalletAllowed == false) return null + val scanResponse = reduxStateHolder.scanResponse + if (scanResponse?.card?.settings?.isHDWalletAllowed == false) return null - val selectorItems = getDerivationPathsSelectorItems() + val selectorItems = + getDerivationPathsSelectorItems(scanResponse?.derivationStyleProvider?.getDerivationStyle()) return AddCustomTokenSelectorField.DerivationPath( label = TextReference.Res(R.string.custom_token_derivation_path_input_title), selectedItem = requireNotNull(selectorItems.firstOrNull()), @@ -263,22 +268,31 @@ internal class AddCustomTokenViewModel @Inject constructor( ) } - private fun getDerivationPathsSelectorItems(): List { + private fun getDerivationPathsSelectorItems( + derivationStyle: DerivationStyle?, + ): List { return listOf( createDerivationPathSelectorAdditionalItem( blockchain = Blockchain.Unknown, type = DerivationPathSelectorType.DEFAULT, + derivationStyle = derivationStyle, ), createDerivationPathSelectorAdditionalItem( blockchain = Blockchain.Unknown, type = DerivationPathSelectorType.CUSTOM, + derivationStyle = derivationStyle, ), ) + Blockchain.values() .filter { blockchain -> blockchain.isSupportedInApp() && !blockchain.isTestnet() } .sortedBy(Blockchain::fullName) - .map(::createDerivationPathSelectorAdditionalItem) + .map { + createDerivationPathSelectorAdditionalItem( + blockchain = it, + derivationStyle = derivationStyle, + ) + } } private fun createDerivationPathInputField(): AddCustomTokenInputField.DerivationPath? { @@ -782,6 +796,7 @@ internal class AddCustomTokenViewModel @Inject constructor( } fun onResetButtonClick() { + val scanResponse = reduxStateHolder.scanResponse with(uiState.form) { uiState = uiState.copySealed( form = uiState.form.copy( @@ -799,11 +814,11 @@ internal class AddCustomTokenViewModel @Inject constructor( decimalsInputField = decimalsInputField.copy(value = "", isEnabled = false), derivationPathSelectorField = derivationPathSelectorField?.copy( isEnabled = true, - selectedItem = formStateBuilder - .createDerivationPathSelectorAdditionalItem( - blockchain = Blockchain.Unknown, - type = DerivationPathSelectorType.DEFAULT, - ), + selectedItem = formStateBuilder.createDerivationPathSelectorAdditionalItem( + blockchain = Blockchain.Unknown, + type = DerivationPathSelectorType.DEFAULT, + derivationStyle = scanResponse?.derivationStyleProvider?.getDerivationStyle(), + ), ), ), )