Updated on 2026-08-14

This commit is contained in:
Tangem 2023-09-07 12:48:22 +03:00
commit c1964170e2
5 changed files with 37 additions and 13 deletions

View file

@ -175,7 +175,7 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
override fun onDestroy() { override fun onDestroy() {
store.dispatch(NavigationAction.ActivityDestroyed(WeakReference(this))) store.dispatch(NavigationAction.ActivityDestroyed(WeakReference(this)))
intentProcessor.removeAll() intentProcessor.removeAll()
cardSdkLifecycleObserver.onDestroy() cardSdkLifecycleObserver.onDestroy(this)
super.onDestroy() super.onDestroy()
} }

View file

@ -12,6 +12,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.Token import com.tangem.blockchain.common.Token
import com.tangem.blockchain.common.derivation.DerivationStyle
import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.analytics.api.AnalyticsEventHandler
import com.tangem.crypto.hdWallet.DerivationPath import com.tangem.crypto.hdWallet.DerivationPath
import com.tangem.crypto.hdWallet.HDWalletError import com.tangem.crypto.hdWallet.HDWalletError
@ -212,13 +213,21 @@ internal class AddCustomTokenViewModel @Inject constructor(
return listOf(defaultNetwork) + Blockchain.values() return listOf(defaultNetwork) + Blockchain.values()
.filter { blockchain -> .filter { blockchain ->
scanResponse?.card?.supportedBlockchains(scanResponse.cardTypesResolver) scanResponse?.card?.supportedBlockchains(scanResponse.cardTypesResolver)
?.contains(blockchain) == true && ?.contains(blockchain) == true && isDerivationPathNotEmpty(derivationStyle, blockchain)
blockchain.derivationPath(derivationStyle)?.rawPath?.isNotEmpty() == true
} }
.sortedBy(Blockchain::fullName) .sortedBy(Blockchain::fullName)
.map(::createNetworkSelectorItem) .map(::createNetworkSelectorItem)
} }
private fun isDerivationPathNotEmpty(derivationStyle: DerivationStyle?, blockchain: Blockchain): Boolean {
// derivationStyle is null for cards without HD wallets, always return true
return if (derivationStyle != null) {
blockchain.derivationPath(derivationStyle)?.rawPath?.isNotEmpty() == true
} else {
true
}
}
private fun createTokenNameInputField(): AddCustomTokenInputField.TokenName { private fun createTokenNameInputField(): AddCustomTokenInputField.TokenName {
return AddCustomTokenInputField.TokenName( return AddCustomTokenInputField.TokenName(
value = "", value = "",
@ -288,7 +297,12 @@ internal class AddCustomTokenViewModel @Inject constructor(
} }
.sortedBy(Blockchain::fullName) .sortedBy(Blockchain::fullName)
.mapNotNull { .mapNotNull {
val derivationPath = it.derivationPath(derivationStyle)?.rawPath val derivationPath = if (derivationStyle != null) {
it.derivationPath(derivationStyle)?.rawPath
} else {
// derivationStyle is null for cards without HDWallet, use DerivationStyle.V1
it.derivationPath(DerivationStyle.V1)?.rawPath
}
if (derivationPath?.isNotEmpty() == true) { if (derivationPath?.isNotEmpty() == true) {
createDerivationPathSelectorAdditionalItem( createDerivationPathSelectorAdditionalItem(
blockchain = it, blockchain = it,
@ -628,6 +642,7 @@ internal class AddCustomTokenViewModel @Inject constructor(
if (blockchain == null) return null if (blockchain == null) return null
val derivationStyle = reduxStateHolder.scanResponse?.derivationStyleProvider?.getDerivationStyle() val derivationStyle = reduxStateHolder.scanResponse?.derivationStyleProvider?.getDerivationStyle()
?: DerivationStyle.V1
val derivationNetwork = if (blockchain == Blockchain.Unknown) { val derivationNetwork = if (blockchain == Blockchain.Unknown) {
uiState.form.networkSelectorField.selectedItem.blockchain uiState.form.networkSelectorField.selectedItem.blockchain

View file

@ -49,8 +49,8 @@
<item name="cornerRadius">14dp</item> <item name="cornerRadius">14dp</item>
<item name="android:textAllCaps">false</item> <item name="android:textAllCaps">false</item>
<item name="android:textSize">14sp</item> <item name="android:textSize">14sp</item>
<item name="android:fontFamily">@font/roboto_regular</item> <item name="android:fontFamily">@font/roboto_medium</item>
<item name="android:letterSpacing">0</item> <item name="android:letterSpacing">0.01</item>
<item name="fontWeight">500</item> <item name="fontWeight">500</item>
<item name="lineHeight">16sp</item> <item name="lineHeight">16sp</item>
<item name="iconPadding">4dp</item> <item name="iconPadding">4dp</item>

View file

@ -12,6 +12,6 @@ interface CardSdkLifecycleObserver {
/** Callback of creating activity [context] */ /** Callback of creating activity [context] */
fun onCreate(context: Context) fun onCreate(context: Context)
/** Callback of destroying activity */ /** Callback of destroying activity [context] */
fun onDestroy() fun onDestroy(context: Context)
} }

View file

@ -7,6 +7,7 @@ import com.tangem.common.CardFilter
import com.tangem.common.card.FirmwareVersion import com.tangem.common.card.FirmwareVersion
import com.tangem.common.core.Config import com.tangem.common.core.Config
import com.tangem.sdk.extensions.initWithBiometrics import com.tangem.sdk.extensions.initWithBiometrics
import java.lang.ref.WeakReference
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -23,14 +24,22 @@ internal class DefaultCardSdkProvider @Inject constructor() : CardSdkProvider, C
private var _sdk: TangemSdk? = null private var _sdk: TangemSdk? = null
/** Weak reference of context that uses to create [TangemSdk] */
private var contextRef: WeakReference<Context> = WeakReference(null)
override fun onCreate(context: Context) { override fun onCreate(context: Context) {
if (_sdk == null) { contextRef = WeakReference(context)
_sdk = TangemSdk.initWithBiometrics(activity = context as FragmentActivity, config = config) _sdk = TangemSdk.initWithBiometrics(activity = context as FragmentActivity, config = config)
}
} }
override fun onDestroy() { override fun onDestroy(context: Context) {
_sdk = null /*
*/
if (contextRef.get() == context) {
_sdk = null
}
} }
private companion object { private companion object {