Updated on 2026-08-14
This commit is contained in:
parent
e7b7c086bb
commit
ef8a13cfaa
14 changed files with 267 additions and 46 deletions
|
|
@ -0,0 +1,23 @@
|
|||
package com.tangem.datasource.local.converter
|
||||
|
||||
import com.tangem.datasource.api.onramp.models.response.model.OnrampCountryDTO
|
||||
import com.tangem.datasource.local.txhistory.db.entity.express.OnrampCountryEntity
|
||||
|
||||
/** Maps an [OnrampCountryDTO] API response into its persisted [OnrampCountryEntity]. */
|
||||
fun OnrampCountryDTO.toEntity(): OnrampCountryEntity {
|
||||
return OnrampCountryEntity(
|
||||
code = code,
|
||||
name = name,
|
||||
image = image,
|
||||
alpha3 = alpha3,
|
||||
continent = continent,
|
||||
isOnrampAvailable = onrampAvailable,
|
||||
defaultCurrency = OnrampCountryEntity.CurrencyEmbedded(
|
||||
name = defaultCurrency.name,
|
||||
code = defaultCurrency.code,
|
||||
image = defaultCurrency.image,
|
||||
precision = defaultCurrency.precision,
|
||||
unit = defaultCurrency.unit ?: defaultCurrency.code,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ import com.tangem.datasource.local.txhistory.db.entity.express.ExpressSyncStateE
|
|||
import com.tangem.datasource.local.txhistory.db.entity.express.ExpressExchangeEntity
|
||||
import com.tangem.datasource.local.txhistory.db.entity.express.ExpressOnrampEntity
|
||||
import com.tangem.datasource.local.txhistory.db.entity.express.ExpressProviderEntity
|
||||
import com.tangem.datasource.local.txhistory.db.entity.express.OnrampCountryEntity
|
||||
|
||||
@Database(
|
||||
version = 1,
|
||||
|
|
@ -16,6 +17,7 @@ import com.tangem.datasource.local.txhistory.db.entity.express.ExpressProviderEn
|
|||
ExpressExchangeEntity::class,
|
||||
ExpressOnrampEntity::class,
|
||||
ExpressSyncStateEntity::class,
|
||||
OnrampCountryEntity::class,
|
||||
],
|
||||
)
|
||||
abstract class TxHistoryDatabase : RoomDatabase() {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import androidx.room.Query
|
|||
import com.tangem.datasource.local.txhistory.db.entity.express.ExpressExchangeEntity
|
||||
import com.tangem.datasource.local.txhistory.db.entity.express.ExpressOnrampEntity
|
||||
import com.tangem.datasource.local.txhistory.db.entity.express.ExpressProviderEntity
|
||||
import com.tangem.datasource.local.txhistory.db.entity.express.OnrampCountryEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
|
|
@ -22,12 +23,19 @@ interface ExpressHistoryDao {
|
|||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertOnramps(items: List<ExpressOnrampEntity>)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertCountries(items: List<OnrampCountryEntity>)
|
||||
|
||||
/**
|
||||
* All persisted providers keyed by [ExpressProviderEntity.id]
|
||||
*/
|
||||
@Query("SELECT * FROM express_provider")
|
||||
fun getProvidersById(): Flow<Map<@MapColumn(columnName = "id") String, ExpressProviderEntity>>
|
||||
|
||||
/** All persisted onramp countries keyed by [OnrampCountryEntity.code]. */
|
||||
@Query("SELECT * FROM onramp_country")
|
||||
fun getCountriesByCode(): Flow<Map<@MapColumn(columnName = "code") String, OnrampCountryEntity>>
|
||||
|
||||
/**
|
||||
* Outgoing swaps: the viewed currency is the swap's `from` side, so the row is stored under this
|
||||
* address ([ExpressExchangeEntity.ownerAddress] == fromAddress). Join to on-chain by `payin_hash`.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
package com.tangem.datasource.local.txhistory.db.entity.express
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
/** Persisted onramp country, matched to a transaction by [code] == [ExpressOnrampEntity.countryCode]. */
|
||||
@Entity(tableName = "onramp_country")
|
||||
data class OnrampCountryEntity(
|
||||
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "code")
|
||||
val code: String,
|
||||
|
||||
@ColumnInfo(name = "name")
|
||||
val name: String,
|
||||
|
||||
@ColumnInfo(name = "image")
|
||||
val image: String,
|
||||
|
||||
@ColumnInfo(name = "alpha3")
|
||||
val alpha3: String,
|
||||
|
||||
@ColumnInfo(name = "continent")
|
||||
val continent: String,
|
||||
|
||||
@ColumnInfo(name = "onramp_available")
|
||||
val isOnrampAvailable: Boolean,
|
||||
|
||||
@Embedded(prefix = "currency_")
|
||||
val defaultCurrency: CurrencyEmbedded,
|
||||
) {
|
||||
|
||||
data class CurrencyEmbedded(
|
||||
|
||||
@ColumnInfo(name = "name")
|
||||
val name: String,
|
||||
|
||||
@ColumnInfo(name = "code")
|
||||
val code: String,
|
||||
|
||||
@ColumnInfo(name = "image")
|
||||
val image: String?,
|
||||
|
||||
@ColumnInfo(name = "precision")
|
||||
val precision: Int,
|
||||
|
||||
@ColumnInfo(name = "unit")
|
||||
val unit: String,
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue