import { ChangeEvent, useRef, useState } from 'react' import { Row, Col, Space, Button, Typography, Input } from 'antd' import IonIcon from '@sentre/antd-ionicon' import NewKeyStore from './newKeystore' import { useRootDispatch, RootDispatch } from 'store' import { connectWallet } from 'store/wallet.reducer' import { KeystoreWallet } from '../../lib' const KeyStore = () => { const [password, setPassword] = useState('') const [filename, setFilename] = useState('') const [keystore, setKeystore] = useState(null) const [visible, setVisible] = useState(false) const refFile = useRef(null) const dispatch = useRootDispatch() const onKeystore = (e: ChangeEvent) => { const [file] = Array.from(e?.target?.files || []) if (file) { const reader = new FileReader() reader.readAsText(file) reader.onloadend = () => { setFilename(file.name) setKeystore(JSON.parse(reader.result as string) || {}) } } } const connect = async () => { if (!keystore) return window.notify({ type: 'warning', description: 'Please upload your keystore', }) if (!password) return window.notify({ type: 'warning', description: 'Please enter your password to unlock your wallet', }) try { const wallet = new KeystoreWallet(keystore as any, password) await dispatch(connectWallet(wallet)).unwrap() } catch (er: any) { return window.notify({ type: 'error', description: er.message }) } } return ( {`Keystore ( `} SolFlare {' '} {`compatible )`} } style={{ marginRight: -8 }} onClick={() => refFile.current?.click()} > Upload } readOnly /> ) => setPassword(e.target.value || '') } suffix={