@@ -60,6 +60,7 @@ import {
6060 getTokenStandardAndDetails ,
6161 showModal ,
6262 addUnapprovedTransactionAndRouteToConfirmationPage ,
63+ updateTransactionSendFlowHistory ,
6364} from '../../store/actions' ;
6465import { setCustomGasLimit } from '../gas/gas.duck' ;
6566import {
@@ -110,6 +111,7 @@ import {
110111import { readAddressAsContract } from '../../../shared/modules/contract-utils' ;
111112import { INVALID_ASSET_TYPE } from '../../helpers/constants/error-keys' ;
112113import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils' ;
114+ import { getValueFromWeiHex } from '../../helpers/utils/confirm-tx.util' ;
113115// typedefs
114116/**
115117 * @typedef {import('@reduxjs/toolkit').PayloadAction } PayloadAction
@@ -684,12 +686,19 @@ export const initialState = {
684686 // Layer 1 gas fee total on multi-layer fee networks
685687 layer1GasTotal : '0x0' ,
686688 } ,
689+ history : [ ] ,
687690} ;
688691
689692const slice = createSlice ( {
690693 name,
691694 initialState,
692695 reducers : {
696+ addHistoryEntry : ( state , action ) => {
697+ state . history . push ( {
698+ entry : action . payload ,
699+ timestamp : Date . now ( ) ,
700+ } ) ;
701+ } ,
693702 /**
694703 * update current amount.value in state and run post update validation of
695704 * the amount field and the send state. Recomputes the draftTransaction
@@ -1402,9 +1411,10 @@ const {
14021411 updateGasLimit,
14031412 validateRecipientUserInput,
14041413 updateRecipientSearchMode,
1414+ addHistoryEntry,
14051415} = actions ;
14061416
1407- export { useDefaultGas , useCustomGas , updateGasLimit } ;
1417+ export { useDefaultGas , useCustomGas , updateGasLimit , addHistoryEntry } ;
14081418
14091419// Action Creators
14101420
@@ -1421,6 +1431,9 @@ export { useDefaultGas, useCustomGas, updateGasLimit };
14211431 */
14221432export function updateGasPrice ( gasPrice ) {
14231433 return ( dispatch ) => {
1434+ dispatch (
1435+ addHistoryEntry ( `sendFlow - user set legacy gasPrice to ${ gasPrice } ` ) ,
1436+ ) ;
14241437 dispatch (
14251438 actions . updateGasFees ( {
14261439 gasPrice,
@@ -1452,8 +1465,36 @@ export function resetSendState() {
14521465 */
14531466export function updateSendAmount ( amount ) {
14541467 return async ( dispatch , getState ) => {
1455- await dispatch ( actions . updateSendAmount ( amount ) ) ;
14561468 const state = getState ( ) ;
1469+ let logAmount = amount ;
1470+ if ( state [ name ] . asset . type === ASSET_TYPES . TOKEN ) {
1471+ const multiplier = Math . pow (
1472+ 10 ,
1473+ Number ( state [ name ] . asset . details ?. decimals || 0 ) ,
1474+ ) ;
1475+ const decimalValueString = conversionUtil ( addHexPrefix ( amount ) , {
1476+ fromNumericBase : 'hex' ,
1477+ toNumericBase : 'dec' ,
1478+ toCurrency : state [ name ] . asset . details ?. symbol ,
1479+ conversionRate : multiplier ,
1480+ invertConversionRate : true ,
1481+ } ) ;
1482+
1483+ logAmount = `${ Number ( decimalValueString ) ? decimalValueString : '' } ${
1484+ state [ name ] . asset . details ?. symbol
1485+ } `;
1486+ } else {
1487+ const ethValue = getValueFromWeiHex ( {
1488+ value : amount ,
1489+ toCurrency : ETH ,
1490+ numberOfDecimals : 8 ,
1491+ } ) ;
1492+ logAmount = `${ ethValue } ${ ETH } ` ;
1493+ }
1494+ await dispatch (
1495+ addHistoryEntry ( `sendFlow - user set amount to ${ logAmount } ` ) ,
1496+ ) ;
1497+ await dispatch ( actions . updateSendAmount ( amount ) ) ;
14571498 if ( state . send . amount . mode === AMOUNT_MODES . MAX ) {
14581499 await dispatch ( actions . updateAmountMode ( AMOUNT_MODES . INPUT ) ) ;
14591500 }
@@ -1482,6 +1523,19 @@ export function updateSendAmount(amount) {
14821523 */
14831524export function updateSendAsset ( { type, details } ) {
14841525 return async ( dispatch , getState ) => {
1526+ dispatch ( addHistoryEntry ( `sendFlow - user set asset type to ${ type } ` ) ) ;
1527+ dispatch (
1528+ addHistoryEntry (
1529+ `sendFlow - user set asset symbol to ${ details ?. symbol ?? 'undefined' } ` ,
1530+ ) ,
1531+ ) ;
1532+ dispatch (
1533+ addHistoryEntry (
1534+ `sendFlow - user set asset address to ${
1535+ details ?. address ?? 'undefined'
1536+ } `,
1537+ ) ,
1538+ ) ;
14851539 const state = getState ( ) ;
14861540 let { balance, error } = state . send . asset ;
14871541 const userAddress = state . send . account . address ?? getSelectedAddress ( state ) ;
@@ -1580,6 +1634,11 @@ export function updateSendAsset({ type, details }) {
15801634 * it only applicable for use within action creators.
15811635 */
15821636const debouncedValidateRecipientUserInput = debounce ( ( dispatch , payload ) => {
1637+ dispatch (
1638+ addHistoryEntry (
1639+ `sendFlow - user typed ${ payload . userInput } into recipient input field` ,
1640+ ) ,
1641+ ) ;
15831642 dispatch ( validateRecipientUserInput ( payload ) ) ;
15841643} , 300 ) ;
15851644
@@ -1600,6 +1659,7 @@ export function updateRecipientUserInput(userInput) {
16001659 const useTokenDetection = getUseTokenDetection ( state ) ;
16011660 const tokenAddressList = Object . keys ( getTokenList ( state ) ) ;
16021661 debouncedValidateRecipientUserInput ( dispatch , {
1662+ userInput,
16031663 chainId,
16041664 tokens,
16051665 useTokenDetection,
@@ -1610,12 +1670,22 @@ export function updateRecipientUserInput(userInput) {
16101670
16111671export function useContactListForRecipientSearch ( ) {
16121672 return ( dispatch ) => {
1673+ dispatch (
1674+ addHistoryEntry (
1675+ `sendFlow - user selected back to all on recipient screen` ,
1676+ ) ,
1677+ ) ;
16131678 dispatch ( updateRecipientSearchMode ( RECIPIENT_SEARCH_MODES . CONTACT_LIST ) ) ;
16141679 } ;
16151680}
16161681
16171682export function useMyAccountsForRecipientSearch ( ) {
16181683 return ( dispatch ) => {
1684+ dispatch (
1685+ addHistoryEntry (
1686+ `sendFlow - user selected transfer to my accounts on recipient screen` ,
1687+ ) ,
1688+ ) ;
16191689 dispatch ( updateRecipientSearchMode ( RECIPIENT_SEARCH_MODES . MY_ACCOUNTS ) ) ;
16201690 } ;
16211691}
@@ -1638,6 +1708,8 @@ export function useMyAccountsForRecipientSearch() {
16381708 */
16391709export function updateRecipient ( { address, nickname } ) {
16401710 return async ( dispatch , getState ) => {
1711+ // Do not addHistoryEntry here as this is called from a number of places
1712+ // each with significance to the user and transaction history.
16411713 const state = getState ( ) ;
16421714 const nicknameFromAddressBookEntryOrAccountName =
16431715 getAddressBookEntryOrAccountName ( state , address ) ?? '' ;
@@ -1656,6 +1728,7 @@ export function updateRecipient({ address, nickname }) {
16561728 */
16571729export function resetRecipientInput ( ) {
16581730 return async ( dispatch ) => {
1731+ await dispatch ( addHistoryEntry ( `sendFlow - user cleared recipient input` ) ) ;
16591732 await dispatch ( updateRecipientUserInput ( '' ) ) ;
16601733 await dispatch ( updateRecipient ( { address : '' , nickname : '' } ) ) ;
16611734 await dispatch ( resetEnsResolution ( ) ) ;
@@ -1675,6 +1748,9 @@ export function resetRecipientInput() {
16751748 */
16761749export function updateSendHexData ( hexData ) {
16771750 return async ( dispatch , getState ) => {
1751+ await dispatch (
1752+ addHistoryEntry ( `sendFlow - user added custom hexData ${ hexData } ` ) ,
1753+ ) ;
16781754 await dispatch ( actions . updateUserInputHexData ( hexData ) ) ;
16791755 const state = getState ( ) ;
16801756 if ( state . send . asset . type === ASSET_TYPES . NATIVE ) {
@@ -1695,9 +1771,11 @@ export function toggleSendMaxMode() {
16951771 if ( state . send . amount . mode === AMOUNT_MODES . MAX ) {
16961772 await dispatch ( actions . updateAmountMode ( AMOUNT_MODES . INPUT ) ) ;
16971773 await dispatch ( actions . updateSendAmount ( '0x0' ) ) ;
1774+ await dispatch ( addHistoryEntry ( `sendFlow - user toggled max mode off` ) ) ;
16981775 } else {
16991776 await dispatch ( actions . updateAmountMode ( AMOUNT_MODES . MAX ) ) ;
17001777 await dispatch ( actions . updateAmountToMax ( ) ) ;
1778+ await dispatch ( addHistoryEntry ( `sendFlow - user toggled max mode on` ) ) ;
17011779 }
17021780 await dispatch ( computeEstimatedGasLimit ( ) ) ;
17031781 } ;
@@ -1746,6 +1824,12 @@ export function signTransaction() {
17461824 eip1559support ? eip1559OnlyTxParamsToUpdate : txParams ,
17471825 ) ,
17481826 } ;
1827+ await dispatch (
1828+ addHistoryEntry (
1829+ `sendFlow - user clicked next and transaction should be updated in controller` ,
1830+ ) ,
1831+ ) ;
1832+ await dispatch ( updateTransactionSendFlowHistory ( id , state [ name ] . history ) ) ;
17491833 dispatch ( updateEditableParams ( id , editingTx . txParams ) ) ;
17501834 dispatch ( updateTransactionGasFees ( id , editingTx . txParams ) ) ;
17511835 } else {
@@ -1757,10 +1841,17 @@ export function signTransaction() {
17571841 ? TRANSACTION_TYPES . TOKEN_METHOD_TRANSFER_FROM
17581842 : TRANSACTION_TYPES . TOKEN_METHOD_TRANSFER ;
17591843 }
1844+ await dispatch (
1845+ addHistoryEntry (
1846+ `sendFlow - user clicked next and transaction should be added to controller` ,
1847+ ) ,
1848+ ) ;
1849+
17601850 dispatch (
17611851 addUnapprovedTransactionAndRouteToConfirmationPage (
17621852 txParams ,
17631853 transactionType ,
1854+ state [ name ] . history ,
17641855 ) ,
17651856 ) ;
17661857 }
@@ -1775,6 +1866,11 @@ export function editTransaction(
17751866) {
17761867 return async ( dispatch , getState ) => {
17771868 const state = getState ( ) ;
1869+ await dispatch (
1870+ addHistoryEntry (
1871+ `sendFlow - user clicked edit on transaction with id ${ transactionId } ` ,
1872+ ) ,
1873+ ) ;
17781874 const unapprovedTransactions = getUnapprovedTxs ( state ) ;
17791875 const transaction = unapprovedTransactions [ transactionId ] ;
17801876 const { txParams } = transaction ;
0 commit comments