From b586e7ed7f4885ca39487de86504caadc5b52b5c Mon Sep 17 00:00:00 2001 From: George Lima Date: Sat, 12 Jan 2019 16:30:44 -0300 Subject: [PATCH] feature(settings): add export private keys in settings view --- app/views/settings.js | 172 ++++++++++++++++++++++++++++-------------- 1 file changed, 117 insertions(+), 55 deletions(-) diff --git a/app/views/settings.js b/app/views/settings.js index 0aa0df0..ac19426 100644 --- a/app/views/settings.js +++ b/app/views/settings.js @@ -3,10 +3,12 @@ import React, { PureComponent } from 'react'; import styled from 'styled-components'; import { Button } from '../components/button'; -import { ModalComponent } from '../components/modal'; import { ConfirmDialogComponent } from '../components/confirm-dialog'; import { TextComponent } from '../components/text'; import { InputComponent } from '../components/input'; +import { InputLabelComponent } from '../components/input-label'; +import { RowComponent } from '../components/row'; +import { Clipboard } from '../components/clipboard'; import rpc from '../../services/api'; @@ -17,10 +19,26 @@ const Wrapper = styled.div` const ModalContent = styled.div` padding: 20px; width: 100%; - overflow-x: hidden; + max-height: 600px; + overflow-y: auto; + + p { + word-break: break-all; + } `; -type ViewKey = { +const Btn = styled(Button)` + margin-bottom: 10px; +`; + +const ClipboardButton = styled(Clipboard)` + width: 50px; + border-radius: ${props => props.theme.boxBorderRadius}; + height: 45px; + margin-left: 5px; +`; + +type Key = { zAddress: string, key: string, }; @@ -29,18 +47,20 @@ type Props = { addresses: string[], }; type State = { - viewKeys: ViewKey[], + viewKeys: Key[], + privateKeys: Key[], isLoading: boolean, successExportViewKeys: boolean, - message: string | null, + successExportPrivateKeys: boolean, }; export class SettingsView extends PureComponent { state = { viewKeys: [], + privateKeys: [], isLoading: false, successExportViewKeys: false, - message: null, + successExportPrivateKeys: false, }; exportViewKeys = () => { @@ -48,6 +68,8 @@ export class SettingsView extends PureComponent { const zAddresses = addresses.filter(addr => addr.startsWith('z')); + this.setState({ isLoading: true }); + Promise.all( zAddresses.map(async (zAddr) => { const viewKey = await rpc.z_exportviewingkey(zAddr); @@ -57,76 +79,116 @@ export class SettingsView extends PureComponent { this.setState({ viewKeys, successExportViewKeys: true, + isLoading: false, }); }); }; - handleCloseModal = (fn: () => void) => () => { - this.setState( - { - message: null, - }, - fn, - ); + exportPrivateKeys = () => { + const { addresses } = this.props; + + const zAddresses = addresses.filter(addr => addr.startsWith('z')); + + this.setState({ isLoading: true }); + + Promise.all( + zAddresses.map(async (zAddr) => { + const privateKey = await rpc.z_exportkey(zAddr); + return { zAddress: zAddr, key: privateKey }; + }), + ).then((privateKeys) => { + this.setState({ + privateKeys, + successExportPrivateKeys: true, + isLoading: false, + }); + }); }; render = () => { const { - viewKeys, isLoading, successExportViewKeys, message, + viewKeys, + isLoading, + successExportViewKeys, + privateKeys, + successExportPrivateKeys, } = this.state; return ( - ( -