Skip to content

Commit

Permalink
Fix update previous ids for custom networks
Browse files Browse the repository at this point in the history
  • Loading branch information
zerts committed May 22, 2024
1 parent caf3c48 commit e052599
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/modules/ethereum/chains/ChainConfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ function updateChainOrigin(origin: string, prevOrigin: string | null) {
return origin;
}

function updatePreviousIds(
id: string,
previousId: string,
previousIds: string[] | null
) {
return previousId !== id && !previousIds?.includes(previousId)
? [...(previousIds || []), previousId]
: previousIds;
}

class ChainConfigStore extends PersistentStore<ChainConfig> {
static initialState: ChainConfig = {
version: 2,
Expand Down Expand Up @@ -69,10 +79,7 @@ class ChainConfigStore extends PersistentStore<ChainConfig> {
);
const existingEntry = existingItems.get(prevId);
const existingPreviousIds = existingEntry?.previousIds || null;
const previousIds =
prevId !== id && !existingPreviousIds?.includes(prevId)
? [...(existingPreviousIds || []), prevId]
: existingPreviousIds;
const previousIds = updatePreviousIds(id, prevId, existingPreviousIds);
const now = Date.now();
const newEntry: EthereumChainConfig = {
origin: updateChainOrigin(origin, existingEntry?.origin || null),
Expand Down Expand Up @@ -122,7 +129,15 @@ class ChainConfigStore extends PersistentStore<ChainConfig> {
`Unable to fetch network info by chainId: ${config.value.chainId}`
);
}
updatedEthereumChainConfigs.push({ ...config, id: network.id });
updatedEthereumChainConfigs.push({
...config,
id: network.id,
previousIds: updatePreviousIds(
network.id,
config.id,
config.previousIds
),
});
} catch {
updatedEthereumChainConfigs.push(config);
}
Expand Down

0 comments on commit e052599

Please sign in to comment.