Skip to content

Commit 8a19fbf

Browse files
committed
fix(walletconnect): support legacy solana chain id
1 parent 92e95f8 commit 8a19fbf

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
@@ -190,7 +190,7 @@ const ethereumRequestThunk = createThunk<
190190
}
191191
});
192192

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

195195
export const getNamespace = (accounts: Account[]) => {
196196
const eip155 = {
@@ -206,11 +206,13 @@ export const getNamespace = (accounts: Account[]) => {
206206

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

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

216218
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<
@@ -130,14 +130,25 @@ const solanaRequestThunk = createThunk<
130130

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

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

142153
export const getNamespace = (accounts: Account[]) => {
143154
const solana = {
@@ -153,11 +164,13 @@ export const getNamespace = (accounts: Account[]) => {
153164

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

156-
const walletConnectChainId = getChainId(network);
157-
if (!solana.chains.includes(walletConnectChainId)) {
158-
solana.chains.push(walletConnectChainId);
167+
const walletConnectChainIds = getChainId(network);
168+
for (const walletConnectChainId of walletConnectChainIds) {
169+
if (!solana.chains.includes(walletConnectChainId)) {
170+
solana.chains.push(walletConnectChainId);
171+
}
172+
solana.accounts.push(`${walletConnectChainId}:${account.descriptor}`);
159173
}
160-
solana.accounts.push(`${walletConnectChainId}:${account.descriptor}`);
161174
});
162175

163176
return { solana };
@@ -173,11 +186,13 @@ const processNamespaces = (
173186
([key, namespace]: [string, ProposalTypes.RequiredNamespace]) => {
174187
if (key === 'solana') {
175188
namespace.chains?.forEach(chain => {
176-
const alreadyAdded = networks.some(network => network.namespaceId === chain);
177-
if (alreadyAdded) return;
178189
const supported = networksCollection
179190
.filter(nc => nc.networkType === 'solana')
180-
.find(nc => chain === getChainId(nc));
191+
.find(nc => getChainId(nc).includes(chain as SolanaChainIds));
192+
const alreadyAdded = networks.some(
193+
network => network.symbol === supported?.symbol,
194+
);
195+
if (alreadyAdded) return;
181196
const getStatus = () => {
182197
if (!supported) return 'unsupported';
183198
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)