-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cleanup Acknowledgement.tsx (#8472)
- Loading branch information
1 parent
bf7ed3f
commit b0e722f
Showing
15 changed files
with
128 additions
and
120 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,5 @@ | ||
import type { AcknowledgementProps } from './Acknowledgement' | ||
import { Acknowledgement } from './Acknowledgement' | ||
|
||
export const InfoAcknowledgement = (props: AcknowledgementProps) => | ||
Acknowledgement({ ...props, buttonColorScheme: 'blue', iconColorScheme: 'yellow' }) |
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,5 @@ | ||
import type { AcknowledgementProps } from './Acknowledgement' | ||
import { Acknowledgement } from './Acknowledgement' | ||
|
||
export const WarningAcknowledgement = (props: AcknowledgementProps) => | ||
Acknowledgement({ ...props, buttonColorScheme: 'red', iconColorScheme: 'red' }) |
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
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
75 changes: 75 additions & 0 deletions
75
...mponents/MultiHopTrade/components/TradeInput/components/ArbitrumBridgeAcknowledgement.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,75 @@ | ||
import { Box, Checkbox, Link } from '@chakra-ui/react' | ||
import { useColorModeValue } from '@chakra-ui/system' | ||
import { useCallback, useMemo, useState } from 'react' | ||
import { useTranslate } from 'react-polyglot' | ||
import type { AcknowledgementProps } from 'components/Acknowledgement/Acknowledgement' | ||
import { Acknowledgement } from 'components/Acknowledgement/Acknowledgement' | ||
import { RawText } from 'components/Text/Text' | ||
|
||
type ArbitrumAcknowledgementProps = Omit<AcknowledgementProps, 'message'> | ||
|
||
export const ArbitrumBridgeAcknowledgement = (props: ArbitrumAcknowledgementProps) => { | ||
const translate = useTranslate() | ||
const [hasAgreed, setHasAgreed] = useState([false, false]) | ||
|
||
const isDisabled = useMemo(() => !hasAgreed.every(Boolean), [hasAgreed]) | ||
|
||
const handleAgree = useCallback( | ||
(index: number) => (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const updatedAgreements = [...hasAgreed] | ||
updatedAgreements[index] = event.target.checked | ||
setHasAgreed(updatedAgreements) | ||
}, | ||
[hasAgreed], | ||
) | ||
|
||
const checkboxTextColor = useColorModeValue('gray.800', 'gray.50') | ||
|
||
const checkboxes = useMemo( | ||
() => ( | ||
<Box py={4} textAlign='left' color={checkboxTextColor}> | ||
<Checkbox onChange={handleAgree(0)} fontWeight='bold' py={2}> | ||
{translate('bridge.arbitrum.waitCta')} | ||
</Checkbox> | ||
<Checkbox onChange={handleAgree(1)} fontWeight='bold' py={2}> | ||
{translate('bridge.arbitrum.claimCta')} | ||
</Checkbox> | ||
</Box> | ||
), | ||
[checkboxTextColor, handleAgree, translate], | ||
) | ||
|
||
const handleAcknowledge = useMemo(() => { | ||
if (isDisabled) return | ||
|
||
return props.onAcknowledge | ||
}, [isDisabled, props]) | ||
|
||
const message = useMemo( | ||
() => ( | ||
<> | ||
<RawText as='span'>{translate('bridge.arbitrum.waitWarning')}</RawText>{' '} | ||
<Link | ||
href='https://docs.arbitrum.io/arbitrum-bridge/quickstart#withdraw-eth-or-erc-20-tokens-from-child-chain-to-parent-chain' | ||
isExternal | ||
colorScheme='blue' | ||
color='blue.500' | ||
> | ||
{translate('common.learnMore')} | ||
</Link> | ||
</> | ||
), | ||
[translate], | ||
) | ||
|
||
return ( | ||
<Acknowledgement | ||
{...props} | ||
buttonTranslation='common.continue' | ||
message={message} | ||
content={checkboxes} | ||
disableButton={isDisabled} | ||
onAcknowledge={handleAcknowledge} | ||
/> | ||
) | ||
} |
28 changes: 28 additions & 0 deletions
28
src/components/MultiHopTrade/components/TradeInput/components/StreamingAcknowledgement.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,28 @@ | ||
import { useTranslate } from 'react-polyglot' | ||
import type { AcknowledgementProps } from 'components/Acknowledgement/Acknowledgement' | ||
import { Acknowledgement } from 'components/Acknowledgement/Acknowledgement' | ||
import { StreamIcon } from 'components/Icons/Stream' | ||
import { formatSecondsToDuration } from 'lib/utils/time' | ||
|
||
type StreamingAcknowledgementProps = Omit<AcknowledgementProps, 'message'> & { | ||
estimatedTimeMs: number | ||
} | ||
|
||
export const StreamingAcknowledgement = ({ | ||
estimatedTimeMs, | ||
...restProps | ||
}: StreamingAcknowledgementProps) => { | ||
const translate = useTranslate() | ||
|
||
return ( | ||
<Acknowledgement | ||
{...restProps} | ||
buttonColorScheme='blue' | ||
buttonTranslation='common.continue' | ||
message={translate('streamingAcknowledgement.description', { | ||
estimatedTimeHuman: formatSecondsToDuration(estimatedTimeMs / 1000), | ||
})} | ||
icon={StreamIcon} | ||
/> | ||
) | ||
} |
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
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