Skip to content

Commit b781e97

Browse files
committed
[TOOL-2764] Dashboard: Fix published contract version selector with duplicate versions (#5893)
<!-- start pr-codex --> ## PR-Codex overview This PR focuses on refining the contract fetching logic to ensure that only unique published contracts are returned, specifically keeping the latest version of each contract. ### Detailed summary - Introduced a new variable `publishedContracts` to store fulfilled responses. - Added logic to filter out duplicate contracts by version, keeping only the latest occurrence. - Returned the filtered list of unique published contracts. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 18ef10b commit b781e97

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

apps/dashboard/src/components/contract-components/fetch-contracts-with-versions.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,18 @@ export async function fetchPublishedContractVersions(
4747
),
4848
);
4949

50-
return responses.filter((r) => r.status === "fulfilled").map((r) => r.value);
50+
const publishedContracts = responses
51+
.filter((r) => r.status === "fulfilled")
52+
.map((r) => r.value);
53+
54+
// if there are two published contract with same version, keep the latest (first in list - list is already sorted) one
55+
const uniquePublishedContracts = publishedContracts.filter(
56+
(contract, idx, arr) =>
57+
// if this is the first occurrence of this version in list - keep it
58+
arr.findIndex((c) => c.version === contract.version) === idx,
59+
);
60+
61+
return uniquePublishedContracts;
5162
}
5263

5364
export async function fetchPublishedContractVersion(

0 commit comments

Comments
 (0)