Skip to content

Commit

Permalink
Merge pull request #150 from c4dt/increase_timeout
Browse files Browse the repository at this point in the history
Increase timeout
  • Loading branch information
ineiti authored Mar 15, 2024
2 parents f8d78b8 + c1477bc commit f9d43fe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
4 changes: 3 additions & 1 deletion web/frontend/src/components/utils/usePostCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const usePostCall = (setError) => {
try {
const result = await response.json();
if (result.Token) {
pollTransaction(checkTransaction, result.Token, 1000, 30).then(
// 600s is the time to shuffle 10'000 votes. This should be enough for
// everybody.
pollTransaction(checkTransaction, result.Token, 1000, 600).then(
() => {
setIsPosting((prev) => !prev);
},
Expand Down
11 changes: 0 additions & 11 deletions web/frontend/src/pages/form/components/FomrStatusLoading.tsx

This file was deleted.

41 changes: 21 additions & 20 deletions web/frontend/src/pages/form/components/utils/TransactionPoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,35 @@ const pollTransaction = (
};

const executePoll = async (resolve, reject): Promise<any> => {
let response, result;
try {
attempts += 1;
const response = await fetch(endpoint(data), request);
const result = await response.json();

if (!response.ok) {
throw new Error(JSON.stringify(result));
}
response = await fetch(endpoint(data), request);
result = await response.json();
} catch (e) {
return reject(e);
}

data = result.Token;
if (!response.ok) {
throw new Error(JSON.stringify(result));
}

if (result.Status === 1) {
return resolve(result);
}
data = result.Token;

if (result.Status === 2) {
throw new Error('Transaction Rejected');
}
if (result.Status === 1) {
return resolve(result);
}

// Add a timeout
if (attempts === maxAttempts) {
throw new Error('Timeout');
}
if (result.Status === 2) {
throw new Error('Transaction Rejected');
}

setTimeout(executePoll, interval, resolve, reject);
} catch (e) {
return reject(e);
// Add a timeout
if (attempts === maxAttempts) {
throw new Error('Timeout');
}

setTimeout(executePoll, interval, resolve, reject);
};

return new Promise(executePoll);
Expand Down

0 comments on commit f9d43fe

Please sign in to comment.