Skip to content

Commit

Permalink
fix(sui,solana): Should return address after connect (#1135)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gin-lsl authored Sep 9, 2024
1 parent c22eb4d commit 1091cfd
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/healthy-spies-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ant-design/web3-solana': patch
'@ant-design/web3-sui': patch
---

fix(sui,solana): Should return address after connect
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -228,6 +230,7 @@ describe('Solana Connect', () => {
() => {
expect(connectRunned).toBeCalled();
expect(shownConnectRunDone.textContent).toBe('true');
expect(gotAddressAfterConnect).toBeCalledWith(mockedData.address.value);
},
{
timeout: 5000,
Expand Down
9 changes: 5 additions & 4 deletions packages/solana/src/solana-provider/config-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { hasWalletReady } from '../utils';
import { WalletConnectWalletAdapter } from '../wallet-connect-adapter';

interface ConnectAsync {
promise: Promise<void>;
resolve: () => void;
promise: Promise<Account>;
resolve: (account?: Account) => void;
reject: (reason: any) => void;
}

Expand Down Expand Up @@ -70,7 +70,7 @@ export const AntDesignWeb3ConfigProvider: React.FC<
}

if (connected) {
connectAsyncRef.current.resolve();
connectAsyncRef.current.resolve({ address: publicKey!.toBase58() });
connectAsyncRef.current = undefined;
}
}, [connected]);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -223,7 +224,7 @@ export const AntDesignWeb3ConfigProvider: React.FC<
selectWallet(null);
}

const promise = new Promise<void>((res, rej) => {
const promise = new Promise<Account>((res, rej) => {
resolve = res;
reject = rej;
});
Expand Down
7 changes: 6 additions & 1 deletion packages/sui/src/sui-provider/config-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions packages/web3/src/solana/demos/balance.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { ConnectButton, Connector } from '@ant-design/web3';
import { CoinbaseWallet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana';

Expand Down
1 change: 1 addition & 0 deletions packages/web3/src/solana/demos/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { ConnectButton, Connector } from '@ant-design/web3';
import { CoinbaseWallet, PhantomWallet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana';

Expand Down
1 change: 1 addition & 0 deletions packages/web3/src/solana/demos/more-components.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions packages/web3/src/solana/demos/more-wallets.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { ConnectButton, Connector } from '@ant-design/web3';
import { CoinbaseWallet, PhantomWallet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana';

Expand Down
1 change: 1 addition & 0 deletions packages/web3/src/solana/demos/networks.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { ConnectButton, Connector } from '@ant-design/web3';
import {
CoinbaseWallet,
Expand Down
1 change: 1 addition & 0 deletions packages/web3/src/solana/demos/sign-message.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { ConnectButton, Connector } from '@ant-design/web3';
import {
PhantomWallet,
Expand Down
1 change: 1 addition & 0 deletions packages/web3/src/solana/demos/wallet-connect.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { ConnectButton, Connector } from '@ant-design/web3';
import {
PhantomWallet,
Expand Down

0 comments on commit 1091cfd

Please sign in to comment.