@sodax/wallet-sdk-react 1.4.4-beta → 1.5.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sodax/wallet-sdk-react",
3
3
  "license": "MIT",
4
- "version": "1.4.4-beta",
4
+ "version": "1.5.0-beta",
5
5
  "description": "Wallet SDK of Sodax",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
@@ -51,8 +51,8 @@
51
51
  "wagmi": "2.16.9",
52
52
  "zustand": "4.5.2",
53
53
  "bs58": "6.0.0",
54
- "@sodax/types": "1.4.4-beta",
55
- "@sodax/wallet-sdk-core": "1.4.4-beta"
54
+ "@sodax/wallet-sdk-core": "1.5.0-beta",
55
+ "@sodax/types": "1.5.0-beta"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/react": "^19.0.8",
@@ -27,20 +27,57 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
27
27
 
28
28
  const queryClient = new QueryClient();
29
29
 
30
- export const SodaxWalletProvider = ({ children, rpcConfig }: { children: React.ReactNode; rpcConfig: RpcConfig }) => {
30
+ export type WagmiOptions = {
31
+ reconnectOnMount?: boolean;
32
+ ssr?: boolean;
33
+ };
34
+
35
+ export type SodaxWalletProviderOptions = {
36
+ wagmi?: WagmiOptions;
37
+ solana?: {
38
+ autoConnect?: boolean;
39
+ };
40
+ sui?: {
41
+ autoConnect?: boolean;
42
+ };
43
+ };
44
+
45
+ const defaultOptions = {
46
+ wagmi: {
47
+ reconnectOnMount: false,
48
+ ssr: true,
49
+ },
50
+ solana: {
51
+ autoConnect: true,
52
+ },
53
+ sui: {
54
+ autoConnect: true,
55
+ },
56
+ } satisfies SodaxWalletProviderOptions;
57
+
58
+ export type SodaxWalletProviderProps = {
59
+ children: React.ReactNode;
60
+ rpcConfig: RpcConfig;
61
+ options?: SodaxWalletProviderOptions;
62
+ };
63
+
64
+ export const SodaxWalletProvider = ({ children, rpcConfig, options }: SodaxWalletProviderProps) => {
65
+ const wagmi = useMemo(() => ({ ...defaultOptions.wagmi, ...options?.wagmi }), [options?.wagmi]);
31
66
  const wagmiConfig = useMemo(() => {
32
- return createWagmiConfig(rpcConfig);
33
- }, [rpcConfig]);
67
+ return createWagmiConfig(rpcConfig, wagmi);
68
+ }, [rpcConfig, wagmi]);
34
69
 
35
70
  const wallets = useMemo(() => [new UnsafeBurnerWalletAdapter()], []);
71
+ const solana = useMemo(() => ({ ...defaultOptions.solana, ...options?.solana }), [options?.solana]);
72
+ const sui = useMemo(() => ({ ...defaultOptions.sui, ...options?.sui }), [options?.sui]);
36
73
 
37
74
  return (
38
75
  <QueryClientProvider client={queryClient}>
39
- <WagmiProvider reconnectOnMount={false} config={wagmiConfig}>
76
+ <WagmiProvider reconnectOnMount={wagmi.reconnectOnMount} config={wagmiConfig}>
40
77
  <SuiClientProvider networks={{ mainnet: { url: getFullnodeUrl('mainnet') } }} defaultNetwork="mainnet">
41
- <SuiWalletProvider autoConnect={true}>
78
+ <SuiWalletProvider autoConnect={sui.autoConnect}>
42
79
  <SolanaConnectionProvider endpoint={rpcConfig['solana'] ?? 'https://api.mainnet-beta.solana.com'}>
43
- <SolanaWalletProvider wallets={wallets} autoConnect>
80
+ <SolanaWalletProvider wallets={wallets} autoConnect={solana.autoConnect}>
44
81
  <Hydrate rpcConfig={rpcConfig} />
45
82
  {children}
46
83
  </SolanaWalletProvider>
@@ -33,6 +33,7 @@ import {
33
33
  redbellyMainnet,
34
34
  kaia,
35
35
  } from 'wagmi/chains';
36
+ import type { WagmiOptions } from '@/SodaxWalletProvider';
36
37
 
37
38
  // HyperEVM chain is not supported by viem, so we need to define it manually
38
39
  export const hyper = /*#__PURE__*/ defineChain({
@@ -60,7 +61,7 @@ export const hyper = /*#__PURE__*/ defineChain({
60
61
  },
61
62
  });
62
63
 
63
- export const createWagmiConfig = (config: RpcConfig) => {
64
+ export const createWagmiConfig = (config: RpcConfig, options?: WagmiOptions) => {
64
65
  return createConfig({
65
66
  chains: [
66
67
  mainnet,
@@ -76,7 +77,7 @@ export const createWagmiConfig = (config: RpcConfig) => {
76
77
  kaia,
77
78
  redbellyMainnet,
78
79
  ],
79
- ssr: true,
80
+ ssr: options?.ssr,
80
81
  transports: {
81
82
  [mainnet.id]: http(config[ETHEREUM_MAINNET_CHAIN_ID]),
82
83
  [avalanche.id]: http(config[AVALANCHE_MAINNET_CHAIN_ID]),