Skip to content

Commit

Permalink
bug fixeds
Browse files Browse the repository at this point in the history
  • Loading branch information
polstianka committed Aug 24, 2024
1 parent 8d6ca04 commit 0321de7
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -61,7 +57,7 @@ class PasscodeManager(
migration(context, code)
true
} catch (e: Throwable) {
context.showError(e)
context.logError(e)
false
}
}
Expand All @@ -81,7 +77,7 @@ class PasscodeManager(
}
true
} catch (e: Throwable) {
context.showError(e)
context.logError(e)
false
}
}
Expand Down Expand Up @@ -132,7 +128,7 @@ class PasscodeManager(
migration(context, passcode)
true
} catch (e: Throwable) {
context.showError(e)
context.logError(e)
false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ data class StakedEntity(
staking: StakingEntity,
tokens: List<AccountTokenEntity>
): List<StakedEntity> {
if (true) {
return emptyList()
}
val list = mutableListOf<StakedEntity>()
val activePools = getActivePools(staking, tokens)
for (pool in activePools) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -84,7 +90,8 @@ class RootActivity: BaseWalletActivity() {
collectFlow(viewModel.passcodeFlow, ::passcodeFlow)

collectFlow(viewModel.themeFlow) {
recreate()
viewModelStore.clear()
recreate() // Call after theme change
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class RootViewModel(
val biometric: Boolean,
)

private val selectedWalletFlow: Flow<WalletEntity> = accountRepository.selectedWalletFlow

private val _hasWalletFlow = MutableEffectFlow<Boolean?>()
val hasWalletFlow = _hasWalletFlow.asSharedFlow().filterNotNull()

Expand All @@ -117,6 +119,7 @@ class RootViewModel(
val tonConnectEventsFlow = tonConnectRepository.eventsFlow

init {
Log.d("RootViewModel", "init")
combine(
settingsRepository.biometricFlow.take(1),
settingsRepository.lockscreenFlow.take(1)
Expand All @@ -141,7 +144,7 @@ class RootViewModel(
}.flowOn(Dispatchers.IO).launchIn(viewModelScope)

combine(
accountRepository.selectedWalletFlow,
selectedWalletFlow,
settingsRepository.hiddenBalancesFlow
) { wallet, hiddenBalance ->
val wallets = accountRepository.getWallets()
Expand All @@ -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")
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<HistoryItem.Event>().firstOrNull() ?: return@launch
_eventFlow.tryEmit(RootEvent.Transaction(item))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,3 +69,8 @@ val Context.activity: ComponentActivity?
return null
}


fun Context.logError(e: Throwable) {
//
}

10 changes: 0 additions & 10 deletions ui/uikit/core/src/main/java/uikit/extensions/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 6 additions & 0 deletions ui/uikit/core/src/main/java/uikit/widget/ToastView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0321de7

Please sign in to comment.