@dynamic-labs/sdk-react-core 0.18.100-viem.0 → 0.18.100-viem.10
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 +111 -1
- package/package.cjs +3 -3
- package/package.js +3 -3
- package/package.json +10 -10
- package/src/index.cjs +4 -0
- package/src/index.js +2 -0
- package/src/lib/Main.cjs +5 -0
- package/src/lib/Main.js +5 -0
- package/src/lib/components/Button/Button.cjs +10 -7
- package/src/lib/components/Button/Button.js +10 -7
- package/src/lib/components/DynamicConnectButton/components/ConnectButton.cjs +1 -1
- package/src/lib/components/DynamicConnectButton/components/ConnectButton.js +1 -1
- package/src/lib/components/ErrorContainer/ErrorContainer.d.ts +1 -1
- package/src/lib/components/ListTile/ListTile.cjs +1 -1
- package/src/lib/components/ListTile/ListTile.js +1 -1
- package/src/lib/components/ListTile/ListTile.types.d.ts +1 -0
- package/src/lib/components/MenuList/Dropdown/Dropdown.cjs +1 -1
- package/src/lib/components/MenuList/Dropdown/Dropdown.js +1 -1
- package/src/lib/components/ModalHeaderBanner/ModalHeaderBanner.cjs +6 -2
- package/src/lib/components/ModalHeaderBanner/ModalHeaderBanner.d.ts +2 -1
- package/src/lib/components/ModalHeaderBanner/ModalHeaderBanner.js +6 -2
- package/src/lib/components/OTPVerificationView/OTPVerificationView.cjs +5 -3
- package/src/lib/components/OTPVerificationView/OTPVerificationView.d.ts +2 -0
- package/src/lib/components/OTPVerificationView/OTPVerificationView.js +5 -3
- package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.cjs +3 -1
- package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.js +3 -1
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.cjs +2 -2
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.js +2 -2
- package/src/lib/components/Typography/Typography.cjs +1 -0
- package/src/lib/components/Typography/Typography.js +1 -0
- package/src/lib/components/Typography/Typography.types.d.ts +1 -1
- package/src/lib/components/UserProfile/UserProfile.cjs +1 -1
- package/src/lib/components/UserProfile/UserProfile.js +1 -1
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.cjs +1 -1
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.js +1 -1
- package/src/lib/context/DynamicContext/DynamicContext.cjs +15 -4
- package/src/lib/context/DynamicContext/DynamicContext.js +17 -6
- package/src/lib/context/DynamicContext/hooks/useVerificationInProgress/useVerificationInProgress.cjs +13 -3
- package/src/lib/context/DynamicContext/hooks/useVerificationInProgress/useVerificationInProgress.js +13 -3
- package/src/lib/context/DynamicContext/internalEvents/index.d.ts +2 -0
- package/src/lib/context/DynamicContext/internalEvents/internalEvents.cjs +14 -0
- package/src/lib/context/DynamicContext/internalEvents/internalEvents.d.ts +8 -0
- package/src/lib/context/DynamicContext/internalEvents/internalEvents.js +6 -0
- package/src/lib/context/DynamicContext/types/index.d.ts +6 -3
- package/src/lib/context/DynamicContext/useDynamicContext.cjs +2 -1
- package/src/lib/context/DynamicContext/useDynamicContext.d.ts +1 -1
- package/src/lib/context/DynamicContext/useDynamicContext.js +2 -1
- package/src/lib/context/SendBalanceContext/SendBalanceContext.types.d.ts +2 -2
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.cjs +2 -1
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +2 -1
- package/src/lib/context/ViewContext/ViewContext.d.ts +1 -1
- package/src/lib/data/api.cjs +33 -1
- package/src/lib/data/api.d.ts +3 -1
- package/src/lib/data/api.js +34 -4
- package/src/lib/layout/DynamicAuthLayout/Header/header.cjs +10 -2
- package/src/lib/layout/DynamicAuthLayout/Header/header.js +10 -2
- package/src/lib/main.global.cjs +1 -1
- package/src/lib/main.global.js +1 -1
- package/src/lib/modals/SendBalanceModal/SendBalanceModal.d.ts +2 -2
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.cjs +11 -2
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.js +11 -2
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.types.d.ts +6 -3
- package/src/lib/shared/assets/double-arrow-right.cjs +53 -0
- package/src/lib/shared/assets/double-arrow-right.js +29 -0
- package/src/lib/shared/assets/index.d.ts +1 -0
- package/src/lib/shared/utils/hooks/usePreventPageScroll/usePreventPageScroll.cjs +28 -2
- package/src/lib/shared/utils/hooks/usePreventPageScroll/usePreventPageScroll.js +28 -2
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/constants/errors.cjs +7 -0
- package/src/lib/utils/constants/errors.d.ts +1 -0
- package/src/lib/utils/constants/errors.js +3 -0
- package/src/lib/utils/constants/index.d.ts +1 -1
- package/src/lib/utils/constants/localStorage.cjs +2 -0
- package/src/lib/utils/constants/localStorage.d.ts +1 -0
- package/src/lib/utils/constants/localStorage.js +2 -1
- package/src/lib/utils/functions/createUserProfile/createUserProfile.cjs +1 -1
- package/src/lib/utils/functions/createUserProfile/createUserProfile.js +1 -1
- package/src/lib/utils/functions/digestSHA256/digestSHA256.cjs +11 -0
- package/src/lib/utils/functions/digestSHA256/digestSHA256.d.ts +1 -0
- package/src/lib/utils/functions/digestSHA256/digestSHA256.js +7 -0
- package/src/lib/utils/functions/digestSHA256/index.d.ts +1 -0
- package/src/lib/utils/functions/encodeBase64URL/encodeBase64URL.cjs +14 -0
- package/src/lib/utils/functions/encodeBase64URL/encodeBase64URL.d.ts +1 -0
- package/src/lib/utils/functions/encodeBase64URL/encodeBase64URL.js +10 -0
- package/src/lib/utils/functions/encodeBase64URL/index.d.ts +1 -0
- package/src/lib/utils/functions/getRedirectURIOrigin/getRedirectURIOrigin.cjs +33 -0
- package/src/lib/utils/functions/getRedirectURIOrigin/getRedirectURIOrigin.d.ts +1 -0
- package/src/lib/utils/functions/getRedirectURIOrigin/getRedirectURIOrigin.js +29 -0
- package/src/lib/utils/functions/getRedirectURIOrigin/index.d.ts +1 -0
- package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.cjs +14 -2
- package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.d.ts +3 -2
- package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.js +14 -2
- package/src/lib/utils/functions/index.d.ts +7 -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/functions/randomString/index.d.ts +1 -0
- package/src/lib/utils/functions/randomString/randomString.cjs +14 -0
- package/src/lib/utils/functions/randomString/randomString.d.ts +1 -0
- package/src/lib/utils/functions/randomString/randomString.js +10 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/index.d.ts +1 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/sendTransactionWithAutoNonce.cjs +48 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/sendTransactionWithAutoNonce.d.ts +18 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/sendTransactionWithAutoNonce.js +43 -0
- package/src/lib/utils/functions/stringifyURIQuery/index.d.ts +1 -0
- package/src/lib/utils/functions/stringifyURIQuery/stringifyURIQuery.cjs +13 -0
- package/src/lib/utils/functions/stringifyURIQuery/stringifyURIQuery.d.ts +1 -0
- package/src/lib/utils/functions/stringifyURIQuery/stringifyURIQuery.js +9 -0
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +10 -4
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.d.ts +2 -1
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +11 -5
- package/src/lib/utils/hooks/index.d.ts +2 -0
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.cjs +19 -3
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.d.ts +1 -2
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.js +20 -4
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +15 -9
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.d.ts +1 -1
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +15 -9
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +2 -1
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +2 -1
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +16 -18
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +1 -1
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +17 -19
- package/src/lib/utils/hooks/useConnectedWalletsNetworkValidation/useConnectedWalletsNetworkValidation.cjs +7 -6
- package/src/lib/utils/hooks/useConnectedWalletsNetworkValidation/useConnectedWalletsNetworkValidation.js +7 -6
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/useFetchNetworkConfigurations.cjs +2 -7
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/useFetchNetworkConfigurations.js +2 -7
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/index.d.ts +1 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/index.d.ts +1 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.cjs +16 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.d.ts +2 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.js +12 -0
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.cjs +6 -2
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.d.ts +2 -1
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.js +6 -2
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.cjs +149 -26
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.d.ts +5 -1
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +151 -28
- package/src/lib/utils/hooks/useTransactionEstimatedGas/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.cjs +31 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.d.ts +20 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.js +27 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.cjs +56 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.d.ts +32 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.js +52 -0
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +1 -0
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +1 -0
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.d.ts +1 -1
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.cjs +2 -2
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.d.ts +5 -1
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.js +2 -2
- package/src/lib/utils/hooks/useWallets/useWallets.d.ts +2 -2
- package/src/lib/views/CaptchaVerifyUser/CaptchaVerifyUser.cjs +9 -3
- package/src/lib/views/CaptchaVerifyUser/CaptchaVerifyUser.js +9 -3
- package/src/lib/views/CollectUserDataView/UserDataFields/index.cjs +4 -0
- package/src/lib/views/CollectUserDataView/UserDataFields/index.js +4 -0
- package/src/lib/views/EmailUpdate/EmailUpdate.cjs +13 -4
- package/src/lib/views/EmailUpdate/EmailUpdate.js +13 -4
- package/src/lib/views/EmailVerification/EmailVerification.cjs +12 -1
- package/src/lib/views/EmailVerification/EmailVerification.js +14 -3
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.cjs +3 -2
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.js +3 -2
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailWalletList/LoginWithEmailWalletList.cjs +4 -1
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailWalletList/LoginWithEmailWalletList.js +4 -1
- package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.cjs +1 -1
- package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.js +1 -1
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.cjs +111 -0
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.d.ts +2 -0
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.js +107 -0
- package/src/lib/views/MergeUserAccountsView/index.d.ts +1 -0
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +4 -2
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +4 -2
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +4 -2
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +4 -2
- package/src/lib/views/SendBalanceView/SendBalanceView.cjs +14 -35
- package/src/lib/views/SendBalanceView/SendBalanceView.d.ts +2 -2
- package/src/lib/views/SendBalanceView/SendBalanceView.js +15 -36
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.cjs +67 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.d.ts +8 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.js +63 -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/SocialRedirectView/SocialRedirectView.cjs +1 -2
- package/src/lib/views/SocialRedirectView/SocialRedirectView.js +1 -2
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +31 -8
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.d.ts +4 -3
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +32 -9
- package/src/lib/views/TransactionConfirmationView/hooks/index.d.ts +2 -1
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/index.d.ts +1 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/useTransactionGas.cjs +69 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/useTransactionGas.d.ts +11 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/useTransactionGas.js +65 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/index.d.ts +1 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/useTransactionTotal.cjs +14 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/useTransactionTotal.d.ts +6 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/useTransactionTotal.js +10 -0
- package/src/lib/views/WalletGroupView/components/WalletGroupItem/WalletGroupItem.cjs +1 -0
- package/src/lib/views/WalletGroupView/components/WalletGroupItem/WalletGroupItem.js +1 -0
- package/src/lib/views/WalletList/WalletList.cjs +4 -1
- package/src/lib/views/WalletList/WalletList.js +4 -1
- package/src/lib/views/WalletList/WalletListItem/WalletListItem.cjs +1 -1
- package/src/lib/views/WalletList/WalletListItem/WalletListItem.js +1 -1
- package/src/lib/views/WalletLockedView/WalletLockedView.cjs +20 -4
- package/src/lib/views/WalletLockedView/WalletLockedView.js +20 -4
- package/src/lib/views/viewToComponentMap.cjs +2 -0
- package/src/lib/views/viewToComponentMap.js +2 -0
- package/src/lib/widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.cjs +4 -1
- package/src/lib/widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.js +4 -1
- package/src/lib/widgets/OAuthIFrameContainer/OAuthIFrameContainer.cjs +13 -0
- package/src/lib/widgets/OAuthIFrameContainer/OAuthIFrameContainer.d.ts +2 -0
- package/src/lib/widgets/OAuthIFrameContainer/OAuthIFrameContainer.js +9 -0
- package/src/lib/widgets/OAuthIFrameContainer/index.d.ts +1 -0
- package/src/lib/widgets/index.d.ts +1 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/index.d.ts +0 -1
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.cjs +0 -104
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.d.ts +0 -17
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.js +0 -100
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
-
import { useState, useMemo } from 'react';
|
|
2
|
+
import { useState, useRef, useMemo } from 'react';
|
|
3
3
|
import { useInternalDynamicContext } from '../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
4
|
-
import { unlinkOAuth, verifyOAuth } from '../../../data/api.js';
|
|
4
|
+
import { getOauthLoginUrl, unlinkOAuth, verifyOAuth } from '../../../data/api.js';
|
|
5
5
|
import { useUpdateUserProfileByJWTCallback } from '../useUpdateUserProfileByJWTCallback/useUpdateUserProfileByJWTCallback.js';
|
|
6
6
|
import '@dynamic-labs/sdk-api';
|
|
7
7
|
import { logger } from '../../../shared/logger.js';
|
|
@@ -19,13 +19,35 @@ import '@dynamic-labs/multi-wallet';
|
|
|
19
19
|
import { getAuthToken } from '../../functions/getAuthToken/getAuthToken.js';
|
|
20
20
|
import { getEnabledOAuthProviders } from '../../functions/getEnabledOAuthProviders/index.js';
|
|
21
21
|
import { isSocialKycEnabled } from '../../functions/isSocialKycEnabled/isSocialKycEnabled.js';
|
|
22
|
+
import { randomString } from '../../functions/randomString/randomString.js';
|
|
23
|
+
import { stringifyURIQuery } from '../../functions/stringifyURIQuery/stringifyURIQuery.js';
|
|
24
|
+
import { digestSHA256 } from '../../functions/digestSHA256/digestSHA256.js';
|
|
25
|
+
import { encodeBase64URL } from '../../functions/encodeBase64URL/encodeBase64URL.js';
|
|
26
|
+
import { getRedirectURIOrigin } from '../../functions/getRedirectURIOrigin/getRedirectURIOrigin.js';
|
|
22
27
|
|
|
23
|
-
const
|
|
28
|
+
const socialProviders = [
|
|
29
|
+
'discord',
|
|
30
|
+
'facebook',
|
|
31
|
+
'github',
|
|
32
|
+
'google',
|
|
33
|
+
'instagram',
|
|
34
|
+
'twitch',
|
|
35
|
+
'twitter',
|
|
36
|
+
];
|
|
37
|
+
// pkce params are only required for twitter and break if added for other providers, like google
|
|
38
|
+
// so we should only add provider that support pkce to this list
|
|
39
|
+
const providersRequiringPkce = ['twitter', 'github'];
|
|
40
|
+
const providersWithoutWindowOpenerRefence = ['twitter'];
|
|
41
|
+
const useSocialAccounts = ({ sessionTimeout } = {
|
|
42
|
+
sessionTimeout: 10000,
|
|
43
|
+
}) => {
|
|
24
44
|
var _a;
|
|
25
45
|
const { environmentId, user, projectSettings, onboardingOnlyJwt } = useInternalDynamicContext();
|
|
26
46
|
const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback();
|
|
27
47
|
const [isProcessing, setIsProcessing] = useState(false);
|
|
28
48
|
const [error, setError] = useState();
|
|
49
|
+
const providersWaitingOauthMessages = useRef({});
|
|
50
|
+
const authWindowInterval = useRef();
|
|
29
51
|
const userJwt = (_a = getAuthToken()) !== null && _a !== void 0 ? _a : onboardingOnlyJwt;
|
|
30
52
|
const oauthProviders = getEnabledOAuthProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
|
|
31
53
|
const verifiedOAuthCredentialsMap = useMemo(() => {
|
|
@@ -44,39 +66,101 @@ const useSocialAccounts = () => {
|
|
|
44
66
|
setIsProcessing(false);
|
|
45
67
|
setError(message);
|
|
46
68
|
};
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!
|
|
51
|
-
handleError('Social linking is not enabled on the dashboard');
|
|
69
|
+
const addOAuthIFrame = (url) => {
|
|
70
|
+
const container = document.getElementById('oauth-iframe-container');
|
|
71
|
+
let oauthIFrame = document.getElementById('oauth-iframe');
|
|
72
|
+
if (!container || oauthIFrame) {
|
|
52
73
|
return;
|
|
53
74
|
}
|
|
75
|
+
oauthIFrame = document.createElement('iframe');
|
|
76
|
+
oauthIFrame.setAttribute('id', 'oauth-iframe');
|
|
77
|
+
oauthIFrame.setAttribute('src', url);
|
|
78
|
+
container.appendChild(oauthIFrame);
|
|
79
|
+
};
|
|
80
|
+
const removeOAuthIFrame = () => {
|
|
81
|
+
const oauthIFrame = document.getElementById('oauth-iframe');
|
|
82
|
+
if (oauthIFrame) {
|
|
83
|
+
oauthIFrame.remove();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const checkValidProvider = (provider) => {
|
|
54
87
|
if (!provider) {
|
|
55
88
|
handleError('Provider is required');
|
|
56
|
-
return;
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (!socialProviders.includes(provider)) {
|
|
92
|
+
handleError(`Invalid social provider. Valid providers are: ${socialProviders.join(', ')}`);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
const checkValidOAuthLinking = (provider) => {
|
|
98
|
+
if (!isSocialKycEnabled(projectSettings)) {
|
|
99
|
+
handleError('Social linking is not enabled on the dashboard');
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (!checkValidProvider(provider)) {
|
|
103
|
+
return false;
|
|
57
104
|
}
|
|
58
105
|
const verifiedCredential = verifiedOAuthCredentialsMap[provider];
|
|
59
106
|
if (verifiedCredential) {
|
|
60
107
|
handleError(`Account already linked for provider: ${provider}`);
|
|
61
|
-
return;
|
|
108
|
+
return false;
|
|
62
109
|
}
|
|
63
110
|
const oauthProvider = oauthProviders.find((p) => p.provider === provider);
|
|
64
111
|
if (!oauthProvider) {
|
|
65
112
|
handleError(`Provider is not enabled on the dashboard: ${provider}`);
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
const linkSocialAccount = (provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
var _b;
|
|
119
|
+
clearInterval(authWindowInterval.current);
|
|
120
|
+
setError(undefined);
|
|
121
|
+
setIsProcessing(true);
|
|
122
|
+
// invalid linking request
|
|
123
|
+
if (!checkValidOAuthLinking(provider)) {
|
|
66
124
|
return;
|
|
67
125
|
}
|
|
126
|
+
const state = randomString(8);
|
|
127
|
+
const verifier = randomString(43);
|
|
128
|
+
const clearListeners = () => {
|
|
129
|
+
removeOAuthIFrame();
|
|
130
|
+
window.removeEventListener('message', handleAuthWindowMessage);
|
|
131
|
+
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: false });
|
|
132
|
+
};
|
|
68
133
|
const handleAuthWindowMessage = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
-
|
|
134
|
+
var _c;
|
|
135
|
+
const message = event.data;
|
|
136
|
+
const isAuthorizationMessage = (message === null || message === void 0 ? void 0 : message.type) === 'authorization_response';
|
|
137
|
+
if (isAuthorizationMessage) {
|
|
138
|
+
logger.debug('Message received', { data: message });
|
|
139
|
+
}
|
|
140
|
+
const isValidMessage = isAuthorizationMessage && (message === null || message === void 0 ? void 0 : message.provider) === provider;
|
|
141
|
+
// don't process imvalid messages for provider
|
|
142
|
+
if (!isValidMessage) {
|
|
143
|
+
return;
|
|
72
144
|
}
|
|
73
|
-
|
|
74
|
-
|
|
145
|
+
setIsProcessing(true);
|
|
146
|
+
if (!((_c = providersWaitingOauthMessages.current) === null || _c === void 0 ? void 0 : _c[provider])) {
|
|
147
|
+
handleError(`Linking ${provider} account session timeout.`);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
clearListeners();
|
|
151
|
+
const { code, error } = message;
|
|
152
|
+
if (error && error !== 'undefined') {
|
|
153
|
+
handleError(`Failed to link ${provider} social account: ${error}`);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (!code) {
|
|
157
|
+
handleError(`Failed to link ${provider} social account: no authorization code`);
|
|
75
158
|
return;
|
|
76
159
|
}
|
|
77
|
-
const { code } = event.data;
|
|
78
160
|
const jwt = yield verifyOAuth(environmentId, provider, {
|
|
79
161
|
code,
|
|
162
|
+
codeVerifier: verifier,
|
|
163
|
+
state,
|
|
80
164
|
}, String(userJwt));
|
|
81
165
|
if (!jwt) {
|
|
82
166
|
handleError(`Failed to link social account: ${provider}`);
|
|
@@ -85,22 +169,61 @@ const useSocialAccounts = () => {
|
|
|
85
169
|
yield updateUserProfileByJWT(jwt);
|
|
86
170
|
setIsProcessing(false);
|
|
87
171
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
172
|
+
const loginUrl = yield getOauthLoginUrl(environmentId, provider, String(userJwt));
|
|
173
|
+
if (!loginUrl) {
|
|
174
|
+
handleError(`Failed to get login url to link social account: ${provider}`);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
// we need to use an iframe to be the intermediary in communications between the popup and the sdk
|
|
178
|
+
// because of twitter limitations with accessing the window.opener and BroadcastChannel not working between
|
|
179
|
+
// different origins (our api redirect page and the app where the sdk is running)
|
|
180
|
+
const oauthIFrameUrl = `${getRedirectURIOrigin(loginUrl)}/sdkoauth`;
|
|
181
|
+
addOAuthIFrame(oauthIFrameUrl);
|
|
182
|
+
let oauthLoginUrl = loginUrl;
|
|
183
|
+
if (providersRequiringPkce.includes(provider)) {
|
|
184
|
+
const digest = yield digestSHA256(verifier);
|
|
185
|
+
const pkceParams = stringifyURIQuery({
|
|
186
|
+
code_challenge: encodeBase64URL(digest),
|
|
187
|
+
code_challenge_method: 'S256',
|
|
188
|
+
state: state,
|
|
189
|
+
});
|
|
190
|
+
oauthLoginUrl = `${loginUrl}&${pkceParams}`;
|
|
191
|
+
}
|
|
192
|
+
if (!((_b = providersWaitingOauthMessages.current) === null || _b === void 0 ? void 0 : _b[provider])) {
|
|
193
|
+
window.addEventListener('message', handleAuthWindowMessage);
|
|
194
|
+
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: true });
|
|
195
|
+
}
|
|
196
|
+
const authWindow = window.open(oauthLoginUrl, '_blank', 'width=500,height=600');
|
|
197
|
+
if (!providersWithoutWindowOpenerRefence.includes(provider)) {
|
|
198
|
+
// For provider that support window.opener, we need to clear all states/listeners when the window is closed
|
|
199
|
+
authWindowInterval.current = setInterval(() => {
|
|
200
|
+
if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed)) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
clearInterval(authWindowInterval.current);
|
|
94
204
|
setIsProcessing(false);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
// For provider that don't support window.opener, we need to use a timeout to try to detect when the
|
|
209
|
+
// window is closed
|
|
210
|
+
authWindowInterval.current = setInterval(() => {
|
|
211
|
+
var _a;
|
|
212
|
+
// user didn't complete oauth
|
|
213
|
+
if ((_a = providersWaitingOauthMessages.current) === null || _a === void 0 ? void 0 : _a[provider]) {
|
|
214
|
+
clearListeners();
|
|
215
|
+
handleError(`Linking ${provider} account window timeout.`);
|
|
216
|
+
}
|
|
217
|
+
setIsProcessing(false);
|
|
218
|
+
clearInterval(authWindowInterval.current);
|
|
219
|
+
}, sessionTimeout);
|
|
220
|
+
}
|
|
97
221
|
});
|
|
98
222
|
const unlinkSocialAccount = (provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
-
var
|
|
223
|
+
var _d;
|
|
100
224
|
setError(undefined);
|
|
101
225
|
setIsProcessing(true);
|
|
102
|
-
if (!provider) {
|
|
103
|
-
handleError('Provider is required');
|
|
226
|
+
if (!checkValidProvider(provider)) {
|
|
104
227
|
return;
|
|
105
228
|
}
|
|
106
229
|
const verifiedCredential = verifiedOAuthCredentialsMap[provider];
|
|
@@ -111,7 +234,7 @@ const useSocialAccounts = () => {
|
|
|
111
234
|
try {
|
|
112
235
|
const jwt = yield unlinkOAuth({
|
|
113
236
|
environmentId,
|
|
114
|
-
verifiedCrentialId: (
|
|
237
|
+
verifiedCrentialId: (_d = verifiedCredential.id) !== null && _d !== void 0 ? _d : '',
|
|
115
238
|
}, String(userJwt));
|
|
116
239
|
if (!jwt) {
|
|
117
240
|
handleError(`Failed to unlink social account: ${provider} | ${verifiedCredential.id}`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTransactionEstimatedGas } from './useTransactionEstimatedGas';
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hook to estimate the gas required for a transaction.
|
|
10
|
+
*
|
|
11
|
+
* This hook uses the `usePromise` hook to asynchronously estimate the gas required for a transaction.
|
|
12
|
+
* It first tries to estimate the gas without the 'from' field in the transaction, as the Alchemy API
|
|
13
|
+
* checks the origin address funds and can return an error if the origin wallet has no funds for the transaction.
|
|
14
|
+
* If the error 'UNPREDICTABLE_GAS_LIMIT' is encountered, it tries to estimate the gas again with the
|
|
15
|
+
* original transaction.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link https://docs.alchemy.com/reference/eth-estimategas}
|
|
18
|
+
* @see {@link https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT}
|
|
19
|
+
*
|
|
20
|
+
* @param {ethers.providers.Web3Provider} provider - The Web3 provider to use for estimating the gas.
|
|
21
|
+
* @param {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} transaction - The transaction for
|
|
22
|
+
* which to estimate the gas.
|
|
23
|
+
*
|
|
24
|
+
* @returns {PromiseState<ethers.BigNumber>} A promise that resolves to the estimated gas for the transaction.
|
|
25
|
+
*/
|
|
26
|
+
const useTransactionEstimatedGas = (provider, transaction) => usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const { from } = transaction, transactionWithoutFrom = _tslib.__rest(transaction, ["from"]);
|
|
28
|
+
return provider.estimateGas(Object.assign(Object.assign({}, transactionWithoutFrom), { account: from }));
|
|
29
|
+
}), { deps: [transaction, provider] });
|
|
30
|
+
|
|
31
|
+
exports.useTransactionEstimatedGas = useTransactionEstimatedGas;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PublicClient, TransactionRequest } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to estimate the gas required for a transaction.
|
|
4
|
+
*
|
|
5
|
+
* This hook uses the `usePromise` hook to asynchronously estimate the gas required for a transaction.
|
|
6
|
+
* It first tries to estimate the gas without the 'from' field in the transaction, as the Alchemy API
|
|
7
|
+
* checks the origin address funds and can return an error if the origin wallet has no funds for the transaction.
|
|
8
|
+
* If the error 'UNPREDICTABLE_GAS_LIMIT' is encountered, it tries to estimate the gas again with the
|
|
9
|
+
* original transaction.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://docs.alchemy.com/reference/eth-estimategas}
|
|
12
|
+
* @see {@link https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT}
|
|
13
|
+
*
|
|
14
|
+
* @param {ethers.providers.Web3Provider} provider - The Web3 provider to use for estimating the gas.
|
|
15
|
+
* @param {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} transaction - The transaction for
|
|
16
|
+
* which to estimate the gas.
|
|
17
|
+
*
|
|
18
|
+
* @returns {PromiseState<ethers.BigNumber>} A promise that resolves to the estimated gas for the transaction.
|
|
19
|
+
*/
|
|
20
|
+
export declare const useTransactionEstimatedGas: (provider: PublicClient, transaction: TransactionRequest) => import("../usePromise").PromiseState<bigint, Error>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { __awaiter, __rest } from '../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { usePromise } from '../usePromise/usePromise.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hook to estimate the gas required for a transaction.
|
|
6
|
+
*
|
|
7
|
+
* This hook uses the `usePromise` hook to asynchronously estimate the gas required for a transaction.
|
|
8
|
+
* It first tries to estimate the gas without the 'from' field in the transaction, as the Alchemy API
|
|
9
|
+
* checks the origin address funds and can return an error if the origin wallet has no funds for the transaction.
|
|
10
|
+
* If the error 'UNPREDICTABLE_GAS_LIMIT' is encountered, it tries to estimate the gas again with the
|
|
11
|
+
* original transaction.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://docs.alchemy.com/reference/eth-estimategas}
|
|
14
|
+
* @see {@link https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT}
|
|
15
|
+
*
|
|
16
|
+
* @param {ethers.providers.Web3Provider} provider - The Web3 provider to use for estimating the gas.
|
|
17
|
+
* @param {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} transaction - The transaction for
|
|
18
|
+
* which to estimate the gas.
|
|
19
|
+
*
|
|
20
|
+
* @returns {PromiseState<ethers.BigNumber>} A promise that resolves to the estimated gas for the transaction.
|
|
21
|
+
*/
|
|
22
|
+
const useTransactionEstimatedGas = (provider, transaction) => usePromise(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const { from } = transaction, transactionWithoutFrom = __rest(transaction, ["from"]);
|
|
24
|
+
return provider.estimateGas(Object.assign(Object.assign({}, transactionWithoutFrom), { account: from }));
|
|
25
|
+
}), { deps: [transaction, provider] });
|
|
26
|
+
|
|
27
|
+
export { useTransactionEstimatedGas };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTransactionWithGasPrice } from './useTransactionWithGasPrice';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var usePromise = require('../usePromise/usePromise.cjs');
|
|
6
|
+
|
|
7
|
+
const increaseGasPrice = (gasPrice, increasePercentage) => {
|
|
8
|
+
const increaseFactor = 100 + increasePercentage;
|
|
9
|
+
return (gasPrice * BigInt(increaseFactor)) / BigInt(100);
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A React Hook that returns a transaction object with the gas price set to the current gas price from the provider.
|
|
13
|
+
* The gas price is increased by a certain percentage specified by the user. The hook also allows the user to enable
|
|
14
|
+
* or disable this functionality.
|
|
15
|
+
*
|
|
16
|
+
* @param {Object} props - The properties for the hook.
|
|
17
|
+
* @param {PublicClient} props.provider - The provider to use for getting the current gas price.
|
|
18
|
+
* @param {TransactionRequest} props.transaction - The transaction object.
|
|
19
|
+
* @param {number} props.increasePercentage - The percentage by which to increase the current gas price.
|
|
20
|
+
* @param {boolean} [props.enabled=true] - A flag to enable or disable the gas price increase functionality.
|
|
21
|
+
*
|
|
22
|
+
* @returns {TransactionRequest} A new transaction object with the gas price.
|
|
23
|
+
* If the `enabled` flag is set to false, or if the gas price is not available, or if the transaction already has a
|
|
24
|
+
* gas price set, the original transaction object is returned.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const updatedTransaction = useTransactionWithGasPrice({
|
|
28
|
+
* provider: myProvider,
|
|
29
|
+
* transaction: myTransaction,
|
|
30
|
+
* increasePercentage: 10,
|
|
31
|
+
* enabled: true,
|
|
32
|
+
* });
|
|
33
|
+
*/
|
|
34
|
+
const useTransactionWithGasPrice = ({ increasePercentage = 0, provider, transaction, enabled = true, }) => {
|
|
35
|
+
const isGasPriceDefinedInTransaction = Boolean(transaction.gasPrice);
|
|
36
|
+
const shouldLoadGasPrice = enabled && increasePercentage > 0 && !isGasPriceDefinedInTransaction;
|
|
37
|
+
const { data: gasPrice } = usePromise.usePromise(() => provider.getGasPrice(), {
|
|
38
|
+
deps: [transaction, provider],
|
|
39
|
+
enabled: shouldLoadGasPrice,
|
|
40
|
+
});
|
|
41
|
+
if (!gasPrice) {
|
|
42
|
+
return transaction;
|
|
43
|
+
}
|
|
44
|
+
if (transaction.type === 'legacy' ||
|
|
45
|
+
transaction.type === 'eip2930' ||
|
|
46
|
+
transaction.type === undefined ||
|
|
47
|
+
transaction.maxFeePerGas === undefined) {
|
|
48
|
+
return Object.assign(Object.assign({}, transaction), { gasPrice: increaseGasPrice(gasPrice, increasePercentage) });
|
|
49
|
+
}
|
|
50
|
+
if (transaction.type === 'eip1559') {
|
|
51
|
+
return Object.assign(Object.assign({}, transaction), { maxFeePerGas: increaseGasPrice(gasPrice, increasePercentage) });
|
|
52
|
+
}
|
|
53
|
+
return transaction;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports.useTransactionWithGasPrice = useTransactionWithGasPrice;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PublicClient, TransactionRequest } from 'viem';
|
|
2
|
+
type UseTransactionWithGasPriceProps = {
|
|
3
|
+
provider: PublicClient;
|
|
4
|
+
transaction: TransactionRequest;
|
|
5
|
+
increasePercentage?: number;
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A React Hook that returns a transaction object with the gas price set to the current gas price from the provider.
|
|
10
|
+
* The gas price is increased by a certain percentage specified by the user. The hook also allows the user to enable
|
|
11
|
+
* or disable this functionality.
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} props - The properties for the hook.
|
|
14
|
+
* @param {PublicClient} props.provider - The provider to use for getting the current gas price.
|
|
15
|
+
* @param {TransactionRequest} props.transaction - The transaction object.
|
|
16
|
+
* @param {number} props.increasePercentage - The percentage by which to increase the current gas price.
|
|
17
|
+
* @param {boolean} [props.enabled=true] - A flag to enable or disable the gas price increase functionality.
|
|
18
|
+
*
|
|
19
|
+
* @returns {TransactionRequest} A new transaction object with the gas price.
|
|
20
|
+
* If the `enabled` flag is set to false, or if the gas price is not available, or if the transaction already has a
|
|
21
|
+
* gas price set, the original transaction object is returned.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const updatedTransaction = useTransactionWithGasPrice({
|
|
25
|
+
* provider: myProvider,
|
|
26
|
+
* transaction: myTransaction,
|
|
27
|
+
* increasePercentage: 10,
|
|
28
|
+
* enabled: true,
|
|
29
|
+
* });
|
|
30
|
+
*/
|
|
31
|
+
export declare const useTransactionWithGasPrice: ({ increasePercentage, provider, transaction, enabled, }: UseTransactionWithGasPriceProps) => TransactionRequest;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { usePromise } from '../usePromise/usePromise.js';
|
|
2
|
+
|
|
3
|
+
const increaseGasPrice = (gasPrice, increasePercentage) => {
|
|
4
|
+
const increaseFactor = 100 + increasePercentage;
|
|
5
|
+
return (gasPrice * BigInt(increaseFactor)) / BigInt(100);
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A React Hook that returns a transaction object with the gas price set to the current gas price from the provider.
|
|
9
|
+
* The gas price is increased by a certain percentage specified by the user. The hook also allows the user to enable
|
|
10
|
+
* or disable this functionality.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} props - The properties for the hook.
|
|
13
|
+
* @param {PublicClient} props.provider - The provider to use for getting the current gas price.
|
|
14
|
+
* @param {TransactionRequest} props.transaction - The transaction object.
|
|
15
|
+
* @param {number} props.increasePercentage - The percentage by which to increase the current gas price.
|
|
16
|
+
* @param {boolean} [props.enabled=true] - A flag to enable or disable the gas price increase functionality.
|
|
17
|
+
*
|
|
18
|
+
* @returns {TransactionRequest} A new transaction object with the gas price.
|
|
19
|
+
* If the `enabled` flag is set to false, or if the gas price is not available, or if the transaction already has a
|
|
20
|
+
* gas price set, the original transaction object is returned.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const updatedTransaction = useTransactionWithGasPrice({
|
|
24
|
+
* provider: myProvider,
|
|
25
|
+
* transaction: myTransaction,
|
|
26
|
+
* increasePercentage: 10,
|
|
27
|
+
* enabled: true,
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
const useTransactionWithGasPrice = ({ increasePercentage = 0, provider, transaction, enabled = true, }) => {
|
|
31
|
+
const isGasPriceDefinedInTransaction = Boolean(transaction.gasPrice);
|
|
32
|
+
const shouldLoadGasPrice = enabled && increasePercentage > 0 && !isGasPriceDefinedInTransaction;
|
|
33
|
+
const { data: gasPrice } = usePromise(() => provider.getGasPrice(), {
|
|
34
|
+
deps: [transaction, provider],
|
|
35
|
+
enabled: shouldLoadGasPrice,
|
|
36
|
+
});
|
|
37
|
+
if (!gasPrice) {
|
|
38
|
+
return transaction;
|
|
39
|
+
}
|
|
40
|
+
if (transaction.type === 'legacy' ||
|
|
41
|
+
transaction.type === 'eip2930' ||
|
|
42
|
+
transaction.type === undefined ||
|
|
43
|
+
transaction.maxFeePerGas === undefined) {
|
|
44
|
+
return Object.assign(Object.assign({}, transaction), { gasPrice: increaseGasPrice(gasPrice, increasePercentage) });
|
|
45
|
+
}
|
|
46
|
+
if (transaction.type === 'eip1559') {
|
|
47
|
+
return Object.assign(Object.assign({}, transaction), { maxFeePerGas: increaseGasPrice(gasPrice, increasePercentage) });
|
|
48
|
+
}
|
|
49
|
+
return transaction;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { useTransactionWithGasPrice };
|
|
@@ -145,6 +145,7 @@ const useVerifyWallet = ({ consumeNonce, displaySiweStatement, environmentId, pr
|
|
|
145
145
|
return ({ walletConnector, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth, }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
146
146
|
const walletProvider = getWalletProvider.getWalletProvider(walletConnector);
|
|
147
147
|
try {
|
|
148
|
+
setIsVerificationInProgress(true);
|
|
148
149
|
const Jwt = yield generateJWT(walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth);
|
|
149
150
|
const decodedJwt = decodeJwt.decodeJwt(Jwt);
|
|
150
151
|
if (decodedJwt === undefined)
|
|
@@ -141,6 +141,7 @@ const useVerifyWallet = ({ consumeNonce, displaySiweStatement, environmentId, pr
|
|
|
141
141
|
return ({ walletConnector, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
142
142
|
const walletProvider = getWalletProvider(walletConnector);
|
|
143
143
|
try {
|
|
144
|
+
setIsVerificationInProgress(true);
|
|
144
145
|
const Jwt = yield generateJWT(walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth);
|
|
145
146
|
const decodedJwt = decodeJwt(Jwt);
|
|
146
147
|
if (decodedJwt === undefined)
|
|
@@ -17,7 +17,7 @@ export type UseWalletEventListenersArgs = {
|
|
|
17
17
|
setSelectedWalletWithAction(walletWithAction: WalletWithAction | null): void;
|
|
18
18
|
user: UserProfile | undefined;
|
|
19
19
|
authMode: AuthModeType;
|
|
20
|
-
refreshConnectedWallet: (walletId: string, walletConnector: WalletConnector) => Promise<void>;
|
|
20
|
+
refreshConnectedWallet: (walletId: string, walletConnector: WalletConnector, shouldCallCallback?: boolean) => Promise<void>;
|
|
21
21
|
};
|
|
22
22
|
export declare const useWalletEventListeners: ({ computeConnectedStateForWallets, handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnector, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, authMode, refreshConnectedWallet, }: UseWalletEventListenersArgs) => {
|
|
23
23
|
loadingNetwork: boolean;
|
|
@@ -67,11 +67,11 @@ const useWalletUiUtils = ({ appLogoUrl, appName, getAppOrigin, }) => {
|
|
|
67
67
|
}
|
|
68
68
|
return openSignMessage((resolve, reject) => (jsxRuntime.jsx(SignMessageConfirmationModal.SignMessageConfirmationModal, { appLogoUrl: appLogoUrl, appName: appName, appOrigin: getAppOrigin(), message: message, handler: handler, onSignMessage: resolve, onReject: reject })));
|
|
69
69
|
}, [appLogoUrl, appName, getAppOrigin, openSignMessage, shouldConfirmAction]);
|
|
70
|
-
const sendTransaction = React.useCallback(({ transaction, handler }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
const sendTransaction = React.useCallback(({ transaction, handler, provider, connector }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
71
71
|
if (!shouldConfirmAction()) {
|
|
72
72
|
return handler(transaction);
|
|
73
73
|
}
|
|
74
|
-
return openSendTransaction((resolve, reject) => (jsxRuntime.jsx(TransactionConfirmationModal.TransactionConfirmationModal, { title: 'Send Transaction', transaction: transaction, handler: handler, onTransactionResponseSuccess: resolve, onReject: reject })));
|
|
74
|
+
return openSendTransaction((resolve, reject) => (jsxRuntime.jsx(TransactionConfirmationModal.TransactionConfirmationModal, { walletConnector: connector, title: 'Send Transaction', transaction: transaction, handler: handler, onTransactionResponseSuccess: resolve, onReject: reject, provider: provider })));
|
|
75
75
|
}), [openSendTransaction, shouldConfirmAction]);
|
|
76
76
|
const disabledConfirmationOnce = React.useCallback(() => {
|
|
77
77
|
confirmationStateRef.current = 'disabled';
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { WalletUiUtils } from '@dynamic-labs/types';
|
|
3
|
+
import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
4
|
import { WalletUiUtilsHookProps } from './useWalletUiUtils.types';
|
|
4
|
-
export declare const useWalletUiUtils: ({ appLogoUrl, appName, getAppOrigin, }: WalletUiUtilsHookProps) => [
|
|
5
|
+
export declare const useWalletUiUtils: ({ appLogoUrl, appName, getAppOrigin, }: WalletUiUtilsHookProps) => [
|
|
6
|
+
ReactNode | undefined,
|
|
7
|
+
WalletUiUtils<WalletConnector>
|
|
8
|
+
];
|
|
@@ -63,11 +63,11 @@ const useWalletUiUtils = ({ appLogoUrl, appName, getAppOrigin, }) => {
|
|
|
63
63
|
}
|
|
64
64
|
return openSignMessage((resolve, reject) => (jsx(SignMessageConfirmationModal, { appLogoUrl: appLogoUrl, appName: appName, appOrigin: getAppOrigin(), message: message, handler: handler, onSignMessage: resolve, onReject: reject })));
|
|
65
65
|
}, [appLogoUrl, appName, getAppOrigin, openSignMessage, shouldConfirmAction]);
|
|
66
|
-
const sendTransaction = useCallback(({ transaction, handler }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const sendTransaction = useCallback(({ transaction, handler, provider, connector }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
67
|
if (!shouldConfirmAction()) {
|
|
68
68
|
return handler(transaction);
|
|
69
69
|
}
|
|
70
|
-
return openSendTransaction((resolve, reject) => (jsx(TransactionConfirmationModal, { title: 'Send Transaction', transaction: transaction, handler: handler, onTransactionResponseSuccess: resolve, onReject: reject })));
|
|
70
|
+
return openSendTransaction((resolve, reject) => (jsx(TransactionConfirmationModal, { walletConnector: connector, title: 'Send Transaction', transaction: transaction, handler: handler, onTransactionResponseSuccess: resolve, onReject: reject, provider: provider })));
|
|
71
71
|
}), [openSendTransaction, shouldConfirmAction]);
|
|
72
72
|
const disabledConfirmationOnce = useCallback(() => {
|
|
73
73
|
confirmationStateRef.current = 'disabled';
|
|
@@ -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
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
5
5
|
type Props = {
|
|
6
6
|
appLogoUrl?: string;
|
|
@@ -11,7 +11,7 @@ type Props = {
|
|
|
11
11
|
walletBook: WalletBookSchema;
|
|
12
12
|
walletConnectV1Bridge?: string;
|
|
13
13
|
walletConnectorsProp?: WalletConnectorsMethod[];
|
|
14
|
-
walletUiUtils: WalletUiUtils
|
|
14
|
+
walletUiUtils: WalletUiUtils<WalletConnector>;
|
|
15
15
|
};
|
|
16
16
|
export declare const useWallets: ({ projectSettings, appLogoUrl, appName, flowNetwork, networkConfigurations, walletBook, walletConnectV1Bridge, walletUiUtils, walletConnectorsProp, }: Props) => {
|
|
17
17
|
wallets: import("../../../shared").WalletOption[];
|
|
@@ -5,11 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var iconic = require('@dynamic-labs/iconic');
|
|
8
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
9
|
require('react');
|
|
9
10
|
var Typography = require('../../components/Typography/Typography.cjs');
|
|
10
11
|
require('@dynamic-labs/sdk-api');
|
|
11
12
|
require('../../shared/logger.cjs');
|
|
12
|
-
require('@dynamic-labs/wallet-connector-core');
|
|
13
13
|
var ViewContext = require('../../context/ViewContext/ViewContext.cjs');
|
|
14
14
|
require('@dynamic-labs/wallet-book');
|
|
15
15
|
require('@dynamic-labs/utils');
|
|
@@ -47,7 +47,7 @@ require('../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
|
47
47
|
var Captcha = require('../../components/Captcha/Captcha.cjs');
|
|
48
48
|
|
|
49
49
|
const CaptchaVerifyUser = () => {
|
|
50
|
-
const { consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, selectedWalletConnector: walletConnector, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
50
|
+
const { consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, selectedWalletConnector: walletConnector, walletUiUtils, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
51
51
|
const { setView } = ViewContext.useViewContext();
|
|
52
52
|
const { setCaptchaToken } = CaptchaContext.useCaptchaContext();
|
|
53
53
|
const verifyWallet = useVerifyWallet.useVerifyWallet({
|
|
@@ -65,7 +65,13 @@ const CaptchaVerifyUser = () => {
|
|
|
65
65
|
if (!publicWalletAddress) {
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
if (!walletConnectorCore.isEmbeddedConnector(walletConnector) ||
|
|
69
|
+
walletConnectorCore.isBloctoConnector(walletConnector)) {
|
|
70
|
+
setView('pending-signature');
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
walletUiUtils.disabledConfirmationOnce();
|
|
74
|
+
}
|
|
69
75
|
if (requiresTwoStepAuthentication.requiresTwoStepAuthentication(walletConnector)) {
|
|
70
76
|
setCaptchaToken(captchaToken);
|
|
71
77
|
return;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
2
2
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { CaptchaWaveIcon } from '@dynamic-labs/iconic';
|
|
4
|
+
import { isEmbeddedConnector, isBloctoConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
5
|
import 'react';
|
|
5
6
|
import { Typography } from '../../components/Typography/Typography.js';
|
|
6
7
|
import '@dynamic-labs/sdk-api';
|
|
7
8
|
import '../../shared/logger.js';
|
|
8
|
-
import '@dynamic-labs/wallet-connector-core';
|
|
9
9
|
import { useViewContext } from '../../context/ViewContext/ViewContext.js';
|
|
10
10
|
import '@dynamic-labs/wallet-book';
|
|
11
11
|
import '@dynamic-labs/utils';
|
|
@@ -43,7 +43,7 @@ import '../../components/MenuList/Dropdown/Dropdown.js';
|
|
|
43
43
|
import { Captcha } from '../../components/Captcha/Captcha.js';
|
|
44
44
|
|
|
45
45
|
const CaptchaVerifyUser = () => {
|
|
46
|
-
const { consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, selectedWalletConnector: walletConnector, } = useInternalDynamicContext();
|
|
46
|
+
const { consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, selectedWalletConnector: walletConnector, walletUiUtils, } = useInternalDynamicContext();
|
|
47
47
|
const { setView } = useViewContext();
|
|
48
48
|
const { setCaptchaToken } = useCaptchaContext();
|
|
49
49
|
const verifyWallet = useVerifyWallet({
|
|
@@ -61,7 +61,13 @@ const CaptchaVerifyUser = () => {
|
|
|
61
61
|
if (!publicWalletAddress) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
if (!isEmbeddedConnector(walletConnector) ||
|
|
65
|
+
isBloctoConnector(walletConnector)) {
|
|
66
|
+
setView('pending-signature');
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
walletUiUtils.disabledConfirmationOnce();
|
|
70
|
+
}
|
|
65
71
|
if (requiresTwoStepAuthentication(walletConnector)) {
|
|
66
72
|
setCaptchaToken(captchaToken);
|
|
67
73
|
return;
|