Edit transaction screen changes for EIP-1559 V2 (#12493)
Edit transaction screen changes for EIP-1559 V2feature/default_network_editable
parent
e6ae6e09b8
commit
3dfc1cc5f6
@ -0,0 +1,15 @@ |
|||||||
|
import PropTypes from 'prop-types'; |
||||||
|
|
||||||
|
import { useI18nContext } from '../../../hooks/useI18nContext'; |
||||||
|
|
||||||
|
const I18nValue = ({ messageKey, options }) => { |
||||||
|
const t = useI18nContext(); |
||||||
|
return t(messageKey, options); |
||||||
|
}; |
||||||
|
|
||||||
|
I18nValue.propTypes = { |
||||||
|
messageKey: PropTypes.string.isRequired, |
||||||
|
options: PropTypes.array, |
||||||
|
}; |
||||||
|
|
||||||
|
export default I18nValue; |
@ -0,0 +1 @@ |
|||||||
|
export { default } from './i18n-value.component'; |
@ -0,0 +1,136 @@ |
|||||||
|
import React from 'react'; |
||||||
|
import PropTypes from 'prop-types'; |
||||||
|
|
||||||
|
import { COLORS } from '../../../helpers/constants/design-system'; |
||||||
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common'; |
||||||
|
import { hexWEIToDecGWEI } from '../../../helpers/utils/conversions.util'; |
||||||
|
import { useI18nContext } from '../../../hooks/useI18nContext'; |
||||||
|
|
||||||
|
import Box from '../../../components/ui/box'; |
||||||
|
import Typography from '../../../components/ui/typography/typography'; |
||||||
|
import GasTiming from '../../../components/app/gas-timing/gas-timing.component'; |
||||||
|
import I18nValue from '../../../components/ui/i18n-value'; |
||||||
|
import InfoTooltip from '../../../components/ui/info-tooltip/info-tooltip'; |
||||||
|
import LoadingHeartBeat from '../../../components/ui/loading-heartbeat'; |
||||||
|
import TransactionDetailItem from '../../../components/app/transaction-detail-item/transaction-detail-item.component'; |
||||||
|
import UserPreferencedCurrencyDisplay from '../../../components/app/user-preferenced-currency-display'; |
||||||
|
|
||||||
|
const HeartBeat = () => |
||||||
|
process.env.IN_TEST === 'true' ? null : <LoadingHeartBeat />; |
||||||
|
|
||||||
|
const GasDetailItem = ({ |
||||||
|
hexMaximumTransactionFee, |
||||||
|
hexMinimumTransactionFee, |
||||||
|
isMainnet, |
||||||
|
maxFeePerGas, |
||||||
|
maxPriorityFeePerGas, |
||||||
|
supportsEIP1559, |
||||||
|
txData, |
||||||
|
useNativeCurrencyAsPrimaryCurrency, |
||||||
|
}) => { |
||||||
|
const t = useI18nContext(); |
||||||
|
return ( |
||||||
|
<TransactionDetailItem |
||||||
|
key="gas-item" |
||||||
|
detailTitle={ |
||||||
|
<Box display="flex"> |
||||||
|
<Box marginRight={1}> |
||||||
|
<I18nValue messageKey="transactionDetailGasHeadingV2" /> |
||||||
|
</Box> |
||||||
|
<span className="gas-details-item__estimate"> |
||||||
|
(<I18nValue messageKey="transactionDetailGasInfoV2" />) |
||||||
|
</span> |
||||||
|
<InfoTooltip |
||||||
|
contentText={ |
||||||
|
<> |
||||||
|
<Typography fontSize="12px"> |
||||||
|
{t('transactionDetailGasTooltipIntro', [ |
||||||
|
isMainnet ? t('networkNameEthereum') : '', |
||||||
|
])} |
||||||
|
</Typography> |
||||||
|
<Typography fontSize="12px"> |
||||||
|
{t('transactionDetailGasTooltipExplanation')} |
||||||
|
</Typography> |
||||||
|
<Typography fontSize="12px"> |
||||||
|
<a |
||||||
|
href="https://community.metamask.io/t/what-is-gas-why-do-transactions-take-so-long/3172" |
||||||
|
target="_blank" |
||||||
|
rel="noopener noreferrer" |
||||||
|
> |
||||||
|
{t('transactionDetailGasTooltipConversion')} |
||||||
|
</a> |
||||||
|
</Typography> |
||||||
|
</> |
||||||
|
} |
||||||
|
position="top" |
||||||
|
/> |
||||||
|
</Box> |
||||||
|
} |
||||||
|
detailTitleColor={COLORS.BLACK} |
||||||
|
detailText={ |
||||||
|
<div className="gas-details-item__currency-container"> |
||||||
|
<HeartBeat /> |
||||||
|
<UserPreferencedCurrencyDisplay |
||||||
|
type={SECONDARY} |
||||||
|
value={hexMinimumTransactionFee} |
||||||
|
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)} |
||||||
|
/> |
||||||
|
</div> |
||||||
|
} |
||||||
|
detailTotal={ |
||||||
|
<div className="gas-details-item__currency-container"> |
||||||
|
<HeartBeat /> |
||||||
|
<UserPreferencedCurrencyDisplay |
||||||
|
type={PRIMARY} |
||||||
|
value={hexMinimumTransactionFee} |
||||||
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency} |
||||||
|
/> |
||||||
|
</div> |
||||||
|
} |
||||||
|
subText={t('editGasSubTextFee', [ |
||||||
|
<Box key="editGasSubTextFeeLabel" display="inline-flex"> |
||||||
|
<Box marginRight={1} className="gas-details-item__gasfee-label"> |
||||||
|
<I18nValue messageKey="editGasSubTextFeeLabel" /> |
||||||
|
</Box> |
||||||
|
<div |
||||||
|
key="editGasSubTextFeeValue" |
||||||
|
className="gas-details-item__currency-container" |
||||||
|
> |
||||||
|
<HeartBeat /> |
||||||
|
<UserPreferencedCurrencyDisplay |
||||||
|
key="editGasSubTextFeeAmount" |
||||||
|
type={PRIMARY} |
||||||
|
value={hexMaximumTransactionFee} |
||||||
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency} |
||||||
|
/> |
||||||
|
</div> |
||||||
|
</Box>, |
||||||
|
])} |
||||||
|
subTitle={ |
||||||
|
supportsEIP1559 && ( |
||||||
|
<GasTiming |
||||||
|
maxPriorityFeePerGas={hexWEIToDecGWEI( |
||||||
|
maxPriorityFeePerGas || txData.txParams.maxPriorityFeePerGas, |
||||||
|
)} |
||||||
|
maxFeePerGas={hexWEIToDecGWEI( |
||||||
|
maxFeePerGas || txData.txParams.maxFeePerGas, |
||||||
|
)} |
||||||
|
/> |
||||||
|
) |
||||||
|
} |
||||||
|
/> |
||||||
|
); |
||||||
|
}; |
||||||
|
|
||||||
|
GasDetailItem.propTypes = { |
||||||
|
hexMaximumTransactionFee: PropTypes.string, |
||||||
|
hexMinimumTransactionFee: PropTypes.string, |
||||||
|
isMainnet: PropTypes.bool, |
||||||
|
maxFeePerGas: PropTypes.string, |
||||||
|
maxPriorityFeePerGas: PropTypes.string, |
||||||
|
supportsEIP1559: PropTypes.bool, |
||||||
|
txData: PropTypes.object, |
||||||
|
useNativeCurrencyAsPrimaryCurrency: PropTypes.bool, |
||||||
|
}; |
||||||
|
|
||||||
|
export default GasDetailItem; |
@ -0,0 +1,17 @@ |
|||||||
|
.gas-details-item { |
||||||
|
&__estimate { |
||||||
|
font-weight: 400; |
||||||
|
font-style: italic; |
||||||
|
font-size: 12px; |
||||||
|
color: $Grey-500; |
||||||
|
line-height: inherit; |
||||||
|
} |
||||||
|
|
||||||
|
&__gasfee-label { |
||||||
|
font-weight: bold; |
||||||
|
} |
||||||
|
|
||||||
|
&__currency-container { |
||||||
|
position: relative; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
import React from 'react'; |
||||||
|
import { screen } from '@testing-library/react'; |
||||||
|
|
||||||
|
import { ETH } from '../../../helpers/constants/common'; |
||||||
|
import { renderWithProvider } from '../../../../test/jest'; |
||||||
|
import configureStore from '../../../store/store'; |
||||||
|
|
||||||
|
import GasDetailsItem from './gas-details-item'; |
||||||
|
|
||||||
|
const render = (props) => { |
||||||
|
const store = configureStore({ |
||||||
|
metamask: { |
||||||
|
nativeCurrency: ETH, |
||||||
|
preferences: { |
||||||
|
useNativeCurrencyAsPrimaryCurrency: true, |
||||||
|
}, |
||||||
|
provider: {}, |
||||||
|
}, |
||||||
|
}); |
||||||
|
|
||||||
|
return renderWithProvider(<GasDetailsItem txData={{}} {...props} />, store); |
||||||
|
}; |
||||||
|
|
||||||
|
describe('GasDetailsItem', () => { |
||||||
|
it('should render label', () => { |
||||||
|
render(); |
||||||
|
expect(screen.queryByText('Gas')).toBeInTheDocument(); |
||||||
|
expect(screen.queryByText('(estimated)')).toBeInTheDocument(); |
||||||
|
expect(screen.queryByText('Max fee:')).toBeInTheDocument(); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should render gas fee details', () => { |
||||||
|
render({ |
||||||
|
hexMinimumTransactionFee: '0x1ca62a4f7800', |
||||||
|
hexMaximumTransactionFee: '0x290ee75e3d900', |
||||||
|
}); |
||||||
|
expect(screen.queryAllByText('0.000031')).toHaveLength(2); |
||||||
|
expect(screen.queryByText('ETH')).toBeInTheDocument(); |
||||||
|
expect(screen.queryByText('0.000722')).toBeInTheDocument(); |
||||||
|
}); |
||||||
|
}); |
@ -0,0 +1 @@ |
|||||||
|
export { default } from './gas-details-item'; |
Loading…
Reference in new issue