Add fiatAmount and fiatSymbol members to the TransferDetail object and modify the query to fetch TransferDetails from the database to obtain those two objects from the EquivalentValues table if they have been already obtained

This commit is contained in:
Severiano Jaramillo 2019-02-06 12:42:18 -06:00
parent 577e3ae01f
commit 0b287ca714
2 changed files with 5 additions and 5 deletions

View file

@ -10,9 +10,9 @@ data class TransferDetail(
val assetAmount: Long,
val assetPrecision: Int,
val assetSymbol: String,
val assetIssuer: String
// val fiatAmount: Long,
// val fiatCurrency: String
val assetIssuer: String,
val fiatAmount: Long?,
val fiatSymbol: String?
) {
fun getUIAssetSymbol(): String {
if (assetIssuer == "1.2.0")

View file

@ -7,9 +7,9 @@ import androidx.room.Query
@Dao
interface TransferDetailDao {
@Query("SELECT transfers.id, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.source) AS `from`, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.destination) AS `to`, (CASE WHEN destination=:userId THEN 1 ELSE 0 END) AS `direction`, transfers.memo AS `memo`, transfers.timestamp AS `date`, transfers.transfer_amount AS `assetAmount`, assets.precision AS `assetPrecision`, assets.symbol AS `assetSymbol`, assets.issuer as `assetIssuer` FROM transfers INNER JOIN assets WHERE transfers.id=:transferId AND transfers.transfer_asset_id = assets.id")
@Query("SELECT transfers.id, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.source) AS `from`, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.destination) AS `to`, (CASE WHEN destination=:userId THEN 1 ELSE 0 END) AS `direction`, transfers.memo AS `memo`, transfers.timestamp AS `date`, transfers.transfer_amount AS `assetAmount`, assets.precision AS `assetPrecision`, assets.symbol AS `assetSymbol`, assets.issuer as `assetIssuer`, (SELECT value FROM equivalent_values WHERE equivalent_values.transfer_id=transfers.id) AS `fiatAmount`, (SELECT symbol FROM equivalent_values WHERE equivalent_values.transfer_id=transfers.id) AS `fiatSymbol` FROM transfers INNER JOIN assets WHERE transfers.id=:transferId AND transfers.transfer_asset_id = assets.id")
fun get(userId: String, transferId: String): LiveData<TransferDetail>
@Query("SELECT transfers.id, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.source) AS `from`, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.destination) AS `to`, (CASE WHEN destination=:userId THEN 1 ELSE 0 END) AS `direction`, transfers.memo AS `memo`, transfers.timestamp AS `date`, transfers.transfer_amount AS `assetAmount`, assets.precision AS `assetPrecision`, assets.symbol AS `assetSymbol`, assets.issuer as `assetIssuer` FROM transfers INNER JOIN assets WHERE transfers.transfer_asset_id = assets.id")
@Query("SELECT transfers.id, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.source) AS `from`, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.destination) AS `to`, (CASE WHEN destination=:userId THEN 1 ELSE 0 END) AS `direction`, transfers.memo AS `memo`, transfers.timestamp AS `date`, transfers.transfer_amount AS `assetAmount`, assets.precision AS `assetPrecision`, assets.symbol AS `assetSymbol`, assets.issuer as `assetIssuer`, (SELECT value FROM equivalent_values WHERE equivalent_values.transfer_id=transfers.id) AS `fiatAmount`, (SELECT symbol FROM equivalent_values WHERE equivalent_values.transfer_id=transfers.id) AS `fiatSymbol` FROM transfers INNER JOIN assets WHERE transfers.transfer_asset_id = assets.id")
fun getAll(userId: String): LiveData<List<TransferDetail>>
}