verification: don't request a code twice (#4221)

* verification: check if user has received code

* verification: don't request a code twice

* code style :lint:
This commit is contained in:
Jannis Redmann
2017-01-20 13:23:21 +01:00
committed by Gav Wood
parent 4e35fd215e
commit 1f77c4301a
5 changed files with 67 additions and 11 deletions

View File

@@ -18,8 +18,10 @@ 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'
mode: 'cors',
cache: 'no-store'
})
.then((res) => {
return res.ok;
@@ -29,11 +31,30 @@ export const isServerRunning = (isTestnet = false) => {
});
};
export const hasReceivedCode = (number, address, isTestnet = false) => {
const port = isTestnet ? 8443 : 443;
const query = stringify({ number, address });
return fetch(`https://sms-verification.parity.io:${port}/?${query}`, {
mode: 'cors',
cache: 'no-store'
})
.then((res) => {
return res.ok;
})
.catch(() => {
return false; // todo: check for 404
});
};
export const postToServer = (query, isTestnet = false) => {
const port = isTestnet ? 8443 : 443;
query = stringify(query);
return fetch(`https://sms-verification.parity.io:${port}/?` + query, {
method: 'POST', mode: 'cors', cache: 'no-store'
return fetch(`https://sms-verification.parity.io:${port}/?${query}`, {
method: 'POST',
mode: 'cors',
cache: 'no-store'
})
.then((res) => {
return res.json().then((data) => {