@dynamic-labs/global-wallet-client 4.19.6 → 4.19.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +7 -7
- package/src/lib/client/createClientStore/createClientStore.cjs +1 -0
- package/src/lib/client/createClientStore/createClientStore.d.ts +7 -1
- package/src/lib/client/createClientStore/createClientStore.js +1 -0
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.cjs +11 -5
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.d.ts +3 -1
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.js +11 -5
- package/src/lib/functions/addWebWalletOpenerService/addWebWalletOpenerService.cjs +35 -116
- package/src/lib/functions/addWebWalletOpenerService/addWebWalletOpenerService.js +35 -116
- package/src/lib/functions/addWebWalletOpenerService/constructUrl.cjs +20 -0
- package/src/lib/functions/addWebWalletOpenerService/constructUrl.d.ts +10 -0
- package/src/lib/functions/addWebWalletOpenerService/constructUrl.js +16 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/iframeWalletOpener.cjs +84 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/iframeWalletOpener.d.ts +15 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/iframeWalletOpener.js +80 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/index.d.ts +2 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/popupWalletOpener.cjs +103 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/popupWalletOpener.d.ts +18 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/popupWalletOpener.js +99 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/utils/decodeResponse.cjs +17 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/utils/decodeResponse.d.ts +2 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/utils/decodeResponse.js +13 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/utils/handlePromiseResponse.cjs +33 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/utils/handlePromiseResponse.d.ts +10 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/utils/handlePromiseResponse.js +29 -0
- package/src/lib/functions/addWebWalletOpenerService/methods/utils/index.d.ts +2 -0
- package/src/lib/functions/connect/connect.cjs +2 -1
- package/src/lib/functions/connect/connect.js +2 -1
- package/src/lib/functions/createWalletOpener/createWalletOpener.d.ts +3 -1
- package/src/lib/functions/sendTransaction/sendTransaction.cjs +1 -0
- package/src/lib/functions/sendTransaction/sendTransaction.js +1 -0
- package/src/lib/functions/setInitialConnectionState/setInitialConnectionState.cjs +3 -2
- package/src/lib/functions/setInitialConnectionState/setInitialConnectionState.d.ts +1 -1
- package/src/lib/functions/setInitialConnectionState/setInitialConnectionState.js +3 -2
- package/src/lib/functions/waitForResponse/index.d.ts +1 -0
- package/src/lib/functions/{waitForPopupResponse/waitForPopupResponse.cjs → waitForResponse/waitForResponse.cjs} +3 -3
- package/src/lib/functions/{waitForPopupResponse/waitForPopupResponse.d.ts → waitForResponse/waitForResponse.d.ts} +3 -3
- package/src/lib/functions/{waitForPopupResponse/waitForPopupResponse.js → waitForResponse/waitForResponse.js} +3 -3
- package/src/lib/functions/waitForPopupResponse/index.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.19.7](https://github.com/dynamic-labs/dynamic-auth/compare/v4.19.6...v4.19.7) (2025-06-06)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add util to find waas wallets ([#8871](https://github.com/dynamic-labs/dynamic-auth/issues/8871)) ([2d7114e](https://github.com/dynamic-labs/dynamic-auth/commit/2d7114e51f5badf1d04600597f1fd9433fabf3d0))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* make sure smart account is deployed before creating sessions ([#8894](https://github.com/dynamic-labs/dynamic-auth/issues/8894)) ([5ba3d23](https://github.com/dynamic-labs/dynamic-auth/commit/5ba3d23bb8ef7c7438809128c8ef74c390ba1d48))
|
|
13
|
+
* only deploy zksync smart account if not deployed ([#8840](https://github.com/dynamic-labs/dynamic-auth/issues/8840)) ([66a306a](https://github.com/dynamic-labs/dynamic-auth/commit/66a306aaee25c58f685fa050a5d6aea79b196fce))
|
|
14
|
+
* primary wallet loading time when using React 19 ([#8896](https://github.com/dynamic-labs/dynamic-auth/issues/8896)) ([f5690f3](https://github.com/dynamic-labs/dynamic-auth/commit/f5690f31012e8fc6a5650423d4ece6c04f7c1811))
|
|
15
|
+
|
|
2
16
|
### [4.19.6](https://github.com/dynamic-labs/dynamic-auth/compare/v4.19.5...v4.19.6) (2025-06-04)
|
|
3
17
|
|
|
4
18
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/global-wallet-client",
|
|
3
|
-
"version": "4.19.
|
|
3
|
+
"version": "4.19.7",
|
|
4
4
|
"description": "Core package for building Dynamic's Global Wallet",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
},
|
|
56
56
|
"homepage": "https://www.dynamic.xyz/",
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@dynamic-labs/assert-package-version": "4.19.
|
|
59
|
-
"@dynamic-labs/logger": "4.19.
|
|
60
|
-
"@dynamic-labs/message-transport": "4.19.
|
|
61
|
-
"@dynamic-labs/store": "4.19.
|
|
62
|
-
"@dynamic-labs/types": "4.19.
|
|
63
|
-
"@dynamic-labs/utils": "4.19.
|
|
58
|
+
"@dynamic-labs/assert-package-version": "4.19.7",
|
|
59
|
+
"@dynamic-labs/logger": "4.19.7",
|
|
60
|
+
"@dynamic-labs/message-transport": "4.19.7",
|
|
61
|
+
"@dynamic-labs/store": "4.19.7",
|
|
62
|
+
"@dynamic-labs/types": "4.19.7",
|
|
63
|
+
"@dynamic-labs/utils": "4.19.7",
|
|
64
64
|
"eventemitter3": "5.0.1"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StoreApi } from '@dynamic-labs/store';
|
|
2
|
-
import { BaseWallet, GlobalWalletConnection } from '@dynamic-labs/types';
|
|
2
|
+
import { type BaseWallet, type GlobalWalletConnection, type Provider } from '@dynamic-labs/types';
|
|
3
3
|
export type ClientStore = StoreApi<ClientStoreState>;
|
|
4
4
|
type CreateClientStoreProps = {
|
|
5
5
|
storage?: Storage;
|
|
@@ -31,6 +31,12 @@ export type ClientStoreState = {
|
|
|
31
31
|
solana: {
|
|
32
32
|
currentNetwork: string;
|
|
33
33
|
} | null;
|
|
34
|
+
/**
|
|
35
|
+
* providers settings
|
|
36
|
+
*/
|
|
37
|
+
settings: {
|
|
38
|
+
zeroDevSettings?: Partial<Provider>;
|
|
39
|
+
};
|
|
34
40
|
};
|
|
35
41
|
export declare const createClientStore: ({ environmentId, storage, }: CreateClientStoreProps) => ClientStore;
|
|
36
42
|
export {};
|
|
@@ -24,7 +24,7 @@ var getSupportedEthereumNetworks = require('../../../functions/getSupportedEther
|
|
|
24
24
|
var switchEthereumNetwork = require('../../../functions/switchEthereumNetwork/switchEthereumNetwork.cjs');
|
|
25
25
|
var getActiveConnection = require('../../../functions/getActiveConnection/getActiveConnection.cjs');
|
|
26
26
|
|
|
27
|
-
const createEIP1193Provider = (client) => {
|
|
27
|
+
const createEIP1193Provider = (client, { sessionId } = {}) => {
|
|
28
28
|
const eventEmitter = new eventemitter3.EventEmitter();
|
|
29
29
|
onEvent.onEvent(client, 'connect', () => {
|
|
30
30
|
const currentNetwork = getCurrentEthereumNetworkId.getCurrentEthereumNetworkId(client);
|
|
@@ -46,17 +46,22 @@ const createEIP1193Provider = (client) => {
|
|
|
46
46
|
eth_accounts: () => handleEthAccounts(client),
|
|
47
47
|
eth_chainId: () => handleEthChainId(client),
|
|
48
48
|
eth_requestAccounts: () => handleEthRequestAccounts(client),
|
|
49
|
-
eth_sendTransaction: () =>
|
|
49
|
+
eth_sendTransaction: () => handleMethodInGlobalWallet({
|
|
50
50
|
client,
|
|
51
51
|
method: 'eth_sendTransaction',
|
|
52
52
|
params,
|
|
53
|
+
useIframe: sessionId ? true : false,
|
|
53
54
|
}),
|
|
54
|
-
eth_signTypedData_v4: () =>
|
|
55
|
+
eth_signTypedData_v4: () => handleMethodInGlobalWallet({
|
|
55
56
|
client,
|
|
56
57
|
method: 'eth_signTypedData_v4',
|
|
57
58
|
params,
|
|
58
59
|
}),
|
|
59
|
-
personal_sign: () =>
|
|
60
|
+
personal_sign: () => handleMethodInGlobalWallet({
|
|
61
|
+
client,
|
|
62
|
+
method: 'personal_sign',
|
|
63
|
+
params,
|
|
64
|
+
}),
|
|
60
65
|
wallet_requestPermissions: () => handleEthRequestAccounts(client),
|
|
61
66
|
wallet_revokePermissions: () => handleWalletRevokePermissions(client),
|
|
62
67
|
wallet_switchEthereumChain: () => handleWalletSwitchEthereumChain(client, eventEmitter, params),
|
|
@@ -147,7 +152,7 @@ const handleWalletSwitchEthereumChain = (client, eventEmitter, params) => {
|
|
|
147
152
|
eventEmitter.emit('chainChanged', chainId);
|
|
148
153
|
return null;
|
|
149
154
|
};
|
|
150
|
-
const
|
|
155
|
+
const handleMethodInGlobalWallet = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ client, method, params, useIframe, }) {
|
|
151
156
|
const currentEthereumNetworkId = getCurrentEthereumNetworkId.getCurrentEthereumNetworkId(client);
|
|
152
157
|
if (!currentEthereumNetworkId) {
|
|
153
158
|
throw new Error('No network id found');
|
|
@@ -161,6 +166,7 @@ const handleMethodInPopup = (_a) => _tslib.__awaiter(void 0, [_a], void 0, funct
|
|
|
161
166
|
},
|
|
162
167
|
connection: getActiveConnection.getActiveConnection(client),
|
|
163
168
|
name: 'eth-request',
|
|
169
|
+
useIframe,
|
|
164
170
|
})
|
|
165
171
|
.catch(mapErrorToStandard);
|
|
166
172
|
return data;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { EIP1193Provider } from 'viem';
|
|
2
2
|
import { GlobalWalletClient } from '../../../client';
|
|
3
|
-
export declare const createEIP1193Provider: (client: GlobalWalletClient
|
|
3
|
+
export declare const createEIP1193Provider: (client: GlobalWalletClient, { sessionId }?: {
|
|
4
|
+
sessionId?: string;
|
|
5
|
+
}) => EIP1193Provider;
|
|
@@ -20,7 +20,7 @@ import { getSupportedEthereumNetworks } from '../../../functions/getSupportedEth
|
|
|
20
20
|
import { switchEthereumNetwork } from '../../../functions/switchEthereumNetwork/switchEthereumNetwork.js';
|
|
21
21
|
import { getActiveConnection } from '../../../functions/getActiveConnection/getActiveConnection.js';
|
|
22
22
|
|
|
23
|
-
const createEIP1193Provider = (client) => {
|
|
23
|
+
const createEIP1193Provider = (client, { sessionId } = {}) => {
|
|
24
24
|
const eventEmitter = new EventEmitter();
|
|
25
25
|
onEvent(client, 'connect', () => {
|
|
26
26
|
const currentNetwork = getCurrentEthereumNetworkId(client);
|
|
@@ -42,17 +42,22 @@ const createEIP1193Provider = (client) => {
|
|
|
42
42
|
eth_accounts: () => handleEthAccounts(client),
|
|
43
43
|
eth_chainId: () => handleEthChainId(client),
|
|
44
44
|
eth_requestAccounts: () => handleEthRequestAccounts(client),
|
|
45
|
-
eth_sendTransaction: () =>
|
|
45
|
+
eth_sendTransaction: () => handleMethodInGlobalWallet({
|
|
46
46
|
client,
|
|
47
47
|
method: 'eth_sendTransaction',
|
|
48
48
|
params,
|
|
49
|
+
useIframe: sessionId ? true : false,
|
|
49
50
|
}),
|
|
50
|
-
eth_signTypedData_v4: () =>
|
|
51
|
+
eth_signTypedData_v4: () => handleMethodInGlobalWallet({
|
|
51
52
|
client,
|
|
52
53
|
method: 'eth_signTypedData_v4',
|
|
53
54
|
params,
|
|
54
55
|
}),
|
|
55
|
-
personal_sign: () =>
|
|
56
|
+
personal_sign: () => handleMethodInGlobalWallet({
|
|
57
|
+
client,
|
|
58
|
+
method: 'personal_sign',
|
|
59
|
+
params,
|
|
60
|
+
}),
|
|
56
61
|
wallet_requestPermissions: () => handleEthRequestAccounts(client),
|
|
57
62
|
wallet_revokePermissions: () => handleWalletRevokePermissions(client),
|
|
58
63
|
wallet_switchEthereumChain: () => handleWalletSwitchEthereumChain(client, eventEmitter, params),
|
|
@@ -143,7 +148,7 @@ const handleWalletSwitchEthereumChain = (client, eventEmitter, params) => {
|
|
|
143
148
|
eventEmitter.emit('chainChanged', chainId);
|
|
144
149
|
return null;
|
|
145
150
|
};
|
|
146
|
-
const
|
|
151
|
+
const handleMethodInGlobalWallet = (_a) => __awaiter(void 0, [_a], void 0, function* ({ client, method, params, useIframe, }) {
|
|
147
152
|
const currentEthereumNetworkId = getCurrentEthereumNetworkId(client);
|
|
148
153
|
if (!currentEthereumNetworkId) {
|
|
149
154
|
throw new Error('No network id found');
|
|
@@ -157,6 +162,7 @@ const handleMethodInPopup = (_a) => __awaiter(void 0, [_a], void 0, function* ({
|
|
|
157
162
|
},
|
|
158
163
|
connection: getActiveConnection(client),
|
|
159
164
|
name: 'eth-request',
|
|
165
|
+
useIframe,
|
|
160
166
|
})
|
|
161
167
|
.catch(mapErrorToStandard);
|
|
162
168
|
return data;
|
|
@@ -4,21 +4,14 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
|
-
var utils = require('@dynamic-labs/utils');
|
|
8
7
|
require('eventemitter3');
|
|
9
8
|
require('@dynamic-labs/logger');
|
|
10
9
|
require('@dynamic-labs/store');
|
|
11
10
|
require('../../errors/DisconnectError.cjs');
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var getCenteredPopupFeatures = require('../getCenteredPopupFeatures/getCenteredPopupFeatures.cjs');
|
|
15
|
-
var mergeAndEncryptParams = require('../mergeAndEncryptParams/mergeAndEncryptParams.cjs');
|
|
16
|
-
var waitForPopupResponse = require('../waitForPopupResponse/waitForPopupResponse.cjs');
|
|
17
|
-
var onPopupClose = require('../onPopupClose/onPopupClose.cjs');
|
|
18
|
-
var PopupClosedError = require('../../errors/PopupClosedError.cjs');
|
|
11
|
+
var iframeWalletOpener = require('./methods/iframeWalletOpener.cjs');
|
|
12
|
+
var popupWalletOpener = require('./methods/popupWalletOpener.cjs');
|
|
19
13
|
var getCore = require('../../client/getCore/getCore.cjs');
|
|
20
14
|
|
|
21
|
-
const popupActionTimeout = 1000;
|
|
22
15
|
/**
|
|
23
16
|
* Adds a web wallet opener service to the client.
|
|
24
17
|
* This service is used to open a popup to connect a wallet
|
|
@@ -27,120 +20,46 @@ const popupActionTimeout = 1000;
|
|
|
27
20
|
const addWebWalletOpenerService = (client, globalWindow = global.window) => {
|
|
28
21
|
var _a, _b, _c;
|
|
29
22
|
const { developmentOptions, popupInfo, logger, registry, environmentId, eventEmitter, } = getCore.getCore(client);
|
|
23
|
+
const popupState = {
|
|
24
|
+
didOpenPopup: false,
|
|
25
|
+
lastActionId: null,
|
|
26
|
+
popup: null,
|
|
27
|
+
};
|
|
28
|
+
const iframeState = {
|
|
29
|
+
iframe: null,
|
|
30
|
+
lastActionId: null,
|
|
31
|
+
};
|
|
30
32
|
const popupHeight = (_a = popupInfo.height) !== null && _a !== void 0 ? _a : 640;
|
|
31
33
|
const popupWidth = (_b = popupInfo.width) !== null && _b !== void 0 ? _b : 420;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
popup = null;
|
|
43
|
-
didOpenPopup = false;
|
|
44
|
-
lastActionId = null;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Close popup on page unload
|
|
48
|
-
*/
|
|
49
|
-
if (typeof globalWindow !== 'undefined') {
|
|
50
|
-
globalWindow.addEventListener('beforeunload', closePopup);
|
|
51
|
-
}
|
|
52
|
-
const popupOpener = (_d) => _tslib.__awaiter(void 0, [_d], void 0, function* ({ args, name, connection, }) {
|
|
53
|
-
logger.logVerboseTroubleshootingMessage('new popup action', {
|
|
54
|
-
args,
|
|
55
|
-
name,
|
|
34
|
+
const postfixUrlWithVersion = (_c = developmentOptions.postfixPopupUrlWithVersion) !== null && _c !== void 0 ? _c : true;
|
|
35
|
+
const walletOpener = (props) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const iframeWalletOpener$1 = iframeWalletOpener.createIframeWalletOpener({
|
|
37
|
+
environmentId,
|
|
38
|
+
eventEmitter,
|
|
39
|
+
globalWindow,
|
|
40
|
+
iframeState,
|
|
41
|
+
logger,
|
|
42
|
+
popupInfo,
|
|
43
|
+
postfixUrlWithVersion,
|
|
56
44
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (popup === null) {
|
|
68
|
-
const features = getCenteredPopupFeatures.getCenteredPopupFeatures({
|
|
69
|
-
height: popupHeight,
|
|
70
|
-
width: popupWidth,
|
|
71
|
-
});
|
|
72
|
-
// Open popup
|
|
73
|
-
popup = globalWindow.open('', '_blank', features);
|
|
74
|
-
}
|
|
75
|
-
// Encrypt params if active connection is present
|
|
76
|
-
if (args) {
|
|
77
|
-
yield mergeAndEncryptParams.mergeAndEncryptParams(popupFinalUrl, args, connection);
|
|
78
|
-
}
|
|
79
|
-
if (popup === null) {
|
|
80
|
-
throw new Error('Failed to open popup');
|
|
81
|
-
}
|
|
82
|
-
waitForPopupResponse.waitForPopupResponse({
|
|
83
|
-
decode: (data) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
-
if (connection && utils.isEncryptedMessage(data)) {
|
|
85
|
-
const decryptedData = yield utils.decryptMessage(connection.sharedSecret, data.encryptedMessage, data.iv);
|
|
86
|
-
return JSON.parse(decryptedData);
|
|
87
|
-
}
|
|
88
|
-
return data;
|
|
89
|
-
}),
|
|
90
|
-
onError: (error) => resultDeferredPromise.reject(error),
|
|
91
|
-
onResponse: (response) => resultDeferredPromise.resolve(response.data),
|
|
92
|
-
popupUrl: popupFinalUrl.toString(),
|
|
93
|
-
});
|
|
94
|
-
onPopupClose.onPopupClose(popup, () => {
|
|
95
|
-
resultDeferredPromise.reject(new PopupClosedError.PopupClosedError());
|
|
45
|
+
const popupWalletOpener$1 = popupWalletOpener.createPopupWalletOpener({
|
|
46
|
+
environmentId,
|
|
47
|
+
eventEmitter,
|
|
48
|
+
globalWindow,
|
|
49
|
+
logger,
|
|
50
|
+
popupHeight,
|
|
51
|
+
popupInfo,
|
|
52
|
+
popupState,
|
|
53
|
+
popupWidth,
|
|
54
|
+
postfixUrlWithVersion,
|
|
96
55
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*/
|
|
100
|
-
if (didOpenPopup) {
|
|
101
|
-
popup === null || popup === void 0 ? void 0 : popup.postMessage({
|
|
102
|
-
actionPath: popupFinalUrl.search + popupFinalUrl.hash,
|
|
103
|
-
event: 'new-action',
|
|
104
|
-
}, popupFinalUrl.origin);
|
|
56
|
+
if (props.useIframe) {
|
|
57
|
+
return iframeWalletOpener$1(props);
|
|
105
58
|
}
|
|
106
|
-
|
|
107
|
-
// Load popup
|
|
108
|
-
popup.location = popupFinalUrl.href;
|
|
109
|
-
}
|
|
110
|
-
didOpenPopup = true;
|
|
111
|
-
return resultDeferredPromise.promise
|
|
112
|
-
.then((result) => {
|
|
113
|
-
logger.logVerboseTroubleshootingMessage('popup action result', {
|
|
114
|
-
actionId,
|
|
115
|
-
lastActionId,
|
|
116
|
-
result,
|
|
117
|
-
});
|
|
118
|
-
return result;
|
|
119
|
-
})
|
|
120
|
-
.catch((err) => {
|
|
121
|
-
logger.logVerboseTroubleshootingMessage('popup action error', {
|
|
122
|
-
actionId,
|
|
123
|
-
err,
|
|
124
|
-
lastActionId,
|
|
125
|
-
});
|
|
126
|
-
eventEmitter.emit('error', err);
|
|
127
|
-
closePopup();
|
|
128
|
-
throw err;
|
|
129
|
-
})
|
|
130
|
-
.finally(() => {
|
|
131
|
-
/**
|
|
132
|
-
* Sets a timeout to close the popup.
|
|
133
|
-
* It will only no new actions were fired.
|
|
134
|
-
*/
|
|
135
|
-
setTimeout(() => {
|
|
136
|
-
if (lastActionId === actionId) {
|
|
137
|
-
closePopup();
|
|
138
|
-
}
|
|
139
|
-
}, popupActionTimeout);
|
|
140
|
-
});
|
|
59
|
+
return popupWalletOpener$1(props);
|
|
141
60
|
});
|
|
142
61
|
registry.set('walletOpenerService', {
|
|
143
|
-
openWallet:
|
|
62
|
+
openWallet: walletOpener,
|
|
144
63
|
});
|
|
145
64
|
};
|
|
146
65
|
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
|
-
import { DeferredPromise, isEncryptedMessage, decryptMessage } from '@dynamic-labs/utils';
|
|
4
3
|
import 'eventemitter3';
|
|
5
4
|
import '@dynamic-labs/logger';
|
|
6
5
|
import '@dynamic-labs/store';
|
|
7
6
|
import '../../errors/DisconnectError.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { getCenteredPopupFeatures } from '../getCenteredPopupFeatures/getCenteredPopupFeatures.js';
|
|
11
|
-
import { mergeAndEncryptParams } from '../mergeAndEncryptParams/mergeAndEncryptParams.js';
|
|
12
|
-
import { waitForPopupResponse } from '../waitForPopupResponse/waitForPopupResponse.js';
|
|
13
|
-
import { onPopupClose } from '../onPopupClose/onPopupClose.js';
|
|
14
|
-
import { PopupClosedError } from '../../errors/PopupClosedError.js';
|
|
7
|
+
import { createIframeWalletOpener } from './methods/iframeWalletOpener.js';
|
|
8
|
+
import { createPopupWalletOpener } from './methods/popupWalletOpener.js';
|
|
15
9
|
import { getCore } from '../../client/getCore/getCore.js';
|
|
16
10
|
|
|
17
|
-
const popupActionTimeout = 1000;
|
|
18
11
|
/**
|
|
19
12
|
* Adds a web wallet opener service to the client.
|
|
20
13
|
* This service is used to open a popup to connect a wallet
|
|
@@ -23,120 +16,46 @@ const popupActionTimeout = 1000;
|
|
|
23
16
|
const addWebWalletOpenerService = (client, globalWindow = global.window) => {
|
|
24
17
|
var _a, _b, _c;
|
|
25
18
|
const { developmentOptions, popupInfo, logger, registry, environmentId, eventEmitter, } = getCore(client);
|
|
19
|
+
const popupState = {
|
|
20
|
+
didOpenPopup: false,
|
|
21
|
+
lastActionId: null,
|
|
22
|
+
popup: null,
|
|
23
|
+
};
|
|
24
|
+
const iframeState = {
|
|
25
|
+
iframe: null,
|
|
26
|
+
lastActionId: null,
|
|
27
|
+
};
|
|
26
28
|
const popupHeight = (_a = popupInfo.height) !== null && _a !== void 0 ? _a : 640;
|
|
27
29
|
const popupWidth = (_b = popupInfo.width) !== null && _b !== void 0 ? _b : 420;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
popup = null;
|
|
39
|
-
didOpenPopup = false;
|
|
40
|
-
lastActionId = null;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Close popup on page unload
|
|
44
|
-
*/
|
|
45
|
-
if (typeof globalWindow !== 'undefined') {
|
|
46
|
-
globalWindow.addEventListener('beforeunload', closePopup);
|
|
47
|
-
}
|
|
48
|
-
const popupOpener = (_d) => __awaiter(void 0, [_d], void 0, function* ({ args, name, connection, }) {
|
|
49
|
-
logger.logVerboseTroubleshootingMessage('new popup action', {
|
|
50
|
-
args,
|
|
51
|
-
name,
|
|
30
|
+
const postfixUrlWithVersion = (_c = developmentOptions.postfixPopupUrlWithVersion) !== null && _c !== void 0 ? _c : true;
|
|
31
|
+
const walletOpener = (props) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const iframeWalletOpener = createIframeWalletOpener({
|
|
33
|
+
environmentId,
|
|
34
|
+
eventEmitter,
|
|
35
|
+
globalWindow,
|
|
36
|
+
iframeState,
|
|
37
|
+
logger,
|
|
38
|
+
popupInfo,
|
|
39
|
+
postfixUrlWithVersion,
|
|
52
40
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (popup === null) {
|
|
64
|
-
const features = getCenteredPopupFeatures({
|
|
65
|
-
height: popupHeight,
|
|
66
|
-
width: popupWidth,
|
|
67
|
-
});
|
|
68
|
-
// Open popup
|
|
69
|
-
popup = globalWindow.open('', '_blank', features);
|
|
70
|
-
}
|
|
71
|
-
// Encrypt params if active connection is present
|
|
72
|
-
if (args) {
|
|
73
|
-
yield mergeAndEncryptParams(popupFinalUrl, args, connection);
|
|
74
|
-
}
|
|
75
|
-
if (popup === null) {
|
|
76
|
-
throw new Error('Failed to open popup');
|
|
77
|
-
}
|
|
78
|
-
waitForPopupResponse({
|
|
79
|
-
decode: (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
-
if (connection && isEncryptedMessage(data)) {
|
|
81
|
-
const decryptedData = yield decryptMessage(connection.sharedSecret, data.encryptedMessage, data.iv);
|
|
82
|
-
return JSON.parse(decryptedData);
|
|
83
|
-
}
|
|
84
|
-
return data;
|
|
85
|
-
}),
|
|
86
|
-
onError: (error) => resultDeferredPromise.reject(error),
|
|
87
|
-
onResponse: (response) => resultDeferredPromise.resolve(response.data),
|
|
88
|
-
popupUrl: popupFinalUrl.toString(),
|
|
89
|
-
});
|
|
90
|
-
onPopupClose(popup, () => {
|
|
91
|
-
resultDeferredPromise.reject(new PopupClosedError());
|
|
41
|
+
const popupWalletOpener = createPopupWalletOpener({
|
|
42
|
+
environmentId,
|
|
43
|
+
eventEmitter,
|
|
44
|
+
globalWindow,
|
|
45
|
+
logger,
|
|
46
|
+
popupHeight,
|
|
47
|
+
popupInfo,
|
|
48
|
+
popupState,
|
|
49
|
+
popupWidth,
|
|
50
|
+
postfixUrlWithVersion,
|
|
92
51
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*/
|
|
96
|
-
if (didOpenPopup) {
|
|
97
|
-
popup === null || popup === void 0 ? void 0 : popup.postMessage({
|
|
98
|
-
actionPath: popupFinalUrl.search + popupFinalUrl.hash,
|
|
99
|
-
event: 'new-action',
|
|
100
|
-
}, popupFinalUrl.origin);
|
|
52
|
+
if (props.useIframe) {
|
|
53
|
+
return iframeWalletOpener(props);
|
|
101
54
|
}
|
|
102
|
-
|
|
103
|
-
// Load popup
|
|
104
|
-
popup.location = popupFinalUrl.href;
|
|
105
|
-
}
|
|
106
|
-
didOpenPopup = true;
|
|
107
|
-
return resultDeferredPromise.promise
|
|
108
|
-
.then((result) => {
|
|
109
|
-
logger.logVerboseTroubleshootingMessage('popup action result', {
|
|
110
|
-
actionId,
|
|
111
|
-
lastActionId,
|
|
112
|
-
result,
|
|
113
|
-
});
|
|
114
|
-
return result;
|
|
115
|
-
})
|
|
116
|
-
.catch((err) => {
|
|
117
|
-
logger.logVerboseTroubleshootingMessage('popup action error', {
|
|
118
|
-
actionId,
|
|
119
|
-
err,
|
|
120
|
-
lastActionId,
|
|
121
|
-
});
|
|
122
|
-
eventEmitter.emit('error', err);
|
|
123
|
-
closePopup();
|
|
124
|
-
throw err;
|
|
125
|
-
})
|
|
126
|
-
.finally(() => {
|
|
127
|
-
/**
|
|
128
|
-
* Sets a timeout to close the popup.
|
|
129
|
-
* It will only no new actions were fired.
|
|
130
|
-
*/
|
|
131
|
-
setTimeout(() => {
|
|
132
|
-
if (lastActionId === actionId) {
|
|
133
|
-
closePopup();
|
|
134
|
-
}
|
|
135
|
-
}, popupActionTimeout);
|
|
136
|
-
});
|
|
55
|
+
return popupWalletOpener(props);
|
|
137
56
|
});
|
|
138
57
|
registry.set('walletOpenerService', {
|
|
139
|
-
openWallet:
|
|
58
|
+
openWallet: walletOpener,
|
|
140
59
|
});
|
|
141
60
|
};
|
|
142
61
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var addVersionPostfixToUrl = require('../addVersionPostfixToUrl/addVersionPostfixToUrl.cjs');
|
|
7
|
+
var _package = require('../../../../package.cjs');
|
|
8
|
+
|
|
9
|
+
const buildUrlWithParams = ({ urlInfo, environmentId, name, globalWindow, postfixUrlWithVersion = true, }) => {
|
|
10
|
+
const baseUrl = postfixUrlWithVersion
|
|
11
|
+
? addVersionPostfixToUrl.addVersionPostfixToUrl(_package.version, urlInfo.url)
|
|
12
|
+
: urlInfo.url;
|
|
13
|
+
const finalUrl = new URL(baseUrl);
|
|
14
|
+
finalUrl.hash = `/${name}`;
|
|
15
|
+
finalUrl.searchParams.set('provider_env_id', environmentId);
|
|
16
|
+
finalUrl.searchParams.set('requester_origin', globalWindow.location.origin);
|
|
17
|
+
return finalUrl;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.buildUrlWithParams = buildUrlWithParams;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface BuildUrlWithParamsOptions {
|
|
2
|
+
urlInfo: {
|
|
3
|
+
url: string;
|
|
4
|
+
};
|
|
5
|
+
environmentId: string;
|
|
6
|
+
name: string;
|
|
7
|
+
globalWindow: Window;
|
|
8
|
+
postfixUrlWithVersion?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const buildUrlWithParams: ({ urlInfo, environmentId, name, globalWindow, postfixUrlWithVersion, }: BuildUrlWithParamsOptions) => URL;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { addVersionPostfixToUrl } from '../addVersionPostfixToUrl/addVersionPostfixToUrl.js';
|
|
3
|
+
import { version } from '../../../../package.js';
|
|
4
|
+
|
|
5
|
+
const buildUrlWithParams = ({ urlInfo, environmentId, name, globalWindow, postfixUrlWithVersion = true, }) => {
|
|
6
|
+
const baseUrl = postfixUrlWithVersion
|
|
7
|
+
? addVersionPostfixToUrl(version, urlInfo.url)
|
|
8
|
+
: urlInfo.url;
|
|
9
|
+
const finalUrl = new URL(baseUrl);
|
|
10
|
+
finalUrl.hash = `/${name}`;
|
|
11
|
+
finalUrl.searchParams.set('provider_env_id', environmentId);
|
|
12
|
+
finalUrl.searchParams.set('requester_origin', globalWindow.location.origin);
|
|
13
|
+
return finalUrl;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { buildUrlWithParams };
|