1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Adding edit navigation button flow back to send token flow (#11335)

This commit is contained in:
Alex Donesky 2021-06-23 18:50:24 -05:00 committed by GitHub
parent 6fa36cdf51
commit a6e16f458e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 7 deletions

View File

@ -3,7 +3,7 @@ import {
currentCurrencySelector, currentCurrencySelector,
unconfirmedTransactionsHashSelector, unconfirmedTransactionsHashSelector,
} from '../../selectors'; } from '../../selectors';
import { getNativeCurrency } from '../metamask/metamask'; import { getNativeCurrency, getTokens } from '../metamask/metamask';
import { import {
getValueFromWeiHex, getValueFromWeiHex,
@ -25,6 +25,7 @@ const createActionType = (action) => `metamask/confirm-transaction/${action}`;
const UPDATE_TX_DATA = createActionType('UPDATE_TX_DATA'); const UPDATE_TX_DATA = createActionType('UPDATE_TX_DATA');
const UPDATE_TOKEN_DATA = createActionType('UPDATE_TOKEN_DATA'); const UPDATE_TOKEN_DATA = createActionType('UPDATE_TOKEN_DATA');
const UPDATE_TOKEN_PROPS = createActionType('UPDATE_TOKEN_PROPS');
const CLEAR_CONFIRM_TRANSACTION = createActionType('CLEAR_CONFIRM_TRANSACTION'); const CLEAR_CONFIRM_TRANSACTION = createActionType('CLEAR_CONFIRM_TRANSACTION');
const UPDATE_TRANSACTION_AMOUNTS = createActionType( const UPDATE_TRANSACTION_AMOUNTS = createActionType(
'UPDATE_TRANSACTION_AMOUNTS', 'UPDATE_TRANSACTION_AMOUNTS',
@ -37,6 +38,7 @@ const UPDATE_NONCE = createActionType('UPDATE_NONCE');
const initState = { const initState = {
txData: {}, txData: {},
tokenData: {}, tokenData: {},
tokenProps: {},
fiatTransactionAmount: '', fiatTransactionAmount: '',
fiatTransactionFee: '', fiatTransactionFee: '',
fiatTransactionTotal: '', fiatTransactionTotal: '',
@ -66,6 +68,13 @@ export default function reducer(state = initState, action = {}) {
...action.payload, ...action.payload,
}, },
}; };
case UPDATE_TOKEN_PROPS:
return {
...state,
tokenProps: {
...action.payload,
},
};
case UPDATE_TRANSACTION_AMOUNTS: { case UPDATE_TRANSACTION_AMOUNTS: {
const { const {
fiatTransactionAmount, fiatTransactionAmount,
@ -136,6 +145,13 @@ export function updateTokenData(tokenData) {
}; };
} }
export function updateTokenProps(tokenProps) {
return {
type: UPDATE_TOKEN_PROPS,
payload: tokenProps,
};
}
export function updateTransactionAmounts(amounts) { export function updateTransactionAmounts(amounts) {
return { return {
type: UPDATE_TRANSACTION_AMOUNTS, type: UPDATE_TRANSACTION_AMOUNTS,
@ -296,9 +312,20 @@ export function setTransactionToConfirm(transactionId) {
const { txParams } = transaction; const { txParams } = transaction;
if (txParams.data) { if (txParams.data) {
const { data } = txParams; const { to: tokenAddress, data } = txParams;
const tokenData = getTokenData(data); const tokenData = getTokenData(data);
const tokens = getTokens(state);
const currentToken = tokens?.find(
({ address }) => tokenAddress === address,
);
dispatch(
updateTokenProps({
decimals: currentToken?.decimals,
symbol: currentToken?.symbol,
}),
);
dispatch(updateTokenData(tokenData)); dispatch(updateTokenData(tokenData));
} }

View File

@ -12,6 +12,7 @@ import ConfirmTransactionReducer, * as actions from './confirm-transaction.duck'
const initialState = { const initialState = {
txData: {}, txData: {},
tokenData: {}, tokenData: {},
tokenProps: {},
fiatTransactionAmount: '', fiatTransactionAmount: '',
fiatTransactionFee: '', fiatTransactionFee: '',
fiatTransactionTotal: '', fiatTransactionTotal: '',
@ -307,8 +308,8 @@ describe('Confirm Transaction Duck', () => {
nonce: '', nonce: '',
tokenData: {}, tokenData: {},
tokenProps: { tokenProps: {
tokenDecimals: '', decimals: '',
tokenSymbol: '', symbol: '',
}, },
txData: { txData: {
...txData, ...txData,

View File

@ -23,6 +23,7 @@ export default function ConfirmTokenTransactionBase({
contractExchangeRate, contractExchangeRate,
conversionRate, conversionRate,
currentCurrency, currentCurrency,
onEdit,
}) { }) {
const t = useContext(I18nContext); const t = useContext(I18nContext);
@ -69,6 +70,7 @@ export default function ConfirmTokenTransactionBase({
return ( return (
<ConfirmTransactionBase <ConfirmTransactionBase
toAddress={toAddress} toAddress={toAddress}
onEdit={onEdit}
identiconAddress={tokenAddress} identiconAddress={tokenAddress}
title={tokensText} title={tokensText}
subtitleComponent={ subtitleComponent={
@ -105,4 +107,5 @@ ConfirmTokenTransactionBase.propTypes = {
contractExchangeRate: PropTypes.number, contractExchangeRate: PropTypes.number,
conversionRate: PropTypes.number, conversionRate: PropTypes.number,
currentCurrency: PropTypes.string, currentCurrency: PropTypes.string,
onEdit: PropTypes.func,
}; };

View File

@ -159,7 +159,7 @@ const contractExchangeRatesSelector = (state) =>
const tokenDecimalsSelector = createSelector( const tokenDecimalsSelector = createSelector(
tokenPropsSelector, tokenPropsSelector,
(tokenProps) => tokenProps && tokenProps.tokenDecimals, (tokenProps) => tokenProps && tokenProps.decimals,
); );
const tokenDataArgsSelector = createSelector( const tokenDataArgsSelector = createSelector(

View File

@ -58,8 +58,8 @@ describe('Confirm Transaction Selector', () => {
}), }),
}, },
tokenProps: { tokenProps: {
tokenDecimals: '2', decimals: '2',
tokenSymbol: 'META', symbol: 'META',
}, },
}, },
}; };