forked from pancakeswap/pancake-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(swap-warning-modals): Add warning modals for specific tokens whe…
…n swapping (pancakeswap#1743) * feat(swap-warning-modals): Add config and components to pop warning modal for tokens * feat(swap-warning-modals): Use getAddress helpers * chore(swap-warnings): Modify variable names * feat(swap-warning-modals): Improve styles and reorg component to match design * chore(swap-warnings): Tidy up components and props * chore(swap-warnings): Use uikit message component * chore(warning-modal): Remove unused imports * chore(warning-modal): Type config and use imported tokens where possible * chore(warning-modal): Add Safemoon to tokens config and import to swap warning tokens
- Loading branch information
Showing
10 changed files
with
233 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import tokens from 'config/constants/tokens' | ||
import { Address } from './types' | ||
|
||
const { bondly, safemoon } = tokens | ||
|
||
interface WarningToken { | ||
symbol: string | ||
address: Address | ||
} | ||
|
||
interface WarningTokenList { | ||
[key: string]: WarningToken | ||
} | ||
|
||
const SwapWarningTokens = <WarningTokenList>{ | ||
safemoon, | ||
bondly, | ||
} | ||
|
||
export default SwapWarningTokens |
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
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
37 changes: 37 additions & 0 deletions
37
src/views/Swap/components/SwapWarningModal/Acknowledgement.tsx
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { useState } from 'react' | ||
import { useTranslation } from 'contexts/Localization' | ||
import { Text, Flex, Checkbox, Button } from '@pancakeswap/uikit' | ||
|
||
interface AcknowledgementProps { | ||
handleContinueClick: () => void | ||
} | ||
|
||
const Acknowledgement: React.FC<AcknowledgementProps> = ({ handleContinueClick }) => { | ||
const { t } = useTranslation() | ||
const [isConfirmed, setIsConfirmed] = useState(false) | ||
|
||
return ( | ||
<> | ||
<Flex justifyContent="space-between"> | ||
<Flex alignItems="center"> | ||
<Checkbox | ||
name="confirmed" | ||
type="checkbox" | ||
checked={isConfirmed} | ||
onChange={() => setIsConfirmed(!isConfirmed)} | ||
scale="sm" | ||
/> | ||
<Text ml="10px" style={{ userSelect: 'none' }}> | ||
{t('I understand')} | ||
</Text> | ||
</Flex> | ||
|
||
<Button disabled={!isConfirmed} onClick={handleContinueClick}> | ||
{t('Continue')} | ||
</Button> | ||
</Flex> | ||
</> | ||
) | ||
} | ||
|
||
export default Acknowledgement |
11 changes: 11 additions & 0 deletions
11
src/views/Swap/components/SwapWarningModal/BondlyWarning.tsx
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
import { Text } from '@pancakeswap/uikit' | ||
import { useTranslation } from 'contexts/Localization' | ||
|
||
const BondlyWarning = () => { | ||
const { t } = useTranslation() | ||
|
||
return <Text>{t('Warning: BONDLY has been compromised. Please remove liqudity until further notice.')}</Text> | ||
} | ||
|
||
export default BondlyWarning |
20 changes: 20 additions & 0 deletions
20
src/views/Swap/components/SwapWarningModal/SafemoonWarning.tsx
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import { useTranslation } from 'contexts/Localization' | ||
import { Text } from '@pancakeswap/uikit' | ||
|
||
const SafemoonWarning = () => { | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<> | ||
<Text>{t('To trade SAFEMOON, you must:')} </Text> | ||
<Text>• {t('Click on the settings icon')}</Text> | ||
<Text mb="24px">• {t('Set your slippage tolerance to 12%+')}</Text> | ||
<Text>{t('This is because SafeMoon taxes a 10% fee on each transaction:')}</Text> | ||
<Text>• {t('5% fee = redistributed to all existing holders')}</Text> | ||
<Text>• {t('5% fee = used to add liquidity')}</Text> | ||
</> | ||
) | ||
} | ||
|
||
export default SafemoonWarning |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { useEffect } from 'react' | ||
import styled from 'styled-components' | ||
import { ModalBody, ModalContainer, Message, ModalHeader, Box, Heading } from '@pancakeswap/uikit' | ||
import useTheme from 'hooks/useTheme' | ||
import { getAddress } from 'utils/addressHelpers' | ||
import { useTranslation } from 'contexts/Localization' | ||
import { WrappedTokenInfo } from 'state/lists/hooks' | ||
import SwapWarningTokensConfig from 'config/constants/swapWarningTokens' | ||
import SafemoonWarning from './SafemoonWarning' | ||
import BondlyWarning from './BondlyWarning' | ||
import Acknowledgement from './Acknowledgement' | ||
|
||
const StyledModalContainer = styled(ModalContainer)` | ||
max-width: 440px; | ||
` | ||
|
||
const MessageContainer = styled(Message)` | ||
align-items: flex-start; | ||
justify-content: flex-start; | ||
` | ||
|
||
interface SwapWarningModalProps { | ||
swapCurrency: WrappedTokenInfo | ||
onDismiss?: () => void | ||
} | ||
|
||
// Modal is fired by a useEffect and doesn't respond to closeOnOverlayClick prop being set to false | ||
const usePreventModalOverlayClick = () => { | ||
useEffect(() => { | ||
const preventClickHandler = (e) => { | ||
e.stopPropagation() | ||
e.preventDefault() | ||
return false | ||
} | ||
|
||
document.querySelectorAll('[role="presentation"]').forEach((el) => { | ||
el.addEventListener('click', preventClickHandler, true) | ||
}) | ||
|
||
return () => { | ||
document.querySelectorAll('[role="presentation"]').forEach((el) => { | ||
el.removeEventListener('click', preventClickHandler, true) | ||
}) | ||
} | ||
}, []) | ||
} | ||
|
||
const SwapWarningModal: React.FC<SwapWarningModalProps> = ({ swapCurrency, onDismiss }) => { | ||
const { t } = useTranslation() | ||
const { theme } = useTheme() | ||
usePreventModalOverlayClick() | ||
|
||
const TOKEN_WARNINGS = { | ||
[getAddress(SwapWarningTokensConfig.safemoon.address)]: { | ||
symbol: SwapWarningTokensConfig.safemoon.symbol, | ||
component: <SafemoonWarning />, | ||
}, | ||
[getAddress(SwapWarningTokensConfig.bondly.address)]: { | ||
symbol: SwapWarningTokensConfig.bondly.symbol, | ||
component: <BondlyWarning />, | ||
}, | ||
} | ||
|
||
const SWAP_WARNING = TOKEN_WARNINGS[swapCurrency.address] | ||
|
||
return ( | ||
<StyledModalContainer minWidth="280px"> | ||
<ModalHeader background={theme.colors.gradients.cardHeader}> | ||
<Heading p="12px 24px">{t('Notice for trading %symbol%', { symbol: SWAP_WARNING.symbol })}</Heading> | ||
</ModalHeader> | ||
<ModalBody p="24px"> | ||
<MessageContainer variant="warning" mb="24px"> | ||
<Box>{SWAP_WARNING.component}</Box> | ||
</MessageContainer> | ||
<Acknowledgement handleContinueClick={onDismiss} /> | ||
</ModalBody> | ||
</StyledModalContainer> | ||
) | ||
} | ||
|
||
export default SwapWarningModal |
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