diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/dashspend/ctx/model/GetMerchantResponse.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/dashspend/ctx/model/GetMerchantResponse.kt index e00276fdf8..a45a8c23c6 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/dashspend/ctx/model/GetMerchantResponse.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/data/dashspend/ctx/model/GetMerchantResponse.kt @@ -40,11 +40,14 @@ data class GetMerchantResponse( val id: String, val denominations: List, val denominationsType: String, - val savingsPercentage: Int = 0, + val savingsPercentage: Int? = 0, + val userDiscount: Int? = 0, val redeemType: String = "", val enabled: Boolean = true, val productId: String = "" ) { + val discount + get() = userDiscount ?: savingsPercentage ?: 0 val denominationType: DenominationType get() = DenominationType.fromString(denominationsType) diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/di/ExploreDashModule.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/di/ExploreDashModule.kt index 65c2f04aa9..45850b1f73 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/di/ExploreDashModule.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/di/ExploreDashModule.kt @@ -55,8 +55,9 @@ abstract class ExploreDashModule { @Provides fun provideFirebaseStorage() = Firebase.storage - fun provideRemoteDataSource(config: CTXSpendConfig): RemoteDataSource { - return RemoteDataSource(config) + @Provides + fun provideRemoteDataSource(config: CTXSpendConfig, walletDataProvider: WalletDataProvider): RemoteDataSource { + return RemoteDataSource(config, walletDataProvider) } @Provides diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/network/RemoteDataSource.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/network/RemoteDataSource.kt index 566924f305..eb0e49824b 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/network/RemoteDataSource.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/network/RemoteDataSource.kt @@ -19,6 +19,8 @@ package org.dash.wallet.features.exploredash.network import okhttp3.Authenticator import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor +import org.bitcoinj.core.NetworkParameters +import org.dash.wallet.common.WalletDataProvider import org.dash.wallet.common.data.ServiceName import org.dash.wallet.features.exploredash.network.authenticator.TokenAuthenticator import org.dash.wallet.features.exploredash.network.interceptor.ErrorHandlingInterceptor @@ -33,14 +35,23 @@ import javax.inject.Inject import kotlin.time.Duration.Companion.seconds import kotlin.time.toJavaDuration -class RemoteDataSource @Inject constructor(private val config: CTXSpendConfig) { +class RemoteDataSource @Inject constructor( + private val config: CTXSpendConfig, + private val walletData: WalletDataProvider +) { companion object { private val log = LoggerFactory.getLogger(RemoteDataSource::class.java) } fun buildApi(api: Class): Api { return Retrofit.Builder() - .baseUrl(CTXSpendConstants.BASE_URL) + .baseUrl( + if (walletData.networkParameters.id == NetworkParameters.ID_MAINNET) { + CTXSpendConstants.BASE_URL + } else { + CTXSpendConstants.DEV_BASE_URL + } + ) .client(getOkHttpClient(TokenAuthenticator(buildTokenApi(), config))) .addConverterFactory(GsonConverterFactory.create()) .build() @@ -49,7 +60,13 @@ class RemoteDataSource @Inject constructor(private val config: CTXSpendConfig) { private fun buildTokenApi(): CTXSpendTokenApi { return Retrofit.Builder() - .baseUrl(CTXSpendConstants.BASE_URL) + .baseUrl( + if (walletData.networkParameters.id == NetworkParameters.ID_MAINNET) { + CTXSpendConstants.BASE_URL + } else { + CTXSpendConstants.DEV_BASE_URL + } + ) .client(getOkHttpClient()) .addConverterFactory(GsonConverterFactory.create()) .build() diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/repository/CTXSpendRepository.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/repository/CTXSpendRepository.kt index 729a293215..08dfe7b324 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/repository/CTXSpendRepository.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/repository/CTXSpendRepository.kt @@ -208,7 +208,7 @@ class CTXSpendRepository @Inject constructor( giftCardMap[merchantId] = it UpdatedMerchantDetails( id = response.id, - savingsPercentage = response.savingsPercentage, + savingsPercentage = response.discount, denominationsType = response.denominationsType, denominations = response.denominations.map { denom -> denom.toDouble() }, redeemType = response.redeemType, @@ -244,7 +244,7 @@ class CTXSpendRepository @Inject constructor( } override fun getGiftCardDiscount(merchantId: String, denomination: Double): Double { - return giftCardMap[merchantId]?.savingsPercentage?.let { + return giftCardMap[merchantId]?.discount?.let { it.toDouble() / 10000.0 } ?: 0.0 } diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/repository/DashSpendRepositoryFactory.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/repository/DashSpendRepositoryFactory.kt index 65e670f39e..c85e5a0067 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/repository/DashSpendRepositoryFactory.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/repository/DashSpendRepositoryFactory.kt @@ -44,7 +44,7 @@ class DashSpendRepositoryFactory @Inject constructor( } private fun createCTXSpend(): CTXSpendRepository { - val remoteDataSource = RemoteDataSource(ctxSpendConfig) + val remoteDataSource = RemoteDataSource(ctxSpendConfig, walletDataProvider) val api = remoteDataSource.buildApi(CTXSpendApi::class.java) val tokenApi = remoteDataSource.buildApi(CTXSpendTokenApi::class.java) val tokenAuthenticator = TokenAuthenticator(tokenApi, ctxSpendConfig) diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/dashspend/dialogs/GiftCardDetailsViewModel.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/dashspend/dialogs/GiftCardDetailsViewModel.kt index 01272f76f5..cfc4aaeb0c 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/dashspend/dialogs/GiftCardDetailsViewModel.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/dashspend/dialogs/GiftCardDetailsViewModel.kt @@ -504,8 +504,7 @@ class GiftCardDetailsViewModel @Inject constructor( metadataProvider.updateGiftCardMetadata( giftCard.copy( number = number, - pin = pinCode, - note = null + pin = pinCode ) ) } @@ -519,8 +518,7 @@ class GiftCardDetailsViewModel @Inject constructor( viewModelScope.launch { metadataProvider.updateGiftCardMetadata( giftCard.copy( - merchantUrl = merchantUrl, - note = null + merchantUrl = merchantUrl ) ) } diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/explore/dialogs/ExploreDashInfoDialog.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/explore/dialogs/ExploreDashInfoDialog.kt index 695f7964fb..67cfcfa45b 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/explore/dialogs/ExploreDashInfoDialog.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/explore/dialogs/ExploreDashInfoDialog.kt @@ -30,7 +30,7 @@ import javax.inject.Inject @AndroidEntryPoint class ExploreDashInfoDialog : OffsetDialogFragment(R.layout.explore_dash_main_info) { - + override val forceExpand = true private val binding by viewBinding(ExploreDashMainInfoBinding::bind) @Inject lateinit var analyticsService: AnalyticsService diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/utils/CTXSpendConstants.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/utils/CTXSpendConstants.kt index 0a339940b7..4df371b8da 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/utils/CTXSpendConstants.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/utils/CTXSpendConstants.kt @@ -18,6 +18,7 @@ package org.dash.wallet.features.exploredash.utils object CTXSpendConstants { const val BASE_URL = "https://spend.ctx.com/" + const val DEV_BASE_URL = "https://staging.spend.ctx.com/" const val CLIENT_ID_PARAM_NAME = "X-Client-Id" @JvmField var CLIENT_ID = "dcg_android" const val DEFAULT_DISCOUNT: Int = 0 // 0% diff --git a/features/exploredash/src/main/res/layout/explore_dash_main_info.xml b/features/exploredash/src/main/res/layout/explore_dash_main_info.xml index 6b4baab96e..e714ec93f0 100644 --- a/features/exploredash/src/main/res/layout/explore_dash_main_info.xml +++ b/features/exploredash/src/main/res/layout/explore_dash_main_info.xml @@ -20,7 +20,7 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/root_layout" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="wrap_content">