@reef-knot/core-react 1.2.0 → 1.3.1

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.
@@ -0,0 +1,13 @@
1
+ import React, { FC } from 'react';
2
+ import { WalletAdapterData } from '@reef-knot/types';
3
+ export interface ReefKnotContextProps {
4
+ rpc: Record<number, string>;
5
+ walletconnectProjectId?: string;
6
+ }
7
+ export type ReefKnotContextValue = {
8
+ rpc: Record<number, string>;
9
+ walletDataList: WalletAdapterData[];
10
+ };
11
+ export declare const ReefKnotContext: React.Context<ReefKnotContextValue>;
12
+ export declare const ReefKnot: FC<ReefKnotContextProps>;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,EAAE,EAAW,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,cAAc,EAAE,iBAAiB,EAAE,CAAC;CACrC,CAAC;AAEF,eAAO,MAAM,eAAe,qCAA4C,CAAC;AAEzE,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,oBAAoB,CAiB7C,CAAC"}
@@ -0,0 +1,23 @@
1
+ import React, { createContext, useMemo } from 'react';
2
+ import { getWalletDataList } from '../walletData/index.js';
3
+
4
+ const ReefKnotContext = createContext({});
5
+ const ReefKnot = ({
6
+ rpc,
7
+ walletconnectProjectId,
8
+ children
9
+ }) => {
10
+ const walletDataList = getWalletDataList({
11
+ rpc,
12
+ walletconnectProjectId
13
+ });
14
+ const contextValue = useMemo(() => ({
15
+ rpc,
16
+ walletDataList
17
+ }), [rpc, walletDataList]);
18
+ return React.createElement(ReefKnotContext.Provider, {
19
+ value: contextValue
20
+ }, children);
21
+ };
22
+
23
+ export { ReefKnot, ReefKnotContext };
@@ -0,0 +1,2 @@
1
+ export * from './useReefKnotContext';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ReefKnotContextValue } from '../context';
2
+ export declare const useReefKnotContext: () => ReefKnotContextValue;
3
+ //# sourceMappingURL=useReefKnotContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useReefKnotContext.d.ts","sourceRoot":"","sources":["../../src/hooks/useReefKnotContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEnE,eAAO,MAAM,kBAAkB,QAAO,oBACT,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { useContext } from 'react';
2
+ import { ReefKnotContext } from '../context/index.js';
3
+
4
+ const useReefKnotContext = () => useContext(ReefKnotContext);
5
+
6
+ export { useReefKnotContext };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './walletData';
2
- export * from './utils';
2
+ export * from './context';
3
+ export * from './hooks';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { getConnectors, walletAdapters, walletDataList } from './walletData/index.js';
2
- export { isValidHttpUrl } from './utils/isValidHttpUrl.js';
3
- export { createConnectorsWalletConnect } from './walletData/connectorsWalletConnect.js';
1
+ export { getConnectors, getWalletDataList } from './walletData/index.js';
2
+ export { ReefKnot, ReefKnotContext } from './context/index.js';
3
+ export { useReefKnotContext } from './hooks/useReefKnotContext.js';
@@ -1,8 +1,8 @@
1
- import { Connector } from 'wagmi';
2
- export * from './connectorsWalletConnect';
3
- export declare const walletAdapters: import("@reef-knot/types").WalletAdapterType[];
4
- export declare const walletDataList: import("@reef-knot/types").WalletAdapterData[];
5
- export declare const getConnectors: ({ rpc }: {
1
+ import { WalletAdapterData } from '@reef-knot/types';
2
+ export interface GetConnectorsArgs {
6
3
  rpc: Record<number, string>;
7
- }) => Connector<any, any, any>[];
4
+ walletconnectProjectId?: string;
5
+ }
6
+ export declare const getWalletDataList: ({ rpc, walletconnectProjectId, }: GetConnectorsArgs) => WalletAdapterData[];
7
+ export declare const getConnectors: (args: GetConnectorsArgs) => import("@wagmi/connectors/dist/base-84a689bb").C<any, any, any>[];
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/walletData/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIlC,cAAc,2BAA2B,CAAC;AAE1C,eAAO,MAAM,cAAc,gDAAqC,CAAC;AACjE,eAAO,MAAM,cAAc,gDAE1B,CAAC;AAEF,eAAO,MAAM,aAAa;SAAoB,OAAO,MAAM,EAAE,MAAM,CAAC;gCAOnE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/walletData/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIrD,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,eAAO,MAAM,iBAAiB,qCAG3B,iBAAiB,wBAQnB,CAAC;AAEF,eAAO,MAAM,aAAa,SAAU,iBAAiB,sEAEpD,CAAC"}
@@ -1,16 +1,23 @@
1
1
  import { WalletsListEthereum } from '@reef-knot/wallets-list';
2
- import { createConnectorsWalletConnect } from './connectorsWalletConnect.js';
3
2
 
4
- const walletAdapters = Object.values(WalletsListEthereum);
5
- const walletDataList = walletAdapters.map(walletAdapter => walletAdapter());
6
- const getConnectors = ({
7
- rpc
3
+ let walletDataList;
4
+ const getWalletDataList = ({
5
+ rpc,
6
+ walletconnectProjectId
8
7
  }) => {
9
- const connectors = [...walletDataList].map(walletData => walletData.connector);
10
- const connectorsWC = createConnectorsWalletConnect({
11
- rpc
12
- });
13
- return [...connectorsWC, ...connectors];
8
+ const walletAdapters = Object.values(WalletsListEthereum);
9
+ if (!walletDataList) {
10
+ walletDataList = walletAdapters.map(walletAdapter => walletAdapter({
11
+ rpc,
12
+ walletconnectProjectId
13
+ }));
14
+ }
15
+ return walletDataList;
16
+ };
17
+ const getConnectors = args => {
18
+ return getWalletDataList(args).map(({
19
+ connector
20
+ }) => connector);
14
21
  };
15
22
 
16
- export { createConnectorsWalletConnect, getConnectors, walletAdapters, walletDataList };
23
+ export { getConnectors, getWalletDataList };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reef-knot/core-react",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -38,12 +38,14 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "react": "17.0.2",
41
- "wagmi": "^0.11.7",
42
- "@reef-knot/wallets-list": "^1.2.0"
41
+ "wagmi": "^0.12.12",
42
+ "@reef-knot/wallets-list": "^1.3.1",
43
+ "@reef-knot/types": "^1.1.1"
43
44
  },
44
45
  "peerDependencies": {
45
46
  "react": ">=17",
46
- "wagmi": "^0.11.7",
47
- "@reef-knot/wallets-list": "^1.2.0"
47
+ "wagmi": "^0.12.12",
48
+ "@reef-knot/wallets-list": "^1.3.1",
49
+ "@reef-knot/types": "^1.1.1"
48
50
  }
49
51
  }
@@ -1,2 +0,0 @@
1
- export * from './isValidHttpUrl';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const isValidHttpUrl: (string: string) => boolean;
2
- //# sourceMappingURL=isValidHttpUrl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isValidHttpUrl.d.ts","sourceRoot":"","sources":["../../src/utils/isValidHttpUrl.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,WAAY,MAAM,YAQ5C,CAAC"}
@@ -1,11 +0,0 @@
1
- const isValidHttpUrl = string => {
2
- let url;
3
- try {
4
- url = new URL(string);
5
- } catch (_) {
6
- return false;
7
- }
8
- return url.protocol === 'http:' || url.protocol === 'https:';
9
- };
10
-
11
- export { isValidHttpUrl };
@@ -1,8 +0,0 @@
1
- import { WalletConnectConnector } from 'wagmi/connectors/walletConnect';
2
- export type RKConnectorWalletConnect = WalletConnectConnector & {
3
- _reefknot_id: string;
4
- };
5
- export declare const createConnectorsWalletConnect: ({ rpc, }: {
6
- rpc: Record<number, string>;
7
- }) => WalletConnectConnector[];
8
- //# sourceMappingURL=connectorsWalletConnect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connectorsWalletConnect.d.ts","sourceRoot":"","sources":["../../src/walletData/connectorsWalletConnect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAOxE,MAAM,MAAM,wBAAwB,GAAG,sBAAsB,GAAG;IAC9D,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,6BAA6B;SAGnC,OAAO,MAAM,EAAE,MAAM,CAAC;8BAoD5B,CAAC"}
@@ -1,48 +0,0 @@
1
- import { WalletConnectConnector } from 'wagmi/connectors/walletConnect';
2
- import { isValidHttpUrl } from '../utils/isValidHttpUrl.js';
3
- import { walletConnectMobileLinks } from './walletConnectMobileLinks.js';
4
-
5
- const createConnectorsWalletConnect = ({
6
- rpc
7
- }) => {
8
- const BASE_URL = typeof window === 'undefined' ? '' : window.location.origin;
9
- // adds BASE_URL to `rpc` object's string values
10
- const walletConnectRPC = Object.entries(rpc).reduce((result, [key, value]) => Object.assign(Object.assign({}, result), {
11
- [key]: isValidHttpUrl(value) ? value : BASE_URL + value
12
- }), {});
13
- const connectors = {
14
- WalletConnect: new WalletConnectConnector({
15
- options: {
16
- rpc: walletConnectRPC,
17
- qrcodeModalOptions: {
18
- mobileLinks: walletConnectMobileLinks,
19
- desktopLinks: []
20
- }
21
- }
22
- }),
23
- WalletConnectNoLinks: new WalletConnectConnector({
24
- options: {
25
- rpc: walletConnectRPC,
26
- qrcodeModalOptions: {
27
- mobileLinks: [],
28
- desktopLinks: []
29
- }
30
- }
31
- }),
32
- WalletConnectURI: new WalletConnectConnector({
33
- options: {
34
- rpc: walletConnectRPC,
35
- qrcode: false
36
- }
37
- })
38
- };
39
- // Temporary solution:
40
- // give connectors different ids, so we can choose between them later
41
- // TODO: rework with custom connector classes extending original connector
42
- connectors.WalletConnect._reefknot_id = 'WalletConnect';
43
- connectors.WalletConnectNoLinks._reefknot_id = 'WalletConnectNoLinks';
44
- connectors.WalletConnectURI._reefknot_id = 'WalletConnectURI';
45
- return Object.values(connectors);
46
- };
47
-
48
- export { createConnectorsWalletConnect };
@@ -1,2 +0,0 @@
1
- export declare const walletConnectMobileLinks: string[];
2
- //# sourceMappingURL=walletConnectMobileLinks.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"walletConnectMobileLinks.d.ts","sourceRoot":"","sources":["../../src/walletData/walletConnectMobileLinks.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,UA4CpC,CAAC"}
@@ -1,3 +0,0 @@
1
- const walletConnectMobileLinks = ['MetaMask', 'Trust Wallet', 'Zerion', 'imToken', 'Robinhood Wallet', 'Rainbow', 'Ledger Live', 'Uniswap Wallet', '1inch Wallet', 'Safe', 'Ambire Wallet', 'Unstoppable Domains', 'Argent', 'Omni', 'MathWallet', 'TokenPocket', 'iToken Wallet', 'Atomic', 'Coin98', 'CoolWallet', 'Unstoppable Wallet', 'Infinity Wallet', 'Crypto.com | DeFi Wallet', 'Guarda Wallet', 'Trustee Wallet', 'Rabby', 'Tangem', 'Coinbase Wallet', 'Frame', 'Blockchain.com', 'Exodus', 'ZenGo', 'XDEFI Wallet', 'Frontier', 'OKX Wallet', 'Brave Wallet', 'Binance DeFi Wallet', 'Fireblocks', 'Phantom', 'MEW wallet', 'GameStop Wallet', 'Opera Crypto Browser', 'Taho'];
2
-
3
- export { walletConnectMobileLinks };