@dynamic-labs/wagmi-connector 0.17.0-RC.26 → 0.17.0-RC.28

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 CHANGED
@@ -1,4 +1,29 @@
1
1
 
2
+ ## [0.17.0-RC.28](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.0-RC.27...v0.17.0-RC.28) (2023-06-06)
3
+
4
+
5
+ ### Features
6
+
7
+ * lower username minimum length requirement ([#2265](https://github.com/dynamic-labs/DynamicAuth/issues/2265)) ([ed891ca](https://github.com/dynamic-labs/DynamicAuth/commit/ed891cac8cceaf9e0556b679eda7a3575725805d))
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * **send_balance:** add amount validation to form ([#2261](https://github.com/dynamic-labs/DynamicAuth/issues/2261)) ([9a57cfe](https://github.com/dynamic-labs/DynamicAuth/commit/9a57cfe0dd7f97aa16351b091ab385b2b5c7c5e4))
13
+ * shrink dynamic widget in smaller containers ([#2260](https://github.com/dynamic-labs/DynamicAuth/issues/2260)) ([353f447](https://github.com/dynamic-labs/DynamicAuth/commit/353f44724db83e9f1500c606fdea7d50a8067711))
14
+
15
+ ## [0.17.0-RC.27](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.0-RC.26...v0.17.0-RC.27) (2023-06-06)
16
+
17
+
18
+ ### Features
19
+
20
+ * sync wagmi to first connected eth wallet ([#2253](https://github.com/dynamic-labs/DynamicAuth/issues/2253)) ([c00aed7](https://github.com/dynamic-labs/DynamicAuth/commit/c00aed73a1014c668311c8cb59e5a466b5ee6779))
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * include username in userFieldsSchema ([#2257](https://github.com/dynamic-labs/DynamicAuth/issues/2257)) ([6e5431d](https://github.com/dynamic-labs/DynamicAuth/commit/6e5431d08323d718b11accf3790ef56fc7325b5c))
26
+
2
27
  ## [0.17.0-RC.26](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.0-RC.25...v0.17.0-RC.26) (2023-06-05)
3
28
 
4
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/wagmi-connector",
3
- "version": "0.17.0-RC.26",
3
+ "version": "0.17.0-RC.28",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -11,9 +11,9 @@
11
11
  "react": "^17.0.2 || ^18.0.0",
12
12
  "ethers": "5.7.2",
13
13
  "wagmi": "~0.12.13",
14
- "@dynamic-labs/sdk-react-core": "0.17.0-RC.26",
15
- "@dynamic-labs/types": "0.17.0-RC.26",
16
- "@dynamic-labs/wallet-connector-core": "0.17.0-RC.26"
14
+ "@dynamic-labs/sdk-react-core": "0.17.0-RC.28",
15
+ "@dynamic-labs/types": "0.17.0-RC.28",
16
+ "@dynamic-labs/wallet-connector-core": "0.17.0-RC.28"
17
17
  },
18
18
  "license": "MIT",
19
19
  "main": "./src/index.cjs",
@@ -25,6 +25,7 @@ class Connector extends Connector$1 {
25
25
  this.onDisconnect = () => __awaiter(this, void 0, void 0, function* () { });
26
26
  this.handleLogOut = handleLogOut;
27
27
  this.walletConnector = walletConnector;
28
+ this.id = `dynamic-${walletConnector.key}`;
28
29
  this.setupEventListeners();
29
30
  }
30
31
  setupEventListeners() {
@@ -6,6 +6,7 @@ import { Connector } from './Connector.js';
6
6
  import { SyncDynamicWagmi } from './SyncDynamicWagmi.js';
7
7
  import { getWagmiChainsFromDynamicChains } from './getWagmiChainsFromDynamicChains.js';
8
8
  import { getWagmiProvidersFromDynamicChains } from './getWagmiProvidersFromDynamicChains.js';
9
+ import { getConnector } from './getConnector.js';
9
10
 
10
11
  const { provider } = configureChains([mainnet], [publicProvider()]);
11
12
  const client = createClient({
@@ -18,7 +19,7 @@ const client = createClient({
18
19
  let connector = undefined;
19
20
  const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, children, }) => {
20
21
  var _a;
21
- const { networkConfigurations, walletConnector, handleLogOut } = useDynamicContext();
22
+ const { networkConfigurations, handleLogOut, connectedWallets } = useDynamicContext();
22
23
  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) => {
23
24
  network.chainId = parseInt(network.chainId.toString());
24
25
  return network;
@@ -26,16 +27,11 @@ const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, child
26
27
  const mappedChains = getWagmiChainsFromDynamicChains(evmNetworks);
27
28
  const mappedProviders = getWagmiProvidersFromDynamicChains(evmNetworks);
28
29
  const { chains, provider } = configureChains(mappedChains, mappedProviders);
29
- if (!connector && (walletConnector === null || walletConnector === void 0 ? void 0 : walletConnector.connectedChain) === 'EVM') {
30
- connector = new Connector({
31
- chains,
32
- handleLogOut,
33
- walletConnector,
34
- });
35
- }
36
- else if (connector && !walletConnector) {
37
- connector = undefined;
38
- }
30
+ connector = getConnector(connectedWallets, (wallet) => new Connector({
31
+ chains,
32
+ handleLogOut,
33
+ walletConnector: wallet.connector,
34
+ }));
39
35
  client.config = Object.assign(Object.assign({}, client.config), { autoConnect: true, connectors: connector ? [connector] : [], provider: provider });
40
36
  // use React.createElement to prevent bunding react/jsx-runtime,
41
37
  // which is not compatible when bundling apps using React 17
@@ -0,0 +1,3 @@
1
+ import { Wallet } from '@dynamic-labs/sdk-react-core';
2
+ import { Connector } from './Connector';
3
+ export declare const getConnector: (wallets: Wallet[], createConnector: (wallet: Wallet) => Connector) => Connector | undefined;
@@ -0,0 +1,9 @@
1
+ const getConnector = (wallets, createConnector) => {
2
+ for (const wallet of wallets) {
3
+ if (wallet.connected && wallet.connector.connectedChain === 'EVM') {
4
+ return createConnector(wallet);
5
+ }
6
+ }
7
+ };
8
+
9
+ export { getConnector };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This is used to track a previous value of a variable.
3
+ *
4
+ * Example:
5
+ * const someHook = ({ value }) => {
6
+ * const previousValue = usePrevious(value);
7
+ * useEffect(() => {
8
+ * if (previousValue !== value) {
9
+ * // do something
10
+ * }
11
+ * }, [value, previousValue]);
12
+ * }
13
+ *
14
+ * When someHook is rendered for the first time with value = true, previousValue will be undefined
15
+ * so the condition will be true and the effect will run. When someHook is rendered again with
16
+ * value = true, previousValue will have been set to true so the condition will be false and the
17
+ * effect will not run.
18
+ */
19
+ export declare const usePrevious: <T>(value: T) => T | undefined;
@@ -0,0 +1,29 @@
1
+ import { useRef, useEffect } from 'react';
2
+
3
+ /**
4
+ * This is used to track a previous value of a variable.
5
+ *
6
+ * Example:
7
+ * const someHook = ({ value }) => {
8
+ * const previousValue = usePrevious(value);
9
+ * useEffect(() => {
10
+ * if (previousValue !== value) {
11
+ * // do something
12
+ * }
13
+ * }, [value, previousValue]);
14
+ * }
15
+ *
16
+ * When someHook is rendered for the first time with value = true, previousValue will be undefined
17
+ * so the condition will be true and the effect will run. When someHook is rendered again with
18
+ * value = true, previousValue will have been set to true so the condition will be false and the
19
+ * effect will not run.
20
+ */
21
+ const usePrevious = (value) => {
22
+ const ref = useRef();
23
+ useEffect(() => {
24
+ ref.current = value;
25
+ }, [value]);
26
+ return ref.current;
27
+ };
28
+
29
+ export { usePrevious };
@@ -1,15 +1,17 @@
1
1
  import { useEffect } from 'react';
2
2
  import { useWalletConnectorEverPresent } from '../useWalletConnectorEverPresent/useWalletConnectorEverPresent.js';
3
+ import { usePrevious } from './usePrevious.js';
3
4
 
4
5
  const useSyncConnectState = ({ walletConnector, disconnect, clientStatus, connect, connector, }) => {
5
6
  const wasWalletConnectEverPresent = useWalletConnectorEverPresent(walletConnector);
7
+ const prevConnectorId = usePrevious(connector === null || connector === void 0 ? void 0 : connector.id);
6
8
  useEffect(() => {
7
9
  if (!walletConnector) {
8
10
  if (wasWalletConnectEverPresent) {
9
11
  disconnect();
10
12
  }
11
13
  }
12
- else if (connector && clientStatus !== 'connected') {
14
+ else if ((connector === null || connector === void 0 ? void 0 : connector.id) !== prevConnectorId) {
13
15
  connect({ connector });
14
16
  }
15
17
  }, [
@@ -17,6 +19,7 @@ const useSyncConnectState = ({ walletConnector, disconnect, clientStatus, connec
17
19
  connect,
18
20
  connector,
19
21
  disconnect,
22
+ prevConnectorId,
20
23
  walletConnector,
21
24
  wasWalletConnectEverPresent,
22
25
  ]);