mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
remove transactionCategory in favor of more types (#10615)
* remove transactionCategory in favor of more types * remove reference to STANDARD in stubs
This commit is contained in:
parent
a29fc51838
commit
2ed5bafa11
@ -6,7 +6,7 @@ import { bnToHex } from '../lib/util';
|
|||||||
import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
|
import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
TRANSACTION_TYPES,
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
} from '../../../shared/constants/transaction';
|
} from '../../../shared/constants/transaction';
|
||||||
import {
|
import {
|
||||||
@ -296,7 +296,7 @@ export default class IncomingTransactionsController {
|
|||||||
value: bnToHex(new BN(txMeta.value)),
|
value: bnToHex(new BN(txMeta.value)),
|
||||||
},
|
},
|
||||||
hash: txMeta.hash,
|
hash: txMeta.hash,
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
type: TRANSACTION_TYPES.INCOMING,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import {
|
|||||||
import { TRANSACTION_NO_CONTRACT_ERROR_KEY } from '../../../../ui/app/helpers/constants/error-keys';
|
import { TRANSACTION_NO_CONTRACT_ERROR_KEY } from '../../../../ui/app/helpers/constants/error-keys';
|
||||||
import { getSwapsTokensReceivedFromTxMeta } from '../../../../ui/app/pages/swaps/swaps.util';
|
import { getSwapsTokensReceivedFromTxMeta } from '../../../../ui/app/pages/swaps/swaps.util';
|
||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
TRANSACTION_TYPES,
|
TRANSACTION_TYPES,
|
||||||
} from '../../../../shared/constants/transaction';
|
} from '../../../../shared/constants/transaction';
|
||||||
@ -235,11 +234,10 @@ export default class TransactionController extends EventEmitter {
|
|||||||
`generateTxMeta` adds the default txMeta properties to the passed object.
|
`generateTxMeta` adds the default txMeta properties to the passed object.
|
||||||
These include the tx's `id`. As we use the id for determining order of
|
These include the tx's `id`. As we use the id for determining order of
|
||||||
txes in the tx-state-manager, it is necessary to call the asynchronous
|
txes in the tx-state-manager, it is necessary to call the asynchronous
|
||||||
method `this._determineTransactionCategory` after `generateTxMeta`.
|
method `this._determineTransactionType` after `generateTxMeta`.
|
||||||
*/
|
*/
|
||||||
let txMeta = this.txStateManager.generateTxMeta({
|
let txMeta = this.txStateManager.generateTxMeta({
|
||||||
txParams: normalizedTxParams,
|
txParams: normalizedTxParams,
|
||||||
type: TRANSACTION_TYPES.STANDARD,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (origin === 'metamask') {
|
if (origin === 'metamask') {
|
||||||
@ -265,11 +263,10 @@ export default class TransactionController extends EventEmitter {
|
|||||||
|
|
||||||
txMeta.origin = origin;
|
txMeta.origin = origin;
|
||||||
|
|
||||||
const {
|
const { type, getCodeResponse } = await this._determineTransactionType(
|
||||||
transactionCategory,
|
txParams,
|
||||||
getCodeResponse,
|
);
|
||||||
} = await this._determineTransactionCategory(txParams);
|
txMeta.type = type;
|
||||||
txMeta.transactionCategory = transactionCategory;
|
|
||||||
|
|
||||||
// ensure value
|
// ensure value
|
||||||
txMeta.txParams.value = txMeta.txParams.value
|
txMeta.txParams.value = txMeta.txParams.value
|
||||||
@ -347,7 +344,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
return {};
|
return {};
|
||||||
} else if (
|
} else if (
|
||||||
txMeta.txParams.to &&
|
txMeta.txParams.to &&
|
||||||
txMeta.transactionCategory === TRANSACTION_CATEGORIES.SENT_ETHER
|
txMeta.type === TRANSACTION_TYPES.SENT_ETHER
|
||||||
) {
|
) {
|
||||||
// if there's data in the params, but there's no contract code, it's not a valid transaction
|
// if there's data in the params, but there's no contract code, it's not a valid transaction
|
||||||
if (txMeta.txParams.data) {
|
if (txMeta.txParams.data) {
|
||||||
@ -581,7 +578,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
async publishTransaction(txId, rawTx) {
|
async publishTransaction(txId, rawTx) {
|
||||||
const txMeta = this.txStateManager.getTx(txId);
|
const txMeta = this.txStateManager.getTx(txId);
|
||||||
txMeta.rawTx = rawTx;
|
txMeta.rawTx = rawTx;
|
||||||
if (txMeta.transactionCategory === TRANSACTION_CATEGORIES.SWAP) {
|
if (txMeta.type === TRANSACTION_TYPES.SWAP) {
|
||||||
const preTxBalance = await this.query.getBalance(txMeta.txParams.from);
|
const preTxBalance = await this.query.getBalance(txMeta.txParams.from);
|
||||||
txMeta.preTxBalance = preTxBalance.toString(16);
|
txMeta.preTxBalance = preTxBalance.toString(16);
|
||||||
}
|
}
|
||||||
@ -637,7 +634,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
'transactions#confirmTransaction - add txReceipt',
|
'transactions#confirmTransaction - add txReceipt',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (txMeta.transactionCategory === TRANSACTION_CATEGORIES.SWAP) {
|
if (txMeta.type === TRANSACTION_TYPES.SWAP) {
|
||||||
const postTxBalance = await this.query.getBalance(txMeta.txParams.from);
|
const postTxBalance = await this.query.getBalance(txMeta.txParams.from);
|
||||||
const latestTxMeta = this.txStateManager.getTx(txId);
|
const latestTxMeta = this.txStateManager.getTx(txId);
|
||||||
|
|
||||||
@ -812,10 +809,27 @@ export default class TransactionController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns a "type" for a transaction out of the following list: simpleSend, tokenTransfer, tokenApprove,
|
* @typedef { 'transfer' | 'approve' | 'transferfrom' | 'contractInteraction'| 'sentEther' } InferrableTransactionTypes
|
||||||
contractDeployment, contractMethodCall
|
|
||||||
*/
|
*/
|
||||||
async _determineTransactionCategory(txParams) {
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} InferTransactionTypeResult
|
||||||
|
* @property {InferrableTransactionTypes} type - The type of transaction
|
||||||
|
* @property {string} getCodeResponse - The contract code, in hex format if
|
||||||
|
* it exists. '0x0' or '0x' are also indicators of non-existent contract
|
||||||
|
* code
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the type of the transaction by analyzing the txParams.
|
||||||
|
* This method will return one of the types defined in shared/constants/transactions
|
||||||
|
* It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these
|
||||||
|
* represent specific events that we control from the extension and are added manually
|
||||||
|
* at transaction creation.
|
||||||
|
* @param {Object} txParams - Parameters for the transaction
|
||||||
|
* @returns {InferTransactionTypeResult}
|
||||||
|
*/
|
||||||
|
async _determineTransactionType(txParams) {
|
||||||
const { data, to } = txParams;
|
const { data, to } = txParams;
|
||||||
let name;
|
let name;
|
||||||
try {
|
try {
|
||||||
@ -825,16 +839,16 @@ export default class TransactionController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tokenMethodName = [
|
const tokenMethodName = [
|
||||||
TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE,
|
TRANSACTION_TYPES.TOKEN_METHOD_APPROVE,
|
||||||
TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER,
|
TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||||||
TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER_FROM,
|
TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM,
|
||||||
].find((methodName) => methodName === name && name.toLowerCase());
|
].find((methodName) => methodName === name && name.toLowerCase());
|
||||||
|
|
||||||
let result;
|
let result;
|
||||||
if (data && tokenMethodName) {
|
if (data && tokenMethodName) {
|
||||||
result = tokenMethodName;
|
result = tokenMethodName;
|
||||||
} else if (data && !to) {
|
} else if (data && !to) {
|
||||||
result = TRANSACTION_CATEGORIES.DEPLOY_CONTRACT;
|
result = TRANSACTION_TYPES.DEPLOY_CONTRACT;
|
||||||
}
|
}
|
||||||
|
|
||||||
let code;
|
let code;
|
||||||
@ -849,11 +863,11 @@ export default class TransactionController extends EventEmitter {
|
|||||||
const codeIsEmpty = !code || code === '0x' || code === '0x0';
|
const codeIsEmpty = !code || code === '0x' || code === '0x0';
|
||||||
|
|
||||||
result = codeIsEmpty
|
result = codeIsEmpty
|
||||||
? TRANSACTION_CATEGORIES.SENT_ETHER
|
? TRANSACTION_TYPES.SENT_ETHER
|
||||||
: TRANSACTION_CATEGORIES.CONTRACT_INTERACTION;
|
: TRANSACTION_TYPES.CONTRACT_INTERACTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { transactionCategory: result, getCodeResponse: code };
|
return { type: result, getCodeResponse: code };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
46
app/scripts/migrations/053.js
Normal file
46
app/scripts/migrations/053.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import { cloneDeep } from 'lodash';
|
||||||
|
import { TRANSACTION_TYPES } from '../../../shared/constants/transaction';
|
||||||
|
|
||||||
|
const version = 53;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deprecate transactionCategory and consolidate on 'type'
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
version,
|
||||||
|
async migrate(originalVersionedData) {
|
||||||
|
const versionedData = cloneDeep(originalVersionedData);
|
||||||
|
versionedData.meta.version = version;
|
||||||
|
const state = versionedData.data;
|
||||||
|
versionedData.data = transformState(state);
|
||||||
|
return versionedData;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function transformState(state) {
|
||||||
|
const transactions = state?.TransactionController?.transactions;
|
||||||
|
const incomingTransactions =
|
||||||
|
state?.IncomingTransactionsController?.incomingTransactions;
|
||||||
|
if (Array.isArray(transactions)) {
|
||||||
|
transactions.forEach((transaction) => {
|
||||||
|
if (
|
||||||
|
transaction.type !== TRANSACTION_TYPES.RETRY &&
|
||||||
|
transaction.type !== TRANSACTION_TYPES.CANCEL
|
||||||
|
) {
|
||||||
|
transaction.type = transaction.transactionCategory;
|
||||||
|
}
|
||||||
|
delete transaction.transactionCategory;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (incomingTransactions) {
|
||||||
|
const incomingTransactionsEntries = Object.entries(incomingTransactions);
|
||||||
|
incomingTransactionsEntries.forEach(([key, transaction]) => {
|
||||||
|
delete transaction.transactionCategory;
|
||||||
|
state.IncomingTransactionsController.incomingTransactions[key] = {
|
||||||
|
...transaction,
|
||||||
|
type: TRANSACTION_TYPES.INCOMING,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
@ -57,6 +57,7 @@ const migrations = [
|
|||||||
require('./050').default,
|
require('./050').default,
|
||||||
require('./051').default,
|
require('./051').default,
|
||||||
require('./052').default,
|
require('./052').default,
|
||||||
|
require('./053').default,
|
||||||
];
|
];
|
||||||
|
|
||||||
export default migrations;
|
export default migrations;
|
||||||
|
@ -1,8 +1,26 @@
|
|||||||
/**
|
/**
|
||||||
* Transaction Type is a MetaMask construct used internally
|
* Transaction Type is a MetaMask construct used internally
|
||||||
* @typedef {Object} TransactionTypes
|
* @typedef {Object} TransactionTypes
|
||||||
* @property {'standard'} STANDARD - A standard transaction, usually the first with
|
* @property {'transfer'} TOKEN_METHOD_TRANSFER - A token transaction where the user
|
||||||
* a given nonce
|
* is sending tokens that they own to another address
|
||||||
|
* @property {'transferfrom'} TOKEN_METHOD_TRANSFER_FROM - A token transaction
|
||||||
|
* transferring tokens from an account that the sender has an allowance of.
|
||||||
|
* For more information on allowances, see the approve type.
|
||||||
|
* @property {'approve'} TOKEN_METHOD_APPROVE - A token transaction requesting an
|
||||||
|
* allowance of the token to spend on behalf of the user
|
||||||
|
* @property {'incoming'} INCOMING - An incoming (deposit) transaction
|
||||||
|
* @property {'sentEther'} SENT_ETHER - A transaction sending ether to a recipient
|
||||||
|
* @property {'contractInteraction'} CONTRACT_INTERACTION - A transaction that is
|
||||||
|
* interacting with a smart contract's methods that we have not treated as a special
|
||||||
|
* case, such as approve, transfer, and transferfrom
|
||||||
|
* @property {'contractDeployment'} DEPLOY_CONTRACT - A transaction that deployed
|
||||||
|
* a smart contract
|
||||||
|
* @property {'swap'} SWAP - A transaction swapping one token for another through
|
||||||
|
* MetaMask Swaps
|
||||||
|
* @property {'swapApproval'} SWAP_APPROVAL - Similar to the approve type, a swap
|
||||||
|
* approval is a special case of ERC20 approve method that requests an allowance of
|
||||||
|
* the token to spend on behalf of the user for the MetaMask Swaps contract. The first
|
||||||
|
* swap for any token will have an accompanying swapApproval transaction.
|
||||||
* @property {'cancel'} CANCEL - A transaction submitted with the same nonce as a
|
* @property {'cancel'} CANCEL - A transaction submitted with the same nonce as a
|
||||||
* previous transaction, a higher gas price and a zeroed out send amount. Useful
|
* previous transaction, a higher gas price and a zeroed out send amount. Useful
|
||||||
* for users who accidentally send to erroneous addresses or if they send too much.
|
* for users who accidentally send to erroneous addresses or if they send too much.
|
||||||
@ -16,9 +34,17 @@
|
|||||||
* @type {TransactionTypes}
|
* @type {TransactionTypes}
|
||||||
*/
|
*/
|
||||||
export const TRANSACTION_TYPES = {
|
export const TRANSACTION_TYPES = {
|
||||||
STANDARD: 'standard',
|
|
||||||
CANCEL: 'cancel',
|
CANCEL: 'cancel',
|
||||||
RETRY: 'retry',
|
RETRY: 'retry',
|
||||||
|
TOKEN_METHOD_TRANSFER: 'transfer',
|
||||||
|
TOKEN_METHOD_TRANSFER_FROM: 'transferfrom',
|
||||||
|
TOKEN_METHOD_APPROVE: 'approve',
|
||||||
|
INCOMING: 'incoming',
|
||||||
|
SENT_ETHER: 'sentEther',
|
||||||
|
CONTRACT_INTERACTION: 'contractInteraction',
|
||||||
|
DEPLOY_CONTRACT: 'contractDeployment',
|
||||||
|
SWAP: 'swap',
|
||||||
|
SWAP_APPROVAL: 'swapApproval',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,45 +79,6 @@ export const TRANSACTION_STATUSES = {
|
|||||||
CONFIRMED: 'confirmed',
|
CONFIRMED: 'confirmed',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} TransactionCategories
|
|
||||||
* @property {'transfer'} TOKEN_METHOD_TRANSFER - A token transaction where the user
|
|
||||||
* is sending tokens that they own to another address
|
|
||||||
* @property {'transferfrom'} TOKEN_METHOD_TRANSFER_FROM - A token transaction
|
|
||||||
* transferring tokens from an account that the sender has an allowance of.
|
|
||||||
* For more information on allowances, see the approve category.
|
|
||||||
* @property {'approve'} TOKEN_METHOD_APPROVE - A token transaction requesting an
|
|
||||||
* allowance of the token to spend on behalf of the user
|
|
||||||
* @property {'incoming'} INCOMING - An incoming (deposit) transaction
|
|
||||||
* @property {'sentEther'} SENT_ETHER - A transaction sending ether to a recipient
|
|
||||||
* @property {'contractInteraction'} CONTRACT_INTERACTION - A transaction that is
|
|
||||||
* interacting with a smart contract's methods that we have not treated as a special
|
|
||||||
* case, such as approve, transfer, and transferfrom
|
|
||||||
* @property {'contractDeployment'} DEPLOY_CONTRACT - A transaction that deployed
|
|
||||||
* a smart contract
|
|
||||||
* @property {'swap'} SWAP - A transaction swapping one token for another through
|
|
||||||
* MetaMask Swaps
|
|
||||||
* @property {'swapApproval'} SWAP_APPROVAL - Similar to the approve category, a swap
|
|
||||||
* approval is a special case of ERC20 approve method that requests an allowance of
|
|
||||||
* the token to spend on behalf of the user for the MetaMask Swaps contract. The first
|
|
||||||
* swap for any token will have an accompanying swapApproval transaction.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {TransactionCategories}
|
|
||||||
*/
|
|
||||||
export const TRANSACTION_CATEGORIES = {
|
|
||||||
TOKEN_METHOD_TRANSFER: 'transfer',
|
|
||||||
TOKEN_METHOD_TRANSFER_FROM: 'transferfrom',
|
|
||||||
TOKEN_METHOD_APPROVE: 'approve',
|
|
||||||
INCOMING: 'incoming',
|
|
||||||
SENT_ETHER: 'sentEther',
|
|
||||||
CONTRACT_INTERACTION: 'contractInteraction',
|
|
||||||
DEPLOY_CONTRACT: 'contractDeployment',
|
|
||||||
SWAP: 'swap',
|
|
||||||
SWAP_APPROVAL: 'swapApproval',
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transaction Group Status is a MetaMask construct to track the status of groups
|
* Transaction Group Status is a MetaMask construct to track the status of groups
|
||||||
* of transactions.
|
* of transactions.
|
||||||
|
@ -15,9 +15,8 @@
|
|||||||
"gas": "0x5208",
|
"gas": "0x5208",
|
||||||
"gasPrice": "0x2540be400"
|
"gasPrice": "0x2540be400"
|
||||||
},
|
},
|
||||||
"type": "standard",
|
|
||||||
"origin": "metamask",
|
"origin": "metamask",
|
||||||
"transactionCategory": "sentEther",
|
"type": "sentEther",
|
||||||
"nonceDetails": {
|
"nonceDetails": {
|
||||||
"params": {
|
"params": {
|
||||||
"highestLocallyConfirmed": 12,
|
"highestLocallyConfirmed": 12,
|
||||||
@ -76,9 +75,8 @@
|
|||||||
"gas": "0x5208",
|
"gas": "0x5208",
|
||||||
"gasPrice": "0x2540be400"
|
"gasPrice": "0x2540be400"
|
||||||
},
|
},
|
||||||
"type": "standard",
|
|
||||||
"origin": "metamask",
|
"origin": "metamask",
|
||||||
"transactionCategory": "sentEther",
|
"type": "sentEther",
|
||||||
"nonceDetails": {
|
"nonceDetails": {
|
||||||
"params": {
|
"params": {
|
||||||
"highestLocallyConfirmed": 12,
|
"highestLocallyConfirmed": 12,
|
||||||
@ -142,9 +140,8 @@
|
|||||||
"gas": "0x5208",
|
"gas": "0x5208",
|
||||||
"gasPrice": "0x2540be400"
|
"gasPrice": "0x2540be400"
|
||||||
},
|
},
|
||||||
"type": "standard",
|
|
||||||
"origin": "metamask",
|
"origin": "metamask",
|
||||||
"transactionCategory": "sentEther",
|
"type": "sentEther",
|
||||||
"nonceDetails": {
|
"nonceDetails": {
|
||||||
"params": {
|
"params": {
|
||||||
"highestLocallyConfirmed": 0,
|
"highestLocallyConfirmed": 0,
|
||||||
@ -203,9 +200,8 @@
|
|||||||
"gas": "0x5208",
|
"gas": "0x5208",
|
||||||
"gasPrice": "0x2540be400"
|
"gasPrice": "0x2540be400"
|
||||||
},
|
},
|
||||||
"type": "standard",
|
|
||||||
"origin": "metamask",
|
"origin": "metamask",
|
||||||
"transactionCategory": "sentEther",
|
"type": "sentEther",
|
||||||
"nonceDetails": {
|
"nonceDetails": {
|
||||||
"params": {
|
"params": {
|
||||||
"highestLocallyConfirmed": 0,
|
"highestLocallyConfirmed": 0,
|
||||||
@ -269,9 +265,8 @@
|
|||||||
"gas": "0x5208",
|
"gas": "0x5208",
|
||||||
"gasPrice": "0x306dc4200"
|
"gasPrice": "0x306dc4200"
|
||||||
},
|
},
|
||||||
"type": "standard",
|
|
||||||
"origin": "metamask",
|
"origin": "metamask",
|
||||||
"transactionCategory": "sentEther",
|
"type": "sentEther",
|
||||||
"nonceDetails": {
|
"nonceDetails": {
|
||||||
"params": {
|
"params": {
|
||||||
"highestLocallyConfirmed": 0,
|
"highestLocallyConfirmed": 0,
|
||||||
@ -331,9 +326,8 @@
|
|||||||
"gas": "0x5208",
|
"gas": "0x5208",
|
||||||
"gasPrice": "0x306dc4200"
|
"gasPrice": "0x306dc4200"
|
||||||
},
|
},
|
||||||
"type": "standard",
|
|
||||||
"origin": "metamask",
|
"origin": "metamask",
|
||||||
"transactionCategory": "sentEther",
|
"type": "sentEther",
|
||||||
"nonceDetails": {
|
"nonceDetails": {
|
||||||
"params": {
|
"params": {
|
||||||
"highestLocallyConfirmed": 0,
|
"highestLocallyConfirmed": 0,
|
||||||
@ -398,7 +392,7 @@
|
|||||||
"value": "0x1043561a882930000"
|
"value": "0x1043561a882930000"
|
||||||
},
|
},
|
||||||
"hash": "0x5ca26d1cdcabef1ac2ad5b2b38604c9ced65d143efc7525f848c46f28e0e4116",
|
"hash": "0x5ca26d1cdcabef1ac2ad5b2b38604c9ced65d143efc7525f848c46f28e0e4116",
|
||||||
"transactionCategory": "incoming"
|
"type": "incoming"
|
||||||
},
|
},
|
||||||
"primaryTransaction": {
|
"primaryTransaction": {
|
||||||
"blockNumber": "6477257",
|
"blockNumber": "6477257",
|
||||||
@ -415,7 +409,7 @@
|
|||||||
"value": "0x1043561a882930000"
|
"value": "0x1043561a882930000"
|
||||||
},
|
},
|
||||||
"hash": "0x5ca26d1cdcabef1ac2ad5b2b38604c9ced65d143efc7525f848c46f28e0e4116",
|
"hash": "0x5ca26d1cdcabef1ac2ad5b2b38604c9ced65d143efc7525f848c46f28e0e4116",
|
||||||
"transactionCategory": "incoming"
|
"type": "incoming"
|
||||||
},
|
},
|
||||||
"hasRetried": false,
|
"hasRetried": false,
|
||||||
"hasCancelled": false
|
"hasCancelled": false
|
||||||
@ -436,7 +430,7 @@
|
|||||||
"value": "0x0"
|
"value": "0x0"
|
||||||
},
|
},
|
||||||
"hash": "0xa42b2b433e5bd2616b52e30792aedb6a3c374a752a95d43d99e2a8b143937889",
|
"hash": "0xa42b2b433e5bd2616b52e30792aedb6a3c374a752a95d43d99e2a8b143937889",
|
||||||
"transactionCategory": "incoming"
|
"type": "incoming"
|
||||||
},
|
},
|
||||||
"primaryTransaction": {
|
"primaryTransaction": {
|
||||||
"blockNumber": "6454493",
|
"blockNumber": "6454493",
|
||||||
@ -453,7 +447,7 @@
|
|||||||
"value": "0x0"
|
"value": "0x0"
|
||||||
},
|
},
|
||||||
"hash": "0xa42b2b433e5bd2616b52e30792aedb6a3c374a752a95d43d99e2a8b143937889",
|
"hash": "0xa42b2b433e5bd2616b52e30792aedb6a3c374a752a95d43d99e2a8b143937889",
|
||||||
"transactionCategory": "incoming"
|
"type": "incoming"
|
||||||
},
|
},
|
||||||
"hasRetried": false,
|
"hasRetried": false,
|
||||||
"hasCancelled": false
|
"hasCancelled": false
|
||||||
@ -474,7 +468,7 @@
|
|||||||
"value": "0xde0b6b3a7640000"
|
"value": "0xde0b6b3a7640000"
|
||||||
},
|
},
|
||||||
"hash": "0xbcb195f393f4468945b4045cd41bcdbc2f19ad75ae92a32cf153a3004e42009a",
|
"hash": "0xbcb195f393f4468945b4045cd41bcdbc2f19ad75ae92a32cf153a3004e42009a",
|
||||||
"transactionCategory": "incoming"
|
"type": "incoming"
|
||||||
},
|
},
|
||||||
"primaryTransaction": {
|
"primaryTransaction": {
|
||||||
"blockNumber": "6195526",
|
"blockNumber": "6195526",
|
||||||
@ -491,7 +485,7 @@
|
|||||||
"value": "0xde0b6b3a7640000"
|
"value": "0xde0b6b3a7640000"
|
||||||
},
|
},
|
||||||
"hash": "0xbcb195f393f4468945b4045cd41bcdbc2f19ad75ae92a32cf153a3004e42009a",
|
"hash": "0xbcb195f393f4468945b4045cd41bcdbc2f19ad75ae92a32cf153a3004e42009a",
|
||||||
"transactionCategory": "incoming"
|
"type": "incoming"
|
||||||
},
|
},
|
||||||
"hasRetried": false,
|
"hasRetried": false,
|
||||||
"hasCancelled": false
|
"hasCancelled": false
|
||||||
@ -514,7 +508,7 @@
|
|||||||
"hash": "0xbcb195f393f4468945b4045cd41bcdbc2f19ad75ae92a32cf153a3004e42009a",
|
"hash": "0xbcb195f393f4468945b4045cd41bcdbc2f19ad75ae92a32cf153a3004e42009a",
|
||||||
"destinationTokenSymbol": "ABC",
|
"destinationTokenSymbol": "ABC",
|
||||||
"sourceTokenSymbol": "ETH",
|
"sourceTokenSymbol": "ETH",
|
||||||
"transactionCategory": "swap"
|
"type": "swap"
|
||||||
},
|
},
|
||||||
"primaryTransaction": {
|
"primaryTransaction": {
|
||||||
"blockNumber": "6195527",
|
"blockNumber": "6195527",
|
||||||
@ -531,7 +525,7 @@
|
|||||||
"value": "0xde0b6b3a7640000"
|
"value": "0xde0b6b3a7640000"
|
||||||
},
|
},
|
||||||
"hash": "0xbcb195f393f4468945b4045cd41bcdbc2f19ad75ae92a32cf153a3004e42009a",
|
"hash": "0xbcb195f393f4468945b4045cd41bcdbc2f19ad75ae92a32cf153a3004e42009a",
|
||||||
"transactionCategory": "swap",
|
"type": "swap",
|
||||||
"destinationTokenSymbol": "ABC",
|
"destinationTokenSymbol": "ABC",
|
||||||
"destinationTokenAddress": "0xabca64466f257793eaa52fcfff5066894b76a149",
|
"destinationTokenAddress": "0xabca64466f257793eaa52fcfff5066894b76a149",
|
||||||
"sourceTokenSymbol": "ETH"
|
"sourceTokenSymbol": "ETH"
|
||||||
|
@ -16,7 +16,7 @@ import {
|
|||||||
ROPSTEN_NETWORK_ID,
|
ROPSTEN_NETWORK_ID,
|
||||||
} from '../../../../shared/constants/network';
|
} from '../../../../shared/constants/network';
|
||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
TRANSACTION_TYPES,
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
} from '../../../../shared/constants/transaction';
|
} from '../../../../shared/constants/transaction';
|
||||||
import { NETWORK_EVENTS } from '../../../../app/scripts/controllers/network';
|
import { NETWORK_EVENTS } from '../../../../app/scripts/controllers/network';
|
||||||
@ -276,7 +276,7 @@ describe('IncomingTransactionsController', function () {
|
|||||||
chainId: ROPSTEN_CHAIN_ID,
|
chainId: ROPSTEN_CHAIN_ID,
|
||||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||||
time: 16000000000000000,
|
time: 16000000000000000,
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
type: TRANSACTION_TYPES.INCOMING,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0xfake',
|
from: '0xfake',
|
||||||
gas: '0x0',
|
gas: '0x0',
|
||||||
@ -620,7 +620,7 @@ describe('IncomingTransactionsController', function () {
|
|||||||
chainId: ROPSTEN_CHAIN_ID,
|
chainId: ROPSTEN_CHAIN_ID,
|
||||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||||
time: 16000000000000000,
|
time: 16000000000000000,
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
type: TRANSACTION_TYPES.INCOMING,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0xfake',
|
from: '0xfake',
|
||||||
gas: '0x0',
|
gas: '0x0',
|
||||||
@ -775,7 +775,7 @@ describe('IncomingTransactionsController', function () {
|
|||||||
chainId: ROPSTEN_CHAIN_ID,
|
chainId: ROPSTEN_CHAIN_ID,
|
||||||
status: TRANSACTION_STATUSES.CONFIRMED,
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
||||||
time: 16000000000000000,
|
time: 16000000000000000,
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
type: TRANSACTION_TYPES.INCOMING,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0xfake',
|
from: '0xfake',
|
||||||
gas: '0x0',
|
gas: '0x0',
|
||||||
@ -1362,7 +1362,7 @@ describe('IncomingTransactionsController', function () {
|
|||||||
value: '0xf',
|
value: '0xf',
|
||||||
},
|
},
|
||||||
hash: '0xg',
|
hash: '0xg',
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
type: TRANSACTION_TYPES.INCOMING,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1408,7 +1408,7 @@ describe('IncomingTransactionsController', function () {
|
|||||||
value: '0xf',
|
value: '0xf',
|
||||||
},
|
},
|
||||||
hash: '0xg',
|
hash: '0xg',
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
|
type: TRANSACTION_TYPES.INCOMING,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
TRANSACTION_TYPES,
|
TRANSACTION_TYPES,
|
||||||
} from '../../../../../shared/constants/transaction';
|
} from '../../../../../shared/constants/transaction';
|
||||||
@ -14,7 +13,7 @@ export const txMetaStub = {
|
|||||||
metamaskNetworkId: '4',
|
metamaskNetworkId: '4',
|
||||||
status: TRANSACTION_STATUSES.UNAPPROVED,
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
||||||
time: 1572395156620,
|
time: 1572395156620,
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.SENT_ETHER,
|
type: TRANSACTION_TYPES.SENT_ETHER,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||||
gas: '0x5208',
|
gas: '0x5208',
|
||||||
@ -22,7 +21,6 @@ export const txMetaStub = {
|
|||||||
to: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
to: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||||
value: '0x0',
|
value: '0x0',
|
||||||
},
|
},
|
||||||
type: TRANSACTION_TYPES.STANDARD,
|
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -196,7 +194,7 @@ export const txMetaStub = {
|
|||||||
status: TRANSACTION_STATUSES.SUBMITTED,
|
status: TRANSACTION_STATUSES.SUBMITTED,
|
||||||
submittedTime: 1572395158570,
|
submittedTime: 1572395158570,
|
||||||
time: 1572395156620,
|
time: 1572395156620,
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.SENT_ETHER,
|
type: TRANSACTION_TYPES.SENT_ETHER,
|
||||||
txParams: {
|
txParams: {
|
||||||
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
from: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||||
gas: '0x5208',
|
gas: '0x5208',
|
||||||
@ -205,6 +203,5 @@ export const txMetaStub = {
|
|||||||
to: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
to: '0xf231d46dd78806e1dd93442cf33c7671f8538748',
|
||||||
value: '0x0',
|
value: '0x0',
|
||||||
},
|
},
|
||||||
type: TRANSACTION_TYPES.STANDARD,
|
|
||||||
v: '0x2c',
|
v: '0x2c',
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,6 @@ import {
|
|||||||
getTestAccounts,
|
getTestAccounts,
|
||||||
} from '../../../../stub/provider';
|
} from '../../../../stub/provider';
|
||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
TRANSACTION_TYPES,
|
TRANSACTION_TYPES,
|
||||||
} from '../../../../../shared/constants/transaction';
|
} from '../../../../../shared/constants/transaction';
|
||||||
@ -776,76 +775,76 @@ describe('Transaction Controller', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#_determineTransactionCategory', function () {
|
describe('#_determineTransactionType', function () {
|
||||||
it('should return a simple send transactionCategory when to is truthy but data is falsy', async function () {
|
it('should return a simple send type when to is truthy but data is falsy', async function () {
|
||||||
const result = await txController._determineTransactionCategory({
|
const result = await txController._determineTransactionType({
|
||||||
to: '0xabc',
|
to: '0xabc',
|
||||||
data: '',
|
data: '',
|
||||||
});
|
});
|
||||||
assert.deepEqual(result, {
|
assert.deepEqual(result, {
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.SENT_ETHER,
|
type: TRANSACTION_TYPES.SENT_ETHER,
|
||||||
getCodeResponse: null,
|
getCodeResponse: null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a token transfer transactionCategory when data is for the respective method call', async function () {
|
it('should return a token transfer type when data is for the respective method call', async function () {
|
||||||
const result = await txController._determineTransactionCategory({
|
const result = await txController._determineTransactionType({
|
||||||
to: '0xabc',
|
to: '0xabc',
|
||||||
data:
|
data:
|
||||||
'0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a',
|
'0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a',
|
||||||
});
|
});
|
||||||
assert.deepEqual(result, {
|
assert.deepEqual(result, {
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER,
|
type: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||||||
getCodeResponse: undefined,
|
getCodeResponse: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a token approve transactionCategory when data is for the respective method call', async function () {
|
it('should return a token approve type when data is for the respective method call', async function () {
|
||||||
const result = await txController._determineTransactionCategory({
|
const result = await txController._determineTransactionType({
|
||||||
to: '0xabc',
|
to: '0xabc',
|
||||||
data:
|
data:
|
||||||
'0x095ea7b30000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C9700000000000000000000000000000000000000000000000000000000000000005',
|
'0x095ea7b30000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C9700000000000000000000000000000000000000000000000000000000000000005',
|
||||||
});
|
});
|
||||||
assert.deepEqual(result, {
|
assert.deepEqual(result, {
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE,
|
type: TRANSACTION_TYPES.TOKEN_METHOD_APPROVE,
|
||||||
getCodeResponse: undefined,
|
getCodeResponse: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a contract deployment transactionCategory when to is falsy and there is data', async function () {
|
it('should return a contract deployment type when to is falsy and there is data', async function () {
|
||||||
const result = await txController._determineTransactionCategory({
|
const result = await txController._determineTransactionType({
|
||||||
to: '',
|
to: '',
|
||||||
data: '0xabd',
|
data: '0xabd',
|
||||||
});
|
});
|
||||||
assert.deepEqual(result, {
|
assert.deepEqual(result, {
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.DEPLOY_CONTRACT,
|
type: TRANSACTION_TYPES.DEPLOY_CONTRACT,
|
||||||
getCodeResponse: undefined,
|
getCodeResponse: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a simple send transactionCategory with a 0x getCodeResponse when there is data and but the to address is not a contract address', async function () {
|
it('should return a simple send type with a 0x getCodeResponse when there is data and but the to address is not a contract address', async function () {
|
||||||
const result = await txController._determineTransactionCategory({
|
const result = await txController._determineTransactionType({
|
||||||
to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9',
|
to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9',
|
||||||
data: '0xabd',
|
data: '0xabd',
|
||||||
});
|
});
|
||||||
assert.deepEqual(result, {
|
assert.deepEqual(result, {
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.SENT_ETHER,
|
type: TRANSACTION_TYPES.SENT_ETHER,
|
||||||
getCodeResponse: '0x',
|
getCodeResponse: '0x',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a simple send transactionCategory with a null getCodeResponse when to is truthy and there is data and but getCode returns an error', async function () {
|
it('should return a simple send type with a null getCodeResponse when to is truthy and there is data and but getCode returns an error', async function () {
|
||||||
const result = await txController._determineTransactionCategory({
|
const result = await txController._determineTransactionType({
|
||||||
to: '0xabc',
|
to: '0xabc',
|
||||||
data: '0xabd',
|
data: '0xabd',
|
||||||
});
|
});
|
||||||
assert.deepEqual(result, {
|
assert.deepEqual(result, {
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.SENT_ETHER,
|
type: TRANSACTION_TYPES.SENT_ETHER,
|
||||||
getCodeResponse: null,
|
getCodeResponse: null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a contract interaction transactionCategory with the correct getCodeResponse when to is truthy and there is data and it is not a token transaction', async function () {
|
it('should return a contract interaction type with the correct getCodeResponse when to is truthy and there is data and it is not a token transaction', async function () {
|
||||||
const _providerResultStub = {
|
const _providerResultStub = {
|
||||||
// 1 gwei
|
// 1 gwei
|
||||||
eth_gasPrice: '0x0de0b6b3a7640000',
|
eth_gasPrice: '0x0de0b6b3a7640000',
|
||||||
@ -875,17 +874,17 @@ describe('Transaction Controller', function () {
|
|||||||
}),
|
}),
|
||||||
getParticipateInMetrics: () => false,
|
getParticipateInMetrics: () => false,
|
||||||
});
|
});
|
||||||
const result = await _txController._determineTransactionCategory({
|
const result = await _txController._determineTransactionType({
|
||||||
to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9',
|
to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9',
|
||||||
data: 'abd',
|
data: 'abd',
|
||||||
});
|
});
|
||||||
assert.deepEqual(result, {
|
assert.deepEqual(result, {
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.CONTRACT_INTERACTION,
|
type: TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
||||||
getCodeResponse: '0x0a',
|
getCodeResponse: '0x0a',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a contract interaction transactionCategory with the correct getCodeResponse when to is a contract address and data is falsy', async function () {
|
it('should return a contract interaction type with the correct getCodeResponse when to is a contract address and data is falsy', async function () {
|
||||||
const _providerResultStub = {
|
const _providerResultStub = {
|
||||||
// 1 gwei
|
// 1 gwei
|
||||||
eth_gasPrice: '0x0de0b6b3a7640000',
|
eth_gasPrice: '0x0de0b6b3a7640000',
|
||||||
@ -915,12 +914,12 @@ describe('Transaction Controller', function () {
|
|||||||
}),
|
}),
|
||||||
getParticipateInMetrics: () => false,
|
getParticipateInMetrics: () => false,
|
||||||
});
|
});
|
||||||
const result = await _txController._determineTransactionCategory({
|
const result = await _txController._determineTransactionType({
|
||||||
to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9',
|
to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9',
|
||||||
data: '',
|
data: '',
|
||||||
});
|
});
|
||||||
assert.deepEqual(result, {
|
assert.deepEqual(result, {
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.CONTRACT_INTERACTION,
|
type: TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
||||||
getCodeResponse: '0x0a',
|
getCodeResponse: '0x0a',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
136
test/unit/migrations/053.test.js
Normal file
136
test/unit/migrations/053.test.js
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import { strict as assert } from 'assert';
|
||||||
|
import migration53 from '../../../app/scripts/migrations/053';
|
||||||
|
import { TRANSACTION_TYPES } from '../../../shared/constants/transaction';
|
||||||
|
|
||||||
|
describe('migration #53', function () {
|
||||||
|
it('should update the version metadata', async function () {
|
||||||
|
const oldStorage = {
|
||||||
|
meta: {
|
||||||
|
version: 52,
|
||||||
|
},
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const newStorage = await migration53.migrate(oldStorage);
|
||||||
|
assert.deepEqual(newStorage.meta, {
|
||||||
|
version: 53,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update type of standard transactions', async function () {
|
||||||
|
const oldStorage = {
|
||||||
|
meta: {},
|
||||||
|
data: {
|
||||||
|
TransactionController: {
|
||||||
|
transactions: [
|
||||||
|
{
|
||||||
|
type: TRANSACTION_TYPES.CANCEL,
|
||||||
|
transactionCategory: TRANSACTION_TYPES.SENT_ETHER,
|
||||||
|
txParams: { foo: 'bar' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'standard',
|
||||||
|
transactionCategory: TRANSACTION_TYPES.SENT_ETHER,
|
||||||
|
txParams: { foo: 'bar' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'standard',
|
||||||
|
transactionCategory: TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
||||||
|
txParams: { foo: 'bar' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: TRANSACTION_TYPES.RETRY,
|
||||||
|
transactionCategory: TRANSACTION_TYPES.SENT_ETHER,
|
||||||
|
txParams: { foo: 'bar' },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
IncomingTransactionsController: {
|
||||||
|
incomingTransactions: {
|
||||||
|
test: {
|
||||||
|
transactionCategory: 'incoming',
|
||||||
|
txParams: {
|
||||||
|
foo: 'bar',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
foo: 'bar',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const newStorage = await migration53.migrate(oldStorage);
|
||||||
|
assert.deepEqual(newStorage.data, {
|
||||||
|
TransactionController: {
|
||||||
|
transactions: [
|
||||||
|
{ type: TRANSACTION_TYPES.CANCEL, txParams: { foo: 'bar' } },
|
||||||
|
{ type: TRANSACTION_TYPES.SENT_ETHER, txParams: { foo: 'bar' } },
|
||||||
|
{
|
||||||
|
type: TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
||||||
|
txParams: { foo: 'bar' },
|
||||||
|
},
|
||||||
|
{ type: TRANSACTION_TYPES.RETRY, txParams: { foo: 'bar' } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
IncomingTransactionsController: {
|
||||||
|
incomingTransactions: {
|
||||||
|
test: {
|
||||||
|
type: 'incoming',
|
||||||
|
txParams: {
|
||||||
|
foo: 'bar',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
foo: 'bar',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do nothing if transactions state does not exist', async function () {
|
||||||
|
const oldStorage = {
|
||||||
|
meta: {},
|
||||||
|
data: {
|
||||||
|
TransactionController: {
|
||||||
|
bar: 'baz',
|
||||||
|
},
|
||||||
|
IncomingTransactionsController: {
|
||||||
|
foo: 'baz',
|
||||||
|
},
|
||||||
|
foo: 'bar',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const newStorage = await migration53.migrate(oldStorage);
|
||||||
|
assert.deepEqual(oldStorage.data, newStorage.data);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do nothing if transactions state is empty', async function () {
|
||||||
|
const oldStorage = {
|
||||||
|
meta: {},
|
||||||
|
data: {
|
||||||
|
TransactionController: {
|
||||||
|
transactions: [],
|
||||||
|
bar: 'baz',
|
||||||
|
},
|
||||||
|
IncomingTransactionsController: {
|
||||||
|
incomingTransactions: {},
|
||||||
|
baz: 'bar',
|
||||||
|
},
|
||||||
|
foo: 'bar',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const newStorage = await migration53.migrate(oldStorage);
|
||||||
|
assert.deepEqual(oldStorage.data, newStorage.data);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do nothing if state is empty', async function () {
|
||||||
|
const oldStorage = {
|
||||||
|
meta: {},
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const newStorage = await migration53.migrate(oldStorage);
|
||||||
|
assert.deepEqual(oldStorage.data, newStorage.data);
|
||||||
|
});
|
||||||
|
});
|
@ -6,19 +6,16 @@ import {
|
|||||||
} from '../../../selectors';
|
} from '../../../selectors';
|
||||||
import { getHexGasTotal } from '../../../helpers/utils/confirm-tx.util';
|
import { getHexGasTotal } from '../../../helpers/utils/confirm-tx.util';
|
||||||
import { sumHexes } from '../../../helpers/utils/transactions.util';
|
import { sumHexes } from '../../../helpers/utils/transactions.util';
|
||||||
import { TRANSACTION_CATEGORIES } from '../../../../../shared/constants/transaction';
|
|
||||||
import TransactionBreakdown from './transaction-breakdown.component';
|
import TransactionBreakdown from './transaction-breakdown.component';
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => {
|
const mapStateToProps = (state, ownProps) => {
|
||||||
const { transaction, transactionCategory } = ownProps;
|
const { transaction, isTokenApprove } = ownProps;
|
||||||
const {
|
const {
|
||||||
txParams: { gas, gasPrice, value } = {},
|
txParams: { gas, gasPrice, value } = {},
|
||||||
txReceipt: { gasUsed } = {},
|
txReceipt: { gasUsed } = {},
|
||||||
} = transaction;
|
} = transaction;
|
||||||
const { showFiatInTestnets } = getPreferences(state);
|
const { showFiatInTestnets } = getPreferences(state);
|
||||||
const isMainnet = getIsMainnet(state);
|
const isMainnet = getIsMainnet(state);
|
||||||
const isTokenApprove =
|
|
||||||
transactionCategory === TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE;
|
|
||||||
|
|
||||||
const gasLimit = typeof gasUsed === 'string' ? gasUsed : gas;
|
const gasLimit = typeof gasUsed === 'string' ? gasUsed : gas;
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import Tooltip from '../../ui/tooltip';
|
|||||||
import Copy from '../../ui/icon/copy-icon.component';
|
import Copy from '../../ui/icon/copy-icon.component';
|
||||||
import Popover from '../../ui/popover';
|
import Popover from '../../ui/popover';
|
||||||
import { getBlockExplorerUrlForTx } from '../../../../../shared/modules/transaction.utils';
|
import { getBlockExplorerUrlForTx } from '../../../../../shared/modules/transaction.utils';
|
||||||
|
import { TRANSACTION_TYPES } from '../../../../../shared/constants/transaction';
|
||||||
|
|
||||||
export default class TransactionListItemDetails extends PureComponent {
|
export default class TransactionListItemDetails extends PureComponent {
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
@ -156,7 +157,7 @@ export default class TransactionListItemDetails extends PureComponent {
|
|||||||
} = this.props;
|
} = this.props;
|
||||||
const {
|
const {
|
||||||
primaryTransaction: transaction,
|
primaryTransaction: transaction,
|
||||||
initialTransaction: { transactionCategory },
|
initialTransaction: { type },
|
||||||
} = transactionGroup;
|
} = transactionGroup;
|
||||||
const { hash } = transaction;
|
const { hash } = transaction;
|
||||||
|
|
||||||
@ -255,7 +256,7 @@ export default class TransactionListItemDetails extends PureComponent {
|
|||||||
<div className="transaction-list-item-details__cards-container">
|
<div className="transaction-list-item-details__cards-container">
|
||||||
<TransactionBreakdown
|
<TransactionBreakdown
|
||||||
nonce={transactionGroup.initialTransaction.txParams.nonce}
|
nonce={transactionGroup.initialTransaction.txParams.nonce}
|
||||||
transactionCategory={transactionCategory}
|
isTokenApprove={type === TRANSACTION_TYPES.TOKEN_METHOD_APPROVE}
|
||||||
transaction={transaction}
|
transaction={transaction}
|
||||||
primaryCurrency={primaryCurrency}
|
primaryCurrency={primaryCurrency}
|
||||||
className="transaction-list-item-details__transaction-breakdown"
|
className="transaction-list-item-details__transaction-breakdown"
|
||||||
|
@ -10,7 +10,7 @@ import TransactionListItem from '../transaction-list-item';
|
|||||||
import Button from '../../ui/button';
|
import Button from '../../ui/button';
|
||||||
import { TOKEN_CATEGORY_HASH } from '../../../helpers/constants/transactions';
|
import { TOKEN_CATEGORY_HASH } from '../../../helpers/constants/transactions';
|
||||||
import { SWAPS_CONTRACT_ADDRESS } from '../../../helpers/constants/swaps';
|
import { SWAPS_CONTRACT_ADDRESS } from '../../../helpers/constants/swaps';
|
||||||
import { TRANSACTION_CATEGORIES } from '../../../../../shared/constants/transaction';
|
import { TRANSACTION_TYPES } from '../../../../../shared/constants/transaction';
|
||||||
|
|
||||||
const PAGE_INCREMENT = 10;
|
const PAGE_INCREMENT = 10;
|
||||||
|
|
||||||
@ -25,15 +25,11 @@ const getTransactionGroupRecipientAddressFilter = (recipientAddress) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const tokenTransactionFilter = ({
|
const tokenTransactionFilter = ({
|
||||||
initialTransaction: {
|
initialTransaction: { type, destinationTokenSymbol, sourceTokenSymbol },
|
||||||
transactionCategory,
|
|
||||||
destinationTokenSymbol,
|
|
||||||
sourceTokenSymbol,
|
|
||||||
},
|
|
||||||
}) => {
|
}) => {
|
||||||
if (TOKEN_CATEGORY_HASH[transactionCategory]) {
|
if (TOKEN_CATEGORY_HASH[type]) {
|
||||||
return false;
|
return false;
|
||||||
} else if (transactionCategory === TRANSACTION_CATEGORIES.SWAP) {
|
} else if (type === TRANSACTION_TYPES.SWAP) {
|
||||||
return destinationTokenSymbol === 'ETH' || sourceTokenSymbol === 'ETH';
|
return destinationTokenSymbol === 'ETH' || sourceTokenSymbol === 'ETH';
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -57,7 +57,7 @@ import {
|
|||||||
SWAP_FAILED_ERROR,
|
SWAP_FAILED_ERROR,
|
||||||
SWAPS_FETCH_ORDER_CONFLICT,
|
SWAPS_FETCH_ORDER_CONFLICT,
|
||||||
} from '../../helpers/constants/swaps';
|
} from '../../helpers/constants/swaps';
|
||||||
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction';
|
import { TRANSACTION_TYPES } from '../../../../shared/constants/transaction';
|
||||||
|
|
||||||
const GAS_PRICES_LOADING_STATES = {
|
const GAS_PRICES_LOADING_STATES = {
|
||||||
INITIAL: 'INITIAL',
|
INITIAL: 'INITIAL',
|
||||||
@ -671,7 +671,7 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => {
|
|||||||
updateTransaction(
|
updateTransaction(
|
||||||
{
|
{
|
||||||
...approveTxMeta,
|
...approveTxMeta,
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.SWAP_APPROVAL,
|
type: TRANSACTION_TYPES.SWAP_APPROVAL,
|
||||||
sourceTokenSymbol: sourceTokenInfo.symbol,
|
sourceTokenSymbol: sourceTokenInfo.symbol,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
@ -712,7 +712,7 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => {
|
|||||||
...tradeTxMeta,
|
...tradeTxMeta,
|
||||||
sourceTokenSymbol: sourceTokenInfo.symbol,
|
sourceTokenSymbol: sourceTokenInfo.symbol,
|
||||||
destinationTokenSymbol: destinationTokenInfo.symbol,
|
destinationTokenSymbol: destinationTokenInfo.symbol,
|
||||||
transactionCategory: TRANSACTION_CATEGORIES.SWAP,
|
type: TRANSACTION_TYPES.SWAP,
|
||||||
destinationTokenDecimals: destinationTokenInfo.decimals,
|
destinationTokenDecimals: destinationTokenInfo.decimals,
|
||||||
destinationTokenAddress: destinationTokenInfo.address,
|
destinationTokenAddress: destinationTokenInfo.address,
|
||||||
swapMetaData,
|
swapMetaData,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
TRANSACTION_TYPES,
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
} from '../../../../shared/constants/transaction';
|
} from '../../../../shared/constants/transaction';
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ export const PRIORITY_STATUS_HASH = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const TOKEN_CATEGORY_HASH = {
|
export const TOKEN_CATEGORY_HASH = {
|
||||||
[TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE]: true,
|
[TRANSACTION_TYPES.TOKEN_METHOD_APPROVE]: true,
|
||||||
[TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER]: true,
|
[TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER]: true,
|
||||||
[TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER_FROM]: true,
|
[TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM]: true,
|
||||||
};
|
};
|
||||||
|
@ -5,10 +5,9 @@ import log from 'loglevel';
|
|||||||
|
|
||||||
import { addHexPrefix } from '../../../../app/scripts/lib/util';
|
import { addHexPrefix } from '../../../../app/scripts/lib/util';
|
||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
TRANSACTION_TYPES,
|
||||||
TRANSACTION_GROUP_STATUSES,
|
TRANSACTION_GROUP_STATUSES,
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
TRANSACTION_TYPES,
|
|
||||||
} from '../../../../shared/constants/transaction';
|
} from '../../../../shared/constants/transaction';
|
||||||
import fetchWithCache from './fetch-with-cache';
|
import fetchWithCache from './fetch-with-cache';
|
||||||
|
|
||||||
@ -112,15 +111,15 @@ export function getFourBytePrefix(data = '') {
|
|||||||
/**
|
/**
|
||||||
* Given an transaction category, returns a boolean which indicates whether the transaction is calling an erc20 token method
|
* Given an transaction category, returns a boolean which indicates whether the transaction is calling an erc20 token method
|
||||||
*
|
*
|
||||||
* @param {string} transactionCategory - The category of transaction being evaluated
|
* @param {TRANSACTION_TYPES[keyof TRANSACTION_TYPES]} type - The type of transaction being evaluated
|
||||||
* @returns {boolean} whether the transaction is calling an erc20 token method
|
* @returns {boolean} whether the transaction is calling an erc20 token method
|
||||||
*/
|
*/
|
||||||
export function isTokenMethodAction(transactionCategory) {
|
export function isTokenMethodAction(type) {
|
||||||
return [
|
return [
|
||||||
TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER,
|
TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||||||
TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE,
|
TRANSACTION_TYPES.TOKEN_METHOD_APPROVE,
|
||||||
TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER_FROM,
|
TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM,
|
||||||
].includes(transactionCategory);
|
].includes(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLatestSubmittedTxWithNonce(
|
export function getLatestSubmittedTxWithNonce(
|
||||||
@ -197,39 +196,37 @@ export function getStatusKey(transaction) {
|
|||||||
*
|
*
|
||||||
* This will throw an error if the transaction category is unrecognized and no default is provided.
|
* This will throw an error if the transaction category is unrecognized and no default is provided.
|
||||||
* @param {function} t - The translation function
|
* @param {function} t - The translation function
|
||||||
* @param {TRANSACTION_CATEGORIES[keyof TRANSACTION_CATEGORIES]} transactionCategory - The transaction category constant
|
* @param {TRANSACTION_TYPES[keyof TRANSACTION_TYPES]} type - The transaction type constant
|
||||||
* @returns {string} The transaction category title
|
* @returns {string} The transaction category title
|
||||||
*/
|
*/
|
||||||
export function getTransactionCategoryTitle(t, transactionCategory) {
|
export function getTransactionTypeTitle(t, type) {
|
||||||
switch (transactionCategory) {
|
switch (type) {
|
||||||
case TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER: {
|
case TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER: {
|
||||||
return t('transfer');
|
return t('transfer');
|
||||||
}
|
}
|
||||||
case TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER_FROM: {
|
case TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM: {
|
||||||
return t('transferFrom');
|
return t('transferFrom');
|
||||||
}
|
}
|
||||||
case TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE: {
|
case TRANSACTION_TYPES.TOKEN_METHOD_APPROVE: {
|
||||||
return t('approve');
|
return t('approve');
|
||||||
}
|
}
|
||||||
case TRANSACTION_CATEGORIES.SENT_ETHER: {
|
case TRANSACTION_TYPES.SENT_ETHER: {
|
||||||
return t('sentEther');
|
return t('sentEther');
|
||||||
}
|
}
|
||||||
case TRANSACTION_CATEGORIES.CONTRACT_INTERACTION: {
|
case TRANSACTION_TYPES.CONTRACT_INTERACTION: {
|
||||||
return t('contractInteraction');
|
return t('contractInteraction');
|
||||||
}
|
}
|
||||||
case TRANSACTION_CATEGORIES.DEPLOY_CONTRACT: {
|
case TRANSACTION_TYPES.DEPLOY_CONTRACT: {
|
||||||
return t('contractDeployment');
|
return t('contractDeployment');
|
||||||
}
|
}
|
||||||
case TRANSACTION_CATEGORIES.SWAP: {
|
case TRANSACTION_TYPES.SWAP: {
|
||||||
return t('swap');
|
return t('swap');
|
||||||
}
|
}
|
||||||
case TRANSACTION_CATEGORIES.SWAP_APPROVAL: {
|
case TRANSACTION_TYPES.SWAP_APPROVAL: {
|
||||||
return t('swapApproval');
|
return t('swapApproval');
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
throw new Error(
|
throw new Error(`Unrecognized transaction type: ${type}`);
|
||||||
`Unrecognized transaction category: ${transactionCategory}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
TRANSACTION_TYPES,
|
||||||
TRANSACTION_GROUP_STATUSES,
|
TRANSACTION_GROUP_STATUSES,
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
} from '../../../../shared/constants/transaction';
|
} from '../../../../shared/constants/transaction';
|
||||||
@ -14,7 +14,7 @@ describe('Transactions utils', function () {
|
|||||||
);
|
);
|
||||||
assert.ok(tokenData);
|
assert.ok(tokenData);
|
||||||
const { name, args } = tokenData;
|
const { name, args } = tokenData;
|
||||||
assert.strictEqual(name, TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER);
|
assert.strictEqual(name, TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER);
|
||||||
const to = args._to;
|
const to = args._to;
|
||||||
const value = args._value.toString();
|
const value = args._value.toString();
|
||||||
assert.strictEqual(to, '0x50A9D56C2B8BA9A5c7f2C08C3d26E0499F23a706');
|
assert.strictEqual(to, '0x50A9D56C2B8BA9A5c7f2C08C3d26E0499F23a706');
|
||||||
|
@ -2,14 +2,14 @@ import assert from 'assert';
|
|||||||
import { ethers } from 'ethers';
|
import { ethers } from 'ethers';
|
||||||
import { renderHook } from '@testing-library/react-hooks';
|
import { renderHook } from '@testing-library/react-hooks';
|
||||||
import { useTokenData } from '../useTokenData';
|
import { useTokenData } from '../useTokenData';
|
||||||
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction';
|
import { TRANSACTION_TYPES } from '../../../../shared/constants/transaction';
|
||||||
|
|
||||||
const tests = [
|
const tests = [
|
||||||
{
|
{
|
||||||
data:
|
data:
|
||||||
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000003a98',
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000003a98',
|
||||||
tokenData: {
|
tokenData: {
|
||||||
name: TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER,
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||||||
args: [
|
args: [
|
||||||
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||||||
ethers.BigNumber.from(15000),
|
ethers.BigNumber.from(15000),
|
||||||
@ -20,7 +20,7 @@ const tests = [
|
|||||||
data:
|
data:
|
||||||
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a9700000000000000000000000000000000000000000000000000000000000061a8',
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a9700000000000000000000000000000000000000000000000000000000000061a8',
|
||||||
tokenData: {
|
tokenData: {
|
||||||
name: TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER,
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||||||
args: [
|
args: [
|
||||||
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||||||
ethers.BigNumber.from(25000),
|
ethers.BigNumber.from(25000),
|
||||||
@ -31,7 +31,7 @@ const tests = [
|
|||||||
data:
|
data:
|
||||||
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000002710',
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000002710',
|
||||||
tokenData: {
|
tokenData: {
|
||||||
name: TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER,
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||||||
args: [
|
args: [
|
||||||
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||||||
ethers.BigNumber.from(10000),
|
ethers.BigNumber.from(10000),
|
||||||
|
@ -19,7 +19,7 @@ import { getMessage } from '../../helpers/utils/i18n-helper';
|
|||||||
import messages from '../../../../app/_locales/en/messages.json';
|
import messages from '../../../../app/_locales/en/messages.json';
|
||||||
import { ASSET_ROUTE, DEFAULT_ROUTE } from '../../helpers/constants/routes';
|
import { ASSET_ROUTE, DEFAULT_ROUTE } from '../../helpers/constants/routes';
|
||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
TRANSACTION_TYPES,
|
||||||
TRANSACTION_GROUP_CATEGORIES,
|
TRANSACTION_GROUP_CATEGORIES,
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
} from '../../../../shared/constants/transaction';
|
} from '../../../../shared/constants/transaction';
|
||||||
@ -106,7 +106,7 @@ const expectedResults = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Swap ETH to ABC',
|
title: 'Swap ETH to ABC',
|
||||||
category: TRANSACTION_CATEGORIES.SWAP,
|
category: TRANSACTION_TYPES.SWAP,
|
||||||
subtitle: '',
|
subtitle: '',
|
||||||
subtitleContainsOrigin: false,
|
subtitleContainsOrigin: false,
|
||||||
date: 'May 12, 2020',
|
date: 'May 12, 2020',
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { TRANSACTION_CATEGORIES } from '../../../shared/constants/transaction';
|
import { TRANSACTION_TYPES } from '../../../shared/constants/transaction';
|
||||||
import { ETH_SWAPS_TOKEN_OBJECT } from '../helpers/constants/swaps';
|
import { ETH_SWAPS_TOKEN_OBJECT } from '../helpers/constants/swaps';
|
||||||
import { getSwapsTokensReceivedFromTxMeta } from '../pages/swaps/swaps.util';
|
import { getSwapsTokensReceivedFromTxMeta } from '../pages/swaps/swaps.util';
|
||||||
import { useTokenFiatAmount } from './useTokenFiatAmount';
|
import { useTokenFiatAmount } from './useTokenFiatAmount';
|
||||||
@ -25,7 +25,7 @@ import { useTokenFiatAmount } from './useTokenFiatAmount';
|
|||||||
export function useSwappedTokenValue(transactionGroup, currentAsset) {
|
export function useSwappedTokenValue(transactionGroup, currentAsset) {
|
||||||
const { symbol, decimals, address } = currentAsset;
|
const { symbol, decimals, address } = currentAsset;
|
||||||
const { primaryTransaction, initialTransaction } = transactionGroup;
|
const { primaryTransaction, initialTransaction } = transactionGroup;
|
||||||
const { transactionCategory } = initialTransaction;
|
const { type } = initialTransaction;
|
||||||
const { from: senderAddress } = initialTransaction.txParams || {};
|
const { from: senderAddress } = initialTransaction.txParams || {};
|
||||||
|
|
||||||
const isViewingReceivedTokenFromSwap =
|
const isViewingReceivedTokenFromSwap =
|
||||||
@ -34,8 +34,7 @@ export function useSwappedTokenValue(transactionGroup, currentAsset) {
|
|||||||
primaryTransaction.destinationTokenSymbol === 'ETH');
|
primaryTransaction.destinationTokenSymbol === 'ETH');
|
||||||
|
|
||||||
const swapTokenValue =
|
const swapTokenValue =
|
||||||
transactionCategory === TRANSACTION_CATEGORIES.SWAP &&
|
type === TRANSACTION_TYPES.SWAP && isViewingReceivedTokenFromSwap
|
||||||
isViewingReceivedTokenFromSwap
|
|
||||||
? getSwapsTokensReceivedFromTxMeta(
|
? getSwapsTokensReceivedFromTxMeta(
|
||||||
primaryTransaction.destinationTokenSymbol,
|
primaryTransaction.destinationTokenSymbol,
|
||||||
initialTransaction,
|
initialTransaction,
|
||||||
@ -43,8 +42,7 @@ export function useSwappedTokenValue(transactionGroup, currentAsset) {
|
|||||||
senderAddress,
|
senderAddress,
|
||||||
decimals,
|
decimals,
|
||||||
)
|
)
|
||||||
: transactionCategory === TRANSACTION_CATEGORIES.SWAP &&
|
: type === TRANSACTION_TYPES.SWAP && primaryTransaction.swapTokenValue;
|
||||||
primaryTransaction.swapTokenValue;
|
|
||||||
|
|
||||||
const isNegative =
|
const isNegative =
|
||||||
typeof swapTokenValue === 'string'
|
typeof swapTokenValue === 'string'
|
||||||
|
@ -2,7 +2,7 @@ import { useSelector } from 'react-redux';
|
|||||||
import { getKnownMethodData } from '../selectors/selectors';
|
import { getKnownMethodData } from '../selectors/selectors';
|
||||||
import {
|
import {
|
||||||
getStatusKey,
|
getStatusKey,
|
||||||
getTransactionCategoryTitle,
|
getTransactionTypeTitle,
|
||||||
} from '../helpers/utils/transactions.util';
|
} from '../helpers/utils/transactions.util';
|
||||||
import { camelCaseToCapitalize } from '../helpers/utils/common.util';
|
import { camelCaseToCapitalize } from '../helpers/utils/common.util';
|
||||||
import { PRIMARY, SECONDARY } from '../helpers/constants/common';
|
import { PRIMARY, SECONDARY } from '../helpers/constants/common';
|
||||||
@ -18,7 +18,7 @@ import {
|
|||||||
} from '../helpers/constants/transactions';
|
} from '../helpers/constants/transactions';
|
||||||
import { getTokens } from '../ducks/metamask/metamask';
|
import { getTokens } from '../ducks/metamask/metamask';
|
||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
TRANSACTION_TYPES,
|
||||||
TRANSACTION_GROUP_CATEGORIES,
|
TRANSACTION_GROUP_CATEGORIES,
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
} from '../../../shared/constants/transaction';
|
} from '../../../shared/constants/transaction';
|
||||||
@ -62,7 +62,7 @@ export function useTransactionDisplayData(transactionGroup) {
|
|||||||
const t = useI18nContext();
|
const t = useI18nContext();
|
||||||
const { initialTransaction, primaryTransaction } = transactionGroup;
|
const { initialTransaction, primaryTransaction } = transactionGroup;
|
||||||
// initialTransaction contains the data we need to derive the primary purpose of this transaction group
|
// initialTransaction contains the data we need to derive the primary purpose of this transaction group
|
||||||
const { transactionCategory } = initialTransaction;
|
const { type } = initialTransaction;
|
||||||
|
|
||||||
const { from: senderAddress, to } = initialTransaction.txParams || {};
|
const { from: senderAddress, to } = initialTransaction.txParams || {};
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ export function useTransactionDisplayData(transactionGroup) {
|
|||||||
|
|
||||||
// This value is used to determine whether we should look inside txParams.data
|
// This value is used to determine whether we should look inside txParams.data
|
||||||
// to pull out and render token related information
|
// to pull out and render token related information
|
||||||
const isTokenCategory = TOKEN_CATEGORY_HASH[transactionCategory];
|
const isTokenCategory = TOKEN_CATEGORY_HASH[type];
|
||||||
|
|
||||||
// these values are always instantiated because they are either
|
// these values are always instantiated because they are either
|
||||||
// used by or returned from hooks. Hooks must be called at the top level,
|
// used by or returned from hooks. Hooks must be called at the top level,
|
||||||
@ -145,12 +145,12 @@ export function useTransactionDisplayData(transactionGroup) {
|
|||||||
// 6. Swap
|
// 6. Swap
|
||||||
// 7. Swap Approval
|
// 7. Swap Approval
|
||||||
|
|
||||||
if (transactionCategory === null || transactionCategory === undefined) {
|
if (type === null || type === undefined) {
|
||||||
category = TRANSACTION_GROUP_CATEGORIES.SIGNATURE_REQUEST;
|
category = TRANSACTION_GROUP_CATEGORIES.SIGNATURE_REQUEST;
|
||||||
title = t('signatureRequest');
|
title = t('signatureRequest');
|
||||||
subtitle = origin;
|
subtitle = origin;
|
||||||
subtitleContainsOrigin = true;
|
subtitleContainsOrigin = true;
|
||||||
} else if (transactionCategory === TRANSACTION_CATEGORIES.SWAP) {
|
} else if (type === TRANSACTION_TYPES.SWAP) {
|
||||||
category = TRANSACTION_GROUP_CATEGORIES.SWAP;
|
category = TRANSACTION_GROUP_CATEGORIES.SWAP;
|
||||||
title = t('swapTokenToToken', [
|
title = t('swapTokenToToken', [
|
||||||
initialTransaction.sourceTokenSymbol,
|
initialTransaction.sourceTokenSymbol,
|
||||||
@ -170,48 +170,43 @@ export function useTransactionDisplayData(transactionGroup) {
|
|||||||
} else {
|
} else {
|
||||||
prefix = '-';
|
prefix = '-';
|
||||||
}
|
}
|
||||||
} else if (transactionCategory === TRANSACTION_CATEGORIES.SWAP_APPROVAL) {
|
} else if (type === TRANSACTION_TYPES.SWAP_APPROVAL) {
|
||||||
category = TRANSACTION_GROUP_CATEGORIES.APPROVAL;
|
category = TRANSACTION_GROUP_CATEGORIES.APPROVAL;
|
||||||
title = t('swapApproval', [primaryTransaction.sourceTokenSymbol]);
|
title = t('swapApproval', [primaryTransaction.sourceTokenSymbol]);
|
||||||
subtitle = origin;
|
subtitle = origin;
|
||||||
subtitleContainsOrigin = true;
|
subtitleContainsOrigin = true;
|
||||||
primarySuffix = primaryTransaction.sourceTokenSymbol;
|
primarySuffix = primaryTransaction.sourceTokenSymbol;
|
||||||
} else if (
|
} else if (type === TRANSACTION_TYPES.TOKEN_METHOD_APPROVE) {
|
||||||
transactionCategory === TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE
|
|
||||||
) {
|
|
||||||
category = TRANSACTION_GROUP_CATEGORIES.APPROVAL;
|
category = TRANSACTION_GROUP_CATEGORIES.APPROVAL;
|
||||||
prefix = '';
|
prefix = '';
|
||||||
title = t('approveSpendLimit', [token?.symbol || t('token')]);
|
title = t('approveSpendLimit', [token?.symbol || t('token')]);
|
||||||
subtitle = origin;
|
subtitle = origin;
|
||||||
subtitleContainsOrigin = true;
|
subtitleContainsOrigin = true;
|
||||||
} else if (
|
} else if (
|
||||||
transactionCategory === TRANSACTION_CATEGORIES.DEPLOY_CONTRACT ||
|
type === TRANSACTION_TYPES.DEPLOY_CONTRACT ||
|
||||||
transactionCategory === TRANSACTION_CATEGORIES.CONTRACT_INTERACTION
|
type === TRANSACTION_TYPES.CONTRACT_INTERACTION
|
||||||
) {
|
) {
|
||||||
category = TRANSACTION_GROUP_CATEGORIES.INTERACTION;
|
category = TRANSACTION_GROUP_CATEGORIES.INTERACTION;
|
||||||
const transactionCategoryTitle = getTransactionCategoryTitle(
|
const transactionTypeTitle = getTransactionTypeTitle(t, type);
|
||||||
t,
|
|
||||||
transactionCategory,
|
|
||||||
);
|
|
||||||
title =
|
title =
|
||||||
(methodData?.name && camelCaseToCapitalize(methodData.name)) ||
|
(methodData?.name && camelCaseToCapitalize(methodData.name)) ||
|
||||||
transactionCategoryTitle;
|
transactionTypeTitle;
|
||||||
subtitle = origin;
|
subtitle = origin;
|
||||||
subtitleContainsOrigin = true;
|
subtitleContainsOrigin = true;
|
||||||
} else if (transactionCategory === TRANSACTION_CATEGORIES.INCOMING) {
|
} else if (type === TRANSACTION_TYPES.INCOMING) {
|
||||||
category = TRANSACTION_GROUP_CATEGORIES.RECEIVE;
|
category = TRANSACTION_GROUP_CATEGORIES.RECEIVE;
|
||||||
title = t('receive');
|
title = t('receive');
|
||||||
prefix = '';
|
prefix = '';
|
||||||
subtitle = t('fromAddress', [shortenAddress(senderAddress)]);
|
subtitle = t('fromAddress', [shortenAddress(senderAddress)]);
|
||||||
} else if (
|
} else if (
|
||||||
transactionCategory === TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER_FROM ||
|
type === TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM ||
|
||||||
transactionCategory === TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER
|
type === TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER
|
||||||
) {
|
) {
|
||||||
category = TRANSACTION_GROUP_CATEGORIES.SEND;
|
category = TRANSACTION_GROUP_CATEGORIES.SEND;
|
||||||
title = t('sendSpecifiedTokens', [token?.symbol || t('token')]);
|
title = t('sendSpecifiedTokens', [token?.symbol || t('token')]);
|
||||||
recipientAddress = getTokenAddressParam(tokenData);
|
recipientAddress = getTokenAddressParam(tokenData);
|
||||||
subtitle = t('toAddress', [shortenAddress(recipientAddress)]);
|
subtitle = t('toAddress', [shortenAddress(recipientAddress)]);
|
||||||
} else if (transactionCategory === TRANSACTION_CATEGORIES.SENT_ETHER) {
|
} else if (type === TRANSACTION_TYPES.SENT_ETHER) {
|
||||||
category = TRANSACTION_GROUP_CATEGORIES.SEND;
|
category = TRANSACTION_GROUP_CATEGORIES.SEND;
|
||||||
title = t('sendETH');
|
title = t('sendETH');
|
||||||
subtitle = t('toAddress', [shortenAddress(recipientAddress)]);
|
subtitle = t('toAddress', [shortenAddress(recipientAddress)]);
|
||||||
@ -241,15 +236,12 @@ export function useTransactionDisplayData(transactionGroup) {
|
|||||||
subtitle,
|
subtitle,
|
||||||
subtitleContainsOrigin,
|
subtitleContainsOrigin,
|
||||||
primaryCurrency:
|
primaryCurrency:
|
||||||
transactionCategory === TRANSACTION_CATEGORIES.SWAP && isPending
|
type === TRANSACTION_TYPES.SWAP && isPending ? '' : primaryCurrency,
|
||||||
? ''
|
|
||||||
: primaryCurrency,
|
|
||||||
senderAddress,
|
senderAddress,
|
||||||
recipientAddress,
|
recipientAddress,
|
||||||
secondaryCurrency:
|
secondaryCurrency:
|
||||||
(isTokenCategory && !tokenFiatAmount) ||
|
(isTokenCategory && !tokenFiatAmount) ||
|
||||||
(transactionCategory === TRANSACTION_CATEGORIES.SWAP &&
|
(type === TRANSACTION_TYPES.SWAP && !swapTokenFiatAmount)
|
||||||
!swapTokenFiatAmount)
|
|
||||||
? undefined
|
? undefined
|
||||||
: secondaryCurrency,
|
: secondaryCurrency,
|
||||||
displayedStatusKey,
|
displayedStatusKey,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction';
|
import { TRANSACTION_TYPES } from '../../../../shared/constants/transaction';
|
||||||
import { decimalToHex } from '../../helpers/utils/conversions.util';
|
import { decimalToHex } from '../../helpers/utils/conversions.util';
|
||||||
import {
|
import {
|
||||||
calcTokenValue,
|
calcTokenValue,
|
||||||
@ -14,7 +14,7 @@ export function getCustomTxParamsData(
|
|||||||
|
|
||||||
if (!tokenData) {
|
if (!tokenData) {
|
||||||
throw new Error('Invalid data');
|
throw new Error('Invalid data');
|
||||||
} else if (tokenData.name !== TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE) {
|
} else if (tokenData.name !== TRANSACTION_TYPES.TOKEN_METHOD_APPROVE) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid data; should be 'approve' method, but instead is '${tokenData.name}'`,
|
`Invalid data; should be 'approve' method, but instead is '${tokenData.name}'`,
|
||||||
);
|
);
|
||||||
|
@ -19,10 +19,10 @@ import { hexToDecimal } from '../../helpers/utils/conversions.util';
|
|||||||
import AdvancedGasInputs from '../../components/app/gas-customization/advanced-gas-inputs';
|
import AdvancedGasInputs from '../../components/app/gas-customization/advanced-gas-inputs';
|
||||||
import TextField from '../../components/ui/text-field';
|
import TextField from '../../components/ui/text-field';
|
||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
TRANSACTION_TYPES,
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
} from '../../../../shared/constants/transaction';
|
} from '../../../../shared/constants/transaction';
|
||||||
import { getTransactionCategoryTitle } from '../../helpers/utils/transactions.util';
|
import { getTransactionTypeTitle } from '../../helpers/utils/transactions.util';
|
||||||
|
|
||||||
export default class ConfirmTransactionBase extends Component {
|
export default class ConfirmTransactionBase extends Component {
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
@ -87,7 +87,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
advancedInlineGasShown: PropTypes.bool,
|
advancedInlineGasShown: PropTypes.bool,
|
||||||
insufficientBalance: PropTypes.bool,
|
insufficientBalance: PropTypes.bool,
|
||||||
hideFiatConversion: PropTypes.bool,
|
hideFiatConversion: PropTypes.bool,
|
||||||
transactionCategory: PropTypes.string,
|
type: PropTypes.string,
|
||||||
getNextNonce: PropTypes.func,
|
getNextNonce: PropTypes.func,
|
||||||
nextNonce: PropTypes.number,
|
nextNonce: PropTypes.number,
|
||||||
tryReverseResolveAddress: PropTypes.func.isRequired,
|
tryReverseResolveAddress: PropTypes.func.isRequired,
|
||||||
@ -218,7 +218,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
functionType:
|
functionType:
|
||||||
actionKey ||
|
actionKey ||
|
||||||
getMethodName(methodData.name) ||
|
getMethodName(methodData.name) ||
|
||||||
TRANSACTION_CATEGORIES.CONTRACT_INTERACTION,
|
TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
||||||
origin,
|
origin,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -395,7 +395,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
functionType:
|
functionType:
|
||||||
actionKey ||
|
actionKey ||
|
||||||
getMethodName(methodData.name) ||
|
getMethodName(methodData.name) ||
|
||||||
TRANSACTION_CATEGORIES.CONTRACT_INTERACTION,
|
TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
||||||
origin,
|
origin,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -450,7 +450,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
functionType:
|
functionType:
|
||||||
actionKey ||
|
actionKey ||
|
||||||
getMethodName(methodData.name) ||
|
getMethodName(methodData.name) ||
|
||||||
TRANSACTION_CATEGORIES.CONTRACT_INTERACTION,
|
TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
||||||
origin,
|
origin,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -500,7 +500,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
functionType:
|
functionType:
|
||||||
actionKey ||
|
actionKey ||
|
||||||
getMethodName(methodData.name) ||
|
getMethodName(methodData.name) ||
|
||||||
TRANSACTION_CATEGORIES.CONTRACT_INTERACTION,
|
TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
||||||
origin,
|
origin,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -667,7 +667,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
customNonceValue,
|
customNonceValue,
|
||||||
assetImage,
|
assetImage,
|
||||||
unapprovedTxCount,
|
unapprovedTxCount,
|
||||||
transactionCategory,
|
type,
|
||||||
hideSenderToRecipient,
|
hideSenderToRecipient,
|
||||||
showAccountInHeader,
|
showAccountInHeader,
|
||||||
txData,
|
txData,
|
||||||
@ -690,8 +690,8 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
|
|
||||||
let functionType = getMethodName(name);
|
let functionType = getMethodName(name);
|
||||||
if (!functionType) {
|
if (!functionType) {
|
||||||
if (transactionCategory) {
|
if (type) {
|
||||||
functionType = getTransactionCategoryTitle(t, transactionCategory);
|
functionType = getTransactionTypeTitle(t, type);
|
||||||
} else {
|
} else {
|
||||||
functionType = t('contractInteraction');
|
functionType = t('contractInteraction');
|
||||||
}
|
}
|
||||||
|
@ -81,12 +81,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
provider: { chainId },
|
provider: { chainId },
|
||||||
} = metamask;
|
} = metamask;
|
||||||
const { tokenData, txData, tokenProps, nonce } = confirmTransaction;
|
const { tokenData, txData, tokenProps, nonce } = confirmTransaction;
|
||||||
const {
|
const { txParams = {}, lastGasPrice, id: transactionId, type } = txData;
|
||||||
txParams = {},
|
|
||||||
lastGasPrice,
|
|
||||||
id: transactionId,
|
|
||||||
transactionCategory,
|
|
||||||
} = txData;
|
|
||||||
const transaction =
|
const transaction =
|
||||||
Object.values(unapprovedTxs).find(
|
Object.values(unapprovedTxs).find(
|
||||||
({ id }) => id === (transactionId || Number(paramsTransactionId)),
|
({ id }) => id === (transactionId || Number(paramsTransactionId)),
|
||||||
@ -189,7 +184,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
hideSubtitle: !isMainnet && !showFiatInTestnets,
|
hideSubtitle: !isMainnet && !showFiatInTestnets,
|
||||||
hideFiatConversion: !isMainnet && !showFiatInTestnets,
|
hideFiatConversion: !isMainnet && !showFiatInTestnets,
|
||||||
metaMetricsSendCount,
|
metaMetricsSendCount,
|
||||||
transactionCategory,
|
type,
|
||||||
nextNonce,
|
nextNonce,
|
||||||
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
||||||
isMainnet,
|
isMainnet,
|
||||||
|
@ -15,7 +15,7 @@ import {
|
|||||||
ENCRYPTION_PUBLIC_KEY_REQUEST_PATH,
|
ENCRYPTION_PUBLIC_KEY_REQUEST_PATH,
|
||||||
} from '../../helpers/constants/routes';
|
} from '../../helpers/constants/routes';
|
||||||
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
|
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
|
||||||
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction';
|
import { TRANSACTION_TYPES } from '../../../../shared/constants/transaction';
|
||||||
|
|
||||||
export default class ConfirmTransactionSwitch extends Component {
|
export default class ConfirmTransactionSwitch extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
@ -24,29 +24,29 @@ export default class ConfirmTransactionSwitch extends Component {
|
|||||||
|
|
||||||
redirectToTransaction() {
|
redirectToTransaction() {
|
||||||
const { txData } = this.props;
|
const { txData } = this.props;
|
||||||
const { id, txParams: { data } = {}, transactionCategory } = txData;
|
const { id, txParams: { data } = {}, type } = txData;
|
||||||
|
|
||||||
if (transactionCategory === TRANSACTION_CATEGORIES.DEPLOY_CONTRACT) {
|
if (type === TRANSACTION_TYPES.DEPLOY_CONTRACT) {
|
||||||
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_DEPLOY_CONTRACT_PATH}`;
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_DEPLOY_CONTRACT_PATH}`;
|
||||||
return <Redirect to={{ pathname }} />;
|
return <Redirect to={{ pathname }} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transactionCategory === TRANSACTION_CATEGORIES.SENT_ETHER) {
|
if (type === TRANSACTION_TYPES.SENT_ETHER) {
|
||||||
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_ETHER_PATH}`;
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_ETHER_PATH}`;
|
||||||
return <Redirect to={{ pathname }} />;
|
return <Redirect to={{ pathname }} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
switch (transactionCategory) {
|
switch (type) {
|
||||||
case TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER: {
|
case TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER: {
|
||||||
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_TOKEN_PATH}`;
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_TOKEN_PATH}`;
|
||||||
return <Redirect to={{ pathname }} />;
|
return <Redirect to={{ pathname }} />;
|
||||||
}
|
}
|
||||||
case TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE: {
|
case TRANSACTION_TYPES.TOKEN_METHOD_APPROVE: {
|
||||||
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_APPROVE_PATH}`;
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_APPROVE_PATH}`;
|
||||||
return <Redirect to={{ pathname }} />;
|
return <Redirect to={{ pathname }} />;
|
||||||
}
|
}
|
||||||
case TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER_FROM: {
|
case TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM: {
|
||||||
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TRANSFER_FROM_PATH}`;
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TRANSFER_FROM_PATH}`;
|
||||||
return <Redirect to={{ pathname }} />;
|
return <Redirect to={{ pathname }} />;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
const transaction = totalUnconfirmed
|
const transaction = totalUnconfirmed
|
||||||
? unapprovedTxs[id] || unconfirmedTransactions[0]
|
? unapprovedTxs[id] || unconfirmedTransactions[0]
|
||||||
: {};
|
: {};
|
||||||
const { id: transactionId, transactionCategory } = transaction;
|
const { id: transactionId, type } = transaction;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalUnapprovedCount: totalUnconfirmed,
|
totalUnapprovedCount: totalUnconfirmed,
|
||||||
@ -38,7 +38,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
paramsTransactionId: id && String(id),
|
paramsTransactionId: id && String(id),
|
||||||
transactionId: transactionId && String(transactionId),
|
transactionId: transactionId && String(transactionId),
|
||||||
transaction,
|
transaction,
|
||||||
isTokenMethodAction: isTokenMethodAction(transactionCategory),
|
isTokenMethodAction: isTokenMethodAction(type),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import {
|
|||||||
KOVAN_NETWORK_ID,
|
KOVAN_NETWORK_ID,
|
||||||
MAINNET_CHAIN_ID,
|
MAINNET_CHAIN_ID,
|
||||||
} from '../../../../shared/constants/network';
|
} from '../../../../shared/constants/network';
|
||||||
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction';
|
import { TRANSACTION_TYPES } from '../../../../shared/constants/transaction';
|
||||||
import {
|
import {
|
||||||
unconfirmedTransactionsCountSelector,
|
unconfirmedTransactionsCountSelector,
|
||||||
sendTokenTokenAmountAndToAddressSelector,
|
sendTokenTokenAmountAndToAddressSelector,
|
||||||
@ -52,7 +52,7 @@ describe('Confirm Transaction Selector', function () {
|
|||||||
const state = {
|
const state = {
|
||||||
confirmTransaction: {
|
confirmTransaction: {
|
||||||
tokenData: {
|
tokenData: {
|
||||||
name: TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER,
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||||||
args: getEthersArrayLikeFromObj({
|
args: getEthersArrayLikeFromObj({
|
||||||
_to: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
_to: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||||||
_value: { toString: () => '1' },
|
_value: { toString: () => '1' },
|
||||||
|
@ -6,7 +6,6 @@ import {
|
|||||||
import { hexToDecimal } from '../helpers/utils/conversions.util';
|
import { hexToDecimal } from '../helpers/utils/conversions.util';
|
||||||
import txHelper from '../../lib/tx-helper';
|
import txHelper from '../../lib/tx-helper';
|
||||||
import {
|
import {
|
||||||
TRANSACTION_CATEGORIES,
|
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
TRANSACTION_TYPES,
|
TRANSACTION_TYPES,
|
||||||
} from '../../../shared/constants/transaction';
|
} from '../../../shared/constants/transaction';
|
||||||
@ -229,13 +228,9 @@ export const nonceSortedTransactionsSelector = createSelector(
|
|||||||
status,
|
status,
|
||||||
type,
|
type,
|
||||||
time: txTime,
|
time: txTime,
|
||||||
transactionCategory,
|
|
||||||
} = transaction;
|
} = transaction;
|
||||||
|
|
||||||
if (
|
if (typeof nonce === 'undefined' || type === TRANSACTION_TYPES.INCOMING) {
|
||||||
typeof nonce === 'undefined' ||
|
|
||||||
transactionCategory === TRANSACTION_CATEGORIES.INCOMING
|
|
||||||
) {
|
|
||||||
const transactionGroup = {
|
const transactionGroup = {
|
||||||
transactions: [transaction],
|
transactions: [transaction],
|
||||||
initialTransaction: transaction,
|
initialTransaction: transaction,
|
||||||
@ -244,7 +239,7 @@ export const nonceSortedTransactionsSelector = createSelector(
|
|||||||
hasCancelled: false,
|
hasCancelled: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (transactionCategory === TRANSACTION_CATEGORIES.INCOMING) {
|
if (type === TRANSACTION_TYPES.INCOMING) {
|
||||||
incomingTransactionGroups.push(transactionGroup);
|
incomingTransactionGroups.push(transactionGroup);
|
||||||
} else {
|
} else {
|
||||||
insertTransactionGroupByTime(
|
insertTransactionGroupByTime(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user