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

Feature/app main hyuk dev #663

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion app/src/main/assets/bitcoin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/src/main/assets/injectScript.js

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions app/src/main/java/wannabit/io/cosmostaion/chain/BaseChain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import wannabit.io.cosmostaion.chain.cosmosClass.ChainFetchAi60Old
import wannabit.io.cosmostaion.chain.cosmosClass.ChainFetchAi60Secp
import wannabit.io.cosmostaion.chain.cosmosClass.ChainFinschia
import wannabit.io.cosmostaion.chain.cosmosClass.ChainFirma
import wannabit.io.cosmostaion.chain.testnetClass.ChainGnoTestnet
import wannabit.io.cosmostaion.chain.cosmosClass.ChainGovgen
import wannabit.io.cosmostaion.chain.cosmosClass.ChainGravityBridge
import wannabit.io.cosmostaion.chain.cosmosClass.ChainInjective
Expand Down Expand Up @@ -139,6 +140,7 @@ import wannabit.io.cosmostaion.chain.majorClass.ChainBitCoin44
import wannabit.io.cosmostaion.chain.majorClass.ChainBitCoin49
import wannabit.io.cosmostaion.chain.majorClass.ChainBitCoin84
import wannabit.io.cosmostaion.chain.majorClass.ChainSui
import wannabit.io.cosmostaion.chain.testnetClass.ChainBabylonTestnet
import wannabit.io.cosmostaion.chain.testnetClass.ChainBitcoin44Testnet
import wannabit.io.cosmostaion.chain.testnetClass.ChainBitcoin49Testnet
import wannabit.io.cosmostaion.chain.testnetClass.ChainBitcoin84Testnet
Expand Down Expand Up @@ -485,6 +487,18 @@ open class BaseChain : Parcelable {
return getChainListParam()?.get("is_support_cw721")?.asBoolean ?: false
}

fun isSupportGrc20(): Boolean {
return getChainListParam()?.get("is_support_grc20")?.asBoolean ?: false
}

fun isSupportStaking(): Boolean {
return getChainListParam()?.getAsJsonObject("btc_staking")?.get("is_support_staking")?.asBoolean ?: false
}

fun btcStakingDapp(): String {
return getChainListParam()?.getAsJsonObject("btc_staking")?.get("url")?.asString ?: ""
}

fun explorerAccount(address: String): Uri? {
getChainListParam()?.getAsJsonObject("explorer")
?.get("account")?.asString?.let { urlString ->
Expand Down Expand Up @@ -604,8 +618,8 @@ fun allChains(): MutableList<BaseChain> {
chains.add(ChainCoreum())
chains.add(ChainCronos())
chains.add(ChainCryptoorg())
chains.add(ChainDHealth())
chains.add(ChainDesmos())
chains.add(ChainDHealth())
chains.add(ChainDoravota())
chains.add(ChainDungeon())
chains.add(ChainDydx())
Expand Down Expand Up @@ -701,9 +715,11 @@ fun allChains(): MutableList<BaseChain> {

// chains.add(ChainCosmosTestnet())
// chains.add(ChainArtelaTestnet())
chains.add(ChainBitcoin44Testnet())
chains.add(ChainBitcoin49Testnet())
// chains.add(ChainBitcoin44Testnet())
// chains.add(ChainBitcoin49Testnet())
chains.add(ChainBabylonTestnet())
chains.add(ChainBitcoin84Testnet())
chains.add(ChainGnoTestnet())
chains.add(ChainInitiaTestnet())
chains.add(ChainMantraTestnet())
chains.add(ChainNeutronTestnet())
Expand Down Expand Up @@ -745,6 +761,6 @@ val EVM_BASE_FEE = BigDecimal("588000000000000")

enum class PubKeyType { ETH_KECCAK256, COSMOS_SECP256K1, BERA_SECP256K1, SUI_ED25519, BTC_LEGACY, BTC_NESTED_SEGWIT, BTC_NATIVE_SEGWIT, NONE }

enum class CosmosEndPointType { UNKNOWN, USE_GRPC, USE_LCD }
enum class CosmosEndPointType { UNKNOWN, USE_GRPC, USE_LCD, USE_RPC }

enum class FetchState { IDLE, BUSY, SUCCESS, FAIL }
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class ChainBitcanna : BaseChain(), Parcelable {
override var cosmosEndPointType: CosmosEndPointType? = CosmosEndPointType.USE_GRPC
override var stakeDenom: String = "ubcna"
override var accountPrefix: String = "bcna"
override var grpcHost: String = "grpc-bitcanna.cosmostation.io"
override var lcdUrl: String = "https://lcd-bitcanna.cosmostation.io/"
override var grpcHost: String = "grpc-bitcanna.io"
override var lcdUrl: String = "https://lcd-bitcanna.io/"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import wannabit.io.cosmostaion.chain.PubKeyType
@Parcelize
class ChainCosmos : BaseChain(), Parcelable {

override var name: String = "Cosmos"
override var name: String = "Cosmos Hub"
override var tag: String = "cosmos118"
override var logo: Int = R.drawable.chain_cosmos
override var swipeLogo: Int = R.drawable.chain_swipe_cosmos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import wannabit.io.cosmostaion.chain.PubKeyType
@Parcelize
class ChainRouterchainEvm : BaseChain(), Parcelable {

override var name: String = "Routerchain"
override var name: String = "RouterChain"
override var tag: String = "routerchain60"
override var logo: Int = R.drawable.chain_routerchain
override var apiName: String = "routerchain"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BtcFetcher(private val chain: BaseChain) : CosmosFetcher(chain) {

fun mempoolUrl(): String {
if (chain.isTestnet) {
return "https://mempool.space/testnet4/"
return "https://mempool.space/signet/"
}
return "https://mempool.space/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ open class CosmosFetcher(private val chain: BaseChain) {
var cosmosBaseFees = mutableListOf<CoinProto.DecCoin>()

var tokens = mutableListOf<Token>()
var grc20Tokens = mutableListOf<Token>()
var cw721s = mutableListOf<JsonObject>()
var cw721Fetched = false
var cw721Models = mutableListOf<Cw721Model>()
Expand All @@ -76,13 +77,34 @@ open class CosmosFetcher(private val chain: BaseChain) {
}
}

fun grc20TokenValue(address: String, isUsd: Boolean? = false): BigDecimal {
grc20Tokens.firstOrNull { it.contract == address }?.let { tokenInfo ->
val price = BaseData.getPrice(tokenInfo.coinGeckoId, isUsd)
return price.multiply(tokenInfo.amount?.toBigDecimal())
.movePointLeft(tokenInfo.decimals).setScale(6, RoundingMode.DOWN)
} ?: run {
return BigDecimal.ZERO
}
}

fun allTokenValue(isUsd: Boolean? = false): BigDecimal {
var result = BigDecimal.ZERO
tokens.forEach { token ->
val price = BaseData.getPrice(token.coinGeckoId, isUsd)
val value = price.multiply(token.amount?.toBigDecimal()).movePointLeft(token.decimals)
.setScale(6, RoundingMode.DOWN)
result = result.add(value)
if (tokens.isNotEmpty()) {
tokens.forEach { token ->
val price = BaseData.getPrice(token.coinGeckoId, isUsd)
val value = price.multiply(token.amount?.toBigDecimal()).movePointLeft(token.decimals)
.setScale(6, RoundingMode.DOWN)
result = result.add(value)
}
}

if (grc20Tokens.isNotEmpty()) {
grc20Tokens.forEach { token ->
val price = BaseData.getPrice(token.coinGeckoId, isUsd)
val value = price.multiply(token.amount?.toBigDecimal()).movePointLeft(token.decimals)
.setScale(6, RoundingMode.DOWN)
result = result.add(value)
}
}
return result
}
Expand All @@ -100,6 +122,10 @@ open class CosmosFetcher(private val chain: BaseChain) {
return tokens.count { BigDecimal.ZERO < it.amount?.toBigDecimal() }
}

fun valueGrc20TokenCnt(): Int {
return grc20Tokens.count { BigDecimal.ZERO < it.amount?.toBigDecimal() }
}

fun balanceAmount(denom: String): BigDecimal {
if (cosmosBalances?.isNotEmpty() == true) {
return cosmosBalances?.firstOrNull { it.denom == denom }?.amount?.toBigDecimal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import kotlinx.parcelize.Parcelize
import org.bitcoinj.crypto.ChildNumber
import wannabit.io.cosmostaion.R
import wannabit.io.cosmostaion.chain.AccountKeyType
import wannabit.io.cosmostaion.chain.BaseChain
import wannabit.io.cosmostaion.chain.PubKeyType
import wannabit.io.cosmostaion.common.BaseKey

@Parcelize
class ChainBitCoin44 : ChainBitCoin84(), Parcelable {

override var name: String = "BitCoin"
override var name: String = "Bitcoin"
override var tag: String = "bitcoin44"
override var logo: Int = R.drawable.chain_bitcoin
override var isDefault: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import kotlinx.parcelize.Parcelize
import org.bitcoinj.crypto.ChildNumber
import wannabit.io.cosmostaion.R
import wannabit.io.cosmostaion.chain.AccountKeyType
import wannabit.io.cosmostaion.chain.BaseChain
import wannabit.io.cosmostaion.chain.PubKeyType
import wannabit.io.cosmostaion.common.BaseKey

@Parcelize
class ChainBitCoin49 : ChainBitCoin84(), Parcelable {

override var name: String = "BitCoin"
override var name: String = "Bitcoin"
override var tag: String = "bitcoin49"
override var logo: Int = R.drawable.chain_bitcoin
override var isDefault: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ open class ChainBitCoin84 : BaseChain(), Parcelable {
open var scriptHash: Byte = 0x05
open var bech32PrefixPattern: String = "bc"

override var name: String = "BitCoin"
override var name: String = "Bitcoin"
override var tag: String = "bitcoin84"
override var logo: Int = R.drawable.chain_bitcoin
override var apiName: String = "bitcoin"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package wannabit.io.cosmostaion.chain.testnetClass

import android.os.Parcelable
import com.google.common.collect.ImmutableList
import kotlinx.parcelize.Parcelize
import org.bitcoinj.crypto.ChildNumber
import wannabit.io.cosmostaion.R
import wannabit.io.cosmostaion.chain.AccountKeyType
import wannabit.io.cosmostaion.chain.BaseChain
import wannabit.io.cosmostaion.chain.CosmosEndPointType
import wannabit.io.cosmostaion.chain.PubKeyType

@Parcelize
class ChainBabylonTestnet : BaseChain(), Parcelable {

override var name: String = "Babylon Testnet"
override var tag: String = "babylon118_T"
override var logo: Int = R.drawable.chain_babylon_testnet
override var isTestnet: Boolean = true
override var apiName: String = "babylon-testnet"

override var accountKeyType = AccountKeyType(PubKeyType.COSMOS_SECP256K1, "m/44'/118'/0'/0/X")
override var setParentPath: List<ChildNumber> = ImmutableList.of(
ChildNumber(44, true), ChildNumber(118, true), ChildNumber.ZERO_HARDENED, ChildNumber.ZERO
)

override var cosmosEndPointType: CosmosEndPointType? = CosmosEndPointType.USE_GRPC
override var stakeDenom: String = "ubbn"
override var accountPrefix: String = "bbn"
override var grpcHost: String = "grpc-office-babylon.cosmostation.io"
override var lcdUrl: String = "https://lcd-office.cosmostation.io/babylon-testnet/"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import wannabit.io.cosmostaion.common.BaseKey
@Parcelize
class ChainBitcoin44Testnet : ChainBitcoin84Testnet(), Parcelable {

override var name: String = "BitCoin Testnet"
override var name: String = "Bitcoin Testnet"
override var tag: String = "bitcoin44_T"
override var logo: Int = R.drawable.chain_bitcoin_testnet
override var isDefault: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import wannabit.io.cosmostaion.common.BaseKey
@Parcelize
class ChainBitcoin49Testnet : ChainBitcoin84Testnet(), Parcelable {

override var name: String = "BitCoin Testnet"
override var name: String = "Bitcoin Testnet"
override var tag: String = "bitcoin49_T"
override var logo: Int = R.drawable.chain_bitcoin_testnet
override var isDefault: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ open class ChainBitcoin84Testnet : ChainBitCoin84(), Parcelable {
override var scriptHash: Byte = (-60).toByte()
override var bech32PrefixPattern: String = "tb"

override var name: String = "BitCoin Testnet"
override var name: String = "Bitcoin Signet"
override var tag: String = "bitcoin84_T"
override var logo: Int = R.drawable.chain_bitcoin_testnet
override var logo: Int = R.drawable.chain_bitcoin_signet
override var isTestnet: Boolean = true
override var apiName: String = "bitcoin-testnet"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package wannabit.io.cosmostaion.chain.testnetClass

import android.os.Parcelable
import com.google.common.collect.ImmutableList
import kotlinx.parcelize.Parcelize
import org.bitcoinj.crypto.ChildNumber
import wannabit.io.cosmostaion.R
import wannabit.io.cosmostaion.chain.AccountKeyType
import wannabit.io.cosmostaion.chain.BaseChain
import wannabit.io.cosmostaion.chain.CosmosEndPointType
import wannabit.io.cosmostaion.chain.PubKeyType

@Parcelize
class ChainGnoTestnet : BaseChain(), Parcelable {

override var name: String = "Gno Testnet"
override var tag: String = "gno118_T"
override var logo: Int = R.drawable.chain_gno_testnet
override var isTestnet: Boolean = true
override var apiName: String = "gno-testnet"

override var accountKeyType = AccountKeyType(PubKeyType.COSMOS_SECP256K1, "m/44'/118'/0'/0/X")
override var setParentPath: List<ChildNumber> = ImmutableList.of(
ChildNumber(44, true), ChildNumber(118, true), ChildNumber.ZERO_HARDENED, ChildNumber.ZERO
)

override var cosmosEndPointType: CosmosEndPointType? = CosmosEndPointType.USE_RPC
override var stakeDenom: String = "ugnot"
override var accountPrefix: String = "g"
override var mainUrl: String = "https://rpc.test5.gno.land"
}
14 changes: 14 additions & 0 deletions app/src/main/java/wannabit/io/cosmostaion/common/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -893,3 +893,17 @@ fun com.initia.mstaking.v1.StakingProto.Validator.isActiveValidator(chain: Chain
}
}

fun String.regexWithNumberAndChar(): Pair<String, String> {
val regex = Regex("[0-9]*\\.?[0-9]*")
val matchResult = regex.find(this)
return if (matchResult != null) {
val amount = matchResult.value
val denomIndex = amount.length
val denom = this.substring(denomIndex)
Pair(denom, amount)

} else {
Pair("", "")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ interface MintscanApi {
@GET("v11/assets/{chain}/erc20/info")
suspend fun erc20token(@Path("chain") chain: String): MutableList<Token>

@GET("v11/assets/{chain}/grc20/info")
suspend fun grc20token(@Path("chain") chain: String): MutableList<Token>

@GET("v11/assets/{chain}/cw721")
suspend fun cw721Info(@Path("chain") chain: String): JsonObject

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package wannabit.io.cosmostaion.data.model.req

import com.fasterxml.jackson.annotation.JsonInclude
import com.google.gson.GsonBuilder
import com.google.gson.annotations.SerializedName


data class SignPayload(
val chain_id: String,
val account_number: String,
val sequence: String,
val fee: Fee,
val msgs: MutableList<Msgs>?,
val memo: String? = ""
) {
fun toJson(): String {
val gson = GsonBuilder().setPrettyPrinting().create()
return gson.toJson(this)
}
}

data class Fee(
val gas_wanted: String,
val gas_fee: String
)

data class Msgs(
@SerializedName("@type")
val type: String,

@JsonInclude(JsonInclude.Include.NON_NULL)
val from_address: String? = null,

@JsonInclude(JsonInclude.Include.NON_NULL)
val to_address: String? = null,

@JsonInclude(JsonInclude.Include.NON_NULL)
val amount: String? = null,

@JsonInclude(JsonInclude.Include.NON_NULL)
val send: String? = null,

@JsonInclude(JsonInclude.Include.NON_NULL)
val caller: String? = null,

@JsonInclude(JsonInclude.Include.NON_NULL)
val pkg_path: String? = null,

@JsonInclude(JsonInclude.Include.NON_NULL)
val func: String? = null,

@JsonInclude(JsonInclude.Include.NON_NULL)
val args: List<String>? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package wannabit.io.cosmostaion.data.model.res

data class Coin(val denom: String, val amount: String, val type: CoinType)

enum class CoinType { STAKE, NATIVE, IBC, BRIDGE, ETC, CW20, ERC20 }
enum class CoinType { STAKE, NATIVE, IBC, BRIDGE, ETC, CW20, ERC20, GRC20 }
Loading