@dodoex/wallet-web3-react 0.4.0 → 0.4.2

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.
Files changed (68) hide show
  1. package/babel.config.js +9 -9
  2. package/dist/cjs/index.cjs +4 -13
  3. package/dist/cjs/locales/en.js +1 -1
  4. package/dist/cjs/locales/zh.js +1 -1
  5. package/dist/index.js +4 -13
  6. package/dist/locales/en.js +1 -1
  7. package/dist/locales/zh.js +1 -1
  8. package/dist/types/ClientProvider.d.ts +1 -1
  9. package/dist/types/LangProvider.d.ts +1 -1
  10. package/dist/types/WalletConnect/AccountPage.d.ts +1 -1
  11. package/dist/types/WalletConnect/ActivityList.d.ts +5 -4
  12. package/dist/types/WalletConnect/ConnectAlchemy/index.d.ts +2 -1
  13. package/dist/types/WalletConnect/ConnectDialog.d.ts +2 -1
  14. package/dist/types/WalletConnect/ConnectLedger/ErrorDialog.d.ts +1 -1
  15. package/dist/types/WalletConnect/ConnectLedger/LoadingDialog.d.ts +1 -1
  16. package/dist/types/WalletConnect/ConnectLedger/LockedDialog.d.ts +1 -1
  17. package/dist/types/WalletConnect/ConnectLedger/ProtocolDialog.d.ts +1 -1
  18. package/dist/types/WalletConnect/ConnectLedger/SelectAddressDialog.d.ts +1 -1
  19. package/dist/types/WalletConnect/ConnectLedger/SelectPathDialog.d.ts +1 -1
  20. package/dist/types/WalletConnect/ConnectLedger/index.d.ts +1 -1
  21. package/dist/types/WalletConnect/ConnectPage.d.ts +1 -1
  22. package/dist/types/WalletConnect/HasBalanceTokenList.d.ts +1 -1
  23. package/dist/types/WalletConnect/ReceiveTokenPage.d.ts +2 -1
  24. package/dist/types/WalletConnect/SendTokenPage.d.ts +2 -1
  25. package/dist/types/WalletConnect/WalletDialog.d.ts +2 -1
  26. package/dist/types/WalletConnectProvider.d.ts +2 -2
  27. package/dist/types/components/AddressWithLinkAndCopy.d.ts +2 -2
  28. package/dist/types/components/Dialog.d.ts +3 -3
  29. package/dist/types/components/WalletTag.d.ts +1 -1
  30. package/lingui.config.ts +13 -13
  31. package/package.json +90 -90
  32. package/rollup.config.mjs +106 -103
  33. package/src/ClientProvider.tsx +17 -17
  34. package/src/LangProvider.tsx +36 -36
  35. package/src/WalletConnect/AccountPage.tsx +498 -498
  36. package/src/WalletConnect/ActivityList.tsx +606 -606
  37. package/src/WalletConnect/ConnectAlchemy/index.tsx +248 -248
  38. package/src/WalletConnect/ConnectAlchemy/useConnectAlchemy.ts +105 -105
  39. package/src/WalletConnect/ConnectDialog.tsx +35 -35
  40. package/src/WalletConnect/ConnectLedger/ErrorDialog.tsx +61 -61
  41. package/src/WalletConnect/ConnectLedger/LockedDialog.tsx +54 -54
  42. package/src/WalletConnect/ConnectLedger/helper.ts +14 -14
  43. package/src/WalletConnect/ConnectPage.tsx +508 -508
  44. package/src/WalletConnect/HasBalanceTokenList.tsx +202 -202
  45. package/src/WalletConnect/ReceiveTokenPage.tsx +145 -145
  46. package/src/WalletConnect/SendTokenPage.tsx +251 -251
  47. package/src/WalletConnect/WalletDialog.tsx +80 -80
  48. package/src/WalletConnectProvider.tsx +57 -57
  49. package/src/components/AddressWithLinkAndCopy.tsx +202 -202
  50. package/src/components/Dialog.tsx +158 -158
  51. package/src/components/TokenLogo.tsx +167 -167
  52. package/src/components/WalletTag.tsx +117 -117
  53. package/src/constants/localstorage.ts +24 -24
  54. package/src/hooks/useConnectWallet.ts +150 -150
  55. package/src/hooks/useFetchFiatPrice.ts +53 -53
  56. package/src/hooks/useFetchTokensBalance.ts +53 -53
  57. package/src/hooks/useHasBalanceTokenList.ts +95 -95
  58. package/src/hooks/useTransactionList.ts +89 -89
  59. package/src/index.tsx +7 -7
  60. package/src/locales/en.js +1 -1
  61. package/src/locales/en.po +8 -8
  62. package/src/locales/zh.js +1 -1
  63. package/src/locales/zh.po +4 -4
  64. package/src/react19-types.d.ts +12 -0
  65. package/src/utils/formatter.ts +102 -102
  66. package/src/utils/time.ts +21 -21
  67. package/src/utils/utils.ts +8 -8
  68. package/tsconfig.json +22 -22
@@ -1,105 +1,105 @@
1
- import WalletWeb3, {
2
- allWalletObject,
3
- ConnectorParams,
4
- useWalletStore,
5
- WalletType,
6
- } from '@dodoex/wallet-web3';
7
- import { useMutation } from '@tanstack/react-query';
8
- import React from 'react';
9
- import { connectToWallet } from '../../hooks/useConnectWallet';
10
-
11
- export type AlchemyParams = Exclude<
12
- Partial<ConnectorParams['alchemyParams']>,
13
- undefined
14
- >;
15
-
16
- export const USERNAME_PREFIX = 'DODO';
17
-
18
- export const alchemyWallet = allWalletObject.Alchemy;
19
-
20
- export async function checkAlchemyCache(chainId: number) {
21
- const alchemy = await alchemyWallet.getPackage?.();
22
- if (alchemy) {
23
- const signer = await alchemy.getAlchemySigner(chainId);
24
- const user = await signer.getAuthDetails().catch(() => null);
25
- if (user) {
26
- return true;
27
- }
28
- }
29
- return false;
30
- }
31
-
32
- export function useConnectAlchemyQuery({
33
- walletWeb3,
34
- showAlchemyConnect,
35
- }: {
36
- walletWeb3: WalletWeb3;
37
- showAlchemyConnect: () => void;
38
- }) {
39
- const connectMutation = useConnectAlchemy({
40
- walletWeb3,
41
- });
42
- const { chainId } = useWalletStore();
43
- const search = typeof window !== 'undefined' ? window.location.search : '';
44
-
45
- React.useEffect(() => {
46
- const searchParams = new URLSearchParams(search);
47
- const bundle = searchParams.get('bundle');
48
- if (bundle) {
49
- const orgId = searchParams.get('orgId');
50
- connectMutation.mutate({
51
- type: 'email',
52
- orgId: orgId as string | undefined,
53
- bundle: bundle as string,
54
- });
55
- } else {
56
- // auto connect
57
- const autoConnect = async () => {
58
- const cacheType = walletWeb3.connectController.getAutoCacheType();
59
- if (cacheType === WalletType.Alchemy) {
60
- const alchemy = await alchemyWallet.getPackage?.();
61
- const signer = await alchemy.getAlchemySigner(
62
- chainId,
63
- walletWeb3.providerConfig.alchemyParams?.apiKeyObject!,
64
- );
65
- const user = await signer.getAuthDetails().catch(() => null);
66
- if (user) {
67
- await connectToWallet(walletWeb3, alchemy, {
68
- chainId,
69
- });
70
- } else {
71
- showAlchemyConnect();
72
- }
73
- }
74
- };
75
- autoConnect();
76
- }
77
- }, [search]);
78
- }
79
-
80
- export function useConnectAlchemy({ walletWeb3 }: { walletWeb3: WalletWeb3 }) {
81
- const { chainId } = useWalletStore();
82
- return useMutation({
83
- mutationFn: async (authParams: AlchemyParams['authParams']) => {
84
- const alchemy = await alchemyWallet.getPackage?.();
85
- const signer = await alchemy.getAlchemySigner(chainId);
86
- // Register by email, no need to go down. The user will open a new page from the mailbox and connect in useConnectAlchemyQuery
87
- if (authParams?.type === 'email' && 'email' in authParams) {
88
- const search = new URLSearchParams();
89
- await signer.authenticate({
90
- ...authParams,
91
- redirectParams: search,
92
- });
93
- return;
94
- }
95
- await signer.authenticate(authParams);
96
- await connectToWallet(walletWeb3, alchemy, {
97
- chainId,
98
- alchemyParams: {
99
- authParams,
100
- apiKeyObject: walletWeb3.providerConfig.alchemyParams?.apiKeyObject!,
101
- },
102
- });
103
- },
104
- });
105
- }
1
+ import WalletWeb3, {
2
+ allWalletObject,
3
+ ConnectorParams,
4
+ useWalletStore,
5
+ WalletType,
6
+ } from '@dodoex/wallet-web3';
7
+ import { useMutation } from '@tanstack/react-query';
8
+ import React from 'react';
9
+ import { connectToWallet } from '../../hooks/useConnectWallet';
10
+
11
+ export type AlchemyParams = Exclude<
12
+ Partial<ConnectorParams['alchemyParams']>,
13
+ undefined
14
+ >;
15
+
16
+ export const USERNAME_PREFIX = 'DODO';
17
+
18
+ export const alchemyWallet = allWalletObject.Alchemy;
19
+
20
+ export async function checkAlchemyCache(chainId: number) {
21
+ const alchemy = await alchemyWallet.getPackage?.();
22
+ if (alchemy) {
23
+ const signer = await alchemy.getAlchemySigner(chainId);
24
+ const user = await signer.getAuthDetails().catch(() => null);
25
+ if (user) {
26
+ return true;
27
+ }
28
+ }
29
+ return false;
30
+ }
31
+
32
+ export function useConnectAlchemyQuery({
33
+ walletWeb3,
34
+ showAlchemyConnect,
35
+ }: {
36
+ walletWeb3: WalletWeb3;
37
+ showAlchemyConnect: () => void;
38
+ }) {
39
+ const connectMutation = useConnectAlchemy({
40
+ walletWeb3,
41
+ });
42
+ const { chainId } = useWalletStore();
43
+ const search = typeof window !== 'undefined' ? window.location.search : '';
44
+
45
+ React.useEffect(() => {
46
+ const searchParams = new URLSearchParams(search);
47
+ const bundle = searchParams.get('bundle');
48
+ if (bundle) {
49
+ const orgId = searchParams.get('orgId');
50
+ connectMutation.mutate({
51
+ type: 'email',
52
+ orgId: orgId as string | undefined,
53
+ bundle: bundle as string,
54
+ });
55
+ } else {
56
+ // auto connect
57
+ const autoConnect = async () => {
58
+ const cacheType = walletWeb3.connectController.getAutoCacheType();
59
+ if (cacheType === WalletType.Alchemy) {
60
+ const alchemy = await alchemyWallet.getPackage?.();
61
+ const signer = await alchemy.getAlchemySigner(
62
+ chainId,
63
+ walletWeb3.providerConfig.alchemyParams?.apiKeyObject!,
64
+ );
65
+ const user = await signer.getAuthDetails().catch(() => null);
66
+ if (user) {
67
+ await connectToWallet(walletWeb3, alchemy, {
68
+ chainId,
69
+ });
70
+ } else {
71
+ showAlchemyConnect();
72
+ }
73
+ }
74
+ };
75
+ autoConnect();
76
+ }
77
+ }, [search]);
78
+ }
79
+
80
+ export function useConnectAlchemy({ walletWeb3 }: { walletWeb3: WalletWeb3 }) {
81
+ const { chainId } = useWalletStore();
82
+ return useMutation({
83
+ mutationFn: async (authParams: AlchemyParams['authParams']) => {
84
+ const alchemy = await alchemyWallet.getPackage?.();
85
+ const signer = await alchemy.getAlchemySigner(chainId);
86
+ // Register by email, no need to go down. The user will open a new page from the mailbox and connect in useConnectAlchemyQuery
87
+ if (authParams?.type === 'email' && 'email' in authParams) {
88
+ const search = new URLSearchParams();
89
+ await signer.authenticate({
90
+ ...authParams,
91
+ redirectParams: search,
92
+ });
93
+ return;
94
+ }
95
+ await signer.authenticate(authParams);
96
+ await connectToWallet(walletWeb3, alchemy, {
97
+ chainId,
98
+ alchemyParams: {
99
+ authParams,
100
+ apiKeyObject: walletWeb3.providerConfig.alchemyParams?.apiKeyObject!,
101
+ },
102
+ });
103
+ },
104
+ });
105
+ }
@@ -1,35 +1,35 @@
1
- 'use client';
2
-
3
- import WalletWeb3, { useWalletStore } from '@dodoex/wallet-web3';
4
- import React from 'react';
5
- import Dialog from '../components/Dialog';
6
- import ConnectPage, { ConnectPageProps } from './ConnectPage';
7
-
8
- export default function ConnectDialog({
9
- open,
10
- onClose,
11
- walletWeb3,
12
- onConnectWallet,
13
- WalletTag,
14
- }: {
15
- open: boolean;
16
- onClose: () => void;
17
- walletWeb3: WalletWeb3;
18
- onConnectWallet?: ConnectPageProps['onConnectWallet'];
19
- WalletTag?: ConnectPageProps['WalletTag'];
20
- }) {
21
- const { account, chainId: connectChainId } = useWalletStore();
22
- return (
23
- <Dialog open={open} onClose={onClose} width={420}>
24
- <ConnectPage
25
- chainId={connectChainId}
26
- account={account}
27
- walletWeb3={walletWeb3}
28
- showOtherInjectWallet
29
- onClose={onClose}
30
- onConnectWallet={onConnectWallet}
31
- WalletTag={WalletTag}
32
- />
33
- </Dialog>
34
- );
35
- }
1
+ 'use client';
2
+
3
+ import WalletWeb3, { useWalletStore } from '@dodoex/wallet-web3';
4
+ import React from 'react';
5
+ import Dialog from '../components/Dialog';
6
+ import ConnectPage, { ConnectPageProps } from './ConnectPage';
7
+
8
+ export default function ConnectDialog({
9
+ open,
10
+ onClose,
11
+ walletWeb3,
12
+ onConnectWallet,
13
+ WalletTag,
14
+ }: {
15
+ open: boolean;
16
+ onClose: () => void;
17
+ walletWeb3: WalletWeb3;
18
+ onConnectWallet?: ConnectPageProps['onConnectWallet'];
19
+ WalletTag?: ConnectPageProps['WalletTag'];
20
+ }) {
21
+ const { account, chainId: connectChainId } = useWalletStore();
22
+ return (
23
+ <Dialog open={open} onClose={onClose} width={420}>
24
+ <ConnectPage
25
+ chainId={connectChainId}
26
+ account={account}
27
+ walletWeb3={walletWeb3}
28
+ showOtherInjectWallet
29
+ onClose={onClose}
30
+ onConnectWallet={onConnectWallet}
31
+ WalletTag={WalletTag}
32
+ />
33
+ </Dialog>
34
+ );
35
+ }
@@ -1,61 +1,61 @@
1
- import { Box, Button } from '@dodoex/components';
2
- import { Error } from '@dodoex/icons';
3
- import { Trans } from '@lingui/macro';
4
- import Dialog from '../../components/Dialog';
5
-
6
- export default function ErrorDialog({
7
- error,
8
- onClose,
9
- }: {
10
- error?: string;
11
- onClose: () => void;
12
- }) {
13
- return (
14
- <Dialog open={!!error} width={340} onClose={onClose}>
15
- <Box
16
- sx={{
17
- textAlign: 'center',
18
- p: 20,
19
- }}
20
- >
21
- <Box
22
- component={Error}
23
- sx={{
24
- width: 40,
25
- height: 40,
26
- color: 'error.main',
27
- }}
28
- />
29
- <Box
30
- sx={{
31
- typography: 'caption',
32
- mt: 20,
33
- whiteSpace: 'pre-wrap',
34
- }}
35
- >
36
- <Trans>Unknown Error</Trans>
37
- </Box>
38
- <Box
39
- sx={{
40
- typography: 'h6',
41
- mt: 12,
42
- whiteSpace: 'pre-wrap',
43
- color: 'text.secondary',
44
- }}
45
- >
46
- {error}
47
- </Box>
48
- <Button
49
- onClick={onClose}
50
- fullWidth
51
- variant={Button.Variant.outlined}
52
- sx={{
53
- mt: 24,
54
- }}
55
- >
56
- <Trans>OK</Trans>
57
- </Button>
58
- </Box>
59
- </Dialog>
60
- );
61
- }
1
+ import { Box, Button } from '@dodoex/components';
2
+ import { Error } from '@dodoex/icons';
3
+ import { Trans } from '@lingui/macro';
4
+ import Dialog from '../../components/Dialog';
5
+
6
+ export default function ErrorDialog({
7
+ error,
8
+ onClose,
9
+ }: {
10
+ error?: string;
11
+ onClose: () => void;
12
+ }) {
13
+ return (
14
+ <Dialog open={!!error} width={340} onClose={onClose}>
15
+ <Box
16
+ sx={{
17
+ textAlign: 'center',
18
+ p: 20,
19
+ }}
20
+ >
21
+ <Box
22
+ component={Error}
23
+ sx={{
24
+ width: 40,
25
+ height: 40,
26
+ color: 'error.main',
27
+ }}
28
+ />
29
+ <Box
30
+ sx={{
31
+ typography: 'caption',
32
+ mt: 20,
33
+ whiteSpace: 'pre-wrap',
34
+ }}
35
+ >
36
+ <Trans>Unknown Error</Trans>
37
+ </Box>
38
+ <Box
39
+ sx={{
40
+ typography: 'h6',
41
+ mt: 12,
42
+ whiteSpace: 'pre-wrap',
43
+ color: 'text.secondary',
44
+ }}
45
+ >
46
+ {error}
47
+ </Box>
48
+ <Button
49
+ onClick={onClose}
50
+ fullWidth
51
+ variant={Button.Variant.outlined}
52
+ sx={{
53
+ mt: 24,
54
+ }}
55
+ >
56
+ <Trans>OK</Trans>
57
+ </Button>
58
+ </Box>
59
+ </Dialog>
60
+ );
61
+ }
@@ -1,54 +1,54 @@
1
- import { Button, Box } from '@dodoex/components';
2
- import { Lock } from '@dodoex/icons';
3
- import { Trans } from '@lingui/macro';
4
- import Dialog from '../../components/Dialog';
5
-
6
- export default function LockedDialog({
7
- on,
8
- onClose,
9
- }: {
10
- on: boolean;
11
- onClose: () => void;
12
- }) {
13
- return (
14
- <Dialog open={on} width={340} onClose={onClose}>
15
- <Box
16
- sx={{
17
- textAlign: 'center',
18
- py: 20,
19
- }}
20
- >
21
- <Box
22
- component={Lock}
23
- sx={{
24
- mt: 20,
25
- width: 64,
26
- height: 64,
27
- color: 'primary.main',
28
- }}
29
- />
30
- <Box
31
- sx={{
32
- mt: 20,
33
- whiteSpace: 'pre-wrap',
34
- fontWeight: 600,
35
- }}
36
- >
37
- <Trans>
38
- The Ledger Device is locked\nPlease unlock from the device
39
- </Trans>
40
- </Box>
41
- <Button
42
- onClick={onClose}
43
- fullWidth
44
- variant={Button.Variant.outlined}
45
- sx={{
46
- mt: 24,
47
- }}
48
- >
49
- <Trans>OK</Trans>
50
- </Button>
51
- </Box>
52
- </Dialog>
53
- );
54
- }
1
+ import { Button, Box } from '@dodoex/components';
2
+ import { Lock } from '@dodoex/icons';
3
+ import { Trans } from '@lingui/macro';
4
+ import Dialog from '../../components/Dialog';
5
+
6
+ export default function LockedDialog({
7
+ on,
8
+ onClose,
9
+ }: {
10
+ on: boolean;
11
+ onClose: () => void;
12
+ }) {
13
+ return (
14
+ <Dialog open={on} width={340} onClose={onClose}>
15
+ <Box
16
+ sx={{
17
+ textAlign: 'center',
18
+ py: 20,
19
+ }}
20
+ >
21
+ <Box
22
+ component={Lock}
23
+ sx={{
24
+ mt: 20,
25
+ width: 64,
26
+ height: 64,
27
+ color: 'primary.main',
28
+ }}
29
+ />
30
+ <Box
31
+ sx={{
32
+ mt: 20,
33
+ whiteSpace: 'pre-wrap',
34
+ fontWeight: 600,
35
+ }}
36
+ >
37
+ <Trans>
38
+ The Ledger Device is locked\nPlease unlock from the device
39
+ </Trans>
40
+ </Box>
41
+ <Button
42
+ onClick={onClose}
43
+ fullWidth
44
+ variant={Button.Variant.outlined}
45
+ sx={{
46
+ mt: 24,
47
+ }}
48
+ >
49
+ <Trans>OK</Trans>
50
+ </Button>
51
+ </Box>
52
+ </Dialog>
53
+ );
54
+ }
@@ -1,14 +1,14 @@
1
- import { getLedgerUSBPackage } from '@dodoex/wallet-web3';
2
- export async function getTransport() {
3
- const ledger = await getLedgerUSBPackage();
4
- return ledger.getTransport();
5
- }
6
-
7
- export async function getAccountList(
8
- pathRule: string,
9
- page?: number | undefined,
10
- pageSize?: number,
11
- ) {
12
- const ledger = await getLedgerUSBPackage();
13
- return ledger.getAccountList(pathRule, page, pageSize);
14
- }
1
+ import { getLedgerUSBPackage } from '@dodoex/wallet-web3';
2
+ export async function getTransport() {
3
+ const ledger = await getLedgerUSBPackage();
4
+ return ledger.getTransport();
5
+ }
6
+
7
+ export async function getAccountList(
8
+ pathRule: string,
9
+ page?: number | undefined,
10
+ pageSize?: number,
11
+ ) {
12
+ const ledger = await getLedgerUSBPackage();
13
+ return ledger.getAccountList(pathRule, page, pageSize);
14
+ }