@dodoex/wallet-web3-react 0.2.0 → 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 +91 -76
  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 -146
  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,102 +1,102 @@
1
- import BigNumber from 'bignumber.js';
2
-
3
- const kilo = 1000;
4
- const million = 1000000;
5
- // const billion = 1000000000;
6
- function getNegative(num: number) {
7
- return new BigNumber(num).negated();
8
- }
9
- /**
10
- * format to short number, like: -0.12 -> 0, 0.0000123->0.000012, 123.234 -> 123.23, 1234.12 -> 1.23K, 1000000.123->1.00M
11
- * @param n
12
- */
13
- export function formatShortNumber(n?: BigNumber, showDecimals = 4): string {
14
- if (!n || n.isNaN()) {
15
- return '-';
16
- }
17
- if (n.eq(0)) {
18
- return '0';
19
- }
20
- if (n.lte(0.000001) && n.gte(-0.000001)) {
21
- return n.toExponential(2);
22
- }
23
- if (n.lt(1) && n.gt(-1)) {
24
- return formatReadableNumber({ input: n, showDecimals });
25
- }
26
- if (n.lt(kilo) && n.gt(getNegative(kilo))) {
27
- return formatReadableNumber({ input: n, showDecimals });
28
- }
29
- if (n.lt(million) && n.gt(getNegative(million))) {
30
- return `${formatReadableNumber({ input: n.div(kilo), showDecimals: 2 })}K`;
31
- }
32
- return `${formatReadableNumber({
33
- input: n.div(million),
34
- showDecimals: 2,
35
- })}M`;
36
- }
37
-
38
- /**
39
- * format to readable number, like: 0.00 -> 0, 1.00 -> 1, 1.235 -> 1.23, 1.230 -> 1.23
40
- * @param input
41
- */
42
- export function formatReadableNumber({
43
- input,
44
- showDecimals = 4,
45
- showPrecisionDecimals = 2,
46
- exponentialDecimalsAmount = 8,
47
- showIntegerOnly = false,
48
- showDecimalsOnly = false,
49
- noGroupSeparator = false,
50
- roundingMode = BigNumber.ROUND_DOWN,
51
- }: {
52
- input: BigNumber | number | string;
53
- showDecimals?: number;
54
- showIntegerOnly?: boolean;
55
- showDecimalsOnly?: boolean;
56
- showPrecisionDecimals?: number;
57
- exponentialDecimalsAmount?: number;
58
- noGroupSeparator?: boolean;
59
- roundingMode?: BigNumber.RoundingMode;
60
- }): string {
61
- const source = new BigNumber(input);
62
- if (source.isNaN()) {
63
- return '-';
64
- }
65
- let amount = source.dp(showDecimals, roundingMode);
66
- if (amount.eq(0) && (source.gt(0) || source.lt(0))) {
67
- const significantDigits = showPrecisionDecimals ?? showDecimals;
68
- amount = source.sd(significantDigits, BigNumber.ROUND_DOWN);
69
- const amountDP = amount.dp();
70
- if (
71
- amountDP &&
72
- amountDP > exponentialDecimalsAmount &&
73
- !showDecimalsOnly &&
74
- !showIntegerOnly
75
- ) {
76
- return amount.toExponential();
77
- }
78
-
79
- amount = source.sd(
80
- showPrecisionDecimals ?? showDecimals,
81
- BigNumber.ROUND_DOWN,
82
- );
83
- }
84
- if (showIntegerOnly) {
85
- amount = amount.integerValue(BigNumber.ROUND_DOWN);
86
- }
87
- if (showDecimalsOnly) {
88
- amount = amount.minus(amount.integerValue(BigNumber.ROUND_DOWN));
89
- }
90
-
91
- if (noGroupSeparator) {
92
- return amount.toFormat({
93
- decimalSeparator: '.',
94
- groupSeparator: '',
95
- groupSize: 3,
96
- secondaryGroupSize: 0,
97
- fractionGroupSeparator: '',
98
- fractionGroupSize: 0,
99
- });
100
- }
101
- return amount.toFormat();
102
- }
1
+ import BigNumber from 'bignumber.js';
2
+
3
+ const kilo = 1000;
4
+ const million = 1000000;
5
+ // const billion = 1000000000;
6
+ function getNegative(num: number) {
7
+ return new BigNumber(num).negated();
8
+ }
9
+ /**
10
+ * format to short number, like: -0.12 -> 0, 0.0000123->0.000012, 123.234 -> 123.23, 1234.12 -> 1.23K, 1000000.123->1.00M
11
+ * @param n
12
+ */
13
+ export function formatShortNumber(n?: BigNumber, showDecimals = 4): string {
14
+ if (!n || n.isNaN()) {
15
+ return '-';
16
+ }
17
+ if (n.eq(0)) {
18
+ return '0';
19
+ }
20
+ if (n.lte(0.000001) && n.gte(-0.000001)) {
21
+ return n.toExponential(2);
22
+ }
23
+ if (n.lt(1) && n.gt(-1)) {
24
+ return formatReadableNumber({ input: n, showDecimals });
25
+ }
26
+ if (n.lt(kilo) && n.gt(getNegative(kilo))) {
27
+ return formatReadableNumber({ input: n, showDecimals });
28
+ }
29
+ if (n.lt(million) && n.gt(getNegative(million))) {
30
+ return `${formatReadableNumber({ input: n.div(kilo), showDecimals: 2 })}K`;
31
+ }
32
+ return `${formatReadableNumber({
33
+ input: n.div(million),
34
+ showDecimals: 2,
35
+ })}M`;
36
+ }
37
+
38
+ /**
39
+ * format to readable number, like: 0.00 -> 0, 1.00 -> 1, 1.235 -> 1.23, 1.230 -> 1.23
40
+ * @param input
41
+ */
42
+ export function formatReadableNumber({
43
+ input,
44
+ showDecimals = 4,
45
+ showPrecisionDecimals = 2,
46
+ exponentialDecimalsAmount = 8,
47
+ showIntegerOnly = false,
48
+ showDecimalsOnly = false,
49
+ noGroupSeparator = false,
50
+ roundingMode = BigNumber.ROUND_DOWN,
51
+ }: {
52
+ input: BigNumber | number | string;
53
+ showDecimals?: number;
54
+ showIntegerOnly?: boolean;
55
+ showDecimalsOnly?: boolean;
56
+ showPrecisionDecimals?: number;
57
+ exponentialDecimalsAmount?: number;
58
+ noGroupSeparator?: boolean;
59
+ roundingMode?: BigNumber.RoundingMode;
60
+ }): string {
61
+ const source = new BigNumber(input);
62
+ if (source.isNaN()) {
63
+ return '-';
64
+ }
65
+ let amount = source.dp(showDecimals, roundingMode);
66
+ if (amount.eq(0) && (source.gt(0) || source.lt(0))) {
67
+ const significantDigits = showPrecisionDecimals ?? showDecimals;
68
+ amount = source.sd(significantDigits, BigNumber.ROUND_DOWN);
69
+ const amountDP = amount.dp();
70
+ if (
71
+ amountDP &&
72
+ amountDP > exponentialDecimalsAmount &&
73
+ !showDecimalsOnly &&
74
+ !showIntegerOnly
75
+ ) {
76
+ return amount.toExponential();
77
+ }
78
+
79
+ amount = source.sd(
80
+ showPrecisionDecimals ?? showDecimals,
81
+ BigNumber.ROUND_DOWN,
82
+ );
83
+ }
84
+ if (showIntegerOnly) {
85
+ amount = amount.integerValue(BigNumber.ROUND_DOWN);
86
+ }
87
+ if (showDecimalsOnly) {
88
+ amount = amount.minus(amount.integerValue(BigNumber.ROUND_DOWN));
89
+ }
90
+
91
+ if (noGroupSeparator) {
92
+ return amount.toFormat({
93
+ decimalSeparator: '.',
94
+ groupSeparator: '',
95
+ groupSize: 3,
96
+ secondaryGroupSize: 0,
97
+ fractionGroupSeparator: '',
98
+ fractionGroupSize: 0,
99
+ });
100
+ }
101
+ return amount.toFormat();
102
+ }
package/src/utils/time.ts CHANGED
@@ -1,21 +1,21 @@
1
- import dayjs from 'dayjs';
2
-
3
- export function formatReadableTimeAgo({ time }: { time: number }) {
4
- if (!time) {
5
- return '';
6
- }
7
- const start = dayjs(time);
8
- const end = dayjs();
9
- const diffHours = end.diff(start, 'h');
10
- if (diffHours > 24) {
11
- return start.format('YYYY/MM/DD HH:MM');
12
- }
13
- if (diffHours >= 1) {
14
- return `${diffHours}h ago`;
15
- }
16
- const diffMinute = end.diff(start, 'm');
17
- if (diffMinute >= 1) {
18
- return `${diffMinute}min ago`;
19
- }
20
- return `${end.diff(start, 's')}s`;
21
- }
1
+ import dayjs from 'dayjs';
2
+
3
+ export function formatReadableTimeAgo({ time }: { time: number }) {
4
+ if (!time) {
5
+ return '';
6
+ }
7
+ const start = dayjs(time);
8
+ const end = dayjs();
9
+ const diffHours = end.diff(start, 'h');
10
+ if (diffHours > 24) {
11
+ return start.format('YYYY/MM/DD HH:MM');
12
+ }
13
+ if (diffHours >= 1) {
14
+ return `${diffHours}h ago`;
15
+ }
16
+ const diffMinute = end.diff(start, 'm');
17
+ if (diffMinute >= 1) {
18
+ return `${diffMinute}min ago`;
19
+ }
20
+ return `${end.diff(start, 's')}s`;
21
+ }
@@ -1,8 +1,8 @@
1
- export const increaseArray = (len: number) => {
2
- return Object.keys(new Array(len + 1).join(','));
3
- };
4
-
5
- export const validateEmail = (email: string) => {
6
- const re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/g;
7
- return re.test(email);
8
- };
1
+ export const increaseArray = (len: number) => {
2
+ return Object.keys(new Array(len + 1).join(','));
3
+ };
4
+
5
+ export const validateEmail = (email: string) => {
6
+ const re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/g;
7
+ return re.test(email);
8
+ };
package/tsconfig.json CHANGED
@@ -1,23 +1,23 @@
1
- {
2
- "compilerOptions": {
3
- "lib": ["dom", "dom.iterable", "esnext"],
4
- "allowJs": true,
5
- "skipLibCheck": true,
6
- "strict": true,
7
- "forceConsistentCasingInFileNames": true,
8
- "noEmit": false,
9
- "esModuleInterop": true,
10
- "module": "esnext",
11
- "moduleResolution": "node",
12
- "resolveJsonModule": true,
13
- "isolatedModules": true,
14
- "downlevelIteration": true,
15
- "newLine": "CRLF",
16
- "declaration": true,
17
- "declarationDir": "./dist/types",
18
- "jsx": "preserve",
19
- "target": "es2016"
20
- },
21
- "exclude": ["node_modules", "types", "src/locales"],
22
- "include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.tsx"]
23
- }
1
+ {
2
+ "compilerOptions": {
3
+ "lib": ["dom", "dom.iterable", "esnext"],
4
+ "allowJs": true,
5
+ "skipLibCheck": true,
6
+ "strict": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "noEmit": false,
9
+ "esModuleInterop": true,
10
+ "module": "esnext",
11
+ "moduleResolution": "node",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "downlevelIteration": true,
15
+ "newLine": "CRLF",
16
+ "declaration": true,
17
+ "declarationDir": "./dist/types",
18
+ "jsx": "preserve",
19
+ "target": "es2016"
20
+ },
21
+ "exclude": ["node_modules", "types", "src/locales"],
22
+ "include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.tsx"]
23
+ }