Skip to content

Commit

Permalink
Improve flashing behaviour for loading gas estimates (on confirm scre…
Browse files Browse the repository at this point in the history
…en) (MetaMask#11852)

* Improve flashing behaviour for loading gas estimates

* Fix typo

* renderHeartBeatIfInTest
  • Loading branch information
danjm authored and ryanml committed Aug 17, 2021
1 parent b6086eb commit 805859a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,8 @@
.page-container__footer {
margin-top: auto;
}

&__currency-container {
position: relative;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import PropTypes from 'prop-types';
import { I18nContext } from '../../../contexts/i18n';

import TransactionDetailItem from '../transaction-detail-item/transaction-detail-item.component';
import LoadingHeartBeat from '../../ui/loading-heartbeat';

export default function TransactionDetail({ rows = [], onEdit }) {
const t = useContext(I18nContext);

return (
<div className="transaction-detail">
{process.env.IN_TEST === 'true' ? null : <LoadingHeartBeat />}
{onEdit && (
<div className="transaction-detail-edit">
<button onClick={onEdit}>{t('edit')}</button>
Expand Down
8 changes: 3 additions & 5 deletions ui/components/ui/loading-heartbeat/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
}

@keyframes heartbeat {
0% { opacity: 0; }
25% { opacity: 1; }
50% { opacity: 0.5; }
75% { opacity: 1; }
100% { opacity: 0; }
0% { opacity: 0.2; }
50% { opacity: 1; }
100% { opacity: 0.2; }
}
7 changes: 7 additions & 0 deletions ui/hooks/useShouldAnimateGasEstimations.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ export function useShouldAnimateGasEstimations() {
showLoadingAnimation === true
) {
dispatch(toggleGasLoadingAnimation(true));
}
}, [dispatch, isGasLoadingAnimationActive, showLoadingAnimation]);

useEffect(() => {
if (
isGasLoadingAnimationActive === true &&
showLoadingAnimation === false
) {
setTimeout(() => {
dispatch(toggleGasLoadingAnimation(false));
}, 2000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { toBuffer } from '../../../shared/modules/buffer-utils';
import TransactionDetail from '../../components/app/transaction-detail/transaction-detail.component';
import TransactionDetailItem from '../../components/app/transaction-detail-item/transaction-detail-item.component';
import InfoTooltip from '../../components/ui/info-tooltip/info-tooltip';
import LoadingHeartBeat from '../../components/ui/loading-heartbeat';
import GasTiming from '../../components/app/gas-timing/gas-timing.component';

import { COLORS } from '../../helpers/constants/design-system';
Expand All @@ -43,6 +44,9 @@ import {
removePollingTokenFromAppState,
} from '../../store/actions';

const renderHeartBeatIfNotInTest = () =>
process.env.IN_TEST === 'true' ? null : <LoadingHeartBeat />;

export default class ConfirmTransactionBase extends Component {
static contextTypes = {
t: PropTypes.func,
Expand Down Expand Up @@ -439,29 +443,41 @@ export default class ConfirmTransactionBase extends Component {
txData.dappSuggestedGasFees ? COLORS.SECONDARY1 : COLORS.BLACK
}
detailText={
<UserPreferencedCurrencyDisplay
type={SECONDARY}
value={hexMinimumTransactionFee}
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)}
/>
<div className="confirm-page-container-content__currency-container">
{renderHeartBeatIfNotInTest()}
<UserPreferencedCurrencyDisplay
type={SECONDARY}
value={hexMinimumTransactionFee}
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)}
/>
</div>
}
detailTotal={
<UserPreferencedCurrencyDisplay
type={PRIMARY}
value={hexMinimumTransactionFee}
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
/>
<div className="confirm-page-container-content__currency-container">
{renderHeartBeatIfNotInTest()}
<UserPreferencedCurrencyDisplay
type={PRIMARY}
value={hexMinimumTransactionFee}
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
/>
</div>
}
subText={t('editGasSubTextFee', [
<b key="editGasSubTextFeeLabel">
{t('editGasSubTextFeeLabel')}
</b>,
<UserPreferencedCurrencyDisplay
key="editGasSubTextFeeAmount"
type={PRIMARY}
value={hexMaximumTransactionFee}
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
/>,
<div
key="editGasSubTextFeeValue"
className="confirm-page-container-content__currency-container"
>
{renderHeartBeatIfNotInTest()}
<UserPreferencedCurrencyDisplay
key="editGasSubTextFeeAmount"
type={PRIMARY}
value={hexMaximumTransactionFee}
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
/>
</div>,
])}
subTitle={
<GasTiming
Expand Down

0 comments on commit 805859a

Please sign in to comment.