@dynamic-labs/sdk-react-core 0.17.28 → 0.17.30
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/CHANGELOG.md +14 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/lib/utils/hooks/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.cjs +42 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.d.ts +2 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.js +38 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.cjs +3 -9
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.js +4 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
|
|
2
|
+
### [0.17.30](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.29...v0.17.30) (2023-08-01)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* ensure auto-redirect back to dapp after message signing
|
|
8
|
+
|
|
9
|
+
### [0.17.29](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.28...v0.17.29) (2023-07-28)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* **transaction:** improve gas estimate in transaction confirmation ([#2756](https://github.com/dynamic-labs/DynamicAuth/issues/2756)) ([a45c99d](https://github.com/dynamic-labs/DynamicAuth/commit/a45c99d40208a17f206e192d72c3ce599389069b))
|
|
15
|
+
|
|
2
16
|
### [0.17.28](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.27...v0.17.28) (2023-07-26)
|
|
3
17
|
|
|
4
18
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.30",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"formik": "2.2.9",
|
|
17
17
|
"qrcode": "1.5.1",
|
|
18
18
|
"ethers": "5.7.2",
|
|
19
|
-
"@dynamic-labs/logger": "0.17.
|
|
20
|
-
"@dynamic-labs/multi-wallet": "0.17.
|
|
21
|
-
"@dynamic-labs/rpc-providers": "0.17.
|
|
22
|
-
"@dynamic-labs/types": "0.17.
|
|
23
|
-
"@dynamic-labs/utils": "0.17.
|
|
24
|
-
"@dynamic-labs/wallet-book": "0.17.
|
|
25
|
-
"@dynamic-labs/wallet-connector-core": "0.17.
|
|
19
|
+
"@dynamic-labs/logger": "0.17.30",
|
|
20
|
+
"@dynamic-labs/multi-wallet": "0.17.30",
|
|
21
|
+
"@dynamic-labs/rpc-providers": "0.17.30",
|
|
22
|
+
"@dynamic-labs/types": "0.17.30",
|
|
23
|
+
"@dynamic-labs/utils": "0.17.30",
|
|
24
|
+
"@dynamic-labs/wallet-book": "0.17.30",
|
|
25
|
+
"@dynamic-labs/wallet-connector-core": "0.17.30"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"semver": "7.3.8"
|
|
@@ -25,3 +25,4 @@ export { useGetSocialIcon } from './useGetSocialIcon';
|
|
|
25
25
|
export { useIconThemeVariant } from './useIconThemeVariant';
|
|
26
26
|
export type { IconThemeVariant } from './useIconThemeVariant';
|
|
27
27
|
export { useTransactionWithGasPrice } from './useTransactionWithGasPrice';
|
|
28
|
+
export { useTransactionEstimatedGas } from './useTransactionEstimatedGas';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTransactionEstimatedGas } from './useTransactionEstimatedGas';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
6
|
+
var usePromise = require('../usePromise/usePromise.cjs');
|
|
7
|
+
require('@dynamic-labs/sdk-api');
|
|
8
|
+
var logger = require('../../../shared/logger.cjs');
|
|
9
|
+
require('../../../config/LSSuffix.cjs');
|
|
10
|
+
require('@dynamic-labs/iconic');
|
|
11
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
12
|
+
require('react/jsx-runtime');
|
|
13
|
+
require('../../../context/ViewContext/ViewContext.cjs');
|
|
14
|
+
require('react');
|
|
15
|
+
require('@dynamic-labs/utils');
|
|
16
|
+
require('../../constants/colors.cjs');
|
|
17
|
+
require('ethers');
|
|
18
|
+
require('../../../shared/consts/index.cjs');
|
|
19
|
+
|
|
20
|
+
const useTransactionEstimatedGas = (provider, transaction) => usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
// To safely run estimateGas using alchemy, we need to remove the from address
|
|
22
|
+
// because alchemy checks the origin address funds and can return an error if
|
|
23
|
+
// origin wallet has no funds for the transaction
|
|
24
|
+
// https://docs.alchemy.com/reference/eth-estimategas
|
|
25
|
+
const { from } = transaction, transactionWithNoOrigin = _tslib.__rest(transaction, ["from"]);
|
|
26
|
+
try {
|
|
27
|
+
return yield provider.estimateGas(transactionWithNoOrigin);
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
logger.logger.error(err);
|
|
32
|
+
// If the error is UNPREDICTABLE_GAS_LIMIT, we try to estimate gas again
|
|
33
|
+
// with original transaction
|
|
34
|
+
// https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT
|
|
35
|
+
if (err.code === 'UNPREDICTABLE_GAS_LIMIT') {
|
|
36
|
+
return provider.estimateGas(transaction);
|
|
37
|
+
}
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
exports.useTransactionEstimatedGas = useTransactionEstimatedGas;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __awaiter, __rest } from '../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { usePromise } from '../usePromise/usePromise.js';
|
|
3
|
+
import '@dynamic-labs/sdk-api';
|
|
4
|
+
import { logger } from '../../../shared/logger.js';
|
|
5
|
+
import '../../../config/LSSuffix.js';
|
|
6
|
+
import '@dynamic-labs/iconic';
|
|
7
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
8
|
+
import 'react/jsx-runtime';
|
|
9
|
+
import '../../../context/ViewContext/ViewContext.js';
|
|
10
|
+
import 'react';
|
|
11
|
+
import '@dynamic-labs/utils';
|
|
12
|
+
import '../../constants/colors.js';
|
|
13
|
+
import 'ethers';
|
|
14
|
+
import '../../../shared/consts/index.js';
|
|
15
|
+
|
|
16
|
+
const useTransactionEstimatedGas = (provider, transaction) => usePromise(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
// To safely run estimateGas using alchemy, we need to remove the from address
|
|
18
|
+
// because alchemy checks the origin address funds and can return an error if
|
|
19
|
+
// origin wallet has no funds for the transaction
|
|
20
|
+
// https://docs.alchemy.com/reference/eth-estimategas
|
|
21
|
+
const { from } = transaction, transactionWithNoOrigin = __rest(transaction, ["from"]);
|
|
22
|
+
try {
|
|
23
|
+
return yield provider.estimateGas(transactionWithNoOrigin);
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
logger.error(err);
|
|
28
|
+
// If the error is UNPREDICTABLE_GAS_LIMIT, we try to estimate gas again
|
|
29
|
+
// with original transaction
|
|
30
|
+
// https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT
|
|
31
|
+
if (err.code === 'UNPREDICTABLE_GAS_LIMIT') {
|
|
32
|
+
return provider.estimateGas(transaction);
|
|
33
|
+
}
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
export { useTransactionEstimatedGas };
|
package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.cjs
CHANGED
|
@@ -40,20 +40,14 @@ require('../../../../context/MockContext/MockContext.cjs');
|
|
|
40
40
|
require('../../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
41
41
|
var usePromise = require('../../../../utils/hooks/usePromise/usePromise.cjs');
|
|
42
42
|
require('../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.cjs');
|
|
43
|
+
var useTransactionEstimatedGas = require('../../../../utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.cjs');
|
|
43
44
|
|
|
44
45
|
const useTransactionData = ({ provider, transaction, }) => {
|
|
45
46
|
const { data: transactionValue, isLoading: isEffectiveValueLoading } = usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
46
47
|
const val = yield transaction.value;
|
|
47
48
|
return val ? ethers.ethers.BigNumber.from(val) : undefined;
|
|
48
49
|
}));
|
|
49
|
-
const { data: estimatedGas, isLoading: isEstimatedGasLoading } =
|
|
50
|
-
// To safely run estimateGas using alchemy, we need to remove the from address
|
|
51
|
-
// because alchemy checks the origin address funds and can return an error if
|
|
52
|
-
// origin wallet has no funds for the transaction
|
|
53
|
-
// https://docs.alchemy.com/reference/eth-estimategas
|
|
54
|
-
const { from } = transaction, transactionWithNoOrigin = _tslib.__rest(transaction, ["from"]);
|
|
55
|
-
return provider.estimateGas(transactionWithNoOrigin);
|
|
56
|
-
});
|
|
50
|
+
const { data: estimatedGas, isLoading: isEstimatedGasLoading } = useTransactionEstimatedGas.useTransactionEstimatedGas(provider, transaction);
|
|
57
51
|
const { data: providerGasPrice, isLoading: isProviderGasPrice } = usePromise.usePromise(() => provider.getGasPrice(), []);
|
|
58
52
|
const { data: transactionGasPrice, isLoading: isTransactionGasPriceLoading } = usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
59
53
|
const gasPrice = yield transaction.gasPrice;
|
|
@@ -74,7 +68,7 @@ const useTransactionData = ({ provider, transaction, }) => {
|
|
|
74
68
|
if (transactionGasFee !== undefined && transactionValue !== undefined) {
|
|
75
69
|
return transactionGasFee.add(transactionValue);
|
|
76
70
|
}
|
|
77
|
-
return transactionValue ||
|
|
71
|
+
return transactionValue || transactionGasFee;
|
|
78
72
|
}, [gasEstimate, transactionGas, transactionValue]);
|
|
79
73
|
const isLoading = React.useMemo(() => isEffectiveValueLoading ||
|
|
80
74
|
isGasPriceLoading ||
|
package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __awaiter
|
|
1
|
+
import { __awaiter } from '../../../../../../_virtual/_tslib.js';
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { ethers } from 'ethers';
|
|
4
4
|
import '@dynamic-labs/utils';
|
|
@@ -36,20 +36,14 @@ import '../../../../context/MockContext/MockContext.js';
|
|
|
36
36
|
import '../../../../context/CaptchaContext/CaptchaContext.js';
|
|
37
37
|
import { usePromise } from '../../../../utils/hooks/usePromise/usePromise.js';
|
|
38
38
|
import '../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js';
|
|
39
|
+
import { useTransactionEstimatedGas } from '../../../../utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.js';
|
|
39
40
|
|
|
40
41
|
const useTransactionData = ({ provider, transaction, }) => {
|
|
41
42
|
const { data: transactionValue, isLoading: isEffectiveValueLoading } = usePromise(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
43
|
const val = yield transaction.value;
|
|
43
44
|
return val ? ethers.BigNumber.from(val) : undefined;
|
|
44
45
|
}));
|
|
45
|
-
const { data: estimatedGas, isLoading: isEstimatedGasLoading } =
|
|
46
|
-
// To safely run estimateGas using alchemy, we need to remove the from address
|
|
47
|
-
// because alchemy checks the origin address funds and can return an error if
|
|
48
|
-
// origin wallet has no funds for the transaction
|
|
49
|
-
// https://docs.alchemy.com/reference/eth-estimategas
|
|
50
|
-
const { from } = transaction, transactionWithNoOrigin = __rest(transaction, ["from"]);
|
|
51
|
-
return provider.estimateGas(transactionWithNoOrigin);
|
|
52
|
-
});
|
|
46
|
+
const { data: estimatedGas, isLoading: isEstimatedGasLoading } = useTransactionEstimatedGas(provider, transaction);
|
|
53
47
|
const { data: providerGasPrice, isLoading: isProviderGasPrice } = usePromise(() => provider.getGasPrice(), []);
|
|
54
48
|
const { data: transactionGasPrice, isLoading: isTransactionGasPriceLoading } = usePromise(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
49
|
const gasPrice = yield transaction.gasPrice;
|
|
@@ -70,7 +64,7 @@ const useTransactionData = ({ provider, transaction, }) => {
|
|
|
70
64
|
if (transactionGasFee !== undefined && transactionValue !== undefined) {
|
|
71
65
|
return transactionGasFee.add(transactionValue);
|
|
72
66
|
}
|
|
73
|
-
return transactionValue ||
|
|
67
|
+
return transactionValue || transactionGasFee;
|
|
74
68
|
}, [gasEstimate, transactionGas, transactionValue]);
|
|
75
69
|
const isLoading = useMemo(() => isEffectiveValueLoading ||
|
|
76
70
|
isGasPriceLoading ||
|