Skip to content

Commit

Permalink
save FrequentRpcList correctly. increse the size of the RpcList
Browse files Browse the repository at this point in the history
  • Loading branch information
hackmod committed Jul 20, 2018
1 parent 307ba9d commit a19718d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
3 changes: 3 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,9 @@
"negativeETH": {
"message": "Can not send negative amounts of ETH."
},
"networkName": {
"message": "$1 Network"
},
"networks": {
"message": "Networks"
},
Expand Down
14 changes: 7 additions & 7 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ class PreferencesController {
* @returns {Promise<void>} Promise resolves with undefined
*
*/
updateFrequentRpcList (_url) {
return this.addToFrequentRpcList(_url)
updateFrequentRpcList (url, chainid, explorer, symbol) {
return this.addToFrequentRpcList(url, chainid, explorer, symbol)
.then((rpcList) => {
this.store.updateState({ frequentRpcList: rpcList })
return Promise.resolve()
Expand Down Expand Up @@ -318,16 +318,16 @@ class PreferencesController {
* @returns {Promise<array>} The updated frequentRpcList.
*
*/
addToFrequentRpcList (_url) {
addToFrequentRpcList (url, chainid, explorer, symbol) {
const rpcList = this.getFrequentRpcList()
const index = rpcList.findIndex((element) => { return element === _url })
const index = rpcList.findIndex((element) => { return typeof element === 'object' ? element.url === url : element === url })
if (index !== -1) {
rpcList.splice(index, 1)
}
if (_url !== 'http://localhost:8545') {
rpcList.push(_url)
if (url !== 'http://localhost:8545') {
rpcList.push({ url, chainid, explorer, symbol })
}
if (rpcList.length > 2) {
if (rpcList.length > 3) {
rpcList.shift()
}
return Promise.resolve(rpcList)
Expand Down
18 changes: 14 additions & 4 deletions old-ui/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ App.prototype.renderCustomOption = function (provider) {

// Concatenate long URLs
let label = symbol ? symbol + ' Network' : rpcTarget
if (rpcTarget.length > 31) {
if (rpcTarget && rpcTarget.length > 31) {
label = label.substr(0, 34) + '...'
}

Expand Down Expand Up @@ -702,7 +702,17 @@ App.prototype.renderCommonRpc = function (rpcList, provider) {
const props = this.props
const rpcTarget = provider.rpcTarget

return rpcList.map((rpc) => {
return rpcList.map((entry) => {
var rpc, chainid, explorer, symbol
if (typeof entry === 'object') {
rpc = entry.url
chainid = entry.chainid
explorer = entry.explorer
symbol = entry.symbol
} else {
rpc = entry
chainid = explorer = symbol = null
}
if ((rpc === 'http://localhost:8545') || (rpc === rpcTarget)) {
return null
} else {
Expand All @@ -711,11 +721,11 @@ App.prototype.renderCommonRpc = function (rpcList, provider) {
{
key: `common${rpc}`,
closeMenu: () => this.setState({ isNetworkMenuOpen: false }),
onClick: () => props.dispatch(actions.setRpcTarget(rpc)),
onClick: () => props.dispatch(actions.setRpcTarget(rpc, chainid, explorer, symbol)),
},
[
h('i.fa.fa-question-circle.fa-lg.menu-icon'),
rpc,
symbol ? symbol + ' Network' : rpc,
rpcTarget === rpc ? h('.check', '✓') : null,
]
)
Expand Down
20 changes: 14 additions & 6 deletions ui/app/components/dropdowns/network-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,18 @@ NetworkDropdown.prototype.getNetworkName = function () {
NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) {
const props = this.props
const rpcTarget = provider.rpcTarget
const network = props.network

return rpcList.map((rpc) => {
return rpcList.map((entry) => {
var rpc, chainid, explorer, symbol
if (typeof entry === 'object') {
rpc = entry.url
chainid = entry.chainid
explorer = entry.explorer
symbol = entry.symbol
} else {
rpc = entry
chainid = explorer = symbol = null
}
if ((rpc === 'http://localhost:8545') || (rpc === rpcTarget)) {
return null
} else {
Expand All @@ -310,7 +319,7 @@ NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) {
{
key: `common${rpc}`,
closeMenu: () => this.props.hideNetworkDropdown(),
onClick: () => props.setRpcTarget(rpc, network),
onClick: () => props.setRpcTarget(rpc, chainid, explorer, symbol),
style: {
fontFamily: 'DIN OT',
fontSize: '16px',
Expand All @@ -325,7 +334,7 @@ NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) {
style: {
color: rpcTarget === rpc ? '#ffffff' : '#9b9b9b',
},
}, rpc),
}, symbol ? this.context.t('networkName', [symbol]) : rpc),
]
)
}
Expand All @@ -335,7 +344,6 @@ NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) {
NetworkDropdown.prototype.renderCustomOption = function (provider) {
const { rpcTarget, type, explorerUrl, symbol } = provider
const props = this.props
const network = props.network

if (type !== 'rpc') return null

Expand All @@ -349,7 +357,7 @@ NetworkDropdown.prototype.renderCustomOption = function (provider) {
DropdownMenuItem,
{
key: rpcTarget,
onClick: () => props.setRpcTarget(rpcTarget, network, explorerUrl, symbol),
onClick: () => props.setRpcTarget(rpcTarget, type, explorerUrl, symbol),
closeMenu: () => this.props.hideNetworkDropdown(),
style: {
fontFamily: 'DIN OT',
Expand Down

0 comments on commit a19718d

Please sign in to comment.