sms verification: move helper functions
- checkIfTxFailed & waitForBlockConfirmations are both general-purpose - checkIfVerified, checkIfRequested & postToServer are sms verification-specific
This commit is contained in:
parent
a59526099d
commit
3f0053f884
@ -19,6 +19,7 @@ import Registry from './registry';
|
||||
import SignatureReg from './signaturereg';
|
||||
import TokenReg from './tokenreg';
|
||||
import GithubHint from './githubhint';
|
||||
import smsVerification from './sms-verification';
|
||||
|
||||
let instance = null;
|
||||
|
||||
@ -54,6 +55,10 @@ export default class Contracts {
|
||||
return this._githubhint;
|
||||
}
|
||||
|
||||
get smsVerification () {
|
||||
return smsVerification;
|
||||
}
|
||||
|
||||
static create (api) {
|
||||
return new Contracts(api);
|
||||
}
|
||||
|
@ -14,7 +14,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
const checkIfRequested = (contract, account) => {
|
||||
import { stringify } from 'querystring';
|
||||
|
||||
export const checkIfVerified = (contract, account) => {
|
||||
return contract.instance.certified.call({}, [account]);
|
||||
};
|
||||
|
||||
export const checkIfRequested = (contract, account) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
contract.subscribe('Requested', {
|
||||
fromBlock: 0, toBlock: 'pending'
|
||||
@ -30,4 +36,17 @@ const checkIfRequested = (contract, account) => {
|
||||
});
|
||||
};
|
||||
|
||||
export default checkIfRequested;
|
||||
export const postToServer = (query) => {
|
||||
query = stringify(query);
|
||||
return fetch('https://sms-verification.parity.io/?' + query, {
|
||||
method: 'POST', mode: 'cors', cache: 'no-store'
|
||||
})
|
||||
.then((res) => {
|
||||
return res.json().then((data) => {
|
||||
if (res.ok) {
|
||||
return data.message;
|
||||
}
|
||||
throw new Error(data.message || 'unknown error');
|
||||
});
|
||||
});
|
||||
};
|
@ -1,21 +0,0 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
const checkIfVerified = (contract, account) => {
|
||||
return contract.instance.certified.call({}, [account]);
|
||||
};
|
||||
|
||||
export default checkIfVerified;
|
@ -1,34 +0,0 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { stringify } from 'querystring';
|
||||
|
||||
const postToVerificationServer = (query) => {
|
||||
query = stringify(query);
|
||||
return fetch('https://sms-verification.parity.io/?' + query, {
|
||||
method: 'POST', mode: 'cors', cache: 'no-store'
|
||||
})
|
||||
.then((res) => {
|
||||
return res.json().then((data) => {
|
||||
if (res.ok) {
|
||||
return data.message;
|
||||
}
|
||||
throw new Error(data.message || 'unknown error');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default postToVerificationServer;
|
@ -22,11 +22,9 @@ import ABI from '../../contracts/abi/sms-verification.json';
|
||||
// TODO: move this to a better place
|
||||
const contract = '0xcE381B876A85A72303f7cA7b3a012f58F4CEEEeB';
|
||||
|
||||
import checkIfVerified from './check-if-verified';
|
||||
import checkIfRequested from './check-if-requested';
|
||||
import checkIfTxFailed from './check-if-tx-failed';
|
||||
import waitForConfirmations from './wait-for-confirmations';
|
||||
import postToVerificationServer from './post-to-verification-server';
|
||||
import { checkIfVerified, checkIfRequested, postToServer } from '../../contracts/sms-verification';
|
||||
import checkIfTxFailed from '../../util/check-if-tx-failed';
|
||||
import waitForConfirmations from '../../util/wait-for-block-confirmations';
|
||||
|
||||
const validCode = /^[A-Z\s]+$/i;
|
||||
|
||||
@ -180,7 +178,7 @@ export default class VerificationStore {
|
||||
chain
|
||||
.then(() => {
|
||||
this.step = REQUESTING_SMS;
|
||||
return postToVerificationServer({ number, address: account });
|
||||
return postToServer({ number, address: account });
|
||||
})
|
||||
.then(() => {
|
||||
this.step = REQUESTED_SMS;
|
||||
|
Loading…
Reference in New Issue
Block a user