@dynamic-labs/wagmi-connector 0.16.13 → 0.16.14
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 +7 -0
- package/package.json +3 -2
- package/src/lib/SyncDynamicWagmi.js +9 -9
- package/src/lib/hooks/index.d.ts +2 -0
- package/src/lib/hooks/useSyncConnectState/index.d.ts +1 -0
- package/src/lib/hooks/useSyncConnectState/useSyncConnectState.d.ts +11 -0
- package/src/lib/hooks/useSyncConnectState/useSyncConnectState.js +25 -0
- package/src/lib/hooks/useWalletConnectorEverPresent/index.d.ts +1 -0
- package/src/lib/hooks/useWalletConnectorEverPresent/useWalletConnectorEverPresent.d.ts +2 -0
- package/src/lib/hooks/useWalletConnectorEverPresent/useWalletConnectorEverPresent.js +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
|
|
2
|
+
### [0.16.14](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.13...v0.16.14) (2023-05-08)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* **DynamicWagmiConnector:** prevent disconnect when WC is not present… ([#2071](https://github.com/dynamic-labs/DynamicAuth/issues/2071)) ([bb8d023](https://github.com/dynamic-labs/DynamicAuth/commit/bb8d023f097d80c69dcf08282dec3823069e129e)), closes [#2063](https://github.com/dynamic-labs/DynamicAuth/issues/2063) [#2060](https://github.com/dynamic-labs/DynamicAuth/issues/2060)
|
|
8
|
+
|
|
2
9
|
### [0.16.13](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.12...v0.16.13) (2023-05-08)
|
|
3
10
|
|
|
4
11
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/wagmi-connector",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.14",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"react": "^17.0.2 || ^18.0.0",
|
|
12
12
|
"ethers": "^5.7.2",
|
|
13
13
|
"wagmi": "~0.10.3",
|
|
14
|
-
"@dynamic-labs/sdk-react-core": "0.16.
|
|
14
|
+
"@dynamic-labs/sdk-react-core": "0.16.14",
|
|
15
|
+
"@dynamic-labs/wallet-connector-core": "0.16.14"
|
|
15
16
|
},
|
|
16
17
|
"license": "MIT",
|
|
17
18
|
"main": "./src/index.cjs",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { useClient, useConnect, useDisconnect } from 'wagmi';
|
|
3
3
|
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
|
|
4
|
+
import { useSyncConnectState } from './hooks/useSyncConnectState/useSyncConnectState.js';
|
|
4
5
|
|
|
5
6
|
const SyncDynamicWagmi = ({ children, connector, }) => {
|
|
6
7
|
const { status: clientStatus } = useClient();
|
|
@@ -16,14 +17,13 @@ const SyncDynamicWagmi = ({ children, connector, }) => {
|
|
|
16
17
|
}, 100);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}, [clientStatus, connect, connector, disconnect, walletConnector]);
|
|
20
|
+
useSyncConnectState({
|
|
21
|
+
clientStatus,
|
|
22
|
+
connect,
|
|
23
|
+
connector,
|
|
24
|
+
disconnect,
|
|
25
|
+
walletConnector,
|
|
26
|
+
});
|
|
27
27
|
// use React.createElement to prevent bunding react/jsx-runtime,
|
|
28
28
|
// which is not compatible when bundling apps using React 17
|
|
29
29
|
return React.createElement(React.Fragment, null, children);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSyncConnectState } from './useSyncConnectState';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Connector } from 'wagmi';
|
|
2
|
+
import { ConnectArgs } from '@wagmi/core';
|
|
3
|
+
import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
export type SyncConnectStateHookProps = {
|
|
5
|
+
clientStatus: 'connected' | 'connecting' | 'reconnecting' | 'disconnected';
|
|
6
|
+
connect: (args?: Partial<ConnectArgs> | undefined) => void;
|
|
7
|
+
connector: Connector | undefined;
|
|
8
|
+
disconnect: () => void;
|
|
9
|
+
walletConnector: WalletConnector | null;
|
|
10
|
+
};
|
|
11
|
+
export declare const useSyncConnectState: ({ walletConnector, disconnect, clientStatus, connect, connector, }: SyncConnectStateHookProps) => void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useWalletConnectorEverPresent } from '../useWalletConnectorEverPresent/useWalletConnectorEverPresent.js';
|
|
3
|
+
|
|
4
|
+
const useSyncConnectState = ({ walletConnector, disconnect, clientStatus, connect, connector, }) => {
|
|
5
|
+
const wasWalletConnectEverPresent = useWalletConnectorEverPresent(walletConnector);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!walletConnector) {
|
|
8
|
+
if (wasWalletConnectEverPresent) {
|
|
9
|
+
disconnect();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else if (connector && clientStatus !== 'connected') {
|
|
13
|
+
connect({ connector });
|
|
14
|
+
}
|
|
15
|
+
}, [
|
|
16
|
+
clientStatus,
|
|
17
|
+
connect,
|
|
18
|
+
connector,
|
|
19
|
+
disconnect,
|
|
20
|
+
walletConnector,
|
|
21
|
+
wasWalletConnectEverPresent,
|
|
22
|
+
]);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { useSyncConnectState };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useWalletConnectorEverPresent } from './useWalletConnectorEverPresent';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const useWalletConnectorEverPresent = (walletConnector) => {
|
|
4
|
+
const [present, setPresent] = useState(false);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (walletConnector) {
|
|
7
|
+
setPresent(true);
|
|
8
|
+
}
|
|
9
|
+
}, [walletConnector]);
|
|
10
|
+
return present;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { useWalletConnectorEverPresent };
|