This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2266 from ethcore/ng-tokenreg-queries
Dapp - Tokereg ; Query Tokens from TLA or Address
- Loading branch information
Showing
12 changed files
with
535 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default from './query'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
import { Dialog, FlatButton, SelectField, MenuItem } from 'material-ui'; | ||
|
||
import InputText from '../../Inputs/Text'; | ||
import Loading from '../../Loading'; | ||
import Token from '../../Tokens/Token'; | ||
|
||
import { SIMPLE_TOKEN_ADDRESS_TYPE, SIMPLE_TLA_TYPE } from '../../Inputs/validation'; | ||
|
||
import styles from '../actions.css'; | ||
|
||
const initState = { | ||
queryKey: 'tla', | ||
form: { | ||
valid: false, | ||
value: '' | ||
} | ||
}; | ||
|
||
export default class QueryAction extends Component { | ||
|
||
static propTypes = { | ||
show: PropTypes.bool.isRequired, | ||
onClose: PropTypes.func.isRequired, | ||
handleQueryToken: PropTypes.func.isRequired, | ||
handleQueryMetaLookup: PropTypes.func.isRequired, | ||
|
||
loading: PropTypes.bool.isRequired, | ||
data: PropTypes.object, | ||
notFound: PropTypes.bool, | ||
metaLoading: PropTypes.bool, | ||
metaData: PropTypes.object | ||
} | ||
|
||
state = initState; | ||
|
||
render () { | ||
return ( | ||
<Dialog | ||
title={ 'search for a token' } | ||
open={ this.props.show } | ||
className={ styles.dialog } | ||
onRequestClose={ this.onClose } | ||
actions={ this.renderActions() } > | ||
{ this.renderContent() } | ||
</Dialog> | ||
); | ||
} | ||
|
||
renderActions () { | ||
let { loading, data, notFound } = this.props; | ||
|
||
if (loading) { | ||
return ( | ||
<FlatButton | ||
label='Loading...' | ||
primary | ||
disabled /> | ||
); | ||
} | ||
|
||
let complete = data || notFound; | ||
|
||
if (complete) { | ||
return ([ | ||
<FlatButton | ||
label='Close' | ||
primary | ||
onTouchTap={ this.onClose } /> | ||
]); | ||
} | ||
|
||
const isValid = this.state.form.valid; | ||
|
||
return ([ | ||
<FlatButton | ||
label='Cancel' | ||
primary | ||
onTouchTap={ this.onClose } />, | ||
<FlatButton | ||
label='Query' | ||
primary | ||
disabled={ !isValid } | ||
onTouchTap={ this.onQuery } /> | ||
]); | ||
} | ||
|
||
renderContent () { | ||
let { loading, notFound, data } = this.props; | ||
|
||
if (loading) { | ||
return ( | ||
<Loading size={ 1 } /> | ||
); | ||
} | ||
|
||
if (notFound) { | ||
return ( | ||
<p>No token has been found in the registry...</p> | ||
); | ||
} | ||
|
||
if (data) { | ||
return this.renderData(); | ||
} | ||
|
||
return this.renderForm(); | ||
} | ||
|
||
renderData () { | ||
let { data } = this.props; | ||
|
||
return ( | ||
<Token | ||
fullWidth | ||
handleMetaLookup={ this.props.handleQueryMetaLookup } | ||
isMetaLoading={ this.props.metaLoading } | ||
meta={ this.props.metaData } | ||
{ ...data } | ||
/> | ||
); | ||
} | ||
|
||
renderForm () { | ||
return ( | ||
<div> | ||
<SelectField | ||
floatingLabelText='Select which field to query' | ||
fullWidth | ||
value={ this.state.queryKey } | ||
onChange={ this.onQueryKeyChange }> | ||
<MenuItem value='tla' label='TLA' primaryText='TLA' /> | ||
<MenuItem value='address' label='Address' primaryText='Address' /> | ||
</SelectField> | ||
|
||
{ | ||
this.state.queryKey !== 'tla' | ||
? (<InputText | ||
key={ 0 } | ||
|
||
floatingLabelText="Token's address" | ||
hintText='0xdeadbeef...' | ||
|
||
validationType={ SIMPLE_TOKEN_ADDRESS_TYPE } | ||
onChange={ this.onChange } />) | ||
: (<InputText | ||
key={ 1 } | ||
|
||
floatingLabelText="Token's TLA" | ||
hintText='GAV' | ||
|
||
validationType={ SIMPLE_TLA_TYPE } | ||
onChange={ this.onChange } />) | ||
} | ||
</div> | ||
); | ||
} | ||
|
||
onQueryKeyChange = (event, index, queryKey) => { | ||
this.setState({ | ||
queryKey, | ||
form: { valid: false, value: '' } | ||
}); | ||
} | ||
|
||
onChange = (valid, value) => { | ||
this.setState({ | ||
form: { | ||
valid, value | ||
} | ||
}); | ||
} | ||
|
||
onQuery = () => { | ||
let { queryKey, form } = this.state; | ||
|
||
this.props.handleQueryToken(queryKey, form.value); | ||
} | ||
|
||
onClose = () => { | ||
this.setState(initState); | ||
this.props.onClose(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.