Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

gavcoin global import of parity api #2082

Merged
merged 4 commits into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions js/src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -60,6 +61,10 @@ export default class Api {
return format;
}

get util () {
return util;
}

newContract (abi, address) {
return new Contract(this, abi).at(address);
}
Expand Down
9 changes: 9 additions & 0 deletions js/src/api/util/identity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import blockies from 'blockies';

export function createIdentityImg (address, scale = 7) {
return blockies({
seed: (address || '').toLowerCase(),
size: 8,
scale
}).toDataURL();
}
5 changes: 5 additions & 0 deletions js/src/api/util/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createIdentityImg } from './identity';

export default {
createIdentityImg
};
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -31,9 +31,7 @@ export default class AccountItem extends Component {
return (
<div className={ styles.account }>
<div className={ styles.image }>
<IdentityIcon
inline center
address={ account.address } />
<IdentityIcon address={ account.address } />
</div>
<div className={ styles.details }>
<div className={ styles.name }>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = ' ';
Expand Down Expand Up @@ -77,9 +76,7 @@ export default class AccountSelectorText extends Component {

return (
<div className={ styles.addricon }>
<IdentityIcon
inline center
address={ account.address } />
<IdentityIcon address={ account.address } />
</div>
);
}
Expand Down
7 changes: 2 additions & 5 deletions js/src/dapps/gavcoin/Accounts/accounts.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -44,9 +43,7 @@ export default class Accounts extends Component {
<Chip
className={ styles.account }
key={ account.address }>
<IdentityIcon
inline center
address={ account.address } />
<IdentityIcon address={ account.address } />
<span className={ styles.name }>
{ account.name }
</span>
Expand Down
3 changes: 1 addition & 2 deletions js/src/dapps/gavcoin/Actions/ActionBuyIn/actionBuyIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions js/src/dapps/gavcoin/Actions/ActionRefund/actionRefund.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ' ';

Expand Down
2 changes: 1 addition & 1 deletion js/src/dapps/gavcoin/Actions/validation.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
4 changes: 2 additions & 2 deletions js/src/dapps/gavcoin/Application/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions js/src/dapps/gavcoin/Events/Event/event.js
Original file line number Diff line number Diff line change
@@ -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 = (
<td></td>
);
Expand Down Expand Up @@ -55,7 +54,7 @@ export default class Event extends Component {

return (
<td className={ styles.account }>
<IdentityIcon inline center address={ address } />
<IdentityIcon address={ address } />
{ this.renderAddressName(address) }
</td>
);
Expand Down
4 changes: 2 additions & 2 deletions js/src/dapps/gavcoin/Events/events.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { Component, PropTypes } from 'react';

import { api } from '../parity';

import EventBuyin from './EventBuyin';
import EventNewTranch from './EventNewTranch';
import EventRefund from './EventRefund';
import EventTransfer from './EventTransfer';

import styles from './events.css';

const { api } = window.parity;

export default class Events extends Component {
static childContextTypes = {
accounts: PropTypes.array
Expand Down
6 changes: 6 additions & 0 deletions js/src/dapps/gavcoin/IdentityIcon/identityIcon.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.icon {
width: 32px;
height: 32px;
border-radius: 50%;
margin-right: 0.5em;
}
20 changes: 20 additions & 0 deletions js/src/dapps/gavcoin/IdentityIcon/identityIcon.js
Original file line number Diff line number Diff line change
@@ -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 (
<img
className={ styles.icon }
src={ api.util.createIdentityImg(address, 4) } />
);
}
}
1 change: 1 addition & 0 deletions js/src/dapps/gavcoin/IdentityIcon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default from './identityIcon';
2 changes: 1 addition & 1 deletion js/src/dapps/gavcoin/format/index.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
5 changes: 5 additions & 0 deletions js/src/dapps/gavcoin/parity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { api } = window.parity;

export {
api
};
18 changes: 9 additions & 9 deletions js/src/ui/IdentityIcon/identityIcon.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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) {
Expand All @@ -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];

Expand All @@ -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)
});
}

Expand Down