@dynamic-labs/wagmi-connector 0.19.0-alpha.14 → 0.19.0-alpha.16
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 +25 -0
- package/package.json +3 -4
- package/src/lib/Connector.js +1 -1
- package/src/lib/DynamicWagmiConnector.js +23 -15
- package/src/lib/SyncDynamicWagmi.d.ts +3 -1
- package/src/lib/SyncDynamicWagmi.js +24 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
|
|
2
|
+
## [0.19.0-alpha.16](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.15...v0.19.0-alpha.16) (2023-10-17)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### ⚠ BREAKING CHANGES
|
|
6
|
+
|
|
7
|
+
* ethers extension integration and rename provider methods (#3573)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add onDisconnect ([#3572](https://github.com/dynamic-labs/DynamicAuth/issues/3572)) ([3e612f7](https://github.com/dynamic-labs/DynamicAuth/commit/3e612f72540781b9246a47ac12a7c979fb6c0d88))
|
|
12
|
+
* user callback on passkey creation complete ([#3591](https://github.com/dynamic-labs/DynamicAuth/issues/3591)) ([92d5f7d](https://github.com/dynamic-labs/DynamicAuth/commit/92d5f7df2ac1cc06338f7e9e75125f7bb71455ab))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* argentX in-browser wallet ([#3588](https://github.com/dynamic-labs/DynamicAuth/issues/3588)) ([7f3b22d](https://github.com/dynamic-labs/DynamicAuth/commit/7f3b22d003182aa0d84406086a313fc4de25e4a8))
|
|
18
|
+
* display a better message when transaction amount decimals are invalid ([#3577](https://github.com/dynamic-labs/DynamicAuth/issues/3577)) ([0238d9b](https://github.com/dynamic-labs/DynamicAuth/commit/0238d9b7712d6a52aec89193c751224dd8fd8b17))
|
|
19
|
+
* remove passkey success view ([#3536](https://github.com/dynamic-labs/DynamicAuth/issues/3536)) ([b559de9](https://github.com/dynamic-labs/DynamicAuth/commit/b559de9c83096ed98e9f073b998ac08f876af24e))
|
|
20
|
+
* **wagmi-connector:** use wallets list to sync wagmi client ([#3563](https://github.com/dynamic-labs/DynamicAuth/issues/3563)) ([1d551b9](https://github.com/dynamic-labs/DynamicAuth/commit/1d551b933aefe0c535285d68c2e6f819cd321e62))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
* ethers extension integration and rename provider methods ([#3573](https://github.com/dynamic-labs/DynamicAuth/issues/3573)) ([efd73c3](https://github.com/dynamic-labs/DynamicAuth/commit/efd73c3b8121df9a7d4ec8c1fb6c4fd76ecce6df))
|
|
24
|
+
|
|
25
|
+
## [0.19.0-alpha.15](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.14...v0.19.0-alpha.15) (2023-10-11)
|
|
26
|
+
|
|
2
27
|
## [0.19.0-alpha.14](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.13...v0.19.0-alpha.14) (2023-10-10)
|
|
3
28
|
|
|
4
29
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/wagmi-connector",
|
|
3
|
-
"version": "0.19.0-alpha.
|
|
3
|
+
"version": "0.19.0-alpha.16",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -11,9 +11,8 @@
|
|
|
11
11
|
"react": "^17.0.2 || ^18.0.0",
|
|
12
12
|
"viem": "^1.1.0",
|
|
13
13
|
"wagmi": "^1.2.0",
|
|
14
|
-
"@dynamic-labs/sdk-react-core": "0.19.0-alpha.
|
|
15
|
-
"@dynamic-labs/types": "0.19.0-alpha.
|
|
16
|
-
"eventemitter3": "5.0.1"
|
|
14
|
+
"@dynamic-labs/sdk-react-core": "0.19.0-alpha.16",
|
|
15
|
+
"@dynamic-labs/types": "0.19.0-alpha.16"
|
|
17
16
|
},
|
|
18
17
|
"license": "MIT",
|
|
19
18
|
"main": "./src/index.cjs",
|
package/src/lib/Connector.js
CHANGED
|
@@ -90,7 +90,7 @@ class Connector extends Connector$1 {
|
|
|
90
90
|
getProvider(config) {
|
|
91
91
|
var _a;
|
|
92
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
return (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.
|
|
93
|
+
return (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getWalletClient();
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
getWalletClient(config) {
|
|
@@ -8,18 +8,18 @@ import { getWagmiChainsFromDynamicChains } from './getWagmiChainsFromDynamicChai
|
|
|
8
8
|
import { getWagmiProvidersFromDynamicChains } from './getWagmiProvidersFromDynamicChains.js';
|
|
9
9
|
import { getConnector } from './getConnector.js';
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* we create a "default" (static chain and provider) client to use in the WagmiConfig
|
|
13
|
-
* until we've loaded the dynamic chains and providers, at which point we update the client
|
|
14
|
-
*/
|
|
15
|
-
let connector = undefined;
|
|
16
11
|
const { publicClient } = configureChains([mainnet], [publicProvider()]);
|
|
17
12
|
const config = createConfig({
|
|
18
13
|
autoConnect: true,
|
|
19
14
|
publicClient,
|
|
20
15
|
});
|
|
21
16
|
const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, children, }) => {
|
|
22
|
-
const { networkConfigurations, handleLogOut, connectedWallets, linkedWallets,
|
|
17
|
+
const { networkConfigurations, handleLogOut, connectedWallets, linkedWallets, authMode, sendWagmiSettings, } = useDynamicContext();
|
|
18
|
+
/**
|
|
19
|
+
* Linked wallets are only available on connect-and-sign mode and the connected wallets
|
|
20
|
+
* are only available on connect-only mode, the wallet const represents the current available
|
|
21
|
+
* wallets to be used when creating an wagmi connector
|
|
22
|
+
*/
|
|
23
23
|
const wallets = authMode === 'connect-and-sign' ? linkedWallets : connectedWallets;
|
|
24
24
|
useEffect(() => {
|
|
25
25
|
// only send wagmi settings once, when the first time DynamicWagmiConnector renders
|
|
@@ -28,7 +28,7 @@ const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, child
|
|
|
28
28
|
});
|
|
29
29
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
30
|
}, []);
|
|
31
|
-
const chains = useMemo(() => {
|
|
31
|
+
const { chains, publicClient, webSocketPublicClient } = useMemo(() => {
|
|
32
32
|
var _a;
|
|
33
33
|
const evmNetworks = ((_a = customerSuppliedEvmNetworks !== null && customerSuppliedEvmNetworks !== void 0 ? customerSuppliedEvmNetworks : networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.evm) !== null && _a !== void 0 ? _a : []).map((network) => {
|
|
34
34
|
network.chainId = parseInt(network.chainId.toString());
|
|
@@ -36,20 +36,28 @@ const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, child
|
|
|
36
36
|
});
|
|
37
37
|
const mappedChains = getWagmiChainsFromDynamicChains(evmNetworks);
|
|
38
38
|
const mappedProviders = getWagmiProvidersFromDynamicChains(evmNetworks);
|
|
39
|
-
|
|
40
|
-
config.setPublicClient(publicClient);
|
|
41
|
-
config.setWebSocketPublicClient(webSocketPublicClient);
|
|
42
|
-
return chains;
|
|
39
|
+
return configureChains(mappedChains, mappedProviders);
|
|
43
40
|
}, [customerSuppliedEvmNetworks, networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.evm]);
|
|
44
|
-
connector = getConnector(wallets, (wallet) => new Connector({
|
|
41
|
+
const connector = useMemo(() => getConnector(wallets, (wallet) => new Connector({
|
|
45
42
|
chains,
|
|
46
43
|
handleLogOut,
|
|
47
44
|
walletConnector: wallet.connector,
|
|
48
|
-
}));
|
|
49
|
-
|
|
45
|
+
})), [wallets, chains, handleLogOut]);
|
|
46
|
+
/**
|
|
47
|
+
* Updating the wagmi config must be done in a useEffect because
|
|
48
|
+
* when setting the public client and connectors, wagmi will fire
|
|
49
|
+
* an rerender.
|
|
50
|
+
* Keeping the update in a useEffect will prevent an state update
|
|
51
|
+
* while react is in the middle of rendering.
|
|
52
|
+
*/
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
config.setPublicClient(publicClient);
|
|
55
|
+
config.setWebSocketPublicClient(webSocketPublicClient);
|
|
56
|
+
config.setConnectors(connector ? [connector] : []);
|
|
57
|
+
}, [connector, publicClient, webSocketPublicClient]);
|
|
50
58
|
// use React.createElement to prevent bunding react/jsx-runtime,
|
|
51
59
|
// which is not compatible when bundling apps using React 17
|
|
52
|
-
return React.createElement(WagmiConfig, { config: config }, React.createElement(SyncDynamicWagmi, { connector }, children));
|
|
60
|
+
return React.createElement(WagmiConfig, { config: config }, React.createElement(SyncDynamicWagmi, { connector, wallets }, children));
|
|
53
61
|
};
|
|
54
62
|
|
|
55
63
|
export { DynamicWagmiConnector };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { Wallet } from '@dynamic-labs/sdk-react-core';
|
|
2
3
|
import { Connector } from './Connector';
|
|
3
4
|
export type SyncDynamicWagmiProps = React.PropsWithChildren<{
|
|
4
5
|
connector: Connector | undefined;
|
|
6
|
+
wallets: Wallet[];
|
|
5
7
|
}>;
|
|
6
|
-
export declare const SyncDynamicWagmi: ({ children, connector, }: SyncDynamicWagmiProps) => React.FunctionComponentElement<{
|
|
8
|
+
export declare const SyncDynamicWagmi: ({ children, connector, wallets, }: SyncDynamicWagmiProps) => React.FunctionComponentElement<{
|
|
7
9
|
children?: React.ReactNode;
|
|
8
10
|
}>;
|
|
@@ -2,24 +2,34 @@ import React, { useRef, useEffect } from 'react';
|
|
|
2
2
|
import { useConfig, useConnect, useDisconnect } from 'wagmi';
|
|
3
3
|
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
|
|
4
4
|
|
|
5
|
-
const SyncDynamicWagmi = ({ children, connector, }) => {
|
|
5
|
+
const SyncDynamicWagmi = ({ children, connector, wallets, }) => {
|
|
6
6
|
const { status: clientStatus } = useConfig();
|
|
7
7
|
const { connect } = useConnect();
|
|
8
8
|
const { disconnect } = useDisconnect();
|
|
9
|
-
const {
|
|
9
|
+
const { walletConnector } = useDynamicContext();
|
|
10
10
|
const lastConnectedConnectorId = useRef(undefined);
|
|
11
11
|
useEffect(() => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
const isConnected = Boolean(lastConnectedConnectorId.current);
|
|
13
|
+
/**
|
|
14
|
+
* Disconnects from Wagmi when no more wallets are available
|
|
15
|
+
* and returns early to prevent re-connecting to the same connector
|
|
16
|
+
*/
|
|
17
|
+
if (!wallets.length) {
|
|
18
|
+
/**
|
|
19
|
+
* Check if the connector is already disconnected to prevent
|
|
20
|
+
* disconnecting in a page transition on NextJS with multiple
|
|
21
|
+
* layouts
|
|
22
|
+
*/
|
|
23
|
+
if (isConnected) {
|
|
24
|
+
disconnect();
|
|
25
|
+
lastConnectedConnectorId.current = undefined;
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Connects to Wagmi when a connector is available and
|
|
31
|
+
* the connector has changed since the last connection
|
|
32
|
+
*/
|
|
23
33
|
if (walletConnector &&
|
|
24
34
|
connector &&
|
|
25
35
|
(connector === null || connector === void 0 ? void 0 : connector.id) !== lastConnectedConnectorId.current) {
|
|
@@ -33,6 +43,7 @@ const SyncDynamicWagmi = ({ children, connector, }) => {
|
|
|
33
43
|
disconnect,
|
|
34
44
|
lastConnectedConnectorId,
|
|
35
45
|
walletConnector,
|
|
46
|
+
wallets,
|
|
36
47
|
]);
|
|
37
48
|
// use React.createElement to prevent bunding react/jsx-runtime,
|
|
38
49
|
// which is not compatible when bundling apps using React 17
|