OSDN Git Service

Merge pull request #14 from Bytom/dev
[bytom/bytom-electron.git] / src / features / assets / components / AssetShow.jsx
1 import React from 'react'
2 import {
3   BaseShow,
4   PageContent,
5   PageTitle,
6   KeyValueTable,
7   RawJsonButton,
8 } from 'features/shared/components'
9 import { Link } from 'react-router'
10 import componentClassNames from 'utility/componentClassNames'
11 import { btmID } from 'utility/environment'
12 import { withNamespaces } from 'react-i18next'
13
14 class AssetShow extends BaseShow {
15   render() {
16     const { item, t } = this.props
17
18     let view
19     if (item) {
20       const title = <span>
21         { t('asset.asset') }
22         <code>{item.alias ? item.alias :item.id}</code>
23       </span>
24
25       const time = (item.limitHeight-this.props.blockHeight) *2.5
26       let assetLabel
27       if(this.props.blockHeight<item.limitHeight){
28         assetLabel = <span className='text-danger'>{t('asset.issuableLabel',{time:time})}</span>
29       }else if(item.limitHeight>0){
30         assetLabel = <span className='text-danger'>{t('asset.noIssuableLabel')}</span>
31       }
32
33       view = <div className={componentClassNames(this)}>
34         <PageTitle
35           title={title}
36           actions={[
37             item.id!==btmID && <Link key='create-asset-btn' className='btn btn-link' to={`/transactions/create?type=issueAsset&alias=${item.alias}`}>{t('transaction.issue.issueAsset')}</Link>,
38           ]}
39         />
40
41         <PageContent>
42           <KeyValueTable
43             id={item.id}
44             object='asset'
45             title={t('form.detail')}
46             actions={[
47               <RawJsonButton key='raw-json' item={item} />
48             ]}
49             items={[
50               {label: 'ID', value: item.id},
51               {label: t('form.alias'), value: item.alias, editUrl: item.alias === 'BTM' ? null : `/assets/${item.id}/alias`},
52               {label: t('form.symbol'), value: item.definition.symbol},
53               {label: t('form.decimals'), value: item.definition.decimals},
54               {label: t('form.reissueTitle'), value:  (item.alias === 'BTM' || item.limitHeight > 0)? 'false ': 'true', note: assetLabel},
55               {label: t('form.xpubs'), value: (item.xpubs || []).length},
56               {label: t('form.quorum'), value: item.quorum},
57               {label: t('asset.additionInfo'), value: item.definition.description},
58             ]}
59           />
60
61           {(item.xpubs || []).map((key, index) =>
62             <KeyValueTable
63               key={index}
64               title={t('asset.xpubs', {id: index + 1})}
65               items={[
66                 {label: t('form.index') , value: index},
67                 {label: t('asset.assetPub') , value: key},
68               ]}
69             />
70           )}
71         </PageContent>
72       </div>
73     }
74     return this.renderIfFound(view)
75   }
76 }
77
78 // Container
79
80 import { connect } from 'react-redux'
81 import actions from 'actions'
82
83 const mapStateToProps = (state, ownProps) => ({
84   item: state.asset.items[ownProps.params.id],
85   blockHeight: state.core.blockHeight
86 })
87
88 const mapDispatchToProps = ( dispatch ) => ({
89   fetchItem: (id) => dispatch(actions.asset.fetchItems({id: `${id}`})),
90   showCirculation: (item) => {
91     let filter = `id='${item.id}'`
92     if (item.alias) {
93       filter = `alias='${item.alias}'`
94     }
95
96     dispatch(actions.balance.pushList({ filter }))
97   },
98 })
99
100
101 export default withNamespaces('translations') ( connect(
102   mapStateToProps,
103   mapDispatchToProps
104 )(AssetShow))