2023-09-14 19:10:33 +00:00
|
|
|
import type { Toast } from '@vegaprotocol/ui-toolkit';
|
|
|
|
import { Intent, useToasts } from '@vegaprotocol/ui-toolkit';
|
|
|
|
import { useTelemetryApproval } from '../../lib/hooks/use-telemetry-approval';
|
|
|
|
import { useCallback, useEffect } from 'react';
|
|
|
|
import { TelemetryApproval } from './telemetry-approval';
|
|
|
|
import { useOnboardingStore } from '../welcome-dialog/use-get-onboarding-step';
|
2023-11-16 03:10:39 +00:00
|
|
|
import { useT } from '../../lib/use-t';
|
2023-09-14 19:10:33 +00:00
|
|
|
|
2023-10-17 15:15:38 +00:00
|
|
|
const TELEMETRY_APPROVAL_TOAST_ID = 'telemetry_toast_id';
|
2023-09-14 19:10:33 +00:00
|
|
|
|
|
|
|
export const Telemetry = () => {
|
2023-11-16 03:10:39 +00:00
|
|
|
const t = useT();
|
2023-09-14 19:10:33 +00:00
|
|
|
const onboardingDissmissed = useOnboardingStore((store) => store.dismissed);
|
|
|
|
const [telemetryValue, setTelemetryValue, isTelemetryNeeded, closeTelemetry] =
|
|
|
|
useTelemetryApproval();
|
|
|
|
|
|
|
|
const [setToast, hasToast, removeToast] = useToasts((store) => [
|
|
|
|
store.setToast,
|
|
|
|
store.hasToast,
|
|
|
|
store.remove,
|
|
|
|
]);
|
|
|
|
|
|
|
|
const onApprovalClose = useCallback(() => {
|
|
|
|
closeTelemetry();
|
|
|
|
removeToast(TELEMETRY_APPROVAL_TOAST_ID);
|
|
|
|
}, [closeTelemetry, removeToast]);
|
|
|
|
|
|
|
|
const setTelemetryApprovalAndClose = useCallback(
|
|
|
|
(value: string) => {
|
|
|
|
setTelemetryValue(value);
|
|
|
|
onApprovalClose();
|
|
|
|
},
|
|
|
|
[onApprovalClose, setTelemetryValue]
|
|
|
|
);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isTelemetryNeeded && onboardingDissmissed) {
|
|
|
|
const toast: Toast = {
|
|
|
|
id: TELEMETRY_APPROVAL_TOAST_ID,
|
|
|
|
intent: Intent.Primary,
|
|
|
|
content: (
|
|
|
|
<>
|
|
|
|
<h3 className="mb-1 text-sm uppercase">
|
|
|
|
{t('Improve vega console')}
|
|
|
|
</h3>
|
|
|
|
<TelemetryApproval
|
|
|
|
telemetryValue={telemetryValue}
|
|
|
|
setTelemetryValue={setTelemetryApprovalAndClose}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
onClose: onApprovalClose,
|
|
|
|
};
|
|
|
|
if (!hasToast(TELEMETRY_APPROVAL_TOAST_ID)) {
|
|
|
|
setToast(toast);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
telemetryValue,
|
|
|
|
isTelemetryNeeded,
|
|
|
|
onboardingDissmissed,
|
|
|
|
setToast,
|
|
|
|
hasToast,
|
|
|
|
onApprovalClose,
|
|
|
|
setTelemetryApprovalAndClose,
|
2023-11-16 03:10:39 +00:00
|
|
|
t,
|
2023-09-14 19:10:33 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|