Skip to content

Commit

Permalink
fix: if any attestors receive and accepts the closing transaction, no…
Browse files Browse the repository at this point in the history
… error is thrown (#65)
  • Loading branch information
Polybius93 authored Apr 2, 2024
1 parent 2736043 commit 86ee872
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/app/hooks/use-attestors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,27 @@ export function useAttestors(): UseAttestorsReturnType {
userNativeSegwitAddress: string
): Promise<void> {
const createPSBTURLs = attestorAPIURLs.map(url => `${url}/app/create-psbt-event`);
try {
const requests = createPSBTURLs.map(async url => {
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' },
body: JSON.stringify({
uuid,
closing_psbt: closingPSBT,
mint_address: userNativeSegwitAddress,
chain: ethereumAttestorChainID,
}),
});

if (!response.ok) {
throw new Error(`HTTP Error! Status: ${response.status}`);
}

return response.text();
});
const requests = createPSBTURLs.map(async url =>
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' },
body: JSON.stringify({
uuid,
closing_psbt: closingPSBT,
mint_address: userNativeSegwitAddress,
chain: ethereumAttestorChainID,
}),
})
.then(response => response.ok)
.catch(() => {
return false;
})
);

await Promise.all(requests);
} catch (error) {
throw new AttestorError(`Error sending closing transaction to Attestors: ${error}`);
const responses = await Promise.all(requests);
if (!responses.includes(true)) {
throw new Error('Error sending Closing Transaction to Attestors!');
}
}

Expand Down

0 comments on commit 86ee872

Please sign in to comment.