sms verification: pull out postToVerificationServer

This commit is contained in:
Jannis R 2016-11-14 18:03:07 +01:00
parent 9df0d33709
commit b5560d27a0
No known key found for this signature in database
GPG Key ID: 0FE83946296A88A5
2 changed files with 39 additions and 15 deletions

View File

@ -19,24 +19,10 @@ import qs from 'querystring';
import TxHash from '../../../ui/TxHash'; import TxHash from '../../../ui/TxHash';
import waitForConfirmations from '../wait-for-confirmations'; import waitForConfirmations from '../wait-for-confirmations';
import postToVerificationServer from '../post-to-verification-server';
import styles from './sendRequest.css'; import styles from './sendRequest.css';
const postToVerificationServer = (query) => {
query = qs.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 class SendRequest extends Component { export default class SendRequest extends Component {
static contextTypes = { static contextTypes = {
api: PropTypes.object.isRequired api: PropTypes.object.isRequired

View File

@ -0,0 +1,38 @@
// 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');
});
})
.catch((err) => {
console.error('foooo', err.stack);
throw err
});
};
export default postToVerificationServer;