Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-24 17:32:48 +04:00
parent e7b7c086bb
commit ef8a13cfaa
14 changed files with 267 additions and 46 deletions

View file

@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "442ac578743a8b624777711cf49c77e2",
"identityHash": "55f2651d215126dd0465b9c711165cba",
"entities": [
{
"tableName": "express_provider",
@ -474,11 +474,88 @@
"address"
]
}
},
{
"tableName": "onramp_country",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`code` TEXT NOT NULL, `name` TEXT NOT NULL, `image` TEXT NOT NULL, `alpha3` TEXT NOT NULL, `continent` TEXT NOT NULL, `onramp_available` INTEGER NOT NULL, `currency_name` TEXT NOT NULL, `currency_code` TEXT NOT NULL, `currency_image` TEXT, `currency_precision` INTEGER NOT NULL, `currency_unit` TEXT NOT NULL, PRIMARY KEY(`code`))",
"fields": [
{
"fieldPath": "code",
"columnName": "code",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "image",
"columnName": "image",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "alpha3",
"columnName": "alpha3",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "continent",
"columnName": "continent",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "onrampAvailable",
"columnName": "onramp_available",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "defaultCurrency.name",
"columnName": "currency_name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "defaultCurrency.code",
"columnName": "currency_code",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "defaultCurrency.image",
"columnName": "currency_image",
"affinity": "TEXT"
},
{
"fieldPath": "defaultCurrency.precision",
"columnName": "currency_precision",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "defaultCurrency.unit",
"columnName": "currency_unit",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"code"
]
}
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '442ac578743a8b624777711cf49c77e2')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '55f2651d215126dd0465b9c711165cba')"
]
}
}

View file

@ -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,
),
)
}

View file

@ -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() {

View file

@ -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`.

View file

@ -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,
)
}