parent
1ea3b8b149
commit
516ea30fe6
|
@ -12,10 +12,10 @@ import { getStatusContactCode, getSNTAllowance } from '../../reducers/accounts';
|
||||||
import FieldGroup from '../standard/FieldGroup';
|
import FieldGroup from '../standard/FieldGroup';
|
||||||
import LinearProgress from '@material-ui/core/LinearProgress';
|
import LinearProgress from '@material-ui/core/LinearProgress';
|
||||||
import { generateXY } from '../../utils/ecdsa';
|
import { generateXY } from '../../utils/ecdsa';
|
||||||
import { BigNumber } from '../standard/utils';
|
|
||||||
|
console.log(TestToken)
|
||||||
|
|
||||||
const { soliditySha3, fromWei } = web3.utils;
|
const { soliditySha3, fromWei } = web3.utils;
|
||||||
const unlimitedAllowance = new BigNumber(2).pow(256).sub(1);
|
|
||||||
|
|
||||||
const InnerForm = ({
|
const InnerForm = ({
|
||||||
values,
|
values,
|
||||||
|
@ -33,98 +33,98 @@ const InnerForm = ({
|
||||||
}) => (
|
}) => (
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<div style={{ margin: '10px' }}>
|
<div style={{ margin: '10px' }}>
|
||||||
{!subDomain &&
|
{!subDomain &&
|
||||||
<FieldGroup
|
<FieldGroup
|
||||||
id="subDomain"
|
id="subDomain"
|
||||||
name="subDomain"
|
name="subDomain"
|
||||||
type="text"
|
type="text"
|
||||||
label="Sub Domain"
|
label="Sub Domain"
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
value={values.subDomain}
|
value={values.subDomain}
|
||||||
error={errors.subDomain}
|
error={errors.subDomain}
|
||||||
/>}
|
/>}
|
||||||
{!domainName &&
|
{!domainName &&
|
||||||
<FieldGroup
|
<FieldGroup
|
||||||
id="domainName"
|
id="domainName"
|
||||||
name="domainName"
|
name="domainName"
|
||||||
type="text"
|
type="text"
|
||||||
label="Domain Name"
|
label="Domain Name"
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
value={values.domainName}
|
value={values.domainName}
|
||||||
button={
|
button={
|
||||||
<Button
|
<Button
|
||||||
mode="strong"
|
mode="strong"
|
||||||
style={{ marginTop: '5px' }}
|
style={{ marginTop: '5px' }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
ENSSubdomainRegistry.methods.getPrice(hash(values.domainName))
|
ENSSubdomainRegistry.methods.getPrice(hash(values.domainName))
|
||||||
.call()
|
.call()
|
||||||
.then((res) => { setFieldValue('price', fromWei(res)); });
|
.then((res) => { setFieldValue('price', fromWei(res)); });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Get Price
|
Get Price
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
/>}
|
/>}
|
||||||
{!domainPrice &&
|
{!domainPrice &&
|
||||||
<FieldGroup
|
<FieldGroup
|
||||||
id="price"
|
id="price"
|
||||||
name="price"
|
name="price"
|
||||||
label="Domain Price"
|
label="Domain Price"
|
||||||
disabled
|
disabled
|
||||||
value={values.price ? `${formatPrice(values.price)} SNT` : ''} />}
|
value={values.price ? `${formatPrice(values.price)} SNT` : ''} />}
|
||||||
<Hidden mdDown>
|
<Hidden mdDown>
|
||||||
<FieldGroup
|
<FieldGroup
|
||||||
id="statusAddress"
|
id="statusAddress"
|
||||||
|
name="statusAddress"
|
||||||
|
type="text"
|
||||||
|
label="Status messenger address domain resolves to"
|
||||||
|
onChange={handleChange}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
value={values.statusAddress}
|
||||||
|
error={errors.statusAddress}
|
||||||
|
wide="true"
|
||||||
|
/>
|
||||||
|
<FieldGroup
|
||||||
|
id="address"
|
||||||
|
name="address"
|
||||||
|
type="text"
|
||||||
|
label="Ethereum address domain resolves to"
|
||||||
|
onChange={handleChange}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
value={values.address}
|
||||||
|
error={errors.address}
|
||||||
|
button={<Button mode="strong" style={{ padding: '5px 15px 5px 15px', marginTop: '5px' }} onClick={() => setFieldValue('address', web3.eth.defaultAccount)}>Use My Primary Address</Button>}
|
||||||
|
/>
|
||||||
|
{!isSubmitting ? <Button wide mode="strong" type="submit" disabled={isSubmitting || !!Object.keys(errors).length}>{!isSubmitting ? 'Submit' : 'Submitting to the Blockchain - (this may take awhile)'}</Button> : <LinearProgress />}
|
||||||
|
</Hidden>
|
||||||
|
<Hidden mdUp>
|
||||||
|
<Field label="Your Contact Code">
|
||||||
|
<MobileSearch
|
||||||
name="statusAddress"
|
name="statusAddress"
|
||||||
type="text"
|
style={{ marginTop: '10px' }}
|
||||||
label="Status messenger address domain resolves to"
|
placeholder="Status Messenger Address"
|
||||||
onChange={handleChange}
|
|
||||||
onBlur={handleBlur}
|
|
||||||
value={values.statusAddress}
|
value={values.statusAddress}
|
||||||
error={errors.statusAddress}
|
|
||||||
wide="true"
|
|
||||||
/>
|
|
||||||
<FieldGroup
|
|
||||||
id="address"
|
|
||||||
name="address"
|
|
||||||
type="text"
|
|
||||||
label="Ethereum address domain resolves to"
|
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
onBlur={handleBlur}
|
paste={() => setFieldValue('statusAddress', statusContactCode)}
|
||||||
|
wide />
|
||||||
|
</Field>
|
||||||
|
<Field label="Your Wallet Address">
|
||||||
|
<MobileSearch
|
||||||
|
name="address"
|
||||||
|
style={{ marginTop: '10px' }}
|
||||||
|
placeholder="Ethereum Address"
|
||||||
value={values.address}
|
value={values.address}
|
||||||
error={errors.address}
|
onChange={handleChange}
|
||||||
button={<Button mode="strong" style={{ padding: '5px 15px 5px 15px', marginTop: '5px' }} onClick={() => setFieldValue('address', web3.eth.defaultAccount)}>Use My Primary Address</Button>}
|
paste={() => setFieldValue('address', web3.eth.defaultAccount)}
|
||||||
/>
|
required
|
||||||
{!isSubmitting ? <Button wide mode="strong" type="submit" disabled={isSubmitting || !!Object.keys(errors).length}>{!isSubmitting ? 'Submit' : 'Submitting to the Blockchain - (this may take awhile)'}</Button> : <LinearProgress />}
|
wide />
|
||||||
</Hidden>
|
</Field>
|
||||||
<Hidden mdUp>
|
<div style={{ position: 'relative', left: 0, right: 0, bottom: 0 }}>
|
||||||
<Field label="Your Contact Code">
|
<MobileButton type="submit" text="Register with transaction" style={{ width: '100%' }}/>
|
||||||
<MobileSearch
|
</div>
|
||||||
name="statusAddress"
|
</Hidden>
|
||||||
style={{ marginTop: '10px' }}
|
|
||||||
placeholder="Status Messenger Address"
|
|
||||||
value={values.statusAddress}
|
|
||||||
onChange={handleChange}
|
|
||||||
paste={() => setFieldValue('statusAddress', statusContactCode)}
|
|
||||||
wide />
|
|
||||||
</Field>
|
|
||||||
<Field label="Your Wallet Address">
|
|
||||||
<MobileSearch
|
|
||||||
name="address"
|
|
||||||
style={{ marginTop: '10px' }}
|
|
||||||
placeholder="Ethereum Address"
|
|
||||||
value={values.address}
|
|
||||||
onChange={handleChange}
|
|
||||||
paste={() => setFieldValue('address', web3.eth.defaultAccount)}
|
|
||||||
required
|
|
||||||
wide />
|
|
||||||
</Field>
|
|
||||||
<div style={{ position: 'relative', left: 0, right: 0, bottom: 0 }}>
|
|
||||||
<MobileButton type="submit" text="Register with transaction" style={{ width: '100%' }}/>
|
|
||||||
</div>
|
|
||||||
</Hidden>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
@ -142,34 +142,22 @@ const RegisterSubDomain = withFormik({
|
||||||
handleSubmit(values, { setSubmitting, props }) {
|
handleSubmit(values, { setSubmitting, props }) {
|
||||||
const { address, statusAddress } = values;
|
const { address, statusAddress } = values;
|
||||||
const { subDomain, domainName, registeredCallbackFn } = props || values;
|
const { subDomain, domainName, registeredCallbackFn } = props || values;
|
||||||
const { SNTAllowance } = props;
|
|
||||||
const { methods: { register } } = ENSSubdomainRegistry;
|
const { methods: { register } } = ENSSubdomainRegistry;
|
||||||
const subdomainHash = soliditySha3(subDomain);
|
const subdomainHash = soliditySha3(subDomain);
|
||||||
const domainNameHash = hash(domainName);
|
const domainNameHash = hash(domainName);
|
||||||
const resolveToAddr = address || zeroAddress;
|
const resolveToAddr = address || zeroAddress;
|
||||||
const points = statusAddress ? generateXY(statusAddress) : null;
|
const points = statusAddress ? generateXY(statusAddress) : null;
|
||||||
|
|
||||||
const registerAbi = ENSSubdomainRegistry.options.jsonInterface.find(x => x.name === 'register');
|
const toSend = register(
|
||||||
const encodedRegister = web3.eth.abi.encodeFunctionCall(registerAbi, [
|
|
||||||
subdomainHash,
|
|
||||||
domainNameHash,
|
|
||||||
resolveToAddr,
|
|
||||||
points ? points.x : zeroBytes32,
|
|
||||||
points ? points.y : zeroBytes32
|
|
||||||
]);
|
|
||||||
|
|
||||||
const sendWithApproval = TestToken.methods.approveAndCall(ENSSubdomainRegistry._address, unlimitedAllowance, encodedRegister);
|
|
||||||
const send = register(
|
|
||||||
subdomainHash,
|
subdomainHash,
|
||||||
domainNameHash,
|
domainNameHash,
|
||||||
resolveToAddr,
|
resolveToAddr,
|
||||||
points ? points.x : zeroBytes32,
|
points ? points.x : zeroBytes32,
|
||||||
points ? points.y : zeroBytes32
|
points ? points.y : zeroBytes32
|
||||||
);
|
);
|
||||||
const toSend = Number(SNTAllowance) > 0 ? send : sendWithApproval;
|
toSend.estimateGas().then(gasEstimated => {
|
||||||
toSend.estimateGas({ data: encodedRegister }).then(gasEstimated => {
|
console.log("Register would work. :D Gas estimated: "+gasEstimated)
|
||||||
console.log("Register would work. :D Gas estimated: " + gasEstimated);
|
console.log("Trying: register(\""+subdomainHash+"\",\""+domainNameHash+"\",\""+resolveToAddr+"\",\""+zeroBytes32+"\",\""+zeroBytes32+"\")")
|
||||||
console.log("Trying: register(\"" + subdomainHash + "\",\"" + domainNameHash+"\",\""+resolveToAddr+"\",\""+zeroBytes32+"\",\""+zeroBytes32+"\")")
|
|
||||||
toSend.send({gas: gasEstimated+1000}).then(txId => {
|
toSend.send({gas: gasEstimated+1000}).then(txId => {
|
||||||
if(txId.status == "0x1" || txId.status == "0x01"){
|
if(txId.status == "0x1" || txId.status == "0x01"){
|
||||||
console.log("Register send success. :)")
|
console.log("Register send success. :)")
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
pragma solidity ^0.4.11;
|
||||||
|
|
||||||
|
contract ApprovalReceiver {
|
||||||
|
function receiveApproval(address from, uint value, address tokenContract, bytes extraData) returns (bool);
|
||||||
|
}
|
|
@ -1,5 +0,0 @@
|
||||||
pragma solidity ^0.4.11;
|
|
||||||
|
|
||||||
contract ApproveAndCallFallBack {
|
|
||||||
function receiveApproval(address from, uint256 _amount, address _token, bytes _data) returns (bool);
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
pragma solidity ^0.4.23;
|
pragma solidity ^0.4.23;
|
||||||
|
|
||||||
import "./StandardToken.sol";
|
import "./StandardToken.sol";
|
||||||
import './ApproveAndCallFallBack.sol';
|
import './ApprovalReceiver.sol';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice ERC20Token for test scripts, can be minted by anyone.
|
* @notice ERC20Token for test scripts, can be minted by anyone.
|
||||||
|
@ -18,15 +18,9 @@ contract TestToken is StandardToken {
|
||||||
mint(msg.sender, _amount);
|
mint(msg.sender, _amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function approveAndCall(address _spender, uint256 _amount, bytes _extraData) returns (bool success) {
|
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
|
||||||
if (!approve(_spender, _amount)) throw;
|
assert(approve(_spender, _value));
|
||||||
ApproveAndCallFallBack(_spender).receiveApproval(
|
return ApprovalReceiver(_spender).receiveApproval(msg.sender, _value, this, _extraData);
|
||||||
msg.sender,
|
|
||||||
_amount,
|
|
||||||
this,
|
|
||||||
_extraData
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue