@dynamic-labs/global-wallet-client 4.0.0-alpha.47 → 4.0.0-alpha.49
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 +36 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +24 -4
- package/src/ethereum.cjs +12 -0
- package/src/ethereum.d.ts +1 -0
- package/src/ethereum.js +3 -0
- package/src/index.cjs +2 -2
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/lib/actions/connectAction/createConnectAction.cjs +38 -0
- package/src/lib/actions/connectAction/createConnectAction.d.ts +10 -0
- package/src/lib/actions/connectAction/createConnectAction.js +34 -0
- package/src/lib/actions/connectAction/index.d.ts +1 -0
- package/src/lib/actions/disconnectAction/createDisconnectAction.cjs +11 -0
- package/src/lib/actions/disconnectAction/createDisconnectAction.d.ts +7 -0
- package/src/lib/actions/disconnectAction/createDisconnectAction.js +7 -0
- package/src/lib/actions/disconnectAction/index.d.ts +1 -0
- package/src/lib/constants/logger.cjs +10 -0
- package/src/lib/constants/logger.d.ts +2 -0
- package/src/lib/constants/logger.js +6 -0
- package/src/lib/createGlobalWalletClient.cjs +44 -0
- package/src/lib/createGlobalWalletClient.d.ts +54 -0
- package/src/lib/createGlobalWalletClient.js +40 -0
- package/src/lib/ethereum/functions/announceEIP6963Provider/announceEIP6963Provider.cjs +29 -0
- package/src/lib/ethereum/functions/announceEIP6963Provider/announceEIP6963Provider.d.ts +12 -0
- package/src/lib/ethereum/functions/announceEIP6963Provider/announceEIP6963Provider.js +25 -0
- package/src/lib/ethereum/functions/announceEIP6963Provider/index.d.ts +1 -0
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.cjs +88 -0
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.d.ts +3 -0
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.js +84 -0
- package/src/lib/ethereum/functions/eip1193Provider/index.d.ts +1 -0
- package/src/lib/ethereum/index.d.ts +2 -0
- package/src/lib/functions/createClientEventEmitter/createClientEventEmitter.cjs +10 -0
- package/src/lib/functions/createClientEventEmitter/createClientEventEmitter.d.ts +6 -0
- package/src/lib/functions/createClientEventEmitter/createClientEventEmitter.js +6 -0
- package/src/lib/functions/createClientEventEmitter/index.d.ts +1 -0
- package/src/lib/functions/createPopupOpener/createPopupOpener.cjs +52 -0
- package/src/lib/functions/createPopupOpener/createPopupOpener.d.ts +15 -0
- package/src/lib/functions/createPopupOpener/createPopupOpener.js +48 -0
- package/src/lib/functions/createPopupOpener/index.d.ts +1 -0
- package/src/lib/functions/mergeAndEncryptParams/index.d.ts +1 -0
- package/src/lib/functions/mergeAndEncryptParams/mergeAndEncryptParams.cjs +23 -0
- package/src/lib/functions/mergeAndEncryptParams/mergeAndEncryptParams.d.ts +2 -0
- package/src/lib/functions/mergeAndEncryptParams/mergeAndEncryptParams.js +19 -0
- package/src/lib/functions/mergeURLSearchParams/index.d.ts +1 -0
- package/src/lib/functions/mergeURLSearchParams/mergeURLSearchParams.cjs +17 -0
- package/src/lib/functions/mergeURLSearchParams/mergeURLSearchParams.d.ts +6 -0
- package/src/lib/functions/mergeURLSearchParams/mergeURLSearchParams.js +13 -0
- package/src/lib/functions/onPopupClose/index.d.ts +1 -0
- package/src/lib/functions/onPopupClose/onPopupClose.cjs +22 -0
- package/src/lib/functions/onPopupClose/onPopupClose.d.ts +8 -0
- package/src/lib/functions/onPopupClose/onPopupClose.js +18 -0
- package/src/lib/functions/waitForPopupResponse/index.d.ts +1 -0
- package/src/lib/functions/waitForPopupResponse/waitForPopupResponse.cjs +55 -0
- package/src/lib/functions/waitForPopupResponse/waitForPopupResponse.d.ts +9 -0
- package/src/lib/functions/waitForPopupResponse/waitForPopupResponse.js +51 -0
- package/src/lib/store/createClientStore.cjs +67 -0
- package/src/lib/store/createClientStore.d.ts +34 -0
- package/src/lib/store/createClientStore.js +63 -0
- package/src/lib/store/index.d.ts +1 -0
- package/src/lib/types.d.ts +37 -0
- package/src/lib/global-wallet-client.cjs +0 -8
- package/src/lib/global-wallet-client.d.ts +0 -1
- package/src/lib/global-wallet-client.js +0 -4
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var store = require('@dynamic-labs/store');
|
|
7
|
+
|
|
8
|
+
const createClientStore = ({ storage = localStorage, } = {}) => {
|
|
9
|
+
const store$1 = store.persist({
|
|
10
|
+
name: 'global-wallet-client',
|
|
11
|
+
partialize: (state) => state,
|
|
12
|
+
storage,
|
|
13
|
+
store: store.createStore(() => ({
|
|
14
|
+
connection: null,
|
|
15
|
+
})),
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
/**
|
|
19
|
+
* Resets the store to its initial state
|
|
20
|
+
*/
|
|
21
|
+
clear: () => {
|
|
22
|
+
store$1.setState(store$1.getInitialState());
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the current active connection if it exists and hasn't expired
|
|
26
|
+
* @returns {Connection | null} The current connection or null if no connection exists or it has expired
|
|
27
|
+
*/
|
|
28
|
+
getActiveConnection: () => {
|
|
29
|
+
const { connection } = store$1.getState();
|
|
30
|
+
if (!connection) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (connection.expiresAt < Date.now()) {
|
|
34
|
+
// Clear the connection if it has expired
|
|
35
|
+
store$1.setState(store$1.getInitialState());
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return connection;
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Updates the connection in the store
|
|
42
|
+
* @param {Connection | null} connection - The connection to store, or null to clear it
|
|
43
|
+
*/
|
|
44
|
+
setConnection: (connection) => {
|
|
45
|
+
store$1.setState({ connection });
|
|
46
|
+
},
|
|
47
|
+
/**
|
|
48
|
+
* Gets the current state of the store
|
|
49
|
+
* @returns The complete store state
|
|
50
|
+
*/
|
|
51
|
+
get state() {
|
|
52
|
+
return store$1.getState();
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Gets the current user's wallets
|
|
56
|
+
* @returns The current user's wallets
|
|
57
|
+
*/
|
|
58
|
+
get userWallets() {
|
|
59
|
+
var _a, _b, _c, _d, _e;
|
|
60
|
+
const evm = (_c = (_b = (_a = store$1.getState().connection) === null || _a === void 0 ? void 0 : _a.evm) === null || _b === void 0 ? void 0 : _b.wallets) !== null && _c !== void 0 ? _c : [];
|
|
61
|
+
const solana = (_e = (_d = store$1.getState().connection) === null || _d === void 0 ? void 0 : _d.solana) === null || _e === void 0 ? void 0 : _e.wallet;
|
|
62
|
+
return solana ? [...evm, solana] : evm;
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
exports.createClientStore = createClientStore;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Connection } from '../types';
|
|
2
|
+
type CreateClientStoreProps = {
|
|
3
|
+
storage?: Storage;
|
|
4
|
+
};
|
|
5
|
+
export declare const createClientStore: ({ storage, }?: CreateClientStoreProps) => {
|
|
6
|
+
/**
|
|
7
|
+
* Resets the store to its initial state
|
|
8
|
+
*/
|
|
9
|
+
clear: () => void;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the current active connection if it exists and hasn't expired
|
|
12
|
+
* @returns {Connection | null} The current connection or null if no connection exists or it has expired
|
|
13
|
+
*/
|
|
14
|
+
getActiveConnection: () => Connection | null;
|
|
15
|
+
/**
|
|
16
|
+
* Updates the connection in the store
|
|
17
|
+
* @param {Connection | null} connection - The connection to store, or null to clear it
|
|
18
|
+
*/
|
|
19
|
+
setConnection: (connection: Connection | null) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the current state of the store
|
|
22
|
+
* @returns The complete store state
|
|
23
|
+
*/
|
|
24
|
+
readonly state: {
|
|
25
|
+
connection: Connection | null;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Gets the current user's wallets
|
|
29
|
+
* @returns The current user's wallets
|
|
30
|
+
*/
|
|
31
|
+
readonly userWallets: import("dist/packages/types/src").BaseWallet[];
|
|
32
|
+
};
|
|
33
|
+
export type ClientStore = ReturnType<typeof createClientStore>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { persist, createStore } from '@dynamic-labs/store';
|
|
3
|
+
|
|
4
|
+
const createClientStore = ({ storage = localStorage, } = {}) => {
|
|
5
|
+
const store = persist({
|
|
6
|
+
name: 'global-wallet-client',
|
|
7
|
+
partialize: (state) => state,
|
|
8
|
+
storage,
|
|
9
|
+
store: createStore(() => ({
|
|
10
|
+
connection: null,
|
|
11
|
+
})),
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
/**
|
|
15
|
+
* Resets the store to its initial state
|
|
16
|
+
*/
|
|
17
|
+
clear: () => {
|
|
18
|
+
store.setState(store.getInitialState());
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the current active connection if it exists and hasn't expired
|
|
22
|
+
* @returns {Connection | null} The current connection or null if no connection exists or it has expired
|
|
23
|
+
*/
|
|
24
|
+
getActiveConnection: () => {
|
|
25
|
+
const { connection } = store.getState();
|
|
26
|
+
if (!connection) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (connection.expiresAt < Date.now()) {
|
|
30
|
+
// Clear the connection if it has expired
|
|
31
|
+
store.setState(store.getInitialState());
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return connection;
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Updates the connection in the store
|
|
38
|
+
* @param {Connection | null} connection - The connection to store, or null to clear it
|
|
39
|
+
*/
|
|
40
|
+
setConnection: (connection) => {
|
|
41
|
+
store.setState({ connection });
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Gets the current state of the store
|
|
45
|
+
* @returns The complete store state
|
|
46
|
+
*/
|
|
47
|
+
get state() {
|
|
48
|
+
return store.getState();
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Gets the current user's wallets
|
|
52
|
+
* @returns The current user's wallets
|
|
53
|
+
*/
|
|
54
|
+
get userWallets() {
|
|
55
|
+
var _a, _b, _c, _d, _e;
|
|
56
|
+
const evm = (_c = (_b = (_a = store.getState().connection) === null || _a === void 0 ? void 0 : _a.evm) === null || _b === void 0 ? void 0 : _b.wallets) !== null && _c !== void 0 ? _c : [];
|
|
57
|
+
const solana = (_e = (_d = store.getState().connection) === null || _d === void 0 ? void 0 : _d.solana) === null || _e === void 0 ? void 0 : _e.wallet;
|
|
58
|
+
return solana ? [...evm, solana] : evm;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export { createClientStore };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createClientStore, type ClientStore } from './createClientStore';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseWallet } from '@dynamic-labs/types';
|
|
2
|
+
export type IconCode = `data:image/png;base64,${string}`;
|
|
3
|
+
export type PopupInfo = {
|
|
4
|
+
url: string;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
};
|
|
8
|
+
export type ConnectArgs = {
|
|
9
|
+
chain: 'evm' | 'solana';
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Defines the current dapp connection
|
|
13
|
+
*/
|
|
14
|
+
export type Connection = {
|
|
15
|
+
/** Unix timestamp when the connection expires */
|
|
16
|
+
expiresAt: number;
|
|
17
|
+
/** EVM blockchain configuration */
|
|
18
|
+
evm: {
|
|
19
|
+
/** List of networks that can be switched to */
|
|
20
|
+
supportedNetworks: {
|
|
21
|
+
chainId: number;
|
|
22
|
+
}[];
|
|
23
|
+
/** Connected EVM wallets */
|
|
24
|
+
wallets: BaseWallet[];
|
|
25
|
+
/** Currently active network identifier */
|
|
26
|
+
network: string;
|
|
27
|
+
} | null;
|
|
28
|
+
/** Solana blockchain configuration */
|
|
29
|
+
solana: {
|
|
30
|
+
/** Connected Solana wallet */
|
|
31
|
+
wallet: BaseWallet;
|
|
32
|
+
/** Currently active network identifier */
|
|
33
|
+
network: string;
|
|
34
|
+
} | null;
|
|
35
|
+
/** Encryption key for secure communication */
|
|
36
|
+
sharedSecret: string;
|
|
37
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const globalWalletClient = "global-wallet-client";
|