Skip to content

Commit

Permalink
Merge pull request #118 from tonkeeper/feature/ledger_usb
Browse files Browse the repository at this point in the history
Bug fixeds for release
  • Loading branch information
polstianka authored Jan 24, 2025
2 parents a704ac5 + cd9e99c commit 7fe55c5
Show file tree
Hide file tree
Showing 164 changed files with 106,346 additions and 101,572 deletions.
20 changes: 8 additions & 12 deletions apps/wallet/api/src/main/java/com/tonapps/wallet/api/API.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tonapps.wallet.api

import android.content.Context
import android.net.Uri
import android.util.ArrayMap
import android.util.Log
import com.squareup.moshi.JsonAdapter
Expand Down Expand Up @@ -760,18 +761,13 @@ class API(
firebaseToken: String,
): Boolean {
return try {
val url = "${config.tonapiMainnetHost}/v1/internal/pushes/tonconnect"

val json = JSONObject()
json.put("app_url", appUrl)
json.put("account", accountId)
json.put("firebase_token", firebaseToken)
json.put("commercial", false)
json.put("silent", true)
val data = json.toString().replace("\\/", "/")

val builder = requestBuilder(url)
builder.delete(data.toRequestBody("application/json".toMediaType()))
val uriBuilder = Uri.parse("${config.tonapiMainnetHost}/v1/internal/pushes/tonconnect").buildUpon()
uriBuilder.appendQueryParameter("firebase_token", firebaseToken)
uriBuilder.appendQueryParameter("app_url", appUrl)
uriBuilder.appendQueryParameter("account", accountId)

val builder = requestBuilder(uriBuilder.build().toString())
builder.delete()
builder.addHeader("X-TonConnect-Auth", token)
builder.addHeader("Connection", "close")
tonAPIHttpClient.execute(builder.build()).isSuccessful
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ internal class DatabaseSource(
val query = "SELECT $walletFields FROM $WALLET_TABLE_NAME LIMIT 1000;"
val cursor = readableDatabase.rawQuery(query, null)
if (cursor.isNullOrEmpty()) {
cursor.close()
emptyList()
} else {
readAccounts(cursor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ class EventsRepository(
localDataSource.addSpam(accountId, testnet, events)
}

suspend fun removeSpam(
accountId: String,
testnet: Boolean,
eventId: String,
) = withContext(Dispatchers.IO) {
localDataSource.removeSpam(accountId, testnet, eventId)
}

suspend fun getRemoteSpam(
accountId: String,
testnet: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ internal class DatabaseSource(
}
}

fun removeSpam(accountId: String, testnet: Boolean, eventId: String) {
writableDatabase.withTransaction {
writableDatabase.delete(SPAM_TABLE_NAME, "$SPAM_TABLE_ACCOUNT_ID_COLUMN = ? AND $SPAM_TABLE_TESTNET_COLUMN = ? AND $SPAM_TABLE_EVENT_ID_COLUMN = ?", arrayOf(accountId.toRawAddress(), if (testnet) "1" else "0", eventId))
}
}

fun getSpam(accountId: String, testnet: Boolean): List<AccountEvent> {
val query = "SELECT $spamFields FROM $SPAM_TABLE_NAME WHERE $SPAM_TABLE_ACCOUNT_ID_COLUMN = ? AND $SPAM_TABLE_TESTNET_COLUMN = ? ORDER BY $SPAM_TABLE_DATE_COLUMN DESC LIMIT 25"
val cursor = readableDatabase.rawQuery(query, arrayOf(accountId.toRawAddress(), if (testnet) "1" else "0"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ internal class LocalDataSource(
databaseSource.addSpam(accountId, testnet, events)
}

fun removeSpam(accountId: String, testnet: Boolean, eventId: String) {
databaseSource.removeSpam(accountId, testnet, eventId)
}

fun getSpam(accountId: String, testnet: Boolean): List<AccountEvent> {
return databaseSource.getSpam(accountId, testnet)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,18 @@ class PurchaseRepository(
if (category.type == "swap") {
list.add(category.copy(items = category.items))
} else {
val items = category.items.filter { methods.contains(it.id) }
val items = category.items.filter {
methods.contains(it.id)
}
if (items.isNotEmpty()) {
list.add(category.copy(items = items))
// Sort by methods
val sortedItems = items.sortedBy {
methods.indexOf(it.id)
}
val categoryEntity = category.copy(
items = sortedItems
)
list.add(categoryEntity)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class SafeModeClient(
loadBadDomains()?.let {
_badDomainsFlow.value = it
}
} else {
_isReadyFlow.value = true
}
}.flowOn(Dispatchers.IO).launchIn(scope)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.tonapps.tonkeeper.ui.screen.tonconnect.TonConnectSafeModeDialog
import com.tonapps.tonkeeper.ui.screen.tonconnect.TonConnectScreen
import com.tonapps.tonkeeper.worker.DAppPushToggleWorker
import com.tonapps.wallet.api.API
import com.tonapps.wallet.data.account.AccountRepository
import com.tonapps.wallet.data.account.entities.WalletEntity
import com.tonapps.wallet.data.dapps.DAppsRepository
import com.tonapps.wallet.data.dapps.entities.AppConnectEntity
Expand Down Expand Up @@ -66,6 +67,7 @@ import java.util.concurrent.atomic.AtomicBoolean
class TonConnectManager(
private val scope: CoroutineScope,
private val api: API,
private val accountRepository: AccountRepository,
private val dAppsRepository: DAppsRepository,
private val pushManager: PushManager,
private val safeModeClient: SafeModeClient,
Expand Down Expand Up @@ -158,6 +160,10 @@ class TonConnectManager(
} else {
bridge.sendDisconnectResponseSuccess(connection, messageId)
}

accountRepository.getWalletByAccountId(connection.accountId, connection.testnet)?.let {
pushManager.dAppUnsubscribe(it, listOf(connection))
}
}

suspend fun getConnection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abstract class BaseWalletVM(
private val navigation: Navigation?
get() = Navigation.from(context)

fun attachHolder(holder: Holder) {
open fun attachHolder(holder: Holder) {
holderRef = WeakReference(holder)
}

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

import android.os.Bundle
import android.view.View
import com.tonapps.tonkeeper.extensions.toast
import com.tonapps.tonkeeper.koin.walletViewModel
import com.tonapps.tonkeeper.ui.base.BaseListWalletScreen
import com.tonapps.tonkeeper.ui.base.ScreenContext
Expand Down Expand Up @@ -64,6 +65,7 @@ class CollectiblesManageScreen(wallet: WalletEntity): BaseListWalletScreen<Scree
private fun showSpamDialog(item: Item.Collection) {
spamDialog.show(item) {
viewModel.notSpam(item)
navigation?.toast(Localization.tx_marked_as_not_spam)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
Expand Down Expand Up @@ -78,13 +79,21 @@ class SpamEventsViewModel(

init {
viewModelScope.launch(Dispatchers.IO) {
_eventsFlow.value = getLocalSpam()
init()
}

if (20 >= _eventsList.size) {
mergeEvents(getRemoteSpam())
} else {
_isLoadingFlow.value = false
}
settingsRepository.walletPrefsChangedFlow.drop(1).collectFlow {
init()
}
}

private suspend fun init() {
_eventsFlow.value = getLocalSpam()

if (20 >= _eventsList.size) {
mergeEvents(getRemoteSpam())
} else {
_isLoadingFlow.value = false
}
}

Expand All @@ -105,7 +114,7 @@ class SpamEventsViewModel(
}
}

private suspend fun mergeEvents(events: List<AccountEvent>) {
private fun mergeEvents(events: List<AccountEvent>) {
_eventsFlow.value = (_eventsList + events).distinctBy {
it.eventId
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tonapps.tonkeeper.ui.screen.purchase.list.holder

import android.util.Log
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatTextView
import com.tonapps.tonkeeper.ui.screen.purchase.list.Item
Expand All @@ -21,7 +22,7 @@ class MethodHolder(
override fun onBind(item: Item.Method) {
itemView.setOnClickListener { onClick(item.entity, item.categoryType) }
itemView.background = item.position.drawable(context)
iconView.setImageURI(item.iconUri)
iconView.setImageURI(item.iconUri, this)
titleView.text = item.title
descriptionView.text = item.description
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.webkit.WebView
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
Expand Down Expand Up @@ -155,20 +156,26 @@ class RootViewModel(
}
}

init {
pushManager.clearNotifications()
override fun attachHolder(holder: Holder) {
super.attachHolder(holder)

tonConnectManager.transactionRequestFlow.map { (connection, message) ->
val tx = RootSignTransaction(connection, message, savedState.returnUri)
savedState.returnUri = null
tx
}.filter { !ignoreTonConnectTransaction.contains(it.hash) }.collectFlow {
}.filter {
!ignoreTonConnectTransaction.contains(it.hash)
}.collectFlow {
_eventFlow.tryEmit(RootEvent.CloseCurrentTonConnect)
viewModelScope.launch {
ignoreTonConnectTransaction.add(it.hash)
signTransaction(it)
}
}
}

init {
pushManager.clearNotifications()

settingsRepository.languageFlow.collectFlow {
context.setLocales(settingsRepository.localeList)
Expand Down Expand Up @@ -479,6 +486,7 @@ class RootViewModel(

fun processTonConnectDeepLink(deeplink: DeepLink, fromPackageName: String?) {
val route = deeplink.route as DeepLinkRoute.TonConnect

savedState.returnUri = tonConnectManager.processDeeplink(
context = context,
uri = route.uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ class TransactionScreen: BaseFragment(R.layout.dialog_transaction), BaseFragment
}

private fun reportSpam(spam: Boolean, actionArgs: HistoryItem.Event) {
navigation?.toastLoading(true)
if (spam) {
navigation?.toastLoading(true)
}
viewModel.reportSpam(
wallet = actionArgs.wallet,
txId = actionArgs.txId,
Expand All @@ -286,10 +288,10 @@ class TransactionScreen: BaseFragment(R.layout.dialog_transaction), BaseFragment
localIsScam = spam
spamView.visibility = if (spam) View.VISIBLE else View.GONE
initArgs(actionArgs)
navigation?.toastLoading(false)
if (spam) {
navigation?.toast(Localization.tx_marked_as_spam)
navigation?.toastLoading(false)
}
navigation?.toast(if (spam) Localization.tx_marked_as_spam else Localization.tx_marked_as_not_spam)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ class TransactionViewModel(
viewModelScope.launch(Dispatchers.IO) {
val state = if (spam) SpamTransactionState.SPAM else SpamTransactionState.NOT_SPAM
settingsRepository.setSpamStateTransaction(wallet.id, txId, state)
try {
if (spam) {
if (spam) {
try {
api.reportTX(
txId = txId,
comment = comment,
recipient = wallet.accountId
)
eventsRepository.markAsSpam(wallet.accountId, wallet.testnet, txId)
}
} catch (ignored: Throwable) { }
} catch (ignored: Throwable) {}
} else {
eventsRepository.removeSpam(wallet.accountId, wallet.testnet, txId)
}
withContext(Dispatchers.Main) {
callback()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tonapps.tonkeeper.ui.screen.wallet.main.list.holder

import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
Expand All @@ -19,18 +20,31 @@ class SetupLinkHolder(parent: ViewGroup): Holder<Item.SetupLink>(parent, R.layou

private val iconView = findViewById<AppCompatImageView>(R.id.icon)
private val textView = findViewById<AppCompatTextView>(R.id.text)
private val buttonView = findViewById<View>(R.id.button)
private val chevronView = findViewById<View>(R.id.chevron)

override fun onBind(item: Item.SetupLink) {
itemView.background = item.position.drawable(context)
iconView.setImageResource(item.iconRes)
textView.setText(item.textRes)
itemView.setOnClickListener {
navigation?.openURL(item.link)
if (item.settingsType == Item.SetupLink.TYPE_TELEGRAM_CHANNEL) {
settingsRepository?.setTelegramChannel(item.walletId)
}
}
itemView.setOnClickListener { click(item) }
setIconColor(if (item.blue) context.accentBlueColor else context.accentOrangeColor)
if (item.settingsType == Item.SetupLink.TYPE_TELEGRAM_CHANNEL) {
buttonView.visibility = View.VISIBLE
buttonView.setOnClickListener { click(item) }
chevronView.visibility = View.GONE
} else {
buttonView.visibility = View.GONE
buttonView.setOnClickListener(null)
chevronView.visibility = View.VISIBLE
}
}

private fun click(item: Item.SetupLink) {
navigation?.openURL(item.link)
if (item.settingsType == Item.SetupLink.TYPE_TELEGRAM_CHANNEL) {
settingsRepository?.setTelegramChannel(item.walletId)
}
}

private fun setIconColor(color: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
<uikit.widget.PhraseWords
android:id="@+id/words"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"/>

</FrameLayout>


<Button
style="@style/Widget.App.Button.Secondary"
android:id="@+id/copy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@
android:textAppearance="@style/TextAppearance.Body2"
android:textColor="?attr/textPrimaryColor"/>

<Button
style="@style/Widget.App.Button.Small.Tertiary"
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_gravity="center"
android:textAppearance="@style/TextAppearance.Label2"
android:textColor="?attr/textPrimaryColor"
android:padding="0dp"
android:text="@string/open"/>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/chevron"
android:layout_width="16dp"
android:layout_height="24dp"
android:layout_gravity="center"
Expand Down
Loading

0 comments on commit 7fe55c5

Please sign in to comment.