@dynamic-labs/wagmi-connector 0.18.7 → 0.18.8
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,12 @@
|
|
|
1
1
|
|
|
2
|
+
### [0.18.8](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.7...v0.18.8) (2023-08-24)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* allow overriding contracts on wagmi chains ([#3107](https://github.com/dynamic-labs/DynamicAuth/issues/3107)) ([d078532](https://github.com/dynamic-labs/DynamicAuth/commit/d078532432415fc26402b9a5405059078be811eb))
|
|
8
|
+
* send wagmi settings only once when DynamicWagmiConnector loads (v18) ([#3108](https://github.com/dynamic-labs/DynamicAuth/issues/3108)) ([d25de8f](https://github.com/dynamic-labs/DynamicAuth/commit/d25de8f8a4ee7be6e89cb74881ea390ef72e578f)), closes [#3103](https://github.com/dynamic-labs/DynamicAuth/issues/3103)
|
|
9
|
+
|
|
2
10
|
### [0.18.7](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.6...v0.18.7) (2023-08-23)
|
|
3
11
|
|
|
4
12
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/wagmi-connector",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.8",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -11,8 +11,8 @@
|
|
|
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.18.
|
|
15
|
-
"@dynamic-labs/types": "0.18.
|
|
14
|
+
"@dynamic-labs/sdk-react-core": "0.18.8",
|
|
15
|
+
"@dynamic-labs/types": "0.18.8",
|
|
16
16
|
"eventemitter3": "5.0.1"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import { configureChains, mainnet, createClient, WagmiConfig } from 'wagmi';
|
|
3
3
|
import { publicProvider } from 'wagmi/providers/public';
|
|
4
4
|
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
|
|
@@ -21,9 +21,13 @@ const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, child
|
|
|
21
21
|
var _a;
|
|
22
22
|
const { networkConfigurations, handleLogOut, connectedWallets, linkedWallets, authMode, sendWagmiSettings, } = useDynamicContext();
|
|
23
23
|
const wallets = authMode === 'connect-only' ? connectedWallets : linkedWallets;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
// only send wagmi settings once, when the first time DynamicWagmiConnector renders
|
|
26
|
+
sendWagmiSettings({
|
|
27
|
+
dynamicWagmiSettings: customerSuppliedEvmNetworks,
|
|
28
|
+
});
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
}, []);
|
|
27
31
|
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) => {
|
|
28
32
|
network.chainId = parseInt(network.chainId.toString());
|
|
29
33
|
return network;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Chain } from 'wagmi';
|
|
2
2
|
import { WagmiEvmNetworks } from '../types';
|
|
3
3
|
export declare const mapDynamicChainToWagmi: (dynamicChain: WagmiEvmNetworks) => Chain;
|
|
4
|
+
export declare const overrideWagmiChainWithDynamicSettings: (wagmiChain: Chain, dynamicChain: WagmiEvmNetworks) => Chain;
|
package/src/lib/mappers/chain.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as allChains from 'wagmi/chains';
|
|
|
2
2
|
import { resolveRpcUrlFromEvmNetworks } from '../utils/resolveRpcUrlFromEvmNetworks/resolveRpcUrlFromEvmNetworks.js';
|
|
3
3
|
|
|
4
4
|
// eslint-disable-next-line import/no-namespace
|
|
5
|
-
const
|
|
5
|
+
const updateRpcProvider = (rpcUrls, privateCustomerRpcUrls, name) => {
|
|
6
6
|
const findRpcUrl = privateCustomerRpcUrls === null || privateCustomerRpcUrls === void 0 ? void 0 : privateCustomerRpcUrls.find((rpcUrl) => {
|
|
7
7
|
if (typeof rpcUrl === 'string') {
|
|
8
8
|
return rpcUrl.includes(name);
|
|
@@ -22,7 +22,14 @@ const findRpcProvider = (rpcUrls, privateCustomerRpcUrls, name) => {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
const mapDynamicChainToWagmi = (dynamicChain) => {
|
|
25
|
-
var _a
|
|
25
|
+
var _a;
|
|
26
|
+
/**
|
|
27
|
+
* Find the chain in Wagmi that matches the chainId of the dynamic chain.
|
|
28
|
+
*/
|
|
29
|
+
const wagmiChain = ((_a = Object.values(allChains).find((chain) => chain.id === dynamicChain.chainId)) !== null && _a !== void 0 ? _a : {});
|
|
30
|
+
return overrideWagmiChainWithDynamicSettings(wagmiChain, dynamicChain);
|
|
31
|
+
};
|
|
32
|
+
const generateRpcUrls = (dynamicChain) => {
|
|
26
33
|
const rpcUrlResolved = resolveRpcUrlFromEvmNetworks(dynamicChain);
|
|
27
34
|
const rpcUrls = {
|
|
28
35
|
default: {
|
|
@@ -33,12 +40,12 @@ const mapDynamicChainToWagmi = (dynamicChain) => {
|
|
|
33
40
|
},
|
|
34
41
|
};
|
|
35
42
|
const rpcUrlProviders = ['alchemy', 'infura'];
|
|
36
|
-
rpcUrlProviders.forEach((name) =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return Object.assign(Object.assign({}, wagmiChain), { blockExplorers: Object.assign(Object.assign({}, wagmiChain === null || wagmiChain === void 0 ? void 0 : wagmiChain.blockExplorers), { default: Object.assign(Object.assign({}, (
|
|
43
|
+
rpcUrlProviders.forEach((name) => updateRpcProvider(rpcUrls, dynamicChain.privateCustomerRpcUrls, name));
|
|
44
|
+
return rpcUrls;
|
|
45
|
+
};
|
|
46
|
+
const overrideWagmiChainWithDynamicSettings = (wagmiChain, dynamicChain) => {
|
|
47
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
48
|
+
return (Object.assign(Object.assign({}, wagmiChain), { blockExplorers: Object.assign(Object.assign({}, wagmiChain === null || wagmiChain === void 0 ? void 0 : wagmiChain.blockExplorers), { default: Object.assign(Object.assign({}, (_a = wagmiChain.blockExplorers) === null || _a === void 0 ? void 0 : _a.default), { name: '', url: (_c = (_b = dynamicChain.blockExplorerUrls) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : '' }) }), contracts: (_d = dynamicChain.contracts) !== null && _d !== void 0 ? _d : wagmiChain.contracts, id: (_e = dynamicChain.chainId) !== null && _e !== void 0 ? _e : wagmiChain.id, name: (_g = (_f = dynamicChain.vanityName) !== null && _f !== void 0 ? _f : dynamicChain.name) !== null && _g !== void 0 ? _g : wagmiChain.name, nativeCurrency: (_h = dynamicChain.nativeCurrency) !== null && _h !== void 0 ? _h : wagmiChain.nativeCurrency, network: (_j = dynamicChain.name) !== null && _j !== void 0 ? _j : wagmiChain.network, rpcUrls: generateRpcUrls(dynamicChain) }));
|
|
42
49
|
};
|
|
43
50
|
|
|
44
|
-
export { mapDynamicChainToWagmi };
|
|
51
|
+
export { mapDynamicChainToWagmi, overrideWagmiChainWithDynamicSettings };
|
package/src/lib/types.d.ts
CHANGED
|
@@ -21,5 +21,8 @@ type CustomProviderOptions = {
|
|
|
21
21
|
};
|
|
22
22
|
export type WagmiEvmNetworks = Omit<PartialBy<EvmNetwork, 'iconUrls' | 'networkId' | 'vanityName'>, 'privateCustomerRpcUrls'> & {
|
|
23
23
|
privateCustomerRpcUrls: (string | CustomProviderOptions)[];
|
|
24
|
+
contracts?: {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
};
|
|
24
27
|
};
|
|
25
28
|
export {};
|