@dodoex/wallet-web3-react 0.2.1 → 0.3.0

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 (40) hide show
  1. package/babel.config.js +9 -9
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.js +1 -1
  4. package/lingui.config.ts +13 -13
  5. package/package.json +90 -77
  6. package/rollup.config.mjs +100 -100
  7. package/src/ClientProvider.tsx +17 -15
  8. package/src/LangProvider.tsx +36 -34
  9. package/src/WalletConnect/AccountPage.tsx +496 -494
  10. package/src/WalletConnect/ActivityList.tsx +606 -604
  11. package/src/WalletConnect/ConnectAlchemy/index.tsx +248 -246
  12. package/src/WalletConnect/ConnectAlchemy/useConnectAlchemy.ts +105 -105
  13. package/src/WalletConnect/ConnectDialog.tsx +35 -33
  14. package/src/WalletConnect/ConnectLedger/ErrorDialog.tsx +61 -61
  15. package/src/WalletConnect/ConnectLedger/LockedDialog.tsx +54 -54
  16. package/src/WalletConnect/ConnectLedger/helper.ts +14 -14
  17. package/src/WalletConnect/ConnectLedger/index.tsx +2 -0
  18. package/src/WalletConnect/ConnectPage.tsx +508 -506
  19. package/src/WalletConnect/HasBalanceTokenList.tsx +202 -200
  20. package/src/WalletConnect/ReceiveTokenPage.tsx +145 -143
  21. package/src/WalletConnect/SendTokenPage.tsx +251 -249
  22. package/src/WalletConnect/WalletDialog.tsx +80 -78
  23. package/src/WalletConnectProvider.tsx +57 -55
  24. package/src/components/AddressWithLinkAndCopy.tsx +202 -200
  25. package/src/components/Dialog.tsx +158 -156
  26. package/src/components/TokenLogo.tsx +167 -165
  27. package/src/components/WalletTag.tsx +117 -115
  28. package/src/constants/localstorage.ts +24 -22
  29. package/src/hooks/useConnectWallet.ts +150 -148
  30. package/src/hooks/useFetchFiatPrice.ts +53 -51
  31. package/src/hooks/useFetchTokensBalance.ts +53 -51
  32. package/src/hooks/useHasBalanceTokenList.ts +95 -93
  33. package/src/hooks/useTransactionList.ts +89 -87
  34. package/src/index.tsx +7 -7
  35. package/src/locales/en.po +51 -51
  36. package/src/locales/zh.po +51 -51
  37. package/src/utils/formatter.ts +102 -102
  38. package/src/utils/time.ts +21 -21
  39. package/src/utils/utils.ts +8 -8
  40. package/tsconfig.json +23 -23
@@ -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,33 +1,35 @@
1
- import WalletWeb3, { useWalletStore } from '@dodoex/wallet-web3';
2
- import React from 'react';
3
- import Dialog from '../components/Dialog';
4
- import ConnectPage, { ConnectPageProps } from './ConnectPage';
5
-
6
- export default function ConnectDialog({
7
- open,
8
- onClose,
9
- walletWeb3,
10
- onConnectWallet,
11
- WalletTag,
12
- }: {
13
- open: boolean;
14
- onClose: () => void;
15
- walletWeb3: WalletWeb3;
16
- onConnectWallet?: ConnectPageProps['onConnectWallet'];
17
- WalletTag?: ConnectPageProps['WalletTag'];
18
- }) {
19
- const { account, chainId: connectChainId } = useWalletStore();
20
- return (
21
- <Dialog open={open} onClose={onClose} width={420}>
22
- <ConnectPage
23
- chainId={connectChainId}
24
- account={account}
25
- walletWeb3={walletWeb3}
26
- showOtherInjectWallet
27
- onClose={onClose}
28
- onConnectWallet={onConnectWallet}
29
- WalletTag={WalletTag}
30
- />
31
- </Dialog>
32
- );
33
- }
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
+ }
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import { useEffect, useMemo, useState } from 'react';
2
4
  import { getTransport } from './helper';
3
5
  import ProtocolDialog from './ProtocolDialog';