@dynamic-labs/sdk-react-core 4.9.1-preview.0 → 4.9.2-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -2
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -11
- package/src/index.cjs +2 -0
- package/src/index.d.ts +4 -3
- package/src/index.js +1 -0
- package/src/lib/components/NetworkPicker/components/NetworkDropdown/NetworkDropdown.cjs +11 -2
- package/src/lib/components/NetworkPicker/components/NetworkDropdown/NetworkDropdown.js +11 -2
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.cjs +10 -4
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.js +10 -4
- package/src/lib/context/DynamicContext/DynamicContext.cjs +1 -3
- package/src/lib/context/DynamicContext/DynamicContext.js +2 -4
- package/src/lib/context/DynamicContext/hooks/useShowAuthFlow/useShowAuthFlow.cjs +1 -1
- package/src/lib/context/DynamicContext/hooks/useShowAuthFlow/useShowAuthFlow.js +1 -1
- package/src/lib/context/DynamicContext/types/IDynamicContext.d.ts +2 -3
- package/src/lib/context/DynamicContext/types/SettingsOverrides.d.ts +12 -5
- package/src/lib/context/OnrampContext/useEnabledOnrampProviders/useEnabledOnrampProviders.cjs +18 -1
- package/src/lib/context/OnrampContext/useEnabledOnrampProviders/useEnabledOnrampProviders.d.ts +2 -2
- package/src/lib/context/OnrampContext/useEnabledOnrampProviders/useEnabledOnrampProviders.js +19 -2
- package/src/lib/context/SocialRedirectContext/hooks/useRedirectSocialHandler/useRedirectSocialHandler.cjs +6 -6
- package/src/lib/context/SocialRedirectContext/hooks/useRedirectSocialHandler/useRedirectSocialHandler.js +6 -6
- package/src/lib/utils/functions/findWalletOptionFor/findWalletOptionFor.cjs +1 -1
- package/src/lib/utils/functions/findWalletOptionFor/findWalletOptionFor.js +1 -1
- package/src/lib/utils/functions/generateMessages/index.cjs +19 -9
- package/src/lib/utils/functions/generateMessages/index.js +19 -9
- package/src/lib/utils/functions/index.d.ts +0 -1
- package/src/lib/utils/functions/onrampConfigurationToOnrampOption/onrampConfigurationToOnrampOption.cjs +31 -18
- package/src/lib/utils/functions/onrampConfigurationToOnrampOption/onrampConfigurationToOnrampOption.d.ts +3 -0
- package/src/lib/utils/functions/onrampConfigurationToOnrampOption/onrampConfigurationToOnrampOption.js +31 -18
- package/src/lib/utils/functions/onrampProviders/coinbase.cjs +55 -0
- package/src/lib/utils/functions/onrampProviders/coinbase.d.ts +15 -0
- package/src/lib/utils/functions/onrampProviders/coinbase.js +50 -0
- package/src/lib/utils/functions/onrampProviders/index.cjs +24 -0
- package/src/lib/utils/functions/onrampProviders/index.d.ts +11 -0
- package/src/lib/utils/functions/onrampProviders/index.js +19 -0
- package/src/lib/utils/functions/openOnrampPopup.cjs +8 -5
- package/src/lib/utils/functions/openOnrampPopup.d.ts +4 -2
- package/src/lib/utils/functions/openOnrampPopup.js +8 -5
- package/src/lib/utils/functions/socialStorage/socialStorage.d.ts +2 -0
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.cjs +2 -2
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.js +2 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +2 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.d.ts +2 -1
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +2 -0
- package/src/lib/utils/hooks/useGlobalLoading/useGlobalLoading.cjs +1 -7
- package/src/lib/utils/hooks/useGlobalLoading/useGlobalLoading.js +1 -7
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.cjs +5 -1
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.d.ts +5 -1
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +5 -1
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +2 -1
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.d.ts +2 -1
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +2 -1
- package/src/lib/utils/hooks/useUserAuth/useUserAuth.cjs +8 -2
- package/src/lib/utils/hooks/useUserAuth/useUserAuth.js +9 -3
- package/src/lib/utils/hooks/useWalletItemActions/useHandleWalletItem/useHandleWalletItem.cjs +4 -0
- package/src/lib/utils/hooks/useWalletItemActions/useHandleWalletItem/useHandleWalletItem.js +4 -0
- package/src/lib/widgets/DynamicEmbeddedWidget/DynamicEmbeddedAuthFlow/DynamicEmbeddedAuthFlow.cjs +5 -7
- package/src/lib/widgets/DynamicEmbeddedWidget/DynamicEmbeddedAuthFlow/DynamicEmbeddedAuthFlow.js +5 -7
- package/src/lib/widgets/OnrampWidget/OnrampWidget.cjs +11 -2
- package/src/lib/widgets/OnrampWidget/OnrampWidget.d.ts +4 -0
- package/src/lib/widgets/OnrampWidget/OnrampWidget.js +11 -2
- package/src/lib/utils/functions/coinbaseOnramp/formatCoinbaseOnrampUrl.cjs +0 -27
- package/src/lib/utils/functions/coinbaseOnramp/formatCoinbaseOnrampUrl.d.ts +0 -2
- package/src/lib/utils/functions/coinbaseOnramp/formatCoinbaseOnrampUrl.js +0 -23
- package/src/lib/utils/functions/coinbaseOnramp/index.d.ts +0 -1
|
@@ -7,6 +7,24 @@ var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
|
7
7
|
var multiWallet = require('@dynamic-labs/multi-wallet');
|
|
8
8
|
var utils = require('@dynamic-labs/utils');
|
|
9
9
|
|
|
10
|
+
const getChainIdForMessage = (walletConnector) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
// If it's a Solana wallet, we should not specify a chainId
|
|
12
|
+
// since it breaks the message signature in some wallets (e.g. Trust Wallet)
|
|
13
|
+
if (walletConnector.connectedChain === 'SOL') {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const chain = yield walletConnector.getNetwork(true);
|
|
17
|
+
if (chain) {
|
|
18
|
+
return chain;
|
|
19
|
+
}
|
|
20
|
+
if (walletConnector.key === 'bloctoevm') {
|
|
21
|
+
return 137;
|
|
22
|
+
}
|
|
23
|
+
if (walletConnector.connectedChain === 'EVM') {
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
return chain;
|
|
27
|
+
});
|
|
10
28
|
const generateMessages = (publicWalletAddress, walletConnector, nonce, projectEnvironmentId, displaySiweStatement, siweStatement) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
11
29
|
if (publicWalletAddress === undefined) {
|
|
12
30
|
throw new utils.DynamicError('Unable to fetch the public address from the wallet');
|
|
@@ -14,15 +32,7 @@ const generateMessages = (publicWalletAddress, walletConnector, nonce, projectEn
|
|
|
14
32
|
if (!walletConnector.connectedChain) {
|
|
15
33
|
throw new utils.DynamicError('Wallet is not connected');
|
|
16
34
|
}
|
|
17
|
-
|
|
18
|
-
if (chainId === undefined) {
|
|
19
|
-
if (walletConnector.key === 'bloctoevm') {
|
|
20
|
-
chainId = 137;
|
|
21
|
-
}
|
|
22
|
-
else if (walletConnector.connectedChain === 'EVM') {
|
|
23
|
-
chainId = 1;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
35
|
+
const chainId = yield getChainIdForMessage(walletConnector);
|
|
26
36
|
const parsedAddress = walletConnector.parseAddress(publicWalletAddress);
|
|
27
37
|
const currentUrl = utils.PlatformService.getUrl();
|
|
28
38
|
const messageToSign = multiWallet.generateMessageToSign({
|
|
@@ -3,6 +3,24 @@ import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
|
3
3
|
import { generateMessageToSign } from '@dynamic-labs/multi-wallet';
|
|
4
4
|
import { DynamicError, PlatformService } from '@dynamic-labs/utils';
|
|
5
5
|
|
|
6
|
+
const getChainIdForMessage = (walletConnector) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7
|
+
// If it's a Solana wallet, we should not specify a chainId
|
|
8
|
+
// since it breaks the message signature in some wallets (e.g. Trust Wallet)
|
|
9
|
+
if (walletConnector.connectedChain === 'SOL') {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const chain = yield walletConnector.getNetwork(true);
|
|
13
|
+
if (chain) {
|
|
14
|
+
return chain;
|
|
15
|
+
}
|
|
16
|
+
if (walletConnector.key === 'bloctoevm') {
|
|
17
|
+
return 137;
|
|
18
|
+
}
|
|
19
|
+
if (walletConnector.connectedChain === 'EVM') {
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
return chain;
|
|
23
|
+
});
|
|
6
24
|
const generateMessages = (publicWalletAddress, walletConnector, nonce, projectEnvironmentId, displaySiweStatement, siweStatement) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7
25
|
if (publicWalletAddress === undefined) {
|
|
8
26
|
throw new DynamicError('Unable to fetch the public address from the wallet');
|
|
@@ -10,15 +28,7 @@ const generateMessages = (publicWalletAddress, walletConnector, nonce, projectEn
|
|
|
10
28
|
if (!walletConnector.connectedChain) {
|
|
11
29
|
throw new DynamicError('Wallet is not connected');
|
|
12
30
|
}
|
|
13
|
-
|
|
14
|
-
if (chainId === undefined) {
|
|
15
|
-
if (walletConnector.key === 'bloctoevm') {
|
|
16
|
-
chainId = 137;
|
|
17
|
-
}
|
|
18
|
-
else if (walletConnector.connectedChain === 'EVM') {
|
|
19
|
-
chainId = 1;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
31
|
+
const chainId = yield getChainIdForMessage(walletConnector);
|
|
22
32
|
const parsedAddress = walletConnector.parseAddress(publicWalletAddress);
|
|
23
33
|
const currentUrl = PlatformService.getUrl();
|
|
24
34
|
const messageToSign = generateMessageToSign({
|
|
@@ -4,28 +4,41 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var openOnrampPopup = require('../openOnrampPopup.cjs');
|
|
7
|
+
var index = require('../onrampProviders/index.cjs');
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Converts an OnrampConfiguration to an OnrampOption based on the provider's display mode
|
|
11
|
+
*/
|
|
8
12
|
const onrampConfigurationToOnrampOption = (provider, onClick, setShowOnramp) => {
|
|
9
|
-
var _a, _b, _c;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
var _a, _b, _c, _d;
|
|
14
|
+
// Determine if this provider uses popup or iframe mode
|
|
15
|
+
const providerKey = provider.provider;
|
|
16
|
+
const openMode = (_a = index.providerDisplayModes[providerKey]) !== null && _a !== void 0 ? _a : 'iframe';
|
|
17
|
+
// Create common properties
|
|
18
|
+
const baseProperties = {
|
|
19
|
+
displayName: (_c = (_b = provider.name) !== null && _b !== void 0 ? _b : provider.provider) !== null && _c !== void 0 ? _c : '',
|
|
20
|
+
iconUrl: (_d = provider.iconUrl) !== null && _d !== void 0 ? _d : '',
|
|
14
21
|
id: String(provider.provider),
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
onClick: (params) => {
|
|
18
|
-
// Call the provided onClick to set the selected provider
|
|
19
|
-
onClick({
|
|
20
|
-
onrampProvider: provider.provider,
|
|
21
|
-
});
|
|
22
|
-
// For Coinbase, handle the popup opening directly in the onClick
|
|
23
|
-
if (isPopupImplementation && provider.url && setShowOnramp) {
|
|
24
|
-
// Use the new openOnrampPopup function to handle the popup logic
|
|
25
|
-
openOnrampPopup.openOnrampPopup(provider.url, params.wallet, setShowOnramp);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
22
|
+
openMode,
|
|
23
|
+
url: provider.url,
|
|
28
24
|
};
|
|
25
|
+
// Create base onClick handler
|
|
26
|
+
const baseOnClick = (params) => {
|
|
27
|
+
onClick({
|
|
28
|
+
onrampProvider: provider.provider,
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
// For popup mode, enhance the onClick handler to open the popup
|
|
32
|
+
if (openMode === 'popup') {
|
|
33
|
+
return Object.assign(Object.assign({}, baseProperties), { onClick: (params) => {
|
|
34
|
+
baseOnClick();
|
|
35
|
+
if (provider.url && setShowOnramp) {
|
|
36
|
+
openOnrampPopup.openOnrampPopup(provider.url, params.wallet, setShowOnramp, provider.provider);
|
|
37
|
+
}
|
|
38
|
+
} });
|
|
39
|
+
}
|
|
40
|
+
// For iframe mode, use the base onClick handler
|
|
41
|
+
return Object.assign(Object.assign({}, baseProperties), { onClick: baseOnClick });
|
|
29
42
|
};
|
|
30
43
|
|
|
31
44
|
exports.onrampConfigurationToOnrampOption = onrampConfigurationToOnrampOption;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { OnrampConfiguration, OnrampProviders } from '@dynamic-labs/sdk-api-core';
|
|
2
2
|
import type { OnrampOption } from '../../../context/DynamicContext';
|
|
3
|
+
/**
|
|
4
|
+
* Converts an OnrampConfiguration to an OnrampOption based on the provider's display mode
|
|
5
|
+
*/
|
|
3
6
|
export declare const onrampConfigurationToOnrampOption: (provider: OnrampConfiguration, onClick: ({ onrampProvider }: {
|
|
4
7
|
onrampProvider: OnrampProviders;
|
|
5
8
|
}) => void, setShowOnramp?: (show: boolean) => void) => OnrampOption;
|
|
@@ -1,27 +1,40 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { openOnrampPopup } from '../openOnrampPopup.js';
|
|
3
|
+
import { providerDisplayModes } from '../onrampProviders/index.js';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Converts an OnrampConfiguration to an OnrampOption based on the provider's display mode
|
|
7
|
+
*/
|
|
4
8
|
const onrampConfigurationToOnrampOption = (provider, onClick, setShowOnramp) => {
|
|
5
|
-
var _a, _b, _c;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
var _a, _b, _c, _d;
|
|
10
|
+
// Determine if this provider uses popup or iframe mode
|
|
11
|
+
const providerKey = provider.provider;
|
|
12
|
+
const openMode = (_a = providerDisplayModes[providerKey]) !== null && _a !== void 0 ? _a : 'iframe';
|
|
13
|
+
// Create common properties
|
|
14
|
+
const baseProperties = {
|
|
15
|
+
displayName: (_c = (_b = provider.name) !== null && _b !== void 0 ? _b : provider.provider) !== null && _c !== void 0 ? _c : '',
|
|
16
|
+
iconUrl: (_d = provider.iconUrl) !== null && _d !== void 0 ? _d : '',
|
|
10
17
|
id: String(provider.provider),
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
onClick: (params) => {
|
|
14
|
-
// Call the provided onClick to set the selected provider
|
|
15
|
-
onClick({
|
|
16
|
-
onrampProvider: provider.provider,
|
|
17
|
-
});
|
|
18
|
-
// For Coinbase, handle the popup opening directly in the onClick
|
|
19
|
-
if (isPopupImplementation && provider.url && setShowOnramp) {
|
|
20
|
-
// Use the new openOnrampPopup function to handle the popup logic
|
|
21
|
-
openOnrampPopup(provider.url, params.wallet, setShowOnramp);
|
|
22
|
-
}
|
|
23
|
-
},
|
|
18
|
+
openMode,
|
|
19
|
+
url: provider.url,
|
|
24
20
|
};
|
|
21
|
+
// Create base onClick handler
|
|
22
|
+
const baseOnClick = (params) => {
|
|
23
|
+
onClick({
|
|
24
|
+
onrampProvider: provider.provider,
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
// For popup mode, enhance the onClick handler to open the popup
|
|
28
|
+
if (openMode === 'popup') {
|
|
29
|
+
return Object.assign(Object.assign({}, baseProperties), { onClick: (params) => {
|
|
30
|
+
baseOnClick();
|
|
31
|
+
if (provider.url && setShowOnramp) {
|
|
32
|
+
openOnrampPopup(provider.url, params.wallet, setShowOnramp, provider.provider);
|
|
33
|
+
}
|
|
34
|
+
} });
|
|
35
|
+
}
|
|
36
|
+
// For iframe mode, use the base onClick handler
|
|
37
|
+
return Object.assign(Object.assign({}, baseProperties), { onClick: baseOnClick });
|
|
25
38
|
};
|
|
26
39
|
|
|
27
40
|
export { onrampConfigurationToOnrampOption };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gets the enabled non-testnet networks for a wallet
|
|
8
|
+
* @param wallet User's wallet
|
|
9
|
+
* @returns Array of enabled non-testnet networks, or empty array if no wallet or networks
|
|
10
|
+
*/
|
|
11
|
+
const getEnabledNonTestnetNetworks = (wallet) => {
|
|
12
|
+
if (!wallet ||
|
|
13
|
+
!wallet.connector ||
|
|
14
|
+
typeof wallet.connector.getEnabledNetworks !== 'function') {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const networks = wallet.connector.getEnabledNetworks();
|
|
18
|
+
if (!networks || networks.length === 0) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
return networks.filter((network) => !network.isTestnet);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Formats a Coinbase onramp URL with wallet information
|
|
25
|
+
* @param url Base URL from Coinbase
|
|
26
|
+
* @param wallet User's wallet
|
|
27
|
+
* @returns Formatted URL with wallet information
|
|
28
|
+
*/
|
|
29
|
+
const formatCoinbaseOnrampUrl = (url, wallet) => {
|
|
30
|
+
const nonTestnetNetworks = getEnabledNonTestnetNetworks(wallet);
|
|
31
|
+
if (nonTestnetNetworks.length === 0 || !(wallet === null || wallet === void 0 ? void 0 : wallet.address)) {
|
|
32
|
+
return url;
|
|
33
|
+
}
|
|
34
|
+
const baseUrl = new URL(url);
|
|
35
|
+
const appId = baseUrl.searchParams.get('appId');
|
|
36
|
+
// If no appId is present, return the original URL
|
|
37
|
+
if (!appId) {
|
|
38
|
+
return url;
|
|
39
|
+
}
|
|
40
|
+
// Filter out networks with empty or undefined keys and remove duplicates
|
|
41
|
+
const uniqueNetworkKeys = Array.from(new Set(nonTestnetNetworks
|
|
42
|
+
.map((network) => network.key)
|
|
43
|
+
.filter((key) => Boolean(key))));
|
|
44
|
+
if (uniqueNetworkKeys.length === 0) {
|
|
45
|
+
return url;
|
|
46
|
+
}
|
|
47
|
+
// Construct the URL with the raw query parameters
|
|
48
|
+
const finalUrl = `${baseUrl.origin}${baseUrl.pathname}?appId=${appId}&addresses=${encodeURIComponent(JSON.stringify({
|
|
49
|
+
[wallet.address]: uniqueNetworkKeys,
|
|
50
|
+
}))}`;
|
|
51
|
+
return finalUrl;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
exports.formatCoinbaseOnrampUrl = formatCoinbaseOnrampUrl;
|
|
55
|
+
exports.getEnabledNonTestnetNetworks = getEnabledNonTestnetNetworks;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import type { GenericNetwork } from '@dynamic-labs/types';
|
|
3
|
+
/**
|
|
4
|
+
* Gets the enabled non-testnet networks for a wallet
|
|
5
|
+
* @param wallet User's wallet
|
|
6
|
+
* @returns Array of enabled non-testnet networks, or empty array if no wallet or networks
|
|
7
|
+
*/
|
|
8
|
+
export declare const getEnabledNonTestnetNetworks: (wallet?: Wallet) => GenericNetwork[];
|
|
9
|
+
/**
|
|
10
|
+
* Formats a Coinbase onramp URL with wallet information
|
|
11
|
+
* @param url Base URL from Coinbase
|
|
12
|
+
* @param wallet User's wallet
|
|
13
|
+
* @returns Formatted URL with wallet information
|
|
14
|
+
*/
|
|
15
|
+
export declare const formatCoinbaseOnrampUrl: (url: string, wallet?: Wallet) => string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/**
|
|
3
|
+
* Gets the enabled non-testnet networks for a wallet
|
|
4
|
+
* @param wallet User's wallet
|
|
5
|
+
* @returns Array of enabled non-testnet networks, or empty array if no wallet or networks
|
|
6
|
+
*/
|
|
7
|
+
const getEnabledNonTestnetNetworks = (wallet) => {
|
|
8
|
+
if (!wallet ||
|
|
9
|
+
!wallet.connector ||
|
|
10
|
+
typeof wallet.connector.getEnabledNetworks !== 'function') {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const networks = wallet.connector.getEnabledNetworks();
|
|
14
|
+
if (!networks || networks.length === 0) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
return networks.filter((network) => !network.isTestnet);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Formats a Coinbase onramp URL with wallet information
|
|
21
|
+
* @param url Base URL from Coinbase
|
|
22
|
+
* @param wallet User's wallet
|
|
23
|
+
* @returns Formatted URL with wallet information
|
|
24
|
+
*/
|
|
25
|
+
const formatCoinbaseOnrampUrl = (url, wallet) => {
|
|
26
|
+
const nonTestnetNetworks = getEnabledNonTestnetNetworks(wallet);
|
|
27
|
+
if (nonTestnetNetworks.length === 0 || !(wallet === null || wallet === void 0 ? void 0 : wallet.address)) {
|
|
28
|
+
return url;
|
|
29
|
+
}
|
|
30
|
+
const baseUrl = new URL(url);
|
|
31
|
+
const appId = baseUrl.searchParams.get('appId');
|
|
32
|
+
// If no appId is present, return the original URL
|
|
33
|
+
if (!appId) {
|
|
34
|
+
return url;
|
|
35
|
+
}
|
|
36
|
+
// Filter out networks with empty or undefined keys and remove duplicates
|
|
37
|
+
const uniqueNetworkKeys = Array.from(new Set(nonTestnetNetworks
|
|
38
|
+
.map((network) => network.key)
|
|
39
|
+
.filter((key) => Boolean(key))));
|
|
40
|
+
if (uniqueNetworkKeys.length === 0) {
|
|
41
|
+
return url;
|
|
42
|
+
}
|
|
43
|
+
// Construct the URL with the raw query parameters
|
|
44
|
+
const finalUrl = `${baseUrl.origin}${baseUrl.pathname}?appId=${appId}&addresses=${encodeURIComponent(JSON.stringify({
|
|
45
|
+
[wallet.address]: uniqueNetworkKeys,
|
|
46
|
+
}))}`;
|
|
47
|
+
return finalUrl;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { formatCoinbaseOnrampUrl, getEnabledNonTestnetNetworks };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var coinbase = require('./coinbase.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registry of provider-specific URL formatters
|
|
10
|
+
*/
|
|
11
|
+
const providerUrlFormatters = {
|
|
12
|
+
coinbaseOnramp: coinbase.formatCoinbaseOnrampUrl,
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Registry of provider display modes (iframe or popup)
|
|
16
|
+
*/
|
|
17
|
+
const providerDisplayModes = {
|
|
18
|
+
coinbaseOnramp: 'popup',
|
|
19
|
+
// Default for other providers is iframe
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.formatCoinbaseOnrampUrl = coinbase.formatCoinbaseOnrampUrl;
|
|
23
|
+
exports.providerDisplayModes = providerDisplayModes;
|
|
24
|
+
exports.providerUrlFormatters = providerUrlFormatters;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { formatCoinbaseOnrampUrl } from './coinbase';
|
|
3
|
+
/**
|
|
4
|
+
* Registry of provider-specific URL formatters
|
|
5
|
+
*/
|
|
6
|
+
export declare const providerUrlFormatters: Record<string, (url: string, wallet: Wallet) => string>;
|
|
7
|
+
/**
|
|
8
|
+
* Registry of provider display modes (iframe or popup)
|
|
9
|
+
*/
|
|
10
|
+
export declare const providerDisplayModes: Record<string, 'iframe' | 'popup'>;
|
|
11
|
+
export { formatCoinbaseOnrampUrl };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { formatCoinbaseOnrampUrl } from './coinbase.js';
|
|
3
|
+
export { formatCoinbaseOnrampUrl } from './coinbase.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Registry of provider-specific URL formatters
|
|
7
|
+
*/
|
|
8
|
+
const providerUrlFormatters = {
|
|
9
|
+
coinbaseOnramp: formatCoinbaseOnrampUrl,
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Registry of provider display modes (iframe or popup)
|
|
13
|
+
*/
|
|
14
|
+
const providerDisplayModes = {
|
|
15
|
+
coinbaseOnramp: 'popup',
|
|
16
|
+
// Default for other providers is iframe
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { providerDisplayModes, providerUrlFormatters };
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
|
-
var
|
|
7
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
8
|
+
var index = require('./onrampProviders/index.cjs');
|
|
8
9
|
var openPopup = require('./openPopup/openPopup.cjs');
|
|
9
10
|
|
|
10
11
|
const ONRAMP_POPUP_CONFIG = {
|
|
@@ -12,15 +13,17 @@ const ONRAMP_POPUP_CONFIG = {
|
|
|
12
13
|
width: 500,
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
15
|
-
* Opens an onramp popup
|
|
16
|
+
* Opens an onramp popup and sets up event listeners to handle popup closure
|
|
16
17
|
* @param url The base URL to open in the popup
|
|
17
18
|
* @param wallet The user's wallet (optional)
|
|
18
19
|
* @param setShowOnramp Callback to update the UI state when popup is closed
|
|
20
|
+
* @param provider The onramp provider ID
|
|
19
21
|
* @returns A promise that resolves when the popup is opened
|
|
20
22
|
*/
|
|
21
|
-
const openOnrampPopup = (
|
|
22
|
-
// Format the URL with wallet information
|
|
23
|
-
const
|
|
23
|
+
const openOnrampPopup = (url_1, wallet_1, setShowOnramp_1, ...args_1) => _tslib.__awaiter(void 0, [url_1, wallet_1, setShowOnramp_1, ...args_1], void 0, function* (url, wallet, setShowOnramp, provider = sdkApiCore.OnrampProviders.CoinbaseOnramp) {
|
|
24
|
+
// Format the URL with wallet information if a formatter exists for this provider
|
|
25
|
+
const formatUrl = index.providerUrlFormatters[provider] || ((url) => url);
|
|
26
|
+
const formattedUrl = wallet ? formatUrl(url, wallet) : url;
|
|
24
27
|
// Open the popup - errors will propagate to the caller
|
|
25
28
|
yield openPopup.openPopup(formattedUrl, ONRAMP_POPUP_CONFIG.width, ONRAMP_POPUP_CONFIG.height, () => {
|
|
26
29
|
// When the popup is closed (by user or programmatically), update the UI
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { OnrampProviders } from '@dynamic-labs/sdk-api-core';
|
|
2
3
|
export declare const ONRAMP_POPUP_CONFIG: {
|
|
3
4
|
readonly height: 600;
|
|
4
5
|
readonly width: 500;
|
|
5
6
|
};
|
|
6
7
|
/**
|
|
7
|
-
* Opens an onramp popup
|
|
8
|
+
* Opens an onramp popup and sets up event listeners to handle popup closure
|
|
8
9
|
* @param url The base URL to open in the popup
|
|
9
10
|
* @param wallet The user's wallet (optional)
|
|
10
11
|
* @param setShowOnramp Callback to update the UI state when popup is closed
|
|
12
|
+
* @param provider The onramp provider ID
|
|
11
13
|
* @returns A promise that resolves when the popup is opened
|
|
12
14
|
*/
|
|
13
|
-
export declare const openOnrampPopup: (url: string, wallet: Wallet | undefined, setShowOnramp: (show: boolean) => void) => Promise<void>;
|
|
15
|
+
export declare const openOnrampPopup: (url: string, wallet: Wallet | undefined, setShowOnramp: (show: boolean) => void, provider?: OnrampProviders) => Promise<void>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
|
-
import {
|
|
3
|
+
import { OnrampProviders } from '@dynamic-labs/sdk-api-core';
|
|
4
|
+
import { providerUrlFormatters } from './onrampProviders/index.js';
|
|
4
5
|
import { openPopup } from './openPopup/openPopup.js';
|
|
5
6
|
|
|
6
7
|
const ONRAMP_POPUP_CONFIG = {
|
|
@@ -8,15 +9,17 @@ const ONRAMP_POPUP_CONFIG = {
|
|
|
8
9
|
width: 500,
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
|
-
* Opens an onramp popup
|
|
12
|
+
* Opens an onramp popup and sets up event listeners to handle popup closure
|
|
12
13
|
* @param url The base URL to open in the popup
|
|
13
14
|
* @param wallet The user's wallet (optional)
|
|
14
15
|
* @param setShowOnramp Callback to update the UI state when popup is closed
|
|
16
|
+
* @param provider The onramp provider ID
|
|
15
17
|
* @returns A promise that resolves when the popup is opened
|
|
16
18
|
*/
|
|
17
|
-
const openOnrampPopup = (
|
|
18
|
-
// Format the URL with wallet information
|
|
19
|
-
const
|
|
19
|
+
const openOnrampPopup = (url_1, wallet_1, setShowOnramp_1, ...args_1) => __awaiter(void 0, [url_1, wallet_1, setShowOnramp_1, ...args_1], void 0, function* (url, wallet, setShowOnramp, provider = OnrampProviders.CoinbaseOnramp) {
|
|
20
|
+
// Format the URL with wallet information if a formatter exists for this provider
|
|
21
|
+
const formatUrl = providerUrlFormatters[provider] || ((url) => url);
|
|
22
|
+
const formattedUrl = wallet ? formatUrl(url, wallet) : url;
|
|
20
23
|
// Open the popup - errors will propagate to the caller
|
|
21
24
|
yield openPopup(formattedUrl, ONRAMP_POPUP_CONFIG.width, ONRAMP_POPUP_CONFIG.height, () => {
|
|
22
25
|
// When the popup is closed (by user or programmatically), update the UI
|
|
@@ -13,6 +13,8 @@ export type SocialStorageItem = {
|
|
|
13
13
|
code?: string;
|
|
14
14
|
/** Social auth mode, either sign-in or link */
|
|
15
15
|
mode: SocialAuthMode;
|
|
16
|
+
/** Whether to show the widget after a connection is made */
|
|
17
|
+
showWidgetAfterConnection?: boolean;
|
|
16
18
|
};
|
|
17
19
|
export type SocialStorage = Partial<Record<ProviderEnum, SocialStorageItem>>;
|
|
18
20
|
export declare const searchSocialStorageByState: (targetState: string) => SocialStorageItem | undefined;
|
|
@@ -133,8 +133,8 @@ const useDynamicWaas = () => {
|
|
|
133
133
|
}
|
|
134
134
|
if (!walletConnectorOptions.length || !environmentId || !apiBaseUrl)
|
|
135
135
|
return undefined;
|
|
136
|
-
const
|
|
137
|
-
|
|
136
|
+
const walletConnector = (_a = walletConnectorOptions.find((option) => option.key.includes(dynamicWaasKey) &&
|
|
137
|
+
option.walletConnector.connectedChain === chainName)) === null || _a === void 0 ? void 0 : _a.walletConnector;
|
|
138
138
|
if (!walletConnector) {
|
|
139
139
|
throw new utils.DynamicError(constants.DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR);
|
|
140
140
|
}
|
|
@@ -129,8 +129,8 @@ const useDynamicWaas = () => {
|
|
|
129
129
|
}
|
|
130
130
|
if (!walletConnectorOptions.length || !environmentId || !apiBaseUrl)
|
|
131
131
|
return undefined;
|
|
132
|
-
const
|
|
133
|
-
|
|
132
|
+
const walletConnector = (_a = walletConnectorOptions.find((option) => option.key.includes(dynamicWaasKey) &&
|
|
133
|
+
option.walletConnector.connectedChain === chainName)) === null || _a === void 0 ? void 0 : _a.walletConnector;
|
|
134
134
|
if (!walletConnector) {
|
|
135
135
|
throw new DynamicError(DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR);
|
|
136
136
|
}
|
|
@@ -160,6 +160,7 @@ const useEmbeddedWallet = () => {
|
|
|
160
160
|
return revealTurnkeyEmbeddedWalletKey(options);
|
|
161
161
|
});
|
|
162
162
|
const shouldPromptForKeyExport = React.useCallback(() => { var _a; return Boolean((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.promptForKeyExport); }, [projectSettings]);
|
|
163
|
+
const embeddedWalletSettingVersion = React.useCallback(() => { var _a; return (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.defaultWalletVersion; }, [projectSettings]);
|
|
163
164
|
const shouldAutoCreateEmbeddedWallet = React.useCallback((verifiedUser) => {
|
|
164
165
|
var _a, _b, _c, _d, _e, _f;
|
|
165
166
|
const hasEmbeddedWalletProviderEnabled = isTurnkeyEnabled.isTurnkeyEnabled(projectSettings);
|
|
@@ -197,6 +198,7 @@ const useEmbeddedWallet = () => {
|
|
|
197
198
|
createEmbeddedWalletAccount,
|
|
198
199
|
createOrRestoreSession,
|
|
199
200
|
createPasskey,
|
|
201
|
+
embeddedWalletSettingVersion,
|
|
200
202
|
getPasskeys,
|
|
201
203
|
getWalletVersion,
|
|
202
204
|
isLoadingEmbeddedWallet,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmbeddedWalletChainEnum } from '@dynamic-labs/sdk-api-core';
|
|
1
|
+
import { EmbeddedWalletChainEnum, EmbeddedWalletVersionEnum } from '@dynamic-labs/sdk-api-core';
|
|
2
2
|
import { Wallet } from '../../../shared';
|
|
3
3
|
import { UserProfile } from '../../../..';
|
|
4
4
|
/**
|
|
@@ -27,6 +27,7 @@ export declare const useEmbeddedWallet: () => {
|
|
|
27
27
|
readonly createPasskey: (options: {
|
|
28
28
|
oneTimeCode: string;
|
|
29
29
|
} | undefined) => Promise<import("dist/packages/wallet-connector-core/src").WebAuthnAttestation>;
|
|
30
|
+
readonly embeddedWalletSettingVersion: () => EmbeddedWalletVersionEnum | undefined;
|
|
30
31
|
readonly getPasskeys: () => Promise<import("@dynamic-labs/sdk-api-core").UserPasskey[]>;
|
|
31
32
|
readonly getWalletVersion: () => import(".").EmbeddedWalletVersion | undefined;
|
|
32
33
|
readonly isLoadingEmbeddedWallet: boolean;
|
|
@@ -156,6 +156,7 @@ const useEmbeddedWallet = () => {
|
|
|
156
156
|
return revealTurnkeyEmbeddedWalletKey(options);
|
|
157
157
|
});
|
|
158
158
|
const shouldPromptForKeyExport = useCallback(() => { var _a; return Boolean((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.promptForKeyExport); }, [projectSettings]);
|
|
159
|
+
const embeddedWalletSettingVersion = useCallback(() => { var _a; return (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.defaultWalletVersion; }, [projectSettings]);
|
|
159
160
|
const shouldAutoCreateEmbeddedWallet = useCallback((verifiedUser) => {
|
|
160
161
|
var _a, _b, _c, _d, _e, _f;
|
|
161
162
|
const hasEmbeddedWalletProviderEnabled = isTurnkeyEnabled(projectSettings);
|
|
@@ -193,6 +194,7 @@ const useEmbeddedWallet = () => {
|
|
|
193
194
|
createEmbeddedWalletAccount,
|
|
194
195
|
createOrRestoreSession,
|
|
195
196
|
createPasskey,
|
|
197
|
+
embeddedWalletSettingVersion,
|
|
196
198
|
getPasskeys,
|
|
197
199
|
getWalletVersion,
|
|
198
200
|
isLoadingEmbeddedWallet,
|
|
@@ -9,7 +9,6 @@ var logger = require('../../../shared/logger.cjs');
|
|
|
9
9
|
var index = require('../../../shared/utils/functions/lastAuthenticatedAccount/index.cjs');
|
|
10
10
|
var shouldFetchNonce = require('../../../shared/utils/functions/shouldFetchNonce/shouldFetchNonce.cjs');
|
|
11
11
|
var loadingAndLifecycle = require('../../../store/state/loadingAndLifecycle.cjs');
|
|
12
|
-
var connectorsInitializing = require('../../../store/state/connectorsInitializing/connectorsInitializing.cjs');
|
|
13
12
|
|
|
14
13
|
const useGlobalLoading = ({ authMode, connectedInfo, connectedWallets, projectSettings, primaryWalletId, primaryWallet, user, isUserLoading, walletBook: walletBook$1, enableInstrumentation, appName, environmentId, nonce, }) => {
|
|
15
14
|
var _a;
|
|
@@ -17,8 +16,6 @@ const useGlobalLoading = ({ authMode, connectedInfo, connectedWallets, projectSe
|
|
|
17
16
|
const hasLoaded = React.useRef(false);
|
|
18
17
|
const loadingStart = React.useRef(new Date().getTime());
|
|
19
18
|
const { sessionValidation } = loadingAndLifecycle.useLoadingAndLifecycle();
|
|
20
|
-
const connectorsInitializingState = connectorsInitializing.useConnectorsInitializing();
|
|
21
|
-
const isWaitingForConnectorsInitialization = React.useMemo(() => Object.values(connectorsInitializingState).some(Boolean), [connectorsInitializingState]);
|
|
22
19
|
const isFetchingNonce = React.useMemo(() => shouldFetchNonce.shouldFetchNonce({
|
|
23
20
|
authMode,
|
|
24
21
|
}) && !nonce, [authMode, nonce]);
|
|
@@ -59,14 +56,12 @@ const useGlobalLoading = ({ authMode, connectedInfo, connectedWallets, projectSe
|
|
|
59
56
|
connectedWallets.length === 0;
|
|
60
57
|
const isValidatingSession = !sessionValidation;
|
|
61
58
|
logger.logger.logVerboseTroubleshootingMessage('[useGlobalLoading] SDK loading', {
|
|
62
|
-
connectorsInitializingState,
|
|
63
59
|
isConnectOnlyWalletsLoading,
|
|
64
60
|
isFetchingNonce,
|
|
65
61
|
isPrimaryWalletLoading,
|
|
66
62
|
isProjectSettingsLoading,
|
|
67
63
|
isUserLoading,
|
|
68
64
|
isValidatingSession,
|
|
69
|
-
isWaitingForConnectorsInitialization,
|
|
70
65
|
isWalletBookLoading,
|
|
71
66
|
});
|
|
72
67
|
if (!isWalletBookLoading &&
|
|
@@ -75,8 +70,7 @@ const useGlobalLoading = ({ authMode, connectedInfo, connectedWallets, projectSe
|
|
|
75
70
|
!isPrimaryWalletLoading &&
|
|
76
71
|
!isConnectOnlyWalletsLoading &&
|
|
77
72
|
!isValidatingSession &&
|
|
78
|
-
!isFetchingNonce
|
|
79
|
-
!isWaitingForConnectorsInitialization) {
|
|
73
|
+
!isFetchingNonce) {
|
|
80
74
|
finishLoading();
|
|
81
75
|
}
|
|
82
76
|
return hasLoaded.current;
|