Skip to content

Commit f9d30bb

Browse files
committed
refactor: explicitly check for presence instead of non-null assertion
1 parent 9137745 commit f9d30bb

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

governance/xc_admin/packages/xc_admin_common/src/programs/core/core_functions.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ export function getConfig(params: GetConfigParams): RawConfig {
147147
{
148148
next: parsed.nextPriceAccountKey,
149149
address: account.pubkey,
150-
publishers: parsed.priceComponents.map((x) => x.publisher!),
150+
publishers: parsed.priceComponents
151+
.filter((x) => x.publisher !== null && x.publisher !== undefined)
152+
.map((x) => x.publisher),
151153
expo: parsed.exponent,
152154
minPub: parsed.minPublishers,
153155
maxLatency: parsed.maxLatency,
@@ -752,17 +754,18 @@ export async function generateInstructions(
752754
newChanges.priceAccounts[0] &&
753755
newChanges.priceAccounts[0].publishers
754756
) {
757+
// We've already checked that these properties exist above
758+
const prevPublishers = prev.priceAccounts[0].publishers;
759+
const newPublishers = newChanges.priceAccounts[0].publishers;
760+
755761
// check if publishers have changed
756-
const publisherKeysToAdd =
757-
newChanges.priceAccounts[0].publishers.filter(
758-
(newPublisher: string) =>
759-
!prev.priceAccounts![0].publishers!.includes(newPublisher),
760-
);
762+
const publisherKeysToAdd = newPublishers.filter(
763+
(newPublisher: string) => !prevPublishers.includes(newPublisher),
764+
);
761765

762766
// check if there are any publishers to remove by comparing prev and new
763-
const publisherKeysToRemove = prev.priceAccounts[0].publishers.filter(
764-
(prevPublisher: string) =>
765-
!newChanges.priceAccounts![0].publishers!.includes(prevPublisher),
767+
const publisherKeysToRemove = prevPublishers.filter(
768+
(prevPublisher: string) => !newPublishers.includes(prevPublisher),
766769
);
767770

768771
// add instructions to remove publishers

0 commit comments

Comments
 (0)