Add `MESSAGE_TYPE` enum (#8743)

Each "message" requiring a user confirmation has a unique `type`
property. These `type` properties have all been added as enums, and the
enum is now used wherever the literal string was used previously.
feature/default_network_editable
Mark Stacey 4 years ago committed by GitHub
parent c8a995dd9b
commit e85b162651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/scripts/lib/decrypt-message-manager.js
  2. 3
      app/scripts/lib/encryption-public-key-manager.js
  3. 9
      app/scripts/lib/enums.js
  4. 3
      app/scripts/lib/message-manager.js
  5. 3
      app/scripts/lib/personal-message-manager.js
  6. 4
      app/scripts/lib/typed-message-manager.js
  7. 12
      ui/app/components/app/signature-request-original/signature-request-original.component.js
  8. 7
      ui/app/components/app/signature-request-original/signature-request-original.container.js
  9. 7
      ui/app/components/app/signature-request/signature-request.container.js
  10. 5
      ui/app/helpers/utils/transactions.util.js
  11. 5
      ui/app/pages/confirm-transaction-switch/confirm-transaction-switch.component.js
  12. 3
      ui/app/pages/confirm-transaction/conf-tx.js

@ -3,6 +3,7 @@ import ObservableStore from 'obs-store'
import ethUtil from 'ethereumjs-util'
import { ethErrors } from 'eth-json-rpc-errors'
import createId from './random-id'
import { MESSAGE_TYPE } from './enums'
const hexRe = /^[0-9A-Fa-f]+$/g
import log from 'loglevel'
@ -124,7 +125,7 @@ export default class DecryptMessageManager extends EventEmitter {
msgParams: msgParams,
time: time,
status: 'unapproved',
type: 'eth_decrypt',
type: MESSAGE_TYPE.ETH_DECRYPT,
}
this.addMsg(msgData)

@ -3,6 +3,7 @@ import ObservableStore from 'obs-store'
import { ethErrors } from 'eth-json-rpc-errors'
import createId from './random-id'
import log from 'loglevel'
import { MESSAGE_TYPE } from './enums'
/**
* Represents, and contains data about, an 'eth_getEncryptionPublicKey' type request. These are created when
@ -114,7 +115,7 @@ export default class EncryptionPublicKeyManager extends EventEmitter {
msgParams: address,
time: time,
status: 'unapproved',
type: 'eth_getEncryptionPublicKey',
type: MESSAGE_TYPE.ETH_GET_ENCRYPTION_PUBLIC_KEY,
}
if (req) {

@ -9,11 +9,20 @@ const PLATFORM_EDGE = 'Edge'
const PLATFORM_FIREFOX = 'Firefox'
const PLATFORM_OPERA = 'Opera'
const MESSAGE_TYPE = {
ETH_DECRYPT: 'eth_decrypt',
ETH_GET_ENCRYPTION_PUBLIC_KEY: 'eth_getEncryptionPublicKey',
ETH_SIGN: 'eth_sign',
ETH_SIGN_TYPED_DATA: 'eth_signTypedData',
PERSONAL_SIGN: 'personal_sign',
}
export {
ENVIRONMENT_TYPE_POPUP,
ENVIRONMENT_TYPE_NOTIFICATION,
ENVIRONMENT_TYPE_FULLSCREEN,
ENVIRONMENT_TYPE_BACKGROUND,
MESSAGE_TYPE,
PLATFORM_BRAVE,
PLATFORM_CHROME,
PLATFORM_EDGE,

@ -3,6 +3,7 @@ import ObservableStore from 'obs-store'
import ethUtil from 'ethereumjs-util'
import { ethErrors } from 'eth-json-rpc-errors'
import createId from './random-id'
import { MESSAGE_TYPE } from './enums'
/**
* Represents, and contains data about, an 'eth_sign' type signature request. These are created when a signature for
@ -116,7 +117,7 @@ export default class MessageManager extends EventEmitter {
msgParams: msgParams,
time: time,
status: 'unapproved',
type: 'eth_sign',
type: MESSAGE_TYPE.ETH_SIGN,
}
this.addMsg(msgData)

@ -3,6 +3,7 @@ import ObservableStore from 'obs-store'
import ethUtil from 'ethereumjs-util'
import { ethErrors } from 'eth-json-rpc-errors'
import createId from './random-id'
import { MESSAGE_TYPE } from './enums'
const hexRe = /^[0-9A-Fa-f]+$/g
import log from 'loglevel'
@ -125,7 +126,7 @@ export default class PersonalMessageManager extends EventEmitter {
msgParams: msgParams,
time: time,
status: 'unapproved',
type: 'personal_sign',
type: MESSAGE_TYPE.PERSONAL_SIGN,
}
this.addMsg(msgData)

@ -6,7 +6,7 @@ import { ethErrors } from 'eth-json-rpc-errors'
import sigUtil from 'eth-sig-util'
import log from 'loglevel'
import jsonschema from 'jsonschema'
import { MESSAGE_TYPE } from './enums'
/**
* Represents, and contains data about, an 'eth_signTypedData' type signature request. These are created when a
* signature for an eth_signTypedData call is requested.
@ -118,7 +118,7 @@ export default class TypedMessageManager extends EventEmitter {
msgParams: msgParams,
time: time,
status: 'unapproved',
type: 'eth_signTypedData',
type: MESSAGE_TYPE.ETH_SIGN_TYPED_DATA,
}
this.addMsg(msgData)

@ -4,7 +4,7 @@ import ethUtil from 'ethereumjs-util'
import classnames from 'classnames'
import { ObjectInspector } from 'react-inspector'
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../../app/scripts/lib/enums'
import { ENVIRONMENT_TYPE_NOTIFICATION, MESSAGE_TYPE } from '../../../../../app/scripts/lib/enums'
import { getEnvironmentType } from '../../../../../app/scripts/lib/util'
import Identicon from '../../ui/identicon'
import AccountListItem from '../../../pages/send/account-list-item/account-list-item.component'
@ -208,11 +208,11 @@ export default class SignatureRequestOriginal extends Component {
const { txData } = this.props
const { type, msgParams: { data } } = txData
if (type === 'personal_sign') {
if (type === MESSAGE_TYPE.PERSONAL_SIGN) {
rows = [{ name: this.context.t('message'), value: this.msgHexToText(data) }]
} else if (type === 'eth_signTypedData') {
} else if (type === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA) {
rows = data
} else if (type === 'eth_sign') {
} else if (type === MESSAGE_TYPE.ETH_SIGN) {
rows = [{ name: this.context.t('message'), value: data }]
notice = this.context.t('signNotice')
}
@ -223,12 +223,12 @@ export default class SignatureRequestOriginal extends Component {
{ this.renderRequestInfo() }
<div
className={classnames('request-signature__notice', {
'request-signature__warning': type === 'eth_sign',
'request-signature__warning': type === MESSAGE_TYPE.ETH_SIGN,
})}
>
{ notice }
{
type === 'eth_sign'
type === MESSAGE_TYPE.ETH_SIGN
? (
<span
className="request-signature__help-link"

@ -2,6 +2,7 @@ import { connect } from 'react-redux'
import { compose } from 'redux'
import { withRouter } from 'react-router-dom'
import { MESSAGE_TYPE } from '../../../../../app/scripts/lib/enums'
import { goHome } from '../../../store/actions'
import {
accountsWithSendEtherInfoSelector,
@ -50,13 +51,13 @@ function mergeProps (stateProps, dispatchProps, ownProps) {
let cancel
let sign
if (type === 'personal_sign') {
if (type === MESSAGE_TYPE.PERSONAL_SIGN) {
cancel = cancelPersonalMessage
sign = signPersonalMessage
} else if (type === 'eth_signTypedData') {
} else if (type === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA) {
cancel = cancelTypedMessage
sign = signTypedMessage
} else if (type === 'eth_sign') {
} else if (type === MESSAGE_TYPE.ETH_SIGN) {
cancel = cancelMessage
sign = signMessage
}

@ -5,6 +5,7 @@ import {
accountsWithSendEtherInfoSelector,
} from '../../../selectors'
import { getAccountByAddress } from '../../../helpers/utils/util'
import { MESSAGE_TYPE } from '../../../../../app/scripts/lib/enums'
function mapStateToProps (state) {
return {
@ -38,13 +39,13 @@ function mergeProps (stateProps, dispatchProps, ownProps) {
let cancel
let sign
if (type === 'personal_sign') {
if (type === MESSAGE_TYPE.PERSONAL_SIGN) {
cancel = cancelPersonalMessage
sign = signPersonalMessage
} else if (type === 'eth_signTypedData') {
} else if (type === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA) {
cancel = cancelTypedMessage
sign = signTypedMessage
} else if (type === 'eth_sign') {
} else if (type === MESSAGE_TYPE.ETH_SIGN) {
cancel = cancelMessage
sign = signMessage
}

@ -6,6 +6,7 @@ import {
TRANSACTION_TYPE_CANCEL,
TRANSACTION_STATUS_CONFIRMED,
} from '../../../../app/scripts/controllers/transactions/enums'
import { MESSAGE_TYPE } from '../../../../app/scripts/lib/enums'
import prefixForNetwork from '../../../lib/etherscan-prefix-for-network'
import fetchWithCache from './fetch-with-cache'
@ -137,9 +138,9 @@ export function getTransactionActionKey (transaction) {
}
if (msgParams) {
if (type === 'eth_decrypt') {
if (type === MESSAGE_TYPE.ETH_DECRYPT) {
return DECRYPT_REQUEST_KEY
} else if (type === 'eth_getEncryptionPublicKey') {
} else if (type === MESSAGE_TYPE.ETH_GET_ENCRYPTION_PUBLIC_KEY) {
return ENCRYPTION_PUBLIC_KEY_REQUEST_KEY
} else {
return SIGNATURE_REQUEST_KEY

@ -21,6 +21,7 @@ import {
DEPLOY_CONTRACT_ACTION_KEY,
SEND_ETHER_ACTION_KEY,
} from '../../helpers/constants/transactions'
import { MESSAGE_TYPE } from '../../../../app/scripts/lib/enums'
export default class ConfirmTransactionSwitch extends Component {
static propTypes = {
@ -74,9 +75,9 @@ export default class ConfirmTransactionSwitch extends Component {
return this.redirectToTransaction()
} else if (txData.msgParams) {
let pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${SIGNATURE_REQUEST_PATH}`
if (txData.type === 'eth_decrypt') {
if (txData.type === MESSAGE_TYPE.ETH_DECRYPT) {
pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${DECRYPT_MESSAGE_REQUEST_PATH}`
} else if (txData.type === 'eth_getEncryptionPublicKey') {
} else if (txData.type === MESSAGE_TYPE.ETH_GET_ENCRYPTION_PUBLIC_KEY) {
pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${ENCRYPTION_PUBLIC_KEY_REQUEST_PATH}`
}
return <Redirect to={{ pathname }} />

@ -11,6 +11,7 @@ import SignatureRequest from '../../components/app/signature-request'
import SignatureRequestOriginal from '../../components/app/signature-request-original'
import Loading from '../../components/ui/loading-screen'
import { getMostRecentOverviewPage } from '../../ducks/history/history'
import { MESSAGE_TYPE } from '../../../../app/scripts/lib/enums'
function mapStateToProps (state) {
const { metamask, appState } = state
@ -111,7 +112,7 @@ class ConfirmTxScreen extends Component {
signatureSelect (type, version) {
// Temporarily direct only v3 and v4 requests to new code.
if (type === 'eth_signTypedData' && (version === 'V3' || version === 'V4')) {
if (type === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA && (version === 'V3' || version === 'V4')) {
return SignatureRequest
}

Loading…
Cancel
Save