2023-10-16 14:49:23 +00:00
|
|
|
import { useSearchParams } from 'react-router-dom';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { useEnvironment } from '@vegaprotocol/environment';
|
|
|
|
import { useEagerConnect as useEthereumEagerConnect } from '@vegaprotocol/web3';
|
|
|
|
import {
|
|
|
|
useEagerConnect as useVegaEagerConnect,
|
|
|
|
useVegaWallet,
|
|
|
|
} from '@vegaprotocol/wallet';
|
|
|
|
import { useGlobalStore } from '../stores';
|
2023-12-12 12:53:20 +00:00
|
|
|
import { useConnectors } from '../lib/vega-connectors';
|
2023-10-16 14:49:23 +00:00
|
|
|
import { useTelemetryApproval } from '../lib/hooks/use-telemetry-approval';
|
|
|
|
|
|
|
|
export const MaybeConnectEagerly = () => {
|
|
|
|
const { VEGA_ENV, SENTRY_DSN } = useEnvironment();
|
|
|
|
const update = useGlobalStore((store) => store.update);
|
2023-12-12 12:53:20 +00:00
|
|
|
const connectors = useConnectors();
|
|
|
|
const eagerConnecting = useVegaEagerConnect(connectors);
|
2023-10-16 14:49:23 +00:00
|
|
|
const [isTelemetryApproved] = useTelemetryApproval();
|
|
|
|
useEthereumEagerConnect(
|
|
|
|
isTelemetryApproved ? { dsn: SENTRY_DSN, env: VEGA_ENV } : {}
|
|
|
|
);
|
|
|
|
|
|
|
|
const { pubKey, connect } = useVegaWallet();
|
|
|
|
const [searchParams] = useSearchParams();
|
|
|
|
const [query] = useState(searchParams.get('address'));
|
|
|
|
if (query && !pubKey) {
|
2023-12-12 12:53:20 +00:00
|
|
|
connect(connectors.view);
|
2023-10-16 14:49:23 +00:00
|
|
|
}
|
|
|
|
useEffect(() => {
|
|
|
|
update({ eagerConnecting });
|
|
|
|
}, [update, eagerConnecting]);
|
|
|
|
return null;
|
|
|
|
};
|