// Copyright 2015-2017 Parity Technologies (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 .
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { api } from '../../parity';
import Container from '../../Container';
import styles from './deployment.css';
const DECIMALS = 6;
const BASE = Math.pow(10, DECIMALS);
const ERRORS = {
name: 'specify a valid name >2 & <32 characters',
tla: 'specify a valid TLA, 3 characters in length',
usedtla: 'the TLA used is not available for registration',
supply: `supply needs to be > 1 & <1 trillion, with no more than ${DECIMALS} decimals`
};
export default class Deployment extends Component {
static contextTypes = {
accounts: PropTypes.object.isRequired,
router: PropTypes.object.isRequired,
managerInstance: PropTypes.object.isRequired,
registryInstance: PropTypes.object.isRequired,
tokenregInstance: PropTypes.object.isRequired
};
static initState = {
base: null,
deployBusy: false,
deployDone: false,
deployError: null,
deployState: null,
globalReg: false,
globalFee: 0,
globalFeeText: '1.000',
fromAddress: null,
name: '',
nameError: ERRORS.name,
tla: '',
tlaError: ERRORS.tla,
totalSupply: '5000000',
totalSupplyError: null,
signerRequestId: null,
txHash: null
};
state = Deployment.initState
componentDidMount () {
const { managerInstance, tokenregInstance } = this.context;
Promise
.all([
managerInstance.base.call(),
tokenregInstance.fee.call()
])
.then(([base, globalFee]) => {
this.setState({
base,
baseText: base.toFormat(0),
globalFee,
globalFeeText: api.util.fromWei(globalFee).toFormat(3)
});
});
}
reset () {
this.setState(Deployment.initState, () => this.componentDidMount());
}
render () {
const { deployBusy } = this.state;
return deployBusy
? this.renderDeploying()
: this.renderForm();
}
renderDeploying () {
const { deployDone, deployError, deployState } = this.state;
if (deployDone) {
return (
Your token has been deployed
);
}
if (deployError) {
return (
Your deployment has encountered an error
{ deployError.message }
);
}
return (
Your token is currently being deployed to the network