@dynamic-labs/sdk-react-core 1.0.0-alpha.11 → 1.0.0-alpha.13
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 +19 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +10 -10
- package/src/index.cjs +3 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +2 -0
- package/src/lib/components/SecureTurnkeyWalletCard/SecureTurnkeyWalletCard.cjs +1 -1
- package/src/lib/components/SecureTurnkeyWalletCard/SecureTurnkeyWalletCard.js +1 -1
- package/src/lib/context/FundingContext/FundingContext.cjs +35 -27
- package/src/lib/context/FundingContext/FundingContext.d.ts +4 -0
- package/src/lib/context/FundingContext/FundingContext.js +36 -28
- package/src/lib/context/FundingContext/index.d.ts +1 -0
- package/src/lib/context/FundingContext/useFunding/index.d.ts +1 -0
- package/src/lib/context/FundingContext/useFunding/useFunding.cjs +39 -0
- package/src/lib/context/FundingContext/useFunding/useFunding.d.ts +9 -0
- package/src/lib/context/FundingContext/useFunding/useFunding.js +35 -0
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.cjs +5 -5
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.js +5 -5
- package/src/lib/utils/hooks/useWalletConnectors/utils/updateUserWalletsFromLinkedWallets/updateUserWalletsFromLinkedWallets.cjs +0 -2
- package/src/lib/utils/hooks/useWalletConnectors/utils/updateUserWalletsFromLinkedWallets/updateUserWalletsFromLinkedWallets.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
|
|
2
|
+
## [1.0.0-alpha.13](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.12...v1.0.0-alpha.13) (2023-12-12)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* embedded wallet connected flag not picking up ([#4128](https://github.com/dynamic-labs/DynamicAuth/issues/4128)) ([c6fbb1d](https://github.com/dynamic-labs/DynamicAuth/commit/c6fbb1de2027b186a4277a75545fd66d0d11ba95))
|
|
8
|
+
|
|
9
|
+
## [1.0.0-alpha.12](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.11...v1.0.0-alpha.12) (2023-12-11)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* add useFunding hook ([#4098](https://github.com/dynamic-labs/DynamicAuth/issues/4098)) ([27424ab](https://github.com/dynamic-labs/DynamicAuth/commit/27424ab1a15202ee2b7c73c8a19f11e480e1794a))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* add primary color to the secure wallet text ([#4127](https://github.com/dynamic-labs/DynamicAuth/issues/4127)) ([7c642d0](https://github.com/dynamic-labs/DynamicAuth/commit/7c642d0385112289df52874bc5dd2eaa0e6cdf50))
|
|
20
|
+
|
|
2
21
|
## [1.0.0-alpha.11](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.10...v1.0.0-alpha.11) (2023-12-11)
|
|
3
22
|
|
|
4
23
|
## [1.0.0-alpha.10](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2023-12-08)
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.13",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
"react-focus-lock": "2.9.2",
|
|
18
18
|
"react-i18next": "^13.2.0",
|
|
19
19
|
"yup": "0.32.11",
|
|
20
|
-
"@dynamic-labs/ethereum": "1.0.0-alpha.
|
|
21
|
-
"@dynamic-labs/logger": "1.0.0-alpha.
|
|
22
|
-
"@dynamic-labs/multi-wallet": "1.0.0-alpha.
|
|
23
|
-
"@dynamic-labs/rpc-providers": "1.0.0-alpha.
|
|
24
|
-
"@dynamic-labs/types": "1.0.0-alpha.
|
|
25
|
-
"@dynamic-labs/utils": "1.0.0-alpha.
|
|
26
|
-
"@dynamic-labs/viem-utils": "1.0.0-alpha.
|
|
27
|
-
"@dynamic-labs/wallet-book": "1.0.0-alpha.
|
|
28
|
-
"@dynamic-labs/wallet-connector-core": "1.0.0-alpha.
|
|
20
|
+
"@dynamic-labs/ethereum": "1.0.0-alpha.13",
|
|
21
|
+
"@dynamic-labs/logger": "1.0.0-alpha.13",
|
|
22
|
+
"@dynamic-labs/multi-wallet": "1.0.0-alpha.13",
|
|
23
|
+
"@dynamic-labs/rpc-providers": "1.0.0-alpha.13",
|
|
24
|
+
"@dynamic-labs/types": "1.0.0-alpha.13",
|
|
25
|
+
"@dynamic-labs/utils": "1.0.0-alpha.13",
|
|
26
|
+
"@dynamic-labs/viem-utils": "1.0.0-alpha.13",
|
|
27
|
+
"@dynamic-labs/wallet-book": "1.0.0-alpha.13",
|
|
28
|
+
"@dynamic-labs/wallet-connector-core": "1.0.0-alpha.13",
|
|
29
29
|
"eventemitter3": "5.0.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
package/src/index.cjs
CHANGED
|
@@ -177,6 +177,8 @@ var themesData = require('./lib/context/ThemeContext/themesData.cjs');
|
|
|
177
177
|
var getNetwork = require('./lib/utils/functions/getNetwork/getNetwork.cjs');
|
|
178
178
|
var index$3 = require('./lib/utils/functions/walletFilters/index.cjs');
|
|
179
179
|
var SendBalanceContext = require('./lib/context/SendBalanceContext/SendBalanceContext.cjs');
|
|
180
|
+
require('./lib/context/FundingContext/FundingContext.cjs');
|
|
181
|
+
var useFunding = require('./lib/context/FundingContext/useFunding/useFunding.cjs');
|
|
180
182
|
|
|
181
183
|
|
|
182
184
|
|
|
@@ -336,3 +338,4 @@ exports.RemoveWallets = index$3.RemoveWallets;
|
|
|
336
338
|
exports.SortWallets = index$3.SortWallets;
|
|
337
339
|
exports.UniswapFilter = index$3.UniswapFilter;
|
|
338
340
|
exports.useSendBalance = SendBalanceContext.useSendBalance;
|
|
341
|
+
exports.useFunding = useFunding.useFunding;
|
package/src/index.d.ts
CHANGED
|
@@ -31,3 +31,4 @@ export type { UpdateUserFieldsArg } from './lib/utils/hooks/';
|
|
|
31
31
|
export { type DynamicJwt, DynamicJwtFromJSON } from '@dynamic-labs/sdk-api';
|
|
32
32
|
export { useSendBalance } from './lib/context/SendBalanceContext';
|
|
33
33
|
export type { LocaleResource } from './lib/locale';
|
|
34
|
+
export { useFunding } from './lib/context/FundingContext';
|
package/src/index.js
CHANGED
|
@@ -173,3 +173,5 @@ export { getDefaultColor, getThemeConfig, themesData } from './lib/context/Theme
|
|
|
173
173
|
export { getNetwork } from './lib/utils/functions/getNetwork/getNetwork.js';
|
|
174
174
|
export { FilterAndSortWallets, FilterBridgeChainsName, FilterWallets, RemoveWallets, SortWallets, UniswapFilter } from './lib/utils/functions/walletFilters/index.js';
|
|
175
175
|
export { useSendBalance } from './lib/context/SendBalanceContext/SendBalanceContext.js';
|
|
176
|
+
import './lib/context/FundingContext/FundingContext.js';
|
|
177
|
+
export { useFunding } from './lib/context/FundingContext/useFunding/useFunding.js';
|
|
@@ -16,7 +16,7 @@ const SecureTurnkeyWalletCard = ({ className }) => {
|
|
|
16
16
|
const { initPasskeyRecoveryProcess } = usePasskeyRecovery.usePasskeyRecovery();
|
|
17
17
|
if (!isTurnkeyWalletWithoutAuthenticator)
|
|
18
18
|
return null;
|
|
19
|
-
return (jsxRuntime.jsxs("div", { className: classNames.classNames('secure-turnkey-wallet-card', className), children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', className: 'secure-turnkey-wallet-card__text', children: t('dyn_secure_pregenerated_wallet.description') }), jsxRuntime.jsx(Button.Button, { onClick: initPasskeyRecoveryProcess, buttonVariant: 'brand-primary', color: 'primary', typographyProps: {
|
|
19
|
+
return (jsxRuntime.jsxs("div", { className: classNames.classNames('secure-turnkey-wallet-card', className), children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', className: 'secure-turnkey-wallet-card__text', color: 'primary', children: t('dyn_secure_pregenerated_wallet.description') }), jsxRuntime.jsx(Button.Button, { onClick: initPasskeyRecoveryProcess, buttonVariant: 'brand-primary', color: 'primary', typographyProps: {
|
|
20
20
|
color: 'inherit',
|
|
21
21
|
}, showInternalLoading: false, children: t('dyn_secure_pregenerated_wallet.secure_button') })] }));
|
|
22
22
|
};
|
|
@@ -12,7 +12,7 @@ const SecureTurnkeyWalletCard = ({ className }) => {
|
|
|
12
12
|
const { initPasskeyRecoveryProcess } = usePasskeyRecovery();
|
|
13
13
|
if (!isTurnkeyWalletWithoutAuthenticator)
|
|
14
14
|
return null;
|
|
15
|
-
return (jsxs("div", { className: classNames('secure-turnkey-wallet-card', className), children: [jsx(Typography, { variant: 'body_small', weight: 'regular', className: 'secure-turnkey-wallet-card__text', children: t('dyn_secure_pregenerated_wallet.description') }), jsx(Button, { onClick: initPasskeyRecoveryProcess, buttonVariant: 'brand-primary', color: 'primary', typographyProps: {
|
|
15
|
+
return (jsxs("div", { className: classNames('secure-turnkey-wallet-card', className), children: [jsx(Typography, { variant: 'body_small', weight: 'regular', className: 'secure-turnkey-wallet-card__text', color: 'primary', children: t('dyn_secure_pregenerated_wallet.description') }), jsx(Button, { onClick: initPasskeyRecoveryProcess, buttonVariant: 'brand-primary', color: 'primary', typographyProps: {
|
|
16
16
|
color: 'inherit',
|
|
17
17
|
}, showInternalLoading: false, children: t('dyn_secure_pregenerated_wallet.secure_button') })] }));
|
|
18
18
|
};
|
|
@@ -30,6 +30,32 @@ const FundingContextProvider = ({ children, }) => {
|
|
|
30
30
|
const [fundingUrl, setFundingUrl] = React.useState('');
|
|
31
31
|
const { environmentId, network, primaryWallet, projectSettings } = useInternalDynamicContext.useInternalDynamicContext();
|
|
32
32
|
const fundingEnabled = (_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) === null || _a === void 0 ? void 0 : _a.some((p) => isOnrampProvider.isOnrampProvider(p) && Boolean(p.enabledAt))) !== null && _b !== void 0 ? _b : false;
|
|
33
|
+
const updateSupportsFunding = React.useCallback(({ address, token } = {}) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
var _c;
|
|
35
|
+
if (!fundingEnabled)
|
|
36
|
+
return;
|
|
37
|
+
if (!primaryWallet)
|
|
38
|
+
return;
|
|
39
|
+
const chainName = (_c = walletConnectorCore.getChainInfo(primaryWallet.chain)) === null || _c === void 0 ? void 0 : _c.name;
|
|
40
|
+
if (!chainName)
|
|
41
|
+
return;
|
|
42
|
+
try {
|
|
43
|
+
const [{ url }] = yield api.getOnrampProviders({
|
|
44
|
+
chain: chainName,
|
|
45
|
+
environmentId,
|
|
46
|
+
networkId: network ? network.toString() : undefined,
|
|
47
|
+
token,
|
|
48
|
+
walletAddress: address ? address : primaryWallet.address,
|
|
49
|
+
});
|
|
50
|
+
if (!url)
|
|
51
|
+
throw new Error('No onramp url found');
|
|
52
|
+
setFundingUrl(url);
|
|
53
|
+
setSupportsFunding(true);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
setSupportsFunding(false);
|
|
57
|
+
}
|
|
58
|
+
}), [environmentId, fundingEnabled, network, primaryWallet]);
|
|
33
59
|
const value = React.useMemo(() => ({
|
|
34
60
|
fundingEnabled,
|
|
35
61
|
fundingRef,
|
|
@@ -37,35 +63,17 @@ const FundingContextProvider = ({ children, }) => {
|
|
|
37
63
|
setShowFunding,
|
|
38
64
|
showFunding,
|
|
39
65
|
supportsFunding,
|
|
40
|
-
|
|
66
|
+
updateSupportsFunding,
|
|
67
|
+
}), [
|
|
68
|
+
fundingEnabled,
|
|
69
|
+
fundingUrl,
|
|
70
|
+
showFunding,
|
|
71
|
+
supportsFunding,
|
|
72
|
+
updateSupportsFunding,
|
|
73
|
+
]);
|
|
41
74
|
React.useEffect(() => {
|
|
42
|
-
const updateSupportsFunding = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
var _a;
|
|
44
|
-
if (!fundingEnabled)
|
|
45
|
-
return;
|
|
46
|
-
if (!primaryWallet)
|
|
47
|
-
return;
|
|
48
|
-
const chainName = (_a = walletConnectorCore.getChainInfo(primaryWallet.chain)) === null || _a === void 0 ? void 0 : _a.name;
|
|
49
|
-
if (!chainName)
|
|
50
|
-
return;
|
|
51
|
-
try {
|
|
52
|
-
const [{ url }] = yield api.getOnrampProviders({
|
|
53
|
-
chain: chainName,
|
|
54
|
-
environmentId,
|
|
55
|
-
networkId: network ? network.toString() : undefined,
|
|
56
|
-
walletAddress: primaryWallet.address,
|
|
57
|
-
});
|
|
58
|
-
if (!url)
|
|
59
|
-
throw new Error('No onramp url found');
|
|
60
|
-
setFundingUrl(url);
|
|
61
|
-
setSupportsFunding(true);
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
setSupportsFunding(false);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
75
|
updateSupportsFunding();
|
|
68
|
-
}, [
|
|
76
|
+
}, [environmentId, fundingEnabled, network, primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address]);
|
|
69
77
|
return (jsxRuntime.jsx(FundingContext.Provider, { value: value, children: children }));
|
|
70
78
|
};
|
|
71
79
|
const useFundingContext = () => {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { ReactNode, SetStateAction, Dispatch } from 'react';
|
|
2
2
|
export type FundingContextProps = {
|
|
3
|
+
updateSupportsFunding: (props?: {
|
|
4
|
+
address?: string;
|
|
5
|
+
token?: string;
|
|
6
|
+
}) => Promise<void>;
|
|
3
7
|
fundingEnabled: boolean;
|
|
4
8
|
fundingRef: React.RefObject<HTMLDivElement>;
|
|
5
9
|
fundingUrl: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { createContext, useContext, useRef, useState, useMemo, useEffect } from 'react';
|
|
3
|
+
import { createContext, useContext, useRef, useState, useCallback, useMemo, useEffect } from 'react';
|
|
4
4
|
import { getChainInfo } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { getOnrampProviders } from '../../data/api.js';
|
|
6
6
|
import { useInternalDynamicContext } from '../DynamicContext/useInternalDynamicContext.js';
|
|
@@ -26,6 +26,32 @@ const FundingContextProvider = ({ children, }) => {
|
|
|
26
26
|
const [fundingUrl, setFundingUrl] = useState('');
|
|
27
27
|
const { environmentId, network, primaryWallet, projectSettings } = useInternalDynamicContext();
|
|
28
28
|
const fundingEnabled = (_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) === null || _a === void 0 ? void 0 : _a.some((p) => isOnrampProvider(p) && Boolean(p.enabledAt))) !== null && _b !== void 0 ? _b : false;
|
|
29
|
+
const updateSupportsFunding = useCallback(({ address, token } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
var _c;
|
|
31
|
+
if (!fundingEnabled)
|
|
32
|
+
return;
|
|
33
|
+
if (!primaryWallet)
|
|
34
|
+
return;
|
|
35
|
+
const chainName = (_c = getChainInfo(primaryWallet.chain)) === null || _c === void 0 ? void 0 : _c.name;
|
|
36
|
+
if (!chainName)
|
|
37
|
+
return;
|
|
38
|
+
try {
|
|
39
|
+
const [{ url }] = yield getOnrampProviders({
|
|
40
|
+
chain: chainName,
|
|
41
|
+
environmentId,
|
|
42
|
+
networkId: network ? network.toString() : undefined,
|
|
43
|
+
token,
|
|
44
|
+
walletAddress: address ? address : primaryWallet.address,
|
|
45
|
+
});
|
|
46
|
+
if (!url)
|
|
47
|
+
throw new Error('No onramp url found');
|
|
48
|
+
setFundingUrl(url);
|
|
49
|
+
setSupportsFunding(true);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
setSupportsFunding(false);
|
|
53
|
+
}
|
|
54
|
+
}), [environmentId, fundingEnabled, network, primaryWallet]);
|
|
29
55
|
const value = useMemo(() => ({
|
|
30
56
|
fundingEnabled,
|
|
31
57
|
fundingRef,
|
|
@@ -33,35 +59,17 @@ const FundingContextProvider = ({ children, }) => {
|
|
|
33
59
|
setShowFunding,
|
|
34
60
|
showFunding,
|
|
35
61
|
supportsFunding,
|
|
36
|
-
|
|
62
|
+
updateSupportsFunding,
|
|
63
|
+
}), [
|
|
64
|
+
fundingEnabled,
|
|
65
|
+
fundingUrl,
|
|
66
|
+
showFunding,
|
|
67
|
+
supportsFunding,
|
|
68
|
+
updateSupportsFunding,
|
|
69
|
+
]);
|
|
37
70
|
useEffect(() => {
|
|
38
|
-
const updateSupportsFunding = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
var _a;
|
|
40
|
-
if (!fundingEnabled)
|
|
41
|
-
return;
|
|
42
|
-
if (!primaryWallet)
|
|
43
|
-
return;
|
|
44
|
-
const chainName = (_a = getChainInfo(primaryWallet.chain)) === null || _a === void 0 ? void 0 : _a.name;
|
|
45
|
-
if (!chainName)
|
|
46
|
-
return;
|
|
47
|
-
try {
|
|
48
|
-
const [{ url }] = yield getOnrampProviders({
|
|
49
|
-
chain: chainName,
|
|
50
|
-
environmentId,
|
|
51
|
-
networkId: network ? network.toString() : undefined,
|
|
52
|
-
walletAddress: primaryWallet.address,
|
|
53
|
-
});
|
|
54
|
-
if (!url)
|
|
55
|
-
throw new Error('No onramp url found');
|
|
56
|
-
setFundingUrl(url);
|
|
57
|
-
setSupportsFunding(true);
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
setSupportsFunding(false);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
71
|
updateSupportsFunding();
|
|
64
|
-
}, [
|
|
72
|
+
}, [environmentId, fundingEnabled, network, primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address]);
|
|
65
73
|
return (jsx(FundingContext.Provider, { value: value, children: children }));
|
|
66
74
|
};
|
|
67
75
|
const useFundingContext = () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useFunding } from './useFunding';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
var FundingContext = require('../FundingContext.cjs');
|
|
9
|
+
|
|
10
|
+
const useFunding = () => {
|
|
11
|
+
const promiseRef = React.useRef(null);
|
|
12
|
+
const { fundingEnabled, setShowFunding, showFunding, updateSupportsFunding } = FundingContext.useFundingContext();
|
|
13
|
+
const openFunding = ({ address, token } = {}) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
if (!fundingEnabled) {
|
|
15
|
+
throw new Error('Funding is not enabled');
|
|
16
|
+
}
|
|
17
|
+
if (promiseRef.current) {
|
|
18
|
+
return promiseRef.current.promise;
|
|
19
|
+
}
|
|
20
|
+
if (address || token) {
|
|
21
|
+
yield updateSupportsFunding({ address, token });
|
|
22
|
+
}
|
|
23
|
+
promiseRef.current = new utils.DeferredPromise();
|
|
24
|
+
setShowFunding(true);
|
|
25
|
+
return promiseRef.current.promise;
|
|
26
|
+
});
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
if (!showFunding && promiseRef.current) {
|
|
29
|
+
promiseRef.current.resolve();
|
|
30
|
+
promiseRef.current = null;
|
|
31
|
+
}
|
|
32
|
+
}, [showFunding]);
|
|
33
|
+
return {
|
|
34
|
+
enabled: fundingEnabled,
|
|
35
|
+
openFunding,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.useFunding = useFunding;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { useRef, useEffect } from 'react';
|
|
3
|
+
import { DeferredPromise } from '@dynamic-labs/utils';
|
|
4
|
+
import { useFundingContext } from '../FundingContext.js';
|
|
5
|
+
|
|
6
|
+
const useFunding = () => {
|
|
7
|
+
const promiseRef = useRef(null);
|
|
8
|
+
const { fundingEnabled, setShowFunding, showFunding, updateSupportsFunding } = useFundingContext();
|
|
9
|
+
const openFunding = ({ address, token } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
10
|
+
if (!fundingEnabled) {
|
|
11
|
+
throw new Error('Funding is not enabled');
|
|
12
|
+
}
|
|
13
|
+
if (promiseRef.current) {
|
|
14
|
+
return promiseRef.current.promise;
|
|
15
|
+
}
|
|
16
|
+
if (address || token) {
|
|
17
|
+
yield updateSupportsFunding({ address, token });
|
|
18
|
+
}
|
|
19
|
+
promiseRef.current = new DeferredPromise();
|
|
20
|
+
setShowFunding(true);
|
|
21
|
+
return promiseRef.current.promise;
|
|
22
|
+
});
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!showFunding && promiseRef.current) {
|
|
25
|
+
promiseRef.current.resolve();
|
|
26
|
+
promiseRef.current = null;
|
|
27
|
+
}
|
|
28
|
+
}, [showFunding]);
|
|
29
|
+
return {
|
|
30
|
+
enabled: fundingEnabled,
|
|
31
|
+
openFunding,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { useFunding };
|
|
@@ -35,11 +35,6 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, walletConn
|
|
|
35
35
|
walletConnectorOptions,
|
|
36
36
|
});
|
|
37
37
|
}, [authToken, primaryWalletId, walletConnectorOptions]);
|
|
38
|
-
const { setUserWallets } = UserWalletsContext.useInternalUserWallets();
|
|
39
|
-
// Keep userWallets in sync whenever linkedWallets changes
|
|
40
|
-
React.useEffect(() => {
|
|
41
|
-
setUserWallets((userWallets) => updateUserWalletsFromLinkedWallets.updateUserWalletsFromLinkedWallets(userWallets, linkedWallets));
|
|
42
|
-
}, [linkedWallets, setUserWallets]);
|
|
43
38
|
const walletsBasedOnAuthMode = React.useMemo(() => {
|
|
44
39
|
// Before signing the first message we are using connected wallets list
|
|
45
40
|
// This is because we want the first connected wallet to have events applied by useWalletEventListeners
|
|
@@ -71,6 +66,11 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, walletConn
|
|
|
71
66
|
}), [walletsBasedOnAuthMode]);
|
|
72
67
|
const { connectedWalletMap, didConnectedStateLoad } = useWalletsConnectionState.useWalletsConnectionState(walletsBasedOnAuthMode);
|
|
73
68
|
const wallets = React.useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletMap[wallet.id]) }))), [connectedWalletMap, walletsBasedOnAuthMode]);
|
|
69
|
+
const { setUserWallets } = UserWalletsContext.useInternalUserWallets();
|
|
70
|
+
// Keep userWallets in sync whenever linkedWallets changes
|
|
71
|
+
React.useEffect(() => {
|
|
72
|
+
setUserWallets((userWallets) => updateUserWalletsFromLinkedWallets.updateUserWalletsFromLinkedWallets(userWallets, wallets));
|
|
73
|
+
}, [setUserWallets, wallets]);
|
|
74
74
|
const primaryWallet = React.useMemo(() => { var _a; return (_a = wallets.find((wallet) => wallet.id === primaryWalletId)) !== null && _a !== void 0 ? _a : null; }, [primaryWalletId, wallets]);
|
|
75
75
|
const secondaryWallets = React.useMemo(() => canHaveMultipleWalletsConnected
|
|
76
76
|
? wallets.filter((wallet) => wallet.id !== primaryWalletId)
|
|
@@ -31,11 +31,6 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, walletConn
|
|
|
31
31
|
walletConnectorOptions,
|
|
32
32
|
});
|
|
33
33
|
}, [authToken, primaryWalletId, walletConnectorOptions]);
|
|
34
|
-
const { setUserWallets } = useInternalUserWallets();
|
|
35
|
-
// Keep userWallets in sync whenever linkedWallets changes
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
setUserWallets((userWallets) => updateUserWalletsFromLinkedWallets(userWallets, linkedWallets));
|
|
38
|
-
}, [linkedWallets, setUserWallets]);
|
|
39
34
|
const walletsBasedOnAuthMode = useMemo(() => {
|
|
40
35
|
// Before signing the first message we are using connected wallets list
|
|
41
36
|
// This is because we want the first connected wallet to have events applied by useWalletEventListeners
|
|
@@ -67,6 +62,11 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, walletConn
|
|
|
67
62
|
}), [walletsBasedOnAuthMode]);
|
|
68
63
|
const { connectedWalletMap, didConnectedStateLoad } = useWalletsConnectionState(walletsBasedOnAuthMode);
|
|
69
64
|
const wallets = useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletMap[wallet.id]) }))), [connectedWalletMap, walletsBasedOnAuthMode]);
|
|
65
|
+
const { setUserWallets } = useInternalUserWallets();
|
|
66
|
+
// Keep userWallets in sync whenever linkedWallets changes
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
setUserWallets((userWallets) => updateUserWalletsFromLinkedWallets(userWallets, wallets));
|
|
69
|
+
}, [setUserWallets, wallets]);
|
|
70
70
|
const primaryWallet = useMemo(() => { var _a; return (_a = wallets.find((wallet) => wallet.id === primaryWalletId)) !== null && _a !== void 0 ? _a : null; }, [primaryWalletId, wallets]);
|
|
71
71
|
const secondaryWallets = useMemo(() => canHaveMultipleWalletsConnected
|
|
72
72
|
? wallets.filter((wallet) => wallet.id !== primaryWalletId)
|
|
@@ -22,8 +22,6 @@ const updateUserWalletsFromLinkedWallets = (userWallets, authenticatedWallets) =
|
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
24
|
// If already present, just update to match the new state
|
|
25
|
-
// Don't change connected state
|
|
26
|
-
authenticatedWallet.connected = userWalletsCopy[respectiveIndex].connected;
|
|
27
25
|
userWalletsCopy[respectiveIndex] = authenticatedWallet;
|
|
28
26
|
// NOTE: this will actually update the wallet's ID if it changed, which happens when a wallet is signed
|
|
29
27
|
// It initially has a id in the format "connected-wallet-X", and after being signed it changes to a hash
|
|
@@ -18,8 +18,6 @@ const updateUserWalletsFromLinkedWallets = (userWallets, authenticatedWallets) =
|
|
|
18
18
|
continue;
|
|
19
19
|
}
|
|
20
20
|
// If already present, just update to match the new state
|
|
21
|
-
// Don't change connected state
|
|
22
|
-
authenticatedWallet.connected = userWalletsCopy[respectiveIndex].connected;
|
|
23
21
|
userWalletsCopy[respectiveIndex] = authenticatedWallet;
|
|
24
22
|
// NOTE: this will actually update the wallet's ID if it changed, which happens when a wallet is signed
|
|
25
23
|
// It initially has a id in the format "connected-wallet-X", and after being signed it changes to a hash
|