Display decimal chain ID in network form (#9780)

* Display network form chain ID in decimal

* Hide chainId tooltip in view mode

* Display chain ID error message in entered format

* Update locale messages

* Rename on change chain ID validator
feature/default_network_editable
Erik Marks 4 years ago committed by GitHub
parent 026a06b39d
commit ad838df3e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/_locales/am/messages.json
  2. 2
      app/_locales/ar/messages.json
  3. 2
      app/_locales/bg/messages.json
  4. 2
      app/_locales/bn/messages.json
  5. 2
      app/_locales/ca/messages.json
  6. 2
      app/_locales/da/messages.json
  7. 2
      app/_locales/el/messages.json
  8. 8
      app/_locales/en/messages.json
  9. 2
      app/_locales/es/messages.json
  10. 2
      app/_locales/es_419/messages.json
  11. 2
      app/_locales/et/messages.json
  12. 2
      app/_locales/fa/messages.json
  13. 2
      app/_locales/fi/messages.json
  14. 2
      app/_locales/fil/messages.json
  15. 2
      app/_locales/fr/messages.json
  16. 2
      app/_locales/he/messages.json
  17. 2
      app/_locales/hi/messages.json
  18. 2
      app/_locales/hr/messages.json
  19. 2
      app/_locales/hu/messages.json
  20. 2
      app/_locales/id/messages.json
  21. 2
      app/_locales/it/messages.json
  22. 2
      app/_locales/kn/messages.json
  23. 2
      app/_locales/ko/messages.json
  24. 2
      app/_locales/lt/messages.json
  25. 2
      app/_locales/lv/messages.json
  26. 2
      app/_locales/ms/messages.json
  27. 2
      app/_locales/no/messages.json
  28. 2
      app/_locales/pl/messages.json
  29. 2
      app/_locales/pt_BR/messages.json
  30. 2
      app/_locales/ro/messages.json
  31. 2
      app/_locales/ru/messages.json
  32. 2
      app/_locales/sk/messages.json
  33. 2
      app/_locales/sl/messages.json
  34. 2
      app/_locales/sr/messages.json
  35. 2
      app/_locales/sv/messages.json
  36. 2
      app/_locales/sw/messages.json
  37. 2
      app/_locales/uk/messages.json
  38. 2
      app/_locales/zh_CN/messages.json
  39. 2
      app/_locales/zh_TW/messages.json
  40. 93
      ui/app/pages/settings/networks-tab/network-form/network-form.component.js

@ -731,7 +731,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "ኤክስፕሎረር URL አግድ (አማራጭ)" "message": "ኤክስፕሎረር URL አግድ (አማራጭ)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "ምልክት (አማራጭ)" "message": "ምልክት (አማራጭ)"
}, },
"orderOneHere": { "orderOneHere": {

@ -727,7 +727,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "العنوان الإلكتروني لمستكشف البلوكات (اختياري)" "message": "العنوان الإلكتروني لمستكشف البلوكات (اختياري)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "الرمز (اختياري)" "message": "الرمز (اختياري)"
}, },
"orderOneHere": { "orderOneHere": {

@ -730,7 +730,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Блокиране на Explorer URL (по избор)" "message": "Блокиране на Explorer URL (по избор)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Символ (по избор)" "message": "Символ (по избор)"
}, },
"orderOneHere": { "orderOneHere": {

@ -734,7 +734,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "একসপর URL বলক করন (ঐচিক)" "message": "একসপর URL বলক করন (ঐচিক)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "পরতক (ঐচিক)" "message": "পরতক (ঐচিক)"
}, },
"orderOneHere": { "orderOneHere": {

@ -718,7 +718,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Bloqueja l'URL d'Explorer (opcional)" "message": "Bloqueja l'URL d'Explorer (opcional)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Símbol (opcional)" "message": "Símbol (opcional)"
}, },
"orderOneHere": { "orderOneHere": {

@ -718,7 +718,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Blok-stifinder-URL (valgfrit)" "message": "Blok-stifinder-URL (valgfrit)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Symbol (valgfrit)" "message": "Symbol (valgfrit)"
}, },
"orderOneHere": { "orderOneHere": {

@ -731,7 +731,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Διεύθυνση URL Εξερευνητή Μπλοκ (προαιρετικό)" "message": "Διεύθυνση URL Εξερευνητή Μπλοκ (προαιρετικό)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Σύμβολο (προαιρετικό)" "message": "Σύμβολο (προαιρετικό)"
}, },
"orderOneHere": { "orderOneHere": {

@ -869,7 +869,7 @@
"message": "Invalid IPFS Gateway: The value must be a valid URL" "message": "Invalid IPFS Gateway: The value must be a valid URL"
}, },
"invalidNumber": { "invalidNumber": {
"message": "Invalid number. Enter a decimal or hexadecimal number." "message": "Invalid number. Enter a decimal or '0x'-prefixed hexadecimal number."
}, },
"invalidNumberLeadingZeros": { "invalidNumberLeadingZeros": {
"message": "Invalid number. Remove any leading zeros." "message": "Invalid number. Remove any leading zeros."
@ -1031,7 +1031,7 @@
"message": "Network Name" "message": "Network Name"
}, },
"networkSettingsChainIdDescription": { "networkSettingsChainIdDescription": {
"message": "The chain ID is used for signing transactions. It must match the chain ID returned by the network. Enter a decimal or hexadecimal number starting with '0x'." "message": "The chain ID is used for signing transactions. It must match the chain ID returned by the network. You can enter a decimal or '0x'-prefixed hexadecimal number, but we will display the number in decimal."
}, },
"networkSettingsDescription": { "networkSettingsDescription": {
"message": "Add and edit custom RPC networks" "message": "Add and edit custom RPC networks"
@ -1150,8 +1150,8 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Block Explorer URL (optional)" "message": "Block Explorer URL (optional)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Symbol (optional)" "message": "Currency Symbol (optional)"
}, },
"orderOneHere": { "orderOneHere": {
"message": "Order a Trezor or Ledger and keep your funds in cold storage" "message": "Order a Trezor or Ledger and keep your funds in cold storage"

@ -574,7 +574,7 @@
"ofTextNofM": { "ofTextNofM": {
"message": "de" "message": "de"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Símbolo (opcional)" "message": "Símbolo (opcional)"
}, },
"orderOneHere": { "orderOneHere": {

@ -719,7 +719,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Bloquear la URL de Explorer (opcional)" "message": "Bloquear la URL de Explorer (opcional)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Símbolo (opcional)" "message": "Símbolo (opcional)"
}, },
"orderOneHere": { "orderOneHere": {

@ -724,7 +724,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Blokeeri Exploreri URL (valikuline)" "message": "Blokeeri Exploreri URL (valikuline)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Sümbol (valikuline)" "message": "Sümbol (valikuline)"
}, },
"orderOneHere": { "orderOneHere": {

@ -734,7 +734,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "بلاک کردن مرورگر URL (انتخابی)" "message": "بلاک کردن مرورگر URL (انتخابی)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "سمبول (انتخابی)" "message": "سمبول (انتخابی)"
}, },
"orderOneHere": { "orderOneHere": {

@ -731,7 +731,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Estä Explorerin URL-osoite (valinnainen)" "message": "Estä Explorerin URL-osoite (valinnainen)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Symboli (valinnainen)" "message": "Symboli (valinnainen)"
}, },
"orderOneHere": { "orderOneHere": {

@ -665,7 +665,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Block Explorer URL (opsyonal)" "message": "Block Explorer URL (opsyonal)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Simbolo (opsyonal)" "message": "Simbolo (opsyonal)"
}, },
"orderOneHere": { "orderOneHere": {

@ -716,7 +716,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Bloquer l'URL de l'explorateur (facultatif)" "message": "Bloquer l'URL de l'explorateur (facultatif)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Symbole (facultatif)" "message": "Symbole (facultatif)"
}, },
"orderOneHere": { "orderOneHere": {

@ -731,7 +731,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "חסום כתובת URL של אקספלורר (אופציונלי)" "message": "חסום כתובת URL של אקספלורר (אופציונלי)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "סמל (אופציונלי)" "message": "סמל (אופציונלי)"
}, },
"orderOneHere": { "orderOneHere": {

@ -731,7 +731,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "एकसपरर यआरएल बक (वकलिक)" "message": "एकसपरर यआरएल बक (वकलिक)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "सिबल (वकलिक)" "message": "सिबल (वकलिक)"
}, },
"orderOneHere": { "orderOneHere": {

@ -727,7 +727,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Blokiraj Explorerov URL (neobavezno)" "message": "Blokiraj Explorerov URL (neobavezno)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Simbol (neobavezno)" "message": "Simbol (neobavezno)"
}, },
"orderOneHere": { "orderOneHere": {

@ -727,7 +727,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Explorer URL letiltása (nem kötelező)" "message": "Explorer URL letiltása (nem kötelező)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Szimbólum (opcionális)" "message": "Szimbólum (opcionális)"
}, },
"orderOneHere": { "orderOneHere": {

@ -718,7 +718,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Blokir URL Penjelajah (opsional)" "message": "Blokir URL Penjelajah (opsional)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Simbol (opsional)" "message": "Simbol (opsional)"
}, },
"orderOneHere": { "orderOneHere": {

@ -1050,7 +1050,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "URL del Block Explorer (opzionale)" "message": "URL del Block Explorer (opzionale)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Simbolo (opzionale)" "message": "Simbolo (opzionale)"
}, },
"orderOneHere": { "orderOneHere": {

@ -734,7 +734,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "ಅನಷಕ URL ಅನಿಿಿ (ಐಚಿಕ)" "message": "ಅನಷಕ URL ಅನಿಿಿ (ಐಚಿಕ)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "ಚಿ (ಐಚಿಕ)" "message": "ಚಿ (ಐಚಿಕ)"
}, },
"orderOneHere": { "orderOneHere": {

@ -728,7 +728,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "익스플로러 URL 차단 (선택 사항)" "message": "익스플로러 URL 차단 (선택 사항)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Symbol (선택)" "message": "Symbol (선택)"
}, },
"orderOneHere": { "orderOneHere": {

@ -734,7 +734,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Blokuoti naršyklės URL (pasirinktinai)" "message": "Blokuoti naršyklės URL (pasirinktinai)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Simbolis (nebūtinas)" "message": "Simbolis (nebūtinas)"
}, },
"orderOneHere": { "orderOneHere": {

@ -730,7 +730,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Bloķēt Explorer URL (pēc izvēles)" "message": "Bloķēt Explorer URL (pēc izvēles)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Simbols (neobligāti)" "message": "Simbols (neobligāti)"
}, },
"orderOneHere": { "orderOneHere": {

@ -711,7 +711,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Sekat URL Explorer (pilihan)" "message": "Sekat URL Explorer (pilihan)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Simbol (pilihan)" "message": "Simbol (pilihan)"
}, },
"orderOneHere": { "orderOneHere": {

@ -721,7 +721,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Blokker Explorer URL (valgfritt)" "message": "Blokker Explorer URL (valgfritt)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Symbol (valgfritt)" "message": "Symbol (valgfritt)"
}, },
"orderOneHere": { "orderOneHere": {

@ -728,7 +728,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Adres URL przeglądarki łańcucha bloków (opcjonalnie)" "message": "Adres URL przeglądarki łańcucha bloków (opcjonalnie)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Symbol (opcjonalnie)" "message": "Symbol (opcjonalnie)"
}, },
"orderOneHere": { "orderOneHere": {

@ -722,7 +722,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "URL exploradora de blocos (opcional)" "message": "URL exploradora de blocos (opcional)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Símbolo (opcional)" "message": "Símbolo (opcional)"
}, },
"orderOneHere": { "orderOneHere": {

@ -721,7 +721,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "URL explorator bloc (opțional)" "message": "URL explorator bloc (opțional)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Simbol (opțional)" "message": "Simbol (opțional)"
}, },
"orderOneHere": { "orderOneHere": {

@ -763,7 +763,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "URL блок-эксплорера (необязательно)" "message": "URL блок-эксплорера (необязательно)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Символ (необязательно)" "message": "Символ (необязательно)"
}, },
"orderOneHere": { "orderOneHere": {

@ -703,7 +703,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Blokovať URL Explorera (voliteľné)" "message": "Blokovať URL Explorera (voliteľné)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Symbol (voliteľné)" "message": "Symbol (voliteľné)"
}, },
"orderOneHere": { "orderOneHere": {

@ -719,7 +719,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Blokiraj URL Explorerja (poljubno)" "message": "Blokiraj URL Explorerja (poljubno)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Simbol (nezahtevano)" "message": "Simbol (nezahtevano)"
}, },
"orderOneHere": { "orderOneHere": {

@ -725,7 +725,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Blokirajte URL Explorer-a (opciono)" "message": "Blokirajte URL Explorer-a (opciono)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Simbol (opciono)" "message": "Simbol (opciono)"
}, },
"orderOneHere": { "orderOneHere": {

@ -718,7 +718,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Block Explorer URL (valfritt)" "message": "Block Explorer URL (valfritt)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Symbol (frivillig)" "message": "Symbol (frivillig)"
}, },
"orderOneHere": { "orderOneHere": {

@ -712,7 +712,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "URL ya Block Explorer URL (hiari)" "message": "URL ya Block Explorer URL (hiari)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Ishara (hiari)" "message": "Ishara (hiari)"
}, },
"orderOneHere": { "orderOneHere": {

@ -734,7 +734,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "Блокувати Explorer URL (не обов'язково)" "message": "Блокувати Explorer URL (не обов'язково)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Символ (не обов'язково)" "message": "Символ (не обов'язково)"
}, },
"orderOneHere": { "orderOneHere": {

@ -716,7 +716,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "屏蔽管理器 URL(选填)" "message": "屏蔽管理器 URL(选填)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "符号(选填)" "message": "符号(选填)"
}, },
"orderOneHere": { "orderOneHere": {

@ -725,7 +725,7 @@
"optionalBlockExplorerUrl": { "optionalBlockExplorerUrl": {
"message": "區塊鏈瀏覽器 URL(非必要)" "message": "區塊鏈瀏覽器 URL(非必要)"
}, },
"optionalSymbol": { "optionalCurrencySymbol": {
"message": "Symbol (可選)" "message": "Symbol (可選)"
}, },
"orderOneHere": { "orderOneHere": {

@ -35,7 +35,7 @@ export default class NetworkForm extends PureComponent {
state = { state = {
rpcUrl: this.props.rpcUrl, rpcUrl: this.props.rpcUrl,
chainId: this.props.chainId, chainId: this.getDisplayChainIdFromProps(),
ticker: this.props.ticker, ticker: this.props.ticker,
networkName: this.props.networkName, networkName: this.props.networkName,
blockExplorerUrl: this.props.blockExplorerUrl, blockExplorerUrl: this.props.blockExplorerUrl,
@ -49,7 +49,6 @@ export default class NetworkForm extends PureComponent {
} = prevProps } = prevProps
const { const {
rpcUrl, rpcUrl,
chainId,
ticker, ticker,
networkName, networkName,
networksTabIsInAddMode, networksTabIsInAddMode,
@ -68,7 +67,7 @@ export default class NetworkForm extends PureComponent {
} else if (prevRpcUrl !== rpcUrl) { } else if (prevRpcUrl !== rpcUrl) {
this.setState({ this.setState({
rpcUrl, rpcUrl,
chainId, chainId: this.getDisplayChainIdFromProps(),
ticker, ticker,
networkName, networkName,
blockExplorerUrl, blockExplorerUrl,
@ -94,17 +93,11 @@ export default class NetworkForm extends PureComponent {
} }
resetForm() { resetForm() {
const { const { rpcUrl, ticker, networkName, blockExplorerUrl } = this.props
rpcUrl,
chainId,
ticker,
networkName,
blockExplorerUrl,
} = this.props
this.setState({ this.setState({
rpcUrl, rpcUrl,
chainId, chainId: this.getDisplayChainIdFromProps(),
ticker, ticker,
networkName, networkName,
blockExplorerUrl, blockExplorerUrl,
@ -112,6 +105,28 @@ export default class NetworkForm extends PureComponent {
}) })
} }
/**
* Ensures that the chainId is always displayed in decimal, even though
* it's stored in hexadecimal.
*
* Should be called to get the chainId whenever props are used to set the
* component's state.
*
* @returns {string} The props chainId in decimal.
*/
getDisplayChainIdFromProps() {
const { chainId: propsChainId } = this.props
if (
!propsChainId ||
typeof propsChainId !== 'string' ||
!propsChainId.startsWith('0x')
) {
return propsChainId
}
return new BigNumber(propsChainId, 16).toString(10)
}
onSubmit = async () => { onSubmit = async () => {
const { const {
setRpcTarget, setRpcTarget,
@ -129,13 +144,14 @@ export default class NetworkForm extends PureComponent {
blockExplorerUrl, blockExplorerUrl,
} = this.state } = this.state
const formChainId = stateChainId.trim().toLowerCase()
// Ensure chainId is a 0x-prefixed, lowercase hex string // Ensure chainId is a 0x-prefixed, lowercase hex string
let chainId = stateChainId.trim().toLowerCase() let chainId = formChainId
if (!chainId.startsWith('0x')) { if (!chainId.startsWith('0x')) {
chainId = `0x${new BigNumber(chainId, 10).toString(16)}` chainId = `0x${new BigNumber(chainId, 10).toString(16)}`
} }
if (!(await this.validateChainIdOnSubmit(chainId, rpcUrl))) { if (!(await this.validateChainIdOnSubmit(formChainId, chainId, rpcUrl))) {
return return
} }
@ -153,6 +169,10 @@ export default class NetworkForm extends PureComponent {
if (networksTabIsInAddMode) { if (networksTabIsInAddMode) {
onClear() onClear()
} else {
this.setState({
chainId: this.getDisplayChainIdFromProps(),
})
} }
} }
@ -178,13 +198,7 @@ export default class NetworkForm extends PureComponent {
} }
stateIsUnchanged() { stateIsUnchanged() {
const { const { rpcUrl, ticker, networkName, blockExplorerUrl } = this.props
rpcUrl,
chainId,
ticker,
networkName,
blockExplorerUrl,
} = this.props
const { const {
rpcUrl: stateRpcUrl, rpcUrl: stateRpcUrl,
@ -196,7 +210,7 @@ export default class NetworkForm extends PureComponent {
return ( return (
stateRpcUrl === rpcUrl && stateRpcUrl === rpcUrl &&
stateChainId === chainId && stateChainId === this.getDisplayChainIdFromProps() &&
stateTicker === ticker && stateTicker === ticker &&
stateNetworkName === networkName && stateNetworkName === networkName &&
stateBlockExplorerUrl === blockExplorerUrl stateBlockExplorerUrl === blockExplorerUrl
@ -260,7 +274,7 @@ export default class NetworkForm extends PureComponent {
}) })
} }
validateChainId = (chainIdArg = '') => { validateChainIdOnChange = (chainIdArg = '') => {
const chainId = chainIdArg.trim() const chainId = chainIdArg.trim()
let errorMessage = '' let errorMessage = ''
@ -279,7 +293,17 @@ export default class NetworkForm extends PureComponent {
this.setErrorTo('chainId', errorMessage) this.setErrorTo('chainId', errorMessage)
} }
validateChainIdOnSubmit = async (chainId, rpcUrl) => { /**
* Validates the chain ID by checking it against the `eth_chainId` return
* value from the given RPC URL.
* Assumes that all strings are non-empty and correctly formatted.
*
* @param {string} formChainId - Non-empty, hex or decimal number string from
* the form.
* @param {string} parsedChainId - The parsed, hex string chain ID.
* @param {string} rpcUrl - The RPC URL from the form.
*/
validateChainIdOnSubmit = async (formChainId, parsedChainId, rpcUrl) => {
const { t } = this.context const { t } = this.context
let errorMessage let errorMessage
let endpointChainId let endpointChainId
@ -294,7 +318,22 @@ export default class NetworkForm extends PureComponent {
if (providerError || typeof endpointChainId !== 'string') { if (providerError || typeof endpointChainId !== 'string') {
errorMessage = t('failedToFetchChainId') errorMessage = t('failedToFetchChainId')
} else if (chainId !== endpointChainId) { } else if (parsedChainId !== endpointChainId) {
// Here, we are in an error state. The endpoint should always return a
// hexadecimal string. If the user entered a decimal string, we attempt
// to convert the endpoint's return value to decimal before rendering it
// in an error message in the form.
if (!formChainId.startsWith('0x')) {
try {
endpointChainId = new BigNumber(endpointChainId, 16).toString(10)
} catch (err) {
log.warn(
'Failed to convert endpoint chain ID to decimal',
endpointChainId,
)
}
}
errorMessage = t('endpointReturnedDifferentChainId', [ errorMessage = t('endpointReturnedDifferentChainId', [
endpointChainId.length <= 12 endpointChainId.length <= 12
? endpointChainId ? endpointChainId
@ -394,17 +433,17 @@ export default class NetworkForm extends PureComponent {
{this.renderFormTextField( {this.renderFormTextField(
'chainId', 'chainId',
'chainId', 'chainId',
this.setStateWithValue('chainId', this.validateChainId), this.setStateWithValue('chainId', this.validateChainIdOnChange),
chainId, chainId,
null, null,
t('networkSettingsChainIdDescription'), viewOnly ? null : t('networkSettingsChainIdDescription'),
)} )}
{this.renderFormTextField( {this.renderFormTextField(
'symbol', 'symbol',
'network-ticker', 'network-ticker',
this.setStateWithValue('ticker'), this.setStateWithValue('ticker'),
ticker, ticker,
'optionalSymbol', 'optionalCurrencySymbol',
)} )}
{this.renderFormTextField( {this.renderFormTextField(
'blockExplorerUrl', 'blockExplorerUrl',

Loading…
Cancel
Save