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

Fix/add chain names #1338

Merged
merged 2 commits into from
Jan 13, 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
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')
})
})