diff --git a/.changeset/healthy-spies-smash.md b/.changeset/healthy-spies-smash.md new file mode 100644 index 000000000..e48205763 --- /dev/null +++ b/.changeset/healthy-spies-smash.md @@ -0,0 +1,6 @@ +--- +'@ant-design/web3-solana': patch +'@ant-design/web3-sui': patch +--- + +fix(sui,solana): Should return address after connect diff --git a/packages/solana/src/solana-provider/__tests__/connect.test.tsx b/packages/solana/src/solana-provider/__tests__/connect.test.tsx index c1d86dfab..265647261 100644 --- a/packages/solana/src/solana-provider/__tests__/connect.test.tsx +++ b/packages/solana/src/solana-provider/__tests__/connect.test.tsx @@ -149,6 +149,7 @@ describe('Solana Connect', () => { const { useWallet } = await import('@solana/wallet-adapter-react'); const switchWalletRunned = vi.fn(); const connectRunned = vi.fn(); + const gotAddressAfterConnect = vi.fn(); const CustomConnectBtn: React.FC = () => { const { connect, availableWallets } = useProvider(); @@ -172,7 +173,8 @@ describe('Solana Connect', () => { await connectWallet(); // mock connect twice connect?.(availableWallets?.[1]); - await connect?.(availableWallets?.[0]); + const connectedAddress = await connect?.(availableWallets?.[0]); + gotAddressAfterConnect(connectedAddress?.address); await connect?.(availableWallets?.[2]); connectRunned(); @@ -228,6 +230,7 @@ describe('Solana Connect', () => { () => { expect(connectRunned).toBeCalled(); expect(shownConnectRunDone.textContent).toBe('true'); + expect(gotAddressAfterConnect).toBeCalledWith(mockedData.address.value); }, { timeout: 5000, diff --git a/packages/solana/src/solana-provider/config-provider.tsx b/packages/solana/src/solana-provider/config-provider.tsx index 1470980c2..fbc992b77 100644 --- a/packages/solana/src/solana-provider/config-provider.tsx +++ b/packages/solana/src/solana-provider/config-provider.tsx @@ -14,8 +14,8 @@ import { hasWalletReady } from '../utils'; import { WalletConnectWalletAdapter } from '../wallet-connect-adapter'; interface ConnectAsync { - promise: Promise; - resolve: () => void; + promise: Promise; + resolve: (account?: Account) => void; reject: (reason: any) => void; } @@ -70,7 +70,7 @@ export const AntDesignWeb3ConfigProvider: React.FC< } if (connected) { - connectAsyncRef.current.resolve(); + connectAsyncRef.current.resolve({ address: publicKey!.toBase58() }); connectAsyncRef.current = undefined; } }, [connected]); @@ -172,6 +172,7 @@ export const AntDesignWeb3ConfigProvider: React.FC< name: adapter.name, icon: adapter.icon, remark: adapter.name, + _standardWallet: adapter, hasExtensionInstalled: async () => { return adapter.readyState === WalletReadyState.Installed; @@ -223,7 +224,7 @@ export const AntDesignWeb3ConfigProvider: React.FC< selectWallet(null); } - const promise = new Promise((res, rej) => { + const promise = new Promise((res, rej) => { resolve = res; reject = rej; }); diff --git a/packages/sui/src/sui-provider/config-provider.tsx b/packages/sui/src/sui-provider/config-provider.tsx index d143432f3..69338d17c 100644 --- a/packages/sui/src/sui-provider/config-provider.tsx +++ b/packages/sui/src/sui-provider/config-provider.tsx @@ -140,7 +140,12 @@ export const AntDesignWeb3ConfigProvider: React.FC< throw new Error(`Can not find wallet ${wallet?.name}`); } - await connectAsync({ wallet: foundWallet }); + const { accounts } = await connectAsync({ wallet: foundWallet }); + const connectedAccount = accounts[0]; + + return { + address: connectedAccount.address, + }; }} disconnect={async () => { await disconnectAsync(); diff --git a/packages/web3/src/solana/demos/balance.tsx b/packages/web3/src/solana/demos/balance.tsx index aafc6bebd..24925f249 100644 --- a/packages/web3/src/solana/demos/balance.tsx +++ b/packages/web3/src/solana/demos/balance.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { ConnectButton, Connector } from '@ant-design/web3'; import { CoinbaseWallet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana'; diff --git a/packages/web3/src/solana/demos/basic.tsx b/packages/web3/src/solana/demos/basic.tsx index b987c32ef..bb5ef7d60 100644 --- a/packages/web3/src/solana/demos/basic.tsx +++ b/packages/web3/src/solana/demos/basic.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { ConnectButton, Connector } from '@ant-design/web3'; import { CoinbaseWallet, PhantomWallet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana'; diff --git a/packages/web3/src/solana/demos/more-components.tsx b/packages/web3/src/solana/demos/more-components.tsx index 3bdfaa53f..f834afbba 100644 --- a/packages/web3/src/solana/demos/more-components.tsx +++ b/packages/web3/src/solana/demos/more-components.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { Address, BrowserLink, NFTCard } from '@ant-design/web3'; import { CoinbaseWallet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana'; import { Space } from 'antd'; diff --git a/packages/web3/src/solana/demos/more-wallets.tsx b/packages/web3/src/solana/demos/more-wallets.tsx index b987c32ef..bb5ef7d60 100644 --- a/packages/web3/src/solana/demos/more-wallets.tsx +++ b/packages/web3/src/solana/demos/more-wallets.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { ConnectButton, Connector } from '@ant-design/web3'; import { CoinbaseWallet, PhantomWallet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana'; diff --git a/packages/web3/src/solana/demos/networks.tsx b/packages/web3/src/solana/demos/networks.tsx index 61c5aee02..c08de880e 100644 --- a/packages/web3/src/solana/demos/networks.tsx +++ b/packages/web3/src/solana/demos/networks.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { ConnectButton, Connector } from '@ant-design/web3'; import { CoinbaseWallet, diff --git a/packages/web3/src/solana/demos/sign-message.tsx b/packages/web3/src/solana/demos/sign-message.tsx index 4d1ad55b8..323c4ce6b 100644 --- a/packages/web3/src/solana/demos/sign-message.tsx +++ b/packages/web3/src/solana/demos/sign-message.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { ConnectButton, Connector } from '@ant-design/web3'; import { PhantomWallet, diff --git a/packages/web3/src/solana/demos/wallet-connect.tsx b/packages/web3/src/solana/demos/wallet-connect.tsx index 8a93cc8bb..391bfd89c 100644 --- a/packages/web3/src/solana/demos/wallet-connect.tsx +++ b/packages/web3/src/solana/demos/wallet-connect.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { ConnectButton, Connector } from '@ant-design/web3'; import { PhantomWallet,