Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
verification: check if server is running (#4140)
Browse files Browse the repository at this point in the history
* verification: check if server is running

See also ethcore/email-verification#67c6466 and ethcore/sms-verification#a585e42.

* verification: show in the UI if server is running

* verification: code style ✨, more i18n

* fix i18n key
  • Loading branch information
derhuerst authored and arkpar committed Jan 16, 2017
1 parent 5b30a61 commit 8939e78
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 25 deletions.
13 changes: 13 additions & 0 deletions js/src/3rdparty/email-verification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@

import { stringify } from 'querystring';

export const isServerRunning = (isTestnet = false) => {
const port = isTestnet ? 28443 : 18443;
return fetch(`https://email-verification.parity.io:${port}/health`, {
mode: 'cors', cache: 'no-store'
})
.then((res) => {
return res.ok;
})
.catch(() => {
return false;
});
};

export const postToServer = (query, isTestnet = false) => {
const port = isTestnet ? 28443 : 18443;
query = stringify(query);
Expand Down
13 changes: 13 additions & 0 deletions js/src/3rdparty/sms-verification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@

import { stringify } from 'querystring';

export const isServerRunning = (isTestnet = false) => {
const port = isTestnet ? 8443 : 443;
return fetch(`https://sms-verification.parity.io:${port}/health`, {
mode: 'cors', cache: 'no-store'
})
.then((res) => {
return res.ok;
})
.catch(() => {
return false;
});
};

export const postToServer = (query, isTestnet = false) => {
const port = isTestnet ? 8443 : 443;
query = stringify(query);
Expand Down
104 changes: 94 additions & 10 deletions js/src/modals/Verification/GatherData/gatherData.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import React, { Component, PropTypes } from 'react';
import { FormattedMessage } from 'react-intl';
import BigNumber from 'bignumber.js';
import { Checkbox } from 'material-ui';
import InfoIcon from 'material-ui/svg-icons/action/info-outline';
Expand All @@ -33,10 +34,11 @@ import styles from './gatherData.css';
export default class GatherData extends Component {
static propTypes = {
fee: React.PropTypes.instanceOf(BigNumber),
method: PropTypes.string.isRequired,
fields: PropTypes.array.isRequired,
isVerified: nullableProptype(PropTypes.bool.isRequired),
hasRequested: nullableProptype(PropTypes.bool.isRequired),
isServerRunning: nullableProptype(PropTypes.bool.isRequired),
isVerified: nullableProptype(PropTypes.bool.isRequired),
method: PropTypes.string.isRequired,
setConsentGiven: PropTypes.func.isRequired
}

Expand All @@ -48,13 +50,19 @@ export default class GatherData extends Component {
return (
<Form>
{ howItWorks }
{ this.renderServerRunning() }
{ this.renderFee() }
{ this.renderCertified() }
{ this.renderRequested() }
{ this.renderFields() }
<Checkbox
className={ styles.spacing }
label={ 'I agree to the terms and conditions below.' }
label={
<FormattedMessage
id='ui.verification.gatherData.termsOfService'
defaultMessage='I agree to the terms and conditions below.'
/>
}
disabled={ isVerified }
onCheck={ this.consentOnChange }
/>
Expand All @@ -63,6 +71,44 @@ export default class GatherData extends Component {
);
}

renderServerRunning () {
const { isServerRunning } = this.props;

if (isServerRunning) {
return (
<div className={ styles.container }>
<SuccessIcon />
<p className={ styles.message }>
<FormattedMessage
id='ui.verification.gatherData.isServerRunning.true'
defaultMessage='The verification server is running.'
/>
</p>
</div>
);
} else if (isServerRunning === false) {
return (
<div className={ styles.container }>
<ErrorIcon />
<p className={ styles.message }>
<FormattedMessage
id='ui.verification.gatherData.isServerRunning.false'
defaultMessage='The verification server is not running.'
/>
</p>
</div>
);
}
return (
<p className={ styles.message }>
<FormattedMessage
id='ui.verification.gatherData.isServerRunning.pending'
defaultMessage='Checking if the verification server is running…'
/>
</p>
);
}

renderFee () {
const { fee } = this.props;

Expand All @@ -72,7 +118,15 @@ export default class GatherData extends Component {
return (
<div className={ styles.container }>
<InfoIcon />
<p className={ styles.message }>The fee is { fromWei(fee).toFixed(3) } ETH.</p>
<p className={ styles.message }>
<FormattedMessage
id='ui.verification.gatherData.fee'
defaultMessage='The fee is {amount} ETH.'
values={ {
amount: fromWei(fee).toFixed(3)
} }
/>
</p>
</div>
);
}
Expand All @@ -84,19 +138,34 @@ export default class GatherData extends Component {
return (
<div className={ styles.container }>
<ErrorIcon />
<p className={ styles.message }>Your account is already verified.</p>
<p className={ styles.message }>
<FormattedMessage
id='ui.verification.gatherData.isVerified.true'
defaultMessage='Your account is already verified.'
/>
</p>
</div>
);
} else if (isVerified === false) {
return (
<div className={ styles.container }>
<SuccessIcon />
<p className={ styles.message }>Your account is not verified yet.</p>
<p className={ styles.message }>
<FormattedMessage
id='ui.verification.gatherData.isVerified.false'
defaultMessage='Your account is not verified yet.'
/>
</p>
</div>
);
}
return (
<p className={ styles.message }>Checking if your account is verified…</p>
<p className={ styles.message }>
<FormattedMessage
id='ui.verification.gatherData.isVerified.pending'
defaultMessage='Checking if your account is verified…'
/>
</p>
);
}

Expand All @@ -112,19 +181,34 @@ export default class GatherData extends Component {
return (
<div className={ styles.container }>
<InfoIcon />
<p className={ styles.message }>You already requested verification.</p>
<p className={ styles.message }>
<FormattedMessage
id='ui.verification.gatherData.hasRequested.true'
defaultMessage='You already requested verification.'
/>
</p>
</div>
);
} else if (hasRequested === false) {
return (
<div className={ styles.container }>
<SuccessIcon />
<p className={ styles.message }>You did not request verification yet.</p>
<p className={ styles.message }>
<FormattedMessage
id='ui.verification.gatherData.hasRequested.false'
defaultMessage='You did not request verification yet.'
/>
</p>
</div>
);
}
return (
<p className={ styles.message }>Checking if you requested verification…</p>
<p className={ styles.message }>
<FormattedMessage
id='ui.verification.gatherData.hasRequested.pending'
defaultMessage='Checking if you requested verification…'
/>
</p>
);
}

Expand Down
6 changes: 5 additions & 1 deletion js/src/modals/Verification/email-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import EmailVerificationABI from '~/contracts/abi/email-verification.json';
import VerificationStore, {
LOADING, QUERY_DATA, QUERY_CODE, POSTED_CONFIRMATION, DONE
} from './store';
import { postToServer } from '../../3rdparty/email-verification';
import { isServerRunning, postToServer } from '../../3rdparty/email-verification';

const EMAIL_VERIFICATION = 7; // id in the `BadgeReg.sol` contract

Expand Down Expand Up @@ -59,6 +59,10 @@ export default class EmailVerificationStore extends VerificationStore {
super(api, EmailVerificationABI, EMAIL_VERIFICATION, account, isTestnet);
}

isServerRunning = () => {
return isServerRunning(this.isTestnet);
}

requestValues = () => [ sha3.text(this.email) ]

@action setEmail = (email) => {
Expand Down
6 changes: 5 additions & 1 deletion js/src/modals/Verification/sms-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import SMSVerificationABI from '~/contracts/abi/sms-verification.json';
import VerificationStore, {
LOADING, QUERY_DATA, QUERY_CODE, POSTED_CONFIRMATION, DONE
} from './store';
import { postToServer } from '../../3rdparty/sms-verification';
import { isServerRunning, postToServer } from '../../3rdparty/sms-verification';

const SMS_VERIFICATION = 0; // id in the `BadgeReg.sol` contract

Expand Down Expand Up @@ -58,6 +58,10 @@ export default class SMSVerificationStore extends VerificationStore {
super(api, SMSVerificationABI, SMS_VERIFICATION, account, isTestnet);
}

isServerRunning = () => {
return isServerRunning(this.isTestnet);
}

@action setNumber = (number) => {
this.number = number;
}
Expand Down
11 changes: 10 additions & 1 deletion js/src/modals/Verification/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class VerificationStore {
@observable fee = null;
@observable isVerified = null;
@observable hasRequested = null;
@observable isServerRunning = null;
@observable consentGiven = false;
@observable requestTx = null;
@observable code = '';
Expand Down Expand Up @@ -73,6 +74,14 @@ export default class VerificationStore {
const { contract, account } = this;
this.step = LOADING;
const isServerRunning = this.isServerRunning()
.then((isRunning) => {
this.isServerRunning = isRunning;
})
.catch((err) => {
this.error = 'Failed to check if server is running: ' + err.message;
});
const fee = contract.instance.fee.call()
.then((fee) => {
this.fee = fee;
Expand Down Expand Up @@ -101,7 +110,7 @@ export default class VerificationStore {
});
Promise
.all([ fee, isVerified, hasRequested ])
.all([ isServerRunning, fee, isVerified, hasRequested ])
.then(() => {
this.step = QUERY_DATA;
});
Expand Down
Loading

0 comments on commit 8939e78

Please sign in to comment.