Skip to content

Commit

Permalink
Enable adding custom Solana tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
omurovch committed Jun 20, 2024
1 parent 5052bc1 commit 4fcfc78
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AddTokenService(
BlockchainType.Fantom,
BlockchainType.ArbitrumOne,
BlockchainType.Optimism,
BlockchainType.Solana
)

val blockchains = marketKit
Expand All @@ -52,6 +53,9 @@ class AddTokenService(
BlockchainType.Tron -> {
AddTronTokenBlockchainService.getInstance(blockchain)
}
BlockchainType.Solana -> {
AddSolanaTokenBlockchainService.getInstance(blockchain)
}
else -> AddEvmTokenBlockchainService.getInstance(blockchain)
}

Expand Down

0 comments on commit 4fcfc78

Please sign in to comment.