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

New settings custom rpc form #6490

Merged
merged 42 commits into from
May 9, 2019
Merged

New settings custom rpc form #6490

merged 42 commits into from
May 9, 2019

Conversation

danjm
Copy link
Contributor

@danjm danjm commented Apr 22, 2019

resolves #6209

This PR implements the new designs for the Custom RPC form. This PR incorporates everything that was included in the previous #6483 PR, and included additions of the customizable block explorer. It should also incorporate fixes to all the feedback from @bdresser and @cjeria

demo:
Peek 2019-04-29 04-37

@danjm danjm requested a review from whymarrh as a code owner April 22, 2019 16:50
@danjm danjm changed the base branch from develop to custom-rpc-form-updates April 22, 2019 16:51
@danjm danjm force-pushed the custom-rpc-form-updates branch from d523d9d to 817f4c2 Compare April 22, 2019 16:54
@metamaskbot
Copy link
Collaborator

Builds ready [17f976f]: chrome, firefox, edge, opera

@metamaskbot
Copy link
Collaborator

Builds ready [6ddb24f]: chrome, firefox, edge, opera

@danjm danjm changed the title Add block explorer customization to network form New settings custom rpc form Apr 29, 2019
@danjm danjm changed the base branch from custom-rpc-form-updates to develop April 29, 2019 21:40
} else {
setRpcTarget(rpcUrl, chainId, ticker, networkName, {
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl,
...rpcPrefs,
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't actually setting the blockExplorerUrl in rpcPrefs, which is being passed to setRpcTarget in the background as undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tmashuang So when you submit a custom rpc form with a block explorer url, you don't have anything set in any of the rpc objects in the state.metamask.frequentRpcListDetail array?

Copy link
Contributor

@tmashuang tmashuang May 6, 2019

Choose a reason for hiding this comment

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

No, it's not there either. I was looking at it from the provider params, state.metamask.provider when the network is selected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tmashuang This should be fixed now.

@danjm danjm force-pushed the custom-block-explorers branch 2 times, most recently from 9b67e59 to 0eda003 Compare May 7, 2019 18:19
@metamaskbot
Copy link
Collaborator

Builds ready [0eda003]: chrome, firefox, edge, opera

await this.preferencesController.updateRpc({ rpcUrl, chainId, ticker, nickname })
this.networkController.setRpcTarget(rpcUrl, chainId, ticker, nickname)
async updateAndSetCustomRpc (rpcUrl, chainId, ticker = 'ETH', nickname, rpcPrefs) {
console.log('updateAndSetCustomRpc rpcUrl, chainId, ticker, nickname, rpcPrefs', rpcUrl, chainId, ticker, nickname, rpcPrefs)
Copy link
Contributor

Choose a reason for hiding this comment

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

console.log here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 0707b27

if (!!chainId && !Number.isNaN(parseInt(chainId))) {
checkedChainId = chainId
addToFrequentRpcList (url, chainId, ticker = 'ETH', nickname = '', rpcPrefs = {}) {
console.log('addToFrequentRpcList url, chainId, ticker, nickname, rpcPrefs', url, chainId, ticker, nickname, rpcPrefs)
Copy link
Contributor

Choose a reason for hiding this comment

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

console.log here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 0707b27

return {
setSelectedSettingsRpcUrl: newRpcUrl => dispatch(setSelectedSettingsRpcUrl(newRpcUrl)),
setRpcTarget: (newRpc, chainId, ticker, nickname, rpcPrefs) => {
console.log('setRpcTarget newRpc, chainId, ticker, nickname, rpcPrefs', newRpc, chainId, ticker, nickname, rpcPrefs)
Copy link
Contributor

Choose a reason for hiding this comment

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

console.log here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 0707b27

displayWarning: warning => dispatch(displayWarning(warning)),
setNetworksTabAddMode: isInAddMode => dispatch(setNetworksTabAddMode(isInAddMode)),
editRpc: (oldRpc, newRpc, chainId, ticker, nickname, rpcPrefs) => {
console.log('editRpc oldRpc, newRpc, chainId, ticker, nickname, rpcPrefs', oldRpc, newRpc, chainId, ticker, nickname, rpcPrefs)
Copy link
Contributor

Choose a reason for hiding this comment

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

console.log here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 0707b27

return (dispatch) => {
log.debug(`background.updateAndSetCustomRpc: ${newRpc} ${chainId} ${ticker} ${nickname}`)
background.updateAndSetCustomRpc(newRpc, chainId, ticker, nickname || newRpc, (err, result) => {
console.log('updateAndSetCustomRpc newRpc, chainId, ticker, nickname || newRpc, rpcPrefs', newRpc, chainId, ticker, nickname || newRpc, rpcPrefs)
Copy link
Contributor

Choose a reason for hiding this comment

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

console.log here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix during rebase

@whymarrh
Copy link
Contributor

whymarrh commented May 8, 2019

Updated to resolve a conflict from #6583 (commit will be removed in the squash+merge anyhow)

onClick: () => {
global.platform.openWindow({ url: genAccountLink(address, network, rpcPrefs) })
},
}, this.context.t('blockExplorerView', rpcPrefs.blockExplorerUrl && [rpcPrefs.blockExplorerUrl])),
Copy link
Contributor

@tmashuang tmashuang May 8, 2019

Choose a reason for hiding this comment

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

I am getting View account at $1 on the modal screen when on the default Ethereum networks. Could we do

Suggested change
}, this.context.t('blockExplorerView', rpcPrefs.blockExplorerUrl && [rpcPrefs.blockExplorerUrl])),
}, rpcrpcPrefs.blockExplorerUrl ? this.context.t('blockExplorerView [rpcPrefs.blockExplorerUrl])) : this.context.t('viewOnEtherscan'),

and with [rpcPrefs.blockExplorerUrl] could we parse the url with Regex for just the domain? For my first ugly stab at it,

const expression = /(\w+\.)/gi
const regex = new RegExp(expression)
customBlockExplorer.match(regex)[0].charAt(0).toUpperCase() + customBlockExplorer.match(regex)[0].slice(1).replace(/[^a-zA-Z ]/gi, '')

Edit: probably this [^https?\:\/\/]\w+ might be simpler but doesn't catch some edge cases.

Also, needs the same logic for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ed81fed

"message": "Block Explorer"
},
"blockExplorerView": {
"message": "View account at $1",
Copy link
Contributor

Choose a reason for hiding this comment

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

at vs on?

Suggested change
"message": "View account at $1",
"message": "View account on $1",

Copy link
Contributor

Choose a reason for hiding this comment

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

@danjm addressed a similar comment below and I believe $1 will also be a URL here:

I don't know what the correct grammar is here. $1 will always be a [URL]. "View at http://example.com" sounds a bit more correct... but I don't know why and I might be wrong.

I believe that Dan's correct here and that "at" sounds more natural.

Copy link
Contributor

@whymarrh whymarrh left a comment

Choose a reason for hiding this comment

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

A few small comments and a few quick suggestions

},
"blockExplorerView": {
"message": "View account at $1",
"description": "$1 replaced by url for custom block explorer"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"description": "$1 replaced by url for custom block explorer"
"description": "$1 replaced by URL for custom block explorer"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 5083384

@@ -245,6 +258,9 @@
"cancelN": {
"message": "Cancel all $1 transactions"
},
"chainId": {
"message": "Chain Id"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"message": "Chain Id"
"message": "Chain ID"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 5083384

"message": "Block Explorer"
},
"blockExplorerView": {
"message": "View account at $1",
Copy link
Contributor

Choose a reason for hiding this comment

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

@danjm addressed a similar comment below and I believe $1 will also be a URL here:

I don't know what the correct grammar is here. $1 will always be a [URL]. "View at http://example.com" sounds a bit more correct... but I don't know why and I might be wrong.

I believe that Dan's correct here and that "at" sounds more natural.

@@ -188,3 +190,17 @@ export function getStatusKey (transaction) {

return transaction.status
}

/**
* An external block explorer url at which a transaction can be viewed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* An external block explorer url at which a transaction can be viewed.
* Returns an external block explorer URL at which a transaction can be viewed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 29c5762


export default class NetworksTab extends PureComponent {
static contextTypes = {
t: PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
t: PropTypes.func,
t: PropTypes.func.isRequired,

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should try to add .isRequired to all appropriate prop types going forward. I've suggested them here for the contextTypes only since I know that these are required and suggesting it for the correct props would require more thought—if you want to add them quickly go for it, but this is more a "moving forward" suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 29c5762

export default class NetworksTab extends PureComponent {
static contextTypes = {
t: PropTypes.func,
metricsEvent: PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
metricsEvent: PropTypes.func,
metricsEvent: PropTypes.func.isRequired,

Copy link
Contributor

Choose a reason for hiding this comment

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

See note above (attached to t)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 29c5762

this.setErrorTo(stateKey, '')
} else {
const appendedRpc = `http://${url}`
const validWhenAppended = validUrl.isWebUri(appendedRpc) && !url.match(/^https*:\/\/$/)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const validWhenAppended = validUrl.isWebUri(appendedRpc) && !url.match(/^https*:\/\/$/)
const validWhenAppended = validUrl.isWebUri(appendedRpc) && !url.match(/^https?:\/\/$/)

This regex will allow zero or more 's' characters following 'http' (i.e., *) when it should be zero or 1 (i.e., ?).[1]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 29c5762


export default class NetworksTab extends PureComponent {
static contextTypes = {
t: PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
t: PropTypes.func,
t: PropTypes.func.isRequired,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 29c5762

export default class NetworksTab extends PureComponent {
static contextTypes = {
t: PropTypes.func,
metricsEvent: PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
metricsEvent: PropTypes.func,
metricsEvent: PropTypes.func.isRequired,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 29c5762

@whymarrh
Copy link
Contributor

whymarrh commented May 9, 2019

Also with #6583 merged, a few functions might need to be updated

@danjm danjm force-pushed the custom-block-explorers branch from 5a29eee to 039acca Compare May 9, 2019 15:10
@metamaskbot
Copy link
Collaborator

Builds ready [039acca]: chrome, firefox, edge, opera

@danjm danjm force-pushed the custom-block-explorers branch from 039acca to 29c5762 Compare May 9, 2019 15:42
@metamaskbot
Copy link
Collaborator

Builds ready [29c5762]: chrome, firefox, edge, opera

@whymarrh
Copy link
Contributor

whymarrh commented May 9, 2019

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improvements to Custom RPC form
5 participants