Skip to content

Commit

Permalink
Merge pull request #89 from rnsdomains/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ilanolkies authored Dec 9, 2019
2 parents 2ea8aad + 595b19f commit 7aa01ed
Show file tree
Hide file tree
Showing 24 changed files with 2,541 additions and 2,075 deletions.
2 changes: 1 addition & 1 deletion src/app/auth/operations.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hash as namehash } from 'eth-ens-namehash';
import { rns as registryAddress } from '../../config/contracts';
import { rns as registryAddress } from '../../config/contracts.json';
import { checkResolver } from '../notifications';

import {
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/ResolverDatalist.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { multilanguage } from 'redux-multilanguage';
import { publicResolver, multiChainResolver } from '../../config/contracts';
import { publicResolver, multiChainResolver } from '../../config/contracts.json';

export default multilanguage(({ strings }) => (
<datalist id="resolvers">
Expand Down
14 changes: 8 additions & 6 deletions src/app/containers/FieldContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FieldComponent } from '../components';
import * as valueTypes from '../types';
import { validateAddress, validatePositiveNumber, validateBytes32 } from '../validations';
import { toChecksumAddress } from '../selectors';
import { publicResolver, multiChainResolver } from '../../config/contracts';
import { publicResolver, multiChainResolver } from '../../config/contracts.json';

function getResolverName(address, rskResolverText, multiChainResolverText) {
if (address.toLowerCase() === publicResolver.toLowerCase()) return rskResolverText;
Expand All @@ -18,7 +18,7 @@ const mapStateToProps = (state, ownProps) => {
const {
getting, value, editOpen, editing,
} = getField(state);
const { name, network } = state.auth;
const { name, network, address } = state.auth;
const { action, defaultValue } = parse(state.router.location.search);

let displayValue = value;
Expand All @@ -31,13 +31,14 @@ const mapStateToProps = (state, ownProps) => {
&& getResolverName(value, strings.rsk_resolver, strings.multi_chain_resolver)
);
} else if (valueType === valueTypes.POSITIVE_NUMBER) {
displayValue = value && value.toNumber();
// eslint-disable-next-line radix
displayValue = value && parseInt(value);
}

let validate = () => null;

if (valueType === valueTypes.ADDRESS || valueType === valueTypes.RESOLVER) {
validate = address => validateAddress(address, network);
validate = addr => validateAddress(addr, network);
} else if (valueType === valueTypes.POSITIVE_NUMBER) {
validate = number => validatePositiveNumber(number);
} else if (valueType === valueTypes.BYTES32) {
Expand All @@ -50,6 +51,7 @@ const mapStateToProps = (state, ownProps) => {
name,
getting,
value: displayValue,
address,
editOpen,
editing,
validate,
Expand All @@ -63,7 +65,7 @@ const mapDispatchToProps = (dispatch, ownProps) => {
return {
get: name => dispatch(get(name)),
changeEdit: () => dispatch(changeEdit()),
set: (name, value) => dispatch(set(name, value)),
set: (name, value, address) => dispatch(set(name, value, address)),
};
};

Expand All @@ -72,7 +74,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => ({
...stateProps,
...dispatchProps,
get: () => dispatchProps.get(stateProps.name),
set: value => dispatchProps.set(stateProps.name, value),
set: value => dispatchProps.set(stateProps.name, value, stateProps.address),
});

export default multilanguage(connect(
Expand Down
19 changes: 11 additions & 8 deletions src/app/factories/operationFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@ export const get = (request, receive, action) => name => (dispatch) => {
dispatch(request(name));

const hash = namehash(name);

return new Promise((resolve) => {
action(hash, (error, result) => {
action(hash).call((error, result) => {
if (error) return resolve(dispatch(notifyError(error.message)));
return resolve(dispatch(receive(result)));
});
});
};

export const set = (request, receive, txType, action, callback) => (name, value) => (dispatch) => {
// eslint-disable-next-line max-len
export const set = (request, receive, txType, action, callback) => (name, value, sender) => (dispatch) => {
dispatch(request(name, value));

const hash = namehash(name);

return new Promise((resolve) => {
action(hash, value, (error, result) => {
dispatch(receive());
if (error) return resolve(dispatch(notifyError(error.message)));
return resolve(dispatch(notifyTx(result, '', { type: txType, name, value }, callback ? () => callback(name) : null)));
});
action(hash, value).send(
{ from: sender },
(error, result) => {
dispatch(receive());
if (error) return resolve(dispatch(notifyError(error.message)));
return resolve(dispatch(notifyTx(result, '', { type: txType, name, value }, callback ? () => callback(name) : null)));
},
);
});
};
2 changes: 1 addition & 1 deletion src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Routes from './routes';
import { HeaderContainer } from './containers';
import { AuthModal } from './auth';
import { Notifications, notificationTypes } from './notifications';
import { multiChainResolver } from '../config/contracts';
import { multiChainResolver } from '../config/contracts.json';

// eslint-disable-next-line react/prop-types
const App = ({ strings, history, multiChainNotification }) => (
Expand Down
2 changes: 1 addition & 1 deletion src/app/notifications/operations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { hash as namehash } from 'eth-ens-namehash';
import { addTxNotification, txMined, notifyMigrateResolver } from './actions';
import { rns as rnsAddress, publicResolver } from '../../config/contracts';
import { rns as rnsAddress, publicResolver } from '../../config/contracts.json';

export const notifyTx = (tx, message, params, callback) => (dispatch) => {
dispatch(addTxNotification(tx, message, params));
Expand Down
69 changes: 1 addition & 68 deletions src/app/notifications/selectors.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,8 @@
import React from 'react';
import { Link } from 'react-router-dom';
import AddToCalendar from 'react-add-to-calendar';
import { Button } from 'react-bootstrap';
import { revealPeriod, multiChainResolver } from '../../config/contracts';
import { multiChainResolver } from '../../config/contracts.json';
import { txTypes } from './types';


const unsealEvent = (domain, registrationDate, title) => ({
title: `${title} ${domain}`,
description: `https://manager.rns.rsk.co/search?domain=${domain}`,
location: '',
startTime: new Date((registrationDate - revealPeriod) * 1000).toString(),
endTime: new Date(registrationDate * 1000).toString(),
});

const finalizeEvent = (domain, registrationDate, title) => ({
title: `${title} ${domain}`,
description: `https://manager.rns.rsk.co/search?domain=${domain}`,
location: '',
startTime: new Date(registrationDate * 1000).toString(),
endTime: new Date((registrationDate + 86400) * 1000).toString(),
});

const downloadBid = (domain, value, salt) => {
const text = `domain: ${domain}\nvalue: ${value}\nsalt: ${salt}`;
const element = document.createElement('a');
element.setAttribute('href', `data:text/plain;charset=utf-8,${encodeURIComponent(text)}`);
element.setAttribute('download', `bid - ${Date.now().toString()}.txt`);
element.style.display = 'none';

document.body.appendChild(element);
element.click();

document.body.removeChild(element);
};

const displaySetTx = (title, description, action = null) => ({
title,
description: `${title}: ${description}`,
Expand All @@ -44,41 +12,6 @@ const displaySetTx = (title, description, action = null) => ({
export default strings => (params) => {
if (!params) return null;
switch (params.type) {
case txTypes.START_AUCTION: return {
title: strings.notifications_start_auction_title,
action: <Link to={`/bid?domain=${params.name}`} className="btn btn-primary">{strings.notifications_start_auction_action}</Link>,
};
case txTypes.BID_AUCTION: return {
title: strings.notifications_bid_title,
action: (
<React.Fragment>
<p>
{strings.notifications_bid_dont_forget}
{params.registrationDate && <Button variant="link"><AddToCalendar event={unsealEvent(params.name, params.registrationDate, strings.notifications_bid_event_title)} /></Button>}
</p>
<hr />
<p>
{strings.notifications_bid_download_message}
<Button variant="link" onClick={() => downloadBid(params.name, params.value, params.salt)}>{strings.download}</Button>
.
</p>
</React.Fragment>
),
};
case txTypes.UNSEAL_AUCTION: return {
title: strings.notifications_unseal_title,
action: (
<p>
{strings.notifications_unseal_dont_forget}
<br />
{params.registrationDate && <Button variant="link"><AddToCalendar event={finalizeEvent(params.name, params.registrationDate, strings.notifications_unseal_event_title)} /></Button>}
</p>
),
};
case txTypes.FINALIZE_AUCTION: return {
title: strings.notifications_finalize_action,
action: <Link to={`/publicResolver?action=addr&defaultValue=${params.addr}`} className="btn btn-primary">{strings.notifications_finalize_action}</Link>,
};
case txTypes.SET_OWNER: return displaySetTx(strings.notifications_new_owner, params.value);
case txTypes.SET_RESOLVER: return displaySetTx(
strings.notifications_new_resolver,
Expand Down
2 changes: 1 addition & 1 deletion src/app/tabs/AdminMyCryptoTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { hash as namehash } from 'eth-ens-namehash';
import { multilanguage } from 'redux-multilanguage';
import { LinkToMyCryptoInteractComponent, ResolverDatalist, ChainAddrSelectorComponent } from '../../components';
import { getRnsField, getSubdomainOwner as _getSubdomainOwner } from './rns';
import { publicResolver, multiChainResolver } from '../../../config/contracts';
import { publicResolver, multiChainResolver } from '../../../config/contracts.json';

class AdminMyCryptoTabComponent extends Component {
constructor(props) {
Expand Down
6 changes: 3 additions & 3 deletions src/app/tabs/AdminMyCryptoTab/rns.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Web3 from 'web3';
import { hash as namehash } from 'eth-ens-namehash';
import { rskMain } from '../../../config/nodes';
import { rnsAbi } from './abis';
import { rns as rnsAddress } from '../../../config/contracts';
import { rskMain } from '../../../config/nodes.json';
import { rnsAbi } from './abis.json';
import { rns as rnsAddress } from '../../../config/contracts.json';

export const getRnsField = (field, name) => {
const web3 = new Web3(rskMain);
Expand Down
5 changes: 3 additions & 2 deletions src/app/tabs/admin/containers/FIFSMigrationContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import { FIFSMigrationComponent } from '../components';

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

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

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

export default connect(
Expand Down
4 changes: 2 additions & 2 deletions src/app/tabs/admin/containers/ReverseSetupContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const mapStateToProps = state => ({

const mapDispatchToProps = dispatch => ({
getReverse: address => dispatch(getReverseResolution(address)),
setReverse: name => dispatch(setReverseResolution(name)),
setReverse: (name, address) => dispatch(setReverseResolution(name, address)),
});

const mergeProps = (stateProps, dispatchProps, ownProps) => ({
...ownProps,
...stateProps,
getReverse: () => dispatchProps.getReverse(stateProps.address),
setReverse: () => dispatchProps.setReverse(stateProps.name),
setReverse: () => dispatchProps.setReverse(stateProps.name, stateProps.address),
});

export default connect(
Expand Down
5 changes: 3 additions & 2 deletions src/app/tabs/admin/containers/SubdomainContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const mapStateToProps = (state, ownProps) => {

return {
parent: state.auth.name,
address: state.auth.address,
owner: subdomain.owner && toChecksumAddress(state)(subdomain.owner),
viewEdit: subdomain.viewEdit,
editing: subdomain.editing,
Expand All @@ -19,14 +20,14 @@ const mapStateToProps = (state, ownProps) => {

const mapDispatchToProps = (dispatch, ownProps) => ({
changeEdit: () => dispatch(viewEditSubdomainOwner(ownProps.label)),
set: (node, owner) => dispatch(setSubdomainOwner(node, ownProps.label, owner)),
set: (node, owner, address) => dispatch(setSubdomainOwner(node, ownProps.label, owner, address)),
});

const mergeProps = (stateProps, dispatchProps, ownProps) => ({
...ownProps,
...stateProps,
...dispatchProps,
set: owner => dispatchProps.set(stateProps.parent, owner),
set: owner => dispatchProps.set(stateProps.parent, owner, stateProps.address),
});

export default connect(
Expand Down
Loading

0 comments on commit 7aa01ed

Please sign in to comment.