From a737ca3b20714a0c89fc6620ce1fed3602a02796 Mon Sep 17 00:00:00 2001 From: Felipe Mendes Date: Fri, 13 Dec 2024 16:03:41 -0300 Subject: [PATCH] fix: filter out duplicated addresses from WalletStandardConnector (#3454) --- .changeset/sweet-pants-hunt.md | 22 +++++++++++++++++++ .../src/connectors/WalletStandardConnector.ts | 20 ++++++++++++----- .../WalletStandardConnector.test.ts | 22 +++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 .changeset/sweet-pants-hunt.md diff --git a/.changeset/sweet-pants-hunt.md b/.changeset/sweet-pants-hunt.md new file mode 100644 index 0000000000..875b08898c --- /dev/null +++ b/.changeset/sweet-pants-hunt.md @@ -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 diff --git a/packages/adapters/bitcoin/src/connectors/WalletStandardConnector.ts b/packages/adapters/bitcoin/src/connectors/WalletStandardConnector.ts index 5997c4717f..899300d128 100644 --- a/packages/adapters/bitcoin/src/connectors/WalletStandardConnector.ts +++ b/packages/adapters/bitcoin/src/connectors/WalletStandardConnector.ts @@ -70,11 +70,21 @@ export class WalletStandardConnector extends ProviderEventEmitter implements Bit } async getAccountAddresses(): Promise { - const mappedAccounts = this.wallet.accounts.map(acc => ({ - address: acc.address, - purpose: 'payment', - publicKey: Buffer.from(acc.publicKey).toString('hex') - })) + const addresses = new Set() + const mappedAccounts = this.wallet.accounts + .map(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) } diff --git a/packages/adapters/bitcoin/tests/connectors/WalletStandardConnector.test.ts b/packages/adapters/bitcoin/tests/connectors/WalletStandardConnector.test.ts index 3400133295..b0a24c8698 100644 --- a/packages/adapters/bitcoin/tests/connectors/WalletStandardConnector.test.ts +++ b/packages/adapters/bitcoin/tests/connectors/WalletStandardConnector.test.ts @@ -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', () => {