Skip to content

Commit

Permalink
fix(dashspend): update for new API responses
Browse files Browse the repository at this point in the history
  • Loading branch information
HashEngineering committed Jun 21, 2024
1 parent ffc719a commit 22eddf6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,40 @@ package org.dash.wallet.features.exploredash.data.ctxspend.model

import com.google.gson.annotations.SerializedName

/**
* denominationType: "min-max", "min-max-major" or "fixed"
*/
data class GetMerchantResponse(
@SerializedName("id") val id: String,
@SerializedName("minimumCardPurchase") val minimumCardPurchase: Double? = 0.0,
@SerializedName("maximumCardPurchase") val maximumCardPurchase: Double? = 0.0,
@SerializedName("savingsPercentage") val savingsPercentage: Double? = 0.0,
@SerializedName("hasBarcode") val hasBarcode: Boolean? = false
)
val id: String,
val denominations: List<String>,
val denominationType: String,
val savingsPercentage: Int = 0,
val redeemType: String = ""
) {
val savings: Double
get() = savingsPercentage.toDouble() / 100

val minimumCardPurchase: Double
get() {
require(denominations.isNotEmpty())
return denominations[0].toDouble()
}
val maximumCardPurchase: Double
get() {
return when (denominationType) {
"min-max" -> {
require(denominations.size == 2)
denominations[1].toDouble()
}
"min-max-major" -> {
require(denominations.size == 3)
denominations[1].toDouble()
}
"fixed" -> {
require(denominations.isNotEmpty())
denominations.last().toDouble()
}
else -> error("unknown denomination type")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,14 @@ class CTXSpendViewModel @Inject constructor(
val response = getMerchant(merchant.merchantId!!)

if (response is ResponseResource.Success) {
response.value?.let {
merchant.savingsPercentage = it.savingsPercentage
merchant.minCardPurchase = it.minimumCardPurchase
merchant.maxCardPurchase = it.maximumCardPurchase
try {
response.value?.let {
merchant.savingsPercentage = it.savings
merchant.minCardPurchase = it.minimumCardPurchase
merchant.maxCardPurchase = it.maximumCardPurchase
}
} catch (e: Exception) {
log.warn("updated merchant details contains unexpected data:", e)
}
}
}
Expand Down

0 comments on commit 22eddf6

Please sign in to comment.