Updated on 2026-08-14
This commit is contained in:
parent
ddcb68caf6
commit
782a2ec0f5
21 changed files with 479 additions and 6 deletions
1
data/txhistory/.gitignore
vendored
Normal file
1
data/txhistory/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
21
data/txhistory/build.gradle.kts
Normal file
21
data/txhistory/build.gradle.kts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
plugins {
|
||||
alias(deps.plugins.android.library)
|
||||
alias(deps.plugins.kotlin.android)
|
||||
alias(deps.plugins.kotlin.kapt)
|
||||
id("configuration")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.tangem.data.txhistory"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.domain.txhistory)
|
||||
|
||||
implementation(deps.kotlin.coroutines)
|
||||
implementation(deps.androidx.paging.runtime)
|
||||
implementation(deps.arrow.core)
|
||||
|
||||
implementation(deps.hilt.core)
|
||||
kapt(deps.hilt.kapt)
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.tangem.data.txhistory.di
|
||||
|
||||
import com.tangem.data.txhistory.repository.MockTxHistoryRepository
|
||||
import com.tangem.domain.txhistory.repository.TxHistoryRepository
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal object TxHistoryDataModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideTxHistoryRepository(): TxHistoryRepository = MockTxHistoryRepository()
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.tangem.data.txhistory.mock
|
||||
|
||||
import com.tangem.domain.txhistory.model.TxHistoryItem
|
||||
import java.math.BigDecimal
|
||||
|
||||
internal object MockTxHistoryItems {
|
||||
|
||||
private val txHistoryItem1 = TxHistoryItem(
|
||||
txHash = "noster",
|
||||
timestamp = 1689930746,
|
||||
direction = TxHistoryItem.TransactionDirection.Incoming("address"),
|
||||
status = TxHistoryItem.TxStatus.Confirmed,
|
||||
type = TxHistoryItem.TransactionType.Transfer,
|
||||
amount = BigDecimal("1000000000.5"),
|
||||
)
|
||||
|
||||
private val txHistoryItem2 = TxHistoryItem(
|
||||
txHash = "noster",
|
||||
timestamp = 1689844346,
|
||||
direction = TxHistoryItem.TransactionDirection.Incoming("address2"),
|
||||
status = TxHistoryItem.TxStatus.Unconfirmed,
|
||||
type = TxHistoryItem.TransactionType.Transfer,
|
||||
amount = BigDecimal("1000000000.5"),
|
||||
)
|
||||
|
||||
private val txHistoryItem3 = TxHistoryItem(
|
||||
txHash = "noster",
|
||||
timestamp = 1689757946,
|
||||
direction = TxHistoryItem.TransactionDirection.Outgoing("address3"),
|
||||
status = TxHistoryItem.TxStatus.Confirmed,
|
||||
type = TxHistoryItem.TransactionType.Transfer,
|
||||
amount = BigDecimal("1000000000.5"),
|
||||
)
|
||||
|
||||
private val txHistoryItem4 = TxHistoryItem(
|
||||
txHash = "noster",
|
||||
timestamp = 1689671546,
|
||||
direction = TxHistoryItem.TransactionDirection.Incoming("address4"),
|
||||
status = TxHistoryItem.TxStatus.Confirmed,
|
||||
type = TxHistoryItem.TransactionType.Transfer,
|
||||
amount = BigDecimal("1000000000.5"),
|
||||
)
|
||||
|
||||
private val txHistoryItem5 = TxHistoryItem(
|
||||
txHash = "noster",
|
||||
timestamp = 1689585146,
|
||||
direction = TxHistoryItem.TransactionDirection.Outgoing("address5"),
|
||||
status = TxHistoryItem.TxStatus.Unconfirmed,
|
||||
type = TxHistoryItem.TransactionType.Transfer,
|
||||
amount = BigDecimal("1000000000.5"),
|
||||
)
|
||||
|
||||
private val txHistoryItem6 = TxHistoryItem(
|
||||
txHash = "noster",
|
||||
timestamp = 1689585146,
|
||||
direction = TxHistoryItem.TransactionDirection.Incoming("address6"),
|
||||
status = TxHistoryItem.TxStatus.Confirmed,
|
||||
type = TxHistoryItem.TransactionType.Transfer,
|
||||
amount = BigDecimal("1000000000.5"),
|
||||
)
|
||||
|
||||
val txHistoryItems = listOf(
|
||||
txHistoryItem1,
|
||||
txHistoryItem2,
|
||||
txHistoryItem3,
|
||||
txHistoryItem4,
|
||||
txHistoryItem5,
|
||||
txHistoryItem6,
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.tangem.data.txhistory.repository
|
||||
|
||||
import androidx.paging.Pager
|
||||
import androidx.paging.PagingConfig
|
||||
import androidx.paging.PagingData
|
||||
import com.tangem.data.txhistory.repository.paging.TxHistoryPagingSource
|
||||
import com.tangem.domain.txhistory.model.TxHistoryItem
|
||||
import com.tangem.domain.txhistory.repository.TxHistoryRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
internal class MockTxHistoryRepository : TxHistoryRepository {
|
||||
|
||||
override suspend fun getTxHistoryItemsCount(networkId: String, derivationPath: String): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getTxHistoryItems(networkId: String, pageSize: Int): Flow<PagingData<TxHistoryItem>> {
|
||||
return Pager(
|
||||
config = PagingConfig(
|
||||
pageSize = pageSize,
|
||||
),
|
||||
pagingSourceFactory = { TxHistoryPagingSource() },
|
||||
).flow
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.tangem.data.txhistory.repository.paging
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import com.tangem.data.txhistory.mock.MockTxHistoryItems
|
||||
import com.tangem.domain.txhistory.model.TxHistoryItem
|
||||
|
||||
private const val INITIAL_PAGE = 1
|
||||
|
||||
internal class TxHistoryPagingSource : PagingSource<Int, TxHistoryItem>() {
|
||||
|
||||
override fun getRefreshKey(state: PagingState<Int, TxHistoryItem>): Int? {
|
||||
return state.anchorPosition?.let { anchorPosition ->
|
||||
state.closestPageToPosition(anchorPosition)?.prevKey?.plus(other = 1)
|
||||
?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(other = 1)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, TxHistoryItem> {
|
||||
val currentPage = params.key ?: INITIAL_PAGE
|
||||
return try {
|
||||
// TODO: [REDACTED_JIRA]
|
||||
// val result = txHistoryManager.getTxHistoryItems(
|
||||
// networkId = networkId,
|
||||
// derivationPath = derivationPath,
|
||||
// page = currentPage,
|
||||
// pageSize = params.loadSize,
|
||||
// )
|
||||
val result = MockTxHistoryItems.txHistoryItems
|
||||
|
||||
LoadResult.Page(
|
||||
data = result,
|
||||
prevKey = if (currentPage > INITIAL_PAGE) currentPage.minus(1) else null,
|
||||
// TODO: handle end of reached [REDACTED_JIRA]
|
||||
nextKey = null,
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
LoadResult.Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue