diff --git a/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeBiometric.kt b/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeBiometric.kt index 93c7b6c07..277f3815a 100644 --- a/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeBiometric.kt +++ b/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeBiometric.kt @@ -1,7 +1,6 @@ package com.tonapps.wallet.data.passcode import android.content.Context -import android.util.Log import androidx.biometric.BiometricManager import androidx.biometric.BiometricPrompt import androidx.core.content.ContextCompat diff --git a/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeHelper.kt b/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeHelper.kt index 57c3e5303..7506bf47b 100644 --- a/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeHelper.kt +++ b/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeHelper.kt @@ -1,13 +1,11 @@ package com.tonapps.wallet.data.passcode import android.content.Context -import android.graphics.Color -import com.tonapps.extensions.bestMessage +import com.tonapps.extensions.logError import com.tonapps.wallet.data.account.AccountRepository import com.tonapps.wallet.data.passcode.source.PasscodeStore import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import uikit.navigation.Navigation.Companion.navigation class PasscodeHelper( private val store: PasscodeStore, @@ -46,7 +44,7 @@ class PasscodeHelper( store.setPinCode(code) true } catch (e: Throwable) { - context.navigation?.toast(e.bestMessage, false, Color.RED) + context.logError(e) false } } diff --git a/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeManager.kt b/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeManager.kt index 5318cbc8c..05b29610f 100644 --- a/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeManager.kt +++ b/apps/wallet/data/passcode/src/main/java/com/tonapps/wallet/data/passcode/PasscodeManager.kt @@ -1,9 +1,7 @@ package com.tonapps.wallet.data.passcode import android.content.Context -import android.graphics.Color -import androidx.fragment.app.FragmentActivity -import com.tonapps.extensions.bestMessage +import com.tonapps.extensions.logError import com.tonapps.wallet.data.account.AccountRepository import com.tonapps.wallet.data.passcode.dialog.PasscodeDialog import com.tonapps.wallet.data.rn.RNLegacy @@ -13,9 +11,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.flow import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import uikit.extensions.showError import uikit.navigation.Navigation -import uikit.navigation.Navigation.Companion.navigation class PasscodeManager( private val accountRepository: AccountRepository, @@ -61,7 +57,7 @@ class PasscodeManager( migration(context, code) true } catch (e: Throwable) { - context.showError(e) + context.logError(e) false } } @@ -81,7 +77,7 @@ class PasscodeManager( } true } catch (e: Throwable) { - context.showError(e) + context.logError(e) false } } @@ -132,7 +128,7 @@ class PasscodeManager( migration(context, passcode) true } catch (e: Throwable) { - context.showError(e) + context.logError(e) false } } diff --git a/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/core/entities/StakedEntity.kt b/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/core/entities/StakedEntity.kt index 73b40d888..4559efba7 100644 --- a/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/core/entities/StakedEntity.kt +++ b/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/core/entities/StakedEntity.kt @@ -22,6 +22,9 @@ data class StakedEntity( staking: StakingEntity, tokens: List ): List { + if (true) { + return emptyList() + } val list = mutableListOf() val activePools = getActivePools(staking, tokens) for (pool in activePools) { diff --git a/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/core/history/list/holder/HistoryActionHolder.kt b/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/core/history/list/holder/HistoryActionHolder.kt index 00978f6c1..1f4cd8b6d 100644 --- a/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/core/history/list/holder/HistoryActionHolder.kt +++ b/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/core/history/list/holder/HistoryActionHolder.kt @@ -9,6 +9,7 @@ import androidx.annotation.ColorInt import androidx.appcompat.widget.AppCompatTextView import com.facebook.imagepipeline.postprocessors.BlurPostProcessor import com.facebook.imagepipeline.request.ImageRequestBuilder +import com.tonapps.extensions.logError import com.tonapps.icu.CurrencyFormatter.withCustomSymbol import com.tonapps.tonkeeper.core.history.ActionType import com.tonapps.tonkeeper.core.history.HistoryHelper @@ -35,7 +36,6 @@ import uikit.extensions.clearDrawables import uikit.extensions.drawable import uikit.extensions.reject import uikit.extensions.setLeftDrawable -import uikit.extensions.showError import uikit.navigation.Navigation import uikit.navigation.Navigation.Companion.navigation import uikit.widget.FrescoView @@ -185,7 +185,7 @@ class HistoryActionHolder( val scope = lifecycleScope ?: return val flow = context.historyHelper?.requestDecryptComment(context, comment, txId, senderAddress) ?: return flow.catch { - context.showError(it) + context.logError(it) commentView.reject() }.onEach { bindComment(it, txId, senderAddress) diff --git a/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/root/RootActivity.kt b/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/root/RootActivity.kt index 7c33c4060..fc2edd869 100644 --- a/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/root/RootActivity.kt +++ b/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/root/RootActivity.kt @@ -4,12 +4,16 @@ import android.content.Intent import android.net.Uri import android.os.Bundle import android.os.Handler +import android.util.Log import android.view.View import androidx.biometric.BiometricPrompt import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.updatePadding +import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle +import androidx.lifecycle.whenCreated import com.tonapps.tonkeeper.ui.screen.transaction.TransactionScreen import com.tonapps.tonkeeper.extensions.toast import com.tonapps.tonkeeper.fragment.tonconnect.auth.TCAuthFragment @@ -36,6 +40,7 @@ import com.tonapps.wallet.localization.Localization import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.launch import org.koin.android.ext.android.inject import org.koin.androidx.viewmodel.ext.android.viewModel import uikit.dialog.alert.AlertDialog @@ -57,6 +62,7 @@ class RootActivity: BaseWalletActivity() { override fun onCreate(savedInstanceState: Bundle?) { setTheme(viewModel.theme.resId) super.onCreate(savedInstanceState) + Log.d("RootViewModel", "onCreate: $viewModel") legacyRN.setActivity(this) windowInsetsController.isAppearanceLightStatusBars = viewModel.theme.light windowInsetsController.isAppearanceLightNavigationBars = viewModel.theme.light @@ -84,7 +90,8 @@ class RootActivity: BaseWalletActivity() { collectFlow(viewModel.passcodeFlow, ::passcodeFlow) collectFlow(viewModel.themeFlow) { - recreate() + viewModelStore.clear() + recreate() // Call after theme change } } diff --git a/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/root/RootViewModel.kt b/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/root/RootViewModel.kt index a9e104d38..4b5634adf 100644 --- a/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/root/RootViewModel.kt +++ b/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/root/RootViewModel.kt @@ -100,6 +100,8 @@ class RootViewModel( val biometric: Boolean, ) + private val selectedWalletFlow: Flow = accountRepository.selectedWalletFlow + private val _hasWalletFlow = MutableEffectFlow() val hasWalletFlow = _hasWalletFlow.asSharedFlow().filterNotNull() @@ -117,6 +119,7 @@ class RootViewModel( val tonConnectEventsFlow = tonConnectRepository.eventsFlow init { + Log.d("RootViewModel", "init") combine( settingsRepository.biometricFlow.take(1), settingsRepository.lockscreenFlow.take(1) @@ -141,7 +144,7 @@ class RootViewModel( }.flowOn(Dispatchers.IO).launchIn(viewModelScope) combine( - accountRepository.selectedWalletFlow, + selectedWalletFlow, settingsRepository.hiddenBalancesFlow ) { wallet, hiddenBalance -> val wallets = accountRepository.getWallets() @@ -156,8 +159,11 @@ class RootViewModel( settingsRepository.firebaseToken = GooglePushService.requestToken() } - collectFlow(accountRepository.selectedWalletFlow, ::applyAnalyticsKeys) - collectFlow(accountRepository.selectedWalletFlow, ::initShortcuts) + collectFlow(selectedWalletFlow) { wallet -> + applyAnalyticsKeys(wallet) + initShortcuts(wallet) + } + collectFlow(api.configFlow.take(1)) { config -> AnalyticsHelper.setConfig(context, config) AnalyticsHelper.trackEvent("launch_app") @@ -242,7 +248,7 @@ class RootViewModel( context: Context, request: SignRequestEntity ): String { - val wallet = accountRepository.selectedWalletFlow.firstOrNull() ?: throw Exception("wallet is null") + val wallet = selectedWalletFlow.firstOrNull() ?: throw Exception("wallet is null") return requestSign(context, wallet, request) } @@ -271,7 +277,7 @@ class RootViewModel( url: String, json: JSONObject ): String? { - val wallet = accountRepository.selectedWalletFlow.firstOrNull() ?: throw IllegalStateException("No active wallet") + val wallet = selectedWalletFlow.firstOrNull() ?: throw IllegalStateException("No active wallet") val app = tonConnectRepository.getConnect(url, wallet) ?: throw IllegalStateException("No app") val event = DAppEventEntity(wallet.copy(), app.copy(), json) if (event.method != "sendTransaction") { @@ -319,7 +325,7 @@ class RootViewModel( } return } - accountRepository.selectedWalletFlow.take(1).onEach { wallet -> + selectedWalletFlow.take(1).onEach { wallet -> delay(1000) resolveOther(refSource, uri, wallet) }.launchIn(viewModelScope) @@ -392,7 +398,7 @@ class RootViewModel( private fun showTransaction(hash: String) { viewModelScope.launch(Dispatchers.IO) { - val wallet = accountRepository.selectedWalletFlow.firstOrNull() ?: return@launch + val wallet = selectedWalletFlow.firstOrNull() ?: return@launch val item = historyHelper.getEvent(wallet, hash).filterIsInstance().firstOrNull() ?: return@launch _eventFlow.tryEmit(RootEvent.Transaction(item)) } diff --git a/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/transaction/TransactionScreen.kt b/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/transaction/TransactionScreen.kt index a5a036a40..a4613e129 100644 --- a/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/transaction/TransactionScreen.kt +++ b/apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/ui/screen/transaction/TransactionScreen.kt @@ -9,6 +9,7 @@ import androidx.appcompat.widget.LinearLayoutCompat import androidx.lifecycle.lifecycleScope import com.tonapps.extensions.getParcelableCompat import com.tonapps.extensions.ifPunycodeToUnicode +import com.tonapps.extensions.logError import com.tonapps.icu.CurrencyFormatter.withCustomSymbol import com.tonapps.tonkeeper.api.shortAddress import com.tonapps.tonkeeper.api.shortHash @@ -34,7 +35,6 @@ import uikit.base.BaseFragment import uikit.extensions.drawable import uikit.extensions.reject import uikit.extensions.setColor -import uikit.extensions.showError import uikit.navigation.Navigation.Companion.navigation import uikit.widget.FrescoView @@ -208,7 +208,7 @@ class TransactionScreen: BaseFragment(R.layout.dialog_transaction), BaseFragment private fun decryptComment(comment: HistoryItem.Event.Comment) { historyHelper.requestDecryptComment(requireContext(), comment, action.txId, action.senderAddress ?: "").catch { - context?.showError(it) + context?.logError(it) commentView.reject() }.onEach { applyComment(it) diff --git a/lib/extensions/src/main/java/com/tonapps/extensions/Context.kt b/lib/extensions/src/main/java/com/tonapps/extensions/Context.kt index 3159c8e7e..11a43ba5f 100644 --- a/lib/extensions/src/main/java/com/tonapps/extensions/Context.kt +++ b/lib/extensions/src/main/java/com/tonapps/extensions/Context.kt @@ -8,6 +8,7 @@ import android.content.pm.PackageInfo import android.os.Build import android.security.keystore.KeyGenParameterSpec import android.security.keystore.KeyProperties +import android.util.Log import androidx.activity.ComponentActivity import androidx.annotation.RawRes import androidx.security.crypto.EncryptedSharedPreferences @@ -68,3 +69,8 @@ val Context.activity: ComponentActivity? return null } + +fun Context.logError(e: Throwable) { + // +} + diff --git a/ui/uikit/core/src/main/java/uikit/extensions/Context.kt b/ui/uikit/core/src/main/java/uikit/extensions/Context.kt index 89048ac34..eec54a102 100644 --- a/ui/uikit/core/src/main/java/uikit/extensions/Context.kt +++ b/ui/uikit/core/src/main/java/uikit/extensions/Context.kt @@ -130,13 +130,3 @@ fun Context.getCurrentFocusEditText(): EditText? { fun Context.hideKeyboard() { (activity?.currentFocus as? EditText)?.hideKeyboard() } - -fun Context.showError(e: Throwable) { - Log.e("AppErrorLog", "error", e) - val bestMessage = e.localizedMessage ?: e.message ?: toString() - if (navigation == null) { - Toast.makeText(this, bestMessage, Toast.LENGTH_LONG).show() - } else { - navigation?.toast(bestMessage, false, Color.RED) - } -} \ No newline at end of file diff --git a/ui/uikit/core/src/main/java/uikit/widget/ToastView.kt b/ui/uikit/core/src/main/java/uikit/widget/ToastView.kt index 5c97afead..60e7aec4f 100644 --- a/ui/uikit/core/src/main/java/uikit/widget/ToastView.kt +++ b/ui/uikit/core/src/main/java/uikit/widget/ToastView.kt @@ -70,6 +70,12 @@ class ToastView @JvmOverloads constructor( } fun show(text: CharSequence, loading: Boolean, color: Int = context.backgroundContentTintColor) { + val isUIThread = Thread.currentThread() == android.os.Looper.getMainLooper().thread + if (!isUIThread) { + post { show(text, loading, color) } + return + } + val data = Data(loading, text, if (color == Color.TRANSPARENT) context.backgroundContentTintColor else color) val cancelCurrent = currentData?.let { it.text == text && it.color == (if (color == Color.TRANSPARENT) context.backgroundContentTintColor else color)