Skip to content

Commit 255899a

Browse files
committed
Fix update previous ids for custom networks
1 parent 2737396 commit 255899a

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/modules/ethereum/chains/ChainConfigStore.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ function updateChainOrigin(origin: string, prevOrigin: string | null) {
3030
return origin;
3131
}
3232

33+
function updatePreviousIds(
34+
id: string,
35+
previousId: string,
36+
previousIds: string[] | null
37+
) {
38+
return previousId !== id && !previousIds?.includes(previousId)
39+
? [...(previousIds || []), previousId]
40+
: previousIds;
41+
}
42+
3343
class ChainConfigStore extends PersistentStore<ChainConfig> {
3444
static initialState: ChainConfig = {
3545
version: 2,
@@ -69,10 +79,7 @@ class ChainConfigStore extends PersistentStore<ChainConfig> {
6979
);
7080
const existingEntry = existingItems.get(prevId);
7181
const existingPreviousIds = existingEntry?.previousIds || null;
72-
const previousIds =
73-
prevId !== id && !existingPreviousIds?.includes(prevId)
74-
? [...(existingPreviousIds || []), prevId]
75-
: existingPreviousIds;
82+
const previousIds = updatePreviousIds(id, prevId, existingPreviousIds);
7683
const now = Date.now();
7784
const newEntry: EthereumChainConfig = {
7885
origin: updateChainOrigin(origin, existingEntry?.origin || null),
@@ -122,7 +129,15 @@ class ChainConfigStore extends PersistentStore<ChainConfig> {
122129
`Unable to fetch network info by chainId: ${config.value.chainId}`
123130
);
124131
}
125-
updatedEthereumChainConfigs.push({ ...config, id: network.id });
132+
updatedEthereumChainConfigs.push({
133+
...config,
134+
id: network.id,
135+
previousIds: updatePreviousIds(
136+
network.id,
137+
config.id,
138+
config.previousIds
139+
),
140+
});
126141
} catch {
127142
updatedEthereumChainConfigs.push(config);
128143
}

0 commit comments

Comments
 (0)