Skip to content

Commit

Permalink
style: reformat (ktlint)
Browse files Browse the repository at this point in the history
  • Loading branch information
HashEngineering committed Apr 16, 2024
1 parent b21b300 commit 4794bdf
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@

package org.dash.wallet.integrations.maya.api

import org.dash.wallet.common.data.ResponseResource
import org.dash.wallet.common.services.analytics.AnalyticsService
import org.dash.wallet.integrations.maya.model.Account
import org.dash.wallet.integrations.maya.model.AccountDataUIModel
import org.dash.wallet.integrations.maya.model.Balance
import org.dash.wallet.integrations.maya.model.PoolInfo
import org.dash.wallet.integrations.maya.model.SwapTradeUIModel
import org.dash.wallet.integrations.maya.model.TradesRequest
import org.slf4j.LoggerFactory
import retrofit2.Response
import retrofit2.http.GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import org.dash.wallet.common.services.analytics.AnalyticsService
import org.dash.wallet.common.util.toBigDecimal
import org.dash.wallet.integrations.maya.model.Account
import org.dash.wallet.integrations.maya.model.AccountDataUIModel
import org.dash.wallet.integrations.maya.model.Amount
import org.dash.wallet.integrations.maya.model.Balance
import org.dash.wallet.integrations.maya.model.CurrencyInputType
import org.dash.wallet.integrations.maya.model.InboundAddress
import org.dash.wallet.integrations.maya.model.NetworkResponse
import org.dash.wallet.integrations.maya.model.PoolInfo
Expand Down Expand Up @@ -126,7 +124,7 @@ open class MayaWebApi @Inject constructor(
}

listOf()
}
}
}

suspend fun getNetwork(): NetworkResponse? {
Expand Down Expand Up @@ -182,13 +180,17 @@ open class MayaWebApi @Inject constructor(

// Liquidity Fee
val swapAmount = tradesRequest.amount.crypto
val poolDepth = destinationPoolInfo!!.assetDepth.toBigDecimal().setScale(8, RoundingMode.HALF_UP).div(BigDecimal(1_0000_000))
val poolDepth = destinationPoolInfo!!.assetDepth.toBigDecimal().setScale(8, RoundingMode.HALF_UP).div(
BigDecimal(1_0000_000)
)
val slip = swapAmount / (swapAmount + poolDepth)
val fee = slip * swapAmount
val feeAmount = tradesRequest.amount.copy().apply { crypto = fee }

// Outgoing Fee
val outgoingFee = destination!!.outboundFee.toBigDecimal().setScale(8, RoundingMode.HALF_UP).div(BigDecimal(1_0000_0000))// * txSize * outboundFeeMultiplier
val outgoingFee = destination!!.outboundFee.toBigDecimal().setScale(8, RoundingMode.HALF_UP).div(
BigDecimal(1_0000_0000)
) // * txSize * outboundFeeMultiplier

feeAmount.crypto += outgoingFee
feeAmount.dash += incomingFee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ class MayaConversionPreviewFragment : Fragment(R.layout.fragment_maya_conversion
AdaptiveDialog.create(
null,
"New Maya Order",
"This order will send (${it.amount.dash} + ${it.feeAmount.dash.setScale(8, RoundingMode.HALF_UP)}) of ${it.inputCurrency} to ${it.amount.crypto.setScale(8, RoundingMode.HALF_UP)} of ${it.amount.cryptoCode} at ${it.destinationAddress}",
"This order will send (${it.amount.dash} + ${it.feeAmount.dash.setScale(
8,
RoundingMode.HALF_UP
)}) of ${it.inputCurrency} to ${
it.amount.crypto.setScale(8, RoundingMode.HALF_UP)
} of ${it.amount.cryptoCode} at ${it.destinationAddress}",
getString(R.string.button_okay)
).show(requireActivity())
viewModel.commitSwapTrade(orderId)
Expand Down Expand Up @@ -251,7 +256,8 @@ class MayaConversionPreviewFragment : Fragment(R.layout.fragment_maya_conversion
inputAmount,
inputCurrencySymbol,
isCurrencyCodeFirst,
true, false
true,
false
)

val outputAmount = this.amount.crypto.setScale(8, RoundingMode.HALF_UP)
Expand All @@ -262,7 +268,8 @@ class MayaConversionPreviewFragment : Fragment(R.layout.fragment_maya_conversion
outputAmount,
outputCurrency,
isCurrencyCodeFirst,
false, false
false,
false
)

val currencySymbol = GenericUtils.currencySymbol(this.amount.anchoredCurrencyCode)
Expand Down Expand Up @@ -341,9 +348,10 @@ class MayaConversionPreviewFragment : Fragment(R.layout.fragment_maya_conversion
// show Dash Icon if DASH is the primary currency
if (isDash) {
// TODO: adjust for dark mode
val drawable = ContextCompat.getDrawable(context, org.dash.wallet.common.R.drawable.ic_dash_d_black)?.apply {
setBounds(0, 0, (iconSize * scale).toInt(), (iconSize * scale).toInt())
}
val drawable =
ContextCompat.getDrawable(context, org.dash.wallet.common.R.drawable.ic_dash_d_black)?.apply {
setBounds(0, 0, (iconSize * scale).toInt(), (iconSize * scale).toInt())
}
val imageSpan = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
drawable?.let { ImageSpan(it, ImageSpan.ALIGN_CENTER) }
} else {
Expand Down Expand Up @@ -411,35 +419,36 @@ class MayaConversionPreviewFragment : Fragment(R.layout.fragment_maya_conversion
responseMessage,
dashToCoinbase = viewModel.swapTradeUIModel.inputCurrency == Constants.DASH_CURRENCY
).apply {
this.onCoinBaseResultDialogButtonsClickListener = object : MayaResultDialog.CoinBaseResultDialogButtonsClickListener {
override fun onPositiveButtonClick(type: MayaResultDialog.Type) {
when (type) {
MayaResultDialog.Type.CONVERSION_ERROR -> {
viewModel.logEvent(AnalyticsConstants.Coinbase.CONVERT_ERROR_RETRY)
dismiss()
findNavController().popBackStack()
}
MayaResultDialog.Type.SWAP_ERROR -> {
viewModel.logEvent(AnalyticsConstants.Coinbase.CONVERT_ERROR_RETRY)
dismiss()
findNavController().popBackStack()
findNavController().popBackStack()
}
MayaResultDialog.Type.CONVERSION_SUCCESS -> {
viewModel.logEvent(AnalyticsConstants.Coinbase.CONVERT_SUCCESS_CLOSE)
dismiss()
val navController = findNavController()
val home = navController.graph.startDestinationId
navController.popBackStack(home, false)
this.onCoinBaseResultDialogButtonsClickListener =
object : MayaResultDialog.CoinBaseResultDialogButtonsClickListener {
override fun onPositiveButtonClick(type: MayaResultDialog.Type) {
when (type) {
MayaResultDialog.Type.CONVERSION_ERROR -> {
viewModel.logEvent(AnalyticsConstants.Coinbase.CONVERT_ERROR_RETRY)
dismiss()
findNavController().popBackStack()
}
MayaResultDialog.Type.SWAP_ERROR -> {
viewModel.logEvent(AnalyticsConstants.Coinbase.CONVERT_ERROR_RETRY)
dismiss()
findNavController().popBackStack()
findNavController().popBackStack()
}
MayaResultDialog.Type.CONVERSION_SUCCESS -> {
viewModel.logEvent(AnalyticsConstants.Coinbase.CONVERT_SUCCESS_CLOSE)
dismiss()
val navController = findNavController()
val home = navController.graph.startDestinationId
navController.popBackStack(home, false)
}
else -> {}
}
else -> {}
}
}

override fun onNegativeButtonClick(type: MayaResultDialog.Type) {
viewModel.logEvent(AnalyticsConstants.Coinbase.CONVERT_ERROR_CLOSE)
override fun onNegativeButtonClick(type: MayaResultDialog.Type) {
viewModel.logEvent(AnalyticsConstants.Coinbase.CONVERT_ERROR_CLOSE)
}
}
}
}
transactionStateDialog?.showNow(parentFragmentManager, "CoinBaseBuyDashDialog")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,15 @@ package org.dash.wallet.integrations.maya.ui
import androidx.lifecycle.*
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import org.bitcoinj.core.Address
import org.bitcoinj.core.Coin
import org.bitcoinj.core.InsufficientMoneyException
import org.dash.wallet.common.WalletDataProvider
import org.dash.wallet.common.data.ResponseResource
import org.dash.wallet.common.data.ServiceName
import org.dash.wallet.common.data.SingleLiveEvent
import org.dash.wallet.common.services.NetworkStateInt
import org.dash.wallet.common.services.SendPaymentService
import org.dash.wallet.common.services.TransactionMetadataProvider
import org.dash.wallet.common.services.analytics.AnalyticsConstants
import org.dash.wallet.common.services.analytics.AnalyticsService
import org.dash.wallet.integrations.maya.api.MayaWebApi
import org.dash.wallet.integrations.maya.model.Amount
import org.dash.wallet.integrations.maya.model.CoinbaseErrorResponse
import org.dash.wallet.integrations.maya.model.SwapTradeResponse
import org.dash.wallet.integrations.maya.model.SwapTradeUIModel
Expand Down Expand Up @@ -79,8 +74,8 @@ class MayaConversionPreviewViewModel @Inject constructor(
val inputCurrency = swapTradeUIModel.amount.dashCode
val inputAmount = swapTradeUIModel.amount.dash

//TODO: this is the action to do the swap
//_showLoading.value = true
// TODO: this is the action to do the swap
// _showLoading.value = true
// when (val result = coinBaseRepository.commitSwapTrade(tradeId)) {
// is ResponseResource.Success -> {
// _showLoading.value = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import kotlinx.coroutines.launch
import org.bitcoinj.core.Address
import org.bitcoinj.core.Coin
import org.bitcoinj.script.ScriptBuilder
import org.bitcoinj.utils.Fiat
import org.dash.wallet.common.WalletDataProvider
import org.dash.wallet.common.data.PaymentIntent
import org.dash.wallet.common.data.ResponseResource
Expand All @@ -39,7 +38,6 @@ import org.dash.wallet.common.services.NetworkStateInt
import org.dash.wallet.common.services.analytics.AnalyticsConstants
import org.dash.wallet.common.services.analytics.AnalyticsService
import org.dash.wallet.common.util.Constants
import org.dash.wallet.common.util.toFormattedStringNoCode
import org.dash.wallet.integrations.maya.api.MayaWebApi
import org.dash.wallet.integrations.maya.model.AccountDataUIModel
import org.dash.wallet.integrations.maya.model.CoinbaseErrorResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.dash.wallet.integrations.maya.ui

import android.content.Context
import org.dash.wallet.common.util.GenericUtils
import org.dash.wallet.integrations.maya.R
import java.util.Currency

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,18 @@ class ConvertViewViewModel @Inject constructor(
viewModelScope.launch {
analyticsService.logEvent(AnalyticsConstants.Coinbase.CONVERT_CONTINUE, mapOf())
val currencyInputType = getCurrencyInputType(pickedCurrencyOption)
//val amount = getFiatAmount(currencyInputType)
// val amount = getFiatAmount(currencyInputType)
logEnteredAmountCurrency(currencyInputType)
onContinueEvent.value = selectedCryptoCurrencyAccount.value?.coinbaseAccount?.let {
destinationAddress?.let { address ->
SwapRequest(
amount, address, it.currency, it.asset, selectedLocalCurrencyCode
)
}
destinationAddress?.let { address ->
SwapRequest(
amount,
address,
it.currency,
it.asset,
selectedLocalCurrencyCode
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ data class SendTransactionToWalletParams(
val to: String?,
val type: String?,
val description: String? = "Dash Wallet App"
): Parcelable
) : Parcelable

0 comments on commit 4794bdf

Please sign in to comment.