-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,69 @@ | ||
import { FC } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { TFunction } from 'i18next' | ||
import Tooltip from '@mui/material/Tooltip' | ||
import { tooltipDelay } from '../../../styles/theme' | ||
import { UnknownIcon } from './../CustomIcons/Unknown' | ||
import { TransferIcon } from './../CustomIcons/Transfer' | ||
import { COLORS } from '../../../styles/theme/colors' | ||
import StreamIcon from '@mui/icons-material/Stream' | ||
import LocalFireDepartmentIcon from '@mui/icons-material/LocalFireDepartment' | ||
import ApprovalIcon from '@mui/icons-material/Approval' | ||
import Box from '@mui/material/Box' | ||
import { MethodIcon } from '../ConsensusTransactionMethod' | ||
import ArrowForwardIcon from '@mui/icons-material/ArrowForward' | ||
import QuestionMarkIcon from '@mui/icons-material/QuestionMark' | ||
|
||
const getTokenTransferLabel = (t: TFunction, name: string | undefined): string => { | ||
const getTokenTransferIcon = (t: TFunction, name: string | undefined) => { | ||
switch (name) { | ||
case undefined: | ||
return t('tokens.transferEventType.unavailable') | ||
case 'Transfer': | ||
return t('tokens.transferEventType.transfer') | ||
return ( | ||
<MethodIcon | ||
border={false} | ||
color="green" | ||
icon={<ArrowForwardIcon />} | ||
label={t('tokens.transferEventType.transfer')} | ||
/> | ||
) | ||
case 'Approval': | ||
return t('tokens.transferEventType.approval') | ||
return ( | ||
<MethodIcon | ||
color="green" | ||
border={false} | ||
icon={<ApprovalIcon />} | ||
label={t('tokens.transferEventType.approval')} | ||
/> | ||
) | ||
case 'Minting': | ||
return t('tokens.transferEventType.minting') | ||
return ( | ||
<MethodIcon | ||
color="green" | ||
border={false} | ||
icon={<StreamIcon />} | ||
label={t('tokens.transferEventType.minting')} | ||
/> | ||
) | ||
case 'Burning': | ||
return t('tokens.transferEventType.burning') | ||
return ( | ||
<MethodIcon | ||
color="orange" | ||
border={false} | ||
icon={<LocalFireDepartmentIcon />} | ||
label={t('tokens.transferEventType.burning')} | ||
/> | ||
) | ||
default: | ||
return t('tokens.transferEventType.unknown', { name }) | ||
return ( | ||
<MethodIcon | ||
border={false} | ||
color="gray" | ||
icon={<QuestionMarkIcon />} | ||
label={name || t('common.unknown')} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
const getTokenTransferIcon = (name: string | undefined) => { | ||
switch (name) { | ||
case undefined: | ||
// Method may be undefined if the transaction was malformed. | ||
return <UnknownIcon fontSize="inherit" /> | ||
case 'Transfer': | ||
return <TransferIcon fontSize="inherit" /> | ||
case 'Approval': | ||
return <ApprovalIcon fontSize="inherit" htmlColor={COLORS.eucalyptus} /> | ||
case 'Minting': | ||
return <StreamIcon fontSize="inherit" htmlColor={COLORS.eucalyptus} /> | ||
case 'Burning': | ||
return <LocalFireDepartmentIcon fontSize="inherit" htmlColor={COLORS.eucalyptus} /> | ||
default: | ||
return <UnknownIcon fontSize="inherit" /> | ||
} | ||
} | ||
|
||
interface TokenTransferLabelProps { | ||
/** | ||
* The event name | ||
*/ | ||
interface TokenTransferIconProps { | ||
name: string | undefined | ||
} | ||
|
||
export const TokenTransferLabel: FC<TokenTransferLabelProps> = ({ name }) => { | ||
const { t } = useTranslation() | ||
|
||
return <>{getTokenTransferLabel(t, name)}</> | ||
} | ||
|
||
interface TokenTransferIconProps extends TokenTransferLabelProps { | ||
size: number | ||
} | ||
|
||
export const TokenTransferIcon: FC<TokenTransferIconProps> = ({ name, size }) => { | ||
export const TokenTransferIcon: FC<TokenTransferIconProps> = ({ name }) => { | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<Tooltip | ||
arrow | ||
placement="top" | ||
title={getTokenTransferLabel(t, name)} | ||
enterDelay={tooltipDelay} | ||
enterNextDelay={tooltipDelay} | ||
> | ||
<Box component="span" sx={{ fontSize: size, lineHeight: 0 }}> | ||
{getTokenTransferIcon(name)} | ||
</Box> | ||
</Tooltip> | ||
) | ||
return <>{getTokenTransferIcon(t, name)}</> | ||
} |