diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/ctxspend/model/GetMerchantResponse.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/ctxspend/model/GetMerchantResponse.kt index 625ef9f9d..43e834982 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/ctxspend/model/GetMerchantResponse.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/ctxspend/model/GetMerchantResponse.kt @@ -16,12 +16,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, + val denominationsType: 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 (denominationsType) { + "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") + } + } +} diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/explore/model/SearchResult.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/explore/model/SearchResult.kt index 8acd3cee6..272bf3576 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/explore/model/SearchResult.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/explore/model/SearchResult.kt @@ -20,6 +20,7 @@ package org.dash.wallet.features.exploredash.data.explore.model import androidx.room.ColumnInfo import androidx.room.Ignore import androidx.room.PrimaryKey +import org.dash.wallet.common.data.ServiceName import org.dash.wallet.features.exploredash.ui.extensions.Const open class SearchResult( @@ -60,6 +61,15 @@ open class SearchResult( addressBuilder.append("${separator}$address4") } + // CTX records do not use address2, address3, address4 + if (source?.lowercase() == ServiceName.CTXSpend.lowercase()) { + addressBuilder.append("${separator}$city") + territory?.let { + addressBuilder.append(", ") + addressBuilder.append(territory) + } + } + return addressBuilder.toString() } diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/ctxspend/CTXSpendViewModel.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/ctxspend/CTXSpendViewModel.kt index 255a07881..e6183989f 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/ctxspend/CTXSpendViewModel.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/ctxspend/CTXSpendViewModel.kt @@ -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) } } } diff --git a/features/exploredash/src/main/res/values/strings-explore-dash.xml b/features/exploredash/src/main/res/values/strings-explore-dash.xml index 25ddbd218..c01cd3f93 100644 --- a/features/exploredash/src/main/res/values/strings-explore-dash.xml +++ b/features/exploredash/src/main/res/values/strings-explore-dash.xml @@ -230,5 +230,5 @@ Buy a gift card with your DashSpend account Create a DashSpend account or log in to the existing one pay.ctx.com - https://ionia.docsend.com/view/ixu6g9x5eiz2jgnu + https://ctx.com/user-agreement/ \ No newline at end of file