From 26cd0c7ca0c3400c836aeb45d0d92c95e6060059 Mon Sep 17 00:00:00 2001 From: Meng Date: Wed, 30 Apr 2025 22:06:06 +0800 Subject: [PATCH] fix: child account class cast exception --- .../manager/childaccount/ChildAccountList.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/flowfoundation/wallet/manager/childaccount/ChildAccountList.kt b/app/src/main/java/com/flowfoundation/wallet/manager/childaccount/ChildAccountList.kt index cbb9c63e4..d1c20fa0c 100644 --- a/app/src/main/java/com/flowfoundation/wallet/manager/childaccount/ChildAccountList.kt +++ b/app/src/main/java/com/flowfoundation/wallet/manager/childaccount/ChildAccountList.kt @@ -8,6 +8,7 @@ import com.flowfoundation.wallet.manager.flowjvm.CadenceScript import com.flowfoundation.wallet.manager.flowjvm.executeCadence import com.flowfoundation.wallet.utils.ioScope import com.flowfoundation.wallet.utils.logd +import com.google.gson.reflect.TypeToken import kotlinx.parcelize.Parcelize import org.onflow.flow.infrastructure.Cadence import java.lang.ref.WeakReference @@ -21,7 +22,7 @@ class ChildAccountList( private val accountList = mutableListOf() init { - ioScope { accountList.addAll(cache().read().orEmpty()) } + ioScope { accountList.addAll(cache().read()?.accountList.orEmpty()) } refresh() } @@ -34,7 +35,7 @@ class ChildAccountList( } else { localAccount.pinTime = System.currentTimeMillis() } - cache().cache(ArrayList(accountList)) + cache().cache(ChildAccountCache(accountList.toList())) } fun refresh() { @@ -44,7 +45,7 @@ class ChildAccountList( accounts.forEach { account -> account.pinTime = (oldAccounts.firstOrNull { it.address == account.address }?.pinTime ?: 0) } accountList.clear() accountList.addAll(accounts) - cache().cache(ArrayList(accountList)) + cache().cache(ChildAccountCache(accountList.toList())) dispatchAccountUpdateListener(address, accountList.toList()) logd(TAG, "refresh: $address, ${accountList.size}") @@ -61,11 +62,10 @@ class ChildAccountList( return result?.encode()?.parseAccountMetas() } - private fun cache(): CacheManager> { - @Suppress("UNCHECKED_CAST") + private fun cache(): CacheManager { return CacheManager( "${address}.child_account_list".cacheFile(), - ArrayList::class.java as Class>, + ChildAccountCache::class.java, ) } @@ -101,3 +101,8 @@ data class ChildAccount( @SerializedName("description") val description: String? = null, ) : Parcelable + +data class ChildAccountCache( + @SerializedName("accountList") + val accountList: List = emptyList(), +)