Skip to content

Commit

Permalink
refactor(dashspend): rename discount related fields in Merchant
Browse files Browse the repository at this point in the history
  • Loading branch information
HashEngineering committed Aug 15, 2024
1 parent 5ac7fec commit 2d40aa9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ data class Merchant(
var redeemType: String? = "",
@Ignore var minCardPurchase: Double? = null,
@Ignore var maxCardPurchase: Double? = null,
var savingsPercentage: Int? = 0,
var savingsPercentage: Int? = 0, // in basis points 1 = 0.001%
@Ignore var physicalAmount: Int = 0
) : SearchResult() {

// 1% discount is 0.01
val savingsPercentageAsDouble: Double
val savingsAsDouble: Double
get() = (savingsPercentage?.toDouble() ?: 0.0) / 10000

// 1% discount is 1.00
val savingsPercentageAsDouble: Double
get() = savingsAsDouble * 100
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class MerchantViewHolder(val binding: MerchantRowBinding) : ExploreViewHolder(bi
binding.subtitle.text = getDistanceText(resources, merchant)
binding.subtitle.isVisible = merchant?.type != MerchantType.ONLINE && binding.subtitle.text.isNotEmpty()
if (merchant != null) {
if (merchant.savingsPercentageAsDouble != 0.00) {
if (merchant.savingsAsDouble != 0.00) {
binding.discountValue.isVisible = true
binding.discountValue.text = binding.root.context.getString(R.string.explore_discount, merchant.savingsPercentageAsDouble * 100)
binding.discountValue.text = binding.root.context.getString(R.string.explore_discount, merchant.savingsPercentageAsDouble)
} else {
binding.discountValue.isVisible = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CTXSpendViewModel @Inject constructor(

val balanceWithDiscount: Coin?
get() = _balance.value?.let {
val d = giftCardMerchant.savingsPercentageAsDouble
val d = giftCardMerchant.savingsAsDouble
return Coin.valueOf((it.value / (1.0 - d)).toLong()).minus(Transaction.DEFAULT_TX_FEE.multiply(20))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class PurchaseGiftCardFragment : Fragment(R.layout.fragment_purchase_ctxspend_gi

private fun setDiscountHint() {
val merchant = viewModel.giftCardMerchant
val savingsPercentage = merchant.savingsPercentageAsDouble
val savingsPercentage = merchant.savingsAsDouble

if (savingsPercentage != DEFAULT_DISCOUNT_AS_DOUBLE) {
val purchaseAmount = enterAmountViewModel.amount.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class PurchaseGiftCardConfirmDialog : OffsetDialogFragment(R.layout.dialog_confi

val merchant = viewModel.giftCardMerchant
val paymentValue = viewModel.giftCardPaymentValue
val savingsPercentage = merchant.savingsPercentageAsDouble
val savingsPercentage = merchant.savingsAsDouble
binding.merchantName.text = merchant.name
merchant.logoLocation?.let { logoLocation ->
binding.merchantLogo.load(logoLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ class ItemDetails(context: Context, attrs: AttributeSet) : LinearLayout(context,

bindCommonDetails(merchant, isOnline)

if (merchant.savingsPercentageAsDouble != 0.0) {
if (merchant.savingsAsDouble != 0.0) {
binding.discountValue.isVisible = true
binding.discountValue.text = root.context.getString(R.string.explore_pay_with_dash_save, merchant.savingsPercentageAsDouble * 100)
binding.discountValue.text = root.context.getString(R.string.explore_pay_with_dash_save, merchant.savingsPercentageAsDouble)
} else {
binding.discountValue.isVisible = false
}
Expand Down

0 comments on commit 2d40aa9

Please sign in to comment.