From cb8a8f36f29133108676a658be19f7a792ae6dd8 Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Fri, 8 Mar 2024 10:19:13 -0500 Subject: [PATCH] remove Pylon presets for Goerli chains (#1704) --- main/store/migrate/migrations/41/index.ts | 61 ++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/main/store/migrate/migrations/41/index.ts b/main/store/migrate/migrations/41/index.ts index 572140bae..1e1324aa8 100644 --- a/main/store/migrate/migrations/41/index.ts +++ b/main/store/migrate/migrations/41/index.ts @@ -1,6 +1,6 @@ import log from 'electron-log' -import { v38StateSchema } from '../38/schema' +import { v38Connection, v38StateSchema } from '../38/schema' function baseSepolia() { const chain = { @@ -128,6 +128,37 @@ function optimismSepolia() { return { chain, metadata } } +function removeGoerliPylonPreset(connection: v38Connection) { + // remove Goerli Pylon preset + const isPylon = connection.current === 'pylon' + + if (isPylon) { + log.info('Migration 41: removing Pylon presets from Goerli') + } + + return { + ...connection, + current: isPylon ? 'custom' : connection.current, + custom: isPylon ? 'wss://evm.pylon.link/goerli' : connection.custom + } +} + +function removeBaseGoerliConnection(connection: v38Connection) { + // remove Base Goerli Pylon preset + const isPylon = connection.current === 'pylon' + + if (isPylon) { + log.info('Migration 41: removing Pylon presets from Base Goerli') + } + + return { + ...connection, + on: isPylon ? false : connection.on, + current: isPylon ? 'custom' : connection.current, + custom: isPylon ? '' : connection.custom + } +} + const migrate = (initial: unknown) => { try { const state = v38StateSchema.parse(initial) @@ -147,6 +178,34 @@ const migrate = (initial: unknown) => { state.main.networksMeta.ethereum[11155420] = metadata } + const goerliChainPresent = '5' in state.main.networks.ethereum + + if (goerliChainPresent) { + const goerliChain = state.main.networks.ethereum[5] + + state.main.networks.ethereum[5] = { + ...goerliChain, + connection: { + primary: removeGoerliPylonPreset(goerliChain.connection.primary), + secondary: removeGoerliPylonPreset(goerliChain.connection.secondary) + } + } + } + + const baseGoerliChainPresent = '84531' in state.main.networks.ethereum + + if (baseGoerliChainPresent) { + const baseGoerliChain = state.main.networks.ethereum[84531] + + state.main.networks.ethereum[84531] = { + ...baseGoerliChain, + connection: { + primary: removeBaseGoerliConnection(baseGoerliChain.connection.primary), + secondary: removeBaseGoerliConnection(baseGoerliChain.connection.secondary) + } + } + } + return state } catch (e) { log.error('Migration 41: could not parse state', e)