Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,14 @@ dependencies {
implementation 'androidx.compose.ui:ui:1.7.8'
implementation 'androidx.compose.ui:ui-tooling-preview:1.7.8'
implementation 'androidx.compose.foundation:foundation:1.7.8'
implementation 'androidx.compose.material:material:1.7.8'
implementation 'androidx.compose.material3:material3-android:1.3.2'
implementation 'androidx.compose.runtime:runtime-livedata:1.7.8'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.4'
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.8.4'
implementation 'androidx.compose.ui:ui-tooling:1.7.8'
implementation "androidx.constraintlayout:constraintlayout-compose:1.1.0"
implementation("io.coil-kt.coil3:coil-compose:3.0.4")
implementation("io.coil-kt.coil3:coil-network-okhttp:3.0.4")

/** Google Drive **/
implementation('com.google.api-client:google-api-client:1.23.0') {
Expand Down
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
-keep class org.onflow.flow.models.** { *; }
-keep enum org.onflow.flow.** { *; }

-dontwarn coil3.PlatformContext
-dontwarn java.lang.management.RuntimeMXBean
-dontwarn com.google.devtools.build.android.desugar.runtime.ThrowableExtension
-dontwarn com.google.protobuf.nano.CodedOutputByteBufferNano
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@
android:name=".page.profile.subpage.wallet.WalletListActivity"
android:screenOrientation="portrait"/>

<activity
android:name=".page.account.AccountListActivity"
android:screenOrientation="portrait"/>

<activity
android:name=".page.landing.LandingActivity"
android:screenOrientation="portrait"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.flowfoundation.wallet.firebase.config.initFirebaseConfig
import com.flowfoundation.wallet.firebase.firebaseInitialize
import com.flowfoundation.wallet.instabug.instabugInitialize
import com.flowfoundation.wallet.manager.account.AccountManager
import com.flowfoundation.wallet.manager.account.AccountVisibilityManager
import com.flowfoundation.wallet.manager.account.DeviceInfoManager
import com.flowfoundation.wallet.manager.app.AppLifecycleObserver
import com.flowfoundation.wallet.manager.app.PageLifecycleObserver
Expand Down Expand Up @@ -42,7 +43,7 @@ object LaunchManager {
safeRun { System.loadLibrary("TrustWalletCore") }
ioScope {
safeRun {
AccountManager.init()
AccountManager.init()
logd("LaunchManager", "AccountManager initialized successfully")
}
}
Expand Down Expand Up @@ -78,6 +79,7 @@ object LaunchManager {
safeRun { NftCollectionStateManager.reload() }
safeRun { CurrencyManager.init() }
safeRun { StakingManager.init() }
safeRun { AccountVisibilityManager.init() }
}

private fun setNightMode() {
Expand All @@ -97,4 +99,4 @@ object LaunchManager {
private fun runCompatibleScript() {
restoreMnemonicV0()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package com.flowfoundation.wallet.manager.account

import android.content.Context
import android.content.SharedPreferences
import com.flowfoundation.wallet.firebase.auth.firebaseUid
import com.flowfoundation.wallet.manager.app.AppLifecycleObserver
import com.flowfoundation.wallet.utils.Env
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

/**
* Manages account visibility state
* Storage structure: Map<UserId, List<Address>>
* UserId - User ID, Address - Hidden wallet address
*/
object AccountVisibilityManager {

private const val PREF_NAME = "account_visibility"
private const val KEY_HIDDEN_ACCOUNTS = "hidden_accounts"

private var sharedPreferences: SharedPreferences? = null
private val gson = Gson()

// In-memory cache, format: Map<UserId, Set<Address>>
private var hiddenAccountsCache = mutableMapOf<String, MutableSet<String>>()

fun init() {
if (sharedPreferences == null) {
sharedPreferences = Env.getApp().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
loadHiddenAccounts()
}
}

/**
* Load hidden account data from SharedPreferences
*/
private fun loadHiddenAccounts() {
val json = sharedPreferences?.getString(KEY_HIDDEN_ACCOUNTS, null)
if (!json.isNullOrEmpty()) {
try {
val type = object : TypeToken<Map<String, List<String>>>() {}.type
val loadedData: Map<String, List<String>> = gson.fromJson(json, type)

// Convert to in-memory cache format
hiddenAccountsCache.clear()
loadedData.forEach { (userId, addresses) ->
hiddenAccountsCache[userId] = addresses.toMutableSet()
}
} catch (e: Exception) {
e.printStackTrace()
hiddenAccountsCache.clear()
}
}
}

/**
* Save hidden account data to SharedPreferences
*/
private fun saveHiddenAccounts() {
try {
// Convert to serializable format
val dataToSave = hiddenAccountsCache.mapValues { it.value.toList() }
val json = gson.toJson(dataToSave)
sharedPreferences?.edit()?.putString(KEY_HIDDEN_ACCOUNTS, json)?.apply()
} catch (e: Exception) {
e.printStackTrace()
}
}

/**
* Get hidden account list for current user
*/
fun getHiddenAccounts(userId: String): Set<String> {
return hiddenAccountsCache[userId]?.toSet() ?: emptySet()
}

/**
* Check if the specified address is hidden
*/
fun isAccountHidden(userId: String, address: String): Boolean {
return hiddenAccountsCache[userId]?.contains(address) ?: false
}

fun isCurrentProfileAccountHidden(address: String): Boolean {
val userId = firebaseUid() ?: return false
return isAccountHidden(userId, address)
}

/**
* Hide specified account
*/
fun hideAccount(userId: String, address: String) {
if (hiddenAccountsCache[userId] == null) {
hiddenAccountsCache[userId] = mutableSetOf()
}

if (hiddenAccountsCache[userId]!!.add(address)) {
saveHiddenAccounts()
}
}

/**
* Show specified account (unhide)
*/
fun showAccount(userId: String, address: String) {
val userHiddenAccounts = hiddenAccountsCache[userId]
if (userHiddenAccounts != null && userHiddenAccounts.remove(address)) {
// If the user has no hidden accounts left, remove the user's record
if (userHiddenAccounts.isEmpty()) {
hiddenAccountsCache.remove(userId)
}
saveHiddenAccounts()
}
}

/**
* Toggle account visibility
*/
fun toggleAccountVisibility(userId: String, address: String): Boolean {
val isHidden = isAccountHidden(userId, address)
if (isHidden) {
showAccount(userId, address)
} else {
hideAccount(userId, address)
}
return !isHidden // Return the hidden state after toggle
}

/**
* Filter out hidden accounts
*/
fun <T> filterVisibleAccounts(
userId: String,
accounts: List<T>,
addressExtractor: (T) -> String
): List<T> {
val hiddenAddresses = getHiddenAccounts(userId)
if (hiddenAddresses.isEmpty()) {
return accounts
}

return accounts.filter { account ->
val address = addressExtractor(account)
!hiddenAddresses.contains(address)
}
}

/**
* Clear all hidden accounts for specified user
*/
fun clearUserHiddenAccounts(userId: String) {
if (hiddenAccountsCache.remove(userId) != null) {
saveHiddenAccounts()
}
}

/**
* Clear all hidden account data
*/
fun clearAllHiddenAccounts() {
hiddenAccountsCache.clear()
sharedPreferences?.edit()?.remove(KEY_HIDDEN_ACCOUNTS)?.apply()
}

/**
* Get hidden account statistics for all users
*/
fun getHiddenAccountsStats(): Map<String, Int> {
return hiddenAccountsCache.mapValues { it.value.size }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ object EVMWalletManager {
}
}

fun getEVMAddressByAddress(address: String): String? {
val evmAddress = evmAddressMap[address]
return if (evmAddress.isNullOrBlank() || evmAddress == "0x") {
ErrorReporter.reportWithMixpanel(EVMError.QUERY_EVM_ADDRESS_FAILED, getCurrentCodeLocation())
return null
} else {
val checksumAddress = toChecksumEVMAddress(evmAddress)
// Validate the address format - if it's corrupted, try to refresh it
if (!isValidEVMAddress(checksumAddress)) {
logd(TAG, "Detected corrupted EVM address: $checksumAddress, attempting to refresh")
return null
}
checksumAddress
}
}

fun isValidEVMAddress(address: String): Boolean {
// Check if address matches valid EVM address pattern and doesn't have suspicious patterns
if (!address.matches(Regex("^0x[a-fA-F0-9]{40}$"))) {
Expand Down
Loading