Skip to content

Commit f9d43fe

Browse files
authored
Merge pull request #150 from c4dt/increase_timeout
Increase timeout
2 parents f8d78b8 + c1477bc commit f9d43fe

File tree

3 files changed

+24
-32
lines changed

3 files changed

+24
-32
lines changed

web/frontend/src/components/utils/usePostCall.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const usePostCall = (setError) => {
1717
try {
1818
const result = await response.json();
1919
if (result.Token) {
20-
pollTransaction(checkTransaction, result.Token, 1000, 30).then(
20+
// 600s is the time to shuffle 10'000 votes. This should be enough for
21+
// everybody.
22+
pollTransaction(checkTransaction, result.Token, 1000, 600).then(
2123
() => {
2224
setIsPosting((prev) => !prev);
2325
},

web/frontend/src/pages/form/components/FomrStatusLoading.tsx

-11
This file was deleted.

web/frontend/src/pages/form/components/utils/TransactionPoll.ts

+21-20
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,35 @@ const pollTransaction = (
1212
};
1313

1414
const executePoll = async (resolve, reject): Promise<any> => {
15+
let response, result;
1516
try {
1617
attempts += 1;
17-
const response = await fetch(endpoint(data), request);
18-
const result = await response.json();
19-
20-
if (!response.ok) {
21-
throw new Error(JSON.stringify(result));
22-
}
18+
response = await fetch(endpoint(data), request);
19+
result = await response.json();
20+
} catch (e) {
21+
return reject(e);
22+
}
2323

24-
data = result.Token;
24+
if (!response.ok) {
25+
throw new Error(JSON.stringify(result));
26+
}
2527

26-
if (result.Status === 1) {
27-
return resolve(result);
28-
}
28+
data = result.Token;
2929

30-
if (result.Status === 2) {
31-
throw new Error('Transaction Rejected');
32-
}
30+
if (result.Status === 1) {
31+
return resolve(result);
32+
}
3333

34-
// Add a timeout
35-
if (attempts === maxAttempts) {
36-
throw new Error('Timeout');
37-
}
34+
if (result.Status === 2) {
35+
throw new Error('Transaction Rejected');
36+
}
3837

39-
setTimeout(executePoll, interval, resolve, reject);
40-
} catch (e) {
41-
return reject(e);
38+
// Add a timeout
39+
if (attempts === maxAttempts) {
40+
throw new Error('Timeout');
4241
}
42+
43+
setTimeout(executePoll, interval, resolve, reject);
4344
};
4445

4546
return new Promise(executePoll);

0 commit comments

Comments
 (0)