This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to fetch missing transactions
- Loading branch information
1 parent
3fc70a6
commit c055670
Showing
5 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,6 @@ object Constants { | |
const val SWIPE_UP_EXPANDED_THRESHOLD = 200 | ||
|
||
const val SUPPORT_EMAIL = "[email protected]" | ||
|
||
const val PAGE_TRANSACTIONS_SIZE = 100 | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/ivy/wallet/domain/action/transaction/FetchAllTrnsFromServerAct.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.ivy.wallet.domain.action.transaction | ||
|
||
import com.ivy.frp.action.FPAction | ||
import com.ivy.frp.monad.Res | ||
import com.ivy.frp.monad.tryOp | ||
import com.ivy.wallet.Constants | ||
import com.ivy.wallet.io.network.RestClient | ||
import com.ivy.wallet.io.persistence.dao.TransactionDao | ||
import javax.inject.Inject | ||
|
||
class FetchAllTrnsFromServerAct @Inject constructor( | ||
restClient: RestClient, | ||
private val transactionDao: TransactionDao | ||
) : FPAction<Unit, Res<Exception, Unit>>() { | ||
companion object { | ||
private const val MAX_LIMIT_IF_SHIT_HAPPENS = 1000 | ||
} | ||
|
||
private val transactionService = restClient.transactionService | ||
|
||
override suspend fun Unit.compose(): suspend () -> Res<Exception, Unit> = tryOp( | ||
operation = ::fetch | ||
) | ||
|
||
private suspend fun fetch() { | ||
tailrec suspend fun fetchInternal(page: Int) { | ||
val transactions = transactionService.getPaginated( | ||
page = page, | ||
size = Constants.PAGE_TRANSACTIONS_SIZE | ||
).transactions.map { it.toEntity() } | ||
|
||
transactionDao.save(transactions) | ||
|
||
if (transactions.isNotEmpty() && page < MAX_LIMIT_IF_SHIT_HAPPENS) { | ||
//recurse | ||
fetchInternal(page = page + 1) | ||
} | ||
} | ||
|
||
fetchInternal(page = 0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters