OSDN Git Service

Merge branch 'master' of git://github.com/Bytom/dashboard into dashboardmaster
[bytom/bytom-electron.git] / src / features / mockhsm / components / Show.jsx
1 import React from 'react'
2 import { Link } from 'react-router'
3 import {
4   BaseShow,
5   KeyValueTable,
6   PageContent,
7   PageTitle,
8 } from 'features/shared/components'
9 import  ExportKey  from './ExportKey/ExportKey'
10 import componentClassNames from 'utility/componentClassNames'
11
12 class Show extends BaseShow {
13   constructor(props) {
14     super(props)
15   }
16
17   showExportKey(item, lang){
18     this.props.showModal(
19       <div>
20         <p>{lang === 'zh' ?  `请输入密码然后导出${item.alias}的私钥:` : `Please enter the password and export ${item.alias}'s private key:`}</p>
21         <ExportKey
22           key='export-key-form' // required by React
23           item={item}
24           lang={lang}
25           exportKey={this.props.exportKey}
26         />
27       </div>
28       )
29   }
30
31   render() {
32     const item = this.props.item
33     const lang = this.props.lang
34
35     let view
36     if (item) {
37       const title = <span>
38         {lang === 'zh' ? '密钥' : 'Keys '}
39         <code>{item.alias ? item.alias : item.id}</code>
40       </span>
41
42       view = <div className={componentClassNames(this)}>
43         <PageTitle
44           title={title}
45         />
46
47         <PageContent>
48           <KeyValueTable
49             id={item.id}
50             object='key'
51             title={lang === 'zh' ? '详情' : 'Details'}
52             actions={[
53               <Link key='reset-password-btn' className='btn btn-link' to={`/keys/${item.id}/reset-password`}>{lang === 'zh' ? '重置密码' : 'Reset Password' }</Link>
54             ]}
55             items={[
56               {label: (lang === 'zh' ? '别名' : 'Alias' ), value: item.alias},
57               {label: (lang === 'zh' ? '主公钥' : 'xpub'), value: item.xpub},
58             ]}
59             lang={lang}
60           />
61         </PageContent>
62       </div>
63     }
64     return this.renderIfFound(view)
65   }
66 }
67
68 // Container
69
70 import {connect} from 'react-redux'
71 import actions from 'actions'
72
73 const mapStateToProps = (state, ownProps) => ({
74   item: state.key.items[ownProps.params.id],
75   lang: state.core.lang
76 })
77
78 const mapDispatchToProps = ( dispatch ) => ({
79   fetchItem: () => dispatch(actions.key.fetchItems()),
80   exportKey: (item, fileName) => dispatch(actions.key.createExport(item, fileName)),
81   showModal: (body) => dispatch(actions.app.showModal(
82     body,
83     actions.app.hideModal
84   )),
85 })
86
87
88 export default connect(
89   mapStateToProps,
90   mapDispatchToProps
91 )(Show)