Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support Sui #1024

Merged
merged 50 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
4e8967f
feat: add Sui adapter
gin-lsl Jul 8, 2024
5dc7cea
chore: update dep
gin-lsl Jul 8, 2024
d0a9943
chore: changeset
gin-lsl Jul 8, 2024
18f795b
chore: fix dep
gin-lsl Jul 9, 2024
3df4c98
fix: remove unused code
gin-lsl Jul 9, 2024
f5c1e48
chore: dep
gin-lsl Jul 9, 2024
3097634
fix: deps
gin-lsl Jul 9, 2024
a65007e
feat: improve props
gin-lsl Jul 9, 2024
933666a
docs: update demos
gin-lsl Jul 9, 2024
c534bbb
chore: update deps
gin-lsl Jul 9, 2024
045814f
docs(sui): Readme
gin-lsl Jul 11, 2024
35e58dc
add tests
gin-lsl Jul 11, 2024
a920331
feat: merge queryClient
gin-lsl Jul 11, 2024
32d9eb8
udpate demos
gin-lsl Jul 11, 2024
ad6f138
typo
gin-lsl Jul 11, 2024
37170b7
docs: update
gin-lsl Jul 11, 2024
1eb8164
rename
gin-lsl Jul 11, 2024
5446054
Update
gin-lsl Jul 11, 2024
9237865
add test cases
gin-lsl Jul 11, 2024
d4a7eee
add test of queryclient
gin-lsl Jul 12, 2024
29e856c
test
gin-lsl Jul 12, 2024
8e195b3
docs: add queryClient demo
gin-lsl Jul 12, 2024
ff09469
docs: api doc
gin-lsl Jul 12, 2024
a14dd1a
en doc
gin-lsl Jul 12, 2024
6279456
feat(assets): add sui wallet metadata
gin-lsl Jul 12, 2024
b69d9fb
feat: support wallets prop
gin-lsl Jul 12, 2024
99cb60d
Update packages/web3/src/sui/index.md
gin-lsl Jul 12, 2024
bbcf36d
Merge branch 'main' into feat/sui-adapter
gin-lsl Jul 12, 2024
baaf3b8
fix: update browser link
gin-lsl Jul 12, 2024
b28546d
cointype
gin-lsl Jul 13, 2024
a8d7053
Merge branch 'main' into feat/sui-adapter
gin-lsl Jul 15, 2024
b52e4ff
Merge remote-tracking branch 'origin/main' into feat/sui-adapter
gin-lsl Jul 26, 2024
b8a376d
chore: update lock
gin-lsl Jul 26, 2024
c7bf499
Merge branch 'main' into feat/sui-adapter
gin-lsl Jul 26, 2024
ad0bb0c
add Suiet wallet metadata
gin-lsl Jul 26, 2024
a28165b
Merge remote-tracking branch 'origin/main' into feat/sui-adapter
gin-lsl Jul 31, 2024
6b8bb89
merge master
gin-lsl Jul 31, 2024
1a48fd2
feat: add sui token
gin-lsl Jul 31, 2024
34793eb
refactor: use SUI token
gin-lsl Jul 31, 2024
00797f9
chore: replace @mysten/sui with @mysten/sui.js
gin-lsl Aug 5, 2024
75e9438
Merge remote-tracking branch 'origin/main' into feat/sui-adapter
gin-lsl Aug 5, 2024
0f6fd15
fix lock file
gin-lsl Aug 5, 2024
a2ef502
Merge remote-tracking branch 'origin/main' into feat/sui-adapter
gin-lsl Aug 10, 2024
6453853
improve wallet connect
gin-lsl Aug 10, 2024
b8549e5
update lock
gin-lsl Aug 10, 2024
fe7cf87
Merge remote-tracking branch 'origin/main' into feat/sui-adapter
gin-lsl Aug 21, 2024
13556ba
merge package
gin-lsl Aug 21, 2024
daf7d54
chore: update lock file
gin-lsl Aug 21, 2024
fe7cef0
Merge remote-tracking branch 'origin/main' into feat/sui-adapter
gin-lsl Aug 22, 2024
0c6f080
chore: update lock
gin-lsl Aug 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/hip-comics-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ant-design/web3-sui': major
'@ant-design/web3-common': minor
---

feat: Add Sui adapter
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,15 @@
"@ant-design/web3-ethers": "workspace:*",
"@ant-design/web3-icons": "workspace:*",
"@ant-design/web3-solana": "workspace:*",
"@ant-design/web3-sui": "workspace:*",
"@ant-design/web3-ton": "workspace:*",
"@ant-design/web3-wagmi": "workspace:*",
"@mysten/dapp-kit": "^0.14.11",
"@mysten/sui": "^1.4.0",
"@solana/wallet-adapter-coinbase": "^0.1.19",
"@solana/wallet-adapter-trust": "^0.1.13",
"@tanstack/query-sync-storage-persister": "^5.51.9",
"@tanstack/react-query-persist-client": "^5.51.11",
"@tanstack/react-query": "^5.51.11",
"antd": "^5.20.1",
"antd-style": "^3.6.2",
Expand Down
1 change: 1 addition & 0 deletions packages/assets/src/tokens/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './eth';
export * from './usdc';
export * from './usdt';
export * from './sui';
10 changes: 10 additions & 0 deletions packages/assets/src/tokens/sui.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Token } from '@ant-design/web3-common';
import { SuiColorful } from '@ant-design/web3-icons';

export const SUI: Token = {
name: 'Sui',
symbol: 'SUI',
decimal: 9,
icon: <SuiColorful />,
availableChains: [],
};
2 changes: 2 additions & 0 deletions packages/assets/src/wallets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export * from './unisat-wallet';
export * from './backpack';
export * from './trust';
export * from './mobile-wallet';
export * from './sui-wallet';
export * from './suiet';
20 changes: 20 additions & 0 deletions packages/assets/src/wallets/sui-wallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { WalletMetadata } from '@ant-design/web3-common';
import { ChromeCircleColorful, SuiColorful } from '@ant-design/web3-icons';

export const metadata_SuiWallet: WalletMetadata = {
name: 'Sui Wallet',
remark: 'Sui Wallet',
icon: <SuiColorful />,
app: {
link: 'https://suiwallet.com/',
},
extensions: [
{
key: 'Chrome',
browserIcon: <ChromeCircleColorful />,
browserName: 'Chrome',
link: 'https://chromewebstore.google.com/detail/sui-wallet/opcgpfmipidbgpenhmajoajpbobppdil',
description: 'Access your wallet right from your favorite web browser.',
},
],
};
20 changes: 20 additions & 0 deletions packages/assets/src/wallets/suiet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { WalletMetadata } from '@ant-design/web3-common';
import { ChromeCircleColorful, SuietColorful } from '@ant-design/web3-icons';

export const metadata_Suiet: WalletMetadata = {
name: 'Suiet',
remark: 'Suiet Wallet',
icon: <SuietColorful />,
app: {
link: 'https://suiet.app/',
},
extensions: [
{
key: 'Chrome',
browserIcon: <ChromeCircleColorful />,
browserName: 'Chrome',
link: 'https://chromewebstore.google.com/detail/suiet-sui-wallet/khpkpbbcccdmmclmpigdgddabeilkdpd',
description: 'Access your wallet right from your favorite web browser.',
},
],
};
15 changes: 14 additions & 1 deletion packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export enum SolanaChainIds {
Testnet = 4,
}

export enum SuiChainIds {
gin-lsl marked this conversation as resolved.
Show resolved Hide resolved
Mainnet = 1,
Testnet = 2,
Devnet = 3,
Localnet = 4,
}

export type BrowserLinkType = 'address' | 'transaction';

export type BalanceMetadata = {
Expand All @@ -50,6 +57,11 @@ export enum ChainType {
* Bitcoin chain
*/
Bitcoin = 'Bitcoin',

/**
* Sui chain
*/
Sui = 'Sui',
}

export interface Chain {
Expand All @@ -71,7 +83,7 @@ export interface NFTMetadata {
description?: string;
image?: string;
dna?: string;
edition?: number;
edition?: string | number;
date?: number;
attributes?: {
trait_type?: string;
Expand Down Expand Up @@ -109,6 +121,7 @@ export interface UniversalWeb3ProviderInterface {
}

export interface Wallet extends WalletMetadata {
_standardWallet?: any;
hasWalletReady?: () => Promise<boolean>;
hasExtensionInstalled?: () => Promise<boolean>;
getQrCode?: () => Promise<{ uri: string }>;
Expand Down
5 changes: 5 additions & 0 deletions packages/sui/.fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'father';

export default defineConfig({
extends: '../../.fatherrc.base.ts',
});
35 changes: 35 additions & 0 deletions packages/sui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# @ant-design/web3-solana
gin-lsl marked this conversation as resolved.
Show resolved Hide resolved

This package provides a [Sui](https://sui.io) adapter for [@ant-design/web3](https://www.npmjs.com/package/@ant-design/web3).

## Installation

```bash
npm install @ant-design/web3 @ant-design/web3-sui --save
```

## Usage

```tsx
import { ConnectButton, Connector } from '@ant-design/web3';
import { SuiWallet, SuiWeb3ConfigProvider } from '@ant-design/web3-sui';

const App: React.FC = () => {
return (
<SuiWeb3ConfigProvider>
<Connector>
<ConnectButton />
</Connector>
</SuiWeb3ConfigProvider>
);
};

export default App;
```

For more examples, refer to [Sui - Ant Design Web3](https://web3.ant.design/components/sui).

## Documentation

- For more information, visit [Ant Design Web3](https://web3.ant.design).
- For an introduction to Sui, visit [Sui](https://sui.io).
71 changes: 71 additions & 0 deletions packages/sui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"name": "@ant-design/web3-sui",
"version": "0.0.0",
"main": "dist/lib/index.js",
"module": "dist/esm/index.js",
"typings": "dist/esm/index.d.ts",
"exports": {
"import": "./dist/esm/index.js",
"require": "./dist/lib/index.js",
"types": "./dist/esm/index.d.ts"
},
"sideEffects": false,
"files": [
"dist",
"CHANGELOG.md",
"README.md"
],
"keywords": [
"ant",
"component",
"components",
"design",
"framework",
"frontend",
"react",
"react-component",
"ui",
"web3",
"sui"
],
"homepage": "https://web3.ant.design",
"bugs": {
"url": "https://github.com/ant-design/ant-design-web3/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/ant-design/ant-design-web3"
},
"scripts": {
"dev": "father dev",
"build": "father build"
},
"dependencies": {
"@ant-design/web3-assets": "workspace:*",
"@ant-design/web3-common": "workspace:*",
"debug": "^4.3.4"
},
"devDependencies": {
"@mysten/dapp-kit": "^0.14.11",
"@mysten/sui": "^1.4.0",
"@tanstack/react-query": "^5.40.1",
"@types/debug": "^4.1.12",
"father": "^4.4.4",
"typescript": "^5.5.2"
},
"peerDependencies": {
"@mysten/dapp-kit": "^0.14.11",
"@mysten/sui": "^1.4.0",
"@tanstack/react-query": "^5.40.1"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
},
"browserslist": [
"last 2 versions",
"Firefox ESR",
"> 1%",
"ie >= 11"
]
}
57 changes: 57 additions & 0 deletions packages/sui/src/chain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import type { Chain } from '@ant-design/web3-common';
import { createGetBrowserLink, SuiChainIds } from '@ant-design/web3-common';
import { SuiColorful } from '@ant-design/web3-icons';
import { SUI_DECIMALS } from '@mysten/sui/utils';

export interface SuiChain extends Chain {
id: SuiChainIds;
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
}

export const suiMainnet: SuiChain = {
id: SuiChainIds.Mainnet,
name: 'Sui',
network: 'mainnet',
icon: <SuiColorful />,
browser: {
icon: <SuiColorful />,
getBrowserLink: createGetBrowserLink('https://suiscan.xyz/mainnet'),
},
nativeCurrency: { name: 'Sui', symbol: 'SUI', decimals: SUI_DECIMALS },
};

export const suiTestnet: SuiChain = {
id: SuiChainIds.Testnet,
name: 'Sui Testnet',
network: 'testnet',
icon: <SuiColorful />,
browser: {
icon: <SuiColorful />,
getBrowserLink: createGetBrowserLink('https://suiscan.xyz/testnet'),
},
nativeCurrency: { name: 'Sui', symbol: 'SUI', decimals: SUI_DECIMALS },
};

export const suiDevnet: SuiChain = {
id: SuiChainIds.Devnet,
name: 'Sui Devnet',
network: 'devnet',
icon: <SuiColorful />,
browser: {
icon: <SuiColorful />,
getBrowserLink: createGetBrowserLink('https://suiscan.xyz/devnet'),
},
nativeCurrency: { name: 'Sui', symbol: 'SUI', decimals: SUI_DECIMALS },
};

export const suiLocalnet: SuiChain = {
id: SuiChainIds.Localnet,
name: 'Sui Localnet',
network: 'localnet',
icon: <SuiColorful />,
browser: {
icon: <SuiColorful />,
},
nativeCurrency: { name: 'Sui', symbol: 'SUI', decimals: SUI_DECIMALS },
};
4 changes: 4 additions & 0 deletions packages/sui/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './chain';
export * from './sui-provider';
export * from './wallets/built-in';
export * from './wallets/factory';
84 changes: 84 additions & 0 deletions packages/sui/src/sui-provider/__tests__/account.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react';
import { ConnectButton, Connector } from '@ant-design/web3';
import { fireEvent } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';

import { SuiWeb3ConfigProvider } from '../../';
import { xrender } from './utils';

describe('SuiWeb3ConfigProvider basic tests', () => {
const mockedDatas = vi.hoisted(() => {
return {
// fake address
shortAddress: '0xa123...y123',
address: '0xa123a123b123b123____a00aaf10c9c283aae9498684218____x123x123y123y123',
sns: 'fakesns.sui',
};
});

vi.mock('@mysten/dapp-kit', async () => {
const originModules = await vi.importActual('@mysten/dapp-kit');

return {
...originModules,
useCurrentAccount: () => {
return {
address: mockedDatas.address,
};
},
useResolveSuiNSName: (address?: string) => {
const sns = address ? mockedDatas.sns : undefined;

return { data: sns };
},
};
});

it('available get account info', async () => {
const App = () => {
return (
<SuiWeb3ConfigProvider>
<Connector>
<ConnectButton />
</Connector>
</SuiWeb3ConfigProvider>
);
};

const { selector } = xrender(App);

const connectBtn = selector('.ant-web3-connect-button');

expect(connectBtn?.textContent).toBe(mockedDatas.shortAddress);
fireEvent.click(connectBtn!);

await vi.waitFor(() => {
const addressInfo = selector('.ant-web3-connect-button-profile-modal .ant-web3-address');
expect(addressInfo?.textContent).toBe(mockedDatas.address);
});
});

it('available get sns info', async () => {
const App = () => {
return (
<SuiWeb3ConfigProvider sns>
<Connector>
<ConnectButton />
</Connector>
</SuiWeb3ConfigProvider>
);
};

const { selector } = xrender(App);

const connectBtn = selector('.ant-web3-connect-button');

expect(connectBtn?.textContent).toBe(mockedDatas.sns);
fireEvent.click(connectBtn!);

await vi.waitFor(() => {
const addressInfo = selector('.ant-web3-connect-button-profile-modal .ant-web3-address');
expect(addressInfo?.textContent).toBe(mockedDatas.address);
});
});
});
Loading
Loading