@dynamic-labs/global-wallet-client 4.9.7 → 4.9.9
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 +7 -6
- package/src/core.d.ts +4 -0
- package/src/lib/actions/connectAction/createConnectAction.cjs +3 -1
- package/src/lib/actions/connectAction/createConnectAction.js +4 -2
- package/src/lib/createGlobalWalletClient.cjs +10 -4
- package/src/lib/createGlobalWalletClient.js +10 -4
- package/src/lib/errors/DisconnectError.cjs +19 -0
- package/src/lib/errors/DisconnectError.d.ts +5 -0
- package/src/lib/errors/DisconnectError.js +15 -0
- package/src/lib/errors/PopupClosedError.cjs +12 -0
- package/src/lib/errors/PopupClosedError.d.ts +3 -0
- package/src/lib/errors/PopupClosedError.js +8 -0
- package/src/lib/errors/UnknownError.cjs +12 -0
- package/src/lib/errors/UnknownError.d.ts +3 -0
- package/src/lib/errors/UnknownError.js +8 -0
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.cjs +13 -7
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.js +13 -7
- package/src/lib/functions/createEncryptedMessageEncoder/createEncryptedMessageEncoder.cjs +19 -0
- package/src/lib/functions/createEncryptedMessageEncoder/createEncryptedMessageEncoder.d.ts +3 -0
- package/src/lib/functions/createEncryptedMessageEncoder/createEncryptedMessageEncoder.js +15 -0
- package/src/lib/functions/createEncryptedMessageEncoder/index.d.ts +1 -0
- package/src/lib/functions/createPopupMessageClient/createPopupMessageClient.cjs +74 -0
- package/src/lib/functions/createPopupMessageClient/createPopupMessageClient.d.ts +14 -0
- package/src/lib/functions/createPopupMessageClient/createPopupMessageClient.js +70 -0
- package/src/lib/functions/createPopupMessageClient/index.d.ts +1 -0
- package/src/lib/functions/createPopupOpener/createPopupOpener.cjs +110 -42
- package/src/lib/functions/createPopupOpener/createPopupOpener.d.ts +2 -1
- package/src/lib/functions/createPopupOpener/createPopupOpener.js +111 -43
- package/src/lib/functions/createPopupOpener/utils/mapErrorFromPopup.cjs +25 -0
- package/src/lib/functions/createPopupOpener/utils/mapErrorFromPopup.d.ts +4 -0
- package/src/lib/functions/createPopupOpener/utils/mapErrorFromPopup.js +21 -0
- package/src/lib/solana/errors/UserRejectedRequestError.cjs +13 -0
- package/src/lib/solana/errors/UserRejectedRequestError.d.ts +4 -0
- package/src/lib/solana/errors/UserRejectedRequestError.js +9 -0
- package/src/lib/solana/functions/convertErrorToStandard/convertErrorToStandard.cjs +17 -0
- package/src/lib/solana/functions/convertErrorToStandard/convertErrorToStandard.d.ts +1 -0
- package/src/lib/solana/functions/convertErrorToStandard/convertErrorToStandard.js +13 -0
- package/src/lib/solana/functions/convertErrorToStandard/index.d.ts +1 -0
- package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/createSolanaSignAndSendTransactionFeature.cjs +5 -2
- package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/createSolanaSignAndSendTransactionFeature.js +5 -2
- package/src/lib/solana/functions/createSolanaSignMessageFeature/createSolanaSignMessageFeature.cjs +5 -2
- package/src/lib/solana/functions/createSolanaSignMessageFeature/createSolanaSignMessageFeature.js +5 -2
- package/src/lib/solana/functions/createSolanaSignTransactionFeature/createSolanaSignTransactionFeature.cjs +5 -2
- package/src/lib/solana/functions/createSolanaSignTransactionFeature/createSolanaSignTransactionFeature.js +5 -2
- package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.cjs +2 -1
- package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.js +2 -1
- package/src/lib/store/createClientStore.cjs +23 -1
- package/src/lib/store/createClientStore.d.ts +14 -0
- package/src/lib/store/createClientStore.js +23 -1
- package/src/lib/types/GlobalWalletPopupMessages.d.ts +16 -0
- package/src/lib/constants/logger.cjs +0 -10
- package/src/lib/constants/logger.js +0 -6
- package/src/lib/functions/mergeAndEncryptParams/index.d.ts +0 -1
- package/src/lib/functions/mergeAndEncryptParams/mergeAndEncryptParams.cjs +0 -23
- package/src/lib/functions/mergeAndEncryptParams/mergeAndEncryptParams.d.ts +0 -2
- package/src/lib/functions/mergeAndEncryptParams/mergeAndEncryptParams.js +0 -19
- package/src/lib/functions/mergeURLSearchParams/index.d.ts +0 -1
- package/src/lib/functions/mergeURLSearchParams/mergeURLSearchParams.cjs +0 -17
- package/src/lib/functions/mergeURLSearchParams/mergeURLSearchParams.d.ts +0 -6
- package/src/lib/functions/mergeURLSearchParams/mergeURLSearchParams.js +0 -13
- package/src/lib/functions/waitForPopupResponse/index.d.ts +0 -1
- package/src/lib/functions/waitForPopupResponse/waitForPopupResponse.cjs +0 -55
- package/src/lib/functions/waitForPopupResponse/waitForPopupResponse.d.ts +0 -9
- package/src/lib/functions/waitForPopupResponse/waitForPopupResponse.js +0 -51
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
3
|
import { uint8ArrayToBase64, uint8ArrayFromBase64 } from '@dynamic-labs/utils';
|
|
4
|
+
import { convertErrorToStandard } from '../convertErrorToStandard/convertErrorToStandard.js';
|
|
4
5
|
|
|
5
6
|
const createSolanaSignTransactionFeature = (client) => ({
|
|
6
7
|
signTransaction: (_a) => __awaiter(void 0, [_a], void 0, function* ({ account, transaction, chain }) {
|
|
7
|
-
const { signedTransaction } = yield client
|
|
8
|
+
const { signedTransaction } = yield client
|
|
9
|
+
.invoke({
|
|
8
10
|
params: {
|
|
9
11
|
address: account.address,
|
|
10
12
|
chain: chain,
|
|
11
13
|
transaction: uint8ArrayToBase64(transaction),
|
|
12
14
|
},
|
|
13
15
|
pathname: 'solana_signTransaction',
|
|
14
|
-
})
|
|
16
|
+
})
|
|
17
|
+
.catch(convertErrorToStandard);
|
|
15
18
|
return [
|
|
16
19
|
{
|
|
17
20
|
signedTransaction: uint8ArrayFromBase64(signedTransaction),
|
package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.cjs
CHANGED
|
@@ -5,11 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
7
7
|
var convertBaseWalletToWalletAccount = require('../convertBaseWalletToWalletAccount/convertBaseWalletToWalletAccount.cjs');
|
|
8
|
+
var convertErrorToStandard = require('../convertErrorToStandard/convertErrorToStandard.cjs');
|
|
8
9
|
|
|
9
10
|
const createStandardConnectFeature = (client) => ({
|
|
10
11
|
connect: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
11
12
|
if (!client.solana.wallets.length) {
|
|
12
|
-
yield client.connect({ chain: 'solana' });
|
|
13
|
+
yield client.connect({ chain: 'solana' }).catch(convertErrorToStandard.convertErrorToStandard);
|
|
13
14
|
}
|
|
14
15
|
return {
|
|
15
16
|
accounts: client.solana.wallets.map((wallet) => convertBaseWalletToWalletAccount.convertBaseWalletToWalletAccount(wallet, client)),
|
package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
3
|
import { convertBaseWalletToWalletAccount } from '../convertBaseWalletToWalletAccount/convertBaseWalletToWalletAccount.js';
|
|
4
|
+
import { convertErrorToStandard } from '../convertErrorToStandard/convertErrorToStandard.js';
|
|
4
5
|
|
|
5
6
|
const createStandardConnectFeature = (client) => ({
|
|
6
7
|
connect: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
7
8
|
if (!client.solana.wallets.length) {
|
|
8
|
-
yield client.connect({ chain: 'solana' });
|
|
9
|
+
yield client.connect({ chain: 'solana' }).catch(convertErrorToStandard);
|
|
9
10
|
}
|
|
10
11
|
return {
|
|
11
12
|
accounts: client.solana.wallets.map((wallet) => convertBaseWalletToWalletAccount(wallet, client)),
|
|
@@ -8,11 +8,20 @@ var store = require('@dynamic-labs/store');
|
|
|
8
8
|
const createClientStore = ({ storage = localStorage, } = {}) => {
|
|
9
9
|
const store$1 = store.persist({
|
|
10
10
|
name: 'global-wallet-client',
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The client should not persist sessionAuthCode
|
|
13
|
+
*/
|
|
14
|
+
partialize: (state) => ({
|
|
15
|
+
connection: state.connection,
|
|
16
|
+
ethereum: state.ethereum,
|
|
17
|
+
solana: state.solana,
|
|
18
|
+
wallets: state.wallets,
|
|
19
|
+
}),
|
|
12
20
|
storage,
|
|
13
21
|
store: store.createStore(() => ({
|
|
14
22
|
connection: null,
|
|
15
23
|
ethereum: null,
|
|
24
|
+
sessionAuthCode: null,
|
|
16
25
|
solana: null,
|
|
17
26
|
wallets: [],
|
|
18
27
|
})),
|
|
@@ -47,6 +56,12 @@ const createClientStore = ({ storage = localStorage, } = {}) => {
|
|
|
47
56
|
}
|
|
48
57
|
return connection;
|
|
49
58
|
},
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves the session auth code
|
|
61
|
+
*/
|
|
62
|
+
get sessionAuthCode() {
|
|
63
|
+
return store$1.getState().sessionAuthCode;
|
|
64
|
+
},
|
|
50
65
|
/**
|
|
51
66
|
* Updates current connection, wallets
|
|
52
67
|
* Used when the popup confirm a connection
|
|
@@ -55,6 +70,13 @@ const createClientStore = ({ storage = localStorage, } = {}) => {
|
|
|
55
70
|
setInitialConnectionState: ({ connection, wallets, ethereum, solana, }) => {
|
|
56
71
|
store$1.setState({ connection, ethereum, solana, wallets });
|
|
57
72
|
},
|
|
73
|
+
/**
|
|
74
|
+
* Updates the session auth code
|
|
75
|
+
* @param {BufferSource} sessionAuthCode - The session auth code to store
|
|
76
|
+
*/
|
|
77
|
+
setSessionAuthCode: (sessionAuthCode) => {
|
|
78
|
+
store$1.setState({ sessionAuthCode });
|
|
79
|
+
},
|
|
58
80
|
/**
|
|
59
81
|
* Get all Solana wallets connected to the current connection
|
|
60
82
|
*/
|
|
@@ -26,6 +26,11 @@ type ClientStoreState = {
|
|
|
26
26
|
solana: {
|
|
27
27
|
currentNetwork: string;
|
|
28
28
|
} | null;
|
|
29
|
+
/**
|
|
30
|
+
* Session Auth Code
|
|
31
|
+
* Used to decrypt and encrypt messages between client and popup
|
|
32
|
+
*/
|
|
33
|
+
sessionAuthCode: BufferSource | null;
|
|
29
34
|
};
|
|
30
35
|
export declare const createClientStore: ({ storage, }?: CreateClientStoreProps) => {
|
|
31
36
|
/**
|
|
@@ -46,12 +51,21 @@ export declare const createClientStore: ({ storage, }?: CreateClientStoreProps)
|
|
|
46
51
|
* @returns {Connection | null} The current connection or null if no connection exists or it has expired
|
|
47
52
|
*/
|
|
48
53
|
getActiveConnection: () => GlobalWalletConnection | null;
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves the session auth code
|
|
56
|
+
*/
|
|
57
|
+
readonly sessionAuthCode: BufferSource | null;
|
|
49
58
|
/**
|
|
50
59
|
* Updates current connection, wallets
|
|
51
60
|
* Used when the popup confirm a connection
|
|
52
61
|
* @param {GlobalWalletConnection | null} connection - The connection to store, or null to clear it
|
|
53
62
|
*/
|
|
54
63
|
setInitialConnectionState: ({ connection, wallets, ethereum, solana, }: Pick<ClientStoreState, 'connection' | 'wallets' | 'ethereum' | 'solana'>) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Updates the session auth code
|
|
66
|
+
* @param {BufferSource} sessionAuthCode - The session auth code to store
|
|
67
|
+
*/
|
|
68
|
+
setSessionAuthCode: (sessionAuthCode: BufferSource) => void;
|
|
55
69
|
/**
|
|
56
70
|
* Get all Solana wallets connected to the current connection
|
|
57
71
|
*/
|
|
@@ -4,11 +4,20 @@ import { persist, createStore } from '@dynamic-labs/store';
|
|
|
4
4
|
const createClientStore = ({ storage = localStorage, } = {}) => {
|
|
5
5
|
const store = persist({
|
|
6
6
|
name: 'global-wallet-client',
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The client should not persist sessionAuthCode
|
|
9
|
+
*/
|
|
10
|
+
partialize: (state) => ({
|
|
11
|
+
connection: state.connection,
|
|
12
|
+
ethereum: state.ethereum,
|
|
13
|
+
solana: state.solana,
|
|
14
|
+
wallets: state.wallets,
|
|
15
|
+
}),
|
|
8
16
|
storage,
|
|
9
17
|
store: createStore(() => ({
|
|
10
18
|
connection: null,
|
|
11
19
|
ethereum: null,
|
|
20
|
+
sessionAuthCode: null,
|
|
12
21
|
solana: null,
|
|
13
22
|
wallets: [],
|
|
14
23
|
})),
|
|
@@ -43,6 +52,12 @@ const createClientStore = ({ storage = localStorage, } = {}) => {
|
|
|
43
52
|
}
|
|
44
53
|
return connection;
|
|
45
54
|
},
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves the session auth code
|
|
57
|
+
*/
|
|
58
|
+
get sessionAuthCode() {
|
|
59
|
+
return store.getState().sessionAuthCode;
|
|
60
|
+
},
|
|
46
61
|
/**
|
|
47
62
|
* Updates current connection, wallets
|
|
48
63
|
* Used when the popup confirm a connection
|
|
@@ -51,6 +66,13 @@ const createClientStore = ({ storage = localStorage, } = {}) => {
|
|
|
51
66
|
setInitialConnectionState: ({ connection, wallets, ethereum, solana, }) => {
|
|
52
67
|
store.setState({ connection, ethereum, solana, wallets });
|
|
53
68
|
},
|
|
69
|
+
/**
|
|
70
|
+
* Updates the session auth code
|
|
71
|
+
* @param {BufferSource} sessionAuthCode - The session auth code to store
|
|
72
|
+
*/
|
|
73
|
+
setSessionAuthCode: (sessionAuthCode) => {
|
|
74
|
+
store.setState({ sessionAuthCode });
|
|
75
|
+
},
|
|
54
76
|
/**
|
|
55
77
|
* Get all Solana wallets connected to the current connection
|
|
56
78
|
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SerializedError } from '@dynamic-labs/message-transport';
|
|
2
|
+
import { IPopupActionDefinition } from '@dynamic-labs/types';
|
|
3
|
+
export type GlobalWalletPopupMessages = {
|
|
4
|
+
sendPopupNonce: (nonce: string) => void;
|
|
5
|
+
sendPopupSessionPublicKey: (sessionPublicKey: string) => void;
|
|
6
|
+
actionResolved: (response: {
|
|
7
|
+
data: unknown;
|
|
8
|
+
id: string;
|
|
9
|
+
}) => void;
|
|
10
|
+
actionRejected: (response: {
|
|
11
|
+
serializedError: SerializedError;
|
|
12
|
+
id: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
sendError: (serializedError: SerializedError) => void;
|
|
15
|
+
sendAction: (action: IPopupActionDefinition) => void;
|
|
16
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { mergeAndEncryptParams } from './mergeAndEncryptParams';
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
|
-
var utils = require('@dynamic-labs/utils');
|
|
8
|
-
var mergeURLSearchParams = require('../mergeURLSearchParams/mergeURLSearchParams.cjs');
|
|
9
|
-
|
|
10
|
-
const mergeAndEncryptParams = (url, params, activeConnection) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
-
if (activeConnection) {
|
|
12
|
-
const encryptedParams = yield utils.encryptMessage(activeConnection.sharedSecret, JSON.stringify(params));
|
|
13
|
-
mergeURLSearchParams.mergeURLSearchParams(url.searchParams, new URLSearchParams({
|
|
14
|
-
encrypted_message: encryptedParams.encryptedMessage,
|
|
15
|
-
iv: encryptedParams.iv,
|
|
16
|
-
}));
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
mergeURLSearchParams.mergeURLSearchParams(url.searchParams, new URLSearchParams(params));
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
exports.mergeAndEncryptParams = mergeAndEncryptParams;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
|
-
import { encryptMessage } from '@dynamic-labs/utils';
|
|
4
|
-
import { mergeURLSearchParams } from '../mergeURLSearchParams/mergeURLSearchParams.js';
|
|
5
|
-
|
|
6
|
-
const mergeAndEncryptParams = (url, params, activeConnection) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7
|
-
if (activeConnection) {
|
|
8
|
-
const encryptedParams = yield encryptMessage(activeConnection.sharedSecret, JSON.stringify(params));
|
|
9
|
-
mergeURLSearchParams(url.searchParams, new URLSearchParams({
|
|
10
|
-
encrypted_message: encryptedParams.encryptedMessage,
|
|
11
|
-
iv: encryptedParams.iv,
|
|
12
|
-
}));
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
mergeURLSearchParams(url.searchParams, new URLSearchParams(params));
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export { mergeAndEncryptParams };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { mergeURLSearchParams } from './mergeURLSearchParams';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Merges URL search parameters from a source into a target URLSearchParams object
|
|
8
|
-
* @param target - The URLSearchParams object to merge into
|
|
9
|
-
* @param source - The URLSearchParams object to merge from
|
|
10
|
-
*/
|
|
11
|
-
const mergeURLSearchParams = (target, source) => {
|
|
12
|
-
source.forEach((value, key) => {
|
|
13
|
-
target.set(key, value);
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
exports.mergeURLSearchParams = mergeURLSearchParams;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Merges URL search parameters from a source into a target URLSearchParams object
|
|
3
|
-
* @param target - The URLSearchParams object to merge into
|
|
4
|
-
* @param source - The URLSearchParams object to merge from
|
|
5
|
-
*/
|
|
6
|
-
export declare const mergeURLSearchParams: (target: URLSearchParams, source: URLSearchParams) => void;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
/**
|
|
3
|
-
* Merges URL search parameters from a source into a target URLSearchParams object
|
|
4
|
-
* @param target - The URLSearchParams object to merge into
|
|
5
|
-
* @param source - The URLSearchParams object to merge from
|
|
6
|
-
*/
|
|
7
|
-
const mergeURLSearchParams = (target, source) => {
|
|
8
|
-
source.forEach((value, key) => {
|
|
9
|
-
target.set(key, value);
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export { mergeURLSearchParams };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { waitForPopupResponse } from './waitForPopupResponse';
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
|
-
var logger = require('../../constants/logger.cjs');
|
|
8
|
-
|
|
9
|
-
const waitForPopupResponse = ({ popupUrl, decode, onResponse, onError, }) => {
|
|
10
|
-
const handleOnWindowEvent = (event) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
-
if (event.origin !== new URL(popupUrl).origin)
|
|
12
|
-
return;
|
|
13
|
-
let parsedData = null;
|
|
14
|
-
try {
|
|
15
|
-
parsedData = JSON.parse(event.data);
|
|
16
|
-
}
|
|
17
|
-
catch (err) {
|
|
18
|
-
logger.logger.debug('Error parsing data from WebExtension iFrame event', err);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const decodedMessage = decode ? yield decode(parsedData) : parsedData;
|
|
22
|
-
const { error, success } = parseData(decodedMessage);
|
|
23
|
-
if (!error && !success) {
|
|
24
|
-
logger.logger.debug('Error validating event data schema from popup response event', parsedData);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (success) {
|
|
28
|
-
onResponse(success);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
32
|
-
onError(new Error(error.message));
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
window.addEventListener('message', handleOnWindowEvent);
|
|
36
|
-
return () => {
|
|
37
|
-
window.removeEventListener('message', handleOnWindowEvent);
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
const parseData = (data) => {
|
|
41
|
-
if (!data || typeof data !== 'object') {
|
|
42
|
-
return {};
|
|
43
|
-
}
|
|
44
|
-
// Check if it's a success response
|
|
45
|
-
if (data.name && data.data) {
|
|
46
|
-
return { success: data };
|
|
47
|
-
}
|
|
48
|
-
// Check if it's an error response
|
|
49
|
-
if (data.message) {
|
|
50
|
-
return { error: data };
|
|
51
|
-
}
|
|
52
|
-
return {};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
exports.waitForPopupResponse = waitForPopupResponse;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { IPopupActionSuccessResponse } from '@dynamic-labs/types';
|
|
2
|
-
type WaitForPopupResponseProps = {
|
|
3
|
-
popupUrl: string;
|
|
4
|
-
decode?: (data: any) => Promise<any>;
|
|
5
|
-
onResponse: (response: IPopupActionSuccessResponse) => void;
|
|
6
|
-
onError: (error: Error) => void;
|
|
7
|
-
};
|
|
8
|
-
export declare const waitForPopupResponse: ({ popupUrl, decode, onResponse, onError, }: WaitForPopupResponseProps) => () => void;
|
|
9
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
|
-
import { logger } from '../../constants/logger.js';
|
|
4
|
-
|
|
5
|
-
const waitForPopupResponse = ({ popupUrl, decode, onResponse, onError, }) => {
|
|
6
|
-
const handleOnWindowEvent = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7
|
-
if (event.origin !== new URL(popupUrl).origin)
|
|
8
|
-
return;
|
|
9
|
-
let parsedData = null;
|
|
10
|
-
try {
|
|
11
|
-
parsedData = JSON.parse(event.data);
|
|
12
|
-
}
|
|
13
|
-
catch (err) {
|
|
14
|
-
logger.debug('Error parsing data from WebExtension iFrame event', err);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const decodedMessage = decode ? yield decode(parsedData) : parsedData;
|
|
18
|
-
const { error, success } = parseData(decodedMessage);
|
|
19
|
-
if (!error && !success) {
|
|
20
|
-
logger.debug('Error validating event data schema from popup response event', parsedData);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (success) {
|
|
24
|
-
onResponse(success);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
28
|
-
onError(new Error(error.message));
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
window.addEventListener('message', handleOnWindowEvent);
|
|
32
|
-
return () => {
|
|
33
|
-
window.removeEventListener('message', handleOnWindowEvent);
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
const parseData = (data) => {
|
|
37
|
-
if (!data || typeof data !== 'object') {
|
|
38
|
-
return {};
|
|
39
|
-
}
|
|
40
|
-
// Check if it's a success response
|
|
41
|
-
if (data.name && data.data) {
|
|
42
|
-
return { success: data };
|
|
43
|
-
}
|
|
44
|
-
// Check if it's an error response
|
|
45
|
-
if (data.message) {
|
|
46
|
-
return { error: data };
|
|
47
|
-
}
|
|
48
|
-
return {};
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export { waitForPopupResponse };
|