Skip to content

Commit

Permalink
feat: add SendToWalletToggled event
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Aug 25, 2023
1 parent 9b8afd0 commit e6bffcf
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 142 deletions.
4 changes: 4 additions & 0 deletions packages/widget-playground/src/components/WidgetEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const WidgetEvents = () => {
const onRouteHighValueLoss = (update: RouteHighValueLossUpdate) => {
// console.log('onRouteHighValueLoss continued.');
};
const onSendToWalletToggled = (open: boolean) => {
// console.log('onSendToWalletToggled', open);
};
// const onRouteContactSupport = (supportId: RouteContactSupport) => {
// console.log('onRouteContactSupport clicked', supportId);
// };
Expand All @@ -36,6 +39,7 @@ export const WidgetEvents = () => {
);
widgetEvents.on(WidgetEvent.RouteHighValueLoss, onRouteHighValueLoss);
widgetEvents.on(WidgetEvent.RouteExecutionFailed, onRouteExecutionFailed);
widgetEvents.on(WidgetEvent.SendToWalletToggled, onSendToWalletToggled);
// widgetEvents.on(WidgetEvent.RouteContactSupport, onRouteContactSupport);
return () => widgetEvents.all.clear();
}, [widgetEvents]);
Expand Down
92 changes: 45 additions & 47 deletions packages/widget/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,49 @@ export const Card = styled(Box, {
!['variant', 'indented', 'selectionColor', 'pointerEvents'].includes(
prop as string,
),
})<CardProps>(
({
theme,
variant,
selectionColor = 'primary',
indented,
})<CardProps>(({
theme,
variant,
selectionColor = 'primary',
indented,
pointerEvents,
onClick,
}) => {
const backgroundColor = getBackgroundColor(theme, variant, selectionColor);
const backgroundHoverColor = onClick
? theme.palette.mode === 'light'
? darken(backgroundColor, 0.02)
: lighten(backgroundColor, 0.02)
: backgroundColor;
return {
backgroundColor,
border: `1px solid`,
borderColor:
variant === 'error'
? theme.palette.error.main
: variant === 'selected'
? selectionColor === 'primary'
? theme.palette.primary.main
: alpha(theme.palette.secondary.main, 0.48)
: theme.palette.mode === 'light'
? theme.palette.grey[300]
: theme.palette.grey[800],
borderRadius: theme.shape.borderRadius,
overflow: 'hidden',
position: 'relative',
padding: indented ? theme.spacing(2) : 0,
boxSizing: 'border-box',
'&:hover': {
cursor: onClick ? 'pointer' : 'default',
backgroundColor: backgroundHoverColor,
},
[`&:hover .${badgeClasses.badge} > div`]: {
borderColor: backgroundHoverColor,
},
transition: theme.transitions.create(['background-color'], {
duration: theme.transitions.duration.enteringScreen,
easing: theme.transitions.easing.easeOut,
}),
pointerEvents,
onClick,
}) => {
const backgroundColor = getBackgroundColor(theme, variant, selectionColor);
const backgroundHoverColor = onClick
? theme.palette.mode === 'light'
? darken(backgroundColor, 0.02)
: lighten(backgroundColor, 0.02)
: backgroundColor;
return {
backgroundColor,
border: `1px solid`,
borderColor:
variant === 'error'
? theme.palette.error.main
: variant === 'selected'
? selectionColor === 'primary'
? theme.palette.primary.main
: alpha(theme.palette.secondary.main, 0.48)
: theme.palette.mode === 'light'
? theme.palette.grey[300]
: theme.palette.grey[800],
borderRadius: theme.shape.borderRadius,
overflow: 'hidden',
position: 'relative',
padding: indented ? theme.spacing(2) : 0,
boxSizing: 'border-box',
'&:hover': {
cursor: onClick ? 'pointer' : 'default',
backgroundColor: backgroundHoverColor,
},
[`&:hover .${badgeClasses.badge} > div`]: {
borderColor: backgroundHoverColor,
},
transition: theme.transitions.create(['background-color'], {
duration: theme.transitions.duration.enteringScreen,
easing: theme.transitions.easing.easeOut,
}),
pointerEvents,
};
},
);
};
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IconButtonProps } from '@mui/material';
import { Box, CircularProgress, IconButton, Tooltip } from '@mui/material';
import { useEffect, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { Trans } from 'react-i18next';

const getProgressValue = (updatedAt: number, timeToUpdate: number) =>
updatedAt
Expand All @@ -18,7 +18,6 @@ export const ProgressToNextUpdate: React.FC<
isLoading?: boolean;
} & IconButtonProps
> = ({ updatedAt, timeToUpdate, isLoading, onClick, ...other }) => {
const { t } = useTranslation();
const [value, setValue] = useState(() =>
getProgressValue(updatedAt, timeToUpdate),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import WalletIcon from '@mui/icons-material/Wallet';
import { Button, Tooltip } from '@mui/material';
import { useFormContext } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { useWidgetEvents } from '../../hooks';
import { FormKey, useWallet, useWidgetConfig } from '../../providers';
import { useSendToWalletStore, useSettings } from '../../stores';
import { DisabledUI, HiddenUI, RequiredUI } from '../../types';
import { DisabledUI, HiddenUI, RequiredUI, WidgetEvent } from '../../types';

export const SendToWalletButton: React.FC = () => {
const { t } = useTranslation();
const { setValue } = useFormContext();
const emitter = useWidgetEvents();
const { account } = useWallet();
const { disabledUI, hiddenUI, requiredUI } = useWidgetConfig();
const { showSendToWallet, toggleSendToWallet } = useSendToWalletStore();
Expand All @@ -28,6 +30,10 @@ export const SendToWalletButton: React.FC = () => {
setValue(FormKey.ToAddress, '', { shouldTouch: true });
}
toggleSendToWallet();
emitter.emit(
WidgetEvent.SendToWalletToggled,
useSendToWalletStore.getState().showSendToWallet,
);
};

return (
Expand Down
5 changes: 2 additions & 3 deletions packages/widget/src/components/Step/Step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ export const Step: React.FC<{

const formattedToAddress = shortenAddress(toAddress);
const toAddressLink = toAddress
? `${
getChainById(step.action.toChainId)?.metamask.blockExplorerUrls[0]
}address/${toAddress}`
? `${getChainById(step.action.toChainId)?.metamask
.blockExplorerUrls[0]}address/${toAddress}`
: undefined;

return (
Expand Down
11 changes: 10 additions & 1 deletion packages/widget/src/components/TokenList/useTokenSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export const useTokenSelect = (formType: FormType, onClick?: () => void) => {

onClick?.();
},
[formType, getValues, onBlur, onChange, onClick, setValue, subvariant],
[
emitter,
formType,
getValues,
onBlur,
onChange,
onClick,
setValue,
subvariant,
],
);
};
Loading

0 comments on commit e6bffcf

Please sign in to comment.