-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove infura and alchemy connections in favor of Pylon * add ability to mute migrate to Pylon notice * add notification * add default connection, just in case
- Loading branch information
Showing
8 changed files
with
177 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,49 @@ | ||
function removeRpcConnection(connection: Connection, replaceWithPylon = true) { | ||
const isServiceRpc = connection.current === 'infura' || connection.current === 'alchemy' | ||
|
||
return { | ||
...connection, | ||
// turn off existing connections to Infura or Alchemy if they're not being replaced by Pylon | ||
on: connection.on && (!isServiceRpc || replaceWithPylon), | ||
current: isServiceRpc ? (replaceWithPylon ? 'pylon' : 'custom') : connection.current | ||
} | ||
} | ||
const pylonChainIds = ['1', '5', '10', '137', '42161', '11155111'] | ||
const retiredChainIds = ['3', '4', '42'] | ||
const chainsToMigrate = [...pylonChainIds, ...retiredChainIds] | ||
|
||
export default function (initial: State) { | ||
// disable all Infura and Alchemy connections; these may later be | ||
// replaced by connections to Pylon if the user opts in, otherwise they will be left as | ||
// custom connections to be specified by the user | ||
|
||
function updateChain(chain: Network, replaceWithPylon = true) { | ||
const { primary, secondary } = chain.connection | ||
let showMigrationWarning = false | ||
|
||
const updatedChain = { | ||
...chain, | ||
connection: { | ||
...chain.connection, | ||
primary: removeRpcConnection(primary, replaceWithPylon), | ||
secondary: removeRpcConnection(secondary, replaceWithPylon) | ||
const removeRpcConnection = (connection: Connection) => { | ||
const isServiceRpc = connection.current === 'infura' || connection.current === 'alchemy' | ||
|
||
showMigrationWarning = showMigrationWarning || isServiceRpc | ||
|
||
return { | ||
...connection, | ||
current: isServiceRpc ? 'custom' : connection.current, | ||
custom: isServiceRpc ? '' : connection.custom | ||
} | ||
} | ||
|
||
return updatedChain | ||
} | ||
const updateChain = (chain: Network) => { | ||
const { primary, secondary } = chain.connection | ||
|
||
const updatedChain = { | ||
...chain, | ||
connection: { | ||
...chain.connection, | ||
primary: removeRpcConnection(primary), | ||
secondary: removeRpcConnection(secondary) | ||
} | ||
} | ||
|
||
return updatedChain | ||
} | ||
|
||
export default function (initial: State) { | ||
const chains = Object.entries(initial.main.networks.ethereum) | ||
|
||
// migrate existing Infura and Alchemy connections to use Pylon where applicable | ||
const pylonChains = chains | ||
.filter(([id]) => ['1', '5', '10', '137', '42161', '11155111'].includes(id)) | ||
const migratedChains = chains | ||
.filter(([id]) => chainsToMigrate.includes(id)) | ||
.map(([id, chain]) => [id, updateChain(chain)]) | ||
|
||
// these connections previously used Infura and Alchemy and are not supported by Pylon | ||
const retiredChains = chains | ||
.filter(([id]) => ['3', '4', '42'].includes(id)) | ||
.map(([id, chain]) => [id, updateChain(chain, false)]) | ||
|
||
initial.main.networks.ethereum = Object.fromEntries([...chains, ...pylonChains, ...retiredChains]) | ||
initial.main.networks.ethereum = Object.fromEntries([...chains, ...migratedChains]) | ||
initial.main.mute.migrateToPylon = !showMigrationWarning | ||
|
||
return initial | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters