Merge branch 'master' into ng-webpack-update
This commit is contained in:
@@ -53,7 +53,7 @@ export default class GatherData extends Component {
|
||||
{ this.renderCertified() }
|
||||
{ this.renderRequested() }
|
||||
<Input
|
||||
label={ 'phone number' }
|
||||
label={ 'phone number in international format' }
|
||||
hint={ 'the SMS will be sent to this number' }
|
||||
error={ isNumberValid ? null : 'invalid number' }
|
||||
disabled={ isVerified }
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
LOADING,
|
||||
QUERY_DATA,
|
||||
POSTING_REQUEST, POSTED_REQUEST,
|
||||
REQUESTING_SMS, REQUESTED_SMS,
|
||||
REQUESTING_SMS, QUERY_CODE,
|
||||
POSTING_CONFIRMATION, POSTED_CONFIRMATION,
|
||||
DONE
|
||||
} from './store';
|
||||
@@ -48,7 +48,7 @@ export default class SMSVerification extends Component {
|
||||
[LOADING]: 0,
|
||||
[QUERY_DATA]: 1,
|
||||
[POSTING_REQUEST]: 2, [POSTED_REQUEST]: 2, [REQUESTING_SMS]: 2,
|
||||
[REQUESTED_SMS]: 3,
|
||||
[QUERY_CODE]: 3,
|
||||
[POSTING_CONFIRMATION]: 4, [POSTED_CONFIRMATION]: 4,
|
||||
[DONE]: 5
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export default class SendRequest extends Component {
|
||||
|
||||
case REQUESTING_SMS:
|
||||
return (
|
||||
<p>Requesting an SMS from the Parity server.</p>
|
||||
<p>Requesting an SMS from the Parity server and waiting for the puzzle to be put into the contract.</p>
|
||||
);
|
||||
|
||||
default:
|
||||
|
||||
@@ -20,19 +20,16 @@ import { sha3 } from '../../api/util/sha3';
|
||||
|
||||
import Contracts from '../../contracts';
|
||||
|
||||
import { checkIfVerified, checkIfRequested } from '../../contracts/sms-verification';
|
||||
import { checkIfVerified, checkIfRequested, awaitPuzzle } from '../../contracts/sms-verification';
|
||||
import { postToServer } from '../../3rdparty/sms-verification';
|
||||
import checkIfTxFailed from '../../util/check-if-tx-failed';
|
||||
import waitForConfirmations from '../../util/wait-for-block-confirmations';
|
||||
|
||||
const validCode = /^[A-Z\s]+$/i;
|
||||
|
||||
export const LOADING = 'fetching-contract';
|
||||
export const QUERY_DATA = 'query-data';
|
||||
export const POSTING_REQUEST = 'posting-request';
|
||||
export const POSTED_REQUEST = 'posted-request';
|
||||
export const REQUESTING_SMS = 'requesting-sms';
|
||||
export const REQUESTED_SMS = 'requested-sms';
|
||||
export const QUERY_CODE = 'query-code';
|
||||
export const POSTING_CONFIRMATION = 'posting-confirmation';
|
||||
export const POSTED_CONFIRMATION = 'posted-confirmation';
|
||||
@@ -50,11 +47,9 @@ export default class VerificationStore {
|
||||
@observable number = '';
|
||||
@observable requestTx = null;
|
||||
@observable code = '';
|
||||
@observable isCodeValid = null;
|
||||
@observable confirmationTx = null;
|
||||
|
||||
@computed get isCodeValid () {
|
||||
return validCode.test(this.code);
|
||||
}
|
||||
@computed get isNumberValid () {
|
||||
return phone.isValidNumber(this.number);
|
||||
}
|
||||
@@ -72,20 +67,19 @@ export default class VerificationStore {
|
||||
return this.contract && this.fee && this.isVerified !== null && this.hasRequested !== null;
|
||||
case QUERY_DATA:
|
||||
return this.isNumberValid && this.consentGiven;
|
||||
case REQUESTED_SMS:
|
||||
return this.requestTx;
|
||||
case QUERY_CODE:
|
||||
return this.isCodeValid;
|
||||
return this.requestTx && this.isCodeValid === true;
|
||||
case POSTED_CONFIRMATION:
|
||||
return this.confirmationTx;
|
||||
return !!this.confirmationTx;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
constructor (api, account) {
|
||||
constructor (api, account, isTestnet) {
|
||||
this.api = api;
|
||||
this.account = account;
|
||||
this.isTestnet = isTestnet;
|
||||
|
||||
this.step = LOADING;
|
||||
Contracts.create(api).registry.getContract('smsverification')
|
||||
@@ -151,7 +145,26 @@ export default class VerificationStore {
|
||||
}
|
||||
|
||||
@action setCode = (code) => {
|
||||
const { contract, account } = this;
|
||||
if (!contract || !account || code.length === 0) return;
|
||||
|
||||
const confirm = contract.functions.find((fn) => fn.name === 'confirm');
|
||||
const options = { from: account };
|
||||
const values = [ sha3(code) ];
|
||||
|
||||
this.code = code;
|
||||
this.isCodeValid = null;
|
||||
confirm.estimateGas(options, values)
|
||||
.then((gas) => {
|
||||
options.gas = gas.mul(1.2).toFixed(0);
|
||||
return confirm.call(options, values);
|
||||
})
|
||||
.then((result) => {
|
||||
this.isCodeValid = result === true;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.error = 'Failed to check if the code is valid: ' + err.message;
|
||||
});
|
||||
}
|
||||
|
||||
@action sendRequest = () => {
|
||||
@@ -188,11 +201,15 @@ export default class VerificationStore {
|
||||
|
||||
chain
|
||||
.then(() => {
|
||||
this.step = REQUESTING_SMS;
|
||||
return postToServer({ number, address: account });
|
||||
return api.parity.netChain();
|
||||
})
|
||||
.then((chain) => {
|
||||
this.step = REQUESTING_SMS;
|
||||
return postToServer({ number, address: account }, this.isTestnet);
|
||||
})
|
||||
.then(() => awaitPuzzle(api, contract, account))
|
||||
.then(() => {
|
||||
this.step = REQUESTED_SMS;
|
||||
this.step = QUERY_CODE;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.error = 'Failed to request a confirmation SMS: ' + err.message;
|
||||
|
||||
Reference in New Issue
Block a user