mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
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.
This commit is contained in:
parent
c8a995dd9b
commit
e85b162651
@ -3,6 +3,7 @@ import ObservableStore from 'obs-store'
|
|||||||
import ethUtil from 'ethereumjs-util'
|
import ethUtil from 'ethereumjs-util'
|
||||||
import { ethErrors } from 'eth-json-rpc-errors'
|
import { ethErrors } from 'eth-json-rpc-errors'
|
||||||
import createId from './random-id'
|
import createId from './random-id'
|
||||||
|
import { MESSAGE_TYPE } from './enums'
|
||||||
|
|
||||||
const hexRe = /^[0-9A-Fa-f]+$/g
|
const hexRe = /^[0-9A-Fa-f]+$/g
|
||||||
import log from 'loglevel'
|
import log from 'loglevel'
|
||||||
@ -124,7 +125,7 @@ export default class DecryptMessageManager extends EventEmitter {
|
|||||||
msgParams: msgParams,
|
msgParams: msgParams,
|
||||||
time: time,
|
time: time,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
type: 'eth_decrypt',
|
type: MESSAGE_TYPE.ETH_DECRYPT,
|
||||||
}
|
}
|
||||||
this.addMsg(msgData)
|
this.addMsg(msgData)
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import ObservableStore from 'obs-store'
|
|||||||
import { ethErrors } from 'eth-json-rpc-errors'
|
import { ethErrors } from 'eth-json-rpc-errors'
|
||||||
import createId from './random-id'
|
import createId from './random-id'
|
||||||
import log from 'loglevel'
|
import log from 'loglevel'
|
||||||
|
import { MESSAGE_TYPE } from './enums'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents, and contains data about, an 'eth_getEncryptionPublicKey' type request. These are created when
|
* 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,
|
msgParams: address,
|
||||||
time: time,
|
time: time,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
type: 'eth_getEncryptionPublicKey',
|
type: MESSAGE_TYPE.ETH_GET_ENCRYPTION_PUBLIC_KEY,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req) {
|
if (req) {
|
||||||
|
@ -9,11 +9,20 @@ const PLATFORM_EDGE = 'Edge'
|
|||||||
const PLATFORM_FIREFOX = 'Firefox'
|
const PLATFORM_FIREFOX = 'Firefox'
|
||||||
const PLATFORM_OPERA = 'Opera'
|
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 {
|
export {
|
||||||
ENVIRONMENT_TYPE_POPUP,
|
ENVIRONMENT_TYPE_POPUP,
|
||||||
ENVIRONMENT_TYPE_NOTIFICATION,
|
ENVIRONMENT_TYPE_NOTIFICATION,
|
||||||
ENVIRONMENT_TYPE_FULLSCREEN,
|
ENVIRONMENT_TYPE_FULLSCREEN,
|
||||||
ENVIRONMENT_TYPE_BACKGROUND,
|
ENVIRONMENT_TYPE_BACKGROUND,
|
||||||
|
MESSAGE_TYPE,
|
||||||
PLATFORM_BRAVE,
|
PLATFORM_BRAVE,
|
||||||
PLATFORM_CHROME,
|
PLATFORM_CHROME,
|
||||||
PLATFORM_EDGE,
|
PLATFORM_EDGE,
|
||||||
|
@ -3,6 +3,7 @@ import ObservableStore from 'obs-store'
|
|||||||
import ethUtil from 'ethereumjs-util'
|
import ethUtil from 'ethereumjs-util'
|
||||||
import { ethErrors } from 'eth-json-rpc-errors'
|
import { ethErrors } from 'eth-json-rpc-errors'
|
||||||
import createId from './random-id'
|
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
|
* 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,
|
msgParams: msgParams,
|
||||||
time: time,
|
time: time,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
type: 'eth_sign',
|
type: MESSAGE_TYPE.ETH_SIGN,
|
||||||
}
|
}
|
||||||
this.addMsg(msgData)
|
this.addMsg(msgData)
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import ObservableStore from 'obs-store'
|
|||||||
import ethUtil from 'ethereumjs-util'
|
import ethUtil from 'ethereumjs-util'
|
||||||
import { ethErrors } from 'eth-json-rpc-errors'
|
import { ethErrors } from 'eth-json-rpc-errors'
|
||||||
import createId from './random-id'
|
import createId from './random-id'
|
||||||
|
import { MESSAGE_TYPE } from './enums'
|
||||||
|
|
||||||
const hexRe = /^[0-9A-Fa-f]+$/g
|
const hexRe = /^[0-9A-Fa-f]+$/g
|
||||||
import log from 'loglevel'
|
import log from 'loglevel'
|
||||||
@ -125,7 +126,7 @@ export default class PersonalMessageManager extends EventEmitter {
|
|||||||
msgParams: msgParams,
|
msgParams: msgParams,
|
||||||
time: time,
|
time: time,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
type: 'personal_sign',
|
type: MESSAGE_TYPE.PERSONAL_SIGN,
|
||||||
}
|
}
|
||||||
this.addMsg(msgData)
|
this.addMsg(msgData)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import { ethErrors } from 'eth-json-rpc-errors'
|
|||||||
import sigUtil from 'eth-sig-util'
|
import sigUtil from 'eth-sig-util'
|
||||||
import log from 'loglevel'
|
import log from 'loglevel'
|
||||||
import jsonschema from 'jsonschema'
|
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
|
* Represents, and contains data about, an 'eth_signTypedData' type signature request. These are created when a
|
||||||
* signature for an eth_signTypedData call is requested.
|
* signature for an eth_signTypedData call is requested.
|
||||||
@ -118,7 +118,7 @@ export default class TypedMessageManager extends EventEmitter {
|
|||||||
msgParams: msgParams,
|
msgParams: msgParams,
|
||||||
time: time,
|
time: time,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
type: 'eth_signTypedData',
|
type: MESSAGE_TYPE.ETH_SIGN_TYPED_DATA,
|
||||||
}
|
}
|
||||||
this.addMsg(msgData)
|
this.addMsg(msgData)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import ethUtil from 'ethereumjs-util'
|
|||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import { ObjectInspector } from 'react-inspector'
|
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 { getEnvironmentType } from '../../../../../app/scripts/lib/util'
|
||||||
import Identicon from '../../ui/identicon'
|
import Identicon from '../../ui/identicon'
|
||||||
import AccountListItem from '../../../pages/send/account-list-item/account-list-item.component'
|
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 { txData } = this.props
|
||||||
const { type, msgParams: { data } } = txData
|
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) }]
|
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
|
rows = data
|
||||||
} else if (type === 'eth_sign') {
|
} else if (type === MESSAGE_TYPE.ETH_SIGN) {
|
||||||
rows = [{ name: this.context.t('message'), value: data }]
|
rows = [{ name: this.context.t('message'), value: data }]
|
||||||
notice = this.context.t('signNotice')
|
notice = this.context.t('signNotice')
|
||||||
}
|
}
|
||||||
@ -223,12 +223,12 @@ export default class SignatureRequestOriginal extends Component {
|
|||||||
{ this.renderRequestInfo() }
|
{ this.renderRequestInfo() }
|
||||||
<div
|
<div
|
||||||
className={classnames('request-signature__notice', {
|
className={classnames('request-signature__notice', {
|
||||||
'request-signature__warning': type === 'eth_sign',
|
'request-signature__warning': type === MESSAGE_TYPE.ETH_SIGN,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{ notice }
|
{ notice }
|
||||||
{
|
{
|
||||||
type === 'eth_sign'
|
type === MESSAGE_TYPE.ETH_SIGN
|
||||||
? (
|
? (
|
||||||
<span
|
<span
|
||||||
className="request-signature__help-link"
|
className="request-signature__help-link"
|
||||||
|
@ -2,6 +2,7 @@ import { connect } from 'react-redux'
|
|||||||
import { compose } from 'redux'
|
import { compose } from 'redux'
|
||||||
import { withRouter } from 'react-router-dom'
|
import { withRouter } from 'react-router-dom'
|
||||||
|
|
||||||
|
import { MESSAGE_TYPE } from '../../../../../app/scripts/lib/enums'
|
||||||
import { goHome } from '../../../store/actions'
|
import { goHome } from '../../../store/actions'
|
||||||
import {
|
import {
|
||||||
accountsWithSendEtherInfoSelector,
|
accountsWithSendEtherInfoSelector,
|
||||||
@ -50,13 +51,13 @@ function mergeProps (stateProps, dispatchProps, ownProps) {
|
|||||||
|
|
||||||
let cancel
|
let cancel
|
||||||
let sign
|
let sign
|
||||||
if (type === 'personal_sign') {
|
if (type === MESSAGE_TYPE.PERSONAL_SIGN) {
|
||||||
cancel = cancelPersonalMessage
|
cancel = cancelPersonalMessage
|
||||||
sign = signPersonalMessage
|
sign = signPersonalMessage
|
||||||
} else if (type === 'eth_signTypedData') {
|
} else if (type === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA) {
|
||||||
cancel = cancelTypedMessage
|
cancel = cancelTypedMessage
|
||||||
sign = signTypedMessage
|
sign = signTypedMessage
|
||||||
} else if (type === 'eth_sign') {
|
} else if (type === MESSAGE_TYPE.ETH_SIGN) {
|
||||||
cancel = cancelMessage
|
cancel = cancelMessage
|
||||||
sign = signMessage
|
sign = signMessage
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
accountsWithSendEtherInfoSelector,
|
accountsWithSendEtherInfoSelector,
|
||||||
} from '../../../selectors'
|
} from '../../../selectors'
|
||||||
import { getAccountByAddress } from '../../../helpers/utils/util'
|
import { getAccountByAddress } from '../../../helpers/utils/util'
|
||||||
|
import { MESSAGE_TYPE } from '../../../../../app/scripts/lib/enums'
|
||||||
|
|
||||||
function mapStateToProps (state) {
|
function mapStateToProps (state) {
|
||||||
return {
|
return {
|
||||||
@ -38,13 +39,13 @@ function mergeProps (stateProps, dispatchProps, ownProps) {
|
|||||||
let cancel
|
let cancel
|
||||||
let sign
|
let sign
|
||||||
|
|
||||||
if (type === 'personal_sign') {
|
if (type === MESSAGE_TYPE.PERSONAL_SIGN) {
|
||||||
cancel = cancelPersonalMessage
|
cancel = cancelPersonalMessage
|
||||||
sign = signPersonalMessage
|
sign = signPersonalMessage
|
||||||
} else if (type === 'eth_signTypedData') {
|
} else if (type === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA) {
|
||||||
cancel = cancelTypedMessage
|
cancel = cancelTypedMessage
|
||||||
sign = signTypedMessage
|
sign = signTypedMessage
|
||||||
} else if (type === 'eth_sign') {
|
} else if (type === MESSAGE_TYPE.ETH_SIGN) {
|
||||||
cancel = cancelMessage
|
cancel = cancelMessage
|
||||||
sign = signMessage
|
sign = signMessage
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
TRANSACTION_TYPE_CANCEL,
|
TRANSACTION_TYPE_CANCEL,
|
||||||
TRANSACTION_STATUS_CONFIRMED,
|
TRANSACTION_STATUS_CONFIRMED,
|
||||||
} from '../../../../app/scripts/controllers/transactions/enums'
|
} from '../../../../app/scripts/controllers/transactions/enums'
|
||||||
|
import { MESSAGE_TYPE } from '../../../../app/scripts/lib/enums'
|
||||||
import prefixForNetwork from '../../../lib/etherscan-prefix-for-network'
|
import prefixForNetwork from '../../../lib/etherscan-prefix-for-network'
|
||||||
import fetchWithCache from './fetch-with-cache'
|
import fetchWithCache from './fetch-with-cache'
|
||||||
|
|
||||||
@ -137,9 +138,9 @@ export function getTransactionActionKey (transaction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (msgParams) {
|
if (msgParams) {
|
||||||
if (type === 'eth_decrypt') {
|
if (type === MESSAGE_TYPE.ETH_DECRYPT) {
|
||||||
return DECRYPT_REQUEST_KEY
|
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
|
return ENCRYPTION_PUBLIC_KEY_REQUEST_KEY
|
||||||
} else {
|
} else {
|
||||||
return SIGNATURE_REQUEST_KEY
|
return SIGNATURE_REQUEST_KEY
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
DEPLOY_CONTRACT_ACTION_KEY,
|
DEPLOY_CONTRACT_ACTION_KEY,
|
||||||
SEND_ETHER_ACTION_KEY,
|
SEND_ETHER_ACTION_KEY,
|
||||||
} from '../../helpers/constants/transactions'
|
} from '../../helpers/constants/transactions'
|
||||||
|
import { MESSAGE_TYPE } from '../../../../app/scripts/lib/enums'
|
||||||
|
|
||||||
export default class ConfirmTransactionSwitch extends Component {
|
export default class ConfirmTransactionSwitch extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
@ -74,9 +75,9 @@ export default class ConfirmTransactionSwitch extends Component {
|
|||||||
return this.redirectToTransaction()
|
return this.redirectToTransaction()
|
||||||
} else if (txData.msgParams) {
|
} else if (txData.msgParams) {
|
||||||
let pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${SIGNATURE_REQUEST_PATH}`
|
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}`
|
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}`
|
pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${ENCRYPTION_PUBLIC_KEY_REQUEST_PATH}`
|
||||||
}
|
}
|
||||||
return <Redirect to={{ pathname }} />
|
return <Redirect to={{ pathname }} />
|
||||||
|
@ -11,6 +11,7 @@ import SignatureRequest from '../../components/app/signature-request'
|
|||||||
import SignatureRequestOriginal from '../../components/app/signature-request-original'
|
import SignatureRequestOriginal from '../../components/app/signature-request-original'
|
||||||
import Loading from '../../components/ui/loading-screen'
|
import Loading from '../../components/ui/loading-screen'
|
||||||
import { getMostRecentOverviewPage } from '../../ducks/history/history'
|
import { getMostRecentOverviewPage } from '../../ducks/history/history'
|
||||||
|
import { MESSAGE_TYPE } from '../../../../app/scripts/lib/enums'
|
||||||
|
|
||||||
function mapStateToProps (state) {
|
function mapStateToProps (state) {
|
||||||
const { metamask, appState } = state
|
const { metamask, appState } = state
|
||||||
@ -111,7 +112,7 @@ class ConfirmTxScreen extends Component {
|
|||||||
|
|
||||||
signatureSelect (type, version) {
|
signatureSelect (type, version) {
|
||||||
// Temporarily direct only v3 and v4 requests to new code.
|
// 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
|
return SignatureRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user