Skip to content

feat(dashspend): update to new CTX API endpoints #1294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class ExploreDatabaseMigrations {
database.execSQL(
"ALTER TABLE merchant ADD COLUMN redeemType TEXT DEFAULT 'barcode'"
)
database.execSQL(
"ALTER TABLE merchant ADD COLUMN savingsPercentage INTEGER DEFAULT 0"
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ data class GetMerchantResponse(
val savingsPercentage: Int = 0,
val redeemType: String = ""
) {
val savings: Double
get() = savingsPercentage.toDouble() / 100

val minimumCardPurchase: Double
get() {
require(denominations.isNotEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ data class Merchant(
var redeemType: String? = "",
@Ignore var minCardPurchase: Double? = null,
@Ignore var maxCardPurchase: Double? = null,
@Ignore var savingsPercentage: Double? = null,
var savingsPercentage: Int? = 0,
@Ignore var physicalAmount: Int = 0
) : SearchResult()
) : SearchResult() {

// 1% discount is 0.01
val savingsPercentageAsDouble: Double
get() = (savingsPercentage?.toDouble() ?: 0.0) / 10000
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil.size.Scale
import coil.transform.RoundedCornersTransformation
import org.dash.wallet.common.data.ServiceName
import org.dash.wallet.features.exploredash.R
import org.dash.wallet.features.exploredash.data.explore.model.*
import org.dash.wallet.features.exploredash.databinding.AtmRowBinding
import org.dash.wallet.features.exploredash.databinding.MerchantRowBinding
import org.dash.wallet.features.exploredash.ui.extensions.isMetric
import org.dash.wallet.features.exploredash.utils.CTXSpendConstants
import java.util.*

open class ExploreViewHolder(root: View) : RecyclerView.ViewHolder(root) {
Expand Down Expand Up @@ -116,10 +114,6 @@ 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?.source?.lowercase() == ServiceName.CTXSpend) {
merchant.logoLocation = CTXSpendConstants.BASE_URL + "merchants/" + merchant.merchantId + "/logo"
}

binding.logoImg.load(merchant?.logoLocation) {
crossfade(200)
scale(Scale.FILL)
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.savingsPercentage ?: 0.00) / 100
val d = giftCardMerchant.savingsPercentageAsDouble
return Coin.valueOf((it.value / (1.0 - d)).toLong()).minus(Transaction.DEFAULT_TX_FEE.multiply(20))
}

Expand Down Expand Up @@ -152,7 +152,7 @@ class CTXSpendViewModel @Inject constructor(
if (response is ResponseResource.Success) {
try {
response.value?.let {
merchant.savingsPercentage = it.savings
merchant.savingsPercentage = it.savingsPercentage
merchant.minCardPurchase = it.minimumCardPurchase
merchant.maxCardPurchase = it.maximumCardPurchase
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.dash.wallet.features.exploredash.data.explore.model.Merchant
import org.dash.wallet.features.exploredash.databinding.FragmentPurchaseCtxspendGiftCardBinding
import org.dash.wallet.features.exploredash.ui.ctxspend.dialogs.PurchaseGiftCardConfirmDialog
import org.dash.wallet.features.exploredash.ui.explore.ExploreViewModel
import org.dash.wallet.features.exploredash.utils.CTXSpendConstants.DEFAULT_DISCOUNT
import org.dash.wallet.features.exploredash.utils.CTXSpendConstants.DEFAULT_DISCOUNT_AS_DOUBLE
import org.dash.wallet.features.exploredash.utils.exploreViewModels

fun min(a: Coin, b: Coin?): Coin {
Expand Down Expand Up @@ -159,9 +159,9 @@ class PurchaseGiftCardFragment : Fragment(R.layout.fragment_purchase_ctxspend_gi

private fun setDiscountHint() {
val merchant = viewModel.giftCardMerchant
val savingsPercentage = merchant.savingsPercentage ?: DEFAULT_DISCOUNT
val savingsPercentage = merchant.savingsPercentageAsDouble

if (savingsPercentage != DEFAULT_DISCOUNT) {
if (savingsPercentage != DEFAULT_DISCOUNT_AS_DOUBLE) {
val purchaseAmount = enterAmountViewModel.amount.value
if (purchaseAmount != null && purchaseAmount != Coin.ZERO) {
val rate = enterAmountViewModel.selectedExchangeRate.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import org.dash.wallet.features.exploredash.R
import org.dash.wallet.features.exploredash.databinding.DialogConfirmPurchaseGiftCardBinding
import org.dash.wallet.features.exploredash.repository.CTXSpendException
import org.dash.wallet.features.exploredash.ui.ctxspend.CTXSpendViewModel
import org.dash.wallet.features.exploredash.utils.CTXSpendConstants.DEFAULT_DISCOUNT
import org.dash.wallet.features.exploredash.utils.exploreViewModels
import org.slf4j.LoggerFactory
import javax.inject.Inject
Expand All @@ -68,7 +67,7 @@ class PurchaseGiftCardConfirmDialog : OffsetDialogFragment(R.layout.dialog_confi

val merchant = viewModel.giftCardMerchant
val paymentValue = viewModel.giftCardPaymentValue
val savingsPercentage = merchant.savingsPercentage ?: DEFAULT_DISCOUNT
val savingsPercentage = merchant.savingsPercentageAsDouble
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 @@ -43,7 +43,6 @@ import org.dash.wallet.features.exploredash.R
import org.dash.wallet.features.exploredash.data.explore.model.*
import org.dash.wallet.features.exploredash.databinding.ItemDetailsViewBinding
import org.dash.wallet.features.exploredash.ui.extensions.isMetric
import org.dash.wallet.features.exploredash.utils.CTXSpendConstants
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.*
Expand Down Expand Up @@ -197,9 +196,6 @@ class ItemDetails(context: Context, attrs: AttributeSet) : LinearLayout(context,
locationHint.isVisible = false
backButton.isVisible = !isOnline && !isGrouped

if (merchant.source?.lowercase() == ServiceName.CTXSpend) {
merchant.logoLocation = CTXSpendConstants.BASE_URL + "merchants/" + merchant.merchantId + "/logo"
}
loadImage(merchant.logoLocation, itemImage)
itemType.text = getMerchantType(merchant.type)
itemAddress.isVisible = !isOnline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.dash.wallet.common.data.Resource
import org.dash.wallet.common.data.ServiceName
import org.dash.wallet.common.data.Status
import org.dash.wallet.common.services.analytics.AnalyticsConstants
import org.dash.wallet.common.ui.decorators.ListDividerDecorator
Expand All @@ -66,7 +65,6 @@ import org.dash.wallet.features.exploredash.ui.ctxspend.CTXSpendViewModel
import org.dash.wallet.features.exploredash.ui.ctxspend.dialogs.CTXSpendLoginInfoDialog
import org.dash.wallet.features.exploredash.ui.ctxspend.dialogs.CTXSpendTermsDialog
import org.dash.wallet.features.exploredash.ui.extensions.*
import org.dash.wallet.features.exploredash.utils.CTXSpendConstants
import org.dash.wallet.features.exploredash.utils.exploreViewModels

@AndroidEntryPoint
Expand Down Expand Up @@ -675,9 +673,6 @@ class SearchFragment : Fragment(R.layout.fragment_search) {
bottomSheet.state = setBottomSheetState(expand)

viewModel.selectedItem.value?.let { item ->
if (item.source?.lowercase() == ServiceName.CTXSpend) {
item.logoLocation = CTXSpendConstants.BASE_URL + "location/" + item.sourceId + "/logo"
}
val header =
MerchantLocationsHeaderAdapter(
item.name ?: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ object CTXSpendConstants {
const val BASE_URL = "https://spend.ctx.com/"
const val CLIENT_ID_PARAM_NAME = "clientId"
@JvmField var CLIENT_ID = ""
const val DEFAULT_DISCOUNT = 0.0
const val DEFAULT_DISCOUNT: Int = 0 // 0%
const val DEFAULT_DISCOUNT_AS_DOUBLE: Double = 0.0 // 0%
}
18 changes: 18 additions & 0 deletions features/exploredash/src/main/res/drawable/ic_ctx_logo_blue.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1999.2dp"
android:height="740dp"
android:viewportWidth="1999.2"
android:viewportHeight="740">
<path
android:pathData="M838.9,740h237.5V191.8h137L1076.5,0H619.7v191.8h219.3V740z"
android:fillColor="#008be2"
android:fillType="evenOdd"/>
<path
android:pathData="M1999.2,740l-274.5,-381.5L1980.9,0h-274.1l-115.5,188.3L1460.2,0h-274.1l258.1,367.9L1177,740h283.2L1585,542.3L1716,740H1999.2z"
android:fillColor="#008be2"
android:fillType="evenOdd"/>
<path
android:pathData="M510.1,0H409.6C331.8,0 262,10.5 199.7,43.1C139,74.1 88.3,121.4 53.1,179.7C17.3,239.8 -1.1,308.7 0,378.7C0,453 17.7,501.1 53.1,559.6c35.2,58.3 85.9,105.6 146.6,136.6C262,728.7 331.8,740 409.6,740l0,0c71.4,0 117.5,-6.7 173.2,-32.8c45.9,-21.6 110.2,-56.6 146.6,-104.2L619.7,447.6c-63.2,54.1 -135.7,87.5 -197.3,87.5c-51.8,0 -102.6,-7.5 -134.2,-40.8c-31.5,-33.3 -47.3,-59.6 -47.3,-115.7s20.1,-106 56.4,-133.9c43.1,-33.3 52.3,-54.7 212.7,-53"
android:fillColor="#008be2"
android:fillType="evenOdd"/>
</vector>
10 changes: 0 additions & 10 deletions features/exploredash/src/main/res/drawable/ic_ctxspend_logo.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:layout_marginHorizontal="20dp"
android:src="@drawable/ic_dashspend_logo" />
android:src="@drawable/ic_ctx_logo_blue" />

<TextView
android:id="@+id/dialog_title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="@drawable/ic_ctxspend_logo" />
android:src="@drawable/ic_dashspend_logo" />

<TextView
android:id="@+id/dialog_title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,11 @@

<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="18dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:layout_marginBottom="40dp"
android:src="@drawable/ic_dashspend_logo" />
android:src="@drawable/ic_ctx_logo_blue" />

</LinearLayout>
</androidx.core.widget.NestedScrollView>
Expand Down
Loading