diff --git a/data/src/main/kotlin/com/vultisig/wallet/data/api/SolanaApi.kt b/data/src/main/kotlin/com/vultisig/wallet/data/api/SolanaApi.kt index 22a5bf52f..1cfab6772 100644 --- a/data/src/main/kotlin/com/vultisig/wallet/data/api/SolanaApi.kt +++ b/data/src/main/kotlin/com/vultisig/wallet/data/api/SolanaApi.kt @@ -232,39 +232,57 @@ internal class SolanaApiImp @Inject constructor( ) }.body() - override suspend fun getSPLTokens(walletAddress: String): List? { - try { - val payload = RpcPayload( - jsonrpc = "2.0", - method = "getTokenAccountsByOwner", - params = buildJsonArray { - add(walletAddress) - addJsonObject { - put("programId", PROGRAM_ID_SPL_REQUEST_PARAM) + override suspend fun getSPLTokens(walletAddress: String): List? = + coroutineScope { + try { + val payload = getSplRpcPayload(walletAddress, PROGRAM_ID_SPL_REQUEST_PARAM) + val payloadToken2022 = getSplRpcPayload(walletAddress, TOKEN_PROGRAM_ID_2022) + + val response = async { + httpClient.post(rpcEndpoint) { + setBody(payload) } - addJsonObject { - put("encoding", ENCODING_SPL_REQUEST_PARAM) + } + + val responseToken2022 = async { + httpClient.post(rpcEndpoint) { + setBody(payloadToken2022) } - }, - id = 1, - ) - val response = httpClient.post(rpcEndpoint) { - setBody(payload) - } - val responseContent = response.bodyAsText() - Timber.d(responseContent) - val rpcResp = response.body() + } - if (rpcResp.error != null) { - Timber.d("get spl token addresses error: ${rpcResp.error}") - return null + listOf(response, responseToken2022) + .awaitAll() + .mapNotNull { it.body().result?.accounts } + .flatten() + + } catch (e: Exception) { + Timber.e(e) + null } - return rpcResp.result?.accounts - } catch (e: Exception) { - Timber.e(e) - return null } - } + + + private fun getSplRpcPayload(address: String, programId: String) = RpcPayload( + jsonrpc = "2.0", + method = "getTokenAccountsByOwner", + params = buildJsonArray { + add(address) + addJsonObject { + put( + "programId", + programId + ) + } + addJsonObject { + put( + "encoding", + ENCODING_SPL_REQUEST_PARAM + ) + } + }, + id = 1, + ) + override suspend fun getSPLTokenBalance(walletAddress: String, coinAddress: String): String? { try { @@ -335,6 +353,8 @@ internal class SolanaApiImp @Inject constructor( companion object { private const val PROGRAM_ID_SPL_REQUEST_PARAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + private const val TOKEN_PROGRAM_ID_2022 = + "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" private const val ENCODING_SPL_REQUEST_PARAM = "jsonParsed" private const val DATA_LENGTH_MINIMUM_BALANCE_FOR_RENT_EXEMPTION = 165 } diff --git a/data/src/main/kotlin/com/vultisig/wallet/data/repositories/AccountsRepository.kt b/data/src/main/kotlin/com/vultisig/wallet/data/repositories/AccountsRepository.kt index 8f50ecde8..d42b7d50c 100644 --- a/data/src/main/kotlin/com/vultisig/wallet/data/repositories/AccountsRepository.kt +++ b/data/src/main/kotlin/com/vultisig/wallet/data/repositories/AccountsRepository.kt @@ -119,7 +119,7 @@ internal class AccountsRepositoryImpl @Inject constructor( solanaCoins: List, vault: Vault ): List { - if (solanaCoins.isNotEmpty()) return emptyList() + if (solanaCoins.any { !it.isNativeToken }) return emptyList() val solanaAddress = solanaCoins.firstOrNull()?.address val newSPLTokens = mutableListOf() solanaAddress?.let {