@reef-knot/web3-react 1.0.0 → 1.0.2
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/dist/context/connectors.d.ts +3 -3
- package/dist/context/connectors.d.ts.map +1 -1
- package/dist/context/connectors.js +3 -6
- package/dist/context/web3.d.ts +2 -2
- package/dist/context/web3.d.ts.map +1 -1
- package/dist/context/web3.js +7 -16
- package/dist/hooks/useConnectors.js +0 -1
- package/dist/hooks/useSupportedChains.d.ts.map +1 -1
- package/dist/hooks/useSupportedChains.js +24 -3
- package/dist/hooks/useWeb3.d.ts +2 -2
- package/dist/hooks/useWeb3.d.ts.map +1 -1
- package/dist/hooks/useWeb3.js +23 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { InjectedConnector } from '@web3-react/injected-connector';
|
|
3
3
|
import { WalletLinkConnector } from '@web3-react/walletlink-connector';
|
|
4
4
|
import { SafeAppConnector } from '@gnosis.pm/safe-apps-web3-react';
|
|
@@ -20,7 +20,7 @@ export type ConnectorsContextValue = {
|
|
|
20
20
|
gnosis?: SafeAppConnector;
|
|
21
21
|
};
|
|
22
22
|
export type Connector = keyof ConnectorsContextValue;
|
|
23
|
-
export declare const ConnectorsContext:
|
|
24
|
-
declare const _default:
|
|
23
|
+
export declare const ConnectorsContext: React.Context<ConnectorsContextValue>;
|
|
24
|
+
declare const _default: React.MemoExoticComponent<React.FC<ConnectorsContextProps>>;
|
|
25
25
|
export default _default;
|
|
26
26
|
//# sourceMappingURL=connectors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectors.d.ts","sourceRoot":"","sources":["../../src/context/connectors.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"connectors.d.ts","sourceRoot":"","sources":["../../src/context/connectors.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAK5D,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,UAAU,EAAE,mBAAmB,CAAC;IAChC,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,UAAU,EAAE,sBAAsB,CAAC;IACnC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,sBAAsB,CAAC;AAErD,eAAO,MAAM,iBAAiB,uCAA8C,CAAC;;AA+E7E,wBAAoE"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { memo, createContext, useMemo } from 'react';
|
|
1
|
+
import React, { memo, createContext, useMemo } from 'react';
|
|
3
2
|
import { InjectedConnector } from '@web3-react/injected-connector';
|
|
4
3
|
import { WalletLinkConnector } from '@web3-react/walletlink-connector';
|
|
5
4
|
import { SafeAppConnector } from '@gnosis.pm/safe-apps-web3-react';
|
|
@@ -68,11 +67,9 @@ var ProviderConnectors = props => {
|
|
|
68
67
|
})
|
|
69
68
|
}), [appLogoUrl, appName, rpc, defaultChainId, supportedChainIds]);
|
|
70
69
|
useAutoConnect(connectors);
|
|
71
|
-
return
|
|
70
|
+
return /*#__PURE__*/React.createElement(ConnectorsContext.Provider, {
|
|
72
71
|
value: connectors
|
|
73
|
-
},
|
|
74
|
-
children: children
|
|
75
|
-
}));
|
|
72
|
+
}, children);
|
|
76
73
|
};
|
|
77
74
|
const ProviderConnectors$1 = /*#__PURE__*/memo(ProviderConnectors);
|
|
78
75
|
|
package/dist/context/web3.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { CHAINS } from '@lido-sdk/constants';
|
|
3
3
|
import { SWRConfiguration } from 'swr';
|
|
4
4
|
import { ConnectorsContextProps } from './connectors';
|
|
@@ -9,6 +9,6 @@ export interface ProviderWeb3Props extends ConnectorsContextProps {
|
|
|
9
9
|
pollingInterval?: number;
|
|
10
10
|
onError?: (error: unknown) => void;
|
|
11
11
|
}
|
|
12
|
-
declare const _default:
|
|
12
|
+
declare const _default: React.MemoExoticComponent<React.FC<ProviderWeb3Props>>;
|
|
13
13
|
export default _default;
|
|
14
14
|
//# sourceMappingURL=web3.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web3.d.ts","sourceRoot":"","sources":["../../src/context/web3.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"web3.d.ts","sourceRoot":"","sources":["../../src/context/web3.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAOxC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAI7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAEvC,OAA2B,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE1E,MAAM,WAAW,iBAAkB,SAAQ,sBAAsB;IAC/D,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC;;AAiED,wBAAyD"}
|
package/dist/context/web3.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { __rest } from '../_virtual/_tslib.js';
|
|
2
|
-
import {
|
|
3
|
-
import { memo } from 'react';
|
|
2
|
+
import React, { memo } from 'react';
|
|
4
3
|
import invariant from 'tiny-invariant';
|
|
5
4
|
import { Web3Provider } from '@ethersproject/providers';
|
|
6
5
|
import { CHAINS } from '@lido-sdk/constants';
|
|
@@ -34,16 +33,14 @@ var ProviderSDK = props => {
|
|
|
34
33
|
invariant(rpc[CHAINS.Mainnet], 'RPC url for mainnet is not provided');
|
|
35
34
|
var providerRpc = getStaticRpcBatchProvider(chainId, rpc[chainId], 0, pollingInterval);
|
|
36
35
|
var providerMainnetRpc = getStaticRpcBatchProvider(CHAINS.Mainnet, rpc[CHAINS.Mainnet], 0, pollingInterval);
|
|
37
|
-
return
|
|
36
|
+
return /*#__PURE__*/React.createElement(ProviderSDK$1, Object.assign({
|
|
38
37
|
chainId: chainId,
|
|
39
38
|
supportedChainIds: supportedChainIds,
|
|
40
39
|
providerWeb3: library,
|
|
41
40
|
providerRpc: providerRpc,
|
|
42
41
|
providerMainnetRpc: providerMainnetRpc,
|
|
43
42
|
account: account !== null && account !== void 0 ? account : undefined
|
|
44
|
-
}, rest,
|
|
45
|
-
children: children
|
|
46
|
-
}));
|
|
43
|
+
}, rest), children);
|
|
47
44
|
};
|
|
48
45
|
var ProviderWeb3 = props => {
|
|
49
46
|
var {
|
|
@@ -62,17 +59,11 @@ var ProviderWeb3 = props => {
|
|
|
62
59
|
appLogoUrl,
|
|
63
60
|
defaultChainId
|
|
64
61
|
};
|
|
65
|
-
return
|
|
62
|
+
return /*#__PURE__*/React.createElement(Web3ReactProvider, {
|
|
66
63
|
getLibrary: getLibrary
|
|
67
|
-
}, {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}, sdkProps, {
|
|
71
|
-
children: jsx(ProviderConnectors, Object.assign({}, connectorsProps, {
|
|
72
|
-
children: children
|
|
73
|
-
}))
|
|
74
|
-
}))
|
|
75
|
-
}));
|
|
64
|
+
}, /*#__PURE__*/React.createElement(ProviderSDK, Object.assign({
|
|
65
|
+
rpc: rpc
|
|
66
|
+
}, sdkProps), /*#__PURE__*/React.createElement(ProviderConnectors, Object.assign({}, connectorsProps), children)));
|
|
76
67
|
};
|
|
77
68
|
const web3 = /*#__PURE__*/memo(ProviderWeb3);
|
|
78
69
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSupportedChains.d.ts","sourceRoot":"","sources":["../../src/hooks/useSupportedChains.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,OAAO,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"useSupportedChains.d.ts","sourceRoot":"","sources":["../../src/hooks/useSupportedChains.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAM/D,eAAO,MAAM,kBAAkB;mBACd,OAAO;qBACL,OAAO,EAAE;CAsC3B,CAAC"}
|
|
@@ -1,20 +1,41 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { getNetwork } from '@ethersproject/providers';
|
|
3
|
+
import { useNetwork } from 'wagmi';
|
|
3
4
|
import { useWeb3 } from './useWeb3.js';
|
|
4
5
|
import { UnsupportedChainIdError } from '@web3-react/core';
|
|
5
6
|
|
|
6
7
|
var STABLE_ARRAY = [];
|
|
7
8
|
var useSupportedChains = () => {
|
|
8
|
-
var
|
|
9
|
+
var supportedIds = STABLE_ARRAY;
|
|
10
|
+
var isUnsupported;
|
|
11
|
+
// legacy web3-react data
|
|
9
12
|
var {
|
|
10
13
|
error,
|
|
11
14
|
connector
|
|
12
15
|
} = useWeb3();
|
|
13
|
-
|
|
16
|
+
// wagmi data
|
|
17
|
+
var {
|
|
18
|
+
chain,
|
|
19
|
+
chains
|
|
20
|
+
} = useNetwork();
|
|
21
|
+
var wagmiSupportedChainIds = useMemo(() => chains.map(c => c.id), [chains]);
|
|
22
|
+
// add chain ids from legacy web3-react connector
|
|
23
|
+
if (connector === null || connector === void 0 ? void 0 : connector.supportedChainIds) {
|
|
24
|
+
supportedIds = connector.supportedChainIds;
|
|
25
|
+
}
|
|
26
|
+
// add wagmi chain ids too
|
|
27
|
+
if (wagmiSupportedChainIds.length > 0) {
|
|
28
|
+
supportedIds = [...supportedIds, ...wagmiSupportedChainIds];
|
|
29
|
+
supportedIds = [...new Set(supportedIds)]; // deduplicate ids
|
|
30
|
+
}
|
|
31
|
+
|
|
14
32
|
var supportedChains = useMemo(() => {
|
|
15
33
|
return supportedIds.map(chainId => getNetwork(chainId));
|
|
16
34
|
}, [supportedIds]);
|
|
17
|
-
|
|
35
|
+
// legacy web3-react check
|
|
36
|
+
isUnsupported = error instanceof UnsupportedChainIdError;
|
|
37
|
+
// wagmi check
|
|
38
|
+
isUnsupported = isUnsupported || !!(chain === null || chain === void 0 ? void 0 : chain.unsupported);
|
|
18
39
|
return {
|
|
19
40
|
isUnsupported,
|
|
20
41
|
supportedChains
|
package/dist/hooks/useWeb3.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Web3ReactContextInterface } from '@web3-react/core/dist/types';
|
|
2
2
|
export { UnsupportedChainIdError } from '@web3-react/core';
|
|
3
|
-
export declare
|
|
3
|
+
export declare function useWeb3<T = any>(key?: string): Web3ReactContextInterface<T>;
|
|
4
4
|
//# sourceMappingURL=useWeb3.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWeb3.d.ts","sourceRoot":"","sources":["../../src/hooks/useWeb3.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useWeb3.d.ts","sourceRoot":"","sources":["../../src/hooks/useWeb3.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAGxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAG3D,wBAAgB,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,yBAAyB,CAAC,CAAC,CAAC,CA6B3E"}
|
package/dist/hooks/useWeb3.js
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { useWeb3React } from '@web3-react/core';
|
|
2
2
|
export { UnsupportedChainIdError } from '@web3-react/core';
|
|
3
|
+
import { useAccount, useNetwork, useConnect } from 'wagmi';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
// Shimming useWeb3React hook to also use data returned from wagmi
|
|
6
|
+
function useWeb3(key) {
|
|
7
|
+
var _a;
|
|
8
|
+
var web3ReactData = useWeb3React();
|
|
9
|
+
var wagmiAccount = useAccount();
|
|
10
|
+
var wagmiNetwork = useNetwork();
|
|
11
|
+
var {
|
|
12
|
+
error: wagmiError
|
|
13
|
+
} = useConnect();
|
|
14
|
+
var account = web3ReactData.account || (wagmiAccount === null || wagmiAccount === void 0 ? void 0 : wagmiAccount.address);
|
|
15
|
+
var active = web3ReactData.active || (wagmiAccount === null || wagmiAccount === void 0 ? void 0 : wagmiAccount.isConnected);
|
|
16
|
+
var chainId = web3ReactData.chainId || ((_a = wagmiNetwork === null || wagmiNetwork === void 0 ? void 0 : wagmiNetwork.chain) === null || _a === void 0 ? void 0 : _a.id);
|
|
17
|
+
// wagmi and web3-react use the same Error type
|
|
18
|
+
// wagmi is first here because it can be null, but we need Error | undefined
|
|
19
|
+
var error = wagmiError || web3ReactData.error;
|
|
20
|
+
return Object.assign(Object.assign({}, web3ReactData), {
|
|
21
|
+
chainId,
|
|
22
|
+
account,
|
|
23
|
+
active,
|
|
24
|
+
error
|
|
25
|
+
});
|
|
26
|
+
}
|
|
5
27
|
|
|
6
28
|
export { useWeb3 };
|