Skip to content

Commit

Permalink
fix: solana connect bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasackermn committed Dec 2, 2024
1 parent 3151b35 commit f528b3e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 36 deletions.
6 changes: 0 additions & 6 deletions wallets/provider-coinbase/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
16 changes: 12 additions & 4 deletions wallets/provider-coinbase/src/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
};

Expand Down
13 changes: 2 additions & 11 deletions wallets/provider-coinbase/src/namespaces/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) =>
Expand Down
23 changes: 8 additions & 15 deletions wallets/provider-coinbase/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,12 @@ export function solanaCoinbase(): SolanaProviderApi {

export async function getSolanaAccounts(
instance: any
): Promise<ProviderConnectResult[]> {
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<ProviderConnectResult> {
await instance.connect();
const account = instance.publicKey.toString();

return {
accounts: [account],
chainId: LegacyNetworks.SOLANA,
};
}

0 comments on commit f528b3e

Please sign in to comment.