/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ import * as React from 'react' import { StyledContent, StyledImport, StyleButtonWrapper, StyledActionsWrapper, StyledDoneWrapper, StyledStatus, GroupedButton, ActionButton, StyledTitle, StyledTitleWrapper, StyledSafe, StyledTabWrapper, StyledControlWrapper, StyledText, StyledTextWrapper } from './style' import { TextArea, Modal, Button } from '../../../components' import { getLocale } from '../../../helpers' import { Alert, Tab } from '../' import ControlWrapper from '../../../components/formControls/controlWrapper' export interface Props { backupKey: string activeTabId: number onTabChange: () => void onClose: () => void onCopy?: (key: string) => void onPrint?: (key: string) => void onSaveFile?: (key: string) => void onRestore: (key: string) => void error?: React.ReactNode id?: string testId?: string funds?: string } interface State { recoveryKey: string errorShown: boolean } /* TODO - add error flow */ export default class ModalBackupRestore extends React.PureComponent { constructor (props: Props) { super(props) this.state = { recoveryKey: '', errorShown: false } } onFileUpload = (inputFile: React.ChangeEvent) => { const input: HTMLInputElement = inputFile.target const self = this if (!input.files) { return } const reader = new FileReader() reader.onload = function () { if (reader.result) { self.onRestore((reader.result.toString() || '').trim()) } else { self.onRestore('') } } try { reader.readAsText(input.files[0]) } catch (e) { self.onRestore('') } } setRecoveryKey = (event: React.ChangeEvent) => { this.setState({ errorShown: false, recoveryKey: event.target.value }) } onRestore = (key?: string) => { key = typeof key === 'string' ? key : this.state.recoveryKey this.props.onRestore(key) } componentWillReceiveProps (nextProps: Props) { if (nextProps.error) { this.setState({ errorShown: true }) } } getBackup = () => { const { backupKey, onClose, onCopy, onPrint, onSaveFile } = this.props return ( <>