Use subdomain

This commit is contained in:
Anthony Laibe 2018-08-14 11:31:58 +01:00 committed by Pascal Precht
parent 9e7d7bbee2
commit e1043bf5f5
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
6 changed files with 17 additions and 18 deletions

View File

@ -134,7 +134,7 @@ export const messageListen = {
export const ENS_RECORD = createRequestTypes('ENS_RECORD'); export const ENS_RECORD = createRequestTypes('ENS_RECORD');
export const ensRecord = { export const ensRecord = {
resolve: (name) => action(ENS_RECORD[REQUEST], {name}), resolve: (subdomain) => action(ENS_RECORD[REQUEST], {subdomain}),
lookup: (address) => action(ENS_RECORD[REQUEST], {address}), lookup: (address) => action(ENS_RECORD[REQUEST], {address}),
success: (record, payload) => action(ENS_RECORD[SUCCESS], {ensRecords: [Object.assign(payload, record)]}), success: (record, payload) => action(ENS_RECORD[SUCCESS], {ensRecords: [Object.assign(payload, record)]}),
failure: (error) => action(ENS_RECORD[FAILURE], {error}) failure: (error) => action(ENS_RECORD[FAILURE], {error})
@ -142,12 +142,11 @@ export const ensRecord = {
export const ENS_RECORDS = createRequestTypes('ENS_RECORDS'); export const ENS_RECORDS = createRequestTypes('ENS_RECORDS');
export const ensRecords = { export const ensRecords = {
post: (name, address) => action(ENS_RECORDS[REQUEST], {name, address}), post: (subdomain, address) => action(ENS_RECORDS[REQUEST], {subdomain, address}),
success: (_record, payload) => action(ENS_RECORDS[SUCCESS], {ensRecords: [{name: payload.name, address: payload.address}]}), success: (_record, payload) => action(ENS_RECORDS[SUCCESS], {ensRecords: [{subdomain: payload.subdomain, address: payload.address}]}),
failure: (error) => action(ENS_RECORDS[FAILURE], {error}) failure: (error) => action(ENS_RECORDS[FAILURE], {error})
}; };
export const FIDDLE = createRequestTypes('FIDDLE'); export const FIDDLE = createRequestTypes('FIDDLE');
export const fiddle = { export const fiddle = {
request: (codeToCompile) => action(FIDDLE[REQUEST], {codeToCompile}), request: (codeToCompile) => action(FIDDLE[REQUEST], {codeToCompile}),

View File

@ -85,7 +85,7 @@ export function fetchContractProfile(payload) {
} }
export function fetchEnsRecord(payload) { export function fetchEnsRecord(payload) {
if (payload.name) { if (payload.subdomain) {
return get('/ens/resolve', {params: payload}); return get('/ens/resolve', {params: payload});
} else { } else {
return get('/ens/lookup', {params: payload}); return get('/ens/lookup', {params: payload});

View File

@ -28,9 +28,9 @@ class EnsLookup extends Component {
showResult() { showResult() {
let ensRecord = this.props.ensRecords.find((record) => record.address === this.state.address); let ensRecord = this.props.ensRecords.find((record) => record.address === this.state.address);
if (ensRecord) { if (ensRecord) {
return <Alert type="success">The name is: {ensRecord.name}</Alert>; return <Alert type="success">The subdomain is: {ensRecord.subdomain}</Alert>;
} else { } else {
return <Alert type="danger">We could not find a name for this address</Alert>; return <Alert type="danger">We could not find a subdomain for this address</Alert>;
} }
} }

View File

@ -11,7 +11,7 @@ class EnsRegister extends Component {
super(props); super(props);
this.state = { this.state = {
name: '', subdomain: '',
address: '', address: '',
showResult: false showResult: false
}; };
@ -25,12 +25,12 @@ class EnsRegister extends Component {
} }
handleRegister() { handleRegister() {
this.props.register(this.state.name, this.state.address); this.props.register(this.state.subdomain, this.state.address);
this.setState({showResult: true}); this.setState({showResult: true});
} }
showResult() { showResult() {
let ensRecord = this.props.ensRecords.find((record) => record.address === this.state.address && record.name === this.state.name); let ensRecord = this.props.ensRecords.find((record) => record.address === this.state.address && record.subdomain === this.state.subdomain);
if (ensRecord) { if (ensRecord) {
return <Alert type="success">Successfully registered</Alert>; return <Alert type="success">Successfully registered</Alert>;
} else { } else {
@ -46,7 +46,7 @@ class EnsRegister extends Component {
<Grid.Row> <Grid.Row>
<Grid.Col md={6}> <Grid.Col md={6}>
<Form.Group> <Form.Group>
<Form.Input placeholder="Enter a name" onChange={e => this.handleChange(e, "name")}/> <Form.Input placeholder="Enter a subdomain" onChange={e => this.handleChange(e, "subdomain")}/>
</Form.Group> </Form.Group>
</Grid.Col> </Grid.Col>
<Grid.Col md={6}> <Grid.Col md={6}>

View File

@ -11,26 +11,26 @@ class EnsResolve extends Component {
super(props); super(props);
this.state = { this.state = {
name: '', subdomain: '',
showResult: false showResult: false
}; };
} }
handleChange(e) { handleChange(e) {
this.setState({name: e.target.value, showResult: false}); this.setState({subdomain: e.target.value, showResult: false});
} }
handleResolve() { handleResolve() {
this.setState({showResult: true}); this.setState({showResult: true});
this.props.resolve(this.state.name); this.props.resolve(this.state.subdomain);
} }
showResult() { showResult() {
let ensRecord = this.props.ensRecords.find((record) => record.name === this.state.name); let ensRecord = this.props.ensRecords.find((record) => record.subdomain === this.state.subdomain);
if (ensRecord) { if (ensRecord) {
return <Alert type="success">The address is: {ensRecord.address}</Alert>; return <Alert type="success">The address is: {ensRecord.address}</Alert>;
} else { } else {
return <Alert type="danger">We could not find an address for this name</Alert>; return <Alert type="danger">We could not find an address for this subdomain</Alert>;
} }
} }

View File

@ -59,8 +59,8 @@ const filtrer = {
)); ));
}, },
ensRecords: function(record, index, self) { ensRecords: function(record, index, self) {
return record.name && record.address && record.address !== voidAddress && index === self.findIndex((r) => ( return record.subdomain && record.address && record.address !== voidAddress && index === self.findIndex((r) => (
r.address=== record.address && r.name === record.name r.address=== record.address && r.subdomain === record.subdomain
)); ));
} }
}; };