Skip to content

Commit

Permalink
bug fixeds
Browse files Browse the repository at this point in the history
  • Loading branch information
polstianka committed Sep 27, 2024
1 parent 21800ae commit 40fd373
Show file tree
Hide file tree
Showing 169 changed files with 405 additions and 373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import androidx.annotation.ColorInt
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import com.tonapps.blockchain.ton.contract.WalletVersion
import com.tonapps.extensions.bestMessage
import com.tonapps.tonkeeperx.BuildConfig
import com.tonapps.uikit.color.accentGreenColor
import com.tonapps.uikit.color.accentRedColor
import com.tonapps.uikit.color.backgroundContentTintColor
import com.tonapps.uikit.color.textSecondaryColor
import com.tonapps.wallet.data.account.Wallet
import com.tonapps.wallet.localization.Localization
import uikit.navigation.Navigation
import uikit.navigation.Navigation.Companion.navigation

fun Context.showToast(@StringRes resId: Int) {
Expand Down Expand Up @@ -120,3 +123,13 @@ fun Context.getWalletBadges(

return builder
}

fun Context.debugToast(e: Throwable) {
debugToast(e.bestMessage)
}

fun Context.debugToast(text: String) {
if (BuildConfig.DEBUG) {
Navigation.from(this)?.toast(text)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class LedgerProofScreen : BaseFragment(R.layout.fragment_ledger_sign), BaseFragm
}

is LedgerEvent.Rejected -> {

finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.res.Configuration
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
Expand Down Expand Up @@ -53,7 +52,10 @@ import uikit.navigation.Navigation.Companion.navigation

class RootActivity: BaseWalletActivity() {

override val viewModel: RootViewModel by viewModel()
private var rootViewModel: Lazy<RootViewModel>? = null

override val viewModel: RootViewModel
get() = rootViewModel!!.value

private val legacyRN: RNLegacy by inject()

Expand All @@ -64,6 +66,7 @@ class RootActivity: BaseWalletActivity() {
private lateinit var lockSignOut: View

override fun onCreate(savedInstanceState: Bundle?) {
rootViewModel = viewModel<RootViewModel>()
setTheme(viewModel.theme.resId)
supportFragmentManager.fragmentFactory = WalletFragmentFactory()
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -103,8 +106,9 @@ class RootActivity: BaseWalletActivity() {
}

override fun onDestroy() {
viewModelStore.clear()
super.onDestroy()
viewModelStore.clear()
rootViewModel = null
}

override fun onConfigurationChanged(newConfig: Configuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.tonapps.tonkeeper.ui.screen.root
import android.app.Application
import android.content.Context
import android.net.Uri
import android.util.Log
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.lifecycle.viewModelScope
Expand Down Expand Up @@ -46,10 +45,8 @@ import com.tonapps.wallet.data.purchase.PurchaseRepository
import com.tonapps.wallet.data.settings.SettingsRepository
import com.tonapps.wallet.localization.Localization
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
Expand Down Expand Up @@ -90,7 +87,7 @@ class RootViewModel(
private val _hasWalletFlow = MutableEffectFlow<Boolean?>()
val hasWalletFlow = _hasWalletFlow.asSharedFlow().filterNotNull()

private val _eventFlow = MutableSharedFlow<RootEvent>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
private val _eventFlow = MutableEffectFlow<RootEvent?>()
val eventFlow = _eventFlow.asSharedFlow().filterNotNull()

private val _passcodeFlow = MutableStateFlow<Passcode?>(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.tonapps.emoji.ui.EmojiView
import com.tonapps.extensions.getParcelableCompat
import com.tonapps.extensions.short4
import com.tonapps.tonkeeper.dialog.tc.TonConnectCryptoView
import com.tonapps.tonkeeper.extensions.debugToast
import com.tonapps.tonkeeper.extensions.getWalletBadges
import com.tonapps.tonkeeper.extensions.toast
import com.tonapps.tonkeeper.manager.tonconnect.bridge.model.BridgeError
Expand Down Expand Up @@ -114,7 +115,7 @@ class TonConnectScreen: BaseWalletScreen<ScreenContext.None>(R.layout.fragment_t
if (initialWallet == null) {
collectFlow(viewModel.stateFlow, ::applyState)
} else {
applyState(TonConnectScreenState(initialWallet, false))
applyState(TonConnectScreenState.Data(initialWallet, false))
}

setDefaultState()
Expand All @@ -133,8 +134,10 @@ class TonConnectScreen: BaseWalletScreen<ScreenContext.None>(R.layout.fragment_t
val proof = viewModel.requestProof(wallet, args.app, proofPayload)
setResponse(wallet, proof)
} catch (e: CancellationException) {
context?.debugToast(e)
setDefaultState()
} catch (e: Throwable) {
context?.debugToast(e)
setFailedState()
}
}
Expand Down Expand Up @@ -219,6 +222,15 @@ class TonConnectScreen: BaseWalletScreen<ScreenContext.None>(R.layout.fragment_t
}

private fun applyState(state: TonConnectScreenState) {
if (state is TonConnectScreenState.Data) {
applyDataState(state)
} else {
navigation?.toast(Localization.not_supported)
finish()
}
}

private fun applyDataState(state: TonConnectScreenState.Data) {
loaderView.visibility = View.GONE
bodyView.visibility = View.VISIBLE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ package com.tonapps.tonkeeper.ui.screen.tonconnect
import com.tonapps.wallet.data.account.entities.WalletEntity
import com.tonapps.wallet.data.dapps.entities.AppEntity

data class TonConnectScreenState(
val wallet: WalletEntity,
val hasWalletPicker: Boolean
)
sealed class TonConnectScreenState {

data class Data(
val wallet: WalletEntity,
val hasWalletPicker: Boolean
): TonConnectScreenState()

data object Failure: TonConnectScreenState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ class TonConnectViewModel(
init {
viewModelScope.launch(Dispatchers.IO) {
val wallet = accountRepository.selectedWalletFlow.firstOrNull() ?: run {
finish()
_stateFlow.value = TonConnectScreenState.Failure
return@launch
}

val wallets = accountRepository.getWallets().filter { it.isTonConnectSupported }

if (wallets.isEmpty()) {
finish()
_stateFlow.value = TonConnectScreenState.Failure
return@launch
}

val walletsCount = wallets.size

_stateFlow.value = TonConnectScreenState(
_stateFlow.value = TonConnectScreenState.Data(
wallet = if (wallet.isTonConnectSupported) wallet else wallets.first(),
hasWalletPicker = walletsCount > 1
)
Expand All @@ -61,7 +61,7 @@ class TonConnectViewModel(
) = signUseCase(context, wallet, app.url.host!!, proofPayload)

fun setWallet(wallet: WalletEntity) {
val state = _stateFlow.value ?: return
val state = _stateFlow.value as? TonConnectScreenState.Data ?: return
_stateFlow.value = state.copy(wallet = wallet)
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<merger version="3"><dataSet config="androidx.benchmark:benchmark-common:1.3.0" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/polstianka/.gradle/caches/transforms-4/63381d42c15960d22bf355e8c1f9e48b/transformed/benchmark-common-1.3.0/assets"><file name="tracebox_x86" path="/Users/polstianka/.gradle/caches/transforms-4/63381d42c15960d22bf355e8c1f9e48b/transformed/benchmark-common-1.3.0/assets/tracebox_x86"/><file name="tracebox_arm" path="/Users/polstianka/.gradle/caches/transforms-4/63381d42c15960d22bf355e8c1f9e48b/transformed/benchmark-common-1.3.0/assets/tracebox_arm"/><file name="tracebox_x86_64" path="/Users/polstianka/.gradle/caches/transforms-4/63381d42c15960d22bf355e8c1f9e48b/transformed/benchmark-common-1.3.0/assets/tracebox_x86_64"/><file name="tracebox_aarch64" path="/Users/polstianka/.gradle/caches/transforms-4/63381d42c15960d22bf355e8c1f9e48b/transformed/benchmark-common-1.3.0/assets/tracebox_aarch64"/></source></dataSet><dataSet config="androidx.benchmark:benchmark-macro:1.3.0" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/polstianka/.gradle/caches/transforms-4/16568daeee848ddfded80f92edd577dc/transformed/benchmark-macro-1.3.0/assets"><file name="trace_processor_shell_x86" path="/Users/polstianka/.gradle/caches/transforms-4/16568daeee848ddfded80f92edd577dc/transformed/benchmark-macro-1.3.0/assets/trace_processor_shell_x86"/><file name="trace_processor_shell_arm" path="/Users/polstianka/.gradle/caches/transforms-4/16568daeee848ddfded80f92edd577dc/transformed/benchmark-macro-1.3.0/assets/trace_processor_shell_arm"/><file name="trace_processor_shell_aarch64" path="/Users/polstianka/.gradle/caches/transforms-4/16568daeee848ddfded80f92edd577dc/transformed/benchmark-macro-1.3.0/assets/trace_processor_shell_aarch64"/><file name="trace_processor_shell_x86_64" path="/Users/polstianka/.gradle/caches/transforms-4/16568daeee848ddfded80f92edd577dc/transformed/benchmark-macro-1.3.0/assets/trace_processor_shell_x86_64"/></source></dataSet><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/polstianka/StudioProjects/TonkeeperX/baselineprofile/main/src/main/assets"/></dataSet><dataSet config="nonMinifiedRelease" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/polstianka/StudioProjects/TonkeeperX/baselineprofile/main/src/nonMinifiedRelease/assets"/></dataSet><dataSet config="generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/polstianka/StudioProjects/TonkeeperX/baselineprofile/main/build/intermediates/shader_assets/nonMinifiedRelease/compileNonMinifiedReleaseShaders/out"/></dataSet></merger>
<merger version="3"><dataSet config="androidx.benchmark:benchmark-common:1.3.0" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/polstianka/.gradle/caches/transforms-4/fc804f6b4c4b982f5eaa9ac9186ba5ab/transformed/benchmark-common-1.3.0/assets"><file name="tracebox_x86" path="/Users/polstianka/.gradle/caches/transforms-4/fc804f6b4c4b982f5eaa9ac9186ba5ab/transformed/benchmark-common-1.3.0/assets/tracebox_x86"/><file name="tracebox_arm" path="/Users/polstianka/.gradle/caches/transforms-4/fc804f6b4c4b982f5eaa9ac9186ba5ab/transformed/benchmark-common-1.3.0/assets/tracebox_arm"/><file name="tracebox_x86_64" path="/Users/polstianka/.gradle/caches/transforms-4/fc804f6b4c4b982f5eaa9ac9186ba5ab/transformed/benchmark-common-1.3.0/assets/tracebox_x86_64"/><file name="tracebox_aarch64" path="/Users/polstianka/.gradle/caches/transforms-4/fc804f6b4c4b982f5eaa9ac9186ba5ab/transformed/benchmark-common-1.3.0/assets/tracebox_aarch64"/></source></dataSet><dataSet config="androidx.benchmark:benchmark-macro:1.3.0" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/polstianka/.gradle/caches/transforms-4/de6db320ae1d7ec6d148cb3204213225/transformed/benchmark-macro-1.3.0/assets"><file name="trace_processor_shell_x86" path="/Users/polstianka/.gradle/caches/transforms-4/de6db320ae1d7ec6d148cb3204213225/transformed/benchmark-macro-1.3.0/assets/trace_processor_shell_x86"/><file name="trace_processor_shell_arm" path="/Users/polstianka/.gradle/caches/transforms-4/de6db320ae1d7ec6d148cb3204213225/transformed/benchmark-macro-1.3.0/assets/trace_processor_shell_arm"/><file name="trace_processor_shell_aarch64" path="/Users/polstianka/.gradle/caches/transforms-4/de6db320ae1d7ec6d148cb3204213225/transformed/benchmark-macro-1.3.0/assets/trace_processor_shell_aarch64"/><file name="trace_processor_shell_x86_64" path="/Users/polstianka/.gradle/caches/transforms-4/de6db320ae1d7ec6d148cb3204213225/transformed/benchmark-macro-1.3.0/assets/trace_processor_shell_x86_64"/></source></dataSet><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/polstianka/StudioProjects/TonkeeperX/baselineprofile/main/src/main/assets"/></dataSet><dataSet config="nonMinifiedRelease" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/polstianka/StudioProjects/TonkeeperX/baselineprofile/main/src/nonMinifiedRelease/assets"/></dataSet><dataSet config="generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/polstianka/StudioProjects/TonkeeperX/baselineprofile/main/build/intermediates/shader_assets/nonMinifiedRelease/compileNonMinifiedReleaseShaders/out"/></dataSet></merger>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#Sun Sep 08 06:36:12 EDT 2024
#Fri Sep 27 05:43:33 PDT 2024
Loading

0 comments on commit 40fd373

Please sign in to comment.