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

Migrations: ensure native currency names & symbols #1468

Merged
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
56 changes: 48 additions & 8 deletions main/store/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,14 +781,6 @@ const migrations = {

initial.main.tokens.known = knownTokens

const nameNotSet = (chainId) => {
const meta = initial.main.networksMeta.ethereum[chainId]
return meta && !meta.nativeCurrency.name
}

if (nameNotSet(100)) initial.main.networksMeta.ethereum[100].nativeCurrency.name = 'xDAI'
if (nameNotSet(137)) initial.main.networksMeta.ethereum[137].nativeCurrency.name = 'Matic'

return initial
},
33: (initial) => {
Expand Down Expand Up @@ -856,6 +848,54 @@ const migrations = {
}
}

return initial
},
34: (initial) => {
// Add any missing nativeCurrency name values
// Base Görli (84531) value added in #33
const nativeCurrencyMap = {
1: {
name: 'Ether',
symbol: 'ETH'
},
5: {
name: 'Görli Ether',
symbol: 'görETH'
},
10: {
name: 'Ether',
symbol: 'ETH'
},
100: {
name: 'xDAI',
symbol: 'xDAI'
},
137: {
name: 'Matic',
symbol: 'MATIC'
},
42161: {
name: 'Ether',
symbol: 'ETH'
},
11155111: {
name: 'Sepolia Ether',
symbol: 'sepETH'
}
}

Object.values(initial.main.networks.ethereum).forEach((network) => {
const { id } = network
const { name = '', symbol = '' } = nativeCurrencyMap[id] || {}
const nativeCurrency = initial.main.networksMeta.ethereum[id].nativeCurrency

initial.main.networksMeta.ethereum[id].nativeCurrency = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we assume that this chain exists in networksMeta?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...nativeCurrency,
name: nativeCurrency.name || name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Using the spread should assign the name from nativeCurrency if it exists, couldn't we set the default data first and then spread on top?

Copy link
Contributor Author

@goosewobbler goosewobbler Mar 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not sure this works - tests fail

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would assign the name to what was in nativeCurrency even if it were falsy, for example overwriting the new value with empty string, for example

symbol: nativeCurrency.symbol || symbol
}
})

return initial
}
}
Expand Down
Loading