const type = 'key'
const clientApi = () => chainClient().mockHsm.keys
+const list = baseListActions(type, {
+ className: 'Key',
+ clientApi,
+})
+const create = baseCreateActions(type, {
+ className: 'Key',
+ clientApi,
+})
+
export default {
- ...baseCreateActions(type, {
- className: 'Key',
- clientApi,
- }),
- ...baseListActions(type, {
- className: 'Key',
- clientApi,
- }),
+ ...create,
+ ...list,
+ createExport: (item) => () => {
+ clientApi().export(item.xpub).then(resp => {
+ const privateKey = resp.data.privateKey
+
+ var element = document.createElement('a')
+ element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(privateKey))
+ element.setAttribute('download', item.alias)
+ element.style.display = 'none'
+ document.body.appendChild(element)
+ element.click()
+
+ document.body.removeChild(element)
+ })
+ }
}
import React from 'react'
-import { chainClient } from 'utility/environment'
-
-const clientApi = () => chainClient().mockHsm.keys
+import { Link } from 'react-router'
class ListItem extends React.Component {
constructor(props) {
super(props)
-
- this.echo = (item) => clientApi().export(item.xpub).then(resp => {
- const privateKey = resp.data.privateKey
-
- var element = document.createElement('a')
- element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(privateKey))
- element.setAttribute('download', item.alias)
- element.style.display = 'none'
- document.body.appendChild(element)
- element.click()
-
- document.body.removeChild(element)
- })
}
render() {
const item = this.props.item
const lang = this.props.lang
- const operation = (item.complete === undefined || item.complete === true || item.percent == 100) ? (
- <button className='btn btn-link' onClick={this.echo.bind(this, item)}>
- { lang === 'zh' ? '导出私钥' : 'Export private key' }
- </button>
- ) : (
- <span>{`${item.percent}% imported...`}</span>
- )
return(
<tr>
<td>{item.alias}</td>
<td><code>{item.xpub}</code></td>
- <td>{operation}</td>
+ <td><Link to={`/keys/${item.id}`}>
+ {lang === 'zh' ? '更多' : 'More'}
+ </Link></td>
</tr>
)
}
--- /dev/null
+import React from 'react'
+import {
+ BaseShow,
+ KeyValueTable,
+ PageContent,
+ PageTitle,
+} from 'features/shared/components'
+import componentClassNames from 'utility/componentClassNames'
+
+class Show extends BaseShow {
+ constructor(props) {
+ super(props)
+ }
+
+ render() {
+ const item = this.props.item
+ const lang = this.props.lang
+
+ let view
+ if (item) {
+ const title = <span>
+ {lang === 'zh' ? '密钥' : 'Keys '}
+ <code>{item.alias ? item.alias : item.id}</code>
+ </span>
+
+ view = <div className={componentClassNames(this)}>
+ <PageTitle
+ title={title}
+ />
+
+ <PageContent>
+ <KeyValueTable
+ id={item.id}
+ object='key'
+ title={lang === 'zh' ? '详情' : 'Details'}
+ actions={[
+ <button key='export-key' className='btn btn-link' onClick={this.props.exportKey.bind(this, item)}>
+ { lang === 'zh' ? '导出私钥' : 'Export private key' }</button>,
+ ]}
+ items={[
+ {label: 'Alias', value: item.alias},
+ {label: 'xpubs', value: item.xpub},
+ ]}
+ lang={lang}
+ />
+ </PageContent>
+ </div>
+ }
+ return this.renderIfFound(view)
+ }
+}
+
+// Container
+
+import {connect} from 'react-redux'
+import actions from 'actions'
+
+const mapStateToProps = (state, ownProps) => ({
+ item: state.key.items[ownProps.params.id],
+ lang: state.core.lang
+})
+
+const mapDispatchToProps = ( dispatch ) => ({
+ fetchItem: (id) => dispatch(actions.key.fetchItems({id: `${id}`})),
+ exportKey: (item) => dispatch(actions.key.createExport(item))
+})
+
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(Show)
import List from './List'
import New from './New'
+import Show from './Show'
export {
List,
New,
+ Show
}
-import { List, New } from './components'
+import { List, New, Show } from './components'
import { makeRoutes } from 'features/shared'
-export default (store) => makeRoutes(store, 'key', List, New, null, null, { skipFilter: true, name: 'Keys', name_zh:'密钥' })
+export default (store) => makeRoutes(store, 'key', List, New, Show, null, { skipFilter: true, name: 'Keys', name_zh:'密钥' })