Skip to content

Commit

Permalink
feat(sui): Returns addresses on connected (#1219)
Browse files Browse the repository at this point in the history
* feat(sui): Returns addresses on connected

* add test

* chore: update snapshots

* test: update snapshot

---------

Co-authored-by: tingzhao.ytz <[email protected]>
  • Loading branch information
gin-lsl and tingzhao.ytz authored Nov 1, 2024
1 parent 0f5c1b8 commit 06aae9b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-sloths-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ant-design/web3-sui': patch
---

feat(sui): Returns addresses on connected
21 changes: 20 additions & 1 deletion packages/sui/src/sui-provider/__tests__/connect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -41,6 +46,7 @@ describe('SuiWeb3ConfigProvider connect tests', () => {
accountRef.value = mockedDatas.address;

forceUpdate(accountRef.value);
return { accounts: mockedDatas.accounts };
};

return {
Expand All @@ -61,10 +67,16 @@ describe('SuiWeb3ConfigProvider connect tests', () => {
});

it('available connect', async () => {
const testOnConnectedAddresses = vi.fn();

const App = () => {
return (
<SuiWeb3ConfigProvider>
<Connector>
<Connector
onConnected={(account) => {
testOnConnectedAddresses(account?.addresses?.join(','));
}}
>
<ConnectButton />
</Connector>
</SuiWeb3ConfigProvider>
Expand Down Expand Up @@ -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 () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/sui/src/sui-provider/config-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 06aae9b

Please sign in to comment.