Skip to content

Commit

Permalink
fix: filter out duplicated addresses from WalletStandardConnector (#3454
Browse files Browse the repository at this point in the history
)
  • Loading branch information
zoruka authored Dec 13, 2024
1 parent 444d1dd commit a737ca3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
22 changes: 22 additions & 0 deletions .changeset/sweet-pants-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'@reown/appkit-cli': patch
'@reown/appkit-common': patch
'@reown/appkit-core': patch
'@reown/appkit-experimental': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwe': patch
'@reown/appkit-siwx': patch
'@reown/appkit-ui': patch
'@reown/appkit-wallet': patch
'@reown/appkit-wallet-button': patch
---

Filter out duplicated addresses from WalletStandardConnector on Bitcoin adapter
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,21 @@ export class WalletStandardConnector extends ProviderEventEmitter implements Bit
}

async getAccountAddresses(): Promise<BitcoinConnector.AccountAddress[]> {
const mappedAccounts = this.wallet.accounts.map<BitcoinConnector.AccountAddress>(acc => ({
address: acc.address,
purpose: 'payment',
publicKey: Buffer.from(acc.publicKey).toString('hex')
}))
const addresses = new Set<string>()
const mappedAccounts = this.wallet.accounts
.map<BitcoinConnector.AccountAddress>(acc => ({
address: acc.address,
purpose: 'payment',
publicKey: Buffer.from(acc.publicKey).toString('hex')
}))
.filter(acc => {
if (addresses.has(acc.address)) {
return false
}
addresses.add(acc.address)

return true
})

return Promise.resolve(mappedAccounts)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,28 @@ describe('WalletStandardConnector', () => {
}
])
})

it('should filter duplicate addresses', async () => {
vi.spyOn(wallet, 'accounts', 'get').mockReturnValueOnce([
mockWalletStandardProvider.mockAccount({
address: 'address1',
publicKey: Buffer.from('publicKey1')
}),
mockWalletStandardProvider.mockAccount({
address: 'address1',
publicKey: Buffer.from('publicKey2')
})
])

const accounts = await connector.getAccountAddresses()
expect(accounts).toEqual([
{
address: 'address1',
publicKey: '7075626c69634b657931',
purpose: 'payment'
}
])
})
})

describe('signMessage', () => {
Expand Down

0 comments on commit a737ca3

Please sign in to comment.