Skip to content

Commit

Permalink
Transfer registrar button in admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
javiesses committed Oct 17, 2019
1 parent b5a5481 commit 80c9dac
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 53 deletions.
3 changes: 3 additions & 0 deletions src/app/notifications/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export default strings => (params) => {
case txTypes.SET_REVERSE_RESOLUTION: return displaySetTx(
strings.notifications_new_reverse_resolution,
);
case txTypes.MIGRATE_FIFS_REGISTRAR: return displaySetTx(
strings.notifications_migrated_domain,
);
default: return null;
}
};
2 changes: 2 additions & 0 deletions src/app/notifications/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const txTypes = {
SET_CONTENT: 'SET_CONTENT',

SET_CHAIN_ADDR: 'SET_CHAIN_ADDR',

MIGRATE_FIFS_REGISTRAR: 'MIGRATE_FIFS_REGISTRAR',
};

export const ADD_NOTIFICATION = 'ADD_NOTIFICATION';
Expand Down
53 changes: 52 additions & 1 deletion src/app/tabs/admin/abis.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,56 @@
"stateMutability": "pure",
"type": "function"
}
],
"tokenRegistrarAbi": [
{
"constant": true,
"inputs": [
{
"name": "_hash",
"type": "bytes32"
}
],
"name": "entries",
"outputs": [
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "address"
},
{
"name": "",
"type": "uint256"
},
{
"name": "",
"type": "uint256"
},
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_hash",
"type": "bytes32"
}
],
"name": "transferRegistrars",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
}
}
32 changes: 30 additions & 2 deletions src/app/tabs/admin/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
VIEW_EDIT_SUBDOMAIN_OWNER, REQUEST_SET_SUBDOMAIN_OWNER, RECEIVE_SET_SUBDOMAIN_OWNER,
REVERSE_REQUEST_GET, REVERSE_RECEIVE_GET,
REVERSE_REQUEST_SET, REVERSE_RECEIVE_SET, REVERSE_ERROR_SET,
FIFS_MIGRATION_CHECK_SUBDOMAIN,
FIFS_MIGRATION_CHECK_SUBDOMAIN, FIFS_MIGRATION_REQUEST_CHECK_MIGRATION,
FIFS_MIGRATION_RECEIVE_CHECK_MIGRATION, FIFS_MIGRATION_RECEIVE_MIGRATION,
FIFS_MIGRATION_REQUEST_MIGRATION, FIFS_MIGRATION_ERROR_MIGRATION,
FIFS_MIGRATION_ERROR_CHECK_MIGRATION,
} from './types';

import filedActions from '../../factories/actionFactory';
Expand Down Expand Up @@ -67,7 +70,32 @@ export const errorSetReverse = () => ({
type: REVERSE_ERROR_SET,
});

export const fifsMigrationcheckIfSubdomain = isSubdomain => ({
export const fifsMigrationCheckIfSubdomain = isSubdomain => ({
type: FIFS_MIGRATION_CHECK_SUBDOMAIN,
isSubdomain,
});

export const requestCheckFifsMigration = () => ({
type: FIFS_MIGRATION_REQUEST_CHECK_MIGRATION,
});

export const receiveCheckFifsMigration = migrated => ({
type: FIFS_MIGRATION_RECEIVE_CHECK_MIGRATION,
migrated,
});

export const errorCheckFifsMigration = () => ({
type: FIFS_MIGRATION_ERROR_CHECK_MIGRATION,
});

export const requestFifsMigration = () => ({
type: FIFS_MIGRATION_REQUEST_MIGRATION,
});

export const receiveFifsMigration = () => ({
type: FIFS_MIGRATION_RECEIVE_MIGRATION,
});

export const errorFifsMigration = () => ({
type: FIFS_MIGRATION_ERROR_MIGRATION,
});
1 change: 0 additions & 1 deletion src/app/tabs/admin/components/AdminTabComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class AdminTabComponent extends Component {
</h2>
<Row>
<Col>
<h3>{strings.fifs_migration}</h3>
<FIFSMigrationContainer />
</Col>
</Row>
Expand Down
53 changes: 41 additions & 12 deletions src/app/tabs/admin/components/FIFSMigrationComponent.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,52 @@
import React, { Component } from 'react';
import { multilanguage } from 'redux-multilanguage';
import propTypes from 'prop-types';
import { Spinner, Button } from 'react-bootstrap';
import {
Spinner, Button, Alert, Container,
} from 'react-bootstrap';

class FIFSMigrationComponent extends Component {
componentDidMount() {
const { checkIfSubdomain } = this.props;
checkIfSubdomain();
const { checkIfSubdomainOrMigrated } = this.props;
checkIfSubdomainOrMigrated();
}

render() {
const {
isSubdomain, getting, migrating, strings, migrate,
isSubdomain, checking, migrating, strings, migrate, migrated, justMigrated,
} = this.props;

if (isSubdomain) {
return strings.fifs_subdomain;
}
if (!isSubdomain && (!migrated || justMigrated)) {
const title = <h3>{strings.fifs_migration}</h3>;
let html;

if (checking || migrating) {
html = <Spinner animation="grow" variant="primary" />;
} else if (justMigrated) {
html = strings.already_migrated;
} else {
html = (
<div>
<Alert variant="danger" dismissible="true">
<Alert.Heading>{strings.action_needed}</Alert.Heading>
<p>
{strings.due_migration_date}
</p>
</Alert>
<Button disabled={migrating} onClick={migrate}>{strings.fifs_migrate}</Button>
</div>
);
}

if (getting || migrating) {
return <Spinner animation="grow" variant="primary" />;
return (
<Container>
{title}
{html}
</Container>
);
}

return <Button disabled={migrating} onClick={migrate}>{strings.fifs_migrate}</Button>;
return '';
}
}

Expand All @@ -35,12 +59,17 @@ FIFSMigrationComponent.propTypes = {
already_migrated: propTypes.string.isRequired,
fifs_subdomain: propTypes.string.isRequired,
fifs_migrate: propTypes.string.isRequired,
due_migration_date: propTypes.string.isRequired,
action_needed: propTypes.string.isRequired,
fifs_migration: propTypes.string.isRequired,
}).isRequired,
checkIfSubdomain: propTypes.func.isRequired,
checkIfSubdomainOrMigrated: propTypes.func.isRequired,
migrate: propTypes.func.isRequired,
isSubdomain: propTypes.bool,
getting: propTypes.bool.isRequired,
migrated: propTypes.bool.isRequired,
checking: propTypes.bool.isRequired,
migrating: propTypes.bool.isRequired,
justMigrated: propTypes.bool.isRequired,
};

export default multilanguage(FIFSMigrationComponent);
11 changes: 5 additions & 6 deletions src/app/tabs/admin/containers/FIFSMigrationContainer.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { connect } from 'react-redux';
import { checkIfSubdomain, migrateToFifsRegistrar } from '../operations';
import { checkIfSubdomainOrMigrated, migrateToFifsRegistrar } from '../operations';
import { FIFSMigrationComponent } from '../components';

const mapStateToProps = state => ({
address: state.auth.address,
name: state.auth.name,
...state.admin.fifsMigration,
});

const mapDispatchToProps = dispatch => ({
checkIfSubdomain: name => dispatch(checkIfSubdomain(name)),
migrate: address => dispatch(migrateToFifsRegistrar(address)),
checkIfSubdomainOrMigrated: name => dispatch(checkIfSubdomainOrMigrated(name)),
migrate: name => dispatch(migrateToFifsRegistrar(name)),
});

const mergeProps = (stateProps, dispatchProps, ownProps) => ({
...ownProps,
...stateProps,
checkIfSubdomain: () => dispatchProps.checkIfSubdomain(stateProps.name),
migrate: () => dispatchProps.migrate(stateProps.address),
checkIfSubdomainOrMigrated: () => dispatchProps.checkIfSubdomainOrMigrated(stateProps.name),
migrate: () => dispatchProps.migrate(stateProps.name),
});

export default connect(
Expand Down
54 changes: 41 additions & 13 deletions src/app/tabs/admin/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@ import {
addSubdomain as addSubdomainAction, receiveSubdomainOwner, clearSubdomains,
requestSetSubdomainOwner, receiveSetSubdomainOwner,
requestGetReverse, receiveGetReverse, requestSetReverse, receiveSetReverse, errorSetReverse,
fifsMigrationcheckIfSubdomain,
fifsMigrationCheckIfSubdomain, requestCheckFifsMigration, receiveCheckFifsMigration,
requestFifsMigration, receiveFifsMigration, errorFifsMigration, errorCheckFifsMigration,
} from './actions';
import {
rns as registryAddress,
reverseRegistrar as reverseRegistryAddress,
nameResolver as nameResolverAddress,
registrar as tokenRegistrarAddress,
} from '../../../config/contracts';
import {
notifyTx, notifyError, txTypes, checkResolver,
} from '../../notifications';
import { get, set } from '../../factories/operationFactory';
import { rnsAbi, reverseAbi, nameResolverAbi } from './abis';
import {
rnsAbi, reverseAbi, nameResolverAbi, tokenRegistrarAbi,
} from './abis';

const registry = window.web3 && window.web3.eth.contract(rnsAbi).at(registryAddress);
const reverseRegistry = window.web3
&& window.web3.eth.contract(reverseAbi).at(reverseRegistryAddress);
const nameResolver = window.web3
&& window.web3.eth.contract(nameResolverAbi).at(nameResolverAddress);
const tokenRegistrar = window.web3
&& window.web3.eth.contract(tokenRegistrarAbi).at(tokenRegistrarAddress);

export const getDomainOwner = get(owner.requestGet, owner.receiveGet, registry && registry.owner);
export const getDomainResolver = get(
Expand Down Expand Up @@ -144,22 +150,44 @@ export const setReverseResolution = name => (dispatch) => {
});
};

export const checkIfSubdomain = name => (dispatch) => {
export const checkIfSubdomainOrMigrated = name => (dispatch) => {
const labelsAmount = name.split('.').length;

if (labelsAmount > 2) {
dispatch(fifsMigrationcheckIfSubdomain(true));
} else {
dispatch(fifsMigrationcheckIfSubdomain(false));
return Promise.resolve(dispatch(fifsMigrationCheckIfSubdomain(true)));
}

dispatch(requestCheckFifsMigration());

return new Promise((resolve) => {
const label = `0x${sha3(name.split('.')[0])}`;

tokenRegistrar.entries(label, (error, result) => {
if (error) {
dispatch(errorCheckFifsMigration());
return resolve(dispatch(notifyError(error.message)));
}

const deed = result[1];

return resolve(dispatch(receiveCheckFifsMigration(deed === '0x0000000000000000000000000000000000000000')));
});
});
};

export const migrateToFifsRegistrar = address => (dispatch) => { // TODO
const labelsAmount = address.length;
export const migrateToFifsRegistrar = name => (dispatch) => {
dispatch(requestFifsMigration());

if (labelsAmount > 2) {
dispatch(fifsMigrationcheckIfSubdomain(true));
} else {
dispatch(fifsMigrationcheckIfSubdomain(false));
}
return new Promise((resolve) => {
const label = `0x${sha3(name.split('.')[0])}`;

tokenRegistrar.transferRegistrars(label, (error, result) => {
if (error) {
dispatch(errorFifsMigration());
return resolve(dispatch(notifyError(error.message)));
}
dispatch(receiveFifsMigration());
return resolve(dispatch(notifyTx(result, '', { type: txTypes.MIGRATE_FIFS_REGISTRAR, name })));
});
});
};
Loading

0 comments on commit 80c9dac

Please sign in to comment.