Skip to content

Commit

Permalink
allow migration when chains were not previously present, bump version (
Browse files Browse the repository at this point in the history
  • Loading branch information
mholtzman authored Feb 24, 2023
1 parent aa72dbf commit efa0593
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 63 deletions.
136 changes: 76 additions & 60 deletions main/store/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,51 +548,54 @@ const migrations = {
}
}

// we removed support for the following goerli RPCs so reset the connections
// to defaults when the user was previously connecting to them
const removedGoerliRPCs = ['mudit', 'slockit', 'prylabs']
const goerli = initial.main.networks.ethereum[5]
const goerliPrimaryConnection = goerli.connection.primary.current
const goerliSecondaryConnection = goerli.connection.secondary.current

if (removedGoerliRPCs.includes(goerliPrimaryConnection)) {
initial.main.networks.ethereum[5] = {
...goerli,
connection: {
...goerli.connection,
primary: {
on: false,
current: 'custom',
status: 'loading',
connected: false,
type: '',
network: '',
custom: ''
if ('5' in initial.main.networks.ethereum) {
// we removed support for the following goerli RPCs so reset the connections
// to defaults when the user was previously connecting to them
const removedGoerliRPCs = ['mudit', 'slockit', 'prylabs']
const goerli = initial.main.networks.ethereum[5]
const goerliPrimaryConnection = goerli.connection.primary.current
const goerliSecondaryConnection = goerli.connection.secondary.current

if (removedGoerliRPCs.includes(goerliPrimaryConnection)) {
initial.main.networks.ethereum[5] = {
...goerli,
connection: {
...goerli.connection,
primary: {
on: false,
current: 'custom',
status: 'loading',
connected: false,
type: '',
network: '',
custom: ''
}
}
}
}
}
if (removedGoerliRPCs.includes(goerliSecondaryConnection)) {
initial.main.networks.ethereum[5] = {
...goerli,
connection: {
...goerli.connection,
secondary: {
on: false,
current: 'custom',
status: 'loading',
connected: false,
type: '',
network: '',
custom: ''

if (removedGoerliRPCs.includes(goerliSecondaryConnection)) {
initial.main.networks.ethereum[5] = {
...goerli,
connection: {
...goerli.connection,
secondary: {
on: false,
current: 'custom',
status: 'loading',
connected: false,
type: '',
network: '',
custom: ''
}
}
}
}
}

// if neither primary nor secondary is enabled then we switch the overall connection off
initial.main.networks.ethereum[5].connection.on =
goerli.connection.primary.on || goerli.connection.secondary.on
// if neither primary nor secondary is enabled then we switch the overall connection off
initial.main.networks.ethereum[5].connection.on =
goerli.connection.primary.on || goerli.connection.secondary.on
}

return initial
},
Expand Down Expand Up @@ -650,19 +653,24 @@ const migrations = {
return initial
},
25: (initial) => {
const optimism = initial.main.networks.ethereum[10]
const removeOptimismConnection = (connection) => ({
...connection,
current: connection.current === 'optimism' ? 'infura' : connection.current
})
// remove Optimism RPC connection presets and use Infura instead
if ('10' in initial.main.networks.ethereum) {
const removeOptimismConnection = (connection) => ({
...connection,
current: connection.current === 'optimism' ? 'infura' : connection.current
})

initial.main.networks.ethereum[10] = {
...optimism,
connection: {
primary: removeOptimismConnection(optimism.connection.primary),
secondary: removeOptimismConnection(optimism.connection.secondary)
const optimism = initial.main.networks.ethereum[10]

initial.main.networks.ethereum[10] = {
...optimism,
connection: {
primary: removeOptimismConnection(optimism.connection.primary),
secondary: removeOptimismConnection(optimism.connection.secondary)
}
}
}

return initial
},
26: (initial) => {
Expand Down Expand Up @@ -691,20 +699,28 @@ const migrations = {
return initial
},
28: (initial) => {
const networkMeta = initial.main.networksMeta.ethereum
const {
5: {
nativeCurrency: { symbol: goerliSymbol }
},
11155111: {
nativeCurrency: { symbol: sepoliaSymbol }
const getUpdatedSymbol = (symbol, chainId) => {
return parseInt(chainId) === 5 ? 'görETH' : parseInt(chainId) === 11155111 ? 'sepETH' : symbol
}

const updatedMeta = Object.entries(initial.main.networksMeta.ethereum).map(([id, chainMeta]) => {
const { symbol, decimals } = chainMeta.nativeCurrency
const updatedSymbol = (symbol || '').toLowerCase() !== 'eth' ? symbol : getUpdatedSymbol(symbol, id)

const updatedChainMeta = {
...chainMeta,
nativeCurrency: {
...chainMeta.nativeCurrency,
symbol: updatedSymbol,
decimals: decimals || 18
}
}
} = networkMeta
goerliSymbol === 'ETH' && (initial.main.networksMeta.ethereum[5].nativeCurrency.symbol = 'görETH')
sepoliaSymbol === 'ETH' && (initial.main.networksMeta.ethereum[11155111].nativeCurrency.symbol = 'sepETH')
Object.values(initial.main.networksMeta.ethereum).forEach((metadata) => {
metadata.nativeCurrency.decimals = metadata.nativeCurrency.decimals || 18

return [id, updatedChainMeta]
})

initial.main.networksMeta.ethereum = Object.fromEntries(updatedMeta)

return initial
},
29: (initial) => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frame",
"version": "0.6.0",
"version": "0.6.1",
"description": "System-wide web3",
"main": "compiled/main",
"scripts": {
Expand Down
32 changes: 32 additions & 0 deletions test/main/store/migrations/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,14 @@ describe('migration 21', () => {

expect(goerli.on).toBe(false)
})

it('takes no action on goerli if the chain is not present', () => {
delete state.main.networks.ethereum[5]

const updatedState = migrations.apply(state, 21)

expect(Object.keys(updatedState.main.networks.ethereum)).toEqual(['11155111'])
})
})

describe('migration 22', () => {
Expand Down Expand Up @@ -967,6 +975,14 @@ describe('migration 25', () => {

expect(optimism.connection[priority].current).toBe('custom')
})

it('takes no action if no Optimism chain is present', () => {
delete state.main.networks.ethereum[10]

const updatedState = migrations.apply(state, 25)

expect(updatedState.main.networks).toStrictEqual({ ethereum: {} })
})
})
})

Expand Down Expand Up @@ -1100,6 +1116,22 @@ describe('migration 28', () => {
const metadata = updatedState.main.networksMeta.ethereum
expect(metadata[5].nativeCurrency.decimals).toBe(18)
})

it('takes no action on Goerli if the chain is not present', () => {
delete state.main.networksMeta.ethereum[5]

const updatedState = migrations.apply(state, 28)

expect(Object.keys(updatedState.main.networksMeta.ethereum)).toEqual(['11155111'])
})

it('takes no action on Sepolia if the chain is not present', () => {
delete state.main.networksMeta.ethereum[11155111]

const updatedState = migrations.apply(state, 28)

expect(Object.keys(updatedState.main.networksMeta.ethereum)).toEqual(['5'])
})
})

describe('migration 29', () => {
Expand Down

0 comments on commit efa0593

Please sign in to comment.