1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Show error if user have insufficient gas. (#12531)

This commit is contained in:
Olusegun Akintayo 2021-10-29 19:45:50 +04:00 committed by GitHub
parent ab1877ae0e
commit 7e7d0c13f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 1 deletions

View File

@ -1171,6 +1171,9 @@
"insufficientFunds": { "insufficientFunds": {
"message": "Insufficient funds." "message": "Insufficient funds."
}, },
"insufficientFundsForGas": {
"message": "Insufficient funds for gas"
},
"insufficientTokens": { "insufficientTokens": {
"message": "Insufficient tokens." "message": "Insufficient tokens."
}, },

View File

@ -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_FETCH_FAILURE_ERROR_KEY = 'gasPriceFetchFailed';
export const GAS_PRICE_EXCESSIVE_ERROR_KEY = 'gasPriceExcessive'; export const GAS_PRICE_EXCESSIVE_ERROR_KEY = 'gasPriceExcessive';
export const UNSENDABLE_ASSET_ERROR_KEY = 'unsendableAsset'; export const UNSENDABLE_ASSET_ERROR_KEY = 'unsendableAsset';
export const INSUFFICIENT_FUNDS_FOR_GAS_ERROR_KEY = 'insufficientFundsForGas';

View File

@ -7,6 +7,7 @@ import {
GAS_PRICE_FETCH_FAILURE_ERROR_KEY, GAS_PRICE_FETCH_FAILURE_ERROR_KEY,
GAS_PRICE_EXCESSIVE_ERROR_KEY, GAS_PRICE_EXCESSIVE_ERROR_KEY,
UNSENDABLE_ASSET_ERROR_KEY, UNSENDABLE_ASSET_ERROR_KEY,
INSUFFICIENT_FUNDS_FOR_GAS_ERROR_KEY,
} from '../../../helpers/constants/error-keys'; } from '../../../helpers/constants/error-keys';
import SendAmountRow from './send-amount-row'; import SendAmountRow from './send-amount-row';
import SendHexDataRow from './send-hex-data-row'; import SendHexDataRow from './send-hex-data-row';
@ -30,6 +31,7 @@ export default class SendContent extends Component {
isEthGasPrice: PropTypes.bool, isEthGasPrice: PropTypes.bool,
noGasPrice: PropTypes.bool, noGasPrice: PropTypes.bool,
networkOrAccountNotSupports1559: PropTypes.bool, networkOrAccountNotSupports1559: PropTypes.bool,
getIsBalanceInsufficient: PropTypes.bool,
}; };
render() { render() {
@ -41,11 +43,14 @@ export default class SendContent extends Component {
noGasPrice, noGasPrice,
isAssetSendable, isAssetSendable,
networkOrAccountNotSupports1559, networkOrAccountNotSupports1559,
getIsBalanceInsufficient,
} = this.props; } = this.props;
let gasError; let gasError;
if (gasIsExcessive) gasError = GAS_PRICE_EXCESSIVE_ERROR_KEY; if (gasIsExcessive) gasError = GAS_PRICE_EXCESSIVE_ERROR_KEY;
else if (noGasPrice) gasError = GAS_PRICE_FETCH_FAILURE_ERROR_KEY; else if (noGasPrice) gasError = GAS_PRICE_FETCH_FAILURE_ERROR_KEY;
else if (getIsBalanceInsufficient)
gasError = INSUFFICIENT_FUNDS_FOR_GAS_ERROR_KEY;
return ( return (
<PageContainerContent> <PageContainerContent>

View File

@ -106,6 +106,21 @@ describe('SendContent Component', () => {
).toStrictEqual(true); ).toStrictEqual(true);
expect(wrapper.find(Dialog)).toHaveLength(0); 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', () => { it('should not render the asset dropdown if token length is 0', () => {

View File

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