Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase timeout #150

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading