Skip to content

Commit 1091cfd

Browse files
authored
fix(sui,solana): Should return address after connect (#1135)
* fix(solana): Should return address after connect * site: import react in demos * fix(sui): Should return address after connect * chore: rename * changeset * fix test case
1 parent c22eb4d commit 1091cfd

File tree

11 files changed

+28
-6
lines changed

11 files changed

+28
-6
lines changed

.changeset/healthy-spies-smash.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@ant-design/web3-solana': patch
3+
'@ant-design/web3-sui': patch
4+
---
5+
6+
fix(sui,solana): Should return address after connect

packages/solana/src/solana-provider/__tests__/connect.test.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ describe('Solana Connect', () => {
149149
const { useWallet } = await import('@solana/wallet-adapter-react');
150150
const switchWalletRunned = vi.fn();
151151
const connectRunned = vi.fn();
152+
const gotAddressAfterConnect = vi.fn();
152153

153154
const CustomConnectBtn: React.FC = () => {
154155
const { connect, availableWallets } = useProvider();
@@ -172,7 +173,8 @@ describe('Solana Connect', () => {
172173
await connectWallet();
173174
// mock connect twice
174175
connect?.(availableWallets?.[1]);
175-
await connect?.(availableWallets?.[0]);
176+
const connectedAddress = await connect?.(availableWallets?.[0]);
177+
gotAddressAfterConnect(connectedAddress?.address);
176178
await connect?.(availableWallets?.[2]);
177179

178180
connectRunned();
@@ -228,6 +230,7 @@ describe('Solana Connect', () => {
228230
() => {
229231
expect(connectRunned).toBeCalled();
230232
expect(shownConnectRunDone.textContent).toBe('true');
233+
expect(gotAddressAfterConnect).toBeCalledWith(mockedData.address.value);
231234
},
232235
{
233236
timeout: 5000,

packages/solana/src/solana-provider/config-provider.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { hasWalletReady } from '../utils';
1414
import { WalletConnectWalletAdapter } from '../wallet-connect-adapter';
1515

1616
interface ConnectAsync {
17-
promise: Promise<void>;
18-
resolve: () => void;
17+
promise: Promise<Account>;
18+
resolve: (account?: Account) => void;
1919
reject: (reason: any) => void;
2020
}
2121

@@ -70,7 +70,7 @@ export const AntDesignWeb3ConfigProvider: React.FC<
7070
}
7171

7272
if (connected) {
73-
connectAsyncRef.current.resolve();
73+
connectAsyncRef.current.resolve({ address: publicKey!.toBase58() });
7474
connectAsyncRef.current = undefined;
7575
}
7676
}, [connected]);
@@ -172,6 +172,7 @@ export const AntDesignWeb3ConfigProvider: React.FC<
172172
name: adapter.name,
173173
icon: adapter.icon,
174174
remark: adapter.name,
175+
_standardWallet: adapter,
175176

176177
hasExtensionInstalled: async () => {
177178
return adapter.readyState === WalletReadyState.Installed;
@@ -223,7 +224,7 @@ export const AntDesignWeb3ConfigProvider: React.FC<
223224
selectWallet(null);
224225
}
225226

226-
const promise = new Promise<void>((res, rej) => {
227+
const promise = new Promise<Account>((res, rej) => {
227228
resolve = res;
228229
reject = rej;
229230
});

packages/sui/src/sui-provider/config-provider.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ export const AntDesignWeb3ConfigProvider: React.FC<
140140
throw new Error(`Can not find wallet ${wallet?.name}`);
141141
}
142142

143-
await connectAsync({ wallet: foundWallet });
143+
const { accounts } = await connectAsync({ wallet: foundWallet });
144+
const connectedAccount = accounts[0];
145+
146+
return {
147+
address: connectedAccount.address,
148+
};
144149
}}
145150
disconnect={async () => {
146151
await disconnectAsync();

packages/web3/src/solana/demos/balance.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react';
12
import { ConnectButton, Connector } from '@ant-design/web3';
23
import { CoinbaseWallet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana';
34

packages/web3/src/solana/demos/basic.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react';
12
import { ConnectButton, Connector } from '@ant-design/web3';
23
import { CoinbaseWallet, PhantomWallet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana';
34

packages/web3/src/solana/demos/more-components.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react';
12
import { Address, BrowserLink, NFTCard } from '@ant-design/web3';
23
import { CoinbaseWallet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana';
34
import { Space } from 'antd';

packages/web3/src/solana/demos/more-wallets.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react';
12
import { ConnectButton, Connector } from '@ant-design/web3';
23
import { CoinbaseWallet, PhantomWallet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana';
34

packages/web3/src/solana/demos/networks.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react';
12
import { ConnectButton, Connector } from '@ant-design/web3';
23
import {
34
CoinbaseWallet,

packages/web3/src/solana/demos/sign-message.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react';
12
import { ConnectButton, Connector } from '@ant-design/web3';
23
import {
34
PhantomWallet,

packages/web3/src/solana/demos/wallet-connect.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react';
12
import { ConnectButton, Connector } from '@ant-design/web3';
23
import {
34
PhantomWallet,

0 commit comments

Comments
 (0)