Skip to content

Commit

Permalink
Migrations: ensure native currency names & symbols (#1468)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Holtzman <matt.holtzman@gmail.com>
  • Loading branch information
goosewobbler and mholtzman authored Mar 3, 2023
1 parent 54e7fcd commit 8b6b841
Show file tree
Hide file tree
Showing 2 changed files with 362 additions and 338 deletions.
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 = {
...nativeCurrency,
name: nativeCurrency.name || name,
symbol: nativeCurrency.symbol || symbol
}
})

return initial
}
}
Expand Down
Loading

0 comments on commit 8b6b841

Please sign in to comment.