Goodbye Gavcoin, Hello Gavcoin (#3080)

This commit is contained in:
Jaco Greeff 2016-11-02 11:27:47 +01:00 committed by Gav Wood
parent 274b109f3f
commit 0912160220
54 changed files with 0 additions and 2888 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

View File

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="icon" href="/parity-logo-black-no-text.png" type="image/png">
<title>GAVcoin</title>
</head>
<body>
<div id="container"></div>
<script src="vendor.js"></script>
<script src="commons.js"></script>
<script src="/parity-utils/parity.js"></script>
<script src="gavcoin.js"></script>
</body>
</html>

View File

@ -1,33 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import ReactDOM from 'react-dom';
import React from 'react';
import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin();
import Application from './gavcoin/Application';
import '../../assets/fonts/Roboto/font.css';
import '../../assets/fonts/RobotoMono/font.css';
import './style.css';
import './gavcoin.html';
ReactDOM.render(
<Application />,
document.querySelector('#container')
);

View File

@ -1,45 +0,0 @@
/* Copyright 2015, 2016 Ethcore (UK) Ltd.
/* This file is part of Parity.
/*
/* Parity is free software: you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published by
/* the Free Software Foundation, either version 3 of the License, or
/* (at your option) any later version.
/*
/* Parity is distributed in the hope that it will be useful,
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/
.account {
padding: 4px 0 !important;
display: inline-block;
}
.name {
display: inline-block;
margin-right: 1em;
text-transform: uppercase;
}
.balance {
display: inline-block;
text-align: right;
color: #aaa;
font-family: 'Roboto Mono', monospace;
}
.details {
display: inline-block;
}
.image {
display: inline-block;
}
.image img {
margin: 0 1em -11px 0;
}

View File

@ -1,63 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import IdentityIcon from '../../IdentityIcon';
import styles from './accountItem.css';
export default class AccountItem extends Component {
static propTypes = {
account: PropTypes.object,
gavBalance: PropTypes.bool
};
render () {
const { account, gavBalance } = this.props;
let balance;
let token;
if (gavBalance) {
if (account.gavBalance) {
balance = account.gavBalance;
token = 'GAV';
}
} else {
if (account.ethBalance) {
balance = account.ethBalance;
token = 'ETH';
}
}
return (
<div className={ styles.account }>
<div className={ styles.image }>
<IdentityIcon address={ account.address } />
</div>
<div className={ styles.details }>
<div className={ styles.name }>
{ account.name || account.address }
</div>
<div className={ styles.balance }>
{ balance }<small> { token }</small>
</div>
</div>
</div>
);
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './accountItem';

View File

@ -1,102 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react';
import { MenuItem, SelectField } from 'material-ui';
import AccountItem from './AccountItem';
const NAME_ID = ' ';
let lastSelectedAccount = {};
export default class AccountSelect extends Component {
static propTypes = {
accounts: PropTypes.array,
account: PropTypes.object,
anyAccount: PropTypes.bool,
gavBalance: PropTypes.bool,
onSelect: PropTypes.func,
errorText: PropTypes.string,
floatingLabelText: PropTypes.string,
hintText: PropTypes.string
}
componentDidMount () {
this.props.onSelect(lastSelectedAccount);
}
render () {
const { account, accounts, anyAccount, errorText, floatingLabelText, gavBalance, hintText } = this.props;
return (
<SelectField
autoComplete='off'
floatingLabelFixed
floatingLabelText={ floatingLabelText }
fullWidth
hintText={ hintText }
errorText={ errorText }
name={ NAME_ID }
id={ NAME_ID }
value={ account }
onChange={ this.onSelect }>
{ renderAccounts(accounts, { anyAccount, gavBalance }) }
</SelectField>
);
}
onSelect = (event, idx, account) => {
lastSelectedAccount = account || {};
this.props.onSelect(lastSelectedAccount);
}
}
function isPositive (numberStr) {
return new BigNumber(numberStr.replace(',', '')).gt(0);
}
export function renderAccounts (accounts, options = {}) {
return accounts
.filter((account) => {
if (options.anyAccount) {
return true;
}
if (account.uuid) {
return isPositive(account[options.gavBalance ? 'gavBalance' : 'ethBalance']);
}
return false;
})
.map((account) => {
const item = (
<AccountItem
account={ account }
key={ account.address }
gavBalance={ options.gavBalance || false } />
);
return (
<MenuItem
key={ account.address }
value={ account }
label={ item }>
{ item }
</MenuItem>
);
});
}

View File

@ -1,22 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { renderAccounts } from './accountSelector';
export default from './accountSelector';
export {
renderAccounts
};

View File

@ -1,28 +0,0 @@
/* Copyright 2015, 2016 Ethcore (UK) Ltd.
/* This file is part of Parity.
/*
/* Parity is free software: you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published by
/* the Free Software Foundation, either version 3 of the License, or
/* (at your option) any later version.
/*
/* Parity is distributed in the hope that it will be useful,
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/
.addrtext {
position: relative;
}
.input input {
padding-left: 48px !important;
}
.addricon {
position: absolute;
top: 37px;
}

View File

@ -1,106 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import { TextField } from 'material-ui';
import IdentityIcon from '../IdentityIcon';
import AccountSelector from '../AccountSelector';
import styles from './accountSelectorText.css';
const NAME_ID = ' ';
export default class AccountSelectorText extends Component {
static propTypes = {
accounts: PropTypes.array,
account: PropTypes.object,
errorText: PropTypes.string,
gavBalance: PropTypes.bool,
anyAccount: PropTypes.bool,
floatingLabelText: PropTypes.string,
hintText: PropTypes.string,
selector: PropTypes.bool,
onChange: PropTypes.func
}
render () {
const { selector } = this.props;
return selector
? this.renderDropDown()
: this.renderTextField();
}
renderDropDown () {
const { account, accounts, anyAccount, errorText, gavBalance, hintText, floatingLabelText, onChange } = this.props;
return (
<AccountSelector
anyAccount={ anyAccount }
gavBalance={ gavBalance }
accounts={ accounts }
account={ account }
errorText={ errorText }
floatingLabelText={ floatingLabelText }
hintText={ hintText }
onSelect={ onChange } />
);
}
renderTextField () {
const { account, errorText, hintText, floatingLabelText } = this.props;
return (
<div className={ styles.addrtext }>
<TextField
className={ styles.input }
autoComplete='off'
floatingLabelFixed
floatingLabelText={ floatingLabelText }
fullWidth
hintText={ hintText }
errorText={ errorText }
name={ NAME_ID }
id={ NAME_ID }
value={ account.address || '' }
onChange={ this.onChangeAddress } />
{ this.renderAddressIcon() }
</div>
);
}
renderAddressIcon () {
const { account } = this.props;
if (!account.address) {
return null;
}
return (
<div className={ styles.addricon }>
<IdentityIcon address={ account.address } />
</div>
);
}
onChangeAddress = (event, address) => {
const lower = address.toLowerCase();
const account = this.props.accounts.find((_account) => _account.address.toLowerCase() === lower);
this.props.onChange(account || { address });
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './accountSelectorText';

View File

@ -1,47 +0,0 @@
/* Copyright 2015, 2016 Ethcore (UK) Ltd.
/* This file is part of Parity.
/*
/* Parity is free software: you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published by
/* the Free Software Foundation, either version 3 of the License, or
/* (at your option) any later version.
/*
/* Parity is distributed in the hope that it will be useful,
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/
.accounts {
padding: 4em 2em 0 2em;
text-align: center;
width: 100%;
}
.account {
margin: 0.5em !important;
background: #430 !important;
display: inline-block !important;
}
.account img {
margin-bottom: -11px;
margin-left: -11px;
}
.balance {
font-family: 'Roboto Mono', monospace;
color: rgba(255, 255, 255, 1) !important;
}
.name {
color: rgba(255, 255, 255, 0.7) !important;
margin-right: 1em;
text-transform: uppercase;
}
.none {
color: rgba(255, 255, 255, 0.7);
}

View File

@ -1,83 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import { Chip } from 'material-ui';
import IdentityIcon from '../IdentityIcon';
import styles from './accounts.css';
export default class Accounts extends Component {
static contextTypes = {
api: PropTypes.object.isRequired,
instance: PropTypes.object.isRequired
}
static propTypes = {
accounts: PropTypes.array
}
render () {
const has = this._hasAccounts();
return (
<div className={ styles.accounts }>
{ has ? this.renderAccounts() : this.renderEmpty() }
</div>
);
}
renderEmpty () {
return (
<div className={ styles.none }>
You currently do not have any GAVcoin in any of your addresses, buy some
</div>
);
}
renderAccounts () {
const { accounts } = this.props;
return accounts
.filter((account) => account.hasGav)
.map((account) => {
return (
<Chip
className={ styles.account }
key={ account.address }>
<IdentityIcon address={ account.address } />
<span className={ styles.name }>
{ account.name }
</span>
<span className={ styles.balance }>
{ account.gavBalance }
</span>
</Chip>
);
});
}
_hasAccounts () {
const { accounts } = this.props;
if (!accounts || !accounts.length) {
return false;
}
return accounts.filter((account) => account.hasGav).length !== 0;
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './accounts';

View File

@ -1,209 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react';
import { Dialog, FlatButton, TextField } from 'material-ui';
import { api } from '../../parity';
import AccountSelector from '../../AccountSelector';
import { ERRORS, validateAccount, validatePositiveNumber } from '../validation';
import styles from '../actions.css';
const NAME_ID = ' ';
export default class ActionBuyIn extends Component {
static contextTypes = {
instance: PropTypes.object.isRequired
}
static propTypes = {
accounts: PropTypes.array,
price: PropTypes.object,
onClose: PropTypes.func
}
state = {
account: {},
accountError: ERRORS.invalidAccount,
amount: 0,
amountError: ERRORS.invalidAmount,
maxPrice: api.util.fromWei(this.props.price.mul(1.2)).toFixed(0),
maxPriceError: null,
sending: false,
complete: false
}
render () {
const { complete } = this.state;
if (complete) {
return null;
}
return (
<Dialog
title='buy coins for a specific account'
modal open
className={ styles.dialog }
actions={ this.renderActions() }>
{ this.renderFields() }
</Dialog>
);
}
renderActions () {
const { complete } = this.state;
if (complete) {
return (
<FlatButton
className={ styles.dlgbtn }
label='Done'
primary
onTouchTap={ this.props.onClose } />
);
}
const { accountError, amountError, maxPriceError, sending } = this.state;
const hasError = !!(amountError || accountError || maxPriceError);
return ([
<FlatButton
className={ styles.dlgbtn }
label='Cancel'
primary
onTouchTap={ this.props.onClose } />,
<FlatButton
className={ styles.dlgbtn }
label='Buy'
primary
disabled={ hasError || sending }
onTouchTap={ this.onSend } />
]);
}
renderFields () {
const maxPriceLabel = `maximum price in ETH (current ${api.util.fromWei(this.props.price).toFormat(3)})`;
return (
<div>
<AccountSelector
accounts={ this.props.accounts }
account={ this.state.account }
errorText={ this.state.accountError }
floatingLabelText='from account'
hintText='the account the transaction will be made from'
onSelect={ this.onChangeAddress } />
<TextField
autoComplete='off'
floatingLabelFixed
floatingLabelText='amount in ETH'
fullWidth
hintText='the amount of ETH you wish to spend'
errorText={ this.state.amountError }
name={ NAME_ID }
id={ NAME_ID }
value={ this.state.amount }
onChange={ this.onChangeAmount } />
<TextField
autoComplete='off'
floatingLabelFixed
floatingLabelText={ maxPriceLabel }
fullWidth
hintText='the maxium price allowed for buying'
errorText={ this.state.maxPriceError }
name={ NAME_ID }
id={ NAME_ID }
value={ this.state.maxPrice }
onChange={ this.onChangeMaxPrice } />
</div>
);
}
onChangeAddress = (account) => {
this.setState({
account,
accountError: validateAccount(account)
}, this.validateTotal);
}
onChangeAmount = (event, amount) => {
this.setState({
amount,
amountError: validatePositiveNumber(amount)
}, this.validateTotal);
}
onChangeMaxPrice = (event, maxPrice) => {
this.setState({
maxPrice,
maxPriceError: validatePositiveNumber(maxPrice)
});
}
validateTotal = () => {
const { account, accountError, amount, amountError } = this.state;
if (accountError || amountError) {
return;
}
if (new BigNumber(amount).gt(account.ethBalance.replace(',', ''))) {
this.setState({
amountError: ERRORS.invalidTotal
});
}
}
onSend = () => {
const { instance } = this.context;
const maxPrice = api.util.toWei(this.state.maxPrice);
const values = [this.state.account.address, maxPrice.toString()];
const options = {
from: this.state.account.address,
value: api.util.toWei(this.state.amount).toString()
};
this.setState({
sending: true
});
instance.buyin
.estimateGas(options, values)
.then((gasEstimate) => {
options.gas = gasEstimate.mul(1.2).toFixed(0);
console.log(`buyin: gas estimated as ${gasEstimate.toFixed(0)} setting to ${options.gas}`);
return instance.buyin.postTransaction(options, values);
})
.then(() => {
this.props.onClose();
this.setState({
sending: false,
complete: true
});
})
.catch((error) => {
console.error('error', error);
this.setState({
sending: false
});
});
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './actionBuyIn';

View File

@ -1,194 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react';
import { Dialog, FlatButton, TextField } from 'material-ui';
import { api } from '../../parity';
import AccountSelector from '../../AccountSelector';
import { ERRORS, validateAccount, validatePositiveNumber } from '../validation';
import styles from '../actions.css';
const DIVISOR = 10 ** 6;
const NAME_ID = ' ';
export default class ActionRefund extends Component {
static contextTypes = {
instance: PropTypes.object.isRequired
}
static propTypes = {
accounts: PropTypes.array,
price: PropTypes.object,
onClose: PropTypes.func
}
state = {
account: {},
accountError: ERRORS.invalidAccount,
complete: false,
sending: false,
amount: 0,
amountError: ERRORS.invalidAmount,
price: api.util.fromWei(this.props.price).toString(),
priceError: null
}
render () {
const { complete } = this.state;
if (complete) {
return null;
}
return (
<Dialog
title='return coins for a refund'
modal open
className={ styles.dialog }
actions={ this.renderActions() }>
{ this.renderFields() }
</Dialog>
);
}
renderActions () {
if (this.state.complete) {
return (
<FlatButton
className={ styles.dlgbtn }
label='Done'
primary
onTouchTap={ this.props.onClose } />
);
}
const hasError = !!(this.state.priceError || this.state.amountError || this.state.accountError);
return ([
<FlatButton
className={ styles.dlgbtn }
label='Cancel'
primary
onTouchTap={ this.props.onClose } />,
<FlatButton
className={ styles.dlgbtn }
label='Refund'
primary
disabled={ hasError || this.state.sending }
onTouchTap={ this.onSend } />
]);
}
renderFields () {
const priceLabel = `price in ETH (current ${api.util.fromWei(this.props.price).toFormat(3)})`;
return (
<div>
<AccountSelector
gavBalance
accounts={ this.props.accounts }
account={ this.state.account }
errorText={ this.state.accountError }
floatingLabelText='from account'
hintText='the account the transaction will be made from'
onSelect={ this.onChangeAddress } />
<TextField
autoComplete='off'
floatingLabelFixed
floatingLabelText='number of coins'
fullWidth
hintText='the number of coins to exchange for an ETH refund'
errorText={ this.state.amountError }
name={ NAME_ID }
id={ NAME_ID }
value={ this.state.amount }
onChange={ this.onChangeAmount } />
<TextField
autoComplete='off'
floatingLabelFixed
floatingLabelText={ priceLabel }
fullWidth
hintText='the price the refund is requested at'
errorText={ this.state.priceError }
name={ NAME_ID }
id={ NAME_ID }
value={ this.state.price }
onChange={ this.onChangePrice } />
</div>
);
}
onChangeAddress = (account) => {
this.setState({
account,
accountError: validateAccount(account)
});
}
onChangeAmount = (event, amount) => {
this.setState({
amount,
amountError: validatePositiveNumber(amount)
});
}
onChangePrice = (event, price) => {
this.setState({
price,
priceError: validatePositiveNumber(price)
});
}
onSend = () => {
const { instance } = this.context;
const price = api.util.toWei(this.state.price);
const amount = new BigNumber(this.state.amount).mul(DIVISOR);
const values = [price.toString(), amount.toFixed(0)];
const options = {
from: this.state.account.address
};
this.setState({
sending: true
});
instance.refund
.estimateGas(options, values)
.then((gasEstimate) => {
options.gas = gasEstimate.mul(1.2).toFixed(0);
console.log(`refund: gas estimated as ${gasEstimate.toFixed(0)} setting to ${options.gas}`);
return instance.refund.postTransaction(options, values);
})
.then(() => {
this.props.onClose();
this.setState({
sending: false,
complete: true
});
})
.catch((error) => {
console.error('error', error);
this.setState({
sending: false
});
});
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './actionRefund';

View File

@ -1,223 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react';
import { Dialog, FlatButton, TextField, Toggle } from 'material-ui';
import AccountSelector from '../../AccountSelector';
import AccountSelectorText from '../../AccountSelectorText';
import { ERRORS, validateAccount, validatePositiveNumber } from '../validation';
import styles from '../actions.css';
const DIVISOR = 10 ** 6;
const NAME_ID = ' ';
export default class ActionTransfer extends Component {
static contextTypes = {
instance: PropTypes.object.isRequired
}
static propTypes = {
accounts: PropTypes.array,
price: PropTypes.object,
onClose: PropTypes.func
}
state = {
fromAccount: {},
fromAccountError: ERRORS.invalidAccount,
toAccount: {},
toAccountError: ERRORS.invalidRecipient,
inputAccount: false,
complete: false,
sending: false,
amount: 0,
amountError: ERRORS.invalidAmount
}
render () {
const { complete } = this.state;
if (complete) {
return null;
}
return (
<Dialog
title='send coins to another account'
modal open
className={ styles.dialog }
actions={ this.renderActions() }>
{ this.renderFields() }
</Dialog>
);
}
renderActions () {
const { complete, sending, amountError, fromAccountError, toAccountError } = this.state;
if (complete) {
return (
<FlatButton
className={ styles.dlgbtn }
label='Done'
primary
onTouchTap={ this.props.onClose } />
);
}
const hasError = !!(amountError || fromAccountError || toAccountError);
return ([
<FlatButton
className={ styles.dlgbtn }
label='Cancel'
primary
onTouchTap={ this.props.onClose } />,
<FlatButton
className={ styles.dlgbtn }
label='Transfer'
primary
disabled={ hasError || sending }
onTouchTap={ this.onSend } />
]);
}
renderFields () {
const { accounts } = this.props;
const { fromAccount, fromAccountError, toAccount, toAccountError, inputAccount, amount, amountError } = this.state;
return (
<div>
<AccountSelector
gavBalance
accounts={ accounts }
account={ fromAccount }
errorText={ fromAccountError }
floatingLabelText='from account'
hintText='the account the transaction will be made from'
onSelect={ this.onChangeFromAccount } />
<div className={ styles.overlay }>
<AccountSelectorText
gavBalance anyAccount
selector={ !inputAccount }
accounts={ accounts }
account={ toAccount }
errorText={ toAccountError }
floatingLabelText='to account'
hintText='the account the coins will be sent to'
onChange={ this.onChangeToAccount } />
<Toggle
className={ styles.overlaytoggle }
label='Edit'
labelPosition='right'
toggled={ inputAccount }
onToggle={ this.onChangeToInput } />
</div>
<TextField
autoComplete='off'
floatingLabelFixed
floatingLabelText='number of coins'
fullWidth
hintText='the number of coins to transfer'
errorText={ amountError }
name={ NAME_ID }
id={ NAME_ID }
value={ amount }
onChange={ this.onChangeAmount } />
</div>
);
}
onChangeFromAccount = (fromAccount) => {
this.setState({
fromAccount,
fromAccountError: validateAccount(fromAccount)
}, this.validateTotal);
}
onChangeToAccount = (toAccount) => {
this.setState({
toAccount,
toAccountError: validateAccount(toAccount)
});
}
onChangeToInput = () => {
this.setState({
inputAccount: !this.state.inputAccount
});
}
onChangeAmount = (event, amount) => {
this.setState({
amount,
amountError: validatePositiveNumber(amount)
}, this.validateTotal);
}
validateTotal = () => {
const { fromAccount, fromAccountError, amount, amountError } = this.state;
if (fromAccountError || amountError) {
return;
}
if (new BigNumber(amount).gt(fromAccount.gavBalance.replace(',', ''))) {
this.setState({
amountError: ERRORS.invalidTotal
});
}
}
onSend = () => {
const { instance } = this.context;
const amount = new BigNumber(this.state.amount).mul(DIVISOR);
const values = [this.state.toAccount.address, amount.toFixed(0)];
const options = {
from: this.state.fromAccount.address
};
this.setState({
sending: true
});
instance.transfer
.estimateGas(options, values)
.then((gasEstimate) => {
options.gas = gasEstimate.mul(1.2).toFixed(0);
console.log(`transfer: gas estimated as ${gasEstimate.toFixed(0)} setting to ${options.gas}`);
return instance.transfer.postTransaction(options, values);
})
.then(() => {
this.props.onClose();
this.setState({
sending: false,
complete: true
});
})
.catch((error) => {
console.error('error', error);
this.setState({
sending: false
});
});
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './actionTransfer';

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './stepComplete';

View File

@ -1,29 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component } from 'react';
import styles from '../actions.css';
export default class StepComplete extends Component {
render () {
return (
<div className={ styles.dialogtext }>
Your transaction has been posted. Please visit the <a href='http://127.0.0.1:8080/#/signer' className={ styles.link } target='_blank'>Parity Signer</a> to authenticate the transfer.
</div>
);
}
}

View File

@ -1,83 +0,0 @@
/* Copyright 2015, 2016 Ethcore (UK) Ltd.
/* This file is part of Parity.
/*
/* Parity is free software: you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published by
/* the Free Software Foundation, either version 3 of the License, or
/* (at your option) any later version.
/*
/* Parity is distributed in the hope that it will be useful,
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/
.actions {
text-align: center;
padding: 2em 0 0 0;
width: 100%;
}
.button {
margin: 0 0.5em;
}
.button button {
background-color: #430 !important;
height: 56px !important;
padding: 0 10px !important;
}
.button button[disabled] {
opacity: 0.25;
}
.dlgbtn {
}
.dlgbtn span {
color: #430 !important;
}
.dlgbtn[disabled] {
opacity: 0.25;
}
.dialog {
}
.dialog h3 {
color: #430 !important;
text-transform: uppercase;
}
.dialogtext {
padding-top: 1em;
}
.link, .link:hover, .link:visited {
color: rgb(0, 188, 212);
text-decoration: none;
}
.overlay {
position: relative;
}
.overlay svg {
opacity: 0;
}
.toggle {
text-align: right;
}
.overlaytoggle {
position: absolute !important;
top: 40px;
right: 0;
display: inline-block !important;
width: auto !important;
}

View File

@ -1,76 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import { RaisedButton } from 'material-ui';
import ActionAddShoppingCart from 'material-ui/svg-icons/action/add-shopping-cart';
// import AvReplay from 'material-ui/svg-icons/av/replay';
import ContentSend from 'material-ui/svg-icons/content/send';
import styles from './actions.css';
export default class Actions extends Component {
static propTypes = {
onAction: PropTypes.func.isRequired,
gavBalance: PropTypes.object.isRequired
}
render () {
const { gavBalance } = this.props;
return (
<div className={ styles.actions }>
<RaisedButton
className={ styles.button }
icon={ <ActionAddShoppingCart /> }
label='buy coins'
primary
onTouchTap={ this.onBuyIn } />
<RaisedButton
disabled={ !gavBalance || gavBalance.eq(0) }
className={ styles.button }
icon={ <ContentSend /> }
label='send coins'
primary
onTouchTap={ this.onTransfer } />
</div>
);
// <RaisedButton
// className={ styles.button }
// icon={ <AvReplay /> }
// label='claim refund'
// primary
// onTouchTap={ this.onRefund } />
}
onBuyIn = () => {
this.props.onAction('BuyIn');
}
onTransfer = () => {
const { gavBalance } = this.props;
if (gavBalance && gavBalance.gt(0)) {
this.props.onAction('Transfer');
}
}
onRefund = () => {
this.props.onAction('Refund');
}
}

View File

@ -1,27 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import ActionBuyIn from './ActionBuyIn';
import ActionRefund from './ActionRefund';
import ActionTransfer from './ActionTransfer';
export default from './actions';
export {
ActionBuyIn,
ActionRefund,
ActionTransfer
};

View File

@ -1,56 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import BigNumber from 'bignumber.js';
import { api } from '../parity';
export const ERRORS = {
invalidAccount: 'please select an account to transact with',
invalidRecipient: 'please select an account to send to',
invalidAddress: 'the address is not in the correct format',
invalidAmount: 'please enter a positive amount > 0',
invalidTotal: 'the amount is greater than the availale balance'
};
export function validatePositiveNumber (value) {
let bn = null;
try {
bn = new BigNumber(value);
} catch (e) {
}
if (!bn || !bn.gt(0)) {
return ERRORS.invalidAmount;
}
return null;
}
export function validateAccount (account) {
if (!account || !account.address) {
return ERRORS.invalidAccount;
}
if (!api.util.isAddressValid(account.address)) {
return ERRORS.invalidAddress;
}
account.address = api.util.toChecksumAddress(account.address);
return null;
}

View File

@ -1,22 +0,0 @@
/* Copyright 2015, 2016 Ethcore (UK) Ltd.
/* This file is part of Parity.
/*
/* Parity is free software: you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published by
/* the Free Software Foundation, either version 3 of the License, or
/* (at your option) any later version.
/*
/* Parity is distributed in the hope that it will be useful,
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/
.body {
background-size: cover;
background-repeat: no-repeat;
width: 100%;
}

View File

@ -1,249 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import lightBaseTheme from 'material-ui/styles/baseThemes/lightBaseTheme';
const muiTheme = getMuiTheme(lightBaseTheme);
import { api } from '../parity';
import * as abis from '../../../contracts/abi';
import Accounts from '../Accounts';
import Actions, { ActionBuyIn, ActionRefund, ActionTransfer } from '../Actions';
import Events from '../Events';
import Loading from '../Loading';
import Status from '../Status';
import styles from './application.css';
import bgimage from '../../../../assets/images/dapps/gavcoin-bg.jpg';
const bgstyle = {
backgroundImage: `url(${bgimage})`
};
const DIVISOR = 10 ** 6;
export default class Application extends Component {
static childContextTypes = {
api: PropTypes.object,
contract: PropTypes.object,
instance: PropTypes.object,
muiTheme: PropTypes.object
};
state = {
action: null,
address: null,
accounts: [],
accountsInfo: {},
blockNumber: new BigNumber(-1),
ethBalance: new BigNumber(0),
gavBalance: new BigNumber(0),
instance: null,
loading: true,
price: null,
remaining: null,
totalSupply: null
}
componentDidMount () {
this.attachInterface();
}
render () {
const { accounts, accountsInfo, address, blockNumber, gavBalance, loading, price, remaining, totalSupply } = this.state;
if (loading) {
return (
<Loading />
);
}
return (
<div className={ styles.body } style={ bgstyle }>
{ this.renderModals() }
<Status
address={ address }
blockNumber={ blockNumber }
gavBalance={ gavBalance }
price={ price }
remaining={ remaining }
totalSupply={ totalSupply }>
<Accounts
accounts={ accounts } />
</Status>
<Actions
gavBalance={ gavBalance }
onAction={ this.onAction } />
<Events
accountsInfo={ accountsInfo } />
</div>
);
}
renderModals () {
const { action, accounts, price } = this.state;
switch (action) {
case 'BuyIn':
return (
<ActionBuyIn
accounts={ accounts }
price={ price }
onClose={ this.onActionClose } />
);
case 'Refund':
return (
<ActionRefund
accounts={ accounts }
price={ price }
onClose={ this.onActionClose } />
);
case 'Transfer':
return (
<ActionTransfer
accounts={ accounts }
onClose={ this.onActionClose } />
);
default:
return null;
}
}
getChildContext () {
const { contract, instance } = this.state;
return {
api,
contract,
instance,
muiTheme
};
}
onAction = (action) => {
this.setState({
action
});
}
onActionClose = () => {
this.setState({
action: null
});
}
onNewBlockNumber = (_error, blockNumber) => {
const { instance, accounts } = this.state;
if (_error) {
console.error('onNewBlockNumber', _error);
return;
}
Promise
.all([
instance.totalSupply.call(),
instance.remaining.call(),
instance.price.call()
])
.then(([totalSupply, remaining, price]) => {
this.setState({
blockNumber,
totalSupply,
remaining,
price
});
const gavQueries = accounts.map((account) => instance.balanceOf.call({}, [account.address]));
const ethQueries = accounts.map((account) => api.eth.getBalance(account.address));
return Promise.all([
Promise.all(gavQueries),
Promise.all(ethQueries)
]);
})
.then(([gavBalances, ethBalances]) => {
this.setState({
ethBalance: ethBalances.reduce((total, balance) => total.add(balance), new BigNumber(0)),
gavBalance: gavBalances.reduce((total, balance) => total.add(balance), new BigNumber(0)),
accounts: accounts.map((account, idx) => {
const ethBalance = ethBalances[idx];
const gavBalance = gavBalances[idx];
account.ethBalance = api.util.fromWei(ethBalance).toFormat(3);
account.gavBalance = gavBalance.div(DIVISOR).toFormat(6);
account.hasGav = gavBalance.gt(0);
return account;
})
});
})
.catch((error) => {
console.error('onNewBlockNumber', error);
});
}
attachInterface = () => {
api.ethcore
.registryAddress()
.then((registryAddress) => {
console.log(`the registry was found at ${registryAddress}`);
const registry = api.newContract(abis.registry, registryAddress).instance;
return Promise
.all([
registry.getAddress.call({}, [api.util.sha3('gavcoin'), 'A']),
api.eth.accounts(),
api.personal.accountsInfo()
]);
})
.then(([address, addresses, accountsInfo]) => {
accountsInfo = accountsInfo || {};
console.log(`gavcoin was found at ${address}`);
const contract = api.newContract(abis.gavcoin, address);
this.setState({
loading: false,
address,
contract,
accountsInfo,
instance: contract.instance,
accounts: addresses.map((address) => {
const info = accountsInfo[address] || {};
return {
address,
name: info.name,
uuid: info.uuid
};
})
});
api.subscribe('eth_blockNumber', this.onNewBlockNumber);
})
.catch((error) => {
console.error('attachInterface', error);
});
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './application';

View File

@ -1,155 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import moment from 'moment';
import React, { Component, PropTypes } from 'react';
import IdentityIcon from '../../IdentityIcon';
import { formatCoins, formatEth, formatHash } from '../../format';
import styles from '../events.css';
const EMPTY_COLUMN = (
<td></td>
);
export default class Event extends Component {
static contextTypes = {
accountsInfo: PropTypes.object.isRequired,
api: PropTypes.object.isRequired
}
static propTypes = {
event: PropTypes.object,
value: PropTypes.object,
price: PropTypes.object,
fromAddress: PropTypes.string,
toAddress: PropTypes.string
}
state = {
block: null
}
componentDidMount () {
this.loadBlock();
}
render () {
const { event, fromAddress, toAddress, price, value } = this.props;
const { block } = this.state;
const { state, type } = event;
const cls = `${styles.event} ${styles[state]} ${styles[type.toLowerCase()]}`;
return (
<tr className={ cls }>
{ this.renderTimestamp(block) }
{ this.renderType(type) }
{ this.renderValue(value) }
{ this.renderPrice(price) }
{ this.renderAddress(fromAddress) }
{ this.renderAddress(toAddress) }
</tr>
);
}
renderTimestamp (block) {
return (
<td className={ styles.blocknumber }>
{ !block ? ' ' : moment(block.timestamp).fromNow() }
</td>
);
}
renderAddress (address) {
if (!address) {
return EMPTY_COLUMN;
}
return (
<td className={ styles.account }>
<IdentityIcon address={ address } />
{ this.renderAddressName(address) }
</td>
);
}
renderAddressName (address) {
const { accountsInfo } = this.context;
const account = accountsInfo[address];
if (account && account.name) {
return (
<div className={ styles.name }>
{ account.name }
</div>
);
}
return (
<div className={ styles.address }>
{ formatHash(address) }
</div>
);
}
renderPrice (price) {
if (!price) {
return EMPTY_COLUMN;
}
return (
<td className={ styles.ethvalue }>
{ formatEth(price) }<small> ETH</small>
</td>
);
}
renderValue (value) {
if (!value) {
return EMPTY_COLUMN;
}
return (
<td className={ styles.gavvalue }>
{ formatCoins(value) }<small> GAV</small>
</td>
);
}
renderType (type) {
return (
<td className={ styles.type }>
{ type }
</td>
);
}
loadBlock () {
const { api } = this.context;
const { event } = this.props;
if (!event || !event.blockNumber || event.blockNumber.eq(0)) {
return;
}
api.eth
.getBlockByNumber(event.blockNumber)
.then((block) => {
this.setState({ block });
});
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './event';

View File

@ -1,38 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import Event from '../Event';
export default class EventBuyin extends Component {
static propTypes = {
event: PropTypes.object
}
render () {
const { event } = this.props;
const { buyer, price, amount } = event.params;
return (
<Event
event={ event }
fromAddress={ buyer }
value={ amount }
price={ price } />
);
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './eventBuyin';

View File

@ -1,36 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import Event from '../Event';
export default class EventNewTranch extends Component {
static propTypes = {
event: PropTypes.object
}
render () {
const { event } = this.props;
const { price } = event.params;
return (
<Event
event={ event }
price={ price } />
);
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './eventNewTranch';

View File

@ -1,38 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import Event from '../Event';
export default class EventRefund extends Component {
static propTypes = {
event: PropTypes.object
}
render () {
const { event } = this.props;
const { buyer, price, amount } = event.params;
return (
<Event
event={ event }
fromAddress={ buyer }
value={ amount }
price={ price } />
);
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './eventRefund';

View File

@ -1,38 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import Event from '../Event';
export default class EventTransfer extends Component {
static propTypes = {
event: PropTypes.object
}
render () {
const { event } = this.props;
const { from, to, value } = event.params;
return (
<Event
event={ event }
fromAddress={ from }
toAddress={ to }
value={ value } />
);
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './eventTransfer';

View File

@ -1,101 +0,0 @@
/* Copyright 2015, 2016 Ethcore (UK) Ltd.
/* This file is part of Parity.
/*
/* Parity is free software: you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published by
/* the Free Software Foundation, either version 3 of the License, or
/* (at your option) any later version.
/*
/* Parity is distributed in the hope that it will be useful,
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/
.events {
padding: 4em 2em;
text-align: center;
display: flex;
}
.container {
overflow: auto;
}
.list {
margin: 0 auto;
border: none;
border-spacing: 0;
text-align: left;
}
.list td {
vertical-align: top;
padding: 0.25em 1em;
max-height: 1.5em;
white-space: nowrap;
}
.event {
line-height: 32px;
vertical-align: top;
}
.blocknumber,
.ethvalue,
.gavvalue {
}
.blocknumber,
.gavvalue {
text-align: right;
}
.ethvalue {
text-align: center;
}
.type {
}
.account {
}
.account img {
margin-bottom: -11px;
}
.address {
}
.name {
text-transform: uppercase;
}
.event div {
display: inline;
margin-right: 1em;
vertical-align: top;
}
.mined {
}
.pending {
opacity: 0.5;
}
.buyin {
}
.refund {
}
.transfer {
}
.newtranch {
background: rgba(255, 175, 0, 0.125); /*rgba(68, 51, 0, 0.15);*/
}

View File

@ -1,161 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
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';
export default class Events extends Component {
static childContextTypes = {
accountsInfo: PropTypes.object
}
static contextTypes = {
contract: PropTypes.object.isRequired,
instance: PropTypes.object.isRequired
}
static propTypes = {
accountsInfo: PropTypes.object.isRequired
}
state = {
allEvents: [],
minedEvents: [],
pendingEvents: []
}
componentDidMount () {
this.setupFilters();
}
render () {
return (
<div className={ styles.events }>
<div className={ styles.container }>
<table className={ styles.list }>
<tbody>
{ this.renderEvents() }
</tbody>
</table>
</div>
</div>
);
}
renderEvents () {
const { allEvents } = this.state;
if (!allEvents.length) {
return null;
}
return allEvents
.map((event) => {
switch (event.type) {
case 'Buyin':
return <EventBuyin key={ event.key } event={ event } />;
case 'NewTranch':
return <EventNewTranch key={ event.key } event={ event } />;
case 'Refund':
return <EventRefund key={ event.key } event={ event } />;
case 'Transfer':
return <EventTransfer key={ event.key } event={ event } />;
}
});
}
getChildContext () {
const { accountsInfo } = this.props;
return { accountsInfo };
}
setupFilters () {
const { contract } = this.context;
const sortEvents = (a, b) => b.blockNumber.cmp(a.blockNumber) || b.logIndex.cmp(a.logIndex);
const logToEvent = (log) => {
const key = api.util.sha3(JSON.stringify(log));
const { blockNumber, logIndex, transactionHash, transactionIndex, params, type } = log;
return {
type: log.event,
state: type,
blockNumber,
logIndex,
transactionHash,
transactionIndex,
params: Object.keys(params).reduce((data, name) => {
data[name] = params[name].value;
return data;
}, {}),
key
};
};
const options = {
fromBlock: 0,
toBlock: 'pending',
limit: 50
};
contract.subscribe(null, options, (error, _logs) => {
if (error) {
console.error('setupFilters', error);
return;
}
if (!_logs.length) {
return;
}
const logs = _logs.map(logToEvent);
const minedEvents = logs
.filter((log) => log.state === 'mined')
.reverse()
.concat(this.state.minedEvents)
.sort(sortEvents);
const pendingEvents = logs
.filter((log) => log.state === 'pending')
.reverse()
.concat(this.state.pendingEvents.filter((event) => {
return !logs.find((log) => {
const isMined = (log.state === 'mined') && (log.transactionHash === event.transactionHash);
const isPending = (log.state === 'pending') && (log.key === event.key);
return isMined || isPending;
});
}))
.sort(sortEvents);
const allEvents = pendingEvents.concat(minedEvents);
this.setState({
allEvents,
minedEvents,
pendingEvents
});
});
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './events';

View File

@ -1,23 +0,0 @@
/* Copyright 2015, 2016 Ethcore (UK) Ltd.
/* This file is part of Parity.
/*
/* Parity is free software: you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published by
/* the Free Software Foundation, either version 3 of the License, or
/* (at your option) any later version.
/*
/* Parity is distributed in the hope that it will be useful,
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/
.icon {
width: 32px;
height: 32px;
border-radius: 50%;
margin-right: 0.5em;
}

View File

@ -1,36 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
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) } />
);
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './identityIcon';

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './loading';

View File

@ -1,21 +0,0 @@
/* Copyright 2015, 2016 Ethcore (UK) Ltd.
/* This file is part of Parity.
/*
/* Parity is free software: you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published by
/* the Free Software Foundation, either version 3 of the License, or
/* (at your option) any later version.
/*
/* Parity is distributed in the hope that it will be useful,
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/
.loading {
width: 100%;
text-align: center;
padding-top: 2em;
}

View File

@ -1,31 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component } from 'react';
import { CircularProgress } from 'material-ui';
import styles from './loading.css';
export default class Loading extends Component {
render () {
return (
<div className={ styles.loading }>
<CircularProgress size={ 120 } thickness={ 7 } />
</div>
);
}
}

View File

@ -1,17 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './status';

View File

@ -1,55 +0,0 @@
/* Copyright 2015, 2016 Ethcore (UK) Ltd.
/* This file is part of Parity.
/*
/* Parity is free software: you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published by
/* the Free Software Foundation, either version 3 of the License, or
/* (at your option) any later version.
/*
/* Parity is distributed in the hope that it will be useful,
/* but WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/
.status {
background: rgba(255, 175, 0, 0.25);
color: #430;
padding: 4em 0 2em 0;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.title {
margin-top: 0;
font-weight: 300;
font-size: 2.5rem;
text-transform: uppercase;
}
.item {
flex: 1;
margin: 1.5rem 1rem;
text-align: center;
}
.byline {
font-size: 1.25em;
color: #430;
opacity: 0.75;
}
.heading {
text-transform: uppercase;
letter-spacing: 0.25em;
font-size: 1.5em;
color: #430;
opacity: 0.75;
}
.hero {
font-size: 4em;
}

View File

@ -1,74 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react';
import { formatBlockNumber, formatCoins, formatEth } from '../format';
import styles from './status.css';
export default class Status extends Component {
static propTypes = {
address: PropTypes.string,
gavBalance: PropTypes.object,
blockNumber: PropTypes.object,
totalSupply: PropTypes.object,
remaining: PropTypes.object,
price: PropTypes.object,
children: PropTypes.node
}
render () {
const { blockNumber, gavBalance, totalSupply, remaining, price } = this.props;
if (!totalSupply) {
return null;
}
return (
<div className={ styles.status }>
<div className={ styles.item }>
<div className={ styles.heading }>&nbsp;</div>
<div className={ styles.hero }>
{ formatCoins(remaining, -1) }
</div>
<div className={ styles.byline }>
available for { formatEth(price) }ETH
</div>
</div>
<div className={ styles.item }>
<div className={ styles.heading }>GAVcoin</div>
<div className={ styles.hero }>
{ formatCoins(totalSupply, -1) }
</div>
<div className={ styles.byline }>
total at { formatBlockNumber(blockNumber) }
</div>
</div>
<div className={ styles.item }>
<div className={ styles.heading }>&nbsp;</div>
<div className={ styles.hero }>
{ formatCoins(gavBalance, -1) }
</div>
<div className={ styles.byline }>
coin balance
</div>
</div>
{ this.props.children }
</div>
);
}
}

View File

@ -1,56 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import BigNumber from 'bignumber.js';
import { api } from '../parity';
const DIVISOR = 10 ** 6;
const ZERO = new BigNumber(0);
export function formatBlockNumber (blockNumber) {
return ZERO.eq(blockNumber || 0)
? 'Pending'
: `#${blockNumber.toFormat()}`;
}
export function formatCoins (amount, decimals = 6) {
const adjusted = amount.div(DIVISOR);
if (decimals === -1) {
if (adjusted.gte(10000)) {
decimals = 0;
} else if (adjusted.gte(1000)) {
decimals = 1;
} else if (adjusted.gte(100)) {
decimals = 2;
} else if (adjusted.gte(10)) {
decimals = 3;
} else {
decimals = 4;
}
}
return adjusted.toFormat(decimals);
}
export function formatEth (eth, decimals = 3) {
return api.util.fromWei(eth).toFormat(decimals);
}
export function formatHash (hash) {
return `${hash.substr(0, 10)}...${hash.substr(-8)}`;
}

View File

@ -1,21 +0,0 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
const { api } = window.parity;
export {
api
};

View File

@ -37,7 +37,6 @@ module.exports = {
entry: {
// dapps
'basiccoin': ['./dapps/basiccoin.js'],
'gavcoin': ['./dapps/gavcoin.js'],
'githubhint': ['./dapps/githubhint.js'],
'registry': ['./dapps/registry.js'],
'signaturereg': ['./dapps/signaturereg.js'],