Skip to content

Commit

Permalink
feat: prepare dashspend for production (#1290)
Browse files Browse the repository at this point in the history
* fix(dashspend): update for new API responses

* fix(dashspend): fix getting discount info and displaying addresses

* fix(dashspend): update ctx terms

* style(dashspend): ktlint
  • Loading branch information
HashEngineering authored Jul 1, 2024
1 parent ffc719a commit c13b430
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
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")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
}

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,5 @@
<string name="buy_a_gift_card_with_your_ctx_spend_account">Buy a gift card with your DashSpend account</string>
<string name="create_an_account_at_ctx_spend_or_log_in_to_the_existing_one">Create a DashSpend account or log in to the existing one</string>
<string name="ctx_spend_url" translatable="false">pay.ctx.com</string>
<string name="ctx_terms_url" translatable="false">https://ionia.docsend.com/view/ixu6g9x5eiz2jgnu</string>
<string name="ctx_terms_url" translatable="false">https://ctx.com/user-agreement/</string>
</resources>

0 comments on commit c13b430

Please sign in to comment.