Skip to content

Commit

Permalink
feat: add emitter-event for contact support button
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyscode committed Jun 21, 2023
1 parent a3aa30f commit 192140a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
7 changes: 5 additions & 2 deletions packages/widget-playground/src/components/WidgetEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const WidgetEvents = () => {

useEffect(() => {
const onRouteExecutionStarted = (route: Route) => {
// console.log('onRouteExecutionStarted fired.');
console.log('onRouteExecutionStarted fired.');
};
const onRouteExecutionUpdated = (update: RouteExecutionUpdate) => {
// console.log('onRouteExecutionUpdated fired.');
Expand All @@ -25,6 +25,9 @@ export const WidgetEvents = () => {
const onRouteHighValueLoss = (update: RouteHighValueLossUpdate) => {
// console.log('onRouteHighValueLoss continued.');
};
// const onRouteContactSupport = (supportId: RouteContactSupport) => {
// // console.log('onRouteContactSupport clicked', supportId);
// };
widgetEvents.on(WidgetEvent.RouteExecutionStarted, onRouteExecutionStarted);
widgetEvents.on(WidgetEvent.RouteExecutionUpdated, onRouteExecutionUpdated);
widgetEvents.on(
Expand All @@ -33,7 +36,7 @@ export const WidgetEvents = () => {
);
widgetEvents.on(WidgetEvent.RouteHighValueLoss, onRouteHighValueLoss);
widgetEvents.on(WidgetEvent.RouteExecutionFailed, onRouteExecutionFailed);
// widgetEvents.on(WidgetEvent.InputValuesUpdated, onInputValuesUpdated);
// widgetEvents.on(WidgetEvent.RouteContactSupport, onRouteContactSupport);
return () => widgetEvents.all.clear();
}, [widgetEvents]);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Button } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { useWidgetEvents } from '../../hooks/';
import { WidgetEvent } from '../../types/events';

interface ContactSupportButtonProps {
supportId?: string;
}

export const ContactSupportButton = ({
supportId,
}: ContactSupportButtonProps) => {
const { t } = useTranslation();
const widgetEvents = useWidgetEvents();

const handleClick = () => {
if (!widgetEvents.all.has(WidgetEvent.RouteContactSupport)) {
const url = 'https://discord.gg/lifi';
const target = '_blank';
const rel = 'nofollow noreferrer';
window.open(url, target, rel);
} else {
widgetEvents.emit(WidgetEvent.RouteContactSupport, { supportId });
}
};

return (
<Button onClick={handleClick} fullWidth>
{t('button.contactSupport')}
</Button>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useNavigateBack } from '../../hooks';
import { useWidgetConfig } from '../../providers';
import { useRouteExecutionStore } from '../../stores';
import { formatTokenAmount } from '../../utils';
import { ContactSupportButton } from './ContactSupportButton';
import { Container } from './TransactionDetailsPage.style';

export const TransactionDetailsPage: React.FC = () => {
Expand Down Expand Up @@ -143,14 +144,7 @@ export const TransactionDetailsPage: React.FC = () => {
</Typography>
</Card>
<Box mt={2}>
<Button
href="https://discord.gg/lifi"
target="_blank"
rel="nofollow noreferrer"
fullWidth
>
{t('button.contactSupport')}
</Button>
<ContactSupportButton supportId={supportId} />
</Box>
<Dialog open={open} onClose={toggleDialog}>
<DialogTitle>{t('warning.title.deleteTransaction')}</DialogTitle>
Expand Down
6 changes: 6 additions & 0 deletions packages/widget/src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum WidgetEvent {
RouteExecutionCompleted = 'routeExecutionCompleted',
RouteExecutionFailed = 'routeExecutionFailed',
RouteHighValueLoss = 'routeHighValueLoss',
RouteContactSupport = 'routeContactSupport',
}

export type WidgetEvents = {
Expand All @@ -14,8 +15,13 @@ export type WidgetEvents = {
routeExecutionCompleted: Route;
routeExecutionFailed: RouteExecutionUpdate;
routeHighValueLoss: RouteHighValueLossUpdate;
routeContactSupport: RouteContactSupport;
};

export interface RouteContactSupport {
supportId?: string;
}

export interface RouteHighValueLossUpdate {
fromAmountUsd: string;
gasCostUSD?: string;
Expand Down

0 comments on commit 192140a

Please sign in to comment.