Skip to content

Commit 326f397

Browse files
committed
fix(walletconnect): support legacy solana chain id
1 parent 48d7295 commit 326f397

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

suite-common/walletconnect/src/adapters/ethereum.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ const ethereumRequestThunk = createThunk<
189189
}
190190
});
191191

192-
export const getChainId = (network: Network) => `eip155:${network.chainId}`;
192+
export const getChainId = (network: Network) => [`eip155:${network.chainId}`];
193193

194194
export const getNamespace = (accounts: Account[]) => {
195195
const eip155 = {
@@ -205,11 +205,13 @@ export const getNamespace = (accounts: Account[]) => {
205205

206206
if (!account.visible || networkType !== 'ethereum') return;
207207

208-
const walletConnectChainId = getChainId(network);
209-
if (!eip155.chains.includes(walletConnectChainId)) {
210-
eip155.chains.push(walletConnectChainId);
208+
const walletConnectChainIds = getChainId(network);
209+
for (const walletConnectChainId of walletConnectChainIds) {
210+
if (!eip155.chains.includes(walletConnectChainId)) {
211+
eip155.chains.push(walletConnectChainId);
212+
}
213+
eip155.accounts.push(`${walletConnectChainId}:${account.descriptor}`);
211214
}
212-
eip155.accounts.push(`${walletConnectChainId}:${account.descriptor}`);
213215
});
214216

215217
return { eip155 };

suite-common/walletconnect/src/adapters/solana.ts

+26-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const methods = [
2121
'solana_requestAccounts',
2222
'solana_signTransaction',
2323
'solana_signAndSendTransaction',
24-
// NOTE: 'solana_signMessage' is not supported in FW
24+
'solana_signMessage',
2525
];
2626

2727
const solanaSignTransaction = createThunk<
@@ -129,14 +129,25 @@ const solanaRequestThunk = createThunk<
129129

130130
return { signature: pushResponse.payload.txid };
131131
}
132+
case 'solana_signMessage': {
133+
// Signing arbitrary messages for Solana is not supported in FW
134+
// We indicate support for it in the adapter for compatibility, since some apps request it but don't actually use it
135+
throw new Error('solana_signMessage not supported');
136+
}
132137
}
133138
});
134139

140+
// https://github.com/reown-com/blockchain-api/blob/master/SUPPORTED_CHAINS.md#solana
141+
enum SolanaChainIds {
142+
MAINNET = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
143+
TESTNET = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
144+
MAINNET_LEGACY = 'solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ',
145+
}
146+
135147
export const getChainId = (network: Network) =>
136-
// https://github.com/reown-com/blockchain-api/blob/master/SUPPORTED_CHAINS.md#solana
137148
network.testnet
138-
? 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1'
139-
: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
149+
? [SolanaChainIds.TESTNET]
150+
: [SolanaChainIds.MAINNET, SolanaChainIds.MAINNET_LEGACY];
140151

141152
export const getNamespace = (accounts: Account[]) => {
142153
const solana = {
@@ -152,11 +163,13 @@ export const getNamespace = (accounts: Account[]) => {
152163

153164
if (!account.visible || networkType !== 'solana') return;
154165

155-
const walletConnectChainId = getChainId(network);
156-
if (!solana.chains.includes(walletConnectChainId)) {
157-
solana.chains.push(walletConnectChainId);
166+
const walletConnectChainIds = getChainId(network);
167+
for (const walletConnectChainId of walletConnectChainIds) {
168+
if (!solana.chains.includes(walletConnectChainId)) {
169+
solana.chains.push(walletConnectChainId);
170+
}
171+
solana.accounts.push(`${walletConnectChainId}:${account.descriptor}`);
158172
}
159-
solana.accounts.push(`${walletConnectChainId}:${account.descriptor}`);
160173
});
161174

162175
return { solana };
@@ -172,11 +185,13 @@ const processNamespaces = (
172185
([key, namespace]: [string, ProposalTypes.RequiredNamespace]) => {
173186
if (key === 'solana') {
174187
namespace.chains?.forEach(chain => {
175-
const alreadyAdded = networks.some(network => network.namespaceId === chain);
176-
if (alreadyAdded) return;
177188
const supported = networksCollection
178189
.filter(nc => nc.networkType === 'solana')
179-
.find(nc => chain === getChainId(nc));
190+
.find(nc => getChainId(nc).includes(chain as SolanaChainIds));
191+
const alreadyAdded = networks.some(
192+
network => network.symbol === supported?.symbol,
193+
);
194+
if (alreadyAdded) return;
180195
const getStatus = () => {
181196
if (!supported) return 'unsupported';
182197
const hasAccounts = accounts.some(

suite-common/walletconnect/src/walletConnectThunks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export const switchSelectedAccountThunk = createThunk<void, { account: Account }
239239
const network = getNetwork(account.symbol);
240240
if (!network || !network.chainId) return;
241241
const sessions = await walletKit.getActiveSessions();
242-
const chainId = getAdapterByNetwork(network.networkType)?.getChainId(network);
242+
const chainId = getAdapterByNetwork(network.networkType)?.getChainId(network)?.[0];
243243
if (!chainId) return;
244244

245245
for (const topic in sessions) {

suite-common/walletconnect/src/walletConnectTypes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface WalletConnectAdapter {
1111
requestThunk: SuiteCompatibleThunk<{
1212
event: WalletKitTypes.SessionRequest;
1313
}>;
14-
getChainId: (network: Network) => string;
14+
getChainId: (network: Network) => string[];
1515
getNamespace: (accounts: Account[]) => Record<string, WalletConnectNamespace>;
1616
processNamespaces: (
1717
accounts: Account[],

0 commit comments

Comments
 (0)