diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingWalletFragment.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingWalletFragment.kt index 2eb4abdc18..aa714f2c28 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingWalletFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingWalletFragment.kt @@ -191,7 +191,7 @@ class OnboardingWalletFragment : } } - internal fun loadImageIntoImageView(uri: Uri?, view: ImageView) { + private fun loadImageIntoImageView(uri: Uri?, view: ImageView) { view.load(uri) { placeholder(R.drawable.card_placeholder_black) error(R.drawable.card_placeholder_black) @@ -412,7 +412,7 @@ class OnboardingWalletFragment : animator.showWriteBackupCard(state, cardNumber) } - internal fun showSuccess() = with(binding) { + private fun showSuccess() = with(binding) { toolbar.title = getString(R.string.onboarding_done_header) tvHeader.text = getText(R.string.onboarding_done_header) @@ -427,9 +427,7 @@ class OnboardingWalletFragment : layoutButtonsCommon.btnWalletAlternativeAction.hide() layoutButtonsCommon.btnWalletMainAction.setOnClickListener { showConfetti(false) - lifecycleScope.launch { - store.dispatch(OnboardingWalletAction.FinishOnboarding(lifecycleCoroutineScope = lifecycleScope)) - } + store.dispatch(OnboardingWalletAction.FinishOnboarding(lifecycleCoroutineScope = lifecycleScope)) } animator.showSuccess { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt index 23054b94df..a182b01ae7 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt @@ -1012,21 +1012,31 @@ internal class WalletViewModel @Inject constructor( } } - private fun initAndSetupWc(tokenListFlow: SharedFlow>, wallet: UserWallet) { - initWalletConnectForWallet(wallet) - tokenListFlow - .filter(::filterLoadedTokenList) - .take(1) - .onEach { - it.onRight { - setupWalletConnectOnWallet(wallet) - } + private fun initAndSetupWc(tokenListFlow: MaybeTokenListFlow, wallet: UserWallet) { + viewModelScope + .launch(dispatchers.main) { + initWalletConnectForWallet(wallet) + + tokenListFlow + .filterLoadedTokenList() + .take(count = 1) + .collect { setupWalletConnectOnWallet(wallet) } } - .flowOn(dispatchers.io) - .launchIn(viewModelScope) .saveIn(updateWcJobHolder) } + private fun initWalletConnectForWallet(userWallet: UserWallet) { + reduxStateHolder.dispatch( + action = WalletConnectActions.New.Initialize(userWallet = userWallet), + ) + } + + private fun setupWalletConnectOnWallet(userWallet: UserWallet) { + reduxStateHolder.dispatch( + action = WalletConnectActions.New.SetupUserChains(userWallet = userWallet), + ) + } + private fun isSingleWalletWithTokens(userWallet: UserWallet): Boolean { return userWallet.scanResponse.walletData?.token != null && !userWallet.isMultiCurrency } @@ -1035,23 +1045,23 @@ internal class WalletViewModel @Inject constructor( return !this.any { it.value is CryptoCurrencyStatus.Loading } } - private fun filterLoadedTokenList(either: Either): Boolean { - return either.fold( - ifRight = { list -> - when (list) { - is TokenList.Ungrouped -> { - list.currencies.isAllCurrenciesLoaded() + private fun MaybeTokenListFlow.filterLoadedTokenList(): MaybeTokenListFlow { + return filter { either -> + either.fold( + ifRight = { list -> + when (list) { + is TokenList.Ungrouped -> { + list.currencies.isAllCurrenciesLoaded() + } + is TokenList.GroupedByNetwork -> { + list.groups.flatMap(NetworkGroup::currencies).isAllCurrenciesLoaded() + } + else -> false } - is TokenList.GroupedByNetwork -> { - list.groups.flatMap { group -> group.currencies }.isAllCurrenciesLoaded() - } - else -> { - false - } - } - }, - ifLeft = { false }, - ) + }, + ifLeft = { false }, + ) + } } private fun List.hasNonZeroWallets(): Boolean { @@ -1187,18 +1197,6 @@ internal class WalletViewModel @Inject constructor( ) } - private fun initWalletConnectForWallet(userWallet: UserWallet) { - reduxStateHolder.dispatch( - WalletConnectActions.New.Initialize(userWallet = userWallet), - ) - } - - private fun setupWalletConnectOnWallet(userWallet: UserWallet) { - reduxStateHolder.dispatch( - WalletConnectActions.New.SetupUserChains(userWallet = userWallet), - ) - } - private fun getWallet(index: Int): UserWallet { return requireNotNull( value = wallets.getOrNull(index), @@ -1214,4 +1212,6 @@ internal class WalletViewModel @Inject constructor( } private fun getCardTypeResolver(index: Int): CardTypesResolver = getWallet(index).scanResponse.cardTypesResolver -} \ No newline at end of file +} + +typealias MaybeTokenListFlow = Flow> \ No newline at end of file