@dodoex/wallet-web3-react 0.4.4 → 0.4.5-beta.1

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.
@@ -1,10 +1,11 @@
1
1
  import WalletWeb3 from '@dodoex/wallet-web3';
2
2
  import React from 'react';
3
3
  import { ConnectPageProps } from './ConnectPage';
4
- export default function ConnectDialog({ open, onClose, walletWeb3, onConnectWallet, WalletTag, }: {
4
+ export default function ConnectDialog({ open, onClose, walletWeb3, priorityWalletType, onConnectWallet, WalletTag, }: {
5
5
  open: boolean;
6
6
  onClose: () => void;
7
7
  walletWeb3: WalletWeb3;
8
+ priorityWalletType?: ConnectPageProps['priorityWalletType'];
8
9
  onConnectWallet?: ConnectPageProps['onConnectWallet'];
9
10
  WalletTag?: ConnectPageProps['WalletTag'];
10
11
  }): React.JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import WalletWeb3 from '@dodoex/wallet-web3';
2
+ import WalletWeb3, { WalletType } from '@dodoex/wallet-web3';
3
3
  import { WalletItem } from '../hooks/useConnectWallet';
4
4
  import { WalletTagProps } from '../components/WalletTag';
5
5
  export type ConnectDialogWalletTag = React.FC<WalletTagProps & {
@@ -10,9 +10,10 @@ export interface ConnectPageProps {
10
10
  account?: string;
11
11
  walletWeb3?: WalletWeb3;
12
12
  showOtherInjectWallet?: boolean;
13
+ priorityWalletType?: WalletType | string;
13
14
  onClose: () => void;
14
15
  onConnectWallet?: (wallet: WalletItem) => void | Promise<void>;
15
16
  WalletTag?: ConnectDialogWalletTag;
16
17
  }
17
- declare function ConnectPage({ chainId, account, walletWeb3, showOtherInjectWallet, onClose, onConnectWallet, WalletTag, }: ConnectPageProps): React.JSX.Element;
18
+ declare function ConnectPage({ chainId, account, walletWeb3, showOtherInjectWallet, priorityWalletType, onClose, onConnectWallet, WalletTag, }: ConnectPageProps): React.JSX.Element;
18
19
  export default ConnectPage;
@@ -1,10 +1,11 @@
1
1
  import WalletWeb3 from '@dodoex/wallet-web3';
2
2
  import React from 'react';
3
3
  import { ConnectPageProps } from './ConnectPage';
4
- export default function WalletDialog({ open, onClose, walletWeb3, onConnectWallet, WalletTag, }: {
4
+ export default function WalletDialog({ open, onClose, walletWeb3, priorityWalletType, onConnectWallet, WalletTag, }: {
5
5
  open: boolean;
6
6
  onClose: () => void;
7
7
  walletWeb3: WalletWeb3;
8
+ priorityWalletType?: ConnectPageProps['priorityWalletType'];
8
9
  onConnectWallet?: ConnectPageProps['onConnectWallet'];
9
10
  WalletTag?: ConnectPageProps['WalletTag'];
10
11
  }): React.JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dodoex/wallet-web3-react",
3
- "version": "0.4.4",
3
+ "version": "0.4.5-beta.1",
4
4
  "source": "src/index.tsx",
5
5
  "types": "dist/types/index.d.ts",
6
6
  "typings": "dist/types/index.d.ts",
@@ -89,4 +89,3 @@
89
89
  "react-infinite-scroller": "^1.2.6"
90
90
  }
91
91
  }
92
-
@@ -9,12 +9,14 @@ export default function ConnectDialog({
9
9
  open,
10
10
  onClose,
11
11
  walletWeb3,
12
+ priorityWalletType,
12
13
  onConnectWallet,
13
14
  WalletTag,
14
15
  }: {
15
16
  open: boolean;
16
17
  onClose: () => void;
17
18
  walletWeb3: WalletWeb3;
19
+ priorityWalletType?: ConnectPageProps['priorityWalletType'];
18
20
  onConnectWallet?: ConnectPageProps['onConnectWallet'];
19
21
  WalletTag?: ConnectPageProps['WalletTag'];
20
22
  }) {
@@ -26,6 +28,7 @@ export default function ConnectDialog({
26
28
  account={account}
27
29
  walletWeb3={walletWeb3}
28
30
  showOtherInjectWallet
31
+ priorityWalletType={priorityWalletType}
29
32
  onClose={onClose}
30
33
  onConnectWallet={onConnectWallet}
31
34
  WalletTag={WalletTag}
@@ -219,6 +219,7 @@ export interface ConnectPageProps {
219
219
  account?: string;
220
220
  walletWeb3?: WalletWeb3;
221
221
  showOtherInjectWallet?: boolean;
222
+ priorityWalletType?: WalletType | string;
222
223
  onClose: () => void;
223
224
  onConnectWallet?: (wallet: WalletItem) => void | Promise<void>;
224
225
  WalletTag?: ConnectDialogWalletTag;
@@ -228,6 +229,7 @@ function ConnectPage({
228
229
  account,
229
230
  walletWeb3,
230
231
  showOtherInjectWallet,
232
+ priorityWalletType,
231
233
  onClose,
232
234
  onConnectWallet,
233
235
  WalletTag,
@@ -267,13 +269,52 @@ function ConnectPage({
267
269
  hasTermsOfServiceLink: !!termsOfServiceLink,
268
270
  });
269
271
  const [showAllWallet, setShowAllWallet] = React.useState(false);
270
- const showWalletList = React.useMemo(() => {
271
- if (showAllWallet) return walletList;
272
- return walletList.slice(0, 6);
273
- }, [walletList, showAllWallet]);
272
+ const sortedWalletList = React.useMemo(() => {
273
+ if (!priorityWalletType) return walletList;
274
+
275
+ const priorityWallet = walletList.find(
276
+ (wallet) => wallet.currentType === priorityWalletType,
277
+ );
278
+ if (!priorityWallet) return walletList;
279
+
280
+ return [
281
+ priorityWallet,
282
+ ...walletList.filter((wallet) => wallet.currentType !== priorityWalletType),
283
+ ];
284
+ }, [priorityWalletType, walletList]);
285
+ const { visibleWalletList, hiddenWalletList } = React.useMemo(() => {
286
+ if (!priorityWalletType) {
287
+ return {
288
+ visibleWalletList: showAllWallet ? sortedWalletList : sortedWalletList.slice(0, 6),
289
+ hiddenWalletList: sortedWalletList.slice(6),
290
+ };
291
+ }
292
+
293
+ const [firstWallet, ...otherWallets] = sortedWalletList;
294
+ if (!firstWallet) {
295
+ return {
296
+ visibleWalletList: [],
297
+ hiddenWalletList: [],
298
+ };
299
+ }
300
+
301
+ const installedWallets = otherWallets.filter((wallet) => wallet.isInstalled);
302
+ const uninstalledWallets = otherWallets.filter((wallet) => !wallet.isInstalled);
303
+ const collapsedVisibleWalletList = [firstWallet, ...installedWallets].slice(0, 6);
304
+ const collapsedHiddenWalletList = sortedWalletList.filter(
305
+ (wallet) => !collapsedVisibleWalletList.includes(wallet),
306
+ );
307
+
308
+ return {
309
+ visibleWalletList: showAllWallet
310
+ ? [firstWallet, ...installedWallets, ...uninstalledWallets]
311
+ : collapsedVisibleWalletList,
312
+ hiddenWalletList: showAllWallet ? uninstalledWallets : collapsedHiddenWalletList,
313
+ };
314
+ }, [priorityWalletType, showAllWallet, sortedWalletList]);
274
315
  const morePriorityWalletList = React.useMemo(() => {
275
- return walletList.slice(6, 9);
276
- }, [walletList]);
316
+ return hiddenWalletList.slice(0, 3);
317
+ }, [hiddenWalletList]);
277
318
 
278
319
  return (
279
320
  <>
@@ -299,7 +340,7 @@ function ConnectPage({
299
340
  ...walletGroupStyle,
300
341
  }}
301
342
  >
302
- {showWalletList.map((wallet) => {
343
+ {visibleWalletList.map((wallet) => {
303
344
  return (
304
345
  <WalletGroupItem
305
346
  key={wallet.title}
@@ -319,7 +360,7 @@ function ConnectPage({
319
360
  );
320
361
  })}
321
362
  </Box>
322
- {morePriorityWalletList.length ? (
363
+ {hiddenWalletList.length ? (
323
364
  <Box
324
365
  sx={{
325
366
  mx: 20,
@@ -12,12 +12,14 @@ export default function WalletDialog({
12
12
  open,
13
13
  onClose,
14
14
  walletWeb3,
15
+ priorityWalletType,
15
16
  onConnectWallet,
16
17
  WalletTag,
17
18
  }: {
18
19
  open: boolean;
19
20
  onClose: () => void;
20
21
  walletWeb3: WalletWeb3;
22
+ priorityWalletType?: ConnectPageProps['priorityWalletType'];
21
23
  onConnectWallet?: ConnectPageProps['onConnectWallet'];
22
24
  WalletTag?: ConnectPageProps['WalletTag'];
23
25
  }) {
@@ -70,6 +72,7 @@ export default function WalletDialog({
70
72
  account={account}
71
73
  walletWeb3={walletWeb3}
72
74
  showOtherInjectWallet
75
+ priorityWalletType={priorityWalletType}
73
76
  onClose={onClose}
74
77
  onConnectWallet={onConnectWallet}
75
78
  WalletTag={WalletTag}
@@ -1,9 +1,14 @@
1
1
  'use client';
2
2
 
3
- import { getFetchERC20BalanceOfQueryOptions } from '@dodoex/dodo-contract-request';
3
+ import {
4
+ getFetchERC20BalanceOfQueryOptions,
5
+ getFetchMulticallWithValidGetEthBalanceQueryOptions,
6
+ } from '@dodoex/dodo-contract-request';
4
7
  import { useQueries } from '@tanstack/react-query';
5
8
  import { TokenInfo } from '../components/TokenLogo';
6
9
 
10
+ const NATIVE_TOKEN_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
11
+
7
12
  type TokenInfoMap = Map<string, bigint>;
8
13
 
9
14
  export default function useFetchTokensBalance({
@@ -19,11 +24,11 @@ export default function useFetchTokensBalance({
19
24
  }) {
20
25
  const tokensQueries = useQueries({
21
26
  queries: (tokenList ?? []).map((token) => {
22
- const query = getFetchERC20BalanceOfQueryOptions(
23
- skip ? undefined : token.chainId,
24
- token?.address,
25
- account,
26
- );
27
+ const chainId = skip ? undefined : token.chainId;
28
+ const query =
29
+ token.address.toLowerCase() === NATIVE_TOKEN_ADDRESS.toLowerCase()
30
+ ? getFetchMulticallWithValidGetEthBalanceQueryOptions(chainId, account)
31
+ : getFetchERC20BalanceOfQueryOptions(chainId, token?.address, account);
27
32
 
28
33
  return {
29
34
  queryKey: blockNumber
package/src/locales/en.po CHANGED
@@ -76,7 +76,7 @@ msgstr "Claim Rewards"
76
76
  msgid "Connect Alchemy"
77
77
  msgstr "Connect Alchemy"
78
78
 
79
- #: src/WalletConnect/ConnectPage.tsx:281
79
+ #: src/WalletConnect/ConnectPage.tsx:322
80
80
  msgid "Connect Wallet"
81
81
  msgstr "Connect Wallet"
82
82
 
@@ -176,7 +176,7 @@ msgstr "Log in with your email or a passkey"
176
176
  msgid "Mint Token"
177
177
  msgstr "Mint Token"
178
178
 
179
- #: src/WalletConnect/ConnectPage.tsx:391
179
+ #: src/WalletConnect/ConnectPage.tsx:432
180
180
  msgid "More Wallets"
181
181
  msgstr "More Wallets"
182
182
 
package/src/locales/zh.po CHANGED
@@ -76,7 +76,7 @@ msgstr ""
76
76
  msgid "Connect Alchemy"
77
77
  msgstr ""
78
78
 
79
- #: src/WalletConnect/ConnectPage.tsx:281
79
+ #: src/WalletConnect/ConnectPage.tsx:322
80
80
  msgid "Connect Wallet"
81
81
  msgstr ""
82
82
 
@@ -174,7 +174,7 @@ msgstr ""
174
174
  msgid "Mint Token"
175
175
  msgstr ""
176
176
 
177
- #: src/WalletConnect/ConnectPage.tsx:391
177
+ #: src/WalletConnect/ConnectPage.tsx:432
178
178
  msgid "More Wallets"
179
179
  msgstr ""
180
180