Skip to content

Commit

Permalink
Ignore extra pkhs when fetching networks for contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
asiia-trilitech committed Apr 15, 2024
1 parent a49c00d commit e635781
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/utils/multisig/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,25 @@ describe("multisig helpers", () => {
])
);
});

it("filters out extra pkhs from api response", async () => {
mockedContractsGet.mockImplementation((...args) => {
if (args[1].baseUrl === MAINNET.tzktApiUrl) {
return Promise.resolve(["pkh1", "pkh3", "pkh4"] as any);
} else {
return Promise.resolve(["pkh2", "pkh5"] as any);
}
});

const result = await getNetworksForContracts([MAINNET, GHOSTNET], ["pkh1", "pkh2", "pkh3"]);

expect(result).toEqual(
new Map([
["pkh1", MAINNET.name],
["pkh2", GHOSTNET.name],
["pkh3", MAINNET.name],
])
);
});
});
});
6 changes: 5 additions & 1 deletion src/utils/multisig/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export const getNetworksForContracts = async (
])
)
);
accountsWithNetwork.flat().forEach(([pkh, network]) => result.set(pkh, network));
accountsWithNetwork.flat().forEach(([pkh, network]) => {
if (contractPkhs.includes(pkh)) {
result.set(pkh, network);
}
});

return result;
};
Expand Down
1 change: 1 addition & 0 deletions src/utils/redux/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe("migrations", () => {
new Map([
[mainnetPkh, "mainnet"],
[ghostnetPkh, "ghostnet"],
[mockContractAddress(3).pkh, "ghostnet"], // not in the store
])
);

Expand Down
8 changes: 4 additions & 4 deletions src/utils/redux/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ export const mainStoreMigrations = {
state.networks.available,
contractPkhs
);
const contractAccounts = [...contractsWithNetworks.entries()].map(([pkh, network]) => [
pkh,
{ ...state.contacts[pkh], network },
]);
const contractAccounts = contractPkhs
.filter(pkh => contractsWithNetworks.has(pkh))
.map(pkh => [pkh, { ...state.contacts[pkh], network: contractsWithNetworks.get(pkh) }]);

return produce(state, (draft: any) => {
draft.contacts = fromPairs([...implicitAccounts, ...contractAccounts]);
Expand Down Expand Up @@ -84,4 +83,5 @@ export const accountsMigrations = {
});
}),
5: identity,
6: identity,
} as any;

1 comment on commit e635781

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 86.46% 3147/3640
🟡 Branches 79.22% 1083/1367
🟢 Functions 85.22% 992/1164
🟢 Lines 86.2% 2980/3457

Test suite run success

1373 tests passing in 171 suites.

Report generated by 🧪jest coverage report action from e635781

Please sign in to comment.