2023-12-12 12:53:20 +00:00
|
|
|
import { useFeatureFlags } from '@vegaprotocol/environment';
|
|
|
|
import { useMemo } from 'react';
|
2023-01-19 11:16:21 +00:00
|
|
|
import {
|
|
|
|
JsonRpcConnector,
|
|
|
|
ViewConnector,
|
2023-07-12 10:34:42 +00:00
|
|
|
InjectedConnector,
|
2023-08-29 01:51:58 +00:00
|
|
|
SnapConnector,
|
|
|
|
DEFAULT_SNAP_ID,
|
2023-01-19 11:16:21 +00:00
|
|
|
} from '@vegaprotocol/wallet';
|
2022-02-22 23:06:35 +00:00
|
|
|
|
2022-10-03 18:12:34 +00:00
|
|
|
export const jsonRpc = new JsonRpcConnector();
|
2023-07-12 10:34:42 +00:00
|
|
|
export const injected = new InjectedConnector();
|
2022-02-23 05:39:12 +00:00
|
|
|
|
2023-01-19 11:16:21 +00:00
|
|
|
let view: ViewConnector;
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
const urlParams = new URLSearchParams(window.location.hash.split('?')[1]);
|
|
|
|
view = new ViewConnector(urlParams.get('address'));
|
|
|
|
} else {
|
|
|
|
view = new ViewConnector();
|
|
|
|
}
|
|
|
|
|
2023-12-12 12:53:20 +00:00
|
|
|
export const snap = new SnapConnector(DEFAULT_SNAP_ID);
|
2023-08-29 01:51:58 +00:00
|
|
|
|
2023-12-12 12:53:20 +00:00
|
|
|
export const useConnectors = () => {
|
|
|
|
const featureFlags = useFeatureFlags((state) => state.flags);
|
|
|
|
return useMemo(
|
|
|
|
() => ({
|
|
|
|
injected,
|
|
|
|
jsonRpc,
|
|
|
|
view,
|
|
|
|
snap: featureFlags.METAMASK_SNAPS ? snap : undefined,
|
|
|
|
}),
|
|
|
|
[featureFlags.METAMASK_SNAPS]
|
|
|
|
);
|
2022-02-22 23:06:35 +00:00
|
|
|
};
|