Skip to content

Commit 0f9aff6

Browse files
authored
Merge pull request #133 from suiet/feat/docs
Feat/docs
2 parents d885b2b + 62e30af commit 0f9aff6

20 files changed

+438
-210
lines changed

packages/kit/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@suiet/wallet-kit",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"type": "module",
55
"files": [
66
"dist"

packages/kit/src/components/WalletProvider.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {useCallback, useEffect, useMemo, useRef, useState} from "react";
22
import {WalletContext} from "../hooks";
33
import type {
4-
ConnectInput,
4+
StandardConnectInput,
55
SuiSignAndExecuteTransactionBlockInput,
66
SuiSignTransactionBlockInput,
77
WalletAccount,
@@ -76,7 +76,7 @@ export const WalletProvider = (props: WalletProviderProps) => {
7676
};
7777

7878
const connect = useCallback(
79-
async (adapter: IWalletAdapter, opts?: ConnectInput) => {
79+
async (adapter: IWalletAdapter, opts?: StandardConnectInput) => {
8080
if (!adapter) throw new KitError("param adapter is missing");
8181

8282
setStatus(ConnectionStatus.CONNECTING);
@@ -238,7 +238,7 @@ export const WalletProvider = (props: WalletProviderProps) => {
238238
[walletAdapter, account, status]
239239
);
240240

241-
useAutoConnect(select, allAvailableWallets, autoConnect)
241+
useAutoConnect(select, status, allAvailableWallets, autoConnect)
242242

243243
// sync kit's chain with wallet's active chain
244244
useEffect(() => {

packages/kit/src/hooks/useAutoConnect.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {useEffect, useRef} from "react";
22
import {isNonEmptyArray} from "../utils";
3-
import {IWallet} from "../types";
3+
import {ConnectionStatus, IWallet} from "../types";
44
import {Storage} from "../utils/storage";
55
import {StorageKey} from "../constants/storage";
66

77
export function useAutoConnect(
88
select: (name: string) => Promise<void>,
9+
status: ConnectionStatus,
910
allAvailableWallets: IWallet[],
1011
autoConnect: boolean,
1112
) {
@@ -15,14 +16,16 @@ export function useAutoConnect(
1516
useEffect(() => {
1617
if (!autoConnect ||
1718
init.current ||
18-
!isNonEmptyArray(allAvailableWallets)
19+
!isNonEmptyArray(allAvailableWallets) ||
20+
status !== ConnectionStatus.DISCONNECTED
1921
) return
2022

2123
const storage = new Storage()
2224
const lastConnectedWalletName = storage.getItem(StorageKey.LAST_CONNECT_WALLET_NAME)
2325
if (!lastConnectedWalletName) return
2426

2527
if (allAvailableWallets.find(item => item.name == lastConnectedWalletName)) {
28+
console.log('auto connect to wallet:', lastConnectedWalletName)
2629
select(lastConnectedWalletName)
2730
.then(() => {
2831
init.current = true

packages/kit/src/utils/check.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export function isNonEmptyArray(value: any): boolean {
77
export function isStandardWalletAdapterCompatibleWallet(
88
wallet: Wallet
99
): wallet is StandardWalletAdapterWallet {
10-
console.log('filter wallet', wallet)
1110
return (
1211
"standard:connect" in wallet.features &&
1312
"standard:events" in wallet.features &&

packages/kit/src/wallet-standard/useWalletDetection.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function useWalletAdapterDetection() {
2424
useEffect(() => {
2525
standardWalletManager.current = getWallets();
2626
const initWalletAdapters = getInitStandardWalletAdapters();
27-
console.log('initWalletAdapters', initWalletAdapters)
27+
// console.log('initWalletAdapters', initWalletAdapters)
2828

2929
if (isNonEmptyArray(initWalletAdapters)) {
3030
setAvailableWalletAdapters(initWalletAdapters
@@ -33,7 +33,7 @@ export function useWalletAdapterDetection() {
3333
}
3434

3535
const clearListeners = standardWalletManager.current.on('register', (...newAdapters: Wallet[]) => {
36-
console.log('register newAdapters', newAdapters)
36+
// console.log('register newAdapters', newAdapters)
3737
if (!standardWalletManager.current) return;
3838
const initWalletAdapters = getInitStandardWalletAdapters();
3939
const allAdapters = [...initWalletAdapters]

packages/kit/vite.config.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import viteSvgr from 'vite-plugin-svgr';
55
import path from 'path';
66

77
// https://vitejs.dev/config/
8-
export default defineConfig({
8+
export default defineConfig(({mode}) => ({
99
plugins: [react(), vanillaExtractPlugin(), viteSvgr()],
1010
css: {
1111
modules: {
1212
localsConvention: 'camelCase',
1313
},
1414
},
1515
esbuild: {
16-
target: "es2020"
16+
target: "es2020",
17+
pure: mode === 'production' ? ['console.log', 'debugger'] : [],
1718
},
1819
optimizeDeps: {
1920
esbuildOptions : {
@@ -41,4 +42,4 @@ export default defineConfig({
4142
},
4243
},
4344
},
44-
});
45+
}));

packages/sdk/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@suiet/wallet-sdk",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"license": "MIT",
55
"type": "module",
66
"scripts": {

pnpm-lock.yaml

+2-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/docs/CanIUse.md

+78-8
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,86 @@ These preset wallets will be displayed as `Popular` on our kit modal by default.
1919
- [OneKey Wallet](https://chrome.google.com/webstore/detail/onekey/jnmbobjmhlngoefaiojfljckilhhlhcj)
2020
- [BitKeep Wallet](https://chrome.google.com/webstore/detail/bitkeep-crypto-nft-wallet/jiidiaalihmmhddjgbnbgdfflelocpak/related)
2121

22-
## Can I Use with xxx Wallet?
22+
## For Dapp Developers
23+
24+
### Can I Use with xxx Wallet?
2325

2426
Due to the adapter difference of each wallet, we present a function comparison table among wallet adapters.
2527

26-
> ⚠️ Remember to handle exceptional cases if some wallet adapters do not support certain features.
28+
:::info
29+
Due to the presense of new [@mysten/wallet-standard (v0.5.0)](https://github.com/MystenLabs/sui/tree/main/sdk/wallet-adapter/wallet-standard),
30+
we are working on updating the statistics. Please stay tuned 🥳
31+
:::
32+
33+
:::tip
34+
Remember to handle exceptional cases if some wallet adapters do not support certain features.
35+
:::
36+
37+
[//]: # (### Hook `useWallet`)
38+
39+
[//]: # ()
40+
[//]: # (|wallet|name|connected|connecting|select|disconnect|getAccounts|executeMoveCall|signAndExecuteTransaction|getPublicKey|signMessage|on&#40;'chainChange'&#41;|chain|)
41+
42+
[//]: # (|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|---|---|---|---|---|)
43+
44+
[//]: # (|[Suiet Wallet]&#40;https://suiet.app/&#41;|✅|✅|✅|✅|✅|✅|✅|✅|✅|✅|✅|✅|)
45+
46+
[//]: # (|[Sui Wallet]&#40;https://chrome.google.com/webstore/detail/sui-wallet/opcgpfmipidbgpenhmajoajpbobppdil&#41;|✅|✅|✅|✅|✅|✅|✅|✅|❌|❌|❌|❌|)
47+
48+
[//]: # (|[Ethos Wallet]&#40;https://ethoswallet.xyz/&#41;|✅|✅|✅|✅|✅|✅|✅|✅|❌|❌|❌|❌|)
49+
50+
51+
## For Wallet Developers
52+
53+
### How to integrate with Suiet Kit?
54+
55+
Please make sure your wallet supports the [@mysten/wallet-standard](https://github.com/MystenLabs/sui/tree/main/sdk/wallet-adapter/wallet-standard) v0.5.0 and above.
56+
57+
Specifically, in order to be auto-detected and recognized as a standard wallet on Sui by our kit,
58+
you need to implement the following features in your wallet adapter:
59+
60+
```js
61+
// a valid wallet adapter should have the following features
62+
{
63+
// ...
64+
features: {
65+
"standard:connect": () => {},
66+
"standard:events": () => {},
67+
"sui:signAndExecuteTransactionBlock": () => {},
68+
}
69+
}
70+
```
71+
72+
### How to list my wallet on Suiet Kit?
73+
74+
You can contact our team via [Twitter@suiet_wallet](https://twitter.com/suiet_wallet) to list your wallet on Suiet Kit.
75+
76+
Or submit a PR to our [repo](https://github.com/suiet/wallet-kit/pulls), modify the following files:
77+
78+
```ts
79+
// packages/kit/src/wallet/preset-wallets/presets.ts
80+
export enum PresetWallet {
81+
// ... resgisted wallet enum
82+
// note that this name should match with your wallet adapter's name
83+
// for auto detection and display purposes
84+
YOUR_WALLET = "Your Wallet",
85+
}
2786

28-
### Hook `useWallet`
87+
export const YourWallet = defineWallet({
88+
name: PresetWallet.YOUR_WALLET,
89+
iconUrl: 'base64 encoded image (recommended, optimize the size!!) / external url',
90+
downloadUrl: {
91+
browserExtension: 'chrome extension installation url',
92+
}
93+
})
94+
```
2995

30-
|wallet|name|connected|connecting|select|disconnect|getAccounts|executeMoveCall|signAndExecuteTransaction|getPublicKey|signMessage|on('chainChange')|chain|
31-
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|---|---|---|---|---|
32-
|[Suiet Wallet](https://suiet.app/)|||||||||||||
33-
|[Sui Wallet](https://chrome.google.com/webstore/detail/sui-wallet/opcgpfmipidbgpenhmajoajpbobppdil)|||||||||||||
34-
|[Ethos Wallet](https://ethoswallet.xyz/)|||||||||||||
96+
```ts
97+
// packages/kit/src/wallet/preset-wallets/index.ts
98+
export const AllDefaultWallets = [
99+
...[
100+
// ... registed wallets
101+
presets.YourWallet,
102+
].sort((a, b) => a.name < b.name ? -1 : 1),
103+
]
104+
```

0 commit comments

Comments
 (0)