diff --git a/main/store/migrations/index.js b/main/store/migrations/index.js index a4485e644..d232d351c 100644 --- a/main/store/migrations/index.js +++ b/main/store/migrations/index.js @@ -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 + } } }) diff --git a/test/main/store/migrations/index.test.js b/test/main/store/migrations/index.test.js index 475a8a171..3d13c2f2f 100644 --- a/test/main/store/migrations/index.test.js +++ b/test/main/store/migrations/index.test.js @@ -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' }) + }) })