Skip to content

Commit

Permalink
ensure chain exists in networksMeta (#1476)
Browse files Browse the repository at this point in the history
* ensure chain exists in networksMeta

* destructure

* add additional test cases

* dont overwrite existing metadata

---------

Co-authored-by: Matt Holtzman <matt.holtzman@gmail.com>
  • Loading branch information
goosewobbler and mholtzman committed Mar 7, 2023
1 parent e5cd876 commit ced11a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
14 changes: 9 additions & 5 deletions main/store/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,12 +887,16 @@ const migrations = {
Object.values(initial.main.networks.ethereum).forEach((network) => {
const { id } = network
const { name = '', symbol = '' } = nativeCurrencyMap[id] || {}
const nativeCurrency = initial.main.networksMeta.ethereum[id].nativeCurrency
const existingMeta = initial.main.networksMeta.ethereum[id] || {}
const { nativeCurrency = {} } = existingMeta

initial.main.networksMeta.ethereum[id].nativeCurrency = {
...nativeCurrency,
name: nativeCurrency.name || name,
symbol: nativeCurrency.symbol || symbol
initial.main.networksMeta.ethereum[id] = {
...existingMeta,
nativeCurrency: {
...nativeCurrency,
name: nativeCurrency.name || name,
symbol: nativeCurrency.symbol || symbol
}
}
})

Expand Down
15 changes: 15 additions & 0 deletions test/main/store/migrations/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1421,4 +1421,19 @@ describe('migration 34', () => {
expect(getNativeCurrency(updatedState, 56)[field]).toBe('')
})
})

it('should set native currency data when no chain metadata previously existed', () => {
state.main.networks.ethereum[10] = { id: 10 }

const updatedState = migrations.apply(state, 34)
expect(getNativeCurrency(updatedState, 10)).toStrictEqual({ name: 'Ether', symbol: 'ETH' })
})

it('should set native currency data when none previously existed', () => {
createChainState(137)
delete state.main.networksMeta.ethereum[137].nativeCurrency

const updatedState = migrations.apply(state, 34)
expect(getNativeCurrency(updatedState, 137)).toStrictEqual({ name: 'Matic', symbol: 'MATIC' })
})
})

0 comments on commit ced11a3

Please sign in to comment.