Skip to content

Commit

Permalink
Merge pull request #10 from ArtBlocks/no-abort-controller
Browse files Browse the repository at this point in the history
Remove unecessary abort controller
  • Loading branch information
ryley-o authored Dec 16, 2024
2 parents 6b77339 + 7daac7e commit e9dab46
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ function App() {
useEffect(() => {
if (contractAddress === undefined || projectId === undefined) return;

const controller = new AbortController();
let isActiveRequest = true;

async function fetchProjectData() {
if (contractAddress === undefined || projectId === undefined) return;

try {
if (controller.signal.aborted) return;
if (!isActiveRequest) return;

const { projectName, artist } = await getProjectNameAndArtist(
publicClient,
contractAddress as Hex,
BigInt(projectId)
);

if (!controller.signal.aborted) {
if (isActiveRequest) {
setProjectData({ projectName, artist });
}
} catch (error) {
Expand All @@ -64,12 +64,12 @@ function App() {
fetchProjectData();

return () => {
controller.abort();
isActiveRequest = false;
};
}, [contractAddress, projectId, publicClient]);

useEffect(() => {
const controller = new AbortController();
let isActiveRequest = true;

async function fetchTokenData() {
if (
Expand All @@ -84,7 +84,7 @@ function App() {

try {
// Check if already aborted
if (controller.signal.aborted) return;
if (!isActiveRequest) return;

setLoading(true);
const data = await publicClient.readContract({
Expand All @@ -95,14 +95,14 @@ function App() {
});

// Check if aborted before setting state
if (!controller.signal.aborted) {
if (isActiveRequest) {
setDataHtml(data);
setError(null);
setLoading(false);
}
} catch (error) {
// Only set error if not aborted
if (!controller.signal.aborted) {
if (isActiveRequest) {
console.log("error", error);
console.error(error);
setError(
Expand All @@ -117,7 +117,7 @@ function App() {

// Cleanup function that aborts any in-flight request
return () => {
controller.abort();
isActiveRequest = false;
};
}, [contractAddress, tokenInvocation, projectId, publicClient]);

Expand Down

0 comments on commit e9dab46

Please sign in to comment.