diff --git a/js/src/api/api.js b/js/src/api/api.js index 2efe426329b..57dc23155a6 100644 --- a/js/src/api/api.js +++ b/js/src/api/api.js @@ -4,6 +4,7 @@ import Contract from './contract/index'; import { Db, Eth, Ethcore, Net, Personal, Shh, Trace, Web3 } from './rpc/index'; import Subscriptions from './subscriptions/index'; import format from './format/index'; +import util from './util/index'; import { isFunction } from './util/types'; export default class Api { @@ -60,6 +61,10 @@ export default class Api { return format; } + get util () { + return util; + } + newContract (abi, address) { return new Contract(this, abi).at(address); } diff --git a/js/src/api/util/identity.js b/js/src/api/util/identity.js new file mode 100644 index 00000000000..82da7d7dfaa --- /dev/null +++ b/js/src/api/util/identity.js @@ -0,0 +1,9 @@ +import blockies from 'blockies'; + +export function createIdentityImg (address, scale = 7) { + return blockies({ + seed: (address || '').toLowerCase(), + size: 8, + scale + }).toDataURL(); +} diff --git a/js/src/api/util/index.js b/js/src/api/util/index.js new file mode 100644 index 00000000000..9ede0386c71 --- /dev/null +++ b/js/src/api/util/index.js @@ -0,0 +1,5 @@ +import { createIdentityImg } from './identity'; + +export default { + createIdentityImg +}; diff --git a/js/src/dapps/gavcoin/AccountSelector/AccountItem/accountItem.js b/js/src/dapps/gavcoin/AccountSelector/AccountItem/accountItem.js index 1db0fba782a..7a5782f33ca 100644 --- a/js/src/dapps/gavcoin/AccountSelector/AccountItem/accountItem.js +++ b/js/src/dapps/gavcoin/AccountSelector/AccountItem/accountItem.js @@ -1,8 +1,8 @@ import React, { Component, PropTypes } from 'react'; -import styles from './accountItem.css'; +import IdentityIcon from '../../IdentityIcon'; -const { IdentityIcon } = window.parity.react; +import styles from './accountItem.css'; export default class AccountItem extends Component { static propTypes = { @@ -31,9 +31,7 @@ export default class AccountItem extends Component { return (
- +
diff --git a/js/src/dapps/gavcoin/AccountSelectorText/accountSelectorText.js b/js/src/dapps/gavcoin/AccountSelectorText/accountSelectorText.js index 2ffff55cec0..19ed6a57390 100644 --- a/js/src/dapps/gavcoin/AccountSelectorText/accountSelectorText.js +++ b/js/src/dapps/gavcoin/AccountSelectorText/accountSelectorText.js @@ -1,10 +1,9 @@ import React, { Component, PropTypes } from 'react'; import { TextField } from 'material-ui'; +import IdentityIcon from '../IdentityIcon'; import AccountSelector from '../AccountSelector'; -const { IdentityIcon } = window.parity.react; - import styles from './accountSelectorText.css'; const NAME_ID = ' '; @@ -77,9 +76,7 @@ export default class AccountSelectorText extends Component { return (
- +
); } diff --git a/js/src/dapps/gavcoin/Accounts/accounts.js b/js/src/dapps/gavcoin/Accounts/accounts.js index c24ab8814f2..624d12e585d 100644 --- a/js/src/dapps/gavcoin/Accounts/accounts.js +++ b/js/src/dapps/gavcoin/Accounts/accounts.js @@ -1,8 +1,7 @@ import React, { Component, PropTypes } from 'react'; - import { Chip } from 'material-ui'; -const { IdentityIcon } = window.parity.react; +import IdentityIcon from '../IdentityIcon'; import styles from './accounts.css'; @@ -44,9 +43,7 @@ export default class Accounts extends Component { - + { account.name } diff --git a/js/src/dapps/gavcoin/Actions/ActionBuyIn/actionBuyIn.js b/js/src/dapps/gavcoin/Actions/ActionBuyIn/actionBuyIn.js index 2575ca641f1..332461f7875 100644 --- a/js/src/dapps/gavcoin/Actions/ActionBuyIn/actionBuyIn.js +++ b/js/src/dapps/gavcoin/Actions/ActionBuyIn/actionBuyIn.js @@ -3,14 +3,13 @@ import React, { Component, PropTypes } from 'react'; import { Dialog, FlatButton, TextField } from 'material-ui'; +import { api } from '../../parity'; import AccountSelector from '../../AccountSelector'; import StepComplete from '../StepComplete'; import { ERRORS, validateAccount, validatePositiveNumber } from '../validation'; import styles from '../actions.css'; -const { api } = window.parity; - const NAME_ID = ' '; export default class ActionBuyIn extends Component { diff --git a/js/src/dapps/gavcoin/Actions/ActionRefund/actionRefund.js b/js/src/dapps/gavcoin/Actions/ActionRefund/actionRefund.js index 983d171c3ce..cde2bcf4210 100644 --- a/js/src/dapps/gavcoin/Actions/ActionRefund/actionRefund.js +++ b/js/src/dapps/gavcoin/Actions/ActionRefund/actionRefund.js @@ -3,14 +3,13 @@ import React, { Component, PropTypes } from 'react'; import { Dialog, FlatButton, TextField } from 'material-ui'; +import { api } from '../../parity'; import AccountSelector from '../../AccountSelector'; import StepComplete from '../StepComplete'; import { ERRORS, validateAccount, validatePositiveNumber } from '../validation'; import styles from '../actions.css'; -const { api } = window.parity; - const DIVISOR = 10 ** 6; const NAME_ID = ' '; diff --git a/js/src/dapps/gavcoin/Actions/validation.js b/js/src/dapps/gavcoin/Actions/validation.js index 4f1350aaec9..f6e35af06b1 100644 --- a/js/src/dapps/gavcoin/Actions/validation.js +++ b/js/src/dapps/gavcoin/Actions/validation.js @@ -1,6 +1,6 @@ import BigNumber from 'bignumber.js'; -const { api } = window.parity; +import { api } from '../parity'; export const ERRORS = { invalidAccount: 'please select an account to transact with', diff --git a/js/src/dapps/gavcoin/Application/application.js b/js/src/dapps/gavcoin/Application/application.js index c8f15d6ddd3..153281f56c9 100644 --- a/js/src/dapps/gavcoin/Application/application.js +++ b/js/src/dapps/gavcoin/Application/application.js @@ -6,6 +6,8 @@ import lightBaseTheme from 'material-ui/styles/baseThemes/lightBaseTheme'; const muiTheme = getMuiTheme(lightBaseTheme); +import { api } from '../parity'; + import registryAbi from '../abi/registry.json'; import gavcoinAbi from '../abi/gavcoin.json'; @@ -15,8 +17,6 @@ import Events from '../Events'; import Loading from '../Loading'; import Status from '../Status'; -const { api } = window.parity; - const DIVISOR = 10 ** 6; export default class Application extends Component { diff --git a/js/src/dapps/gavcoin/Events/Event/event.js b/js/src/dapps/gavcoin/Events/Event/event.js index ddd814c18f8..70830658608 100644 --- a/js/src/dapps/gavcoin/Events/Event/event.js +++ b/js/src/dapps/gavcoin/Events/Event/event.js @@ -1,11 +1,10 @@ import React, { Component, PropTypes } from 'react'; +import IdentityIcon from '../../IdentityIcon'; import { formatBlockNumber, formatCoins, formatEth } from '../../format'; import styles from '../events.css'; -const { IdentityIcon } = window.parity.react; - const EMPTY_COLUMN = ( ); @@ -55,7 +54,7 @@ export default class Event extends Component { return ( - + { this.renderAddressName(address) } ); diff --git a/js/src/dapps/gavcoin/Events/events.js b/js/src/dapps/gavcoin/Events/events.js index 22cca8841a6..9cd9e7909f3 100644 --- a/js/src/dapps/gavcoin/Events/events.js +++ b/js/src/dapps/gavcoin/Events/events.js @@ -1,5 +1,7 @@ import React, { Component, PropTypes } from 'react'; +import { api } from '../parity'; + import EventBuyin from './EventBuyin'; import EventNewTranch from './EventNewTranch'; import EventRefund from './EventRefund'; @@ -7,8 +9,6 @@ import EventTransfer from './EventTransfer'; import styles from './events.css'; -const { api } = window.parity; - export default class Events extends Component { static childContextTypes = { accounts: PropTypes.array diff --git a/js/src/dapps/gavcoin/IdentityIcon/identityIcon.css b/js/src/dapps/gavcoin/IdentityIcon/identityIcon.css new file mode 100644 index 00000000000..b2795dff158 --- /dev/null +++ b/js/src/dapps/gavcoin/IdentityIcon/identityIcon.css @@ -0,0 +1,6 @@ +.icon { + width: 32px; + height: 32px; + border-radius: 50%; + margin-right: 0.5em; +} diff --git a/js/src/dapps/gavcoin/IdentityIcon/identityIcon.js b/js/src/dapps/gavcoin/IdentityIcon/identityIcon.js new file mode 100644 index 00000000000..81c7abcd737 --- /dev/null +++ b/js/src/dapps/gavcoin/IdentityIcon/identityIcon.js @@ -0,0 +1,20 @@ +import React, { Component, PropTypes } from 'react'; + +import { api } from '../parity'; +import styles from './identityIcon.css'; + +export default class IdentityIcon extends Component { + static propTypes = { + address: PropTypes.string.isRequired + } + + render () { + const { address } = this.props; + + return ( + + ); + } +} diff --git a/js/src/dapps/gavcoin/IdentityIcon/index.js b/js/src/dapps/gavcoin/IdentityIcon/index.js new file mode 100644 index 00000000000..51b592d3146 --- /dev/null +++ b/js/src/dapps/gavcoin/IdentityIcon/index.js @@ -0,0 +1 @@ +export default from './identityIcon'; diff --git a/js/src/dapps/gavcoin/format/index.js b/js/src/dapps/gavcoin/format/index.js index c7244c0285d..c20f7ce725b 100644 --- a/js/src/dapps/gavcoin/format/index.js +++ b/js/src/dapps/gavcoin/format/index.js @@ -1,6 +1,6 @@ import BigNumber from 'bignumber.js'; -const { api } = window.parity; +import { api } from '../parity'; const DIVISOR = 10 ** 6; const ZERO = new BigNumber(0); diff --git a/js/src/dapps/gavcoin/parity.js b/js/src/dapps/gavcoin/parity.js new file mode 100644 index 00000000000..6f3a390f1a2 --- /dev/null +++ b/js/src/dapps/gavcoin/parity.js @@ -0,0 +1,5 @@ +const { api } = window.parity; + +export { + api +}; diff --git a/js/src/ui/IdentityIcon/identityIcon.js b/js/src/ui/IdentityIcon/identityIcon.js index a2f8bb72c0f..9f48233fece 100644 --- a/js/src/ui/IdentityIcon/identityIcon.js +++ b/js/src/ui/IdentityIcon/identityIcon.js @@ -1,9 +1,12 @@ import React, { Component, PropTypes } from 'react'; -import blockies from 'blockies'; import styles from './identityIcon.css'; export default class IdentityIcon extends Component { + static contextTypes = { + api: PropTypes.object.isRequired + } + static propTypes = { address: PropTypes.string, className: PropTypes.string, @@ -18,7 +21,9 @@ export default class IdentityIcon extends Component { } componentDidMount () { - this.updateIcon(this.props.address); + const { address } = this.props; + + this.updateIcon(address); } componentWillReceiveProps (newProps) { @@ -32,6 +37,7 @@ export default class IdentityIcon extends Component { } updateIcon (_address) { + const { api } = this.context; const { tokens, inline } = this.props; const token = (tokens || {})[_address]; @@ -43,14 +49,8 @@ export default class IdentityIcon extends Component { return; } - const address = _address.toLowerCase(); - this.setState({ - iconsrc: blockies({ - seed: address, - size: 8, - scale: inline ? 4 : 7 - }).toDataURL() + iconsrc: api.util.createIdentityImg(_address, inline ? 4 : 7) }); }