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,
|
||||||
|
@ -142,33 +142,21 @@ 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"){
|
||||||
|
|
|
@ -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