From f528b3e2e0f31f0a0bb1a90f7c125413a557e510 Mon Sep 17 00:00:00 2001 From: mikasackermn Date: Wed, 27 Nov 2024 12:00:26 +0000 Subject: [PATCH] fix: solana connect bug --- wallets/provider-coinbase/src/constants.ts | 6 ----- wallets/provider-coinbase/src/legacy/index.ts | 16 +++++++++---- .../src/namespaces/solana.ts | 13 ++--------- wallets/provider-coinbase/src/utils.ts | 23 +++++++------------ 4 files changed, 22 insertions(+), 36 deletions(-) diff --git a/wallets/provider-coinbase/src/constants.ts b/wallets/provider-coinbase/src/constants.ts index c54f36c8e..126a1d2c9 100644 --- a/wallets/provider-coinbase/src/constants.ts +++ b/wallets/provider-coinbase/src/constants.ts @@ -1,10 +1,4 @@ import { type ProviderInfo } from '@rango-dev/wallets-core'; -import { LegacyNetworks } from '@rango-dev/wallets-core/legacy'; - -export const EVM_SUPPORTED_CHAINS = [ - LegacyNetworks.ETHEREUM, - LegacyNetworks.POLYGON, -]; export const WALLET_ID = 'coinbase'; diff --git a/wallets/provider-coinbase/src/legacy/index.ts b/wallets/provider-coinbase/src/legacy/index.ts index 0534e67f2..e5617db76 100644 --- a/wallets/provider-coinbase/src/legacy/index.ts +++ b/wallets/provider-coinbase/src/legacy/index.ts @@ -28,7 +28,11 @@ import { solanaBlockchain, } from 'rango-types'; -import { coinbase as coinbase_instance, getSolanaAccounts } from '../utils.js'; +import { + coinbase as coinbase_instance, + getSolanaAccounts, + solanaCoinbase, +} from '../utils.js'; import signer from './signer.js'; @@ -48,15 +52,19 @@ export const connect: Connect = async ({ instance, meta }) => { * whenever we are requesting accounts. */ const evm_instance = chooseInstance(instance, meta, Networks.ETHEREUM); - let results: ProviderConnectResult[] = []; + const results: ProviderConnectResult[] = []; if (evm_instance) { const evm = await getEvmAccounts(evm_instance); results.push(evm); } - const solanaResults = await getSolanaAccounts(instance); - results = [...results, ...solanaResults]; + const solanaInstance = solanaCoinbase(); + if (solanaInstance) { + const solanaResults = await getSolanaAccounts(solanaInstance); + results.push(solanaResults); + } + return results; }; diff --git a/wallets/provider-coinbase/src/namespaces/solana.ts b/wallets/provider-coinbase/src/namespaces/solana.ts index ae3cfff98..a1b68d5a5 100644 --- a/wallets/provider-coinbase/src/namespaces/solana.ts +++ b/wallets/provider-coinbase/src/namespaces/solana.ts @@ -10,10 +10,9 @@ import { CAIP_SOLANA_CHAIN_ID, } from '@rango-dev/wallets-core/namespaces/solana'; import { CAIP } from '@rango-dev/wallets-core/utils'; -import { getSolanaAccounts } from '@rango-dev/wallets-shared'; import { WALLET_ID } from '../constants.js'; -import { solanaCoinbase } from '../utils.js'; +import { getSolanaAccounts, solanaCoinbase } from '../utils.js'; const [changeAccountSubscriber, changeAccountCleanup] = actions.changeAccountSubscriber(solanaCoinbase); @@ -22,15 +21,7 @@ const connect = builders .connect() .action(async function () { const solanaInstance = solanaCoinbase(); - const result = await getSolanaAccounts({ - instance: solanaInstance, - meta: [], - }); - if (Array.isArray(result)) { - throw new Error( - 'Expecting solana response to be a single value, not an array.' - ); - } + const result = await getSolanaAccounts(solanaInstance); const formatAccounts = result.accounts.map( (account) => diff --git a/wallets/provider-coinbase/src/utils.ts b/wallets/provider-coinbase/src/utils.ts index a0c8872de..9303b071a 100644 --- a/wallets/provider-coinbase/src/utils.ts +++ b/wallets/provider-coinbase/src/utils.ts @@ -55,19 +55,12 @@ export function solanaCoinbase(): SolanaProviderApi { export async function getSolanaAccounts( instance: any -): Promise { - const solanaInstance = await instance.get(LegacyNetworks.SOLANA); - const results: ProviderConnectResult[] = []; - - if (solanaInstance) { - await solanaInstance.connect(); - const account = solanaInstance.publicKey.toString(); - - results.push({ - accounts: account ? [account] : [], - chainId: LegacyNetworks.SOLANA, - }); - } - - return results; +): Promise { + await instance.connect(); + const account = instance.publicKey.toString(); + + return { + accounts: [account], + chainId: LegacyNetworks.SOLANA, + }; }