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
Browse files Browse the repository at this point in the history
See also ethcore/email-verification#67c6466 and ethcore/sms-verification#a585e42.
  • Loading branch information
derhuerst committed Jan 11, 2017
1 parent 41da1a0 commit ffe60ea
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 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
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

0 comments on commit ffe60ea

Please sign in to comment.