Skip to content

Commit

Permalink
Fix/add chain names (#1338)
Browse files Browse the repository at this point in the history
* migration to add missing nativeCurrency, and get rid of optimism duplicates from known tokens

* update initial state
  • Loading branch information
Jamchello authored Jan 13, 2023
1 parent 482c64e commit 9b72c8c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
12 changes: 12 additions & 0 deletions main/store/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,18 @@ const migrations = {
initial.main.balances[address] = balances.filter(({ address }) => address !== dodgyAddress)
})

return initial
},
32: (initial) => {
const dodgyAddress = '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000'

Object.entries(initial.main.tokens.known).forEach(([address, knownTokens]) => {
initial.main.tokens.known[address] = knownTokens.filter(({ address }) => address !== dodgyAddress)
})

initial.main.networksMeta.ethereum[100].nativeCurrency.name = 'xDAI'
initial.main.networksMeta.ethereum[137].nativeCurrency.name = 'Matic'

return initial
}
}
Expand Down
7 changes: 3 additions & 4 deletions main/store/state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const initial = {
},
platform: process.platform,
main: {
_version: main('_version', 31),
_version: main('_version', 32),
instanceId: main('instanceId', generateUuid()),
colorway: main('colorway', 'dark'),
colorwayPrimary: {
Expand Down Expand Up @@ -605,8 +605,7 @@ const initial = {
change24hr: 0
},
icon: '',
name: '',
symbol: '',
name: 'xDAI',
decimals: 18
},
icon: 'https://frame.nyc3.cdn.digitaloceanspaces.com/icons/gnosis.svg',
Expand All @@ -628,7 +627,7 @@ const initial = {
change24hr: 0
},
icon: '',
name: '',
name: 'Matic',
decimals: 18
},
icon: 'https://frame.nyc3.cdn.digitaloceanspaces.com/icons/polygon.svg',
Expand Down
65 changes: 65 additions & 0 deletions test/main/store/migrations/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1293,3 +1293,68 @@ describe('migration 31', () => {
])
})
})

describe('migration 32', () => {
const getNativeCurrency = (state, chainId) => state.main.networksMeta.ethereum[chainId].nativeCurrency
const getKnownTokens = (state) => state.main.tokens.known[account]

const account = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'
beforeEach(() => {
state = {
main: {
_version: 31,
networksMeta: {
ethereum: {
100: {
nativeCurrency: {
symbol: 'ETH',
decimals: 0
}
},
137: {
nativeCurrency: {
symbol: 'ETH',
decimals: 18
}
}
}
},
tokens: {
known: {
[account]: [
{
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
},
{
address: '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000'
}
]
}
}
}
}
})

it('should remove any known tokens with the address `0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000`', () => {
const updatedState = migrations.apply(state, 32)
const known = getKnownTokens(updatedState)
expect(known.find(({ address }) => address === '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000')).toBeFalsy()
})

it('should not remove any other known tokens', () => {
const oldKnown = getKnownTokens(state)
const updatedState = migrations.apply(state, 32)
const updatedKnown = getKnownTokens(updatedState)

expect(updatedKnown.length).toBe(oldKnown.length - 1)
})

it('should add the the native currency name for Gnosis mainnet', () => {
const updatedState = migrations.apply(state, 32)
expect(getNativeCurrency(updatedState, 100).name).toBe('xDAI')
})
it('should add the the native currency name for Polygon mainnet', () => {
const updatedState = migrations.apply(state, 32)
expect(getNativeCurrency(updatedState, 137).name).toBe('Matic')
})
})

0 comments on commit 9b72c8c

Please sign in to comment.