Skip to content

Commit

Permalink
Show error if user have insufficient gas. (#12531)
Browse files Browse the repository at this point in the history
  • Loading branch information
segun authored Oct 29, 2021
1 parent ab1877a commit 7e7d0c1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,9 @@
"insufficientFunds": {
"message": "Insufficient funds."
},
"insufficientFundsForGas": {
"message": "Insufficient funds for gas"
},
"insufficientTokens": {
"message": "Insufficient tokens."
},
Expand Down
1 change: 1 addition & 0 deletions ui/helpers/constants/error-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export const ETH_GAS_PRICE_FETCH_WARNING_KEY = 'ethGasPriceFetchWarning';
export const GAS_PRICE_FETCH_FAILURE_ERROR_KEY = 'gasPriceFetchFailed';
export const GAS_PRICE_EXCESSIVE_ERROR_KEY = 'gasPriceExcessive';
export const UNSENDABLE_ASSET_ERROR_KEY = 'unsendableAsset';
export const INSUFFICIENT_FUNDS_FOR_GAS_ERROR_KEY = 'insufficientFundsForGas';
5 changes: 5 additions & 0 deletions ui/pages/send/send-content/send-content.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
GAS_PRICE_FETCH_FAILURE_ERROR_KEY,
GAS_PRICE_EXCESSIVE_ERROR_KEY,
UNSENDABLE_ASSET_ERROR_KEY,
INSUFFICIENT_FUNDS_FOR_GAS_ERROR_KEY,
} from '../../../helpers/constants/error-keys';
import SendAmountRow from './send-amount-row';
import SendHexDataRow from './send-hex-data-row';
Expand All @@ -30,6 +31,7 @@ export default class SendContent extends Component {
isEthGasPrice: PropTypes.bool,
noGasPrice: PropTypes.bool,
networkOrAccountNotSupports1559: PropTypes.bool,
getIsBalanceInsufficient: PropTypes.bool,
};

render() {
Expand All @@ -41,11 +43,14 @@ export default class SendContent extends Component {
noGasPrice,
isAssetSendable,
networkOrAccountNotSupports1559,
getIsBalanceInsufficient,
} = this.props;

let gasError;
if (gasIsExcessive) gasError = GAS_PRICE_EXCESSIVE_ERROR_KEY;
else if (noGasPrice) gasError = GAS_PRICE_FETCH_FAILURE_ERROR_KEY;
else if (getIsBalanceInsufficient)
gasError = INSUFFICIENT_FUNDS_FOR_GAS_ERROR_KEY;

return (
<PageContainerContent>
Expand Down
15 changes: 15 additions & 0 deletions ui/pages/send/send-content/send-content.component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ describe('SendContent Component', () => {
).toStrictEqual(true);
expect(wrapper.find(Dialog)).toHaveLength(0);
});

it('should render insufficient gas dialog', () => {
wrapper.setProps({
showHexData: false,
getIsBalanceInsufficient: true,
});
const PageContainerContentChild = wrapper
.find(PageContainerContent)
.children();
const errorDialogProps = PageContainerContentChild.childAt(0).props();
expect(errorDialogProps.className).toStrictEqual('send__error-dialog');
expect(errorDialogProps.children).toStrictEqual(
'insufficientFundsForGas_t',
);
});
});

it('should not render the asset dropdown if token length is 0', () => {
Expand Down
7 changes: 6 additions & 1 deletion ui/pages/send/send-content/send-content.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {
getNoGasPriceFetched,
checkNetworkOrAccountNotSupports1559,
} from '../../../selectors';
import { getIsAssetSendable, getSendTo } from '../../../ducks/send';
import {
getIsAssetSendable,
getIsBalanceInsufficient,
getSendTo,
} from '../../../ducks/send';

import * as actions from '../../../store/actions';
import SendContent from './send-content.component';
Expand All @@ -28,6 +32,7 @@ function mapStateToProps(state) {
networkOrAccountNotSupports1559: checkNetworkOrAccountNotSupports1559(
state,
),
getIsBalanceInsufficient: getIsBalanceInsufficient(state),
};
}

Expand Down

0 comments on commit 7e7d0c1

Please sign in to comment.