import { ChangeEvent, useState, useEffect } from 'react' import fileDownload from 'js-file-download' import { keystore as ks, Keystore } from '@senswap/sen-js' import { Row, Col, Button, Typography, Input, Modal } from 'antd' import IonIcon from '@sentre/antd-ionicon' const NewKeyStore = ({ visible = false, onClose = () => {}, }: { visible: boolean onClose: () => void }) => { const [password, setPassword] = useState('') const [keystore, setKeystore] = useState(null) useEffect(() => { setPassword('') setKeystore(null) }, [visible]) useEffect(() => { setKeystore(ks.gen(password)) }, [password]) const onDownload = () => { if (!keystore) return window.notify({ type: 'error', description: 'Cannot download a empty keystore', }) fileDownload( JSON.stringify(keystore), `senwallet-keystore-${keystore.publicKey}.json`, ) return onClose() } return ( } footer={null} > New Keystore The password is used to encrypt your keystore. You will need this password to unlock your keystore later. ) => setPassword(e.target.value || '') } iconRender={(visible) => visible ? : } /> ) } export default NewKeyStore