mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
fix confirm transaction details to match spec (#11779)
This commit is contained in:
parent
a0bd496d56
commit
751534e665
@ -690,11 +690,19 @@
|
|||||||
"message": "This network requires a “Gas price” field when submitting a transaction. Gas price is the amount you will pay pay per unit of gas."
|
"message": "This network requires a “Gas price” field when submitting a transaction. Gas price is the amount you will pay pay per unit of gas."
|
||||||
},
|
},
|
||||||
"editGasSubTextAmount": {
|
"editGasSubTextAmount": {
|
||||||
"message": "Max amount: $1",
|
"message": "$1 $2",
|
||||||
"description": "$1 represents a dollar amount"
|
"description": "$1 will be passed the editGasSubTextAmountLabel and $2 will be passed the amount in either cryptocurrency or fiat"
|
||||||
|
},
|
||||||
|
"editGasSubTextAmountLabel": {
|
||||||
|
"message": "Max amount:",
|
||||||
|
"description": "This is meant to be used as the $1 substitution editGasSubTextAmount"
|
||||||
},
|
},
|
||||||
"editGasSubTextFee": {
|
"editGasSubTextFee": {
|
||||||
"message": "Max fee: $1",
|
"message": "$1 $2",
|
||||||
|
"description": "$1 will be passed the editGasSubTextFeeLabel and $2 will be passed the fee amount in either cryptocurrency or fiat"
|
||||||
|
},
|
||||||
|
"editGasSubTextFeeLabel": {
|
||||||
|
"message": "Max fee:",
|
||||||
"description": "$1 represents a dollar amount"
|
"description": "$1 represents a dollar amount"
|
||||||
},
|
},
|
||||||
"editGasTitle": {
|
"editGasTitle": {
|
||||||
|
@ -20,9 +20,11 @@ export default function ConfirmTokenTransactionBase({
|
|||||||
tokenSymbol,
|
tokenSymbol,
|
||||||
fiatTransactionTotal,
|
fiatTransactionTotal,
|
||||||
ethTransactionTotal,
|
ethTransactionTotal,
|
||||||
|
ethTransactionTotalMaxAmount,
|
||||||
contractExchangeRate,
|
contractExchangeRate,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
currentCurrency,
|
currentCurrency,
|
||||||
|
nativeCurrency,
|
||||||
onEdit,
|
onEdit,
|
||||||
}) {
|
}) {
|
||||||
const t = useContext(I18nContext);
|
const t = useContext(I18nContext);
|
||||||
@ -85,13 +87,8 @@ export default function ConfirmTokenTransactionBase({
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
primaryTotalTextOverride={
|
primaryTotalTextOverride={`${tokensText} + ${ethTransactionTotal} ${nativeCurrency}`}
|
||||||
<div>
|
primaryTotalTextOverrideMaxAmount={`${tokensText} + ${ethTransactionTotalMaxAmount} ${nativeCurrency}`}
|
||||||
<span>{`${tokensText} + `}</span>
|
|
||||||
<img src="./images/eth.svg" height="18" alt="" />
|
|
||||||
<span>{ethTransactionTotal}</span>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
secondaryTotalTextOverride={secondaryTotalTextOverride}
|
secondaryTotalTextOverride={secondaryTotalTextOverride}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@ -108,4 +105,6 @@ ConfirmTokenTransactionBase.propTypes = {
|
|||||||
conversionRate: PropTypes.number,
|
conversionRate: PropTypes.number,
|
||||||
currentCurrency: PropTypes.string,
|
currentCurrency: PropTypes.string,
|
||||||
onEdit: PropTypes.func,
|
onEdit: PropTypes.func,
|
||||||
|
nativeCurrency: PropTypes.string,
|
||||||
|
ethTransactionTotalMaxAmount: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,8 @@ import {
|
|||||||
getTokenAddressParam,
|
getTokenAddressParam,
|
||||||
getTokenValueParam,
|
getTokenValueParam,
|
||||||
} from '../../helpers/utils/token-util';
|
} from '../../helpers/utils/token-util';
|
||||||
|
import { hexWEIToDecETH } from '../../helpers/utils/conversions.util';
|
||||||
|
import { getHexGasTotal } from '../../helpers/utils/confirm-tx.util';
|
||||||
import ConfirmTokenTransactionBase from './confirm-token-transaction-base.component';
|
import ConfirmTokenTransactionBase from './confirm-token-transaction-base.component';
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => {
|
const mapStateToProps = (state, ownProps) => {
|
||||||
@ -21,16 +23,30 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
const { id: paramsTransactionId } = params;
|
const { id: paramsTransactionId } = params;
|
||||||
const {
|
const {
|
||||||
confirmTransaction,
|
confirmTransaction,
|
||||||
metamask: { currentCurrency, conversionRate, currentNetworkTxList },
|
metamask: {
|
||||||
|
currentCurrency,
|
||||||
|
conversionRate,
|
||||||
|
currentNetworkTxList,
|
||||||
|
nativeCurrency,
|
||||||
|
},
|
||||||
} = state;
|
} = state;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
txData: {
|
txData: {
|
||||||
id: transactionId,
|
id: transactionId,
|
||||||
txParams: { to: tokenAddress, data } = {},
|
txParams: { to: tokenAddress, data, maxFeePerGas, gasPrice, gas } = {},
|
||||||
} = {},
|
} = {},
|
||||||
} = confirmTransaction;
|
} = confirmTransaction;
|
||||||
|
|
||||||
|
const ethTransactionTotalMaxAmount = Number(
|
||||||
|
hexWEIToDecETH(
|
||||||
|
getHexGasTotal({
|
||||||
|
gasPrice: maxFeePerGas ?? gasPrice,
|
||||||
|
gasLimit: gas,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
).toFixed(6);
|
||||||
|
|
||||||
const transaction =
|
const transaction =
|
||||||
currentNetworkTxList.find(
|
currentNetworkTxList.find(
|
||||||
({ id }) => id === (Number(paramsTransactionId) || transactionId),
|
({ id }) => id === (Number(paramsTransactionId) || transactionId),
|
||||||
@ -61,6 +77,8 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
contractExchangeRate,
|
contractExchangeRate,
|
||||||
fiatTransactionTotal,
|
fiatTransactionTotal,
|
||||||
ethTransactionTotal,
|
ethTransactionTotal,
|
||||||
|
ethTransactionTotalMaxAmount,
|
||||||
|
nativeCurrency,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -108,6 +108,8 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
primaryTotalTextOverride: PropTypes.string,
|
primaryTotalTextOverride: PropTypes.string,
|
||||||
secondaryTotalTextOverride: PropTypes.string,
|
secondaryTotalTextOverride: PropTypes.string,
|
||||||
gasIsLoading: PropTypes.bool,
|
gasIsLoading: PropTypes.bool,
|
||||||
|
primaryTotalTextOverrideMaxAmount: PropTypes.string,
|
||||||
|
useNativeCurrencyAsPrimaryCurrency: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
@ -280,6 +282,9 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
nextNonce,
|
nextNonce,
|
||||||
getNextNonce,
|
getNextNonce,
|
||||||
txData,
|
txData,
|
||||||
|
useNativeCurrencyAsPrimaryCurrency,
|
||||||
|
hexMaximumTransactionFee,
|
||||||
|
primaryTotalTextOverrideMaxAmount,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const { t } = this.context;
|
const { t } = this.context;
|
||||||
|
|
||||||
@ -291,6 +296,70 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderTotalMaxAmount = () => {
|
||||||
|
if (
|
||||||
|
primaryTotalTextOverrideMaxAmount === undefined &&
|
||||||
|
secondaryTotalTextOverride === undefined
|
||||||
|
) {
|
||||||
|
// Native Send
|
||||||
|
return (
|
||||||
|
<UserPreferencedCurrencyDisplay
|
||||||
|
type={PRIMARY}
|
||||||
|
value={addHexes(
|
||||||
|
txData.txParams.value,
|
||||||
|
getHexGasTotal({
|
||||||
|
gasPrice:
|
||||||
|
txData.txParams.maxFeePerGas ?? txData.txParams.gasPrice,
|
||||||
|
gasLimit: txData.txParams.gas,
|
||||||
|
}),
|
||||||
|
)}
|
||||||
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Token send
|
||||||
|
return useNativeCurrencyAsPrimaryCurrency
|
||||||
|
? primaryTotalTextOverrideMaxAmount
|
||||||
|
: secondaryTotalTextOverride;
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderTotalDetailTotal = () => {
|
||||||
|
if (
|
||||||
|
primaryTotalTextOverride === undefined &&
|
||||||
|
secondaryTotalTextOverride === undefined
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<UserPreferencedCurrencyDisplay
|
||||||
|
type={PRIMARY}
|
||||||
|
value={hexTransactionTotal}
|
||||||
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return useNativeCurrencyAsPrimaryCurrency
|
||||||
|
? primaryTotalTextOverride
|
||||||
|
: secondaryTotalTextOverride;
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderTotalDetailText = () => {
|
||||||
|
if (
|
||||||
|
primaryTotalTextOverride === undefined &&
|
||||||
|
secondaryTotalTextOverride === undefined
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<UserPreferencedCurrencyDisplay
|
||||||
|
type={SECONDARY}
|
||||||
|
value={hexTransactionTotal}
|
||||||
|
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return useNativeCurrencyAsPrimaryCurrency
|
||||||
|
? secondaryTotalTextOverride
|
||||||
|
: primaryTotalTextOverride;
|
||||||
|
};
|
||||||
|
|
||||||
const nonceField = useNonceField ? (
|
const nonceField = useNonceField ? (
|
||||||
<div>
|
<div>
|
||||||
<div className="confirm-detail-row">
|
<div className="confirm-detail-row">
|
||||||
@ -372,35 +441,29 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
}
|
}
|
||||||
detailText={
|
detailText={
|
||||||
<UserPreferencedCurrencyDisplay
|
<UserPreferencedCurrencyDisplay
|
||||||
type={PRIMARY}
|
type={SECONDARY}
|
||||||
value={hexMinimumTransactionFee}
|
value={hexMinimumTransactionFee}
|
||||||
hideLabel={false}
|
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
detailTotal={
|
detailTotal={
|
||||||
<UserPreferencedCurrencyDisplay
|
<UserPreferencedCurrencyDisplay
|
||||||
type={SECONDARY}
|
type={PRIMARY}
|
||||||
value={hexMinimumTransactionFee}
|
value={hexMinimumTransactionFee}
|
||||||
hideLabel
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
subText={
|
subText={t('editGasSubTextFee', [
|
||||||
<strong>
|
<b key="editGasSubTextFeeLabel">
|
||||||
{t('editGasSubTextFee', [
|
{t('editGasSubTextFeeLabel')}
|
||||||
<UserPreferencedCurrencyDisplay
|
</b>,
|
||||||
key="gas-subtext"
|
<UserPreferencedCurrencyDisplay
|
||||||
type={SECONDARY}
|
key="editGasSubTextFeeAmount"
|
||||||
value={getHexGasTotal({
|
type={PRIMARY}
|
||||||
gasPrice:
|
value={hexMaximumTransactionFee}
|
||||||
txData.txParams.maxFeePerGas ??
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
||||||
txData.txParams.gasPrice,
|
/>,
|
||||||
gasLimit: txData.txParams.gas,
|
])}
|
||||||
})}
|
|
||||||
hideLabel
|
|
||||||
/>,
|
|
||||||
])}
|
|
||||||
</strong>
|
|
||||||
}
|
|
||||||
subTitle={
|
subTitle={
|
||||||
<GasTiming
|
<GasTiming
|
||||||
maxPriorityFeePerGas={hexWEIToDecGWEI(
|
maxPriorityFeePerGas={hexWEIToDecGWEI(
|
||||||
@ -412,45 +475,16 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
/>,
|
/>,
|
||||||
<TransactionDetailItem
|
<TransactionDetailItem
|
||||||
key="total-item"
|
key="total-item"
|
||||||
detailTitle={primaryTotalTextOverride || t('total')}
|
detailTitle={t('total')}
|
||||||
detailText={
|
detailText={renderTotalDetailText()}
|
||||||
<UserPreferencedCurrencyDisplay
|
detailTotal={renderTotalDetailTotal()}
|
||||||
type={PRIMARY}
|
subTitle={t('transactionDetailGasTotalSubtitle')}
|
||||||
value={hexTransactionTotal}
|
subText={t('editGasSubTextAmount', [
|
||||||
hideLabel={false}
|
<b key="editGasSubTextAmountLabel">
|
||||||
/>
|
{t('editGasSubTextAmountLabel')}
|
||||||
}
|
</b>,
|
||||||
detailTotal={
|
renderTotalMaxAmount(),
|
||||||
<UserPreferencedCurrencyDisplay
|
])}
|
||||||
type={SECONDARY}
|
|
||||||
value={hexTransactionTotal}
|
|
||||||
hideLabel
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
subTitle={
|
|
||||||
secondaryTotalTextOverride ||
|
|
||||||
t('transactionDetailGasTotalSubtitle')
|
|
||||||
}
|
|
||||||
subText={
|
|
||||||
<strong>
|
|
||||||
{t('editGasSubTextAmount', [
|
|
||||||
<UserPreferencedCurrencyDisplay
|
|
||||||
key="gas-total-subtext"
|
|
||||||
type={SECONDARY}
|
|
||||||
value={addHexes(
|
|
||||||
txData.txParams.value,
|
|
||||||
getHexGasTotal({
|
|
||||||
gasPrice:
|
|
||||||
txData.txParams.maxFeePerGas ??
|
|
||||||
txData.txParams.gasPrice,
|
|
||||||
gasLimit: txData.txParams.gas,
|
|
||||||
}),
|
|
||||||
)}
|
|
||||||
hideLabel
|
|
||||||
/>,
|
|
||||||
])}
|
|
||||||
</strong>
|
|
||||||
}
|
|
||||||
/>,
|
/>,
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
@ -28,6 +28,7 @@ import {
|
|||||||
getIsEthGasPriceFetched,
|
getIsEthGasPriceFetched,
|
||||||
getShouldShowFiat,
|
getShouldShowFiat,
|
||||||
checkNetworkAndAccountSupports1559,
|
checkNetworkAndAccountSupports1559,
|
||||||
|
getPreferences,
|
||||||
} from '../../selectors';
|
} from '../../selectors';
|
||||||
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
||||||
import { transactionMatchesNetwork } from '../../../shared/modules/transaction.utils';
|
import { transactionMatchesNetwork } from '../../../shared/modules/transaction.utils';
|
||||||
@ -152,7 +153,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
customNonceValue = getCustomNonceValue(state);
|
customNonceValue = getCustomNonceValue(state);
|
||||||
const isEthGasPrice = getIsEthGasPriceFetched(state);
|
const isEthGasPrice = getIsEthGasPriceFetched(state);
|
||||||
const noGasPrice = getNoGasPriceFetched(state);
|
const noGasPrice = getNoGasPriceFetched(state);
|
||||||
|
const { useNativeCurrencyAsPrimaryCurrency } = getPreferences(state);
|
||||||
return {
|
return {
|
||||||
balance,
|
balance,
|
||||||
fromAddress,
|
fromAddress,
|
||||||
@ -194,6 +195,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
noGasPrice,
|
noGasPrice,
|
||||||
supportsEIP1599,
|
supportsEIP1599,
|
||||||
gasIsLoading: isGasEstimatesLoading || gasLoadingAnimationIsShowing,
|
gasIsLoading: isGasEstimatesLoading || gasLoadingAnimationIsShowing,
|
||||||
|
useNativeCurrencyAsPrimaryCurrency,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user