Updated on 2026-08-14
This commit is contained in:
commit
c1964170e2
5 changed files with 37 additions and 13 deletions
|
|
@ -175,7 +175,7 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
|
|||
override fun onDestroy() {
|
||||
store.dispatch(NavigationAction.ActivityDestroyed(WeakReference(this)))
|
||||
intentProcessor.removeAll()
|
||||
cardSdkLifecycleObserver.onDestroy()
|
||||
cardSdkLifecycleObserver.onDestroy(this)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.Token
|
||||
import com.tangem.blockchain.common.derivation.DerivationStyle
|
||||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.crypto.hdWallet.DerivationPath
|
||||
import com.tangem.crypto.hdWallet.HDWalletError
|
||||
|
|
@ -212,13 +213,21 @@ internal class AddCustomTokenViewModel @Inject constructor(
|
|||
return listOf(defaultNetwork) + Blockchain.values()
|
||||
.filter { blockchain ->
|
||||
scanResponse?.card?.supportedBlockchains(scanResponse.cardTypesResolver)
|
||||
?.contains(blockchain) == true &&
|
||||
blockchain.derivationPath(derivationStyle)?.rawPath?.isNotEmpty() == true
|
||||
?.contains(blockchain) == true && isDerivationPathNotEmpty(derivationStyle, blockchain)
|
||||
}
|
||||
.sortedBy(Blockchain::fullName)
|
||||
.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 {
|
||||
return AddCustomTokenInputField.TokenName(
|
||||
value = "",
|
||||
|
|
@ -288,7 +297,12 @@ internal class AddCustomTokenViewModel @Inject constructor(
|
|||
}
|
||||
.sortedBy(Blockchain::fullName)
|
||||
.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) {
|
||||
createDerivationPathSelectorAdditionalItem(
|
||||
blockchain = it,
|
||||
|
|
@ -628,6 +642,7 @@ internal class AddCustomTokenViewModel @Inject constructor(
|
|||
if (blockchain == null) return null
|
||||
|
||||
val derivationStyle = reduxStateHolder.scanResponse?.derivationStyleProvider?.getDerivationStyle()
|
||||
?: DerivationStyle.V1
|
||||
|
||||
val derivationNetwork = if (blockchain == Blockchain.Unknown) {
|
||||
uiState.form.networkSelectorField.selectedItem.blockchain
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@
|
|||
<item name="cornerRadius">14dp</item>
|
||||
<item name="android:textAllCaps">false</item>
|
||||
<item name="android:textSize">14sp</item>
|
||||
<item name="android:fontFamily">@font/roboto_regular</item>
|
||||
<item name="android:letterSpacing">0</item>
|
||||
<item name="android:fontFamily">@font/roboto_medium</item>
|
||||
<item name="android:letterSpacing">0.01</item>
|
||||
<item name="fontWeight">500</item>
|
||||
<item name="lineHeight">16sp</item>
|
||||
<item name="iconPadding">4dp</item>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,6 @@ interface CardSdkLifecycleObserver {
|
|||
/** Callback of creating activity [context] */
|
||||
fun onCreate(context: Context)
|
||||
|
||||
/** Callback of destroying activity */
|
||||
fun onDestroy()
|
||||
/** Callback of destroying activity [context] */
|
||||
fun onDestroy(context: Context)
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import com.tangem.common.CardFilter
|
|||
import com.tangem.common.card.FirmwareVersion
|
||||
import com.tangem.common.core.Config
|
||||
import com.tangem.sdk.extensions.initWithBiometrics
|
||||
import java.lang.ref.WeakReference
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
|
@ -23,14 +24,22 @@ internal class DefaultCardSdkProvider @Inject constructor() : CardSdkProvider, C
|
|||
|
||||
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) {
|
||||
if (_sdk == null) {
|
||||
_sdk = TangemSdk.initWithBiometrics(activity = context as FragmentActivity, config = config)
|
||||
}
|
||||
contextRef = WeakReference(context)
|
||||
_sdk = TangemSdk.initWithBiometrics(activity = context as FragmentActivity, config = config)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
_sdk = null
|
||||
override fun onDestroy(context: Context) {
|
||||
/*
|
||||
|
||||
|
||||
*/
|
||||
if (contextRef.get() == context) {
|
||||
_sdk = null
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue