@dynamic-labs/ethereum 4.0.0-alpha.39 → 4.0.0-alpha.40
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 +9 -9
- package/src/injected/fetchInjectedWalletConnectors.cjs +42 -36
- package/src/injected/fetchInjectedWalletConnectors.js +43 -37
- package/src/utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.cjs +30 -0
- package/src/utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.d.ts +3 -0
- package/src/utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.js +26 -0
- package/src/utils/getConnectorConstructorForEip6963Wallet/index.d.ts +1 -0
- package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.cjs +44 -0
- package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.d.ts +3 -0
- package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.js +40 -0
- package/src/utils/getConnectorConstructorInjectedWallet/index.d.ts +1 -0
- package/src/walletConnect/walletConnect.cjs +2 -3
- package/src/walletConnect/walletConnect.js +1 -2
- package/src/utils/isString.d.ts +0 -1
- package/src/utils/last.d.ts +0 -1
- package/src/utils/parseIntSafe.cjs +0 -23
- package/src/utils/parseIntSafe.d.ts +0 -1
- package/src/utils/parseIntSafe.js +0 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.0.0-alpha.40](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.39...v4.0.0-alpha.40) (2024-12-03)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* detect all eip6963 wallets, even if not in wallet-book ([#7515](https://github.com/dynamic-labs/dynamic-auth/issues/7515)) ([b658740](https://github.com/dynamic-labs/dynamic-auth/commit/b658740c16d8d26877eb955dc403077c8e9840fb))
|
|
8
|
+
* useWalletOptions provides chain and allows filtering ([#7533](https://github.com/dynamic-labs/dynamic-auth/issues/7533)) ([da47608](https://github.com/dynamic-labs/dynamic-auth/commit/da476084bcc72b2bf0b6fa599992be640d59724c))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **QNTM-1845:** use smaller log in button sizing ([#7526](https://github.com/dynamic-labs/dynamic-auth/issues/7526)) ([264810b](https://github.com/dynamic-labs/dynamic-auth/commit/264810b3b9cddf7006c1f653b4cc10f23804ae50))
|
|
14
|
+
* update twitter to X in social provide label ([#7530](https://github.com/dynamic-labs/dynamic-auth/issues/7530)) ([c02fca0](https://github.com/dynamic-labs/dynamic-auth/commit/c02fca03de2f46a9e50d19c9e7ef2dfba0b33efc))
|
|
15
|
+
|
|
2
16
|
## [4.0.0-alpha.39](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.38...v4.0.0-alpha.39) (2024-12-02)
|
|
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/ethereum",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.40",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"eventemitter3": "5.0.1",
|
|
25
25
|
"buffer": "6.0.3",
|
|
26
26
|
"@metamask/sdk": "0.30.1",
|
|
27
|
-
"@dynamic-labs/assert-package-version": "4.0.0-alpha.
|
|
28
|
-
"@dynamic-labs/embedded-wallet-evm": "4.0.0-alpha.
|
|
29
|
-
"@dynamic-labs/ethereum-core": "4.0.0-alpha.
|
|
30
|
-
"@dynamic-labs/logger": "4.0.0-alpha.
|
|
31
|
-
"@dynamic-labs/types": "4.0.0-alpha.
|
|
32
|
-
"@dynamic-labs/utils": "4.0.0-alpha.
|
|
33
|
-
"@dynamic-labs/wallet-book": "4.0.0-alpha.
|
|
34
|
-
"@dynamic-labs/wallet-connector-core": "4.0.0-alpha.
|
|
27
|
+
"@dynamic-labs/assert-package-version": "4.0.0-alpha.40",
|
|
28
|
+
"@dynamic-labs/embedded-wallet-evm": "4.0.0-alpha.40",
|
|
29
|
+
"@dynamic-labs/ethereum-core": "4.0.0-alpha.40",
|
|
30
|
+
"@dynamic-labs/logger": "4.0.0-alpha.40",
|
|
31
|
+
"@dynamic-labs/types": "4.0.0-alpha.40",
|
|
32
|
+
"@dynamic-labs/utils": "4.0.0-alpha.40",
|
|
33
|
+
"@dynamic-labs/wallet-book": "4.0.0-alpha.40",
|
|
34
|
+
"@dynamic-labs/wallet-connector-core": "4.0.0-alpha.40"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"viem": "^2.7.6"
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
6
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
-
var
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
var getConnectorConstructorForEip6963Wallet = require('../utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.cjs');
|
|
9
|
+
var getConnectorConstructorInjectedWallet = require('../utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.cjs');
|
|
9
10
|
var PhantomEvm = require('./PhantomEvm.cjs');
|
|
10
11
|
var ExodusEvm = require('./ExodusEvm.cjs');
|
|
11
12
|
|
|
@@ -22,47 +23,52 @@ const walletsWithCustomConnectors = [
|
|
|
22
23
|
'edenonline',
|
|
23
24
|
'intersend',
|
|
24
25
|
];
|
|
26
|
+
let removeEip6963EventsListener;
|
|
27
|
+
// should add eip6963 connector only if not in wallet-book, to avoid adding duplicate connectors
|
|
28
|
+
const shouldAddEip6963Connector = (eip6963ProviderInfo, walletBook) => {
|
|
29
|
+
var _a;
|
|
30
|
+
const { rdns, name } = eip6963ProviderInfo;
|
|
31
|
+
const chain = 'evm';
|
|
32
|
+
const connectorKey = `${utils.sanitizeName(name)}${chain}`;
|
|
33
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('[ETH shouldAddEip6963Connector]', rdns, name, chain, connectorKey);
|
|
34
|
+
const existingWallet = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {}).find(([key, wallet]) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
return ((_a = wallet.eip6963Config) === null || _a === void 0 ? void 0 : _a.rdns) === rdns ||
|
|
37
|
+
key === connectorKey ||
|
|
38
|
+
walletsWithCustomConnectors.includes(connectorKey) ||
|
|
39
|
+
(wallet.name === name && ((_b = wallet.injectedConfig) === null || _b === void 0 ? void 0 : _b[0].chain) === chain);
|
|
40
|
+
});
|
|
41
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('[ETH shouldAddEip6963Connector]', existingWallet);
|
|
42
|
+
return !existingWallet;
|
|
43
|
+
};
|
|
44
|
+
const addEip6963Listener = (walletBook) => {
|
|
45
|
+
removeEip6963EventsListener === null || removeEip6963EventsListener === void 0 ? void 0 : removeEip6963EventsListener();
|
|
46
|
+
removeEip6963EventsListener = utils.listenToEip6963Events((event) => {
|
|
47
|
+
if (!shouldAddEip6963Connector(event.detail.info, walletBook)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('[ETH fetchInjectedWalletConnectors] listenToEip6963Events', event.detail);
|
|
51
|
+
walletConnectorCore.walletConnectorEvents.emit('providerInjected', {
|
|
52
|
+
injectedConnectorConstructor: getConnectorConstructorForEip6963Wallet.getConnectorConstructorForEip6963Wallet(event.detail),
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
25
56
|
const fetchInjectedWalletConnector = ({ walletBook, }) => {
|
|
26
57
|
var _a;
|
|
27
|
-
|
|
58
|
+
addEip6963Listener(walletBook);
|
|
59
|
+
const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
28
60
|
.filter(([key, wallet]) => {
|
|
29
61
|
var _a;
|
|
30
62
|
return ((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'evm')) &&
|
|
31
63
|
!walletsWithCustomConnectors.includes(key);
|
|
32
64
|
})
|
|
33
|
-
.map(([key, wallet]) =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.name = name;
|
|
41
|
-
this.walletConnectorFallback = walletConnectorFallback;
|
|
42
|
-
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
43
|
-
this.overrideKey = key;
|
|
44
|
-
}
|
|
45
|
-
getAddress() {
|
|
46
|
-
const _super = Object.create(null, {
|
|
47
|
-
getAddress: { get: () => super.getAddress }
|
|
48
|
-
});
|
|
49
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
var _a;
|
|
51
|
-
if (this.isInstalledOnBrowser()) {
|
|
52
|
-
return _super.getAddress.call(this);
|
|
53
|
-
}
|
|
54
|
-
const inAppBrowserBase = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl;
|
|
55
|
-
if (!inAppBrowserBase) {
|
|
56
|
-
const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
|
|
57
|
-
walletConnectorCore.logger.error(error.message);
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
window.location.href = `${inAppBrowserBase}/${window.location.href}`;
|
|
61
|
-
return undefined;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
});
|
|
65
|
+
.map(([key, wallet]) => getConnectorConstructorInjectedWallet.getConnectorConstructorInjectedWallet(key, wallet));
|
|
66
|
+
const { providers } = utils.Eip6963ProviderSingleton.get();
|
|
67
|
+
const eip6963Connectors = providers
|
|
68
|
+
.filter((provider) => shouldAddEip6963Connector(provider.info, walletBook))
|
|
69
|
+
.map((provider) => getConnectorConstructorForEip6963Wallet.getConnectorConstructorForEip6963Wallet(provider));
|
|
70
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('[ETH fetchInjectedWalletConnectors] eip6963Connectors', eip6963Connectors);
|
|
71
|
+
return [...walletBookConnectors, ...eip6963Connectors];
|
|
66
72
|
};
|
|
67
73
|
|
|
68
74
|
exports.fetchInjectedWalletConnector = fetchInjectedWalletConnector;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { logger, walletConnectorEvents } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { Eip6963ProviderSingleton, sanitizeName, listenToEip6963Events } from '@dynamic-labs/utils';
|
|
4
|
+
import { getConnectorConstructorForEip6963Wallet } from '../utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.js';
|
|
5
|
+
import { getConnectorConstructorInjectedWallet } from '../utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.js';
|
|
5
6
|
import { PhantomEvm } from './PhantomEvm.js';
|
|
6
7
|
import { ExodusEvm } from './ExodusEvm.js';
|
|
7
8
|
|
|
@@ -18,47 +19,52 @@ const walletsWithCustomConnectors = [
|
|
|
18
19
|
'edenonline',
|
|
19
20
|
'intersend',
|
|
20
21
|
];
|
|
22
|
+
let removeEip6963EventsListener;
|
|
23
|
+
// should add eip6963 connector only if not in wallet-book, to avoid adding duplicate connectors
|
|
24
|
+
const shouldAddEip6963Connector = (eip6963ProviderInfo, walletBook) => {
|
|
25
|
+
var _a;
|
|
26
|
+
const { rdns, name } = eip6963ProviderInfo;
|
|
27
|
+
const chain = 'evm';
|
|
28
|
+
const connectorKey = `${sanitizeName(name)}${chain}`;
|
|
29
|
+
logger.logVerboseTroubleshootingMessage('[ETH shouldAddEip6963Connector]', rdns, name, chain, connectorKey);
|
|
30
|
+
const existingWallet = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {}).find(([key, wallet]) => {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
return ((_a = wallet.eip6963Config) === null || _a === void 0 ? void 0 : _a.rdns) === rdns ||
|
|
33
|
+
key === connectorKey ||
|
|
34
|
+
walletsWithCustomConnectors.includes(connectorKey) ||
|
|
35
|
+
(wallet.name === name && ((_b = wallet.injectedConfig) === null || _b === void 0 ? void 0 : _b[0].chain) === chain);
|
|
36
|
+
});
|
|
37
|
+
logger.logVerboseTroubleshootingMessage('[ETH shouldAddEip6963Connector]', existingWallet);
|
|
38
|
+
return !existingWallet;
|
|
39
|
+
};
|
|
40
|
+
const addEip6963Listener = (walletBook) => {
|
|
41
|
+
removeEip6963EventsListener === null || removeEip6963EventsListener === void 0 ? void 0 : removeEip6963EventsListener();
|
|
42
|
+
removeEip6963EventsListener = listenToEip6963Events((event) => {
|
|
43
|
+
if (!shouldAddEip6963Connector(event.detail.info, walletBook)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
logger.logVerboseTroubleshootingMessage('[ETH fetchInjectedWalletConnectors] listenToEip6963Events', event.detail);
|
|
47
|
+
walletConnectorEvents.emit('providerInjected', {
|
|
48
|
+
injectedConnectorConstructor: getConnectorConstructorForEip6963Wallet(event.detail),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
21
52
|
const fetchInjectedWalletConnector = ({ walletBook, }) => {
|
|
22
53
|
var _a;
|
|
23
|
-
|
|
54
|
+
addEip6963Listener(walletBook);
|
|
55
|
+
const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
24
56
|
.filter(([key, wallet]) => {
|
|
25
57
|
var _a;
|
|
26
58
|
return ((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'evm')) &&
|
|
27
59
|
!walletsWithCustomConnectors.includes(key);
|
|
28
60
|
})
|
|
29
|
-
.map(([key, wallet]) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.name = name;
|
|
37
|
-
this.walletConnectorFallback = walletConnectorFallback;
|
|
38
|
-
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
39
|
-
this.overrideKey = key;
|
|
40
|
-
}
|
|
41
|
-
getAddress() {
|
|
42
|
-
const _super = Object.create(null, {
|
|
43
|
-
getAddress: { get: () => super.getAddress }
|
|
44
|
-
});
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
var _a;
|
|
47
|
-
if (this.isInstalledOnBrowser()) {
|
|
48
|
-
return _super.getAddress.call(this);
|
|
49
|
-
}
|
|
50
|
-
const inAppBrowserBase = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl;
|
|
51
|
-
if (!inAppBrowserBase) {
|
|
52
|
-
const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
|
|
53
|
-
logger.error(error.message);
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
window.location.href = `${inAppBrowserBase}/${window.location.href}`;
|
|
57
|
-
return undefined;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
});
|
|
61
|
+
.map(([key, wallet]) => getConnectorConstructorInjectedWallet(key, wallet));
|
|
62
|
+
const { providers } = Eip6963ProviderSingleton.get();
|
|
63
|
+
const eip6963Connectors = providers
|
|
64
|
+
.filter((provider) => shouldAddEip6963Connector(provider.info, walletBook))
|
|
65
|
+
.map((provider) => getConnectorConstructorForEip6963Wallet(provider));
|
|
66
|
+
logger.logVerboseTroubleshootingMessage('[ETH fetchInjectedWalletConnectors] eip6963Connectors', eip6963Connectors);
|
|
67
|
+
return [...walletBookConnectors, ...eip6963Connectors];
|
|
62
68
|
};
|
|
63
69
|
|
|
64
70
|
export { fetchInjectedWalletConnector, injectedWalletOverrides };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
|
+
var InjectedWalletBase = require('../../injected/InjectedWalletBase.cjs');
|
|
8
|
+
|
|
9
|
+
const getConnectorConstructorForEip6963Wallet = (walletDetail) => {
|
|
10
|
+
const { info, provider } = walletDetail;
|
|
11
|
+
const sanitizedName = utils.sanitizeName(info.name);
|
|
12
|
+
return class extends InjectedWalletBase.InjectedWalletBase {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(Object.assign(Object.assign({}, props), { metadata: {
|
|
15
|
+
groupKey: sanitizedName,
|
|
16
|
+
icon: info.icon,
|
|
17
|
+
id: info.uuid,
|
|
18
|
+
name: info.name,
|
|
19
|
+
rdns: info.rdns,
|
|
20
|
+
} }));
|
|
21
|
+
this.name = info.name;
|
|
22
|
+
this.overrideKey = `${sanitizedName}evm`;
|
|
23
|
+
}
|
|
24
|
+
findProvider() {
|
|
25
|
+
return provider;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.getConnectorConstructorForEip6963Wallet = getConnectorConstructorForEip6963Wallet;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Eip6963ProviderDetail } from '@dynamic-labs/utils';
|
|
2
|
+
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
export declare const getConnectorConstructorForEip6963Wallet: (walletDetail: Eip6963ProviderDetail) => WalletConnectorConstructor;
|
package/src/utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { sanitizeName } from '@dynamic-labs/utils';
|
|
3
|
+
import { InjectedWalletBase } from '../../injected/InjectedWalletBase.js';
|
|
4
|
+
|
|
5
|
+
const getConnectorConstructorForEip6963Wallet = (walletDetail) => {
|
|
6
|
+
const { info, provider } = walletDetail;
|
|
7
|
+
const sanitizedName = sanitizeName(info.name);
|
|
8
|
+
return class extends InjectedWalletBase {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(Object.assign(Object.assign({}, props), { metadata: {
|
|
11
|
+
groupKey: sanitizedName,
|
|
12
|
+
icon: info.icon,
|
|
13
|
+
id: info.uuid,
|
|
14
|
+
name: info.name,
|
|
15
|
+
rdns: info.rdns,
|
|
16
|
+
} }));
|
|
17
|
+
this.name = info.name;
|
|
18
|
+
this.overrideKey = `${sanitizedName}evm`;
|
|
19
|
+
}
|
|
20
|
+
findProvider() {
|
|
21
|
+
return provider;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { getConnectorConstructorForEip6963Wallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getConnectorConstructorForEip6963Wallet } from './getConnectorConstructorForEip6963Wallet';
|
package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.cjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var InjectedWalletBase = require('../../injected/InjectedWalletBase.cjs');
|
|
8
|
+
var logger = require('../logger.cjs');
|
|
9
|
+
|
|
10
|
+
const getConnectorConstructorInjectedWallet = (key, wallet) => {
|
|
11
|
+
const { shortName } = wallet;
|
|
12
|
+
const name = shortName || wallet.name;
|
|
13
|
+
const walletConnectorFallback = Boolean(wallet.walletConnect);
|
|
14
|
+
return class extends InjectedWalletBase.InjectedWalletBase {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
this.name = name;
|
|
18
|
+
this.walletConnectorFallback = walletConnectorFallback;
|
|
19
|
+
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
20
|
+
this.overrideKey = key;
|
|
21
|
+
}
|
|
22
|
+
getAddress() {
|
|
23
|
+
const _super = Object.create(null, {
|
|
24
|
+
getAddress: { get: () => super.getAddress }
|
|
25
|
+
});
|
|
26
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
var _a;
|
|
28
|
+
if (this.isInstalledOnBrowser()) {
|
|
29
|
+
return _super.getAddress.call(this);
|
|
30
|
+
}
|
|
31
|
+
const inAppBrowserBase = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl;
|
|
32
|
+
if (!inAppBrowserBase) {
|
|
33
|
+
const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
|
|
34
|
+
logger.logger.error(error.message);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
window.location.href = `${inAppBrowserBase}/${window.location.href}`;
|
|
38
|
+
return undefined;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.getConnectorConstructorInjectedWallet = getConnectorConstructorInjectedWallet;
|
package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { InjectedWalletBase } from '../../injected/InjectedWalletBase.js';
|
|
4
|
+
import { logger } from '../logger.js';
|
|
5
|
+
|
|
6
|
+
const getConnectorConstructorInjectedWallet = (key, wallet) => {
|
|
7
|
+
const { shortName } = wallet;
|
|
8
|
+
const name = shortName || wallet.name;
|
|
9
|
+
const walletConnectorFallback = Boolean(wallet.walletConnect);
|
|
10
|
+
return class extends InjectedWalletBase {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.walletConnectorFallback = walletConnectorFallback;
|
|
15
|
+
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
16
|
+
this.overrideKey = key;
|
|
17
|
+
}
|
|
18
|
+
getAddress() {
|
|
19
|
+
const _super = Object.create(null, {
|
|
20
|
+
getAddress: { get: () => super.getAddress }
|
|
21
|
+
});
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a;
|
|
24
|
+
if (this.isInstalledOnBrowser()) {
|
|
25
|
+
return _super.getAddress.call(this);
|
|
26
|
+
}
|
|
27
|
+
const inAppBrowserBase = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl;
|
|
28
|
+
if (!inAppBrowserBase) {
|
|
29
|
+
const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
|
|
30
|
+
logger.error(error.message);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
window.location.href = `${inAppBrowserBase}/${window.location.href}`;
|
|
34
|
+
return undefined;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { getConnectorConstructorInjectedWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getConnectorConstructorInjectedWallet } from './getConnectorConstructorInjectedWallet';
|
|
@@ -10,7 +10,6 @@ var viem = require('viem');
|
|
|
10
10
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
11
11
|
var utils = require('@dynamic-labs/utils');
|
|
12
12
|
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
13
|
-
var parseIntSafe = require('../utils/parseIntSafe.cjs');
|
|
14
13
|
|
|
15
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
15
|
|
|
@@ -43,7 +42,7 @@ class WalletConnect extends ethereumCore.EthereumWalletConnector {
|
|
|
43
42
|
(_a = Boolean(localStorage.getItem(this.swicthedNetworkKey))) !== null && _a !== void 0 ? _a : false;
|
|
44
43
|
const lsCurrentChain = localStorage.getItem(this.currentChainKey);
|
|
45
44
|
this.currentChainId = lsCurrentChain
|
|
46
|
-
?
|
|
45
|
+
? utils.parseIntSafe(lsCurrentChain)
|
|
47
46
|
: undefined;
|
|
48
47
|
}
|
|
49
48
|
getMappedChains() {
|
|
@@ -196,7 +195,7 @@ class WalletConnect extends ethereumCore.EthereumWalletConnector {
|
|
|
196
195
|
}
|
|
197
196
|
const { name, data } = params.event;
|
|
198
197
|
if (name === 'chainChanged') {
|
|
199
|
-
const chainId =
|
|
198
|
+
const chainId = utils.parseIntSafe(data);
|
|
200
199
|
if (chainId === this.currentChainId) {
|
|
201
200
|
walletConnectorCore.logger.debug(`ignoring chainChanged event with same chain id as current chain id: ${chainId}`);
|
|
202
201
|
return;
|
|
@@ -4,9 +4,8 @@ import EthereumProvider from '@walletconnect/ethereum-provider';
|
|
|
4
4
|
import EventEmitter from 'eventemitter3';
|
|
5
5
|
import { createWalletClient, custom } from 'viem';
|
|
6
6
|
import { logger, performPlatformSpecificConnectionMethod, getDeepLink } from '@dynamic-labs/wallet-connector-core';
|
|
7
|
-
import { DynamicError, sleep, isMobile } from '@dynamic-labs/utils';
|
|
7
|
+
import { parseIntSafe, DynamicError, sleep, isMobile } from '@dynamic-labs/utils';
|
|
8
8
|
import { EthereumWalletConnector, chainsMap } from '@dynamic-labs/ethereum-core';
|
|
9
|
-
import { parseIntSafe } from '../utils/parseIntSafe.js';
|
|
10
9
|
|
|
11
10
|
const activeAccountKey = (walletName) => `dynamic-wc2-active-account-${walletName}`;
|
|
12
11
|
const sessionTopicKey = (walletName) => `dynamic-wc2-session-topic-${walletName}`;
|
package/src/utils/isString.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isString: (value: unknown) => value is string;
|
package/src/utils/last.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const last: <T = unknown>(array: T[]) => T | undefined;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
7
|
-
|
|
8
|
-
const parseIntSafe = (value, radix = 10) => {
|
|
9
|
-
try {
|
|
10
|
-
const int = parseInt(String(value), radix);
|
|
11
|
-
if (isNaN(int)) {
|
|
12
|
-
walletConnectorCore.logger.error(`Error parsing ${value}`);
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
return int;
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
walletConnectorCore.logger.error(`Error parsing ${value} to int: ${e}`);
|
|
19
|
-
}
|
|
20
|
-
return undefined;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
exports.parseIntSafe = parseIntSafe;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const parseIntSafe: (value: string | number, radix?: number) => number | undefined;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
|
|
4
|
-
const parseIntSafe = (value, radix = 10) => {
|
|
5
|
-
try {
|
|
6
|
-
const int = parseInt(String(value), radix);
|
|
7
|
-
if (isNaN(int)) {
|
|
8
|
-
logger.error(`Error parsing ${value}`);
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
return int;
|
|
12
|
-
}
|
|
13
|
-
catch (e) {
|
|
14
|
-
logger.error(`Error parsing ${value} to int: ${e}`);
|
|
15
|
-
}
|
|
16
|
-
return undefined;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { parseIntSafe };
|