From e635781c8c38158f697266a2025099e26fb371bd Mon Sep 17 00:00:00 2001 From: Ana Maksimovskikh Date: Mon, 15 Apr 2024 13:24:39 +0100 Subject: [PATCH] Ignore extra pkhs when fetching networks for contracts --- src/utils/multisig/helper.test.ts | 20 ++++++++++++++++++++ src/utils/multisig/helpers.ts | 6 +++++- src/utils/redux/migrations.test.ts | 1 + src/utils/redux/migrations.ts | 8 ++++---- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/utils/multisig/helper.test.ts b/src/utils/multisig/helper.test.ts index dee67a9ac4..fef7f56c53 100644 --- a/src/utils/multisig/helper.test.ts +++ b/src/utils/multisig/helper.test.ts @@ -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], + ]) + ); + }); }); }); diff --git a/src/utils/multisig/helpers.ts b/src/utils/multisig/helpers.ts index 6dd6ebae08..f028fc9933 100644 --- a/src/utils/multisig/helpers.ts +++ b/src/utils/multisig/helpers.ts @@ -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; }; diff --git a/src/utils/redux/migrations.test.ts b/src/utils/redux/migrations.test.ts index ca6f6e1e68..9d728d1bda 100644 --- a/src/utils/redux/migrations.test.ts +++ b/src/utils/redux/migrations.test.ts @@ -44,6 +44,7 @@ describe("migrations", () => { new Map([ [mainnetPkh, "mainnet"], [ghostnetPkh, "ghostnet"], + [mockContractAddress(3).pkh, "ghostnet"], // not in the store ]) ); diff --git a/src/utils/redux/migrations.ts b/src/utils/redux/migrations.ts index 94aefc5dd4..6977456e72 100644 --- a/src/utils/redux/migrations.ts +++ b/src/utils/redux/migrations.ts @@ -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]); @@ -84,4 +83,5 @@ export const accountsMigrations = { }); }), 5: identity, + 6: identity, } as any;