Updated on 2026-08-14
This commit is contained in:
parent
a3f2c421bf
commit
d174ada664
20 changed files with 71 additions and 189 deletions
|
|
@ -6,6 +6,7 @@ import androidx.lifecycle.lifecycleScope
|
|||
import com.tangem.core.navigation.AppScreen
|
||||
import com.tangem.core.navigation.NavigationAction
|
||||
import com.tangem.domain.settings.repositories.SettingsRepository
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
import com.tangem.domain.wallets.legacy.asLockable
|
||||
import com.tangem.tap.common.extensions.dispatchOnMain
|
||||
import com.tangem.tap.common.extensions.dispatchWithMain
|
||||
|
|
@ -17,6 +18,7 @@ internal class LockUserWalletsTimer(
|
|||
owner: LifecycleOwner,
|
||||
private val settingsRepository: SettingsRepository,
|
||||
private val duration: Duration = with(Duration) { 10.minutes },
|
||||
private val userWalletsListManager: UserWalletsListManager,
|
||||
) : LifecycleOwner by owner,
|
||||
DefaultLifecycleObserver {
|
||||
|
||||
|
|
@ -108,7 +110,7 @@ internal class LockUserWalletsTimer(
|
|||
delay(duration)
|
||||
|
||||
if (isActive) {
|
||||
val userWalletsListManager = userWalletsListManagerSafe?.asLockable() ?: return@launch
|
||||
val userWalletsListManager = userWalletsListManager.asLockable() ?: return@launch
|
||||
|
||||
if (userWalletsListManager.hasUserWallets) {
|
||||
val currentTime = System.currentTimeMillis()
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ import com.tangem.data.card.sdk.CardSdkLifecycleObserver
|
|||
import com.tangem.domain.apptheme.model.AppThemeMode
|
||||
import com.tangem.domain.card.ScanCardUseCase
|
||||
import com.tangem.domain.card.repository.CardSdkConfigRepository
|
||||
import com.tangem.domain.settings.repositories.SettingsRepository
|
||||
import com.tangem.domain.tokens.GetPolkadotCheckHasImmortalUseCase
|
||||
import com.tangem.domain.tokens.GetPolkadotCheckHasResetUseCase
|
||||
import com.tangem.domain.settings.repositories.SettingsRepository
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
import com.tangem.domain.wallets.legacy.asLockable
|
||||
import com.tangem.feature.qrscanning.QrScanningRouter
|
||||
|
|
@ -93,14 +93,6 @@ private val mainCoroutineContext: CoroutineContext
|
|||
get() = Job() + Dispatchers.Main + FeatureCoroutineExceptionHandler.create("mainScope")
|
||||
val mainScope = CoroutineScope(mainCoroutineContext)
|
||||
|
||||
// TODO: will be remove in this task [REDACTED_JIRA]
|
||||
@Deprecated(message = "Provide UserWalletsListManager using DI")
|
||||
val userWalletsListManagerSafe: UserWalletsListManager? get() = store.state.globalState.userWalletsListManager
|
||||
|
||||
// TODO: will be remove in this task [REDACTED_JIRA]
|
||||
@Deprecated(message = "Provide UserWalletsListManager using DI")
|
||||
val userWalletsListManager: UserWalletsListManager get() = userWalletsListManagerSafe!!
|
||||
|
||||
@Suppress("LargeClass")
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbackHolder {
|
||||
|
|
@ -157,6 +149,9 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
|
|||
@Inject
|
||||
lateinit var analyticsEventsHandler: AnalyticsEventHandler
|
||||
|
||||
@Inject
|
||||
lateinit var userWalletsListManager: UserWalletsListManager
|
||||
|
||||
internal val viewModel: MainViewModel by viewModels()
|
||||
|
||||
private lateinit var appThemeModeFlow: SharedFlow<AppThemeMode?>
|
||||
|
|
@ -221,7 +216,11 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
|
|||
tangemSdkManager = injectedTangemSdkManager
|
||||
appStateHolder.tangemSdkManager = tangemSdkManager
|
||||
backupService = BackupService.init(cardSdkConfigRepository.sdk, this)
|
||||
lockUserWalletsTimer = LockUserWalletsTimer(owner = this, settingsRepository = settingsRepository)
|
||||
lockUserWalletsTimer = LockUserWalletsTimer(
|
||||
owner = this,
|
||||
settingsRepository = settingsRepository,
|
||||
userWalletsListManager = userWalletsListManager,
|
||||
)
|
||||
|
||||
initIntentHandlers()
|
||||
|
||||
|
|
@ -307,7 +306,7 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
|
|||
}
|
||||
|
||||
private fun initIntentHandlers() {
|
||||
val hasSavedWalletsProvider = { store.state.globalState.userWalletsListManager?.hasUserWallets == true }
|
||||
val hasSavedWalletsProvider = { userWalletsListManager.hasUserWallets }
|
||||
intentProcessor.addHandler(BackgroundScanIntentHandler(hasSavedWalletsProvider, lifecycleScope))
|
||||
intentProcessor.addHandler(WalletConnectLinkIntentHandler())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import com.tangem.tap.network.exchangeServices.moonpay.MoonPayService
|
|||
import com.tangem.tap.proxy.redux.DaggerGraphState
|
||||
import com.tangem.tap.scope
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.tap.userWalletsListManager
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -107,6 +106,7 @@ private fun handleAction(action: Action, appState: () -> AppState?) {
|
|||
|
||||
scope.launch {
|
||||
val scanResponseProvider: () -> ScanResponse? = {
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
userWalletsListManager.selectedUserWalletSync?.scanResponse
|
||||
}
|
||||
val cardProvider: () -> CardDTO? = { scanResponseProvider.invoke()?.card }
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ import com.tangem.tap.features.details.ui.walletconnect.dialogs.TransactionReque
|
|||
import com.tangem.tap.proxy.redux.DaggerGraphState
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.tap.tangemSdkManager
|
||||
import com.tangem.tap.userWalletsListManager
|
||||
import timber.log.Timber
|
||||
import java.math.BigDecimal
|
||||
import com.tangem.core.analytics.models.AnalyticsParam as CoreAnalyticsParam
|
||||
|
|
@ -44,6 +43,10 @@ import com.tangem.core.analytics.models.AnalyticsParam as CoreAnalyticsParam
|
|||
@Suppress("LargeClass")
|
||||
class WalletConnectSdkHelper {
|
||||
|
||||
private val userWalletsListManager by lazy {
|
||||
store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
}
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
suspend fun prepareTransactionData(data: EthTransactionData): WcTransactionData? {
|
||||
val transaction = data.transaction
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ class DetailsMiddleware {
|
|||
class EraseWalletMiddleware {
|
||||
@Suppress("CyclomaticComplexMethod")
|
||||
fun handle(action: DetailsAction.ResetToFactory) {
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
|
||||
when (action) {
|
||||
is DetailsAction.ResetToFactory.Start -> {
|
||||
val card = store.state.detailsState.cardSettingsState?.card ?: return
|
||||
|
|
@ -523,6 +525,7 @@ class DetailsMiddleware {
|
|||
val userWallet = UserWalletBuilder(scanResponse).build()
|
||||
?: return CompletionResult.Failure(TangemSdkError.WalletIsNotCreated())
|
||||
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
return userWalletsListManager.save(userWallet)
|
||||
.doOnSuccess {
|
||||
store.onUserWalletSelected(userWallet)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import com.tangem.tap.features.demo.DemoHelper
|
|||
import com.tangem.tap.proxy.redux.DaggerGraphState
|
||||
import com.tangem.tap.scope
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.tap.userWalletsListManager
|
||||
import kotlinx.coroutines.launch
|
||||
import org.rekotlin.Action
|
||||
import org.rekotlin.Middleware
|
||||
|
|
@ -174,6 +173,7 @@ class WalletConnectMiddleware {
|
|||
|
||||
private suspend fun getWalletManagers(): List<WalletManager> {
|
||||
val walletManagerFacade = store.inject(DaggerGraphState::walletManagersFacade)
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
val userWallet = userWalletsListManager.selectedUserWalletSync ?: return emptyList()
|
||||
|
||||
return walletManagerFacade.getStoredWalletManagers(userWallet.walletId)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.tangem.core.ui.screen.ComposeFragment
|
|||
import com.tangem.core.ui.theme.AppThemeModeHolder
|
||||
import com.tangem.domain.feedback.FeedbackManagerFeatureToggles
|
||||
import com.tangem.domain.feedback.GetSupportFeedbackEmailUseCase
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
import com.tangem.domain.wallets.repository.WalletsRepository
|
||||
import com.tangem.tap.common.analytics.events.Settings
|
||||
import com.tangem.tap.features.details.redux.DetailsState
|
||||
|
|
@ -36,6 +37,9 @@ internal class DetailsFragment : ComposeFragment(), StoreSubscriber<DetailsState
|
|||
@Inject
|
||||
lateinit var emailSender: EmailSender
|
||||
|
||||
@Inject
|
||||
lateinit var userWalletsListManager: UserWalletsListManager
|
||||
|
||||
private lateinit var detailsViewModel: DetailsViewModel
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
@ -46,6 +50,7 @@ internal class DetailsFragment : ComposeFragment(), StoreSubscriber<DetailsState
|
|||
feedbackManagerFeatureToggles = feedbackManagerFeatureToggles,
|
||||
getSupportFeedbackEmailUseCase = getSupportFeedbackEmailUseCase,
|
||||
emailSender = emailSender,
|
||||
userWalletsListManager = userWalletsListManager,
|
||||
)
|
||||
Analytics.send(Settings.ScreenOpened())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import com.tangem.core.ui.extensions.TextReference
|
|||
import com.tangem.domain.common.util.cardTypesResolver
|
||||
import com.tangem.domain.feedback.FeedbackManagerFeatureToggles
|
||||
import com.tangem.domain.feedback.GetSupportFeedbackEmailUseCase
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
import com.tangem.domain.wallets.repository.WalletsRepository
|
||||
import com.tangem.tap.common.analytics.events.Settings
|
||||
import com.tangem.tap.common.extensions.addContext
|
||||
|
|
@ -31,7 +32,6 @@ import com.tangem.tap.features.home.LocaleRegionProvider
|
|||
import com.tangem.tap.features.home.RUSSIA_COUNTRY_CODE
|
||||
import com.tangem.tap.mainScope
|
||||
import com.tangem.tap.scope
|
||||
import com.tangem.tap.userWalletsListManager
|
||||
import com.tangem.wallet.BuildConfig
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
|
@ -52,6 +52,7 @@ internal class DetailsViewModel(
|
|||
private val feedbackManagerFeatureToggles: FeedbackManagerFeatureToggles,
|
||||
private val getSupportFeedbackEmailUseCase: GetSupportFeedbackEmailUseCase,
|
||||
private val emailSender: EmailSender,
|
||||
private val userWalletsListManager: UserWalletsListManager,
|
||||
) {
|
||||
|
||||
var detailsScreenState: MutableState<DetailsScreenState> = mutableStateOf(updateState(store.state.detailsState))
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import com.tangem.tap.features.home.redux.HomeMiddleware.NEW_BUY_WALLET_URL
|
|||
import com.tangem.tap.proxy.redux.DaggerGraphState
|
||||
import com.tangem.tap.scope
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.tap.userWalletsListManager
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.rekotlin.Action
|
||||
|
|
@ -109,6 +108,7 @@ private fun proceedWithScanResponse(scanResponse: ScanResponse) = scope.launch {
|
|||
return@launch
|
||||
}
|
||||
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
userWalletsListManager.save(userWallet)
|
||||
.doOnFailure { error ->
|
||||
Timber.e(error, "Unable to save user wallet")
|
||||
|
|
@ -128,6 +128,8 @@ private fun sendSignedInCardAnalyticsEvent(scanResponse: ScanResponse) {
|
|||
)
|
||||
|
||||
if (currency != null) {
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
|
||||
Analytics.send(
|
||||
event = Basic.SignedIn(
|
||||
currency = currency,
|
||||
|
|
|
|||
|
|
@ -14,12 +14,15 @@ import com.tangem.domain.models.scan.ProductType
|
|||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.userwallets.UserWalletBuilder
|
||||
import com.tangem.domain.userwallets.UserWalletIdBuilder
|
||||
import com.tangem.tap.*
|
||||
import com.tangem.tap.common.analytics.converters.ParamCardCurrencyConverter
|
||||
import com.tangem.tap.common.extensions.*
|
||||
import com.tangem.tap.features.demo.DemoHelper
|
||||
import com.tangem.tap.features.saveWallet.redux.SaveWalletAction
|
||||
import com.tangem.tap.mainScope
|
||||
import com.tangem.tap.proxy.redux.DaggerGraphState
|
||||
import com.tangem.tap.scope
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.tap.tangemSdkManager
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
|
@ -148,6 +151,7 @@ object OnboardingHelper {
|
|||
return
|
||||
}
|
||||
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
userWalletsListManager.save(userWallet, canOverride = true)
|
||||
.doOnFailure { error ->
|
||||
Timber.e(error, "Unable to save user wallet")
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import com.tangem.tap.mainScope
|
|||
import com.tangem.tap.proxy.redux.DaggerGraphState
|
||||
import com.tangem.tap.scope
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.tap.userWalletsListManager
|
||||
import com.tangem.utils.extensions.DELAY_SDK_DIALOG_CLOSE
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -61,6 +60,7 @@ private fun handle(action: Action, dispatch: DispatchFunction) {
|
|||
val globalState = store.state.globalState
|
||||
val onboardingManager = globalState.onboardingState.onboardingManager
|
||||
val twinCardsState = store.state.twinCardsState
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
|
||||
fun getScanResponse(): ScanResponse {
|
||||
return when (twinCardsState.mode) {
|
||||
|
|
@ -366,6 +366,8 @@ private fun handle(action: Action, dispatch: DispatchFunction) {
|
|||
}
|
||||
|
||||
private fun getPopBackScreen(): AppScreen {
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
|
||||
return if (userWalletsListManager.hasUserWallets) {
|
||||
val isLocked = runCatching { userWalletsListManager.asLockable()?.isLockedSync }
|
||||
.fold(onSuccess = { true }, onFailure = { false })
|
||||
|
|
|
|||
|
|
@ -556,6 +556,7 @@ private fun handleBackupAction(appState: () -> AppState?, action: BackupAction)
|
|||
return@launch
|
||||
}
|
||||
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
userWalletsListManager.update(
|
||||
userWalletId = userWallet.walletId,
|
||||
update = { wallet ->
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import com.tangem.core.navigation.AppScreen
|
|||
import com.tangem.core.navigation.NavigationAction
|
||||
import com.tangem.domain.userwallets.UserWalletBuilder
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.tap.*
|
||||
import com.tangem.tap.common.analytics.events.AnalyticsParam
|
||||
import com.tangem.tap.common.analytics.events.MainScreen
|
||||
import com.tangem.tap.common.analytics.events.Onboarding
|
||||
|
|
@ -17,7 +16,11 @@ import com.tangem.tap.common.extensions.dispatchWithMain
|
|||
import com.tangem.tap.common.extensions.inject
|
||||
import com.tangem.tap.common.extensions.onUserWalletSelected
|
||||
import com.tangem.tap.common.redux.AppState
|
||||
import com.tangem.tap.mainScope
|
||||
import com.tangem.tap.proxy.redux.DaggerGraphState
|
||||
import com.tangem.tap.scope
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.tap.tangemSdkManager
|
||||
import com.tangem.utils.coroutines.JobHolder
|
||||
import com.tangem.utils.coroutines.saveIn
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -70,6 +73,7 @@ internal class SaveWalletMiddleware {
|
|||
return@launch
|
||||
}
|
||||
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
userWalletsListManager.save(userWallet, canOverride = true)
|
||||
.flatMap {
|
||||
saveAccessCodeIfNeeded(accessCode = backupInfo.accessCode, cardsInWallet = userWallet.cardsInWallet)
|
||||
|
|
@ -104,6 +108,7 @@ internal class SaveWalletMiddleware {
|
|||
|
||||
* because it will be automatically saved on UserWalletsListManager switch
|
||||
*/
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
val selectedUserWallet = userWalletsListManager.selectedUserWalletSync.guard {
|
||||
val error = IllegalStateException("No selected user wallet")
|
||||
Timber.e(error, "Unable to save user wallet")
|
||||
|
|
|
|||
|
|
@ -16,13 +16,16 @@ import com.tangem.domain.models.scan.ScanResponse
|
|||
import com.tangem.domain.userwallets.UserWalletBuilder
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager.Lockable.UnlockType
|
||||
import com.tangem.domain.wallets.legacy.unlockIfLockable
|
||||
import com.tangem.tap.*
|
||||
import com.tangem.tap.backupService
|
||||
import com.tangem.tap.common.analytics.converters.ParamCardCurrencyConverter
|
||||
import com.tangem.tap.common.extensions.*
|
||||
import com.tangem.tap.common.redux.AppState
|
||||
import com.tangem.tap.features.intentHandler.handlers.BackgroundScanIntentHandler
|
||||
import com.tangem.tap.features.intentHandler.handlers.WalletConnectLinkIntentHandler
|
||||
import com.tangem.tap.proxy.redux.DaggerGraphState
|
||||
import com.tangem.tap.scope
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.tap.tangemSdkManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.rekotlin.Middleware
|
||||
|
|
@ -83,6 +86,7 @@ internal class WelcomeMiddleware {
|
|||
""".trimIndent(),
|
||||
)
|
||||
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
userWalletsListManager.unlockIfLockable(type = UnlockType.ANY)
|
||||
.doOnFailure { error ->
|
||||
Timber.e(error, "Unable to unlock user wallets with biometrics")
|
||||
|
|
@ -115,6 +119,7 @@ internal class WelcomeMiddleware {
|
|||
scanCardInternal { scanResponse ->
|
||||
val userWallet = UserWalletBuilder(scanResponse).build() ?: return@scanCardInternal
|
||||
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
userWalletsListManager.save(userWallet, canOverride = true)
|
||||
.doOnFailure { error ->
|
||||
Timber.e(error, "Unable to save user wallet")
|
||||
|
|
@ -140,12 +145,14 @@ internal class WelcomeMiddleware {
|
|||
)
|
||||
Analytics.addContext(scanResponse)
|
||||
if (currency != null) {
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
|
||||
Analytics.send(
|
||||
event = Basic.SignedIn(
|
||||
currency = currency,
|
||||
batch = scanResponse.card.batchId,
|
||||
signInType = signInType,
|
||||
walletsCount = store.state.globalState.userWalletsListManager?.walletsCount.toString(),
|
||||
walletsCount = userWalletsListManager.walletsCount.toString(),
|
||||
hasBackup = scanResponse.card.backupStatus?.isActive,
|
||||
),
|
||||
)
|
||||
|
|
@ -153,6 +160,7 @@ internal class WelcomeMiddleware {
|
|||
}
|
||||
|
||||
private suspend fun disableUserWalletsSaving() {
|
||||
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
|
||||
userWalletsListManager.clear()
|
||||
.flatMap { tangemSdkManager.clearSavedUserCodes() }
|
||||
.doOnFailure { e ->
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ import com.tangem.blockchain.common.Token
|
|||
import com.tangem.data.tokens.utils.CryptoCurrencyFactory
|
||||
import com.tangem.domain.common.util.derivationStyleProvider
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.tap.common.extensions.inject
|
||||
import com.tangem.tap.domain.model.Currency
|
||||
import com.tangem.tap.proxy.redux.DaggerGraphState
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.utils.converter.TwoWayConverter
|
||||
|
||||
|
|
@ -20,9 +22,7 @@ internal class CryptoCurrencyConverter : TwoWayConverter<Currency, CryptoCurrenc
|
|||
blockchain = value.blockchain,
|
||||
extraDerivationPath = value.derivationPath,
|
||||
derivationStyleProvider = requireNotNull(
|
||||
store.state.globalState
|
||||
.userWalletsListManager
|
||||
?.selectedUserWalletSync
|
||||
store.inject(DaggerGraphState::generalUserWalletsListManager).selectedUserWalletSync
|
||||
?.scanResponse
|
||||
?.derivationStyleProvider,
|
||||
),
|
||||
|
|
@ -34,9 +34,7 @@ internal class CryptoCurrencyConverter : TwoWayConverter<Currency, CryptoCurrenc
|
|||
blockchain = value.blockchain,
|
||||
extraDerivationPath = value.derivationPath,
|
||||
derivationStyleProvider = requireNotNull(
|
||||
store.state.globalState
|
||||
.userWalletsListManager
|
||||
?.selectedUserWalletSync
|
||||
store.inject(DaggerGraphState::generalUserWalletsListManager).selectedUserWalletSync
|
||||
?.scanResponse
|
||||
?.derivationStyleProvider,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@ import com.tangem.common.core.TangemSdkError
|
|||
import com.tangem.common.extensions.hexToBytes
|
||||
import com.tangem.domain.card.repository.CardSdkConfigRepository
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
import com.tangem.lib.crypto.TransactionManager
|
||||
import com.tangem.lib.crypto.models.*
|
||||
import com.tangem.lib.crypto.models.transactions.SendTxResult
|
||||
import com.tangem.tap.common.redux.global.GlobalAction
|
||||
import com.tangem.tap.domain.TangemSigner
|
||||
import com.tangem.tap.userWalletsListManager
|
||||
import java.math.BigDecimal
|
||||
import java.math.BigInteger
|
||||
import java.math.MathContext
|
||||
|
|
@ -42,6 +42,7 @@ class TransactionManagerImpl(
|
|||
private val appStateHolder: AppStateHolder,
|
||||
private val cardSdkConfigRepository: CardSdkConfigRepository,
|
||||
private val walletManagersFacade: WalletManagersFacade,
|
||||
private val userWalletsListManager: UserWalletsListManager,
|
||||
) : TransactionManager {
|
||||
|
||||
override suspend fun sendApproveTransaction(
|
||||
|
|
|
|||
|
|
@ -2,85 +2,20 @@ package com.tangem.tap.proxy
|
|||
|
||||
import com.tangem.blockchain.common.AmountType
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.Token
|
||||
import com.tangem.blockchain.common.WalletManager
|
||||
import com.tangem.blockchainsdk.utils.fromNetworkId
|
||||
import com.tangem.blockchainsdk.utils.toCoinId
|
||||
import com.tangem.blockchainsdk.utils.toNetworkId
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
import com.tangem.lib.crypto.UserWalletManager
|
||||
import com.tangem.lib.crypto.models.Currency
|
||||
import com.tangem.lib.crypto.models.Currency.NativeToken
|
||||
import com.tangem.lib.crypto.models.Currency.NonNativeToken
|
||||
import com.tangem.lib.crypto.models.ProxyAmount
|
||||
import com.tangem.tap.userWalletsListManager
|
||||
import timber.log.Timber
|
||||
import java.math.BigDecimal
|
||||
|
||||
class UserWalletManagerImpl(
|
||||
private val walletManagersFacade: WalletManagersFacade,
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
private val userWalletsStore: UserWalletsStore,
|
||||
private val userWalletsListManager: UserWalletsListManager,
|
||||
) : UserWalletManager {
|
||||
|
||||
override suspend fun getUserTokens(
|
||||
networkId: String,
|
||||
derivationPath: String?,
|
||||
isExcludeCustom: Boolean,
|
||||
): List<Currency> {
|
||||
// FIXME: Find user wallet by ID
|
||||
val userWallet = requireNotNull(userWalletsStore.selectedUserWalletOrNull) {
|
||||
"No user wallet selected"
|
||||
}
|
||||
return currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWallet.walletId)
|
||||
.filter {
|
||||
val checkCustom = if (isExcludeCustom) {
|
||||
!it.isCustom
|
||||
} else {
|
||||
true
|
||||
}
|
||||
val blockchain = Blockchain.fromId(it.network.id.value)
|
||||
|
||||
blockchain.toNetworkId() == networkId &&
|
||||
checkCustom &&
|
||||
it.network.derivationPath.value == derivationPath
|
||||
}
|
||||
.map {
|
||||
val blockchain = Blockchain.fromId(it.network.id.value)
|
||||
|
||||
if (it is CryptoCurrency.Token) {
|
||||
NonNativeToken(
|
||||
id = it.id.rawCurrencyId ?: "",
|
||||
name = it.name,
|
||||
symbol = it.symbol,
|
||||
networkId = blockchain.toNetworkId(),
|
||||
contractAddress = it.contractAddress,
|
||||
decimalCount = it.decimals,
|
||||
)
|
||||
} else {
|
||||
NativeToken(
|
||||
id = it.id.rawCurrencyId ?: "",
|
||||
name = it.name,
|
||||
symbol = it.symbol,
|
||||
networkId = blockchain.toNetworkId(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getNativeTokenForNetwork(networkId: String): Currency {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
return NativeToken(
|
||||
id = blockchain.toCoinId(),
|
||||
name = blockchain.fullName,
|
||||
symbol = blockchain.currency,
|
||||
networkId = networkId,
|
||||
)
|
||||
}
|
||||
|
||||
override fun getWalletId(): String {
|
||||
val selectedUserWallet = requireNotNull(
|
||||
userWalletsListManager.selectedUserWalletSync,
|
||||
|
|
@ -88,18 +23,6 @@ class UserWalletManagerImpl(
|
|||
return selectedUserWallet.walletId.stringValue
|
||||
}
|
||||
|
||||
override suspend fun isTokenAdded(currency: Currency, derivationPath: String?): Boolean {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(currency.networkId)) { "blockchain not found" }
|
||||
return try {
|
||||
val walletManager = getActualWalletManager(blockchain, derivationPath)
|
||||
walletManager.cardTokens.any {
|
||||
it.id == currency.id
|
||||
}
|
||||
} catch (e: IllegalArgumentException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun hideAllTokens() {
|
||||
// FIXME: Used only in Tester Actions
|
||||
Timber.w("Not implemented")
|
||||
|
|
@ -119,37 +42,6 @@ class UserWalletManagerImpl(
|
|||
?.hash
|
||||
}
|
||||
|
||||
override suspend fun getCurrentWalletTokensBalance(
|
||||
networkId: String,
|
||||
extraTokens: List<Currency>,
|
||||
derivationPath: String?,
|
||||
): Map<String, ProxyAmount> {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
val walletManager = getActualWalletManager(blockchain, derivationPath)
|
||||
|
||||
// workaround for get balance for tokens that doesn't exist in wallet
|
||||
val extraTokensToLoadBalance = extraTokens
|
||||
.filterIsInstance<NonNativeToken>()
|
||||
.map {
|
||||
it.toSdkToken()
|
||||
}
|
||||
.filter {
|
||||
!walletManager.cardTokens.contains(it)
|
||||
}
|
||||
walletManager.addTokens(extraTokensToLoadBalance)
|
||||
walletManager.update()
|
||||
val balances = walletManager.wallet.amounts.map { entry ->
|
||||
val amount = entry.value
|
||||
amount.currencySymbol to ProxyAmount(
|
||||
amount.currencySymbol,
|
||||
amount.value ?: BigDecimal.ZERO,
|
||||
amount.decimals,
|
||||
)
|
||||
}.toMap()
|
||||
extraTokensToLoadBalance.forEach { walletManager.removeToken(it) }
|
||||
return balances
|
||||
}
|
||||
|
||||
override suspend fun getNativeTokenBalance(networkId: String, derivationPath: String?): ProxyAmount? {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
val walletManager = getActualWalletManager(blockchain, derivationPath)
|
||||
|
|
@ -179,14 +71,4 @@ class UserWalletManagerImpl(
|
|||
"No wallet manager found"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun NonNativeToken.toSdkToken(): Token {
|
||||
return Token(
|
||||
id = this.id,
|
||||
name = this.name,
|
||||
symbol = this.symbol,
|
||||
contractAddress = this.contractAddress,
|
||||
decimals = this.decimalCount,
|
||||
)
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package com.tangem.tap.proxy.di
|
||||
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.card.repository.CardSdkConfigRepository
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
import com.tangem.lib.crypto.TransactionManager
|
||||
import com.tangem.lib.crypto.UserWalletManager
|
||||
import com.tangem.tap.proxy.*
|
||||
|
|
@ -28,13 +27,11 @@ internal object ProxyModule {
|
|||
@Singleton
|
||||
fun provideUserWalletManager(
|
||||
walletManagersFacade: WalletManagersFacade,
|
||||
currenciesRepository: CurrenciesRepository,
|
||||
userWalletsStore: UserWalletsStore,
|
||||
userWalletsListManager: UserWalletsListManager,
|
||||
): UserWalletManager {
|
||||
return UserWalletManagerImpl(
|
||||
walletManagersFacade = walletManagersFacade,
|
||||
currenciesRepository = currenciesRepository,
|
||||
userWalletsStore = userWalletsStore,
|
||||
userWalletsListManager = userWalletsListManager,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -44,11 +41,13 @@ internal object ProxyModule {
|
|||
appStateHolder: AppStateHolder,
|
||||
cardSdkConfigRepository: CardSdkConfigRepository,
|
||||
walletManagersFacade: WalletManagersFacade,
|
||||
userWalletsListManager: UserWalletsListManager,
|
||||
): TransactionManager {
|
||||
return TransactionManagerImpl(
|
||||
appStateHolder = appStateHolder,
|
||||
cardSdkConfigRepository = cardSdkConfigRepository,
|
||||
walletManagersFacade = walletManagersFacade,
|
||||
userWalletsListManager = userWalletsListManager,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ import retrofit2.http.Header
|
|||
*/
|
||||
interface TangemTechServiceApi {
|
||||
|
||||
@GET("v1/networks")
|
||||
@GET("networks/providers")
|
||||
suspend fun getBlockchainProviders(
|
||||
@Header("card_public_key") cardPublicKey: String,
|
||||
@Header("card_id") cardId: String,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.tangem.lib.crypto
|
||||
|
||||
import com.tangem.lib.crypto.models.Currency
|
||||
import com.tangem.lib.crypto.models.ProxyAmount
|
||||
|
||||
/**
|
||||
|
|
@ -8,28 +7,11 @@ import com.tangem.lib.crypto.models.ProxyAmount
|
|||
*/
|
||||
interface UserWalletManager {
|
||||
|
||||
/**
|
||||
* Returns all user tokens (merged from local and backend)
|
||||
*/
|
||||
@Throws(IllegalStateException::class)
|
||||
suspend fun getUserTokens(networkId: String, derivationPath: String?, isExcludeCustom: Boolean): List<Currency>
|
||||
|
||||
@Throws(IllegalStateException::class)
|
||||
fun getNativeTokenForNetwork(networkId: String): Currency
|
||||
|
||||
/**
|
||||
* Returns user walletId or empty string
|
||||
*/
|
||||
fun getWalletId(): String
|
||||
|
||||
/**
|
||||
* Checks that token added to user wallet
|
||||
*
|
||||
* @param currency to receive referral payments
|
||||
*/
|
||||
@Throws(IllegalStateException::class)
|
||||
suspend fun isTokenAdded(currency: Currency, derivationPath: String?): Boolean
|
||||
|
||||
suspend fun hideAllTokens()
|
||||
|
||||
/**
|
||||
|
|
@ -41,21 +23,6 @@ interface UserWalletManager {
|
|||
@Throws(IllegalStateException::class)
|
||||
suspend fun getWalletAddress(networkId: String, derivationPath: String?): String
|
||||
|
||||
/**
|
||||
* Return balances from wallet found by networkId
|
||||
*
|
||||
* @param networkId
|
||||
* @param extraTokens tokens you want to check balance that not exists in wallet
|
||||
* @param derivationPath if null uses default
|
||||
* @return map of <Symbol, [ProxyAmount]>
|
||||
*/
|
||||
@Throws(IllegalStateException::class)
|
||||
suspend fun getCurrentWalletTokensBalance(
|
||||
networkId: String,
|
||||
extraTokens: List<Currency>,
|
||||
derivationPath: String?,
|
||||
): Map<String, ProxyAmount>
|
||||
|
||||
@Throws(IllegalStateException::class)
|
||||
suspend fun getNativeTokenBalance(networkId: String, derivationPath: String?): ProxyAmount?
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue