Skip to content

Commit 95fc740

Browse files
authored
Merge pull request #11271 from brave/pr11245_uplift_1.32.x
(uplift 1.32.x) Check decimal number against hex for chain ID (#11245)
2 parents 5447b39 + db6b006 commit 95fc740

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

app/brave_generated_resources.grd

+2-2
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ Are you sure you want to do this?
15261526
The id of new chain
15271527
</message>
15281528
<message name="IDS_SETTINGS_WALLET_NETWORKS_CHAIN_ID_PLACEHOLDER" desc="The placeholder of the chain id input for the wallet network dialog">
1529-
A 0x-prefixed hexadecimal string
1529+
A positive decimal number
15301530
</message>
15311531
<message name="IDS_SETTINGS_WALLET_NETWORKS_CHAIN_NAME_TITLE" desc="The title of the chain name input for the wallet network dialog">
15321532
The name of new chain
@@ -1568,7 +1568,7 @@ Are you sure you want to do this?
15681568
This field cannot be blank.
15691569
</message>
15701570
<message name="IDS_SETTINGS_WALLET_NETWORKS_CHAID_ID_ERROR" desc="The error text of the wallet network dialog for invalid chain id fields">
1571-
Invalid format, the chain id is a 0x-prefixed hexadecimal string
1571+
Invalid format, the chain id is a positive number
15721572
</message>
15731573
<message name="IDS_SETTINGS_WALLET_NETWORKS_EXISTS" desc="The error text of the wallet network dialog for existing network">
15741574
This network is already added.

browser/resources/settings/brave_wallet_page/add_wallet_network_dialog.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
<div slot="body">
2323
<cr-input id="chainId"
2424
label="$i18n{walletAddNetworkDialogChainIdTitle}"
25-
type="text"
25+
type="number"
26+
min="1"
2627
placeholder="$i18n{walletAddNetworkDialogChainIdPlaceholder}"
2728
spellcheck="false"
2829
error-message="{{invalidChainIdMessage_}}"

browser/resources/settings/brave_wallet_page/add_wallet_network_dialog.js

+9-14
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Polymer({
6262
value: false,
6363
},
6464

65-
chainIdValue_: String,
65+
chainIdValue_: Number,
6666
invalidChainIdMessage_: String,
6767
chainIdInvalid_: {
6868
type: Boolean,
@@ -105,7 +105,7 @@ Polymer({
105105
ready: function() {
106106
if (Object.keys(this.selected).length === 0)
107107
return
108-
this.chainIdValue_ = this.selected.chainId
108+
this.chainIdValue_ = parseInt(this.selected.chainId, 16) | 0
109109
this.chainNameValue_ = this.selected.chainName
110110
this.currencyNameValue_ = this.selected.nativeCurrency.name
111111
this.currencySymbolValue_ = this.selected.nativeCurrency.symbol
@@ -135,20 +135,12 @@ Polymer({
135135

136136
return url.protocol === "http:" || url.protocol === "https:"
137137
},
138-
isValidHexValue: function(value) {
139-
var parsed = parseInt(value, 16);
140-
const processed = value.replace('0x', '').toLowerCase()
141-
return (parsed.toString(16) === processed) && value.startsWith('0x');
142-
},
143138
/** @private */
144139
chainIdChanged_: function(event) {
145140
const value = event.target.value
146-
this.chainIdInvalid_ = !this.isValidHexValue(value)
147-
const empty = value.trim() === ''
141+
this.chainIdInvalid_ = value <= 0
148142
if (this.chainIdInvalid_) {
149-
const text = empty ? this.i18n('walletAddNetworkMandarotyFieldError')
150-
: this.i18n('walletAddNetworkInvalidChainId')
151-
this.invalidChainIdMessage_ = text
143+
this.invalidChainIdMessage_ = this.i18n('walletAddNetworkInvalidChainId')
152144
}
153145
this.updateSubmitButtonState_()
154146
},
@@ -198,7 +190,7 @@ Polymer({
198190
return;
199191
}
200192
}
201-
if (this.chainIdValue_ === '') {
193+
if (this.chainIdValue_ <= 0) {
202194
this.isSubmitButtonEnabled_ = false
203195
return;
204196
}
@@ -287,9 +279,12 @@ Polymer({
287279
}
288280
})
289281
},
282+
getHexNumber: function(value) {
283+
return '0x' + Number(this.chainIdValue_).toString(16)
284+
},
290285
onAddNetworkTap_: function(item) {
291286
let payload = Object({
292-
chainId: this.chainIdValue_,
287+
chainId: this.getHexNumber(),
293288
chainName: this.chainNameValue_,
294289
})
295290
const nativeCurrency = Object({

0 commit comments

Comments
 (0)