Skip to content

Commit

Permalink
bug fixeds
Browse files Browse the repository at this point in the history
  • Loading branch information
polstianka committed Oct 31, 2024
1 parent e456a68 commit 2b1d1f1
Show file tree
Hide file tree
Showing 59 changed files with 647 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.tonapps.wallet.data.account
import android.app.KeyguardManager
import android.content.Context
import android.util.Log
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.tonapps.blockchain.ton.contract.BaseWalletContract
import com.tonapps.blockchain.ton.contract.WalletVersion
import com.tonapps.blockchain.ton.contract.walletVersion
Expand All @@ -19,6 +20,7 @@ import com.tonapps.wallet.data.account.entities.WalletEvent
import com.tonapps.wallet.data.account.source.DatabaseSource
import com.tonapps.wallet.data.account.source.StorageSource
import com.tonapps.wallet.data.account.source.VaultSource
import com.tonapps.wallet.data.core.recordException
import com.tonapps.wallet.data.rn.RNLegacy
import com.tonapps.wallet.data.rn.data.RNKeystone
import com.tonapps.wallet.data.rn.data.RNLedger
Expand Down Expand Up @@ -69,8 +71,8 @@ class AccountRepository(

private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
private val database = DatabaseSource(context, scope)
private val storageSource: StorageSource by lazy { StorageSource(context) }
private val vaultSource: VaultSource by lazy { VaultSource(context) }
private val storageSource: StorageSource by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { StorageSource(context) }
private val vaultSource: VaultSource by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { VaultSource(context) }
private val migrationHelper = RNMigrationHelper(rnLegacy)

private val _selectedStateFlow = MutableStateFlow<SelectedState>(SelectedState.Initialization)
Expand Down Expand Up @@ -376,6 +378,7 @@ class AccountRepository(
)
api.tonconnectProof(address.toAccountId(), proof.string(false))
} catch (e: Throwable) {
recordException(e)
null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class StorageSource(context: Context) {
}

private val prefs = context.prefs(NAME)
private val encryptedPrefs: SharedPreferences by lazy { Security.pref(context, KEY_ALIAS, NAME) }
private val encryptedPrefs: SharedPreferences by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { Security.pref(context, KEY_ALIAS, NAME) }

fun getTonProofToken(publicKey: PublicKeyEd25519): String? {
val key = tonProofTokenKey(publicKey)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tonapps.wallet.data.account.source

import android.content.Context
import android.content.SharedPreferences
import androidx.core.content.edit
import com.tonapps.blockchain.ton.extensions.hex
import com.tonapps.extensions.getByteArray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.net.Uri
import android.util.Log
import androidx.collection.ArrayMap
import androidx.core.net.toUri
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.tonapps.blockchain.ton.extensions.toRawAddress
import com.tonapps.blockchain.ton.extensions.toUserFriendly
import com.tonapps.extensions.map
Expand Down Expand Up @@ -158,6 +159,7 @@ class DAppsRepository(
}
return true
} catch (e: Throwable) {
recordException(e)
return false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal class DatabaseSource(

private val coroutineContext: CoroutineContext = Dispatchers.IO.limitedParallelism(1)

private val encryptedPrefs: SharedPreferences by lazy { Security.pref(context, KEY_ALIAS, DATABASE_NAME) }
private val encryptedPrefs: SharedPreferences by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { Security.pref(context, KEY_ALIAS, DATABASE_NAME) }
private val prefs = context.prefs("tonconnect")

private fun createAppTable(db: SQLiteDatabase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fun Action.isOutTransfer(accountId: String): Boolean {
}

val Action.recipient: AccountAddress?
get() = tonTransfer?.recipient ?: jettonTransfer?.recipient ?: nftItemTransfer?.recipient ?: jettonSwap?.userWallet ?: jettonMint?.recipient ?: depositStake?.staker ?: withdrawStake?.staker ?: withdrawStakeRequest?.staker
get() = nftItemTransfer?.recipient ?: tonTransfer?.recipient ?: jettonTransfer?.recipient ?: jettonSwap?.userWallet ?: jettonMint?.recipient ?: depositStake?.staker ?: withdrawStake?.staker ?: withdrawStakeRequest?.staker

val Action.sender: AccountAddress?
get() = tonTransfer?.sender ?: jettonTransfer?.sender ?: nftItemTransfer?.sender ?: jettonSwap?.userWallet ?: jettonBurn?.sender ?: depositStake?.staker ?: withdrawStake?.staker ?: withdrawStakeRequest?.staker
get() = nftItemTransfer?.sender ?:tonTransfer?.sender ?: jettonTransfer?.sender ?: jettonSwap?.userWallet ?: jettonBurn?.sender ?: depositStake?.staker ?: withdrawStake?.staker ?: withdrawStakeRequest?.staker
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class LocalDataSource(
private val _decryptedCommentFlow = MutableEffectFlow<Unit>()
val decryptedCommentFlow = _decryptedCommentFlow.shareIn(scope, SharingStarted.WhileSubscribed(), 1)

private val encryptedPrefs: SharedPreferences by lazy { Security.pref(context, KEY_ALIAS, NAME) }
private val encryptedPrefs: SharedPreferences by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { Security.pref(context, KEY_ALIAS, NAME) }

private fun keyDecryptedComment(txId: String): String {
return "tx_$txId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PasscodeStore(context: Context) {
private const val KEY_ALIAS = "_com_tonapps_passcode_master_key_"
}

private val keyValue: SharedPreferences by lazy { Security.pref(context, KEY_ALIAS, NAME) }
private val keyValue: SharedPreferences by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { Security.pref(context, KEY_ALIAS, NAME) }

val hasPinCode: Boolean
get() = keyValue.contains(CODE_KEY) && !keyValue.getString(CODE_KEY, null).isNullOrBlank()
Expand Down
3 changes: 3 additions & 0 deletions apps/wallet/data/rn/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ android {
}

dependencies {
api(platform(Dependence.Firebase.bom))
api(Dependence.Firebase.crashlytics)

implementation(Dependence.AndroidX.biometric)
implementation(project(Dependence.Lib.sqlite))
implementation(project(Dependence.Lib.security))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.tonapps.wallet.data.rn
import android.content.Context
import android.util.Log
import androidx.fragment.app.FragmentActivity
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.tonapps.extensions.map
import com.tonapps.wallet.data.rn.data.RNDecryptedData
import com.tonapps.wallet.data.rn.data.RNFavorites
Expand All @@ -27,8 +28,14 @@ class RNLegacy(
const val DEFAULT_KEYSTORE_ALIAS = "key_v1"
}

private val sql = RNSql(context)
private val seedStorage = RNSeedStorage(context)
private val sql: RNSql by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
RNSql(context)
}

private val seedStorage: RNSeedStorage by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
RNSeedStorage(context)
}

private var cacheWallets: RNWallets? = null

@Volatile
Expand Down Expand Up @@ -121,6 +128,7 @@ class RNLegacy(
try {
seedStorage.get(passcode)
} catch (e: Throwable) {
FirebaseCrashlytics.getInstance().recordException(e)
RNVaultState()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.os.SystemClock
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.tonapps.sqlite.SQLiteHelper
import org.json.JSONArray
import org.json.JSONObject
Expand Down Expand Up @@ -41,6 +42,7 @@ internal class RNSql(context: Context): SQLiteHelper(context, DATABASE_NAME, DAT
db.close()
return value
} catch (e: Throwable) {
FirebaseCrashlytics.getInstance().recordException(e)
if (attempt > 3) {
return null
}
Expand All @@ -63,6 +65,7 @@ internal class RNSql(context: Context): SQLiteHelper(context, DATABASE_NAME, DAT
db.insertWithOnConflict(KV_TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE)
db.close()
} catch (e: Throwable) {
FirebaseCrashlytics.getInstance().recordException(e)
if (attempt > 3) {
return
}
Expand All @@ -76,6 +79,7 @@ internal class RNSql(context: Context): SQLiteHelper(context, DATABASE_NAME, DAT
return try {
JSONObject(string)
} catch (e: Throwable) {
FirebaseCrashlytics.getInstance().recordException(e)
null
}
}
Expand All @@ -85,6 +89,7 @@ internal class RNSql(context: Context): SQLiteHelper(context, DATABASE_NAME, DAT
return try {
JSONArray(string)
} catch (e: Throwable) {
FirebaseCrashlytics.getInstance().recordException(e)
null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ data class AssetsExtendedEntity(
val verified: Boolean
get() = token.verified

val blacklist: Boolean
get() = token.blacklist

val pinned: Boolean
get() = prefs.pinned

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,27 +591,26 @@ class HistoryHelper(
} else if (action.nftItemTransfer != null) {
val nftItemTransfer = action.nftItemTransfer!!

val isOut = !wallet.isMyAddress(nftItemTransfer.recipient?.address ?: "-")
val sender = nftItemTransfer.sender ?: action.simplePreview.accounts.firstOrNull()
val isBurn = nftItemTransfer.recipient?.let {
isBurnAccount(it)
} ?: false
val sender = nftItemTransfer.sender
val recipient = nftItemTransfer.recipient
val isOut = !wallet.isMyAddress(recipient?.address ?: "-")
val isBurn = recipient?.let { isBurnAccount(it) } ?: false

val itemAction: ActionType
val iconURL: String?
val subtitle: String

if (isBurn) {
itemAction = ActionType.JettonBurn
iconURL = nftItemTransfer.recipient?.iconURL
iconURL = recipient?.iconURL
subtitle = api.getBurnAddress()
} else if (isOut || wallet.isMyAddress(nftItemTransfer.sender?.address ?: "")) {
} else if (isOut || wallet.isMyAddress(sender?.address ?: "")) {
itemAction = ActionType.NftSend
iconURL = nftItemTransfer.recipient?.iconURL
subtitle = sender?.getNameOrAddress(wallet.testnet, true) ?: ""
iconURL = recipient?.iconURL
subtitle = recipient?.getNameOrAddress(wallet.testnet, true) ?: ""
} else {
itemAction = ActionType.NftReceived
iconURL = nftItemTransfer.sender?.iconURL
iconURL = sender?.iconURL
subtitle = sender?.getNameOrAddress(wallet.testnet, true) ?: ""
}

Expand Down Expand Up @@ -644,6 +643,7 @@ class HistoryHelper(
timestamp = timestamp,
date = date,
dateDetails = dateDetails,
unverifiedToken = nftItem?.verified == false,
isOut = isOut,
sender = HistoryItem.Account.ofSender(action, wallet.testnet),
recipient = HistoryItem.Account.ofRecipient(action, wallet.testnet),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.tonapps.tonkeeper.ui.screen.transaction.TransactionScreen
import com.tonapps.tonkeeper.ui.screen.nft.NftScreen
import com.tonapps.tonkeeperx.R
import com.tonapps.uikit.color.accentGreenColor
import com.tonapps.uikit.color.accentOrangeColor
import com.tonapps.uikit.color.iconSecondaryColor
import com.tonapps.uikit.color.stateList
import com.tonapps.uikit.color.textPrimaryColor
Expand Down Expand Up @@ -77,7 +78,7 @@ class HistoryActionHolder(
override fun onBind(item: HistoryItem.Event) {
commentView.clearDrawables()

unverifiedTokenView.visibility = if (item.unverifiedToken) {
unverifiedTokenView.visibility = if (item.nft == null && item.unverifiedToken) {
View.VISIBLE
} else {
View.GONE
Expand Down Expand Up @@ -210,14 +211,20 @@ class HistoryActionHolder(
Navigation.from(context)?.add(NftScreen.newInstance(item.wallet, nft))
}
loadNftImage(nft.mediumUri, item.hiddenBalance)
if (item.hiddenBalance) {
if (item.unverifiedToken) {
nftNameView.text = if (item.hiddenBalance) HIDDEN_BALANCE else nft.name
nftCollectionView.text = getString(Localization.nft_unverified)
nftCollectionView.setTextColor(context.accentOrangeColor)
} else if (item.hiddenBalance) {
nftNameView.text = HIDDEN_BALANCE
nftCollectionView.text = HIDDEN_BALANCE
nftCollectionView.setTextColor(context.textSecondaryColor)
} else {
nftNameView.text = nft.name
nftCollectionView.text = nft.collectionName.ifEmpty {
getString(Localization.unnamed_collection)
}
nftCollectionView.setTextColor(context.textSecondaryColor)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.tonapps.tonkeeper.extensions

import com.tonapps.blockchain.ton.TONOpCode
import com.tonapps.blockchain.ton.TonTransferHelper
import com.tonapps.blockchain.ton.extensions.isBounceable
import com.tonapps.blockchain.ton.extensions.loadAddress
import com.tonapps.blockchain.ton.extensions.loadCoins
import com.tonapps.blockchain.ton.extensions.loadMaybeAddress
Expand Down Expand Up @@ -142,7 +143,7 @@ fun RawMessageEntity.getWalletTransfer(
val builder = WalletTransferBuilder()
builder.destination = address
builder.messageData = MessageData.Raw(body, newStateInit ?: getStateInitRef())
// builder.bounceable = address.isBounceable()
builder.bounceable = address.isBounceable()
if (newCustomPayload != null) {
val defCoins = Coins.of(0.5)
if (defCoins.amount.value > coins.amount.value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import com.tonapps.tonkeeper.ui.screen.staking.viewer.StakeViewerViewModel
import com.tonapps.tonkeeper.ui.screen.staking.unstake.UnStakeViewModel
import com.tonapps.tonkeeper.ui.screen.staking.stake.StakingViewModel
import com.tonapps.tonkeeper.ui.screen.send.transaction.SendTransactionViewModel
import com.tonapps.tonkeeper.ui.screen.settings.apps.AppsViewModel
import com.tonapps.tonkeeper.ui.screen.staking.withdraw.StakeWithdrawViewModel
import org.koin.core.module.dsl.viewModel
import org.koin.core.module.dsl.viewModelOf

val viewModelWalletModule = module {
Expand Down Expand Up @@ -60,4 +62,5 @@ val viewModelWalletModule = module {
viewModelOf(::StakeWithdrawViewModel)
viewModelOf(::AddContactViewModel)
viewModelOf(::EditContactViewModel)
viewModelOf(::AppsViewModel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.json.JSONObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class WalletFragmentFactory: FragmentFactory() {
val fragmentClass = loadFragmentClass(classLoader, className)
val constructors = fragmentClass.constructors
if (constructors.size > 1) {
throw IllegalStateException("${fragmentClass.javaClass} class should have only one constructor")
throw IllegalStateException("$fragmentClass class should have only one constructor")
}
val constructor = constructors.first()
val parameters = constructor.parameterTypes
if (parameters.size > 1) {
throw IllegalStateException("${fragmentClass.javaClass} class should have only one constructor with one parameter")
throw IllegalStateException("$fragmentClass class should have only one constructor with one parameter")
} else if (parameters.isEmpty()) {
return fragmentClass.getConstructor().newInstance()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class CoinInputView @JvmOverloads constructor(
updateClearViewVisible()
}
editText.setRightDrawable(suffixDrawable)
editText.compoundDrawablePadding = 36.dp

clearView = findViewById(R.id.coin_input_clear)
clearView.setOnClickListener { clear() }
Expand All @@ -97,8 +96,10 @@ class CoinInputView @JvmOverloads constructor(
private fun updateSuffix() {
if (suffix.isNullOrBlank() || expanded) {
suffixDrawable.text = null
editText.compoundDrawablePadding = 0
} else {
suffixDrawable.text = suffix
editText.compoundDrawablePadding = 36.dp
}
invalidate()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class DAppViewModel(
): BaseWalletVM(app) {

val connectionFlow = tonConnectManager.walletConnectionsFlow(wallet).filterList { connection ->
connection.type == AppConnectEntity.Type.Internal && connection.appUrl == url
}.map { it.firstOrNull() }
connection.type == AppConnectEntity.Type.Internal && connection.appUrl.host == url.host
}.map {
it.firstOrNull()
}

fun mute() {
DAppPushToggleWorker.run(
Expand All @@ -56,14 +58,7 @@ class DAppViewModel(
}
}

private suspend fun loadConnection(): AppConnectEntity? = withTimeoutOrNull(2.seconds) {
while (isActive) {
val connection = connectionFlow.first()
if (connection != null) {
return@withTimeoutOrNull connection
}
delay(100)
}
return@withTimeoutOrNull null
private suspend fun loadConnection(): AppConnectEntity? {
return connectionFlow.firstOrNull()
}
}
Loading

0 comments on commit 2b1d1f1

Please sign in to comment.