add STT on ropsten + formatPrice for display

This commit is contained in:
Barry Gitarts 2018-06-20 11:13:33 -04:00
parent 8d9dae20c6
commit 22d9798f05
6 changed files with 51 additions and 45 deletions

View File

@ -1,4 +1,5 @@
import React, { Fragment, PureComponent } from 'react';
import web3 from 'web3';
import { connect } from 'react-redux';
import { actions as accountActions } from '../../reducers/accounts';
import ENSSubdomainRegistry from 'Embark/contracts/ENSSubdomainRegistry';
@ -12,6 +13,7 @@ import { CopyToClipboard } from 'react-copy-to-clipboard';
import RegisterSubDomain from '../ens/registerSubDomain';
import StatusLogo from '../../ui/icons/components/StatusLogo'
import EnsLogo from '../../ui/icons/logos/ens.png';
import { formatPrice } from '../ens/utils'
const { getPrice, getExpirationTime } = ENSSubdomainRegistry.methods;
const invalidSuffix = '0000000000000000000000000000000000000000'
@ -21,6 +23,7 @@ const validStatusAddress = address => !address.includes(invalidSuffix);
const formatName = domainName => domainName.includes('.') ? domainName : `${domainName}.stateofus.eth`;
const getDomain = fullDomain => formatName(fullDomain).split('.').slice(1).join('.');
const hashedDomain = domainName => hash(getDomain(domainName));
const { fromWei } = web3.utils;
const cardStyle = {
width: '100%',
@ -95,7 +98,7 @@ class Register extends PureComponent {
{!registered ?
<Fragment>
<Info.Action title="No address is associated with this domain">
<span style={{ color: theme.accent }}>{formattedDomain.toUpperCase()}</span> can be registered for {domainPrice} SNT
<span style={{ color: theme.accent }}>{formattedDomain.toUpperCase()}</span> can be registered for {!!domainPrice && formatPrice(fromWei(domainPrice))} SNT
</Info.Action>
<RegisterSubDomain
subDomain={formattedDomainArray[0]}

View File

@ -4,11 +4,11 @@ import React from 'react';
import { Button } from '../../ui/components';
import { withFormik } from 'formik';
import { hash } from 'eth-ens-namehash';
import { zeroAddress, zeroBytes32 } from './utils';
import { zeroAddress, zeroBytes32, formatPrice } from './utils';
import FieldGroup from '../standard/FieldGroup';
import LinearProgress from '@material-ui/core/LinearProgress';
const { soliditySha3 } = web3.utils;
const { soliditySha3, fromWei } = web3.utils;
const InnerForm = ({
values,
@ -25,46 +25,46 @@ const InnerForm = ({
}) => (
<form onSubmit={handleSubmit}>
{!subDomain &&
<FieldGroup
id="subDomain"
name="subDomain"
type="text"
label="Sub Domain"
onChange={handleChange}
onBlur={handleBlur}
value={values.subDomain}
error={errors.subDomain}
/>}
<FieldGroup
id="subDomain"
name="subDomain"
type="text"
label="Sub Domain"
onChange={handleChange}
onBlur={handleBlur}
value={values.subDomain}
error={errors.subDomain}
/>}
{!domainName &&
<FieldGroup
id="domainName"
name="domainName"
type="text"
label="Domain Name"
onChange={handleChange}
onBlur={handleBlur}
value={values.domainName}
button={
<Button
mode="strong"
style={{ marginTop: '5px' }}
onClick={() => {
<FieldGroup
id="domainName"
name="domainName"
type="text"
label="Domain Name"
onChange={handleChange}
onBlur={handleBlur}
value={values.domainName}
button={
<Button
mode="strong"
style={{ marginTop: '5px' }}
onClick={() => {
ENSSubdomainRegistry.methods.getPrice(hash(values.domainName))
.call()
.then((res) => { setFieldValue('price', res); });
.then((res) => { setFieldValue('price', fromWei(res)); });
}}
>
Get Price
</Button>
}
/>}
>
Get Price
</Button>
}
/>}
{!domainPrice &&
<FieldGroup
id="price"
name="price"
label="Domain Price"
disabled
value={values.price ? `${Number(values.price).toLocaleString()} SNT` : ''} />}
<FieldGroup
id="price"
name="price"
label="Domain Price"
disabled
value={values.price ? `${formatPrice(values.price)} SNT` : ''} />}
<FieldGroup
id="statusAddress"
name="statusAddress"

View File

@ -1,3 +1,3 @@
export const zeroAddress = '0x0000000000000000000000000000000000000000';
export const zeroBytes32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
export const formatPrice = price => price.includes('.') ? price : Number(price).toLocaleString();

View File

@ -8,10 +8,11 @@ import CircularProgress from '@material-ui/core/CircularProgress';
// We set an allowance to be "unlimited" by setting it to
// it's maximum possible value -- namely, 2^256 - 1.
const { fromWei } = web3.utils;
const unlimitedAllowance = new BigNumber(2).pow(256).sub(1);
const getDefaultAccount = () => web3.eth.defaultAccount;
const SUPPORTED_TOKENS = ['SNT'];
const BALANCE_KEYS = { 'SNT': 'SNTBalance' };
const SUPPORTED_TOKENS = ['SNT', 'STT'];
const BALANCE_KEYS = { 'SNT': 'SNTBalance', 'STT': 'SNTBalance' };
class TokenHandle extends PureComponent {
constructor(props){
@ -65,7 +66,7 @@ class TokenHandle extends PureComponent {
checked={!!Number(approved)}
name={symbol}
onChange={this.toggleApproved} />
<label style={{ margin: '2px 0px 0px 10px', fontWeight: 400 }}>{`${Number(account[BALANCE_KEYS[symbol]]).toLocaleString()} ${symbol.toUpperCase()}`}</label>
<label style={{ margin: '2px 0px 0px 10px', fontWeight: 400 }}>{`${Number(fromWei(account[BALANCE_KEYS[symbol]])).toLocaleString()} ${symbol.toUpperCase()}`}</label>
</div>}
{isLoading || updating && <CircularProgress />}
</Fragment>

View File

@ -1,8 +1,7 @@
<html>
<head>
<title>Status.im - Contracts</title>
<title>Status.im Domain Registration</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body class="container">
<div id="app">

View File

@ -79,8 +79,11 @@
"PublicResolver": {
"address": "0x5FfC014343cd971B7eb70732021E26C35B744cc4"
},
"TestToken": {
"address": "0xc55cF4B03948D7EBc8b9E8BAD92643703811d162"
},
"ENSSubdomainRegistry": {
"address": "0x149651FF48AEDBe84ab2551D2CaA48538449CEA5"
"address": "0xb1C47B61CDaeee3fA85Fe8B93FcE6311165E6291"
}
}
},