Skip to content

Commit

Permalink
fix: fallback to account chains to get session chains (#2855)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoruka authored Sep 16, 2024
1 parent bb9e704 commit 9a51638
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,20 @@ export class WalletConnectProvider extends ProviderEventEmitter implements Provi
}

private get sessionChains() {
return this.session?.namespaces['solana']?.chains || []
const solanaNamespace = this.session?.namespaces['solana']

if (!solanaNamespace) {
return []
}

const chains = solanaNamespace.chains || []
const accountsChains = solanaNamespace.accounts.map(account => {
const [chainNamespace, chainId] = account.split(':')

return `${chainNamespace}:${chainId}`
})

return Array.from(new Set([...chains, ...accountsChains]))
}

private serializeTransaction(transaction: AnyTransaction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,31 @@ describe('WalletConnectProvider specific tests', () => {
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'
)
})

it('should get chains from namespace accounts', async () => {
vi.spyOn(provider, 'connect').mockImplementationOnce(() =>
Promise.resolve(
mockUniversalProviderSession({
namespaces: {
solana: {
chains: undefined,
methods: [
'solana_signTransaction',
'solana_signMessage',
'solana_signAndSendTransaction'
],
events: [],
accounts: [
`solana:${TestConstants.chains[0]?.chainId}:${TestConstants.accounts[0].address}`
]
}
}
})
)
)

await walletConnectProvider.connect()

expect(walletConnectProvider.chains).toEqual([TestConstants.chains[0]])
})
})

0 comments on commit 9a51638

Please sign in to comment.