Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure chain exists in networksMeta #1476

Merged
merged 4 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' })
})
})