From 06aae9b8f866d56eed120bbcbb87fca1202be373 Mon Sep 17 00:00:00 2001 From: gin-lsl Date: Fri, 1 Nov 2024 14:24:58 +0800 Subject: [PATCH] feat(sui): Returns addresses on connected (#1219) * feat(sui): Returns addresses on connected * add test * chore: update snapshots * test: update snapshot --------- Co-authored-by: tingzhao.ytz --- .changeset/honest-sloths-march.md | 5 +++++ .../sui-provider/__tests__/connect.test.tsx | 21 ++++++++++++++++++- .../sui/src/sui-provider/config-provider.tsx | 6 ++++-- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 .changeset/honest-sloths-march.md diff --git a/.changeset/honest-sloths-march.md b/.changeset/honest-sloths-march.md new file mode 100644 index 000000000..f95c352c9 --- /dev/null +++ b/.changeset/honest-sloths-march.md @@ -0,0 +1,5 @@ +--- +'@ant-design/web3-sui': patch +--- + +feat(sui): Returns addresses on connected diff --git a/packages/sui/src/sui-provider/__tests__/connect.test.tsx b/packages/sui/src/sui-provider/__tests__/connect.test.tsx index 5fc4cfbca..31ffb5c3c 100644 --- a/packages/sui/src/sui-provider/__tests__/connect.test.tsx +++ b/packages/sui/src/sui-provider/__tests__/connect.test.tsx @@ -12,6 +12,11 @@ describe('SuiWeb3ConfigProvider connect tests', () => { // fake address shortAddress: '0xa123...y123', address: '0xa123a123b123b123____a00aaf10c9c283aae9498684218____x123x123y123y123', + accounts: [ + { address: '0xa123a123b123b123____a00aaf10c9c283aae9498684218____x123x123y123y123' }, + { address: '0xa123a123b123b123____a00aaf10c9c283aae9498684218____x123x123y123y12a' }, + { address: '0xa123a123b123b123____a00aaf10c9c283aae9498684218____x123x123y123y12b' }, + ], WALLETS: [ { name: 'Test Wallet', @@ -41,6 +46,7 @@ describe('SuiWeb3ConfigProvider connect tests', () => { accountRef.value = mockedDatas.address; forceUpdate(accountRef.value); + return { accounts: mockedDatas.accounts }; }; return { @@ -61,10 +67,16 @@ describe('SuiWeb3ConfigProvider connect tests', () => { }); it('available connect', async () => { + const testOnConnectedAddresses = vi.fn(); + const App = () => { return ( - + { + testOnConnectedAddresses(account?.addresses?.join(',')); + }} + > @@ -110,6 +122,13 @@ describe('SuiWeb3ConfigProvider connect tests', () => { await vi.waitFor(() => { expect(selector('.ant-web3-connect-button')?.textContent).toBe(mockedDatas.shortAddress); }); + + // test onConnected callback passed `addresses` + await vi.waitFor(() => { + expect(testOnConnectedAddresses).toBeCalledWith( + mockedDatas.accounts.map((v) => v.address).join(','), + ); + }); }); it('available connect', async () => { diff --git a/packages/sui/src/sui-provider/config-provider.tsx b/packages/sui/src/sui-provider/config-provider.tsx index 69338d17c..602c3770d 100644 --- a/packages/sui/src/sui-provider/config-provider.tsx +++ b/packages/sui/src/sui-provider/config-provider.tsx @@ -141,10 +141,12 @@ export const AntDesignWeb3ConfigProvider: React.FC< } const { accounts } = await connectAsync({ wallet: foundWallet }); - const connectedAccount = accounts[0]; + const defaultAccount = accounts[0]; + const addresses = accounts.map((item) => item.address) as unknown as Account['addresses']; return { - address: connectedAccount.address, + address: defaultAccount.address, + addresses: addresses, }; }} disconnect={async () => {