Skip to content
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

feat: show only supported currencies #1288

Merged
merged 1 commit into from
Jun 13, 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 @@ -16,6 +16,19 @@

package org.dash.wallet.integrations.maya.payments

import androidx.annotation.StringRes
import org.dash.wallet.common.payments.parsers.AddressParser
import org.dash.wallet.common.payments.parsers.Bech32AddressParser
import org.dash.wallet.common.payments.parsers.BitcoinAddressParser
import org.dash.wallet.common.payments.parsers.BitcoinMainNetParams
import org.dash.wallet.common.payments.parsers.PaymentIntentParser
import org.dash.wallet.common.payments.parsers.PaymentParsers
import org.dash.wallet.integrations.maya.R
import org.dash.wallet.integrations.maya.payments.parsers.Bech32PaymentIntentParser
import org.dash.wallet.integrations.maya.payments.parsers.BitcoinPaymentIntentParser
import org.dash.wallet.integrations.maya.payments.parsers.EthereumPaymentIntentParser
import org.dash.wallet.integrations.maya.payments.parsers.RuneAddressParser
import org.dash.wallet.integrations.maya.payments.parsers.RunePaymentIntentProcessor
import java.math.BigDecimal
import java.math.RoundingMode

Expand All @@ -24,6 +37,12 @@ interface MayaCryptoCurrency {
val name: String
val asset: String
val exampleAddress: String
val paymentIntentParser: PaymentIntentParser
val addressParser: AddressParser
@get:StringRes
val codeId: Int
@get:StringRes
val nameId: Int
fun getPoolDepth(depthInSmallUnits: BigDecimal): BigDecimal
fun getFee(feeInSmallUnits: BigDecimal): BigDecimal
}
Expand All @@ -33,6 +52,11 @@ open class MayaBitcoinCryptoCurrency : MayaCryptoCurrency {
override val name: String = "Bitcoin"
override val asset: String = "BTC.BTC"
override val exampleAddress: String = "bc1qxhgnnp745zryn2ud8hm6k3mygkkpkm35020js0"
override val paymentIntentParser: PaymentIntentParser = BitcoinPaymentIntentParser()
override val addressParser: AddressParser = BitcoinAddressParser(BitcoinMainNetParams())
override val codeId: Int = R.string.cryptocurrency_bitcoin_code
override val nameId: Int = R.string.cryptocurrency_bitcoin_network

companion object {
const val SATOSHIS_PER_COIN = 1_0000_0000
}
Expand All @@ -56,6 +80,10 @@ open class MayaEthereumCryptoCurrency : MayaCryptoCurrency {
override val name: String = "Ethereum"
override val asset: String = "ETH.ETH"
override val exampleAddress: String = "0x51a1449b3B6D635EddeC781cD47a99221712De97"
override val paymentIntentParser: PaymentIntentParser = EthereumPaymentIntentParser("ethereum", "ETH.ETH")
override val addressParser: AddressParser = AddressParser.getEthereumAddressParser()
override val codeId: Int = R.string.cryptocurrency_ethereum_code
override val nameId: Int = R.string.cryptocurrency_ethereum_network
companion object {
const val GWEI_PER_COIN = 1_000_000_000
}
Expand All @@ -73,6 +101,16 @@ open class MayaKujiraCryptoCurrency : MayaBitcoinCryptoCurrency() {
override val name: String = "Kujira"
override val asset: String = "KUJI.KUJI"
override val exampleAddress: String = "kujira1r8egcurpwxftegr07gjv9gwffw4fk00960dj4f"
override val paymentIntentParser: PaymentIntentParser = Bech32PaymentIntentParser(
"kuji",
"kujira",
"kujira",
38,
"KIJI.KUJI"
)
override val addressParser: AddressParser = Bech32AddressParser("kujira", 38, null)
override val codeId: Int = R.string.cryptocurrency_kuji_code
override val nameId: Int = R.string.cryptocurrency_kuji_network
}

class MayaKujiraTokenCryptoCurrency(
Expand All @@ -84,14 +122,21 @@ class MayaKujiraTokenCryptoCurrency(
class MayaEthereumTokenCryptoCurrency(
override val code: String,
override val name: String,
override val asset: String
override val asset: String,
override val paymentIntentParser: PaymentIntentParser,
override val codeId: Int,
override val nameId: Int
) : MayaEthereumCryptoCurrency()

open class MayaRuneCryptoCurrency : MayaBitcoinCryptoCurrency() {
override val code: String = "RUNE"
override val name: String = "Rune"
override val asset: String = "THOR.RUNE"
override val exampleAddress: String = "thor166n4w5039meulfa3p6ydg60ve6ueac7tlt0jws"
override val paymentIntentParser: PaymentIntentParser = RunePaymentIntentProcessor()
override val addressParser: AddressParser = RuneAddressParser()
override val codeId: Int = R.string.cryptocurrency_rune_code
override val nameId: Int = R.string.cryptocurrency_rune_network
}

object MayaCurrencyList {
Expand All @@ -100,18 +145,141 @@ object MayaCurrencyList {
val currencyList = listOf(
MayaBitcoinCryptoCurrency(),
MayaEthereumCryptoCurrency(),
MayaEthereumTokenCryptoCurrency("USDC", "USD Coin", "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48"),
MayaEthereumTokenCryptoCurrency("USDT", "Tether", "ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7"),
MayaEthereumTokenCryptoCurrency(
"PEPE",
"PEPE",
"ETH.PEPE-0X6982508145454CE325DDBE47A25D4EC3D2311933",
EthereumPaymentIntentParser("pepe", "ETH.PEPE-11933"),
R.string.cryptocurrency_pepe_code,
R.string.cryptocurrency_pepe_ethereum_network
),
MayaEthereumTokenCryptoCurrency(
"USDC",
"USD Coin",
"ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
EthereumPaymentIntentParser("usdc", "ETH.USDC-6EB48"),
R.string.cryptocurrency_usdcoin_code,
R.string.cryptocurrency_usdcoin_network
),
MayaEthereumTokenCryptoCurrency(
"USDT",
"Tether",
"ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7",
EthereumPaymentIntentParser("usdt", "ETH.USDT-31EC7"),
R.string.cryptocurrency_tether_code,
R.string.cryptocurrency_tether_network
),
MayaEthereumTokenCryptoCurrency(
"WSTETH",
"Wrapped Stable ETH",
"ETH.WSTETH-0X7F39C581F595B53C5CB19BD0B3F8DA6C935E2CA0"
"ETH.WSTETH-0X7F39C581F595B53C5CB19BD0B3F8DA6C935E2CA0",
EthereumPaymentIntentParser("wsteth", "ETH.WSTETH-E2CA0"),
R.string.cryptocurrency_wsteth_code,
R.string.cryptocurrency_wsteth_network
),
MayaEthereumTokenCryptoCurrency(
"ARB",
"Arbitrum",
"ARB.ARB-0X912CE59144191C1204E64559FE8253A0E49E6548",
EthereumPaymentIntentParser("arbitrum", "ARB.ARB-E6548"),
R.string.cryptocurrency_arbitrum_code,
R.string.cryptocurrency_arbitrum_network
),
MayaEthereumTokenCryptoCurrency(
"ETH",
"Ethereum",
"ARB.ETH",
EthereumPaymentIntentParser("ethereum", "ARB.ETH"),
R.string.cryptocurrency_ethereum_code,
R.string.cryptocurrency_ethereum_arbitrum_network
),
MayaEthereumTokenCryptoCurrency(
"DAI",
"Dai",
"ARB.DAI-0XDA10009CBD5D07DD0CECC66161FC93D7C9000DA1",
EthereumPaymentIntentParser("dai", "ARB.DAI-00DA1"),
R.string.cryptocurrency_dai_code,
R.string.cryptocurrency_dai_arbitrum_network
),
MayaEthereumTokenCryptoCurrency(
"GLD",
"Goldario",
"ARB.GLD-0XAFD091F140C21770F4E5D53D26B2859AE97555AA",
EthereumPaymentIntentParser("gld", "ARB.GLD-555AA"),
R.string.cryptocurrency_goldario_code,
R.string.cryptocurrency_goldario_arbitrum_network
),
MayaEthereumTokenCryptoCurrency(
"LEO",
"LEO",
"ARB.LEO-0X93864D81175095DD93360FFA2A529B8642F76A6E",
EthereumPaymentIntentParser("leo", "ARB.LEO-76A6E"),
R.string.cryptocurrency_leo_code,
R.string.cryptocurrency_leo_arbitrum_network
),
MayaEthereumTokenCryptoCurrency(
"LINK",
"ChainLink",
"ARB.LINK-0XF97F4DF75117A78C1A5A0DBB814AF92458539FB4",
EthereumPaymentIntentParser("link", "ARB.LINK-39FB4"),
R.string.cryptocurrency_link_code,
R.string.cryptocurrency_link_arbitrum_network
),
MayaEthereumTokenCryptoCurrency(
"PEPE",
"PEPE",
"ARB.PEPE-0X25D887CE7A35172C62FEBFD67A1856F20FAEBB00",
EthereumPaymentIntentParser("pepe", "ARB.PEPE-EBB00"),
R.string.cryptocurrency_pepe_code,
R.string.cryptocurrency_pepe_arbitrum_network
),
MayaEthereumTokenCryptoCurrency(
"TGT",
"THORWallet",
"ARB.TGT-0X429FED88F10285E61B12BDF00848315FBDFCC341",
EthereumPaymentIntentParser("thorwallet", "ARB.TGT-CC341"),
R.string.cryptocurrency_tgt_code,
R.string.cryptocurrency_tgt_arbitrum_network
),
MayaEthereumTokenCryptoCurrency(
"USDC",
"USD Coin",
"ARB.USDC-0XAF88D065E77C8CC2239327C5EDB3A432268E5831",
EthereumPaymentIntentParser("pepe", "ARB.USDC-0XE5831"),
R.string.cryptocurrency_usdcoin_code,
R.string.cryptocurrency_usdcoin_arbitrum_network
),
MayaEthereumTokenCryptoCurrency(
"WBTC",
"Wrapped Bitcoin",
"ARB.WBTC-0X2F2A2543B76A4166549F7AAB2E75BEF0AEFC5B0F",
EthereumPaymentIntentParser("wbtc", "ARB.WBTC-C5B0F"),
R.string.cryptocurrency_wbtc_code,
R.string.cryptocurrency_wbtc_arbitrum_network
),
MayaEthereumTokenCryptoCurrency(
"WSTETH",
"Wrapped stETH",
"ARB.WSTETH-0X5979D7B546E38E414F7E9822514BE443A4800529",
EthereumPaymentIntentParser("wsetth", "ARB.WSTETH-00529"),
R.string.cryptocurrency_wsteth_code,
R.string.cryptocurrency_wsteth_arbitrum_network
),

MayaKujiraCryptoCurrency(),
MayaKujiraTokenCryptoCurrency("USK", "USK", "KUJI.USK"),
MayaRuneCryptoCurrency()
)
currencyMap = currencyList.associateBy({ it.asset }, { it })
}
operator fun get(asset: String) = currencyMap[asset]
val all: Collection<MayaCryptoCurrency>
get() = currencyMap.values
fun getPaymentProcessors(): PaymentParsers {
val paymentProcessors = PaymentParsers()
for (currency in all) {
paymentProcessors.add(currency.name, currency.code, currency.paymentIntentParser, currency.addressParser)
}
return paymentProcessors
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.dash.wallet.common.util.safeNavigate
import org.dash.wallet.integrations.maya.R
import org.dash.wallet.integrations.maya.databinding.FragmentCurrencyPickerBinding
import org.dash.wallet.integrations.maya.model.PoolInfo
import org.dash.wallet.integrations.maya.payments.MayaCurrencyList

@AndroidEntryPoint
class MayaCryptoCurrencyPickerFragment : Fragment(R.layout.fragment_currency_picker) {
Expand Down Expand Up @@ -83,44 +84,12 @@ class MayaCryptoCurrencyPickerFragment : Fragment(R.layout.fragment_currency_pic
binding.contentList.adapter = adapter

// using this allows for translation of cryptocurrency names
defaultItemMap = mapOf(
"BTC.BTC" to IconifiedViewItem(
requireContext().getString(R.string.cryptocurrency_bitcoin_code),
requireContext().getString(R.string.cryptocurrency_bitcoin_network)
),
"ETH.ETH" to IconifiedViewItem(
requireContext().getString(R.string.cryptocurrency_ethereum_code),
requireContext().getString(R.string.cryptocurrency_ethereum_network)
),
"KUJI.KUJI" to IconifiedViewItem(
requireContext().getString(R.string.cryptocurrency_kuji_code),
requireContext().getString(R.string.cryptocurrency_kuji_network)
),
"KUJI.USK" to IconifiedViewItem(
requireContext().getString(R.string.cryptocurrency_usk_code),
requireContext().getString(R.string.cryptocurrency_usk_network)
),
"DASH.DASH" to IconifiedViewItem(
requireContext().getString(R.string.cryptocurrency_dash_code),
requireContext().getString(R.string.cryptocurrency_dash_network)
),
"ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48" to IconifiedViewItem(
requireContext().getString(R.string.cryptocurrency_usdcoin_code),
requireContext().getString(R.string.cryptocurrency_usdcoin_network)
),
"ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7" to IconifiedViewItem(
requireContext().getString(R.string.cryptocurrency_tether_code),
requireContext().getString(R.string.cryptocurrency_tether_network)
),
"ETH.WSTETH-0X7F39C581F595B53C5CB19BD0B3F8DA6C935E2CA0" to IconifiedViewItem(
requireContext().getString(R.string.cryptocurrency_wsteth_code),
requireContext().getString(R.string.cryptocurrency_wsteth_network)
),
"THOR.RUNE" to IconifiedViewItem(
requireContext().getString(R.string.cryptocurrency_rune_code),
requireContext().getString(R.string.cryptocurrency_rune_network)
defaultItemMap = MayaCurrencyList.all.associateBy({ it.asset }, {
IconifiedViewItem(
requireContext().getString(it.codeId),
requireContext().getString(it.nameId)
)
)
})

binding.searchQuery.doAfterTextChanged { text ->
lifecycleScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import org.dash.wallet.integrations.maya.api.FiatExchangeRateProvider
import org.dash.wallet.integrations.maya.api.MayaApi
import org.dash.wallet.integrations.maya.model.InboundAddress
import org.dash.wallet.integrations.maya.model.PoolInfo
import org.dash.wallet.integrations.maya.payments.parsers.MayaPaymentParsers
import org.dash.wallet.integrations.maya.payments.MayaCurrencyList
import org.dash.wallet.integrations.maya.utils.MayaConfig
import org.slf4j.LoggerFactory
import java.util.Locale
Expand Down Expand Up @@ -78,7 +78,7 @@ class MayaViewModel @Inject constructor(

val poolList = MutableStateFlow<List<PoolInfo>>(listOf())
val inboundAddresses = arrayListOf<InboundAddress>()
val paymentParsers = MayaPaymentParsers()
val paymentParsers = MayaCurrencyList.getPaymentProcessors()

init {
// TODO: is this really needed? we don't support DASH swaps
Expand Down
Loading
Loading