-
Notifications
You must be signed in to change notification settings - Fork 15
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
1 parent
26bc797
commit 1a72c81
Showing
26 changed files
with
890 additions
and
85 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import RodalModal from '../RodalModal/RodalModal' | ||
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil' | ||
import { beaconNodeEndpoint, isBlsExecutionModal, isProcessBls } from '../../recoil/atoms' | ||
import useMediaQuery from '../../hooks/useMediaQuery' | ||
import Typography from '../Typography/Typography' | ||
import CodeInput from '../CodeInput/CodeInput' | ||
import ValidatorDisclosure from '../Disclosures/ValidatorDisclosure' | ||
import { useState } from 'react' | ||
import { MOCK_BLS_JSON, WithdrawalInfoLink } from '../../constants/constants' | ||
import GradientHeader from '../GradientHeader/GradientHeader' | ||
import { ButtonFace } from '../Button/Button' | ||
import { useTranslation, Trans } from 'react-i18next' | ||
import { broadcastBlsChange } from '../../api/beacon' | ||
import { toast } from 'react-toastify' | ||
import axios, { AxiosError } from 'axios' | ||
import useLocalStorage from '../../hooks/useLocalStorage' | ||
import { Storage } from '../../constants/enums' | ||
|
||
const BlsExecutionModal = () => { | ||
const { t } = useTranslation() | ||
const beaconEndpoint = useRecoilValue(beaconNodeEndpoint) | ||
const [isModal, toggleModal] = useRecoilState(isBlsExecutionModal) | ||
const isTablet = useMediaQuery('(max-width: 1024px)') | ||
const [blsJson, setJson] = useState(MOCK_BLS_JSON) | ||
const setIsProcess = useSetRecoilState(isProcessBls) | ||
const [, storeIsBlsProcessing] = useLocalStorage<boolean>(Storage.BLS_PROCESSING, false) | ||
|
||
const closeModal = () => toggleModal(false) | ||
const setJsonValue = (value: string) => setJson(value) | ||
|
||
const handleError = (code?: number) => { | ||
let message = t('error.unknownError', { type: 'BEACON' }) | ||
|
||
if (code === 400) { | ||
message = t('error.executionFailure') | ||
} | ||
|
||
toast.error(message, { | ||
position: 'top-right', | ||
autoClose: 5000, | ||
theme: 'colored', | ||
hideProgressBar: true, | ||
closeOnClick: true, | ||
pauseOnHover: true, | ||
}) | ||
} | ||
|
||
const submitChange = async () => { | ||
try { | ||
const { status } = await broadcastBlsChange(beaconEndpoint, blsJson) | ||
|
||
if (status != 200) { | ||
handleError(status) | ||
return | ||
} | ||
|
||
setIsProcess(true) | ||
storeIsBlsProcessing(true) | ||
} catch (e) { | ||
if (axios.isAxiosError(e)) { | ||
const axiosError = e as AxiosError | ||
|
||
handleError(axiosError.response?.status) | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<RodalModal | ||
isVisible={isModal} | ||
styles={{ | ||
width: 'fit-content', | ||
maxWidth: isTablet ? '448px' : '900px', | ||
height: isTablet ? '540px' : 'max-content', | ||
}} | ||
onClose={closeModal} | ||
> | ||
<div> | ||
<GradientHeader title={t('blsExecution.modal.title')} /> | ||
<div className='p-6 space-y-4'> | ||
<Typography type='text-caption1'> | ||
<Trans i18nKey='blsExecution.modal.subTitle'> | ||
<br /> | ||
</Trans> | ||
{' ---'} | ||
</Typography> | ||
<Typography className='w-3/4' type='text-caption1'> | ||
{t('blsExecution.modal.description')} | ||
</Typography> | ||
<Typography className='w-3/4' type='text-caption1'> | ||
<Trans i18nKey='blsExecution.modal.followLink'> | ||
<a | ||
className='text-blue-500 underline' | ||
target='_blank' | ||
rel='noreferrer' | ||
href={WithdrawalInfoLink} | ||
/> | ||
</Trans> | ||
</Typography> | ||
<CodeInput value={blsJson} onChange={setJsonValue} /> | ||
</div> | ||
{isModal && ( | ||
<div className='p-3 border-t-style100'> | ||
<ValidatorDisclosure | ||
onAccept={submitChange} | ||
ctaType={ButtonFace.SECONDARY} | ||
ctaText={t('blsExecution.modal.cta')} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
</RodalModal> | ||
) | ||
} | ||
|
||
export default BlsExecutionModal |
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,31 @@ | ||
import CodeEditor from '@uiw/react-textarea-code-editor' | ||
import { FC } from 'react' | ||
|
||
export interface CodeInputProps { | ||
onChange: (value: string) => void | ||
value: string | ||
placeholder?: string | ||
} | ||
|
||
const CodeInput: FC<CodeInputProps> = ({ onChange, value, placeholder }) => { | ||
return ( | ||
<div className='w-full max-h-48 overflow-scroll'> | ||
<CodeEditor | ||
rows={5} | ||
className='dark:bg-dark750' | ||
value={value} | ||
language='json' | ||
placeholder={placeholder} | ||
onChange={(evn) => onChange(evn.target.value)} | ||
padding={15} | ||
style={{ | ||
fontSize: 12, | ||
fontFamily: | ||
'ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace', | ||
}} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default CodeInput |
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,38 @@ | ||
import Waves from '../../assets/images/waves.png' | ||
import { FC } from 'react' | ||
import addClassString from '../../utilities/addClassString' | ||
import Typography from '../Typography/Typography' | ||
|
||
export interface GradientHeaderProps { | ||
className?: string | ||
title?: string | ||
} | ||
|
||
const GradientHeader: FC<GradientHeaderProps> = ({ className, title }) => { | ||
const classes = addClassString('w-full h-36 relative', [className]) | ||
|
||
return ( | ||
<div className={classes}> | ||
<div | ||
className='w-full h-full bg-no-repeat bg-right opacity-10' | ||
style={{ backgroundImage: `url(${Waves})` }} | ||
/> | ||
<div className='absolute top-0 left-0 w-3/4 h-full bg-gradient-to-r from-white dark:from-dark750 via-white dark:via-dark750 to-transparent' /> | ||
{title && ( | ||
<div className='absolute top-0 left-0 w-full h-full flex items-center p-5 z-20'> | ||
<Typography | ||
type='text-subtitle1' | ||
color='text-transparent' | ||
darkMode='text-transparent' | ||
className='primary-gradient-text capitalize' | ||
fontWeight='font-light' | ||
> | ||
{title} | ||
</Typography> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default GradientHeader |
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
Oops, something went wrong.