Warn users when an ENS name contains 'confusable' characters (#9187)
* Add warning system for 'confusable' ENS names (#9129) Uses unicode.org's TR39 confusables.txt to display a warning when 'confusable' unicode points are detected. Currently only the `AddRecipient` component has been updated, but the new `Confusable` component could be used elsewhere The new `unicode-confusables` dependency adds close to 100KB to the bundle size, and around 30KB when gzipped. Adds 'tag' prop to the tooltop-v2 component Use $Red-500 for confusable ens warning Lint Tooltip component Update copy for confusing ENS domain warning. * Fix prop type Co-authored-by: Mark Stacey <markjstacey@gmail.com>feature/default_network_editable
parent
caa32d87fb
commit
b04120dd0f
@ -0,0 +1,39 @@ |
||||
import React, { useMemo } from 'react'; |
||||
import PropTypes from 'prop-types'; |
||||
import { confusables } from 'unicode-confusables'; |
||||
import Tooltip from '../tooltip'; |
||||
import { useI18nContext } from '../../../hooks/useI18nContext'; |
||||
|
||||
const Confusable = ({ input }) => { |
||||
const t = useI18nContext(); |
||||
const confusableData = useMemo(() => { |
||||
return confusables(input); |
||||
}, [input]); |
||||
|
||||
return confusableData.map(({ point, similarTo }, index) => { |
||||
const zeroWidth = similarTo === ''; |
||||
if (similarTo === undefined) { |
||||
return point; |
||||
} |
||||
return ( |
||||
<Tooltip |
||||
key={index.toString()} |
||||
tag="span" |
||||
position="top" |
||||
title={ |
||||
zeroWidth |
||||
? t('confusableZeroWidthUnicode') |
||||
: t('confusableUnicode', [point, similarTo]) |
||||
} |
||||
> |
||||
<span className="confusable__point">{zeroWidth ? '?' : point}</span> |
||||
</Tooltip> |
||||
); |
||||
}); |
||||
}; |
||||
|
||||
Confusable.propTypes = { |
||||
input: PropTypes.string.isRequired, |
||||
}; |
||||
|
||||
export default Confusable; |
@ -0,0 +1 @@ |
||||
export { default } from './confusable.component'; |
@ -0,0 +1,5 @@ |
||||
.confusable { |
||||
&__point { |
||||
color: $Red-500; |
||||
} |
||||
} |
Loading…
Reference in new issue