mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
expand transaction constants coverage (#9790)
* expand transaction constants coverage * touchups * dont import inside of e2e * Update app/scripts/controllers/transactions/tx-state-manager.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update test/unit/app/controllers/transactions/tx-controller-test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> Co-authored-by: Mark Stacey <markjstacey@gmail.com>
This commit is contained in:
parent
f30d261e69
commit
a49a4a066c
@ -5,6 +5,10 @@ import createId from '../lib/random-id'
|
||||
import { bnToHex } from '../lib/util'
|
||||
import fetchWithTimeout from '../lib/fetch-with-timeout'
|
||||
|
||||
import {
|
||||
TRANSACTION_CATEGORIES,
|
||||
TRANSACTION_STATUSES,
|
||||
} from '../../../shared/constants/transaction'
|
||||
import {
|
||||
CHAIN_ID_TO_NETWORK_ID_MAP,
|
||||
CHAIN_ID_TO_TYPE_MAP,
|
||||
@ -275,7 +279,10 @@ export default class IncomingTransactionsController {
|
||||
|
||||
_normalizeTxFromEtherscan(txMeta, chainId) {
|
||||
const time = parseInt(txMeta.timeStamp, 10) * 1000
|
||||
const status = txMeta.isError === '0' ? 'confirmed' : 'failed'
|
||||
const status =
|
||||
txMeta.isError === '0'
|
||||
? TRANSACTION_STATUSES.CONFIRMED
|
||||
: TRANSACTION_STATUSES.FAILED
|
||||
return {
|
||||
blockNumber: txMeta.blockNumber,
|
||||
id: createId(),
|
||||
@ -291,7 +298,7 @@ export default class IncomingTransactionsController {
|
||||
value: bnToHex(new BN(txMeta.value)),
|
||||
},
|
||||
hash: txMeta.hash,
|
||||
transactionCategory: 'incoming',
|
||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -183,9 +183,9 @@ export default class TransactionController extends EventEmitter {
|
||||
`${initialTxMeta.id}:finished`,
|
||||
(finishedTxMeta) => {
|
||||
switch (finishedTxMeta.status) {
|
||||
case 'submitted':
|
||||
case TRANSACTION_STATUSES.SUBMITTED:
|
||||
return resolve(finishedTxMeta.hash)
|
||||
case 'rejected':
|
||||
case TRANSACTION_STATUSES.REJECTED:
|
||||
return reject(
|
||||
cleanErrorStack(
|
||||
ethErrors.provider.userRejectedRequest(
|
||||
@ -193,7 +193,7 @@ export default class TransactionController extends EventEmitter {
|
||||
),
|
||||
),
|
||||
)
|
||||
case 'failed':
|
||||
case TRANSACTION_STATUSES.FAILED:
|
||||
return reject(
|
||||
cleanErrorStack(
|
||||
ethErrors.rpc.internal(finishedTxMeta.err.message),
|
||||
@ -724,7 +724,7 @@ export default class TransactionController extends EventEmitter {
|
||||
_onBootCleanUp() {
|
||||
this.txStateManager
|
||||
.getFilteredTxList({
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
loadingDefaults: true,
|
||||
})
|
||||
.forEach((tx) => {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { isValidAddress } from 'ethereumjs-util'
|
||||
import { addHexPrefix } from '../../../lib/util'
|
||||
import { TRANSACTION_STATUSES } from '../../../../../shared/constants/transaction'
|
||||
|
||||
const normalizers = {
|
||||
from: (from) => addHexPrefix(from),
|
||||
@ -93,9 +94,9 @@ export function validateRecipient(txParams) {
|
||||
*/
|
||||
export function getFinalStates() {
|
||||
return [
|
||||
'rejected', // the user has responded no!
|
||||
'confirmed', // the tx has been included in a block.
|
||||
'failed', // the tx failed for some reason, included on tx data.
|
||||
'dropped', // the tx nonce was already used
|
||||
TRANSACTION_STATUSES.REJECTED, // the user has responded no!
|
||||
TRANSACTION_STATUSES.CONFIRMED, // the tx has been included in a block.
|
||||
TRANSACTION_STATUSES.FAILED, // the tx failed for some reason, included on tx data.
|
||||
TRANSACTION_STATUSES.DROPPED, // the tx nonce was already used
|
||||
]
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import EventEmitter from 'safe-event-emitter'
|
||||
import log from 'loglevel'
|
||||
import EthQuery from 'ethjs-query'
|
||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
||||
|
||||
/**
|
||||
|
||||
@ -168,7 +169,7 @@ export default class PendingTransactionTracker extends EventEmitter {
|
||||
const txId = txMeta.id
|
||||
|
||||
// Only check submitted txs
|
||||
if (txMeta.status !== 'submitted') {
|
||||
if (txMeta.status !== TRANSACTION_STATUSES.SUBMITTED) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ import EventEmitter from 'safe-event-emitter'
|
||||
import ObservableStore from 'obs-store'
|
||||
import log from 'loglevel'
|
||||
import createId from '../../lib/random-id'
|
||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
||||
import {
|
||||
generateHistoryEntry,
|
||||
replayHistory,
|
||||
@ -10,27 +11,21 @@ import {
|
||||
import { getFinalStates, normalizeTxParams } from './lib/util'
|
||||
|
||||
/**
|
||||
TransactionStateManager is responsible for the state of a transaction and
|
||||
storing the transaction
|
||||
it also has some convenience methods for finding subsets of transactions
|
||||
*
|
||||
*STATUS METHODS
|
||||
<br>statuses:
|
||||
<br> - `'unapproved'` the user has not responded
|
||||
<br> - `'rejected'` the user has responded no!
|
||||
<br> - `'approved'` the user has approved the tx
|
||||
<br> - `'signed'` the tx is signed
|
||||
<br> - `'submitted'` the tx is sent to a server
|
||||
<br> - `'confirmed'` the tx has been included in a block.
|
||||
<br> - `'failed'` the tx failed for some reason, included on tx data.
|
||||
<br> - `'dropped'` the tx nonce was already used
|
||||
@param {Object} opts
|
||||
@param {Object} [opts.initState={ transactions: [] }] initial transactions list with the key transaction {array}
|
||||
@param {number} [opts.txHistoryLimit] limit for how many finished
|
||||
transactions can hang around in state
|
||||
@param {function} opts.getNetwork return network number
|
||||
@class
|
||||
*/
|
||||
* TransactionStatuses reimported from the shared transaction constants file
|
||||
* @typedef {import('../../../../shared/constants/transaction').TransactionStatuses} TransactionStatuses
|
||||
*/
|
||||
|
||||
/**
|
||||
* TransactionStateManager is responsible for the state of a transaction and
|
||||
* storing the transaction. It also has some convenience methods for finding
|
||||
* subsets of transactions.
|
||||
* @param {Object} opts
|
||||
* @param {Object} [opts.initState={ transactions: [] }] initial transactions list with the key transaction {array}
|
||||
* @param {number} [opts.txHistoryLimit] limit for how many finished
|
||||
* transactions can hang around in state
|
||||
* @param {function} opts.getNetwork return network number
|
||||
* @class
|
||||
*/
|
||||
export default class TransactionStateManager extends EventEmitter {
|
||||
constructor({ initState, txHistoryLimit, getNetwork }) {
|
||||
super()
|
||||
@ -41,9 +36,9 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
@param {Object} opts - the object to use when overwriting defaults
|
||||
@returns {txMeta} - the default txMeta object
|
||||
*/
|
||||
* @param {Object} opts - the object to use when overwriting defaults
|
||||
* @returns {txMeta} - the default txMeta object
|
||||
*/
|
||||
generateTxMeta(opts) {
|
||||
const netId = this.getNetwork()
|
||||
if (netId === 'loading') {
|
||||
@ -52,7 +47,7 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
return {
|
||||
id: createId(),
|
||||
time: new Date().getTime(),
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: netId,
|
||||
loadingDefaults: true,
|
||||
...opts,
|
||||
@ -96,17 +91,20 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
@returns {array} - of all the txMetas in store
|
||||
*/
|
||||
* @returns {array} - of all the txMetas in store
|
||||
*/
|
||||
getFullTxList() {
|
||||
return this.store.getState().transactions
|
||||
}
|
||||
|
||||
/**
|
||||
@returns {array} - the tx list whose status is unapproved
|
||||
*/
|
||||
* @returns {array} - the tx list with unapproved status
|
||||
*/
|
||||
getUnapprovedTxList() {
|
||||
const txList = this.getTxsByMetaData('status', 'unapproved')
|
||||
const txList = this.getTxsByMetaData(
|
||||
'status',
|
||||
TRANSACTION_STATUSES.UNAPPROVED,
|
||||
)
|
||||
return txList.reduce((result, tx) => {
|
||||
result[tx.id] = tx
|
||||
return result
|
||||
@ -114,12 +112,12 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
@param [address] {string} - hex prefixed address to sort the txMetas for [optional]
|
||||
@returns {array} - the tx list whose status is approved if no address is provide
|
||||
returns all txMetas who's status is approved for the current network
|
||||
*/
|
||||
* @param [address] {string} - hex prefixed address to sort the txMetas for [optional]
|
||||
* @returns {array} - the tx list with approved status if no address is provide
|
||||
* returns all txMetas with approved statuses for the current network
|
||||
*/
|
||||
getApprovedTransactions(address) {
|
||||
const opts = { status: 'approved' }
|
||||
const opts = { status: TRANSACTION_STATUSES.APPROVED }
|
||||
if (address) {
|
||||
opts.from = address
|
||||
}
|
||||
@ -127,12 +125,12 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
@param [address] {string} - hex prefixed address to sort the txMetas for [optional]
|
||||
@returns {array} - the tx list whose status is submitted if no address is provide
|
||||
returns all txMetas who's status is submitted for the current network
|
||||
*/
|
||||
* @param [address] {string} - hex prefixed address to sort the txMetas for [optional]
|
||||
* @returns {array} - the tx list submitted status if no address is provide
|
||||
* returns all txMetas with submitted statuses for the current network
|
||||
*/
|
||||
getPendingTransactions(address) {
|
||||
const opts = { status: 'submitted' }
|
||||
const opts = { status: TRANSACTION_STATUSES.SUBMITTED }
|
||||
if (address) {
|
||||
opts.from = address
|
||||
}
|
||||
@ -145,7 +143,7 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
returns all txMetas who's status is confirmed for the current network
|
||||
*/
|
||||
getConfirmedTransactions(address) {
|
||||
const opts = { status: 'confirmed' }
|
||||
const opts = { status: TRANSACTION_STATUSES.CONFIRMED }
|
||||
if (address) {
|
||||
opts.from = address
|
||||
}
|
||||
@ -153,14 +151,14 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
Adds the txMeta to the list of transactions in the store.
|
||||
if the list is over txHistoryLimit it will remove a transaction that
|
||||
is in its final state
|
||||
it will also add the key `history` to the txMeta with the snap shot of the original
|
||||
object
|
||||
@param {Object} txMeta
|
||||
@returns {Object} - the txMeta
|
||||
*/
|
||||
* Adds the txMeta to the list of transactions in the store.
|
||||
* if the list is over txHistoryLimit it will remove a transaction that
|
||||
* is in its final state.
|
||||
* it will also add the key `history` to the txMeta with the snap shot of
|
||||
* the original object
|
||||
* @param {Object} txMeta
|
||||
* @returns {Object} - the txMeta
|
||||
*/
|
||||
addTx(txMeta) {
|
||||
// normalize and validate txParams if present
|
||||
if (txMeta.txParams) {
|
||||
@ -208,20 +206,20 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
@param {number} txId
|
||||
@returns {Object} - the txMeta who matches the given id if none found
|
||||
for the network returns undefined
|
||||
*/
|
||||
* @param {number} txId
|
||||
* @returns {Object} - the txMeta who matches the given id if none found
|
||||
* for the network returns undefined
|
||||
*/
|
||||
getTx(txId) {
|
||||
const txMeta = this.getTxsByMetaData('id', txId)[0]
|
||||
return txMeta
|
||||
}
|
||||
|
||||
/**
|
||||
updates the txMeta in the list and adds a history entry
|
||||
@param {Object} txMeta - the txMeta to update
|
||||
@param {string} [note] - a note about the update for history
|
||||
*/
|
||||
* updates the txMeta in the list and adds a history entry
|
||||
* @param {Object} txMeta - the txMeta to update
|
||||
* @param {string} [note] - a note about the update for history
|
||||
*/
|
||||
updateTx(txMeta, note) {
|
||||
// normalize and validate txParams if present
|
||||
if (txMeta.txParams) {
|
||||
@ -247,11 +245,11 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
merges txParams obj onto txMeta.txParams
|
||||
use extend to ensure that all fields are filled
|
||||
@param {number} txId - the id of the txMeta
|
||||
@param {Object} txParams - the updated txParams
|
||||
*/
|
||||
* merges txParams obj onto txMeta.txParams use extend to ensure
|
||||
* that all fields are filled
|
||||
* @param {number} txId - the id of the txMeta
|
||||
* @param {Object} txParams - the updated txParams
|
||||
*/
|
||||
updateTxParams(txId, txParams) {
|
||||
const txMeta = this.getTx(txId)
|
||||
txMeta.txParams = { ...txMeta.txParams, ...txParams }
|
||||
@ -273,9 +271,9 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
validates txParams members by type
|
||||
@param {Object} txParams - txParams to validate
|
||||
*/
|
||||
* validates txParams members by type
|
||||
* @param {Object} txParams - txParams to validate
|
||||
*/
|
||||
validateTxParams(txParams) {
|
||||
Object.keys(txParams).forEach((key) => {
|
||||
const value = txParams[key]
|
||||
@ -336,13 +334,12 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@param {string} key - the key to check
|
||||
@param value - the value your looking for can also be a function that returns a bool
|
||||
@param [txList=this.getTxList()] {array} - the list to search. default is the txList
|
||||
from txStateManager#getTxList
|
||||
@returns {array} - a list of txMetas who matches the search params
|
||||
*/
|
||||
* @param {string} key - the key to check
|
||||
* @param value - the value your looking for can also be a function that returns a bool
|
||||
* @param [txList=this.getTxList()] {array} - the list to search. default is the txList
|
||||
* from txStateManager#getTxList
|
||||
* @returns {array} - a list of txMetas who matches the search params
|
||||
*/
|
||||
getTxsByMetaData(key, value, txList = this.getTxList()) {
|
||||
const filter = typeof value === 'function' ? value : (v) => v === value
|
||||
|
||||
@ -357,81 +354,80 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
// get::set status
|
||||
|
||||
/**
|
||||
@param {number} txId - the txMeta Id
|
||||
@returns {string} - the status of the tx.
|
||||
*/
|
||||
* @param {number} txId - the txMeta Id
|
||||
* @returns {string} - the status of the tx.
|
||||
*/
|
||||
getTxStatus(txId) {
|
||||
const txMeta = this.getTx(txId)
|
||||
return txMeta.status
|
||||
}
|
||||
|
||||
/**
|
||||
should update the status of the tx to 'rejected'.
|
||||
@param {number} txId - the txMeta Id
|
||||
*/
|
||||
* Update the status of the tx to 'rejected'.
|
||||
* @param {number} txId - the txMeta Id
|
||||
*/
|
||||
setTxStatusRejected(txId) {
|
||||
this._setTxStatus(txId, 'rejected')
|
||||
this._removeTx(txId)
|
||||
}
|
||||
|
||||
/**
|
||||
should update the status of the tx to 'unapproved'.
|
||||
@param {number} txId - the txMeta Id
|
||||
*/
|
||||
* Update the status of the tx to 'unapproved'.
|
||||
* @param {number} txId - the txMeta Id
|
||||
*/
|
||||
setTxStatusUnapproved(txId) {
|
||||
this._setTxStatus(txId, 'unapproved')
|
||||
this._setTxStatus(txId, TRANSACTION_STATUSES.UNAPPROVED)
|
||||
}
|
||||
|
||||
/**
|
||||
should update the status of the tx to 'approved'.
|
||||
@param {number} txId - the txMeta Id
|
||||
*/
|
||||
* Update the status of the tx to 'approved'.
|
||||
* @param {number} txId - the txMeta Id
|
||||
*/
|
||||
setTxStatusApproved(txId) {
|
||||
this._setTxStatus(txId, 'approved')
|
||||
this._setTxStatus(txId, TRANSACTION_STATUSES.APPROVED)
|
||||
}
|
||||
|
||||
/**
|
||||
should update the status of the tx to 'signed'.
|
||||
@param {number} txId - the txMeta Id
|
||||
*/
|
||||
* Update the status of the tx to 'signed'.
|
||||
* @param {number} txId - the txMeta Id
|
||||
*/
|
||||
setTxStatusSigned(txId) {
|
||||
this._setTxStatus(txId, 'signed')
|
||||
this._setTxStatus(txId, TRANSACTION_STATUSES.SIGNED)
|
||||
}
|
||||
|
||||
/**
|
||||
should update the status of the tx to 'submitted'.
|
||||
and add a time stamp for when it was called
|
||||
@param {number} txId - the txMeta Id
|
||||
*/
|
||||
* Update the status of the tx to 'submitted' and add a time stamp
|
||||
* for when it was called
|
||||
* @param {number} txId - the txMeta Id
|
||||
*/
|
||||
setTxStatusSubmitted(txId) {
|
||||
const txMeta = this.getTx(txId)
|
||||
txMeta.submittedTime = new Date().getTime()
|
||||
this.updateTx(txMeta, 'txStateManager - add submitted time stamp')
|
||||
this._setTxStatus(txId, 'submitted')
|
||||
this._setTxStatus(txId, TRANSACTION_STATUSES.SUBMITTED)
|
||||
}
|
||||
|
||||
/**
|
||||
should update the status of the tx to 'confirmed'.
|
||||
@param {number} txId - the txMeta Id
|
||||
*/
|
||||
* Update the status of the tx to 'confirmed'.
|
||||
* @param {number} txId - the txMeta Id
|
||||
*/
|
||||
setTxStatusConfirmed(txId) {
|
||||
this._setTxStatus(txId, 'confirmed')
|
||||
this._setTxStatus(txId, TRANSACTION_STATUSES.CONFIRMED)
|
||||
}
|
||||
|
||||
/**
|
||||
should update the status of the tx to 'dropped'.
|
||||
@param {number} txId - the txMeta Id
|
||||
*/
|
||||
* Update the status of the tx to 'dropped'.
|
||||
* @param {number} txId - the txMeta Id
|
||||
*/
|
||||
setTxStatusDropped(txId) {
|
||||
this._setTxStatus(txId, 'dropped')
|
||||
this._setTxStatus(txId, TRANSACTION_STATUSES.DROPPED)
|
||||
}
|
||||
|
||||
/**
|
||||
should update the status of the tx to 'failed'.
|
||||
and put the error on the txMeta
|
||||
@param {number} txId - the txMeta Id
|
||||
@param {erroObject} err - error object
|
||||
*/
|
||||
* Updates the status of the tx to 'failed' and put the error on the txMeta
|
||||
* @param {number} txId - the txMeta Id
|
||||
* @param {erroObject} err - error object
|
||||
*/
|
||||
setTxStatusFailed(txId, err) {
|
||||
const error = err || new Error('Internal metamask failure')
|
||||
|
||||
@ -442,14 +438,15 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
stack: error.stack,
|
||||
}
|
||||
this.updateTx(txMeta, 'transactions:tx-state-manager#fail - add error')
|
||||
this._setTxStatus(txId, 'failed')
|
||||
this._setTxStatus(txId, TRANSACTION_STATUSES.FAILED)
|
||||
}
|
||||
|
||||
/**
|
||||
Removes transaction from the given address for the current network
|
||||
from the txList
|
||||
@param {string} address - hex string of the from address on the txParams to remove
|
||||
*/
|
||||
* Removes transaction from the given address for the current network
|
||||
* from the txList
|
||||
* @param {string} address - hex string of the from address on the txParams
|
||||
* to remove
|
||||
*/
|
||||
wipeTransactions(address) {
|
||||
// network only tx
|
||||
const txs = this.getFullTxList()
|
||||
@ -467,28 +464,18 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
// Update state
|
||||
this._saveTxList(otherAccountTxs)
|
||||
}
|
||||
|
||||
//
|
||||
// PRIVATE METHODS
|
||||
//
|
||||
|
||||
// STATUS METHODS
|
||||
// statuses:
|
||||
// - `'unapproved'` the user has not responded
|
||||
// - `'rejected'` the user has responded no!
|
||||
// - `'approved'` the user has approved the tx
|
||||
// - `'signed'` the tx is signed
|
||||
// - `'submitted'` the tx is sent to a server
|
||||
// - `'confirmed'` the tx has been included in a block.
|
||||
// - `'failed'` the tx failed for some reason, included on tx data.
|
||||
// - `'dropped'` the tx nonce was already used
|
||||
|
||||
/**
|
||||
@param {number} txId - the txMeta Id
|
||||
@param {string} status - the status to set on the txMeta
|
||||
@emits tx:status-update - passes txId and status
|
||||
@emits ${txMeta.id}:finished - if it is a finished state. Passes the txMeta
|
||||
@emits update:badge
|
||||
*/
|
||||
* @param {number} txId - the txMeta Id
|
||||
* @param {TransactionStatuses[keyof TransactionStatuses]} status - the status to set on the txMeta
|
||||
* @emits tx:status-update - passes txId and status
|
||||
* @emits ${txMeta.id}:finished - if it is a finished state. Passes the txMeta
|
||||
* @emits update:badge
|
||||
*/
|
||||
_setTxStatus(txId, status) {
|
||||
const txMeta = this.getTx(txId)
|
||||
|
||||
@ -501,7 +488,13 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
this.updateTx(txMeta, `txStateManager: setting status to ${status}`)
|
||||
this.emit(`${txMeta.id}:${status}`, txId)
|
||||
this.emit(`tx:status-update`, txId, status)
|
||||
if (['submitted', 'rejected', 'failed'].includes(status)) {
|
||||
if (
|
||||
[
|
||||
TRANSACTION_STATUSES.SUBMITTED,
|
||||
TRANSACTION_STATUSES.REJECTED,
|
||||
TRANSACTION_STATUSES.FAILED,
|
||||
].includes(status)
|
||||
) {
|
||||
this.emit(`${txMeta.id}:finished`, txMeta)
|
||||
}
|
||||
this.emit('update:badge')
|
||||
@ -511,10 +504,9 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
Saves the new/updated txList.
|
||||
@param {array} transactions - the list of transactions to save
|
||||
*/
|
||||
// Function is intended only for internal use
|
||||
* Saves the new/updated txList. Intended only for internal use
|
||||
* @param {array} transactions - the list of transactions to save
|
||||
*/
|
||||
_saveTxList(transactions) {
|
||||
this.store.updateState({ transactions })
|
||||
}
|
||||
@ -527,11 +519,10 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
/**
|
||||
* Filters out the unapproved transactions
|
||||
*/
|
||||
|
||||
clearUnapprovedTxs() {
|
||||
const transactions = this.getFullTxList()
|
||||
const nonUnapprovedTxs = transactions.filter(
|
||||
(tx) => tx.status !== 'unapproved',
|
||||
(tx) => tx.status !== TRANSACTION_STATUSES.UNAPPROVED,
|
||||
)
|
||||
this._saveTxList(nonUnapprovedTxs)
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import {
|
||||
} from '@metamask/controllers'
|
||||
import { getTrackMetaMetricsEvent } from '../../shared/modules/metametrics'
|
||||
import { getBackgroundMetaMetricState } from '../../ui/app/selectors'
|
||||
import { TRANSACTION_STATUSES } from '../../shared/constants/transaction'
|
||||
import ComposableObservableStore from './lib/ComposableObservableStore'
|
||||
import AccountTracker from './lib/account-tracker'
|
||||
import createLoggerMiddleware from './lib/createLoggerMiddleware'
|
||||
@ -304,7 +305,10 @@ export default class MetamaskController extends EventEmitter {
|
||||
this.txController.on('newUnapprovedTx', () => opts.showUnapprovedTx())
|
||||
|
||||
this.txController.on(`tx:status-update`, async (txId, status) => {
|
||||
if (status === 'confirmed' || status === 'failed') {
|
||||
if (
|
||||
status === TRANSACTION_STATUSES.CONFIRMED ||
|
||||
status === TRANSACTION_STATUSES.FAILED
|
||||
) {
|
||||
const txMeta = this.txController.txStateManager.getTx(txId)
|
||||
this.platform.showTransactionNotification(txMeta)
|
||||
|
||||
@ -441,7 +445,10 @@ export default class MetamaskController extends EventEmitter {
|
||||
processEncryptionPublicKey: this.newRequestEncryptionPublicKey.bind(this),
|
||||
getPendingNonce: this.getPendingNonce.bind(this),
|
||||
getPendingTransactionByHash: (hash) =>
|
||||
this.txController.getFilteredTxList({ hash, status: 'submitted' })[0],
|
||||
this.txController.getFilteredTxList({
|
||||
hash,
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
})[0],
|
||||
}
|
||||
const providerProxy = this.networkController.initializeProvider(
|
||||
providerOpts,
|
||||
|
@ -6,6 +6,7 @@ to a 'failed' stated
|
||||
*/
|
||||
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const version = 15
|
||||
|
||||
@ -35,7 +36,7 @@ function transformState(state) {
|
||||
if (!txMeta.err) {
|
||||
return txMeta
|
||||
} else if (txMeta.err.message === 'Gave up submitting tx.') {
|
||||
txMeta.status = 'failed'
|
||||
txMeta.status = TRANSACTION_STATUSES.FAILED
|
||||
}
|
||||
return txMeta
|
||||
})
|
||||
|
@ -6,6 +6,7 @@ to a 'failed' stated
|
||||
*/
|
||||
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const version = 16
|
||||
|
||||
@ -39,7 +40,7 @@ function transformState(state) {
|
||||
if (
|
||||
txMeta.err === 'transaction with the same hash was already imported.'
|
||||
) {
|
||||
txMeta.status = 'submitted'
|
||||
txMeta.status = TRANSACTION_STATUSES.SUBMITTED
|
||||
delete txMeta.err
|
||||
}
|
||||
return txMeta
|
||||
|
@ -5,6 +5,7 @@ This migration sets transactions who were retried and marked as failed to submit
|
||||
*/
|
||||
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const version = 17
|
||||
|
||||
@ -31,11 +32,11 @@ function transformState(state) {
|
||||
if (TransactionController && TransactionController.transactions) {
|
||||
const { transactions } = newState.TransactionController
|
||||
newState.TransactionController.transactions = transactions.map((txMeta) => {
|
||||
if (!txMeta.status === 'failed') {
|
||||
if (!txMeta.status === TRANSACTION_STATUSES.FAILED) {
|
||||
return txMeta
|
||||
}
|
||||
if (txMeta.retryCount > 0 && txMeta.retryCount < 2) {
|
||||
txMeta.status = 'submitted'
|
||||
txMeta.status = TRANSACTION_STATUSES.SUBMITTED
|
||||
delete txMeta.err
|
||||
}
|
||||
return txMeta
|
||||
|
@ -6,6 +6,7 @@ whos nonce is too high
|
||||
*/
|
||||
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const version = 19
|
||||
|
||||
@ -34,12 +35,12 @@ function transformState(state) {
|
||||
|
||||
newState.TransactionController.transactions = transactions.map(
|
||||
(txMeta, _, txList) => {
|
||||
if (txMeta.status !== 'submitted') {
|
||||
if (txMeta.status !== TRANSACTION_STATUSES.SUBMITTED) {
|
||||
return txMeta
|
||||
}
|
||||
|
||||
const confirmedTxs = txList
|
||||
.filter((tx) => tx.status === 'confirmed')
|
||||
.filter((tx) => tx.status === TRANSACTION_STATUSES.CONFIRMED)
|
||||
.filter((tx) => tx.txParams.from === txMeta.txParams.from)
|
||||
.filter(
|
||||
(tx) => tx.metamaskNetworkId.from === txMeta.metamaskNetworkId.from,
|
||||
@ -47,7 +48,7 @@ function transformState(state) {
|
||||
const highestConfirmedNonce = getHighestNonce(confirmedTxs)
|
||||
|
||||
const pendingTxs = txList
|
||||
.filter((tx) => tx.status === 'submitted')
|
||||
.filter((tx) => tx.status === TRANSACTION_STATUSES.SUBMITTED)
|
||||
.filter((tx) => tx.txParams.from === txMeta.txParams.from)
|
||||
.filter(
|
||||
(tx) => tx.metamaskNetworkId.from === txMeta.metamaskNetworkId.from,
|
||||
@ -60,7 +61,7 @@ function transformState(state) {
|
||||
const maxNonce = Math.max(highestContinuousNonce, highestConfirmedNonce)
|
||||
|
||||
if (parseInt(txMeta.txParams.nonce, 16) > maxNonce + 1) {
|
||||
txMeta.status = 'failed'
|
||||
txMeta.status = TRANSACTION_STATUSES.FAILED
|
||||
txMeta.err = {
|
||||
message: 'nonce too high',
|
||||
note: 'migration 019 custom error',
|
||||
|
@ -5,6 +5,7 @@ This migration adds submittedTime to the txMeta if it is not their
|
||||
*/
|
||||
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const version = 22
|
||||
|
||||
@ -32,7 +33,10 @@ function transformState(state) {
|
||||
const { transactions } = newState.TransactionController
|
||||
|
||||
newState.TransactionController.transactions = transactions.map((txMeta) => {
|
||||
if (txMeta.status !== 'submitted' || txMeta.submittedTime) {
|
||||
if (
|
||||
txMeta.status !== TRANSACTION_STATUSES.SUBMITTED ||
|
||||
txMeta.submittedTime
|
||||
) {
|
||||
return txMeta
|
||||
}
|
||||
txMeta.submittedTime = new Date().getTime()
|
||||
|
@ -5,6 +5,7 @@ This migration removes transactions that are no longer usefull down to 40 total
|
||||
*/
|
||||
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const version = 23
|
||||
|
||||
@ -41,10 +42,10 @@ function transformState(state) {
|
||||
while (reverseTxList.length > 40 && stripping) {
|
||||
const txIndex = reverseTxList.findIndex((txMeta) => {
|
||||
return (
|
||||
txMeta.status === 'failed' ||
|
||||
txMeta.status === 'rejected' ||
|
||||
txMeta.status === 'confirmed' ||
|
||||
txMeta.status === 'dropped'
|
||||
txMeta.status === TRANSACTION_STATUSES.FAILED ||
|
||||
txMeta.status === TRANSACTION_STATUSES.REJECTED ||
|
||||
txMeta.status === TRANSACTION_STATUSES.CONFIRMED ||
|
||||
txMeta.status === TRANSACTION_STATUSES.DROPPED
|
||||
)
|
||||
})
|
||||
if (txIndex < 0) {
|
||||
|
@ -6,6 +6,7 @@ all unapproved transactions
|
||||
*/
|
||||
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const version = 24
|
||||
|
||||
@ -31,7 +32,7 @@ function transformState(state) {
|
||||
newState.TransactionController.transactions = transactions.map(
|
||||
(txMeta, _) => {
|
||||
if (
|
||||
txMeta.status === 'unapproved' &&
|
||||
txMeta.status === TRANSACTION_STATUSES.UNAPPROVED &&
|
||||
txMeta.txParams &&
|
||||
txMeta.txParams.from
|
||||
) {
|
||||
|
@ -6,6 +6,7 @@ normalizes txParams on unconfirmed txs
|
||||
*/
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { addHexPrefix } from '../lib/util'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const version = 25
|
||||
|
||||
@ -30,7 +31,7 @@ function transformState(state) {
|
||||
const { transactions } = newState.TransactionController
|
||||
newState.TransactionController.transactions = transactions.map(
|
||||
(txMeta) => {
|
||||
if (txMeta.status !== 'unapproved') {
|
||||
if (txMeta.status !== TRANSACTION_STATUSES.UNAPPROVED) {
|
||||
return txMeta
|
||||
}
|
||||
txMeta.txParams = normalizeTxParams(txMeta.txParams)
|
||||
|
@ -5,6 +5,7 @@ normalizes txParams on unconfirmed txs
|
||||
|
||||
*/
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const version = 27
|
||||
|
||||
@ -28,7 +29,7 @@ function transformState(state) {
|
||||
if (newState.TransactionController.transactions) {
|
||||
const { transactions } = newState.TransactionController
|
||||
newState.TransactionController.transactions = transactions.filter(
|
||||
(txMeta) => txMeta.status !== 'rejected',
|
||||
(txMeta) => txMeta.status !== TRANSACTION_STATUSES.REJECTED,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
// next version number
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
import failTxsThat from './fail-tx'
|
||||
|
||||
const version = 29
|
||||
@ -22,7 +23,7 @@ export default {
|
||||
version,
|
||||
'Stuck in approved state for too long.',
|
||||
(txMeta) => {
|
||||
const isApproved = txMeta.status === 'approved'
|
||||
const isApproved = txMeta.status === TRANSACTION_STATUSES.APPROVED
|
||||
const createdTime = txMeta.submittedTime
|
||||
const now = Date.now()
|
||||
return isApproved && now - createdTime > unacceptableDelay
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
export default function failTxsThat(version, reason, condition) {
|
||||
return function (originalVersionedData) {
|
||||
@ -26,7 +27,7 @@ function transformState(state, condition, reason) {
|
||||
return txMeta
|
||||
}
|
||||
|
||||
txMeta.status = 'failed'
|
||||
txMeta.status = TRANSACTION_STATUSES.FAILED
|
||||
txMeta.err = {
|
||||
message: reason,
|
||||
note: `Tx automatically failed by migration because ${reason}`,
|
||||
|
@ -2,6 +2,7 @@ import extension from 'extensionizer'
|
||||
import { createExplorerLink as explorerLink } from '@metamask/etherscan-link'
|
||||
import { getEnvironmentType, checkForError } from '../lib/util'
|
||||
import { ENVIRONMENT_TYPE_BACKGROUND } from '../lib/enums'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
export default class ExtensionPlatform {
|
||||
//
|
||||
@ -112,7 +113,7 @@ export default class ExtensionPlatform {
|
||||
showTransactionNotification(txMeta) {
|
||||
const { status, txReceipt: { status: receiptStatus } = {} } = txMeta
|
||||
|
||||
if (status === 'confirmed') {
|
||||
if (status === TRANSACTION_STATUSES.CONFIRMED) {
|
||||
// There was an on-chain failure
|
||||
receiptStatus === '0x0'
|
||||
? this._showFailedTransaction(
|
||||
@ -120,7 +121,7 @@ export default class ExtensionPlatform {
|
||||
'Transaction encountered an error.',
|
||||
)
|
||||
: this._showConfirmedTransaction(txMeta)
|
||||
} else if (status === 'failed') {
|
||||
} else if (status === TRANSACTION_STATUSES.FAILED) {
|
||||
this._showFailedTransaction(txMeta)
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ export const TRANSACTION_TYPES = {
|
||||
* @property {'rejected'} REJECTED - The user has rejected the transaction in the
|
||||
* MetaMask UI
|
||||
* @property {'signed'} SIGNED - The transaction has been signed
|
||||
* @property {'submitted'} SIGNED - The transaction has been submitted to network
|
||||
* @property {'submitted'} SUBMITTED - The transaction has been submitted to network
|
||||
* @property {'failed'} FAILED - The transaction has failed for some reason
|
||||
* @property {'dropped'} DROPPED - The transaction was dropped due to a tx with same
|
||||
* nonce being accepted
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { snapshotFromTxMeta } from '../../app/scripts/controllers/transactions/lib/tx-state-history-helpers'
|
||||
import { TRANSACTION_STATUSES } from '../../shared/constants/transaction'
|
||||
|
||||
export default function createTxMeta(partialMeta) {
|
||||
const txMeta = {
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: {},
|
||||
...partialMeta,
|
||||
}
|
||||
|
@ -15,6 +15,10 @@ import {
|
||||
ROPSTEN_CHAIN_ID,
|
||||
ROPSTEN_NETWORK_ID,
|
||||
} from '../../../../app/scripts/controllers/network/enums'
|
||||
import {
|
||||
TRANSACTION_CATEGORIES,
|
||||
TRANSACTION_STATUSES,
|
||||
} from '../../../../shared/constants/transaction'
|
||||
|
||||
const IncomingTransactionsController = proxyquire(
|
||||
'../../../../app/scripts/controllers/incoming-transactions',
|
||||
@ -266,9 +270,9 @@ describe('IncomingTransactionsController', function () {
|
||||
blockNumber: '10',
|
||||
hash: '0xfake',
|
||||
metamaskNetworkId: '3',
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
time: 16000000000000000,
|
||||
transactionCategory: 'incoming',
|
||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
||||
txParams: {
|
||||
from: '0xfake',
|
||||
gas: '0x0',
|
||||
@ -609,9 +613,9 @@ describe('IncomingTransactionsController', function () {
|
||||
blockNumber: '10',
|
||||
hash: '0xfake',
|
||||
metamaskNetworkId: '3',
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
time: 16000000000000000,
|
||||
transactionCategory: 'incoming',
|
||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
||||
txParams: {
|
||||
from: '0xfake',
|
||||
gas: '0x0',
|
||||
@ -763,9 +767,9 @@ describe('IncomingTransactionsController', function () {
|
||||
blockNumber: '10',
|
||||
hash: '0xfake',
|
||||
metamaskNetworkId: '3',
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
time: 16000000000000000,
|
||||
transactionCategory: 'incoming',
|
||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
||||
txParams: {
|
||||
from: '0xfake',
|
||||
gas: '0x0',
|
||||
@ -1340,7 +1344,7 @@ describe('IncomingTransactionsController', function () {
|
||||
blockNumber: 333,
|
||||
id: 54321,
|
||||
metamaskNetworkId: ROPSTEN_NETWORK_ID,
|
||||
status: 'failed',
|
||||
status: TRANSACTION_STATUSES.FAILED,
|
||||
time: 4444000,
|
||||
txParams: {
|
||||
from: '0xa',
|
||||
@ -1351,7 +1355,7 @@ describe('IncomingTransactionsController', function () {
|
||||
value: '0xf',
|
||||
},
|
||||
hash: '0xg',
|
||||
transactionCategory: 'incoming',
|
||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
||||
})
|
||||
})
|
||||
|
||||
@ -1385,7 +1389,7 @@ describe('IncomingTransactionsController', function () {
|
||||
blockNumber: 333,
|
||||
id: 54321,
|
||||
metamaskNetworkId: ROPSTEN_NETWORK_ID,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
time: 4444000,
|
||||
txParams: {
|
||||
from: '0xa',
|
||||
@ -1396,7 +1400,7 @@ describe('IncomingTransactionsController', function () {
|
||||
value: '0xf',
|
||||
},
|
||||
hash: '0xg',
|
||||
transactionCategory: 'incoming',
|
||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -9,6 +9,7 @@ import proxyquire from 'proxyquire'
|
||||
import firstTimeState from '../../localhostState'
|
||||
import createTxMeta from '../../../lib/createTxMeta'
|
||||
import { addHexPrefix } from '../../../../app/scripts/lib/util'
|
||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
||||
|
||||
const threeBoxSpies = {
|
||||
init: sinon.stub(),
|
||||
@ -708,20 +709,24 @@ describe('MetaMaskController', function () {
|
||||
metamaskController.txController.txStateManager._saveTxList([
|
||||
createTxMeta({
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: { from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc' },
|
||||
}),
|
||||
createTxMeta({
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: { from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc' },
|
||||
}),
|
||||
createTxMeta({ id: 2, status: 'rejected', metamaskNetworkId: '32' }),
|
||||
createTxMeta({
|
||||
id: 2,
|
||||
status: TRANSACTION_STATUSES.REJECTED,
|
||||
metamaskNetworkId: '32',
|
||||
}),
|
||||
createTxMeta({
|
||||
id: 3,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: { from: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4' },
|
||||
}),
|
||||
@ -847,7 +852,7 @@ describe('MetaMaskController', function () {
|
||||
})
|
||||
|
||||
it('sets the status to unapproved', function () {
|
||||
assert.equal(metamaskMsgs[msgId].status, 'unapproved')
|
||||
assert.equal(metamaskMsgs[msgId].status, TRANSACTION_STATUSES.UNAPPROVED)
|
||||
})
|
||||
|
||||
it('sets the type to eth_sign', function () {
|
||||
@ -857,7 +862,7 @@ describe('MetaMaskController', function () {
|
||||
it('rejects the message', function () {
|
||||
const msgIdInt = parseInt(msgId, 10)
|
||||
metamaskController.cancelMessage(msgIdInt, noop)
|
||||
assert.equal(messages[0].status, 'rejected')
|
||||
assert.equal(messages[0].status, TRANSACTION_STATUSES.REJECTED)
|
||||
})
|
||||
|
||||
it('errors when signing a message', async function () {
|
||||
@ -924,7 +929,10 @@ describe('MetaMaskController', function () {
|
||||
})
|
||||
|
||||
it('sets the status to unapproved', function () {
|
||||
assert.equal(metamaskPersonalMsgs[msgId].status, 'unapproved')
|
||||
assert.equal(
|
||||
metamaskPersonalMsgs[msgId].status,
|
||||
TRANSACTION_STATUSES.UNAPPROVED,
|
||||
)
|
||||
})
|
||||
|
||||
it('sets the type to personal_sign', function () {
|
||||
@ -934,14 +942,17 @@ describe('MetaMaskController', function () {
|
||||
it('rejects the message', function () {
|
||||
const msgIdInt = parseInt(msgId, 10)
|
||||
metamaskController.cancelPersonalMessage(msgIdInt, noop)
|
||||
assert.equal(personalMessages[0].status, 'rejected')
|
||||
assert.equal(personalMessages[0].status, TRANSACTION_STATUSES.REJECTED)
|
||||
})
|
||||
|
||||
it('errors when signing a message', async function () {
|
||||
await metamaskController.signPersonalMessage(
|
||||
personalMessages[0].msgParams,
|
||||
)
|
||||
assert.equal(metamaskPersonalMsgs[msgId].status, 'signed')
|
||||
assert.equal(
|
||||
metamaskPersonalMsgs[msgId].status,
|
||||
TRANSACTION_STATUSES.SIGNED,
|
||||
)
|
||||
assert.equal(
|
||||
metamaskPersonalMsgs[msgId].rawSig,
|
||||
'0x6a1b65e2b8ed53cf398a769fad24738f9fbe29841fe6854e226953542c4b6a173473cb152b6b1ae5f06d601d45dd699a129b0a8ca84e78b423031db5baa734741b',
|
||||
|
@ -1,3 +1,9 @@
|
||||
import {
|
||||
TRANSACTION_CATEGORIES,
|
||||
TRANSACTION_STATUSES,
|
||||
TRANSACTION_TYPES,
|
||||
} from '../../../../../shared/constants/transaction'
|
||||
|
||||
export const txMetaStub = {
|
||||
firstRetryBlockNumber: '0x51a402',
|
||||
hash: '0x2cc5a25744486f7383edebbf32003e5a66e18135799593d6b5cdd2bb43674f09',
|
||||
@ -6,9 +12,9 @@ export const txMetaStub = {
|
||||
id: 405984854664302,
|
||||
loadingDefaults: true,
|
||||
metamaskNetworkId: '4',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
time: 1572395156620,
|
||||
transactionCategory: 'sentEther',
|
||||
transactionCategory: TRANSACTION_CATEGORIES.SENT_ETHER,
|
||||
txParams: {
|
||||
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||
gas: '0x5208',
|
||||
@ -16,7 +22,7 @@ export const txMetaStub = {
|
||||
to: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||
value: '0x0',
|
||||
},
|
||||
type: 'standard',
|
||||
type: TRANSACTION_TYPES.STANDARD,
|
||||
},
|
||||
[
|
||||
{
|
||||
@ -42,7 +48,7 @@ export const txMetaStub = {
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
timestamp: 1572395158240,
|
||||
value: 'approved',
|
||||
value: TRANSACTION_STATUSES.APPROVED,
|
||||
},
|
||||
],
|
||||
[
|
||||
@ -108,7 +114,7 @@ export const txMetaStub = {
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
timestamp: 1572395158281,
|
||||
value: 'signed',
|
||||
value: TRANSACTION_STATUSES.SIGNED,
|
||||
},
|
||||
{
|
||||
op: 'add',
|
||||
@ -143,7 +149,7 @@ export const txMetaStub = {
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
timestamp: 1572395158576,
|
||||
value: 'submitted',
|
||||
value: TRANSACTION_STATUSES.SUBMITTED,
|
||||
},
|
||||
],
|
||||
[
|
||||
@ -187,10 +193,10 @@ export const txMetaStub = {
|
||||
rawTx:
|
||||
'0xf86204831e848082520894f231d46dd78806e1dd93442cf33c7671f853874880802ca05f973e540f2d3c2f06d3725a626b75247593cb36477187ae07ecfe0a4db3cf57a00259b52ee8c58baaa385fb05c3f96116e58de89bcc165cb3bfdfc708672fed8a',
|
||||
s: '0x0259b52ee8c58baaa385fb05c3f96116e58de89bcc165cb3bfdfc708672fed8a',
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
submittedTime: 1572395158570,
|
||||
time: 1572395156620,
|
||||
transactionCategory: 'sentEther',
|
||||
transactionCategory: TRANSACTION_CATEGORIES.SENT_ETHER,
|
||||
txParams: {
|
||||
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||
gas: '0x5208',
|
||||
@ -199,6 +205,6 @@ export const txMetaStub = {
|
||||
to: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||
value: '0x0',
|
||||
},
|
||||
type: 'standard',
|
||||
type: TRANSACTION_TYPES.STANDARD,
|
||||
v: '0x2c',
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { strict as assert } from 'assert'
|
||||
import sinon from 'sinon'
|
||||
import BN from 'bn.js'
|
||||
import PendingTransactionTracker from '../../../../../app/scripts/controllers/transactions/pending-tx-tracker'
|
||||
import { TRANSACTION_STATUSES } from '../../../../../shared/constants/transaction'
|
||||
|
||||
describe('PendingTransactionTracker', function () {
|
||||
describe('#resubmitPendingTxs', function () {
|
||||
@ -155,7 +156,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 1,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'signed',
|
||||
status: TRANSACTION_STATUSES.SIGNED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x1',
|
||||
@ -213,7 +214,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 1,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'signed',
|
||||
status: TRANSACTION_STATUSES.SIGNED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x1',
|
||||
@ -258,7 +259,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 1,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'signed',
|
||||
status: TRANSACTION_STATUSES.SIGNED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x1',
|
||||
@ -305,7 +306,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 1,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'signed',
|
||||
status: TRANSACTION_STATUSES.SIGNED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x1',
|
||||
@ -405,7 +406,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 1,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x1',
|
||||
@ -438,7 +439,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 1,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x1',
|
||||
@ -459,7 +460,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 1,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x1',
|
||||
@ -472,7 +473,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 2,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x2',
|
||||
@ -518,7 +519,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 1,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x1',
|
||||
@ -531,7 +532,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 2,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x2',
|
||||
@ -578,7 +579,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 1,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x1',
|
||||
@ -647,7 +648,7 @@ describe('PendingTransactionTracker', function () {
|
||||
pendingTxTracker.once('tx:failed', listeners.failed)
|
||||
pendingTxTracker.once('tx:warning', listeners.warning)
|
||||
await pendingTxTracker._checkPendingTx({
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
history: [{}],
|
||||
txParams: { nonce: '0x1' },
|
||||
id: '456',
|
||||
@ -688,7 +689,7 @@ describe('PendingTransactionTracker', function () {
|
||||
await pendingTxTracker._checkPendingTx({
|
||||
id: '2',
|
||||
history: [{}],
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
txParams: { from: '0x1678a085c290ebd122dc42cba69373b5953b831d' },
|
||||
})
|
||||
|
||||
@ -707,7 +708,7 @@ describe('PendingTransactionTracker', function () {
|
||||
it("should emit 'tx:dropped' if another tx with the same nonce succeeds", async function () {
|
||||
const txs = [
|
||||
{
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
history: [{}],
|
||||
txParams: { nonce: '0x1' },
|
||||
id: '456',
|
||||
@ -715,7 +716,7 @@ describe('PendingTransactionTracker', function () {
|
||||
hash: '0xbad',
|
||||
},
|
||||
{
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
history: [{}],
|
||||
txParams: { nonce: '0x1' },
|
||||
id: '123',
|
||||
@ -763,7 +764,7 @@ describe('PendingTransactionTracker', function () {
|
||||
id: 1,
|
||||
hash:
|
||||
'0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
txParams: {
|
||||
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
nonce: '0x1',
|
||||
|
@ -12,6 +12,7 @@ import {
|
||||
} from '../../../../stub/provider'
|
||||
import {
|
||||
TRANSACTION_CATEGORIES,
|
||||
TRANSACTION_STATUSES,
|
||||
TRANSACTION_TYPES,
|
||||
} from '../../../../../shared/constants/transaction'
|
||||
|
||||
@ -83,21 +84,21 @@ describe('Transaction Controller', function () {
|
||||
txController.txStateManager._saveTxList([
|
||||
{
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
@ -113,21 +114,21 @@ describe('Transaction Controller', function () {
|
||||
txController.txStateManager._saveTxList([
|
||||
{
|
||||
id: 1,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
@ -148,63 +149,63 @@ describe('Transaction Controller', function () {
|
||||
txController.txStateManager._saveTxList([
|
||||
{
|
||||
id: 0,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
status: 'rejected',
|
||||
status: TRANSACTION_STATUSES.REJECTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
status: 'signed',
|
||||
status: TRANSACTION_STATUSES.SIGNED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
status: 'failed',
|
||||
status: TRANSACTION_STATUSES.FAILED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
history: [{}],
|
||||
@ -225,7 +226,7 @@ describe('Transaction Controller', function () {
|
||||
to: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
||||
}
|
||||
txMeta = {
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
id: 1,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
@ -350,7 +351,7 @@ describe('Transaction Controller', function () {
|
||||
txController.txStateManager._saveTxList([
|
||||
{
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
@ -384,7 +385,7 @@ describe('Transaction Controller', function () {
|
||||
it('should emit updates', function (done) {
|
||||
const txMeta = {
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
@ -419,7 +420,7 @@ describe('Transaction Controller', function () {
|
||||
const originalValue = '0x01'
|
||||
const txMeta = {
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {
|
||||
nonce: originalValue,
|
||||
@ -454,7 +455,7 @@ describe('Transaction Controller', function () {
|
||||
assert.equal(result.hash, originalValue)
|
||||
assert.equal(
|
||||
result.status,
|
||||
'submitted',
|
||||
TRANSACTION_STATUSES.SUBMITTED,
|
||||
'should have reached the submitted status.',
|
||||
)
|
||||
signStub.restore()
|
||||
@ -467,7 +468,7 @@ describe('Transaction Controller', function () {
|
||||
txController.addTx(
|
||||
{
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
},
|
||||
@ -483,7 +484,7 @@ describe('Transaction Controller', function () {
|
||||
it('should update and approve transactions', async function () {
|
||||
const txMeta = {
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: {
|
||||
from: fromAccount.address,
|
||||
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
@ -496,7 +497,7 @@ describe('Transaction Controller', function () {
|
||||
txController.txStateManager.addTx(txMeta)
|
||||
const approvalPromise = txController.updateAndApproveTransaction(txMeta)
|
||||
const tx = txController.txStateManager.getTx(1)
|
||||
assert.equal(tx.status, 'approved')
|
||||
assert.equal(tx.status, TRANSACTION_STATUSES.APPROVED)
|
||||
await approvalPromise
|
||||
})
|
||||
})
|
||||
@ -513,49 +514,49 @@ describe('Transaction Controller', function () {
|
||||
txController.txStateManager._saveTxList([
|
||||
{
|
||||
id: 0,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: {},
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
status: 'rejected',
|
||||
status: TRANSACTION_STATUSES.REJECTED,
|
||||
txParams: {},
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
txParams: {},
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
status: 'signed',
|
||||
status: TRANSACTION_STATUSES.SIGNED,
|
||||
txParams: {},
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
txParams: {},
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: {},
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
status: 'failed',
|
||||
status: TRANSACTION_STATUSES.FAILED,
|
||||
txParams: {},
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
@ -564,7 +565,11 @@ describe('Transaction Controller', function () {
|
||||
|
||||
txController.once('tx:status-update', (txId, status) => {
|
||||
try {
|
||||
assert.equal(status, 'rejected', 'status should e rejected')
|
||||
assert.equal(
|
||||
status,
|
||||
TRANSACTION_STATUSES.REJECTED,
|
||||
'status should be rejected',
|
||||
)
|
||||
assert.equal(txId, 0, 'id should e 0')
|
||||
done()
|
||||
} catch (e) {
|
||||
@ -596,7 +601,7 @@ describe('Transaction Controller', function () {
|
||||
txController.txStateManager._saveTxList([
|
||||
{
|
||||
id: 1,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
history: [{}],
|
||||
@ -659,7 +664,7 @@ describe('Transaction Controller', function () {
|
||||
'0x2a5523c6fa98b47b7d9b6c8320179785150b42a16bcff36b398c5062b65657e8'
|
||||
txMeta = {
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: {},
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
}
|
||||
@ -673,7 +678,7 @@ describe('Transaction Controller', function () {
|
||||
await txController.publishTransaction(txMeta.id, rawTx)
|
||||
const publishedTx = txController.txStateManager.getTx(1)
|
||||
assert.equal(publishedTx.hash, hash)
|
||||
assert.equal(publishedTx.status, 'submitted')
|
||||
assert.equal(publishedTx.status, TRANSACTION_STATUSES.SUBMITTED)
|
||||
})
|
||||
|
||||
it('should ignore the error "Transaction Failed: known transaction" and be as usual', async function () {
|
||||
@ -689,7 +694,7 @@ describe('Transaction Controller', function () {
|
||||
publishedTx.hash,
|
||||
'0x2cc5a25744486f7383edebbf32003e5a66e18135799593d6b5cdd2bb43674f09',
|
||||
)
|
||||
assert.equal(publishedTx.status, 'submitted')
|
||||
assert.equal(publishedTx.status, TRANSACTION_STATUSES.SUBMITTED)
|
||||
})
|
||||
})
|
||||
|
||||
@ -698,49 +703,49 @@ describe('Transaction Controller', function () {
|
||||
txController.txStateManager._saveTxList([
|
||||
{
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
txParams: { nonce: '0x01' },
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
txParams: { nonce: '0x01' },
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
txParams: { nonce: '0x01' },
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
txParams: { nonce: '0x01' },
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
txParams: { nonce: '0x01' },
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
txParams: { nonce: '0x01' },
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
history: [{}],
|
||||
txParams: { nonce: '0x01' },
|
||||
@ -750,11 +755,11 @@ describe('Transaction Controller', function () {
|
||||
const confirmedTx = txController.txStateManager.getTx(1)
|
||||
const droppedTxs = txController.txStateManager.getFilteredTxList({
|
||||
nonce: '0x01',
|
||||
status: 'dropped',
|
||||
status: TRANSACTION_STATUSES.DROPPED,
|
||||
})
|
||||
assert.equal(
|
||||
confirmedTx.status,
|
||||
'confirmed',
|
||||
TRANSACTION_STATUSES.CONFIRMED,
|
||||
'the confirmedTx should remain confirmed',
|
||||
)
|
||||
assert.equal(droppedTxs.length, 6, 'their should be 6 dropped txs')
|
||||
@ -914,48 +919,48 @@ describe('Transaction Controller', function () {
|
||||
txController.txStateManager._saveTxList([
|
||||
{
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
status: 'rejected',
|
||||
status: TRANSACTION_STATUSES.REJECTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
status: 'signed',
|
||||
status: TRANSACTION_STATUSES.SIGNED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
status: 'failed',
|
||||
status: TRANSACTION_STATUSES.FAILED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
history: [{}],
|
||||
@ -969,8 +974,14 @@ describe('Transaction Controller', function () {
|
||||
const states = txController.pendingTxTracker
|
||||
.getPendingTransactions()
|
||||
.map((tx) => tx.status)
|
||||
assert.ok(states.includes('approved'), 'includes approved')
|
||||
assert.ok(states.includes('submitted'), 'includes submitted')
|
||||
assert.ok(
|
||||
states.includes(TRANSACTION_STATUSES.APPROVED),
|
||||
'includes approved',
|
||||
)
|
||||
assert.ok(
|
||||
states.includes(TRANSACTION_STATUSES.SUBMITTED),
|
||||
'includes submitted',
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -2,6 +2,7 @@ import { strict as assert } from 'assert'
|
||||
import sinon from 'sinon'
|
||||
import TxStateManager from '../../../../../app/scripts/controllers/transactions/tx-state-manager'
|
||||
import { snapshotFromTxMeta } from '../../../../../app/scripts/controllers/transactions/lib/tx-state-history-helpers'
|
||||
import { TRANSACTION_STATUSES } from '../../../../../shared/constants/transaction'
|
||||
|
||||
const noop = () => true
|
||||
|
||||
@ -24,7 +25,7 @@ describe('TransactionStateManager', function () {
|
||||
it('sets the tx status to signed', function () {
|
||||
const tx = {
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
@ -33,13 +34,13 @@ describe('TransactionStateManager', function () {
|
||||
const result = txStateManager.getTxList()
|
||||
assert.ok(Array.isArray(result))
|
||||
assert.equal(result.length, 1)
|
||||
assert.equal(result[0].status, 'signed')
|
||||
assert.equal(result[0].status, TRANSACTION_STATUSES.SIGNED)
|
||||
})
|
||||
|
||||
it('should emit a signed event to signal the execution of callback', function () {
|
||||
const tx = {
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
@ -60,7 +61,7 @@ describe('TransactionStateManager', function () {
|
||||
it('sets the tx status to rejected and removes it from history', function () {
|
||||
const tx = {
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
@ -74,7 +75,7 @@ describe('TransactionStateManager', function () {
|
||||
it('should emit a rejected event to signal the execution of callback', function () {
|
||||
const tx = {
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
@ -116,7 +117,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x0',
|
||||
},
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
}
|
||||
|
||||
const confirmedTx = {
|
||||
@ -128,7 +129,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x3',
|
||||
},
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
}
|
||||
|
||||
const txm = new TxStateManager({
|
||||
@ -151,7 +152,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x0',
|
||||
},
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
}
|
||||
|
||||
const unapprovedTx1 = {
|
||||
@ -163,7 +164,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x1',
|
||||
},
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
}
|
||||
|
||||
const approvedTx2 = {
|
||||
@ -175,7 +176,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x2',
|
||||
},
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
}
|
||||
|
||||
const confirmedTx3 = {
|
||||
@ -187,7 +188,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x3',
|
||||
},
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
}
|
||||
|
||||
const txm = new TxStateManager({
|
||||
@ -216,7 +217,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x0',
|
||||
},
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
},
|
||||
{
|
||||
id: 0,
|
||||
@ -227,7 +228,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x0',
|
||||
},
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
},
|
||||
]
|
||||
|
||||
@ -240,7 +241,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x1',
|
||||
},
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
}
|
||||
|
||||
const approvedTx2s = [
|
||||
@ -253,7 +254,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x2',
|
||||
},
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
@ -264,7 +265,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x2',
|
||||
},
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
},
|
||||
]
|
||||
|
||||
@ -278,7 +279,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x3',
|
||||
},
|
||||
status: 'failed',
|
||||
status: TRANSACTION_STATUSES.FAILED,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
@ -289,7 +290,7 @@ describe('TransactionStateManager', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x3',
|
||||
},
|
||||
status: 'failed',
|
||||
status: TRANSACTION_STATUSES.FAILED,
|
||||
},
|
||||
]
|
||||
|
||||
@ -313,7 +314,7 @@ describe('TransactionStateManager', function () {
|
||||
it('adds a tx returned in getTxList', function () {
|
||||
const tx = {
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
@ -340,7 +341,7 @@ describe('TransactionStateManager', function () {
|
||||
for (const value of invalidValues) {
|
||||
const tx = {
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {
|
||||
...validTxParams,
|
||||
@ -361,13 +362,13 @@ describe('TransactionStateManager', function () {
|
||||
it('does not override txs from other networks', function () {
|
||||
const tx = {
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
const tx2 = {
|
||||
id: 2,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: otherNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
@ -385,7 +386,7 @@ describe('TransactionStateManager', function () {
|
||||
const tx = {
|
||||
id: i,
|
||||
time: new Date(),
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
@ -402,7 +403,7 @@ describe('TransactionStateManager', function () {
|
||||
const tx = {
|
||||
id: i,
|
||||
time: new Date(),
|
||||
status: 'rejected',
|
||||
status: TRANSACTION_STATUSES.REJECTED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
@ -417,7 +418,7 @@ describe('TransactionStateManager', function () {
|
||||
const unconfirmedTx = {
|
||||
id: 0,
|
||||
time: new Date(),
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
@ -427,7 +428,7 @@ describe('TransactionStateManager', function () {
|
||||
const tx = {
|
||||
id: i,
|
||||
time: new Date(),
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
}
|
||||
@ -438,7 +439,7 @@ describe('TransactionStateManager', function () {
|
||||
assert.equal(result[0].id, 0, 'first tx should still be there')
|
||||
assert.equal(
|
||||
result[0].status,
|
||||
'unapproved',
|
||||
TRANSACTION_STATUSES.UNAPPROVED,
|
||||
'first tx should be unapproved',
|
||||
)
|
||||
assert.equal(result[1].id, 2, 'early txs truncated')
|
||||
@ -450,7 +451,7 @@ describe('TransactionStateManager', function () {
|
||||
txStateManager.addTx(
|
||||
{
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
},
|
||||
@ -459,7 +460,7 @@ describe('TransactionStateManager', function () {
|
||||
txStateManager.addTx(
|
||||
{
|
||||
id: '2',
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
},
|
||||
@ -486,7 +487,7 @@ describe('TransactionStateManager', function () {
|
||||
|
||||
txStateManager.addTx({
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: validTxParams,
|
||||
})
|
||||
@ -517,7 +518,7 @@ describe('TransactionStateManager', function () {
|
||||
|
||||
const txMeta = {
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {
|
||||
gasPrice: originalGasPrice,
|
||||
@ -591,7 +592,7 @@ describe('TransactionStateManager', function () {
|
||||
it('does NOT add empty history items', function () {
|
||||
const txMeta = {
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {
|
||||
gasPrice: '0x01',
|
||||
@ -611,7 +612,7 @@ describe('TransactionStateManager', function () {
|
||||
txStateManager.addTx(
|
||||
{
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
},
|
||||
@ -620,7 +621,7 @@ describe('TransactionStateManager', function () {
|
||||
txStateManager.addTx(
|
||||
{
|
||||
id: '2',
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
},
|
||||
@ -628,7 +629,7 @@ describe('TransactionStateManager', function () {
|
||||
)
|
||||
const result = txStateManager.getUnapprovedTxList()
|
||||
assert.equal(typeof result, 'object')
|
||||
assert.equal(result['1'].status, 'unapproved')
|
||||
assert.equal(result['1'].status, TRANSACTION_STATUSES.UNAPPROVED)
|
||||
assert.equal(result['2'], undefined)
|
||||
})
|
||||
})
|
||||
@ -638,7 +639,7 @@ describe('TransactionStateManager', function () {
|
||||
txStateManager.addTx(
|
||||
{
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
},
|
||||
@ -647,14 +648,20 @@ describe('TransactionStateManager', function () {
|
||||
txStateManager.addTx(
|
||||
{
|
||||
id: '2',
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams: {},
|
||||
},
|
||||
noop,
|
||||
)
|
||||
assert.equal(txStateManager.getTx('1').status, 'unapproved')
|
||||
assert.equal(txStateManager.getTx('2').status, 'confirmed')
|
||||
assert.equal(
|
||||
txStateManager.getTx('1').status,
|
||||
TRANSACTION_STATUSES.UNAPPROVED,
|
||||
)
|
||||
assert.equal(
|
||||
txStateManager.getTx('2').status,
|
||||
TRANSACTION_STATUSES.CONFIRMED,
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@ -663,61 +670,61 @@ describe('TransactionStateManager', function () {
|
||||
const txMetas = [
|
||||
{
|
||||
id: 0,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: { from: '0xaa', to: '0xbb' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: { from: '0xaa', to: '0xbb' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: { from: '0xaa', to: '0xbb' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: { from: '0xbb', to: '0xaa' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: { from: '0xbb', to: '0xaa' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: { from: '0xaa', to: '0xbb' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: { from: '0xaa', to: '0xbb' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: { from: '0xbb', to: '0xaa' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: { from: '0xbb', to: '0xaa' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: { from: '0xbb', to: '0xaa' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
@ -725,25 +732,25 @@ describe('TransactionStateManager', function () {
|
||||
txMetas.forEach((txMeta) => txStateManager.addTx(txMeta, noop))
|
||||
let filterParams
|
||||
|
||||
filterParams = { status: 'unapproved', from: '0xaa' }
|
||||
filterParams = { status: TRANSACTION_STATUSES.UNAPPROVED, from: '0xaa' }
|
||||
assert.equal(
|
||||
txStateManager.getFilteredTxList(filterParams).length,
|
||||
3,
|
||||
`getFilteredTxList - ${JSON.stringify(filterParams)}`,
|
||||
)
|
||||
filterParams = { status: 'unapproved', to: '0xaa' }
|
||||
filterParams = { status: TRANSACTION_STATUSES.UNAPPROVED, to: '0xaa' }
|
||||
assert.equal(
|
||||
txStateManager.getFilteredTxList(filterParams).length,
|
||||
2,
|
||||
`getFilteredTxList - ${JSON.stringify(filterParams)}`,
|
||||
)
|
||||
filterParams = { status: 'confirmed', from: '0xbb' }
|
||||
filterParams = { status: TRANSACTION_STATUSES.CONFIRMED, from: '0xbb' }
|
||||
assert.equal(
|
||||
txStateManager.getFilteredTxList(filterParams).length,
|
||||
3,
|
||||
`getFilteredTxList - ${JSON.stringify(filterParams)}`,
|
||||
)
|
||||
filterParams = { status: 'confirmed' }
|
||||
filterParams = { status: TRANSACTION_STATUSES.CONFIRMED }
|
||||
assert.equal(
|
||||
txStateManager.getFilteredTxList(filterParams).length,
|
||||
5,
|
||||
@ -761,7 +768,9 @@ describe('TransactionStateManager', function () {
|
||||
5,
|
||||
`getFilteredTxList - ${JSON.stringify(filterParams)}`,
|
||||
)
|
||||
filterParams = { status: (status) => status !== 'confirmed' }
|
||||
filterParams = {
|
||||
status: (status) => status !== TRANSACTION_STATUSES.CONFIRMED,
|
||||
}
|
||||
assert.equal(
|
||||
txStateManager.getFilteredTxList(filterParams).length,
|
||||
5,
|
||||
@ -778,19 +787,19 @@ describe('TransactionStateManager', function () {
|
||||
const txMetas = [
|
||||
{
|
||||
id: 0,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: { from: specificAddress, to: otherAddress },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: { from: otherAddress, to: specificAddress },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: { from: otherAddress, to: specificAddress },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
@ -814,19 +823,19 @@ describe('TransactionStateManager', function () {
|
||||
const txMetas = [
|
||||
{
|
||||
id: 0,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: { from: specificAddress, to: otherAddress },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: { from: specificAddress, to: otherAddress },
|
||||
metamaskNetworkId: otherNetworkId,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: { from: specificAddress, to: otherAddress },
|
||||
metamaskNetworkId: otherNetworkId,
|
||||
},
|
||||
@ -874,25 +883,25 @@ describe('TransactionStateManager', function () {
|
||||
const txMetas = [
|
||||
{
|
||||
id: 0,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: { from: '0xaa', to: '0xbb' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
txParams: { from: '0xaa', to: '0xbb' },
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: { from: '0xaa', to: '0xbb' },
|
||||
metamaskNetworkId: otherNetworkId,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: { from: '0xaa', to: '0xbb' },
|
||||
metamaskNetworkId: otherNetworkId,
|
||||
},
|
||||
@ -904,7 +913,7 @@ describe('TransactionStateManager', function () {
|
||||
|
||||
const unapprovedTxList = txStateManager
|
||||
.getFullTxList()
|
||||
.filter((tx) => tx.status === 'unapproved')
|
||||
.filter((tx) => tx.status === TRANSACTION_STATUSES.UNAPPROVED)
|
||||
|
||||
assert.equal(unapprovedTxList.length, 0)
|
||||
})
|
||||
|
@ -1,5 +1,6 @@
|
||||
import assert from 'assert'
|
||||
import MessageManager from '../../../app/scripts/lib/message-manager'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
describe('Message Manager', function () {
|
||||
let messageManager
|
||||
@ -18,7 +19,11 @@ describe('Message Manager', function () {
|
||||
|
||||
describe('#addMsg', function () {
|
||||
it('adds a Msg returned in getMsgList', function () {
|
||||
const Msg = { id: 1, status: 'approved', metamaskNetworkId: 'unit test' }
|
||||
const Msg = {
|
||||
id: 1,
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
}
|
||||
messageManager.addMsg(Msg)
|
||||
const result = messageManager.messages
|
||||
assert.ok(Array.isArray(result))
|
||||
@ -39,7 +44,7 @@ describe('Message Manager', function () {
|
||||
const result = messageManager.messages
|
||||
assert.ok(Array.isArray(result))
|
||||
assert.equal(result.length, 1)
|
||||
assert.equal(result[0].status, 'approved')
|
||||
assert.equal(result[0].status, TRANSACTION_STATUSES.APPROVED)
|
||||
})
|
||||
})
|
||||
|
||||
@ -55,7 +60,7 @@ describe('Message Manager', function () {
|
||||
const result = messageManager.messages
|
||||
assert.ok(Array.isArray(result))
|
||||
assert.equal(result.length, 1)
|
||||
assert.equal(result[0].status, 'rejected')
|
||||
assert.equal(result[0].status, TRANSACTION_STATUSES.REJECTED)
|
||||
})
|
||||
})
|
||||
|
||||
@ -68,7 +73,7 @@ describe('Message Manager', function () {
|
||||
})
|
||||
messageManager.addMsg({
|
||||
id: '2',
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
})
|
||||
messageManager._updateMsg({
|
||||
@ -91,7 +96,7 @@ describe('Message Manager', function () {
|
||||
})
|
||||
messageManager.addMsg({
|
||||
id: '2',
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
})
|
||||
const result = messageManager.getUnapprovedMsgs()
|
||||
@ -110,11 +115,14 @@ describe('Message Manager', function () {
|
||||
})
|
||||
messageManager.addMsg({
|
||||
id: '2',
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
})
|
||||
assert.equal(messageManager.getMsg('1').status, 'unapproved')
|
||||
assert.equal(messageManager.getMsg('2').status, 'approved')
|
||||
assert.equal(
|
||||
messageManager.getMsg('2').status,
|
||||
TRANSACTION_STATUSES.APPROVED,
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,5 +1,6 @@
|
||||
import assert from 'assert'
|
||||
import PersonalMessageManager from '../../../app/scripts/lib/personal-message-manager'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
describe('Personal Message Manager', function () {
|
||||
let messageManager
|
||||
@ -18,7 +19,11 @@ describe('Personal Message Manager', function () {
|
||||
|
||||
describe('#addMsg', function () {
|
||||
it('adds a Msg returned in getMsgList', function () {
|
||||
const Msg = { id: 1, status: 'approved', metamaskNetworkId: 'unit test' }
|
||||
const Msg = {
|
||||
id: 1,
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
}
|
||||
messageManager.addMsg(Msg)
|
||||
const result = messageManager.messages
|
||||
assert.ok(Array.isArray(result))
|
||||
@ -31,7 +36,7 @@ describe('Personal Message Manager', function () {
|
||||
it('sets the Msg status to approved', function () {
|
||||
const Msg = {
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
}
|
||||
messageManager.addMsg(Msg)
|
||||
@ -39,7 +44,7 @@ describe('Personal Message Manager', function () {
|
||||
const result = messageManager.messages
|
||||
assert.ok(Array.isArray(result))
|
||||
assert.equal(result.length, 1)
|
||||
assert.equal(result[0].status, 'approved')
|
||||
assert.equal(result[0].status, TRANSACTION_STATUSES.APPROVED)
|
||||
})
|
||||
})
|
||||
|
||||
@ -47,7 +52,7 @@ describe('Personal Message Manager', function () {
|
||||
it('sets the Msg status to rejected', function () {
|
||||
const Msg = {
|
||||
id: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
}
|
||||
messageManager.addMsg(Msg)
|
||||
@ -55,7 +60,7 @@ describe('Personal Message Manager', function () {
|
||||
const result = messageManager.messages
|
||||
assert.ok(Array.isArray(result))
|
||||
assert.equal(result.length, 1)
|
||||
assert.equal(result[0].status, 'rejected')
|
||||
assert.equal(result[0].status, TRANSACTION_STATUSES.REJECTED)
|
||||
})
|
||||
})
|
||||
|
||||
@ -63,12 +68,12 @@ describe('Personal Message Manager', function () {
|
||||
it('replaces the Msg with the same id', function () {
|
||||
messageManager.addMsg({
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
})
|
||||
messageManager.addMsg({
|
||||
id: '2',
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
})
|
||||
messageManager._updateMsg({
|
||||
@ -86,17 +91,17 @@ describe('Personal Message Manager', function () {
|
||||
it('returns unapproved Msgs in a hash', function () {
|
||||
messageManager.addMsg({
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
})
|
||||
messageManager.addMsg({
|
||||
id: '2',
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
})
|
||||
const result = messageManager.getUnapprovedMsgs()
|
||||
assert.equal(typeof result, 'object')
|
||||
assert.equal(result['1'].status, 'unapproved')
|
||||
assert.equal(result['1'].status, TRANSACTION_STATUSES.UNAPPROVED)
|
||||
assert.equal(result['2'], undefined)
|
||||
})
|
||||
})
|
||||
@ -105,16 +110,22 @@ describe('Personal Message Manager', function () {
|
||||
it('returns a Msg with the requested id', function () {
|
||||
messageManager.addMsg({
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
})
|
||||
messageManager.addMsg({
|
||||
id: '2',
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
metamaskNetworkId: 'unit test',
|
||||
})
|
||||
assert.equal(messageManager.getMsg('1').status, 'unapproved')
|
||||
assert.equal(messageManager.getMsg('2').status, 'approved')
|
||||
assert.equal(
|
||||
messageManager.getMsg('1').status,
|
||||
TRANSACTION_STATUSES.UNAPPROVED,
|
||||
)
|
||||
assert.equal(
|
||||
messageManager.getMsg('2').status,
|
||||
TRANSACTION_STATUSES.APPROVED,
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import assert from 'assert'
|
||||
import sinon from 'sinon'
|
||||
import TypedMessageManager from '../../../app/scripts/lib/typed-message-manager'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
describe('Typed Message Manager', function () {
|
||||
let typedMessageManager,
|
||||
@ -89,7 +90,7 @@ describe('Typed Message Manager', function () {
|
||||
})
|
||||
|
||||
it('adds to unapproved messages and sets status to unapproved', function () {
|
||||
assert.equal(typedMsgs[msgId].status, 'unapproved')
|
||||
assert.equal(typedMsgs[msgId].status, TRANSACTION_STATUSES.UNAPPROVED)
|
||||
})
|
||||
|
||||
it('validates params', function () {
|
||||
@ -106,17 +107,17 @@ describe('Typed Message Manager', function () {
|
||||
it('approves messages', async function () {
|
||||
const messageMetaMaskId = messages[0].msgParams
|
||||
typedMessageManager.approveMessage(messageMetaMaskId)
|
||||
assert.equal(messages[0].status, 'approved')
|
||||
assert.equal(messages[0].status, TRANSACTION_STATUSES.APPROVED)
|
||||
})
|
||||
|
||||
it('sets msg status to signed and adds a raw sig to message details', function () {
|
||||
typedMessageManager.setMsgStatusSigned(numberMsgId, 'raw sig')
|
||||
assert.equal(messages[0].status, 'signed')
|
||||
assert.equal(messages[0].status, TRANSACTION_STATUSES.SIGNED)
|
||||
assert.equal(messages[0].rawSig, 'raw sig')
|
||||
})
|
||||
|
||||
it('rejects message', function () {
|
||||
typedMessageManager.rejectMsg(numberMsgId)
|
||||
assert.equal(messages[0].status, 'rejected')
|
||||
assert.equal(messages[0].status, TRANSACTION_STATUSES.REJECTED)
|
||||
})
|
||||
})
|
||||
|
@ -1,5 +1,6 @@
|
||||
import assert from 'assert'
|
||||
import migration22 from '../../../app/scripts/migrations/022'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const properTime = new Date().getTime()
|
||||
const storage = {
|
||||
@ -7,9 +8,9 @@ const storage = {
|
||||
data: {
|
||||
TransactionController: {
|
||||
transactions: [
|
||||
{ status: 'submitted' },
|
||||
{ status: 'submitted', submittedTime: properTime },
|
||||
{ status: 'confirmed' },
|
||||
{ status: TRANSACTION_STATUSES.SUBMITTED },
|
||||
{ status: TRANSACTION_STATUSES.SUBMITTED, submittedTime: properTime },
|
||||
{ status: TRANSACTION_STATUSES.CONFIRMED },
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -1,5 +1,6 @@
|
||||
import assert from 'assert'
|
||||
import migration23 from '../../../app/scripts/migrations/023'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const storage = {
|
||||
meta: {},
|
||||
@ -14,18 +15,14 @@ const transactions = []
|
||||
const transactions40 = []
|
||||
const transactions20 = []
|
||||
|
||||
const txStates = [
|
||||
'unapproved',
|
||||
'approved',
|
||||
'signed',
|
||||
'submitted',
|
||||
'confirmed',
|
||||
'rejected',
|
||||
'failed',
|
||||
'dropped',
|
||||
]
|
||||
const txStates = Object.values(TRANSACTION_STATUSES)
|
||||
|
||||
const deletableTxStates = ['confirmed', 'rejected', 'failed', 'dropped']
|
||||
const deletableTxStates = [
|
||||
TRANSACTION_STATUSES.CONFIRMED,
|
||||
TRANSACTION_STATUSES.REJECTED,
|
||||
TRANSACTION_STATUSES.FAILED,
|
||||
TRANSACTION_STATUSES.DROPPED,
|
||||
]
|
||||
|
||||
let nonDeletableCount = 0
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import assert from 'assert'
|
||||
import migration24 from '../../../app/scripts/migrations/024'
|
||||
import data from '../../../app/scripts/first-time-state'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const firstTimeState = {
|
||||
meta: {},
|
||||
@ -20,11 +21,11 @@ const transactions = []
|
||||
while (transactions.length <= 10) {
|
||||
transactions.push({
|
||||
txParams: { from: '0x8aCce2391c0d510a6c5E5d8f819a678f79b7e675' },
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
})
|
||||
transactions.push({
|
||||
txParams: { from: '0x8aCce2391c0d510a6c5E5d8f819a678f79b7e675' },
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
})
|
||||
}
|
||||
|
||||
@ -38,7 +39,7 @@ describe('storage is migrated successfully and the txParams.from are lowercase',
|
||||
const migratedTransactions =
|
||||
migratedData.data.TransactionController.transactions
|
||||
migratedTransactions.forEach((tx) => {
|
||||
if (tx.status === 'unapproved') {
|
||||
if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) {
|
||||
assert.equal(
|
||||
tx.txParams.from,
|
||||
'0x8acce2391c0d510a6c5e5d8f819a678f79b7e675',
|
||||
|
@ -1,6 +1,7 @@
|
||||
import assert from 'assert'
|
||||
import migration25 from '../../../app/scripts/migrations/025'
|
||||
import data from '../../../app/scripts/first-time-state'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const firstTimeState = {
|
||||
meta: {},
|
||||
@ -25,11 +26,11 @@ while (transactions.length <= 10) {
|
||||
random: 'stuff',
|
||||
chainId: 2,
|
||||
},
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
})
|
||||
transactions.push({
|
||||
txParams: { from: '0x8aCce2391c0d510a6c5E5d8f819a678f79b7e675' },
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
})
|
||||
}
|
||||
|
||||
@ -43,10 +44,10 @@ describe('storage is migrated successfully and the txParams.from are lowercase',
|
||||
const migratedTransactions =
|
||||
migratedData.data.TransactionController.transactions
|
||||
migratedTransactions.forEach((tx) => {
|
||||
if (tx.status === 'unapproved') {
|
||||
if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) {
|
||||
assert(!tx.txParams.random)
|
||||
}
|
||||
if (tx.status === 'unapproved') {
|
||||
if (tx.status === TRANSACTION_STATUSES.UNAPPROVED) {
|
||||
assert(!tx.txParams.chainId)
|
||||
}
|
||||
})
|
||||
|
@ -1,6 +1,7 @@
|
||||
import assert from 'assert'
|
||||
import firstTimeState from '../../../app/scripts/first-time-state'
|
||||
import migration27 from '../../../app/scripts/migrations/027'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const oldStorage = {
|
||||
meta: {},
|
||||
@ -14,9 +15,9 @@ const oldStorage = {
|
||||
const transactions = []
|
||||
|
||||
while (transactions.length < 9) {
|
||||
transactions.push({ status: 'rejected' })
|
||||
transactions.push({ status: 'unapproved' })
|
||||
transactions.push({ status: 'approved' })
|
||||
transactions.push({ status: TRANSACTION_STATUSES.REJECTED })
|
||||
transactions.push({ status: TRANSACTION_STATUSES.UNAPPROVED })
|
||||
transactions.push({ status: TRANSACTION_STATUSES.APPROVED })
|
||||
}
|
||||
|
||||
oldStorage.data.TransactionController.transactions = transactions
|
||||
@ -34,7 +35,7 @@ describe('migration #27', function () {
|
||||
'transactions is expected to have the length of 6',
|
||||
)
|
||||
newTransactions.forEach((txMeta) => {
|
||||
if (txMeta.status === 'rejected') {
|
||||
if (txMeta.status === TRANSACTION_STATUSES.REJECTED) {
|
||||
done(new Error('transaction was found with a status of rejected'))
|
||||
}
|
||||
})
|
||||
|
@ -1,5 +1,6 @@
|
||||
import assert from 'assert'
|
||||
import migration29 from '../../../app/scripts/migrations/029'
|
||||
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'
|
||||
|
||||
const properTime = new Date().getTime()
|
||||
const storage = {
|
||||
@ -7,11 +8,23 @@ const storage = {
|
||||
data: {
|
||||
TransactionController: {
|
||||
transactions: [
|
||||
{ status: 'approved', id: 1, submittedTime: 0 },
|
||||
{ status: 'approved', id: 2, submittedTime: properTime },
|
||||
{ status: 'confirmed', id: 3, submittedTime: properTime },
|
||||
{ status: 'submitted', id: 4, submittedTime: properTime },
|
||||
{ status: 'submitted', id: 5, submittedTime: 0 },
|
||||
{ status: TRANSACTION_STATUSES.APPROVED, id: 1, submittedTime: 0 },
|
||||
{
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
id: 2,
|
||||
submittedTime: properTime,
|
||||
},
|
||||
{
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
id: 3,
|
||||
submittedTime: properTime,
|
||||
},
|
||||
{
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
id: 4,
|
||||
submittedTime: properTime,
|
||||
},
|
||||
{ status: TRANSACTION_STATUSES.SUBMITTED, id: 5, submittedTime: 0 },
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -26,7 +39,11 @@ describe('storage is migrated successfully where transactions that are submitted
|
||||
const [txMeta1] = txs
|
||||
assert.equal(migratedData.meta.version, 29)
|
||||
|
||||
assert.equal(txMeta1.status, 'failed', 'old tx is auto failed')
|
||||
assert.equal(
|
||||
txMeta1.status,
|
||||
TRANSACTION_STATUSES.FAILED,
|
||||
'old tx is auto failed',
|
||||
)
|
||||
assert(
|
||||
txMeta1.err.message.includes('too long'),
|
||||
'error message assigned',
|
||||
@ -36,7 +53,11 @@ describe('storage is migrated successfully where transactions that are submitted
|
||||
if (tx.id === 1) {
|
||||
return
|
||||
}
|
||||
assert.notEqual(tx.status, 'failed', 'other tx is not auto failed')
|
||||
assert.notEqual(
|
||||
tx.status,
|
||||
TRANSACTION_STATUSES.FAILED,
|
||||
'other tx is not auto failed',
|
||||
)
|
||||
})
|
||||
|
||||
done()
|
||||
|
@ -11,6 +11,7 @@ import enLocale from '../../../../app/_locales/en/messages.json'
|
||||
import * as actions from '../../../../ui/app/store/actions'
|
||||
import MetaMaskController from '../../../../app/scripts/metamask-controller'
|
||||
import firstTimeState from '../../localhostState'
|
||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
||||
|
||||
const { provider } = createTestProviderTools({ scaffold: {} })
|
||||
const middleware = [thunk]
|
||||
@ -891,7 +892,7 @@ describe('Actions', function () {
|
||||
|
||||
const txData = {
|
||||
id: '1',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: currentNetworkId,
|
||||
txParams,
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ import {
|
||||
} from '../../../../pages/send/send.utils'
|
||||
import { MIN_GAS_LIMIT_DEC } from '../../../../pages/send/send.constants'
|
||||
import { calcMaxAmount } from '../../../../pages/send/send-content/send-amount-row/amount-max-button/amount-max-button.utils'
|
||||
import { TRANSACTION_STATUSES } from '../../../../../../shared/constants/transaction'
|
||||
import GasModalPageContainer from './gas-modal-page-container.component'
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
@ -193,8 +194,8 @@ const mapStateToProps = (state, ownProps) => {
|
||||
sendAmount,
|
||||
},
|
||||
transaction: txData || transaction,
|
||||
isSpeedUp: transaction.status === 'submitted',
|
||||
isRetry: transaction.status === 'failed',
|
||||
isSpeedUp: transaction.status === TRANSACTION_STATUSES.SUBMITTED,
|
||||
isRetry: transaction.status === TRANSACTION_STATUSES.FAILED,
|
||||
txId: transaction.id,
|
||||
insufficientBalance,
|
||||
gasEstimatesLoading,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import assert from 'assert'
|
||||
import proxyquire from 'proxyquire'
|
||||
import sinon from 'sinon'
|
||||
import { TRANSACTION_STATUSES } from '../../../../../../../shared/constants/transaction'
|
||||
|
||||
let mapStateToProps
|
||||
let mapDispatchToProps
|
||||
@ -195,7 +196,7 @@ describe('gas-modal-page-container container', function () {
|
||||
mockState: baseMockState,
|
||||
mockOwnProps: {
|
||||
...baseMockOwnProps,
|
||||
transaction: { id: 34, status: 'submitted' },
|
||||
transaction: { id: 34, status: TRANSACTION_STATUSES.SUBMITTED },
|
||||
},
|
||||
expectedResult: {
|
||||
...baseExpectedResult,
|
||||
|
@ -1,4 +1,8 @@
|
||||
import assert from 'assert'
|
||||
import {
|
||||
TRANSACTION_STATUSES,
|
||||
TRANSACTION_TYPES,
|
||||
} from '../../../../../../shared/constants/transaction'
|
||||
import {
|
||||
combineTransactionHistories,
|
||||
getActivities,
|
||||
@ -19,7 +23,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
{
|
||||
id: 6400627574331058,
|
||||
time: 1543958845581,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: '3',
|
||||
loadingDefaults: true,
|
||||
txParams: {
|
||||
@ -29,13 +33,13 @@ describe('TransactionActivityLog utils', function () {
|
||||
gas: '0x5208',
|
||||
gasPrice: '0x3b9aca00',
|
||||
},
|
||||
type: 'standard',
|
||||
type: TRANSACTION_TYPES.STANDARD,
|
||||
},
|
||||
[
|
||||
{
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
value: 'approved',
|
||||
value: TRANSACTION_STATUSES.APPROVED,
|
||||
note: 'txStateManager: setting status to approved',
|
||||
timestamp: 1543958847813,
|
||||
},
|
||||
@ -44,7 +48,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
{
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
value: 'submitted',
|
||||
value: TRANSACTION_STATUSES.SUBMITTED,
|
||||
note: 'txStateManager: setting status to submitted',
|
||||
timestamp: 1543958848147,
|
||||
},
|
||||
@ -53,7 +57,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
{
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
value: 'dropped',
|
||||
value: TRANSACTION_STATUSES.DROPPED,
|
||||
note: 'txStateManager: setting status to dropped',
|
||||
timestamp: 1543958897181,
|
||||
},
|
||||
@ -68,7 +72,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
id: 6400627574331058,
|
||||
loadingDefaults: false,
|
||||
metamaskNetworkId: '3',
|
||||
status: 'dropped',
|
||||
status: TRANSACTION_STATUSES.DROPPED,
|
||||
submittedTime: 1543958848135,
|
||||
time: 1543958845581,
|
||||
txParams: {
|
||||
@ -79,7 +83,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
to: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
||||
value: '0x2386f26fc10000',
|
||||
},
|
||||
type: 'standard',
|
||||
type: TRANSACTION_TYPES.STANDARD,
|
||||
},
|
||||
{
|
||||
hash:
|
||||
@ -88,7 +92,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
{
|
||||
id: 6400627574331060,
|
||||
time: 1543958857697,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
metamaskNetworkId: '3',
|
||||
loadingDefaults: false,
|
||||
txParams: {
|
||||
@ -100,7 +104,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
nonce: '0x32',
|
||||
},
|
||||
lastGasPrice: '0x4190ab00',
|
||||
type: 'retry',
|
||||
type: TRANSACTION_TYPES.RETRY,
|
||||
},
|
||||
[
|
||||
{
|
||||
@ -115,7 +119,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
{
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
value: 'approved',
|
||||
value: TRANSACTION_STATUSES.APPROVED,
|
||||
note: 'txStateManager: setting status to approved',
|
||||
timestamp: 1543958859485,
|
||||
},
|
||||
@ -124,7 +128,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
{
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
value: 'signed',
|
||||
value: TRANSACTION_STATUSES.SIGNED,
|
||||
note: 'transactions#publishTransaction',
|
||||
timestamp: 1543958859889,
|
||||
},
|
||||
@ -133,7 +137,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
{
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
value: 'submitted',
|
||||
value: TRANSACTION_STATUSES.SUBMITTED,
|
||||
note: 'txStateManager: setting status to submitted',
|
||||
timestamp: 1543958860061,
|
||||
},
|
||||
@ -151,7 +155,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
{
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
value: 'confirmed',
|
||||
value: TRANSACTION_STATUSES.CONFIRMED,
|
||||
timestamp: 1543958897165,
|
||||
},
|
||||
],
|
||||
@ -160,7 +164,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
lastGasPrice: '0x4190ab00',
|
||||
loadingDefaults: false,
|
||||
metamaskNetworkId: '3',
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
submittedTime: 1543958860054,
|
||||
time: 1543958857697,
|
||||
txParams: {
|
||||
@ -174,7 +178,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
txReceipt: {
|
||||
status: '0x1',
|
||||
},
|
||||
type: 'retry',
|
||||
type: TRANSACTION_TYPES.RETRY,
|
||||
},
|
||||
]
|
||||
|
||||
@ -222,7 +226,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
const transaction = {
|
||||
history: [],
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: {
|
||||
from: '0x1',
|
||||
gas: '0x5208',
|
||||
@ -243,7 +247,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
id: 5559712943815343,
|
||||
loadingDefaults: true,
|
||||
metamaskNetworkId: '3',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
time: 1535507561452,
|
||||
txParams: {
|
||||
from: '0x1',
|
||||
@ -287,7 +291,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
timestamp: 1535507564302,
|
||||
value: 'approved',
|
||||
value: TRANSACTION_STATUSES.APPROVED,
|
||||
},
|
||||
],
|
||||
[
|
||||
@ -314,7 +318,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
timestamp: 1535507564518,
|
||||
value: 'signed',
|
||||
value: TRANSACTION_STATUSES.SIGNED,
|
||||
},
|
||||
{
|
||||
op: 'add',
|
||||
@ -349,7 +353,7 @@ describe('TransactionActivityLog utils', function () {
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
timestamp: 1535507564665,
|
||||
value: 'submitted',
|
||||
value: TRANSACTION_STATUSES.SUBMITTED,
|
||||
},
|
||||
],
|
||||
[
|
||||
@ -367,12 +371,12 @@ describe('TransactionActivityLog utils', function () {
|
||||
op: 'replace',
|
||||
path: '/status',
|
||||
timestamp: 1535507615993,
|
||||
value: 'confirmed',
|
||||
value: TRANSACTION_STATUSES.CONFIRMED,
|
||||
},
|
||||
],
|
||||
],
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: {
|
||||
from: '0x1',
|
||||
gas: '0x5208',
|
||||
|
@ -2,13 +2,14 @@ import assert from 'assert'
|
||||
import React from 'react'
|
||||
import { shallow } from 'enzyme'
|
||||
import TransactionBreakdown from '../transaction-breakdown.component'
|
||||
import { TRANSACTION_STATUSES } from '../../../../../../shared/constants/transaction'
|
||||
|
||||
describe('TransactionBreakdown Component', function () {
|
||||
it('should render properly', function () {
|
||||
const transaction = {
|
||||
history: [],
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: {
|
||||
from: '0x1',
|
||||
gas: '0x5208',
|
||||
|
@ -6,13 +6,14 @@ import Button from '../../../ui/button'
|
||||
import SenderToRecipient from '../../../ui/sender-to-recipient'
|
||||
import TransactionBreakdown from '../../transaction-breakdown'
|
||||
import TransactionActivityLog from '../../transaction-activity-log'
|
||||
import { TRANSACTION_STATUSES } from '../../../../../../shared/constants/transaction'
|
||||
|
||||
describe('TransactionListItemDetails Component', function () {
|
||||
it('should render properly', function () {
|
||||
const transaction = {
|
||||
history: [],
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: {
|
||||
from: '0x1',
|
||||
gas: '0x5208',
|
||||
@ -53,7 +54,7 @@ describe('TransactionListItemDetails Component', function () {
|
||||
const transaction = {
|
||||
history: [],
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: {
|
||||
from: '0x1',
|
||||
gas: '0x5208',
|
||||
@ -96,7 +97,7 @@ describe('TransactionListItemDetails Component', function () {
|
||||
const transaction = {
|
||||
history: [],
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txParams: {
|
||||
from: '0x1',
|
||||
gas: '0x5208',
|
||||
@ -137,7 +138,7 @@ describe('TransactionListItemDetails Component', function () {
|
||||
const transaction = {
|
||||
history: [],
|
||||
id: 1,
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
hash: '0xaa',
|
||||
txParams: {
|
||||
from: '0x1',
|
||||
|
@ -10,7 +10,6 @@ import {
|
||||
} from '../../../../../shared/constants/transaction'
|
||||
|
||||
const QUEUED_PSEUDO_STATUS = 'queued'
|
||||
const PENDING_PSEUDO_STATUS = 'pending'
|
||||
|
||||
/**
|
||||
* A note about status logic for this component:
|
||||
@ -23,9 +22,9 @@ const PENDING_PSEUDO_STATUS = 'pending'
|
||||
* status label will be the date the transaction was finalized.
|
||||
*/
|
||||
const pendingStatusHash = {
|
||||
[TRANSACTION_STATUSES.SUBMITTED]: PENDING_PSEUDO_STATUS,
|
||||
[TRANSACTION_STATUSES.APPROVED]: PENDING_PSEUDO_STATUS,
|
||||
[TRANSACTION_STATUSES.SIGNED]: PENDING_PSEUDO_STATUS,
|
||||
[TRANSACTION_STATUSES.SUBMITTED]: TRANSACTION_GROUP_STATUSES.PENDING,
|
||||
[TRANSACTION_STATUSES.APPROVED]: TRANSACTION_GROUP_STATUSES.PENDING,
|
||||
[TRANSACTION_STATUSES.SIGNED]: TRANSACTION_GROUP_STATUSES.PENDING,
|
||||
}
|
||||
|
||||
const statusToClassNameHash = {
|
||||
@ -35,7 +34,7 @@ const statusToClassNameHash = {
|
||||
[TRANSACTION_STATUSES.DROPPED]: 'transaction-status--dropped',
|
||||
[TRANSACTION_GROUP_STATUSES.CANCELLED]: 'transaction-status--cancelled',
|
||||
[QUEUED_PSEUDO_STATUS]: 'transaction-status--queued',
|
||||
[PENDING_PSEUDO_STATUS]: 'transaction-status--pending',
|
||||
[TRANSACTION_GROUP_STATUSES.PENDING]: 'transaction-status--pending',
|
||||
}
|
||||
|
||||
export default function TransactionStatus({
|
||||
@ -49,7 +48,9 @@ export default function TransactionStatus({
|
||||
const tooltipText = error?.rpc?.message || error?.message
|
||||
let statusKey = status
|
||||
if (pendingStatusHash[status]) {
|
||||
statusKey = isEarliestNonce ? PENDING_PSEUDO_STATUS : QUEUED_PSEUDO_STATUS
|
||||
statusKey = isEarliestNonce
|
||||
? TRANSACTION_GROUP_STATUSES.PENDING
|
||||
: QUEUED_PSEUDO_STATUS
|
||||
}
|
||||
|
||||
const statusText =
|
||||
|
@ -2,6 +2,10 @@ import assert from 'assert'
|
||||
import configureMockStore from 'redux-mock-store'
|
||||
import thunk from 'redux-thunk'
|
||||
import sinon from 'sinon'
|
||||
import {
|
||||
TRANSACTION_CATEGORIES,
|
||||
TRANSACTION_STATUSES,
|
||||
} from '../../../../shared/constants/transaction'
|
||||
|
||||
import ConfirmTransactionReducer, * as actions from './confirm-transaction.duck'
|
||||
|
||||
@ -58,7 +62,7 @@ describe('Confirm Transaction Duck', function () {
|
||||
name: 'abcToken',
|
||||
},
|
||||
methodData: {
|
||||
name: 'approve',
|
||||
name: TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE,
|
||||
},
|
||||
tokenProps: {
|
||||
tokenDecimals: '3',
|
||||
@ -503,7 +507,7 @@ describe('Confirm Transaction Duck', function () {
|
||||
loadingDefaults: false,
|
||||
metamaskNetworkId: '3',
|
||||
origin: 'faucet.metamask.io',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
time: 1530838113716,
|
||||
},
|
||||
},
|
||||
@ -537,7 +541,7 @@ describe('Confirm Transaction Duck', function () {
|
||||
loadingDefaults: false,
|
||||
metamaskNetworkId: '3',
|
||||
origin: 'faucet.metamask.io',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
time: 1530838113716,
|
||||
txParams: {
|
||||
from: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
||||
@ -609,7 +613,7 @@ describe('Confirm Transaction Duck', function () {
|
||||
loadingDefaults: false,
|
||||
metamaskNetworkId: '3',
|
||||
origin: 'faucet.metamask.io',
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
time: 1530838113716,
|
||||
txParams: {
|
||||
from: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
||||
|
@ -6,6 +6,7 @@ import { addHexPrefix } from '../../../../app/scripts/lib/util'
|
||||
import { getEtherscanNetworkPrefix } from '../../../lib/etherscan-prefix-for-network'
|
||||
import {
|
||||
TRANSACTION_CATEGORIES,
|
||||
TRANSACTION_GROUP_STATUSES,
|
||||
TRANSACTION_STATUSES,
|
||||
TRANSACTION_TYPES,
|
||||
} from '../../../../shared/constants/transaction'
|
||||
@ -176,14 +177,14 @@ export function getStatusKey(transaction) {
|
||||
|
||||
// There was an on-chain failure
|
||||
if (receiptStatus === '0x0') {
|
||||
return 'failed'
|
||||
return TRANSACTION_STATUSES.FAILED
|
||||
}
|
||||
|
||||
if (
|
||||
status === TRANSACTION_STATUSES.CONFIRMED &&
|
||||
type === TRANSACTION_TYPES.CANCEL
|
||||
) {
|
||||
return 'cancelled'
|
||||
return TRANSACTION_GROUP_STATUSES.CANCELLED
|
||||
}
|
||||
|
||||
return transaction.status
|
||||
|
@ -1,4 +1,9 @@
|
||||
import assert from 'assert'
|
||||
import {
|
||||
TRANSACTION_CATEGORIES,
|
||||
TRANSACTION_GROUP_STATUSES,
|
||||
TRANSACTION_STATUSES,
|
||||
} from '../../../../shared/constants/transaction'
|
||||
import * as utils from './transactions.util'
|
||||
|
||||
describe('Transactions utils', function () {
|
||||
@ -9,7 +14,7 @@ describe('Transactions utils', function () {
|
||||
)
|
||||
assert.ok(tokenData)
|
||||
const { name, args } = tokenData
|
||||
assert.equal(name, 'transfer')
|
||||
assert.equal(name, TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER)
|
||||
const to = args._to
|
||||
const value = args._value.toString()
|
||||
assert.equal(to, '0x50A9D56C2B8BA9A5c7f2C08C3d26E0499F23a706')
|
||||
@ -26,27 +31,27 @@ describe('Transactions utils', function () {
|
||||
const tests = [
|
||||
{
|
||||
transaction: {
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txReceipt: {
|
||||
status: '0x0',
|
||||
},
|
||||
},
|
||||
expected: 'failed',
|
||||
expected: TRANSACTION_STATUSES.FAILED,
|
||||
},
|
||||
{
|
||||
transaction: {
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
txReceipt: {
|
||||
status: '0x1',
|
||||
},
|
||||
},
|
||||
expected: 'confirmed',
|
||||
expected: TRANSACTION_STATUSES.CONFIRMED,
|
||||
},
|
||||
{
|
||||
transaction: {
|
||||
status: 'pending',
|
||||
status: TRANSACTION_GROUP_STATUSES.PENDING,
|
||||
},
|
||||
expected: 'pending',
|
||||
expected: TRANSACTION_GROUP_STATUSES.PENDING,
|
||||
},
|
||||
]
|
||||
|
||||
|
@ -2,13 +2,14 @@ import assert from 'assert'
|
||||
import { ethers } from 'ethers'
|
||||
import { renderHook } from '@testing-library/react-hooks'
|
||||
import { useTokenData } from '../useTokenData'
|
||||
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction'
|
||||
|
||||
const tests = [
|
||||
{
|
||||
data:
|
||||
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000003a98',
|
||||
tokenData: {
|
||||
name: 'transfer',
|
||||
name: TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER,
|
||||
args: [
|
||||
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||||
ethers.BigNumber.from(15000),
|
||||
@ -19,7 +20,7 @@ const tests = [
|
||||
data:
|
||||
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a9700000000000000000000000000000000000000000000000000000000000061a8',
|
||||
tokenData: {
|
||||
name: 'transfer',
|
||||
name: TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER,
|
||||
args: [
|
||||
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||||
ethers.BigNumber.from(25000),
|
||||
@ -30,7 +31,7 @@ const tests = [
|
||||
data:
|
||||
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000002710',
|
||||
tokenData: {
|
||||
name: 'transfer',
|
||||
name: TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER,
|
||||
args: [
|
||||
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||||
ethers.BigNumber.from(10000),
|
||||
|
@ -18,11 +18,16 @@ import * as i18nhooks from '../useI18nContext'
|
||||
import { getMessage } from '../../helpers/utils/i18n-helper'
|
||||
import messages from '../../../../app/_locales/en/messages.json'
|
||||
import { ASSET_ROUTE, DEFAULT_ROUTE } from '../../helpers/constants/routes'
|
||||
import {
|
||||
TRANSACTION_CATEGORIES,
|
||||
TRANSACTION_GROUP_CATEGORIES,
|
||||
TRANSACTION_STATUSES,
|
||||
} from '../../../../shared/constants/transaction'
|
||||
|
||||
const expectedResults = [
|
||||
{
|
||||
title: 'Send ETH',
|
||||
category: 'send',
|
||||
category: TRANSACTION_GROUP_CATEGORIES.SEND,
|
||||
subtitle: 'To: 0xffe5...1a97',
|
||||
subtitleContainsOrigin: false,
|
||||
date: 'May 12',
|
||||
@ -31,12 +36,12 @@ const expectedResults = [
|
||||
recipientAddress: '0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||||
secondaryCurrency: '-1 ETH',
|
||||
isPending: false,
|
||||
displayedStatusKey: 'confirmed',
|
||||
displayedStatusKey: TRANSACTION_STATUSES.CONFIRMED,
|
||||
isSubmitted: false,
|
||||
},
|
||||
{
|
||||
title: 'Send ETH',
|
||||
category: 'send',
|
||||
category: TRANSACTION_GROUP_CATEGORIES.SEND,
|
||||
subtitle: 'To: 0x0ccc...8848',
|
||||
subtitleContainsOrigin: false,
|
||||
date: 'May 12',
|
||||
@ -45,11 +50,11 @@ const expectedResults = [
|
||||
recipientAddress: '0x0ccc8aeeaf5ce790f3b448325981a143fdef8848',
|
||||
secondaryCurrency: '-2 ETH',
|
||||
isPending: false,
|
||||
displayedStatusKey: 'confirmed',
|
||||
displayedStatusKey: TRANSACTION_STATUSES.CONFIRMED,
|
||||
},
|
||||
{
|
||||
title: 'Send ETH',
|
||||
category: 'send',
|
||||
category: TRANSACTION_GROUP_CATEGORIES.SEND,
|
||||
subtitle: 'To: 0xffe5...1a97',
|
||||
subtitleContainsOrigin: false,
|
||||
date: 'May 12',
|
||||
@ -58,11 +63,11 @@ const expectedResults = [
|
||||
recipientAddress: '0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||||
secondaryCurrency: '-2 ETH',
|
||||
isPending: false,
|
||||
displayedStatusKey: 'confirmed',
|
||||
displayedStatusKey: TRANSACTION_STATUSES.CONFIRMED,
|
||||
},
|
||||
{
|
||||
title: 'Receive',
|
||||
category: 'receive',
|
||||
category: TRANSACTION_GROUP_CATEGORIES.RECEIVE,
|
||||
subtitle: 'From: 0x31b9...4523',
|
||||
subtitleContainsOrigin: false,
|
||||
date: 'May 12',
|
||||
@ -71,11 +76,11 @@ const expectedResults = [
|
||||
recipientAddress: '0x9eca64466f257793eaa52fcfff5066894b76a149',
|
||||
secondaryCurrency: '18.75 ETH',
|
||||
isPending: false,
|
||||
displayedStatusKey: 'confirmed',
|
||||
displayedStatusKey: TRANSACTION_STATUSES.CONFIRMED,
|
||||
},
|
||||
{
|
||||
title: 'Receive',
|
||||
category: 'receive',
|
||||
category: TRANSACTION_GROUP_CATEGORIES.RECEIVE,
|
||||
subtitle: 'From: 0x9eca...a149',
|
||||
subtitleContainsOrigin: false,
|
||||
date: 'May 8',
|
||||
@ -84,11 +89,11 @@ const expectedResults = [
|
||||
recipientAddress: '0x9eca64466f257793eaa52fcfff5066894b76a149',
|
||||
secondaryCurrency: '0 ETH',
|
||||
isPending: false,
|
||||
displayedStatusKey: 'confirmed',
|
||||
displayedStatusKey: TRANSACTION_STATUSES.CONFIRMED,
|
||||
},
|
||||
{
|
||||
title: 'Receive',
|
||||
category: 'receive',
|
||||
category: TRANSACTION_GROUP_CATEGORIES.RECEIVE,
|
||||
subtitle: 'From: 0xee01...febb',
|
||||
subtitleContainsOrigin: false,
|
||||
date: 'May 24',
|
||||
@ -97,11 +102,11 @@ const expectedResults = [
|
||||
recipientAddress: '0x9eca64466f257793eaa52fcfff5066894b76a149',
|
||||
secondaryCurrency: '1 ETH',
|
||||
isPending: false,
|
||||
displayedStatusKey: 'confirmed',
|
||||
displayedStatusKey: TRANSACTION_STATUSES.CONFIRMED,
|
||||
},
|
||||
{
|
||||
title: 'Swap ETH to ABC',
|
||||
category: 'swap',
|
||||
category: TRANSACTION_CATEGORIES.SWAP,
|
||||
subtitle: '',
|
||||
subtitleContainsOrigin: false,
|
||||
date: 'May 12',
|
||||
@ -110,7 +115,7 @@ const expectedResults = [
|
||||
recipientAddress: '0xabca64466f257793eaa52fcfff5066894b76a149',
|
||||
secondaryCurrency: undefined,
|
||||
isPending: false,
|
||||
displayedStatusKey: 'confirmed',
|
||||
displayedStatusKey: TRANSACTION_STATUSES.CONFIRMED,
|
||||
},
|
||||
]
|
||||
|
||||
@ -120,8 +125,9 @@ const renderHookWithRouter = (cb, tokenAddress) => {
|
||||
const initialEntries = [
|
||||
tokenAddress ? `${ASSET_ROUTE}/${tokenAddress}` : DEFAULT_ROUTE,
|
||||
]
|
||||
// eslint-disable-next-line
|
||||
const wrapper = ({ children }) => <MemoryRouter initialEntries={initialEntries}>{children}</MemoryRouter>
|
||||
const wrapper = ({ children }) => (
|
||||
<MemoryRouter initialEntries={initialEntries}>{children}</MemoryRouter>
|
||||
)
|
||||
return renderHook(cb, { wrapper })
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction'
|
||||
import { decimalToHex } from '../../helpers/utils/conversions.util'
|
||||
import {
|
||||
calcTokenValue,
|
||||
@ -13,7 +14,7 @@ export function getCustomTxParamsData(
|
||||
|
||||
if (!tokenData) {
|
||||
throw new Error('Invalid data')
|
||||
} else if (tokenData.name !== 'approve') {
|
||||
} else if (tokenData.name !== TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE) {
|
||||
throw new Error(
|
||||
`Invalid data; should be 'approve' method, but instead is '${tokenData.name}'`,
|
||||
)
|
||||
|
@ -18,7 +18,10 @@ import { PRIMARY, SECONDARY } from '../../helpers/constants/common'
|
||||
import { hexToDecimal } from '../../helpers/utils/conversions.util'
|
||||
import AdvancedGasInputs from '../../components/app/gas-customization/advanced-gas-inputs'
|
||||
import TextField from '../../components/ui/text-field'
|
||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
||||
import {
|
||||
TRANSACTION_CATEGORIES,
|
||||
TRANSACTION_STATUSES,
|
||||
} from '../../../../shared/constants/transaction'
|
||||
|
||||
export default class ConfirmTransactionBase extends Component {
|
||||
static contextTypes = {
|
||||
@ -225,7 +228,9 @@ export default class ConfirmTransactionBase extends Component {
|
||||
customVariables: {
|
||||
recipientKnown: null,
|
||||
functionType:
|
||||
actionKey || getMethodName(methodData.name) || 'contractInteraction',
|
||||
actionKey ||
|
||||
getMethodName(methodData.name) ||
|
||||
TRANSACTION_CATEGORIES.CONTRACT_INTERACTION,
|
||||
origin,
|
||||
},
|
||||
})
|
||||
@ -416,7 +421,9 @@ export default class ConfirmTransactionBase extends Component {
|
||||
customVariables: {
|
||||
recipientKnown: null,
|
||||
functionType:
|
||||
actionKey || getMethodName(methodData.name) || 'contractInteraction',
|
||||
actionKey ||
|
||||
getMethodName(methodData.name) ||
|
||||
TRANSACTION_CATEGORIES.CONTRACT_INTERACTION,
|
||||
origin,
|
||||
},
|
||||
})
|
||||
@ -470,7 +477,9 @@ export default class ConfirmTransactionBase extends Component {
|
||||
customVariables: {
|
||||
recipientKnown: null,
|
||||
functionType:
|
||||
actionKey || getMethodName(methodData.name) || 'contractInteraction',
|
||||
actionKey ||
|
||||
getMethodName(methodData.name) ||
|
||||
TRANSACTION_CATEGORIES.CONTRACT_INTERACTION,
|
||||
origin,
|
||||
},
|
||||
})
|
||||
@ -525,7 +534,7 @@ export default class ConfirmTransactionBase extends Component {
|
||||
functionType:
|
||||
actionKey ||
|
||||
getMethodName(methodData.name) ||
|
||||
'contractInteraction',
|
||||
TRANSACTION_CATEGORIES.CONTRACT_INTERACTION,
|
||||
origin,
|
||||
},
|
||||
})
|
||||
|
@ -11,6 +11,7 @@ import SignatureRequestOriginal from '../../components/app/signature-request-ori
|
||||
import Loading from '../../components/ui/loading-screen'
|
||||
import { getMostRecentOverviewPage } from '../../ducks/history/history'
|
||||
import { MESSAGE_TYPE } from '../../../../app/scripts/lib/enums'
|
||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
||||
|
||||
function mapStateToProps(state) {
|
||||
const { metamask, appState } = state
|
||||
@ -213,7 +214,7 @@ class ConfirmTxScreen extends Component {
|
||||
|
||||
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network)
|
||||
|
||||
if (prevTx && prevTx.status === 'dropped') {
|
||||
if (prevTx && prevTx.status === TRANSACTION_STATUSES.DROPPED) {
|
||||
this.props.dispatch(
|
||||
actions.showModal({
|
||||
name: 'TRANSACTION_CONFIRMED',
|
||||
|
@ -58,6 +58,7 @@ import {
|
||||
ENVIRONMENT_TYPE_POPUP,
|
||||
} from '../../../../app/scripts/lib/enums'
|
||||
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
|
||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
||||
|
||||
export default class Routes extends Component {
|
||||
static propTypes = {
|
||||
@ -271,7 +272,7 @@ export default class Routes extends Component {
|
||||
|
||||
const sidebarShouldClose =
|
||||
sidebarTransaction &&
|
||||
!sidebarTransaction.status === 'failed' &&
|
||||
!sidebarTransaction.status === TRANSACTION_STATUSES.FAILED &&
|
||||
!submittedPendingTransactions.find(
|
||||
({ id }) => id === sidebarTransaction.id,
|
||||
)
|
||||
|
@ -64,6 +64,7 @@ import { useNewMetricEvent } from '../../hooks/useMetricEvent'
|
||||
import { getValueFromWeiHex } from '../../helpers/utils/conversions.util'
|
||||
|
||||
import FeatureToggledRoute from '../../helpers/higher-order-components/feature-toggled-route'
|
||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
||||
import {
|
||||
fetchTokens,
|
||||
fetchTopAssets,
|
||||
@ -139,12 +140,13 @@ export default function Swap() {
|
||||
destinationTokenInfo?.decimals,
|
||||
approveTxData,
|
||||
)
|
||||
const tradeConfirmed = tradeTxData?.status === 'confirmed'
|
||||
const tradeConfirmed = tradeTxData?.status === TRANSACTION_STATUSES.CONFIRMED
|
||||
const approveError =
|
||||
approveTxData?.status === 'failed' ||
|
||||
approveTxData?.status === TRANSACTION_STATUSES.FAILED ||
|
||||
approveTxData?.txReceipt?.status === '0x0'
|
||||
const tradeError =
|
||||
tradeTxData?.status === 'failed' || tradeTxData?.txReceipt?.status === '0x0'
|
||||
tradeTxData?.status === TRANSACTION_STATUSES.FAILED ||
|
||||
tradeTxData?.txReceipt?.status === '0x0'
|
||||
const conversionError = approveError || tradeError
|
||||
|
||||
if (conversionError) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import assert from 'assert'
|
||||
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction'
|
||||
import {
|
||||
unconfirmedTransactionsCountSelector,
|
||||
sendTokenTokenAmountAndToAddressSelector,
|
||||
@ -43,7 +44,7 @@ describe('Confirm Transaction Selector', function () {
|
||||
const state = {
|
||||
confirmTransaction: {
|
||||
tokenData: {
|
||||
name: 'transfer',
|
||||
name: TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER,
|
||||
args: getEthersArrayLikeFromObj({
|
||||
_to: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||||
_value: { toString: () => '1' },
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
||||
|
||||
const state = {
|
||||
metamask: {
|
||||
isInitialized: true,
|
||||
@ -168,7 +170,7 @@ const state = {
|
||||
4768706228115573: {
|
||||
id: 4768706228115573,
|
||||
time: 1487363153561,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
gasMultiplier: 1,
|
||||
metamaskNetworkId: '3',
|
||||
txParams: {
|
||||
|
@ -4,6 +4,7 @@ import {
|
||||
accountsWithSendEtherInfoSelector,
|
||||
getCurrentAccountWithSendEtherInfo,
|
||||
} from '..'
|
||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
||||
import {
|
||||
getBlockGasLimit,
|
||||
getConversionRate,
|
||||
@ -343,7 +344,7 @@ describe('send selectors', function () {
|
||||
4768706228115573: {
|
||||
id: 4768706228115573,
|
||||
time: 1487363153561,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
gasMultiplier: 1,
|
||||
metamaskNetworkId: '3',
|
||||
txParams: {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { strict as assert } from 'assert'
|
||||
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
||||
import {
|
||||
unapprovedMessagesSelector,
|
||||
transactionsSelector,
|
||||
@ -19,7 +20,7 @@ describe('Transaction Selectors', function () {
|
||||
origin: 'origin',
|
||||
},
|
||||
time: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
type: 'eth_sign',
|
||||
}
|
||||
|
||||
@ -46,7 +47,7 @@ describe('Transaction Selectors', function () {
|
||||
origin: 'origin',
|
||||
},
|
||||
time: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
type: 'personal_sign',
|
||||
}
|
||||
|
||||
@ -74,7 +75,7 @@ describe('Transaction Selectors', function () {
|
||||
origin: 'origin',
|
||||
},
|
||||
time: 1,
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
type: 'eth_signTypedData',
|
||||
}
|
||||
|
||||
@ -203,7 +204,7 @@ describe('Transaction Selectors', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x0',
|
||||
},
|
||||
status: 'submitted',
|
||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||
}
|
||||
|
||||
const unapprovedTx = {
|
||||
@ -214,7 +215,7 @@ describe('Transaction Selectors', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x1',
|
||||
},
|
||||
status: 'unapproved',
|
||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||
}
|
||||
|
||||
const approvedTx = {
|
||||
@ -225,7 +226,7 @@ describe('Transaction Selectors', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x2',
|
||||
},
|
||||
status: 'approved',
|
||||
status: TRANSACTION_STATUSES.APPROVED,
|
||||
}
|
||||
|
||||
const confirmedTx = {
|
||||
@ -236,7 +237,7 @@ describe('Transaction Selectors', function () {
|
||||
to: '0xRecipient',
|
||||
nonce: '0x3',
|
||||
},
|
||||
status: 'confirmed',
|
||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||
}
|
||||
|
||||
const state = {
|
||||
|
@ -6,6 +6,7 @@ import {
|
||||
import { hexToDecimal } from '../helpers/utils/conversions.util'
|
||||
import txHelper from '../../lib/tx-helper'
|
||||
import {
|
||||
TRANSACTION_CATEGORIES,
|
||||
TRANSACTION_STATUSES,
|
||||
TRANSACTION_TYPES,
|
||||
} from '../../../shared/constants/transaction'
|
||||
@ -223,7 +224,10 @@ export const nonceSortedTransactionsSelector = createSelector(
|
||||
transactionCategory,
|
||||
} = transaction
|
||||
|
||||
if (typeof nonce === 'undefined' || transactionCategory === 'incoming') {
|
||||
if (
|
||||
typeof nonce === 'undefined' ||
|
||||
transactionCategory === TRANSACTION_CATEGORIES.INCOMING
|
||||
) {
|
||||
const transactionGroup = {
|
||||
transactions: [transaction],
|
||||
initialTransaction: transaction,
|
||||
@ -232,7 +236,7 @@ export const nonceSortedTransactionsSelector = createSelector(
|
||||
hasCancelled: false,
|
||||
}
|
||||
|
||||
if (transactionCategory === 'incoming') {
|
||||
if (transactionCategory === TRANSACTION_CATEGORIES.INCOMING) {
|
||||
incomingTransactionGroups.push(transactionGroup)
|
||||
} else {
|
||||
insertTransactionGroupByTime(
|
||||
|
Loading…
Reference in New Issue
Block a user