@dynamic-labs/sdk-react-core 0.17.27 → 0.17.28
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 +7 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.cjs +1 -1
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.js +1 -1
- package/src/lib/context/DynamicContext/DynamicContext.cjs +4 -4
- package/src/lib/context/DynamicContext/DynamicContext.d.ts +2 -2
- package/src/lib/context/DynamicContext/DynamicContext.js +4 -4
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.cjs +3 -3
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +3 -3
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.cjs +10 -2
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.js +10 -2
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.types.d.ts +2 -0
- package/src/lib/utils/functions/index.d.ts +1 -0
- package/src/lib/utils/functions/isMagicConnector/index.d.ts +1 -0
- package/src/lib/utils/functions/isMagicConnector/isMagicConnector.cjs +10 -0
- package/src/lib/utils/functions/isMagicConnector/isMagicConnector.d.ts +2 -0
- package/src/lib/utils/functions/isMagicConnector/isMagicConnector.js +6 -0
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +2 -2
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +2 -2
- package/src/lib/utils/hooks/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.cjs +41 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.d.ts +32 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.js +37 -0
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.cjs +20 -19
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.d.ts +4 -1
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.js +20 -19
- package/src/lib/utils/hooks/useWallets/useWallets.cjs +3 -3
- package/src/lib/utils/hooks/useWallets/useWallets.d.ts +3 -3
- package/src/lib/utils/hooks/useWallets/useWallets.js +3 -3
- package/src/lib/views/SendBalanceView/SendBalanceView.cjs +9 -16
- package/src/lib/views/SendBalanceView/SendBalanceView.js +9 -16
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.cjs +63 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.d.ts +8 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.js +59 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/index.d.ts +1 -0
- package/src/lib/views/SendBalanceView/components/index.d.ts +1 -0
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +2 -2
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +2 -2
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.cjs +21 -8
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.d.ts +4 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.js +21 -8
|
@@ -54,27 +54,28 @@ const useWalletUiUtils = ({ appLogoUrl, appName, getAppOrigin, }) => {
|
|
|
54
54
|
}
|
|
55
55
|
return true;
|
|
56
56
|
}, [confirmationStateRef]);
|
|
57
|
-
const
|
|
58
|
-
if (!shouldConfirmAction()) {
|
|
59
|
-
return handler(message);
|
|
60
|
-
}
|
|
61
|
-
return openSignMessage((resolve, reject) => (jsx(SignMessageConfirmationModal, { appLogoUrl: appLogoUrl, appName: appName, appOrigin: getAppOrigin(), message: message, handler: handler, onSignMessage: resolve, onReject: reject })));
|
|
62
|
-
}, [appLogoUrl, appName, getAppOrigin, openSignMessage, shouldConfirmAction]);
|
|
63
|
-
const sendTransaction = useCallback(({ transaction, handler, provider }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
-
if (!shouldConfirmAction()) {
|
|
65
|
-
return handler(transaction);
|
|
66
|
-
}
|
|
67
|
-
return openSendTransaction((resolve, reject) => (jsx(TransactionConfirmationModal, { title: 'Send Transaction', transaction: transaction, handler: handler, onTransactionResponseSuccess: resolve, onReject: reject, provider: provider })));
|
|
68
|
-
}), [openSendTransaction, shouldConfirmAction]);
|
|
69
|
-
const disabledConfirmationOnce = useCallback(() => {
|
|
57
|
+
const disableConfirmationOnce = useCallback(() => {
|
|
70
58
|
confirmationStateRef.current = 'disabled';
|
|
71
59
|
}, []);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
60
|
+
const createWalletUiUtils = useCallback((walletConnector) => ({
|
|
61
|
+
sendTransaction: ({ transaction, handler, provider }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
if (!shouldConfirmAction()) {
|
|
63
|
+
return handler(transaction);
|
|
64
|
+
}
|
|
65
|
+
return openSendTransaction((resolve, reject) => (jsx(TransactionConfirmationModal, { title: 'Send Transaction', transaction: transaction, handler: handler, onTransactionResponseSuccess: resolve, onReject: reject, provider: provider, walletConnector: walletConnector })));
|
|
66
|
+
}),
|
|
67
|
+
signMessage: ({ message, handler }) => {
|
|
68
|
+
if (!shouldConfirmAction()) {
|
|
69
|
+
return handler(message);
|
|
70
|
+
}
|
|
71
|
+
return openSignMessage((resolve, reject) => (jsx(SignMessageConfirmationModal, { appLogoUrl: appLogoUrl, appName: appName, appOrigin: getAppOrigin(), message: message, handler: handler, onSignMessage: resolve, onReject: reject })));
|
|
72
|
+
},
|
|
73
|
+
}), [shouldConfirmAction]);
|
|
74
|
+
return useMemo(() => [
|
|
75
|
+
modal || sendTransactionModal,
|
|
76
|
+
createWalletUiUtils,
|
|
77
|
+
{ disableConfirmationOnce },
|
|
78
|
+
], [modal, sendTransactionModal, createWalletUiUtils, disableConfirmationOnce]);
|
|
78
79
|
};
|
|
79
80
|
|
|
80
81
|
export { useWalletUiUtils };
|
|
@@ -5,31 +5,31 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var data = require('../../../views/WalletList/data.cjs');
|
|
7
7
|
|
|
8
|
-
const useWallets = ({ projectSettings, appLogoUrl, appName, flowNetwork, networkConfigurations, walletConnectV1Bridge,
|
|
8
|
+
const useWallets = ({ projectSettings, appLogoUrl, appName, flowNetwork, networkConfigurations, walletConnectV1Bridge, createWalletUiUtils, walletConnectorsProp, }) => {
|
|
9
9
|
const wallets = React.useMemo(() => {
|
|
10
10
|
if (!projectSettings)
|
|
11
11
|
return [];
|
|
12
12
|
const installedWallets = data.getInstalledWallets(projectSettings, {
|
|
13
13
|
appLogoUrl,
|
|
14
14
|
appName,
|
|
15
|
+
createWalletUiUtils,
|
|
15
16
|
customerApiProviders: projectSettings.providers || [],
|
|
16
17
|
flowNetwork,
|
|
17
18
|
networkConfigurations,
|
|
18
19
|
skipMemo: true,
|
|
19
20
|
walletConnectV1Bridge,
|
|
20
21
|
walletConnectorsProp: walletConnectorsProp !== null && walletConnectorsProp !== void 0 ? walletConnectorsProp : [],
|
|
21
|
-
walletUiUtils,
|
|
22
22
|
});
|
|
23
23
|
const notInstalledWallets = data.getNotInstalledWallets(projectSettings, {
|
|
24
24
|
appLogoUrl,
|
|
25
25
|
appName,
|
|
26
|
+
createWalletUiUtils,
|
|
26
27
|
customerApiProviders: projectSettings.providers || [],
|
|
27
28
|
flowNetwork,
|
|
28
29
|
networkConfigurations,
|
|
29
30
|
skipMemo: true,
|
|
30
31
|
walletConnectV1Bridge,
|
|
31
32
|
walletConnectorsProp: walletConnectorsProp !== null && walletConnectorsProp !== void 0 ? walletConnectorsProp : [],
|
|
32
|
-
walletUiUtils,
|
|
33
33
|
});
|
|
34
34
|
return [...installedWallets, ...notInstalledWallets];
|
|
35
35
|
// Cannot include walletUiUtils in the dependency array because it will cause an infinite loop
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProjectSettings } from '@dynamic-labs/sdk-api';
|
|
2
2
|
import { NetworkConfigurationMap, WalletUiUtils } from '@dynamic-labs/types';
|
|
3
|
-
import { WalletConnectorsMethod } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { WalletConnector, WalletConnectorsMethod } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
type Props = {
|
|
5
5
|
appLogoUrl?: string;
|
|
6
6
|
appName?: string;
|
|
@@ -9,9 +9,9 @@ type Props = {
|
|
|
9
9
|
projectSettings: ProjectSettings | undefined;
|
|
10
10
|
walletConnectV1Bridge?: string;
|
|
11
11
|
walletConnectorsProp?: WalletConnectorsMethod[];
|
|
12
|
-
|
|
12
|
+
createWalletUiUtils: (connector: WalletConnector) => WalletUiUtils;
|
|
13
13
|
};
|
|
14
|
-
export declare const useWallets: ({ projectSettings, appLogoUrl, appName, flowNetwork, networkConfigurations, walletConnectV1Bridge,
|
|
14
|
+
export declare const useWallets: ({ projectSettings, appLogoUrl, appName, flowNetwork, networkConfigurations, walletConnectV1Bridge, createWalletUiUtils, walletConnectorsProp, }: Props) => {
|
|
15
15
|
wallets: import("../../../shared").WalletOption[];
|
|
16
16
|
};
|
|
17
17
|
export {};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { getInstalledWallets, getNotInstalledWallets } from '../../../views/WalletList/data.js';
|
|
3
3
|
|
|
4
|
-
const useWallets = ({ projectSettings, appLogoUrl, appName, flowNetwork, networkConfigurations, walletConnectV1Bridge,
|
|
4
|
+
const useWallets = ({ projectSettings, appLogoUrl, appName, flowNetwork, networkConfigurations, walletConnectV1Bridge, createWalletUiUtils, walletConnectorsProp, }) => {
|
|
5
5
|
const wallets = useMemo(() => {
|
|
6
6
|
if (!projectSettings)
|
|
7
7
|
return [];
|
|
8
8
|
const installedWallets = getInstalledWallets(projectSettings, {
|
|
9
9
|
appLogoUrl,
|
|
10
10
|
appName,
|
|
11
|
+
createWalletUiUtils,
|
|
11
12
|
customerApiProviders: projectSettings.providers || [],
|
|
12
13
|
flowNetwork,
|
|
13
14
|
networkConfigurations,
|
|
14
15
|
skipMemo: true,
|
|
15
16
|
walletConnectV1Bridge,
|
|
16
17
|
walletConnectorsProp: walletConnectorsProp !== null && walletConnectorsProp !== void 0 ? walletConnectorsProp : [],
|
|
17
|
-
walletUiUtils,
|
|
18
18
|
});
|
|
19
19
|
const notInstalledWallets = getNotInstalledWallets(projectSettings, {
|
|
20
20
|
appLogoUrl,
|
|
21
21
|
appName,
|
|
22
|
+
createWalletUiUtils,
|
|
22
23
|
customerApiProviders: projectSettings.providers || [],
|
|
23
24
|
flowNetwork,
|
|
24
25
|
networkConfigurations,
|
|
25
26
|
skipMemo: true,
|
|
26
27
|
walletConnectV1Bridge,
|
|
27
28
|
walletConnectorsProp: walletConnectorsProp !== null && walletConnectorsProp !== void 0 ? walletConnectorsProp : [],
|
|
28
|
-
walletUiUtils,
|
|
29
29
|
});
|
|
30
30
|
return [...installedWallets, ...notInstalledWallets];
|
|
31
31
|
// Cannot include walletUiUtils in the dependency array because it will cause an infinite loop
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
6
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
6
|
var React = require('react');
|
|
8
7
|
var ethers = require('ethers');
|
|
@@ -39,9 +38,9 @@ require('../../components/Popper/Popper/Popper.cjs');
|
|
|
39
38
|
require('../../components/Popper/PopperContext/PopperContext.cjs');
|
|
40
39
|
var SendBalancePageLayout = require('../../components/SendBalancePageLayout/SendBalancePageLayout.cjs');
|
|
41
40
|
require('../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
42
|
-
var TransactionConfirmationView = require('../TransactionConfirmationView/TransactionConfirmationView.cjs');
|
|
43
|
-
var TransactionStatusLayout = require('../../components/TransactionStatusLayout/TransactionStatusLayout.cjs');
|
|
44
41
|
var useFetchCurrency = require('../../widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.cjs');
|
|
42
|
+
var TransactionStatusLayout = require('../../components/TransactionStatusLayout/TransactionStatusLayout.cjs');
|
|
43
|
+
var TransactionStage = require('./components/TransactionStage/TransactionStage.cjs');
|
|
45
44
|
require('../../context/MockContext/MockContext.cjs');
|
|
46
45
|
require('../../context/CaptchaContext/CaptchaContext.cjs');
|
|
47
46
|
var usePromise = require('../../utils/hooks/usePromise/usePromise.cjs');
|
|
@@ -49,18 +48,17 @@ require('../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.cjs');
|
|
|
49
48
|
|
|
50
49
|
const SendBalanceView = ({ initialRecipientAddress = '', initialValue, onClickBack, onClickClose, onError, onSuccess, onDone, displayPoweredByDynamicFooter = false, }) => {
|
|
51
50
|
const [stage, setStage] = React.useState('form');
|
|
52
|
-
const { primaryWallet,
|
|
51
|
+
const { primaryWallet, network } = useInternalDynamicContext.useInternalDynamicContext();
|
|
53
52
|
const [value, setValue] = React.useState(initialValue !== null && initialValue !== void 0 ? initialValue : null);
|
|
54
53
|
const [recipientAddress, setRecipientAddress] = React.useState(initialRecipientAddress);
|
|
55
54
|
const transactionRef = React.useRef(null);
|
|
56
55
|
if (!primaryWallet) {
|
|
57
56
|
throw new utils.DynamicError('Primary wallet is not available, send balance cannot be displayed');
|
|
58
57
|
}
|
|
59
|
-
const
|
|
60
|
-
const { data:
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
[];
|
|
58
|
+
const walletConnector = primaryWallet.connector;
|
|
59
|
+
const { data: balance } = usePromise.usePromise(() => walletConnector.getBalance(), [walletConnector]);
|
|
60
|
+
const { data: provider } = usePromise.usePromise(() => walletConnector.getWeb3Provider(), [walletConnector]);
|
|
61
|
+
const evmNetworks = (walletConnector && walletConnector.evmNetworks) || [];
|
|
64
62
|
const evmNetwork = evmNetworks.find((evmNetwork) => evmNetwork.chainId === network);
|
|
65
63
|
const networkIcon = evmNetwork && (jsxRuntime.jsx("img", { src: evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.iconUrls[0], alt: `${evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.name} icon` }));
|
|
66
64
|
const networkName = (evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.vanityName) || (evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.name);
|
|
@@ -85,16 +83,11 @@ const SendBalanceView = ({ initialRecipientAddress = '', initialValue, onClickBa
|
|
|
85
83
|
to: recipientAddress,
|
|
86
84
|
value,
|
|
87
85
|
};
|
|
88
|
-
return (jsxRuntime.jsx(
|
|
86
|
+
return (jsxRuntime.jsx(TransactionStage.TransactionStage, { walletConnector: walletConnector, provider: provider, transaction: transaction, title: 'Confirm transaction', onClickBack: () => setStage('form'), onError: onError, displayPoweredByDynamicFooter: displayPoweredByDynamicFooter, onSuccess: (transaction) => {
|
|
89
87
|
transactionRef.current = transaction;
|
|
90
88
|
setStage('success');
|
|
91
89
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionRef.current);
|
|
92
|
-
}
|
|
93
|
-
walletUiUtils.disabledConfirmationOnce();
|
|
94
|
-
const signer = provider.getSigner();
|
|
95
|
-
const sentTransaction = yield signer.sendTransaction(transaction);
|
|
96
|
-
return sentTransaction;
|
|
97
|
-
}) }));
|
|
90
|
+
} }));
|
|
98
91
|
};
|
|
99
92
|
const buildSuccessState = () => {
|
|
100
93
|
var _a;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
2
1
|
import { jsx } from 'react/jsx-runtime';
|
|
3
2
|
import { useState, useRef } from 'react';
|
|
4
3
|
import { utils } from 'ethers';
|
|
@@ -35,9 +34,9 @@ import '../../components/Popper/Popper/Popper.js';
|
|
|
35
34
|
import '../../components/Popper/PopperContext/PopperContext.js';
|
|
36
35
|
import { SendBalancePageLayout } from '../../components/SendBalancePageLayout/SendBalancePageLayout.js';
|
|
37
36
|
import '../../components/MenuList/Dropdown/Dropdown.js';
|
|
38
|
-
import { TransactionConfirmationView } from '../TransactionConfirmationView/TransactionConfirmationView.js';
|
|
39
|
-
import { TransactionStatusLayout } from '../../components/TransactionStatusLayout/TransactionStatusLayout.js';
|
|
40
37
|
import { useFetchCurrency } from '../../widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.js';
|
|
38
|
+
import { TransactionStatusLayout } from '../../components/TransactionStatusLayout/TransactionStatusLayout.js';
|
|
39
|
+
import { TransactionStage } from './components/TransactionStage/TransactionStage.js';
|
|
41
40
|
import '../../context/MockContext/MockContext.js';
|
|
42
41
|
import '../../context/CaptchaContext/CaptchaContext.js';
|
|
43
42
|
import { usePromise } from '../../utils/hooks/usePromise/usePromise.js';
|
|
@@ -45,18 +44,17 @@ import '../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js';
|
|
|
45
44
|
|
|
46
45
|
const SendBalanceView = ({ initialRecipientAddress = '', initialValue, onClickBack, onClickClose, onError, onSuccess, onDone, displayPoweredByDynamicFooter = false, }) => {
|
|
47
46
|
const [stage, setStage] = useState('form');
|
|
48
|
-
const { primaryWallet,
|
|
47
|
+
const { primaryWallet, network } = useInternalDynamicContext();
|
|
49
48
|
const [value, setValue] = useState(initialValue !== null && initialValue !== void 0 ? initialValue : null);
|
|
50
49
|
const [recipientAddress, setRecipientAddress] = useState(initialRecipientAddress);
|
|
51
50
|
const transactionRef = useRef(null);
|
|
52
51
|
if (!primaryWallet) {
|
|
53
52
|
throw new DynamicError('Primary wallet is not available, send balance cannot be displayed');
|
|
54
53
|
}
|
|
55
|
-
const
|
|
56
|
-
const { data:
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
[];
|
|
54
|
+
const walletConnector = primaryWallet.connector;
|
|
55
|
+
const { data: balance } = usePromise(() => walletConnector.getBalance(), [walletConnector]);
|
|
56
|
+
const { data: provider } = usePromise(() => walletConnector.getWeb3Provider(), [walletConnector]);
|
|
57
|
+
const evmNetworks = (walletConnector && walletConnector.evmNetworks) || [];
|
|
60
58
|
const evmNetwork = evmNetworks.find((evmNetwork) => evmNetwork.chainId === network);
|
|
61
59
|
const networkIcon = evmNetwork && (jsx("img", { src: evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.iconUrls[0], alt: `${evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.name} icon` }));
|
|
62
60
|
const networkName = (evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.vanityName) || (evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.name);
|
|
@@ -81,16 +79,11 @@ const SendBalanceView = ({ initialRecipientAddress = '', initialValue, onClickBa
|
|
|
81
79
|
to: recipientAddress,
|
|
82
80
|
value,
|
|
83
81
|
};
|
|
84
|
-
return (jsx(
|
|
82
|
+
return (jsx(TransactionStage, { walletConnector: walletConnector, provider: provider, transaction: transaction, title: 'Confirm transaction', onClickBack: () => setStage('form'), onError: onError, displayPoweredByDynamicFooter: displayPoweredByDynamicFooter, onSuccess: (transaction) => {
|
|
85
83
|
transactionRef.current = transaction;
|
|
86
84
|
setStage('success');
|
|
87
85
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionRef.current);
|
|
88
|
-
}
|
|
89
|
-
walletUiUtils.disabledConfirmationOnce();
|
|
90
|
-
const signer = provider.getSigner();
|
|
91
|
-
const sentTransaction = yield signer.sendTransaction(transaction);
|
|
92
|
-
return sentTransaction;
|
|
93
|
-
}) }));
|
|
86
|
+
} }));
|
|
94
87
|
};
|
|
95
88
|
const buildSuccessState = () => {
|
|
96
89
|
var _a;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../../../../../_virtual/_tslib.cjs');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
require('react');
|
|
8
|
+
require('@dynamic-labs/utils');
|
|
9
|
+
require('@dynamic-labs/sdk-api');
|
|
10
|
+
require('../../../../config/ApiEndpoint.cjs');
|
|
11
|
+
require('../../../../shared/logger.cjs');
|
|
12
|
+
require('../../../../config/LSSuffix.cjs');
|
|
13
|
+
require('@dynamic-labs/iconic');
|
|
14
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
15
|
+
require('../../../../context/ViewContext/ViewContext.cjs');
|
|
16
|
+
require('../../../../utils/constants/colors.cjs');
|
|
17
|
+
require('ethers');
|
|
18
|
+
require('../../../../shared/consts/index.cjs');
|
|
19
|
+
require('@dynamic-labs/multi-wallet');
|
|
20
|
+
var isMagicConnector = require('../../../../utils/functions/isMagicConnector/isMagicConnector.cjs');
|
|
21
|
+
require('@dynamic-labs/rpc-providers');
|
|
22
|
+
var useInternalDynamicContext = require('../../../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
23
|
+
require('../../../../context/ErrorContext/ErrorContext.cjs');
|
|
24
|
+
require('../../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
25
|
+
require('react-dom');
|
|
26
|
+
require('../../../../components/ShadowDOM/ShadowDOM.cjs');
|
|
27
|
+
require('../../../../context/ThemeContext/ThemeContext.cjs');
|
|
28
|
+
require('react-focus-lock');
|
|
29
|
+
require('../../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
|
|
30
|
+
require('../../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
31
|
+
require('../../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
|
|
32
|
+
require('../../../../components/IconButton/IconButton.cjs');
|
|
33
|
+
require('../../../../components/Alert/Alert.cjs');
|
|
34
|
+
require('@dynamic-labs/wallet-book');
|
|
35
|
+
require('../../../../components/Popper/Popper/Popper.cjs');
|
|
36
|
+
require('../../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
37
|
+
require('formik');
|
|
38
|
+
require('yup');
|
|
39
|
+
require('../../../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
40
|
+
var TransactionConfirmationView = require('../../../TransactionConfirmationView/TransactionConfirmationView.cjs');
|
|
41
|
+
require('../../../../context/MockContext/MockContext.cjs');
|
|
42
|
+
require('../../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
43
|
+
require('../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.cjs');
|
|
44
|
+
var useTransactionWithGasPrice = require('../../../../utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.cjs');
|
|
45
|
+
|
|
46
|
+
const TransactionStage = (_a) => {
|
|
47
|
+
var { transaction, provider, walletConnector } = _a, rest = _tslib.__rest(_a, ["transaction", "provider", "walletConnector"]);
|
|
48
|
+
const { disableWalletConfirmationOnce } = useInternalDynamicContext.useInternalDynamicContext();
|
|
49
|
+
const transactionWithGasPrice = useTransactionWithGasPrice.useTransactionWithGasPrice({
|
|
50
|
+
enabled: isMagicConnector.isMagicConnector(walletConnector),
|
|
51
|
+
increasePercentage: 5,
|
|
52
|
+
provider,
|
|
53
|
+
transaction,
|
|
54
|
+
});
|
|
55
|
+
return (jsxRuntime.jsx(TransactionConfirmationView.TransactionConfirmationView, Object.assign({ provider: provider, transaction: transactionWithGasPrice, mutation: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
disableWalletConfirmationOnce();
|
|
57
|
+
const signer = provider.getSigner();
|
|
58
|
+
const sentTransaction = yield signer.sendTransaction(transactionWithGasPrice);
|
|
59
|
+
return sentTransaction;
|
|
60
|
+
}) }, rest)));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
exports.TransactionStage = TransactionStage;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { TransactionConfirmationViewProps } from '../../../TransactionConfirmationView';
|
|
4
|
+
type TransactionStageProps = Omit<TransactionConfirmationViewProps, 'mutation'> & {
|
|
5
|
+
walletConnector: WalletConnector;
|
|
6
|
+
};
|
|
7
|
+
export declare const TransactionStage: FC<TransactionStageProps>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { __rest, __awaiter } from '../../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
4
|
+
import '@dynamic-labs/utils';
|
|
5
|
+
import '@dynamic-labs/sdk-api';
|
|
6
|
+
import '../../../../config/ApiEndpoint.js';
|
|
7
|
+
import '../../../../shared/logger.js';
|
|
8
|
+
import '../../../../config/LSSuffix.js';
|
|
9
|
+
import '@dynamic-labs/iconic';
|
|
10
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
11
|
+
import '../../../../context/ViewContext/ViewContext.js';
|
|
12
|
+
import '../../../../utils/constants/colors.js';
|
|
13
|
+
import 'ethers';
|
|
14
|
+
import '../../../../shared/consts/index.js';
|
|
15
|
+
import '@dynamic-labs/multi-wallet';
|
|
16
|
+
import { isMagicConnector } from '../../../../utils/functions/isMagicConnector/isMagicConnector.js';
|
|
17
|
+
import '@dynamic-labs/rpc-providers';
|
|
18
|
+
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
19
|
+
import '../../../../context/ErrorContext/ErrorContext.js';
|
|
20
|
+
import '../../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
21
|
+
import 'react-dom';
|
|
22
|
+
import '../../../../components/ShadowDOM/ShadowDOM.js';
|
|
23
|
+
import '../../../../context/ThemeContext/ThemeContext.js';
|
|
24
|
+
import 'react-focus-lock';
|
|
25
|
+
import '../../../../components/Transition/ZoomTransition/ZoomTransition.js';
|
|
26
|
+
import '../../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
|
|
27
|
+
import '../../../../components/Transition/OpacityTransition/OpacityTransition.js';
|
|
28
|
+
import '../../../../components/IconButton/IconButton.js';
|
|
29
|
+
import '../../../../components/Alert/Alert.js';
|
|
30
|
+
import '@dynamic-labs/wallet-book';
|
|
31
|
+
import '../../../../components/Popper/Popper/Popper.js';
|
|
32
|
+
import '../../../../components/Popper/PopperContext/PopperContext.js';
|
|
33
|
+
import 'formik';
|
|
34
|
+
import 'yup';
|
|
35
|
+
import '../../../../components/MenuList/Dropdown/Dropdown.js';
|
|
36
|
+
import { TransactionConfirmationView } from '../../../TransactionConfirmationView/TransactionConfirmationView.js';
|
|
37
|
+
import '../../../../context/MockContext/MockContext.js';
|
|
38
|
+
import '../../../../context/CaptchaContext/CaptchaContext.js';
|
|
39
|
+
import '../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js';
|
|
40
|
+
import { useTransactionWithGasPrice } from '../../../../utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.js';
|
|
41
|
+
|
|
42
|
+
const TransactionStage = (_a) => {
|
|
43
|
+
var { transaction, provider, walletConnector } = _a, rest = __rest(_a, ["transaction", "provider", "walletConnector"]);
|
|
44
|
+
const { disableWalletConfirmationOnce } = useInternalDynamicContext();
|
|
45
|
+
const transactionWithGasPrice = useTransactionWithGasPrice({
|
|
46
|
+
enabled: isMagicConnector(walletConnector),
|
|
47
|
+
increasePercentage: 5,
|
|
48
|
+
provider,
|
|
49
|
+
transaction,
|
|
50
|
+
});
|
|
51
|
+
return (jsx(TransactionConfirmationView, Object.assign({ provider: provider, transaction: transactionWithGasPrice, mutation: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
disableWalletConfirmationOnce();
|
|
53
|
+
const signer = provider.getSigner();
|
|
54
|
+
const sentTransaction = yield signer.sendTransaction(transactionWithGasPrice);
|
|
55
|
+
return sentTransaction;
|
|
56
|
+
}) }, rest)));
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { TransactionStage };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TransactionStage } from './TransactionStage';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TransactionStage';
|
|
@@ -65,7 +65,7 @@ const TransactionConfirmationView = ({ provider, transaction, mutation, onError,
|
|
|
65
65
|
onFailure: (error) => onError === null || onError === void 0 ? void 0 : onError(error),
|
|
66
66
|
onSuccess: (tx) => onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(tx),
|
|
67
67
|
});
|
|
68
|
-
const { isLoading: isLoadingTransaction, isTransactionFromAddressLoading, isTransactionToAddressLoading, transactionFromAddress, transactionToAddress, isEffectiveValueLoading, transactionValue, gasEstimate, isGasPriceLoading, total, } = useTransactionData.useTransactionData({
|
|
68
|
+
const { isLoading: isLoadingTransaction, isTransactionFromAddressLoading, isTransactionToAddressLoading, transactionFromAddress, transactionToAddress, isEffectiveValueLoading, transactionGas, transactionValue, isGasLoading, gasEstimate, isGasPriceLoading, total, } = useTransactionData.useTransactionData({
|
|
69
69
|
provider,
|
|
70
70
|
transaction,
|
|
71
71
|
});
|
|
@@ -90,7 +90,7 @@ const TransactionConfirmationView = ({ provider, transaction, mutation, onError,
|
|
|
90
90
|
return `Insufficient funds due to gas price increase from estimate. Please add ${amountLeft} ${currencySymbol} to continue.`;
|
|
91
91
|
}, [currencySymbol, hasInsufficientFunds, missingFunds]);
|
|
92
92
|
return (jsxRuntime.jsxs(TransactionConfirmationPageLayout.TransactionConfirmationPageLayout, Object.assign({ onClickBack: onClickBack, onClickClose: onClickClose, title: title, appOrigin: appOrigin, appName: appName, appLogoUrl: appLogoUrl, isLoading: isLoading, onClickSend: () => send(), displayPoweredByDynamicFooter: displayPoweredByDynamicFooter, disableSendButton: isLoadingTransaction || hasInsufficientFunds, error: errorMessage, warningMessage: warningMessage }, { children: [jsxRuntime.jsx(TransactionRow.TransactionRow, Object.assign({ label: 'From (You)', isLoading: isTransactionFromAddressLoading, title: transactionFromAddress }, { children: shortenWalletAddress.shortenWalletAddress(transactionFromAddress, 4, 4) })), jsxRuntime.jsx(TransactionRow.TransactionRow, Object.assign({ label: 'To', isLoading: isTransactionToAddressLoading, title: transactionToAddress }, { children: transactionToAddress &&
|
|
93
|
-
shortenWalletAddress.shortenWalletAddress(transactionToAddress, 4, 4) })), jsxRuntime.jsx(TransactionRow.TransactionRow, Object.assign({ label: 'Amount', isLoading: isEffectiveValueLoading, isEmpty: !transactionValue, title: transactionValue && formatBigNumber.formatBigNumber(transactionValue), suffix: currencySymbol, icon: chainIcon, dataTestId: 'transaction-amount' }, { children: transactionValue ? formatBigNumber.formatBigNumber(transactionValue, 10) : 0 })), jsxRuntime.jsx(TransactionRow.TransactionRow, Object.assign({ label: 'Gas (
|
|
93
|
+
shortenWalletAddress.shortenWalletAddress(transactionToAddress, 4, 4) })), jsxRuntime.jsx(TransactionRow.TransactionRow, Object.assign({ label: 'Amount', isLoading: isEffectiveValueLoading, isEmpty: !transactionValue, title: transactionValue && formatBigNumber.formatBigNumber(transactionValue), suffix: currencySymbol, icon: chainIcon, dataTestId: 'transaction-amount' }, { children: transactionValue ? formatBigNumber.formatBigNumber(transactionValue, 10) : 0 })), transactionGas ? (jsxRuntime.jsx(TransactionRow.TransactionRow, Object.assign({ label: 'Gas', isEmpty: !transactionGas, isLoading: isGasLoading, title: transactionGas && formatBigNumber.formatBigNumber(transactionGas), suffix: transactionGas && currencySymbol, icon: transactionGas && chainIcon, dataTestId: 'transaction-gas-fee' }, { children: transactionGas ? formatBigNumber.formatBigNumber(transactionGas, 10) : 'N/A' }))) : (jsxRuntime.jsx(TransactionRow.TransactionRow, Object.assign({ label: 'Gas (estimate)', isEmpty: !gasEstimate, isLoading: isGasPriceLoading, title: gasEstimate && formatBigNumber.formatBigNumber(gasEstimate), suffix: gasEstimate && currencySymbol, icon: gasEstimate && chainIcon, dataTestId: 'transaction-estimated-gas-fee' }, { children: gasEstimate ? formatBigNumber.formatBigNumber(gasEstimate, 10) : 'N/A' }))), jsxRuntime.jsx(TransactionRow.TransactionRow, Object.assign({ label: 'Total', isEmpty: !total, title: total && formatBigNumber.formatBigNumber(total), suffix: total && currencySymbol, icon: total && chainIcon, dataTestId: 'transaction-total' }, { children: total ? formatBigNumber.formatBigNumber(total, 10) : 'N/A' }))] })));
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
exports.TransactionConfirmationView = TransactionConfirmationView;
|
|
@@ -61,7 +61,7 @@ const TransactionConfirmationView = ({ provider, transaction, mutation, onError,
|
|
|
61
61
|
onFailure: (error) => onError === null || onError === void 0 ? void 0 : onError(error),
|
|
62
62
|
onSuccess: (tx) => onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(tx),
|
|
63
63
|
});
|
|
64
|
-
const { isLoading: isLoadingTransaction, isTransactionFromAddressLoading, isTransactionToAddressLoading, transactionFromAddress, transactionToAddress, isEffectiveValueLoading, transactionValue, gasEstimate, isGasPriceLoading, total, } = useTransactionData({
|
|
64
|
+
const { isLoading: isLoadingTransaction, isTransactionFromAddressLoading, isTransactionToAddressLoading, transactionFromAddress, transactionToAddress, isEffectiveValueLoading, transactionGas, transactionValue, isGasLoading, gasEstimate, isGasPriceLoading, total, } = useTransactionData({
|
|
65
65
|
provider,
|
|
66
66
|
transaction,
|
|
67
67
|
});
|
|
@@ -86,7 +86,7 @@ const TransactionConfirmationView = ({ provider, transaction, mutation, onError,
|
|
|
86
86
|
return `Insufficient funds due to gas price increase from estimate. Please add ${amountLeft} ${currencySymbol} to continue.`;
|
|
87
87
|
}, [currencySymbol, hasInsufficientFunds, missingFunds]);
|
|
88
88
|
return (jsxs(TransactionConfirmationPageLayout, Object.assign({ onClickBack: onClickBack, onClickClose: onClickClose, title: title, appOrigin: appOrigin, appName: appName, appLogoUrl: appLogoUrl, isLoading: isLoading, onClickSend: () => send(), displayPoweredByDynamicFooter: displayPoweredByDynamicFooter, disableSendButton: isLoadingTransaction || hasInsufficientFunds, error: errorMessage, warningMessage: warningMessage }, { children: [jsx(TransactionRow, Object.assign({ label: 'From (You)', isLoading: isTransactionFromAddressLoading, title: transactionFromAddress }, { children: shortenWalletAddress(transactionFromAddress, 4, 4) })), jsx(TransactionRow, Object.assign({ label: 'To', isLoading: isTransactionToAddressLoading, title: transactionToAddress }, { children: transactionToAddress &&
|
|
89
|
-
shortenWalletAddress(transactionToAddress, 4, 4) })), jsx(TransactionRow, Object.assign({ label: 'Amount', isLoading: isEffectiveValueLoading, isEmpty: !transactionValue, title: transactionValue && formatBigNumber(transactionValue), suffix: currencySymbol, icon: chainIcon, dataTestId: 'transaction-amount' }, { children: transactionValue ? formatBigNumber(transactionValue, 10) : 0 })), jsx(TransactionRow, Object.assign({ label: 'Gas (
|
|
89
|
+
shortenWalletAddress(transactionToAddress, 4, 4) })), jsx(TransactionRow, Object.assign({ label: 'Amount', isLoading: isEffectiveValueLoading, isEmpty: !transactionValue, title: transactionValue && formatBigNumber(transactionValue), suffix: currencySymbol, icon: chainIcon, dataTestId: 'transaction-amount' }, { children: transactionValue ? formatBigNumber(transactionValue, 10) : 0 })), transactionGas ? (jsx(TransactionRow, Object.assign({ label: 'Gas', isEmpty: !transactionGas, isLoading: isGasLoading, title: transactionGas && formatBigNumber(transactionGas), suffix: transactionGas && currencySymbol, icon: transactionGas && chainIcon, dataTestId: 'transaction-gas-fee' }, { children: transactionGas ? formatBigNumber(transactionGas, 10) : 'N/A' }))) : (jsx(TransactionRow, Object.assign({ label: 'Gas (estimate)', isEmpty: !gasEstimate, isLoading: isGasPriceLoading, title: gasEstimate && formatBigNumber(gasEstimate), suffix: gasEstimate && currencySymbol, icon: gasEstimate && chainIcon, dataTestId: 'transaction-estimated-gas-fee' }, { children: gasEstimate ? formatBigNumber(gasEstimate, 10) : 'N/A' }))), jsx(TransactionRow, Object.assign({ label: 'Total', isEmpty: !total, title: total && formatBigNumber(total), suffix: total && currencySymbol, icon: total && chainIcon, dataTestId: 'transaction-total' }, { children: total ? formatBigNumber(total, 10) : 'N/A' }))] })));
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
export { TransactionConfirmationView };
|
package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.cjs
CHANGED
|
@@ -54,19 +54,28 @@ const useTransactionData = ({ provider, transaction, }) => {
|
|
|
54
54
|
const { from } = transaction, transactionWithNoOrigin = _tslib.__rest(transaction, ["from"]);
|
|
55
55
|
return provider.estimateGas(transactionWithNoOrigin);
|
|
56
56
|
});
|
|
57
|
-
const { data:
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
? ethers.ethers.BigNumber.from(gasPrice)
|
|
61
|
-
|
|
57
|
+
const { data: providerGasPrice, isLoading: isProviderGasPrice } = usePromise.usePromise(() => provider.getGasPrice(), []);
|
|
58
|
+
const { data: transactionGasPrice, isLoading: isTransactionGasPriceLoading } = usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
const gasPrice = yield transaction.gasPrice;
|
|
60
|
+
return gasPrice ? ethers.ethers.BigNumber.from(gasPrice) : undefined;
|
|
61
|
+
}), [transaction.gasPrice]);
|
|
62
|
+
const isGasPriceLoading = isEstimatedGasLoading || isProviderGasPrice || isTransactionGasPriceLoading;
|
|
63
|
+
const isGasLoading = isProviderGasPrice || isTransactionGasPriceLoading;
|
|
64
|
+
const transactionGas = React.useMemo(() => transactionGasPrice && estimatedGas
|
|
65
|
+
? ethers.ethers.BigNumber.from(transactionGasPrice).mul(estimatedGas)
|
|
66
|
+
: undefined, [estimatedGas, transactionGasPrice]);
|
|
67
|
+
const gasEstimate = React.useMemo(() => !transactionGasPrice && providerGasPrice && estimatedGas
|
|
68
|
+
? ethers.ethers.BigNumber.from(providerGasPrice).mul(estimatedGas)
|
|
69
|
+
: undefined, [transactionGasPrice, estimatedGas, providerGasPrice]);
|
|
62
70
|
const { data: transactionToAddress, isLoading: isTransactionToAddressLoading, } = usePromise.usePromise(() => transaction.to);
|
|
63
71
|
const { data: transactionFromAddress, isLoading: isTransactionFromAddressLoading, } = usePromise.usePromise(() => transaction.from);
|
|
64
72
|
const total = React.useMemo(() => {
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
const transactionGasFee = transactionGas || gasEstimate;
|
|
74
|
+
if (transactionGasFee !== undefined && transactionValue !== undefined) {
|
|
75
|
+
return transactionGasFee.add(transactionValue);
|
|
67
76
|
}
|
|
68
77
|
return transactionValue || gasEstimate;
|
|
69
|
-
}, [gasEstimate, transactionValue]);
|
|
78
|
+
}, [gasEstimate, transactionGas, transactionValue]);
|
|
70
79
|
const isLoading = React.useMemo(() => isEffectiveValueLoading ||
|
|
71
80
|
isGasPriceLoading ||
|
|
72
81
|
isTransactionToAddressLoading ||
|
|
@@ -79,12 +88,16 @@ const useTransactionData = ({ provider, transaction, }) => {
|
|
|
79
88
|
return {
|
|
80
89
|
gasEstimate,
|
|
81
90
|
isEffectiveValueLoading,
|
|
91
|
+
isGasLoading,
|
|
82
92
|
isGasPriceLoading,
|
|
83
93
|
isLoading,
|
|
84
94
|
isTransactionFromAddressLoading,
|
|
95
|
+
isTransactionGasPriceLoading,
|
|
85
96
|
isTransactionToAddressLoading,
|
|
86
97
|
total,
|
|
87
98
|
transactionFromAddress,
|
|
99
|
+
transactionGas,
|
|
100
|
+
transactionGasPrice,
|
|
88
101
|
transactionToAddress,
|
|
89
102
|
transactionValue,
|
|
90
103
|
};
|
package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.d.ts
CHANGED
|
@@ -6,12 +6,16 @@ type TransactionDataHookProps = {
|
|
|
6
6
|
export declare const useTransactionData: ({ provider, transaction, }: TransactionDataHookProps) => {
|
|
7
7
|
gasEstimate: ethers.BigNumber | undefined;
|
|
8
8
|
isEffectiveValueLoading: boolean;
|
|
9
|
+
isGasLoading: boolean;
|
|
9
10
|
isGasPriceLoading: boolean;
|
|
10
11
|
isLoading: boolean;
|
|
11
12
|
isTransactionFromAddressLoading: boolean;
|
|
13
|
+
isTransactionGasPriceLoading: boolean;
|
|
12
14
|
isTransactionToAddressLoading: boolean;
|
|
13
15
|
total: ethers.BigNumber | undefined;
|
|
14
16
|
transactionFromAddress: string | undefined;
|
|
17
|
+
transactionGas: ethers.BigNumber | undefined;
|
|
18
|
+
transactionGasPrice: ethers.BigNumber | undefined;
|
|
15
19
|
transactionToAddress: string | undefined;
|
|
16
20
|
transactionValue: ethers.BigNumber | undefined;
|
|
17
21
|
};
|
package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.js
CHANGED
|
@@ -50,19 +50,28 @@ const useTransactionData = ({ provider, transaction, }) => {
|
|
|
50
50
|
const { from } = transaction, transactionWithNoOrigin = __rest(transaction, ["from"]);
|
|
51
51
|
return provider.estimateGas(transactionWithNoOrigin);
|
|
52
52
|
});
|
|
53
|
-
const { data:
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
? ethers.BigNumber.from(gasPrice)
|
|
57
|
-
|
|
53
|
+
const { data: providerGasPrice, isLoading: isProviderGasPrice } = usePromise(() => provider.getGasPrice(), []);
|
|
54
|
+
const { data: transactionGasPrice, isLoading: isTransactionGasPriceLoading } = usePromise(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const gasPrice = yield transaction.gasPrice;
|
|
56
|
+
return gasPrice ? ethers.BigNumber.from(gasPrice) : undefined;
|
|
57
|
+
}), [transaction.gasPrice]);
|
|
58
|
+
const isGasPriceLoading = isEstimatedGasLoading || isProviderGasPrice || isTransactionGasPriceLoading;
|
|
59
|
+
const isGasLoading = isProviderGasPrice || isTransactionGasPriceLoading;
|
|
60
|
+
const transactionGas = useMemo(() => transactionGasPrice && estimatedGas
|
|
61
|
+
? ethers.BigNumber.from(transactionGasPrice).mul(estimatedGas)
|
|
62
|
+
: undefined, [estimatedGas, transactionGasPrice]);
|
|
63
|
+
const gasEstimate = useMemo(() => !transactionGasPrice && providerGasPrice && estimatedGas
|
|
64
|
+
? ethers.BigNumber.from(providerGasPrice).mul(estimatedGas)
|
|
65
|
+
: undefined, [transactionGasPrice, estimatedGas, providerGasPrice]);
|
|
58
66
|
const { data: transactionToAddress, isLoading: isTransactionToAddressLoading, } = usePromise(() => transaction.to);
|
|
59
67
|
const { data: transactionFromAddress, isLoading: isTransactionFromAddressLoading, } = usePromise(() => transaction.from);
|
|
60
68
|
const total = useMemo(() => {
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
const transactionGasFee = transactionGas || gasEstimate;
|
|
70
|
+
if (transactionGasFee !== undefined && transactionValue !== undefined) {
|
|
71
|
+
return transactionGasFee.add(transactionValue);
|
|
63
72
|
}
|
|
64
73
|
return transactionValue || gasEstimate;
|
|
65
|
-
}, [gasEstimate, transactionValue]);
|
|
74
|
+
}, [gasEstimate, transactionGas, transactionValue]);
|
|
66
75
|
const isLoading = useMemo(() => isEffectiveValueLoading ||
|
|
67
76
|
isGasPriceLoading ||
|
|
68
77
|
isTransactionToAddressLoading ||
|
|
@@ -75,12 +84,16 @@ const useTransactionData = ({ provider, transaction, }) => {
|
|
|
75
84
|
return {
|
|
76
85
|
gasEstimate,
|
|
77
86
|
isEffectiveValueLoading,
|
|
87
|
+
isGasLoading,
|
|
78
88
|
isGasPriceLoading,
|
|
79
89
|
isLoading,
|
|
80
90
|
isTransactionFromAddressLoading,
|
|
91
|
+
isTransactionGasPriceLoading,
|
|
81
92
|
isTransactionToAddressLoading,
|
|
82
93
|
total,
|
|
83
94
|
transactionFromAddress,
|
|
95
|
+
transactionGas,
|
|
96
|
+
transactionGasPrice,
|
|
84
97
|
transactionToAddress,
|
|
85
98
|
transactionValue,
|
|
86
99
|
};
|