From 388920dee7bdb8c0d5d8189151a6550ddacc1202 Mon Sep 17 00:00:00 2001 From: chyngyz Date: Thu, 20 Jun 2024 16:45:35 +0600 Subject: [PATCH] Enable adding custom Solana tokens --- app/build.gradle | 2 +- .../AddSolanaTokenBlockchainService.kt | 50 +++++++++++++++++++ .../modules/addtoken/AddTokenService.kt | 4 ++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/io/horizontalsystems/bankwallet/modules/addtoken/AddSolanaTokenBlockchainService.kt diff --git a/app/build.gradle b/app/build.gradle index 9c19be8dca..296da22fe8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -275,7 +275,7 @@ dependencies { implementation 'com.github.horizontalsystems:blockchain-fee-rate-kit-android:1d3bd49' implementation 'com.github.horizontalsystems:binance-chain-kit-android:c1509a2' implementation 'com.github.horizontalsystems:market-kit-android:636ca4d' - implementation 'com.github.horizontalsystems:solana-kit-android:ec238b4' + implementation 'com.github.horizontalsystems:solana-kit-android:ce738d8' implementation 'com.github.horizontalsystems:tron-kit-android:dc3dca7' // Zcash SDK coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4' diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/addtoken/AddSolanaTokenBlockchainService.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/addtoken/AddSolanaTokenBlockchainService.kt new file mode 100644 index 0000000000..2f407df94b --- /dev/null +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/addtoken/AddSolanaTokenBlockchainService.kt @@ -0,0 +1,50 @@ +package io.horizontalsystems.bankwallet.modules.addtoken + +import io.horizontalsystems.bankwallet.core.customCoinUid +import io.horizontalsystems.bankwallet.modules.addtoken.AddTokenModule.IAddTokenBlockchainService +import io.horizontalsystems.marketkit.models.Blockchain +import io.horizontalsystems.marketkit.models.Coin +import io.horizontalsystems.marketkit.models.Token +import io.horizontalsystems.marketkit.models.TokenQuery +import io.horizontalsystems.marketkit.models.TokenType +import io.horizontalsystems.solanakit.core.TokenProvider +import io.horizontalsystems.solanakit.models.Address +import io.horizontalsystems.solanakit.transactions.SolanaFmService + +class AddSolanaTokenBlockchainService( + private val blockchain: Blockchain, + private val tokenProvider: TokenProvider +) : IAddTokenBlockchainService { + + override fun isValid(reference: String): Boolean { + return try { + Address(reference) + true + } catch (e: Throwable) { + false + } + } + + override fun tokenQuery(reference: String): TokenQuery { + return TokenQuery(blockchain.type, TokenType.Spl(reference)) + } + + override suspend fun token(reference: String): Token { + val tokenInfo = tokenProvider.getTokenInfo(reference) + val tokenQuery = tokenQuery(reference) + return Token( + coin = Coin(tokenQuery.customCoinUid, tokenInfo.name, tokenInfo.symbol, tokenInfo.decimals), + blockchain = blockchain, + type = tokenQuery.tokenType, + decimals = tokenInfo.decimals + ) + } + + companion object { + fun getInstance(blockchain: Blockchain): AddSolanaTokenBlockchainService { + val tokenProvider = TokenProvider(SolanaFmService()) + return AddSolanaTokenBlockchainService(blockchain, tokenProvider) + } + } + +} diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/addtoken/AddTokenService.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/addtoken/AddTokenService.kt index 5cfd2c8fdb..caef99814b 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/addtoken/AddTokenService.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/addtoken/AddTokenService.kt @@ -33,6 +33,7 @@ class AddTokenService( BlockchainType.Fantom, BlockchainType.ArbitrumOne, BlockchainType.Optimism, + BlockchainType.Solana ) val blockchains = marketKit @@ -52,6 +53,9 @@ class AddTokenService( BlockchainType.Tron -> { AddTronTokenBlockchainService.getInstance(blockchain) } + BlockchainType.Solana -> { + AddSolanaTokenBlockchainService.getInstance(blockchain) + } else -> AddEvmTokenBlockchainService.getInstance(blockchain) }