Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
dedupe getAll contract call
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges committed Aug 10, 2022
1 parent 1bd3d50 commit 90d3052
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/core/classes/contract-publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,17 @@ export class ContractPublisher extends RPCConnectionHandler {
const data = await this.publisher.readContract.getAllPublishedContracts(
publisherAddress,
);
return data.map((d) => this.toPublishedContract(d));
// since we can fetch from multiple publisher contracts, just keep the latest one in the list
const map = data.reduce<
Record<string, IContractPublisher.CustomContractInstanceStruct>
>((acc, curr) => {
// replaces the previous contract with the latest one
acc[curr.contractId] = curr;
return acc;
}, {});
return Object.entries(map).map(([_, struct]) =>
this.toPublishedContract(struct),
);
}

/**
Expand Down

0 comments on commit 90d3052

Please sign in to comment.