Skip to content

Commit

Permalink
Update refresh transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
SeniorZhai committed Mar 10, 2025
1 parent 82d2fe9 commit 8aa281e
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package one.mixin.android.job
import com.birbit.android.jobqueue.Params
import kotlinx.coroutines.runBlocking
import one.mixin.android.Constants.RouteConfig.ROUTE_BOT_USER_ID
import one.mixin.android.db.property.PropertyHelper
import one.mixin.android.db.web3.vo.Web3Address
import one.mixin.android.db.web3.vo.Web3Transaction
import one.mixin.android.ui.wallet.fiatmoney.requestRouteAPI
Expand All @@ -13,6 +14,7 @@ class RefreshWeb3TransactionJob(
companion object {
private const val serialVersionUID = 1L
const val GROUP = "RefreshWeb3TransactionJob"
private const val KEY_LAST_CREATED_AT = "key_last_created_at"

private const val DEFAULT_LIMIT = 30
}
Expand All @@ -28,7 +30,7 @@ class RefreshWeb3TransactionJob(

Timber.d("Syncing transactions for ${addresses.size} addresses")
addresses.forEach { address ->
val offset = web3TransactionDao.getLatestTransaction(address)?.createdAt
val offset = getLastCreatedAt(address)
fetchTransactions(address, offset, DEFAULT_LIMIT)
}

Expand All @@ -54,7 +56,8 @@ class RefreshWeb3TransactionJob(
Timber.d("Fetched ${result?.size} transactions from API for address $addressId")
}
if ((result?.size ?: 0) >= DEFAULT_LIMIT) {
result?.lastOrNull()?.createdAt.let {
result?.lastOrNull()?.createdAt?.let {
saveLastCreatedAt(addressId, it)
fetchTransactions(addressId, it, limit)
}
}
Expand All @@ -71,4 +74,12 @@ class RefreshWeb3TransactionJob(

return result
}

private suspend fun saveLastCreatedAt(addressId: String, timestamp: String) {
PropertyHelper.updateKeyValue(addressId, timestamp)
}

private suspend fun getLastCreatedAt(addressId: String): String? {
return PropertyHelper.findValueByKey(addressId, null)
}
}

0 comments on commit 8aa281e

Please sign in to comment.