Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use max in send flow #13304

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ exports[`Amount should convert ERC-20 token value to USD 1`] = `
style={
{
"alignSelf": "flex-end",
"color": "#6a737d",
"color": "#0376c9",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 12,
"fontWeight": "400",
Expand Down Expand Up @@ -1148,7 +1148,7 @@ exports[`Amount should convert ETH to USD 1`] = `
style={
{
"alignSelf": "flex-end",
"color": "#6a737d",
"color": "#0376c9",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 12,
"fontWeight": "400",
Expand Down Expand Up @@ -1864,7 +1864,7 @@ exports[`Amount should convert USD to ERC-20 token value 1`] = `
style={
{
"alignSelf": "flex-end",
"color": "#6a737d",
"color": "#0376c9",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 12,
"fontWeight": "400",
Expand Down Expand Up @@ -2597,7 +2597,7 @@ exports[`Amount should convert USD to ETH 1`] = `
style={
{
"alignSelf": "flex-end",
"color": "#6a737d",
"color": "#0376c9",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 12,
"fontWeight": "400",
Expand Down Expand Up @@ -3330,7 +3330,7 @@ exports[`Amount should display correct balance 1`] = `
style={
{
"alignSelf": "flex-end",
"color": "#6a737d",
"color": "#0376c9",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 12,
"fontWeight": "400",
Expand Down Expand Up @@ -4045,7 +4045,7 @@ exports[`Amount should not show a warning when conversion rate is available 1`]
style={
{
"alignSelf": "flex-end",
"color": "#6a737d",
"color": "#0376c9",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 12,
"fontWeight": "400",
Expand Down Expand Up @@ -5434,15 +5434,15 @@ exports[`Amount should proceed if balance is sufficient while on Native primary
}
>
<TouchableOpacity
disabled={true}
disabled={false}
onPress={[Function]}
style={{}}
>
<Text
style={
{
"alignSelf": "flex-end",
"color": "#6a737d",
"color": "#0376c9",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 12,
"fontWeight": "400",
Expand Down Expand Up @@ -6228,7 +6228,7 @@ exports[`Amount should render correctly 1`] = `
style={
{
"alignSelf": "flex-end",
"color": "#6a737d",
"color": "#0376c9",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 12,
"fontWeight": "400",
Expand Down Expand Up @@ -6938,7 +6938,7 @@ exports[`Amount should show a warning when conversion rate is not available 1`]
style={
{
"alignSelf": "flex-end",
"color": "#6a737d",
"color": "#0376c9",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 12,
"fontWeight": "400",
Expand Down Expand Up @@ -7565,15 +7565,15 @@ exports[`Amount should show an error message if balance is insufficient 1`] = `
}
>
<TouchableOpacity
disabled={true}
disabled={false}
onPress={[Function]}
style={{}}
>
<Text
style={
{
"alignSelf": "flex-end",
"color": "#6a737d",
"color": "#0376c9",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 12,
"fontWeight": "400",
Expand Down
22 changes: 2 additions & 20 deletions app/components/Views/confirmations/SendFlow/Amount/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { PureComponent } from 'react';
import BigNumber from 'bignumber.js';
import { fontStyles } from '../../../../../styles/common';
import {
StyleSheet,
Expand Down Expand Up @@ -165,13 +164,6 @@ const createStyles = (colors) =>
alignSelf: 'flex-end',
textTransform: 'uppercase',
},
maxTextDisabled: {
...fontStyles.normal,
fontSize: 12,
color: colors.text.alternative,
alignSelf: 'flex-end',
textTransform: 'uppercase',
},
actionMax: {
flexDirection: 'row',
alignItems: 'center',
Expand Down Expand Up @@ -1465,10 +1457,6 @@ class Amount extends PureComponent {
const colors = this.context.colors || mockTheme.colors;
const styles = createStyles(colors);

const isEstimateedTotalGasValid = estimatedTotalGas
? BigNumber(estimatedTotalGas).gt(0)
: false;

return (
<SafeAreaView
edges={['bottom']}
Expand Down Expand Up @@ -1528,16 +1516,10 @@ class Amount extends PureComponent {
{!selectedAsset.tokenId && (
<TouchableOpacity
style={styles.actionMaxTouchable}
disabled={!isEstimateedTotalGasValid}
disabled={!estimatedTotalGas}
onPress={this.useMax}
>
<Text
style={
isEstimateedTotalGasValid
? styles.maxText
: styles.maxTextDisabled
}
>
<Text style={styles.maxText}>
{strings('transaction.use_max')}
</Text>
</TouchableOpacity>
Expand Down
12 changes: 8 additions & 4 deletions app/components/Views/confirmations/SendFlow/Confirm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ class Confirm extends PureComponent {
transactionTo,
transaction: { value, gas, from },
},
transactionMetadata,
contractBalances,
selectedAsset,
maxValueMode,
Expand Down Expand Up @@ -600,9 +601,10 @@ class Confirm extends PureComponent {
this.props.gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET;
const haveGasFeeMaxNativeChanged = isEIP1559Transaction
? EIP1559GasTransaction.gasFeeMaxNative !==
prevState.EIP1559GasTransaction.gasFeeMaxNative
prevState.EIP1559GasTransaction.gasFeeMaxNative
: legacyGasTransaction.gasFeeMaxNative !==
prevState.legacyGasTransaction.gasFeeMaxNative;
prevState.legacyGasTransaction.gasFeeMaxNative;
const isControllerTransactionAdded = Boolean(!prevProps.transactionMetadata && transactionMetadata);

const haveGasPropertiesChanged =
(this.props.gasFeeEstimates &&
Expand All @@ -613,7 +615,8 @@ class Confirm extends PureComponent {
this.props.gasFeeEstimates,
) ||
gas !== prevProps?.transactionState?.transaction?.gas)) ||
haveEIP1559TotalMaxHexChanged;
haveEIP1559TotalMaxHexChanged ||
isControllerTransactionAdded;

if (
recipientIsDefined &&
Expand All @@ -636,7 +639,7 @@ class Confirm extends PureComponent {
maxValueMode &&
selectedAsset.isETH &&
!isEmpty(gasFeeEstimates) &&
haveGasFeeMaxNativeChanged
(haveGasFeeMaxNativeChanged || isControllerTransactionAdded)
) {
updateTransactionToMaxValue({
transactionId,
Expand Down Expand Up @@ -1621,6 +1624,7 @@ const mapStateToProps = (state) => {
transactionMetadata: selectCurrentTransactionMetadata(state),
useTransactionSimulations: selectUseTransactionSimulations(state),
securityAlertResponse: selectCurrentTransactionSecurityAlertResponse(state),
maxValueMode: state.transaction.maxValueMode,
};
};

Expand Down
11 changes: 6 additions & 5 deletions app/components/Views/confirmations/SendFlow/Confirm/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BN } from 'ethereumjs-util';
import type { TransactionMeta } from '@metamask/transaction-controller';
import { remove0x, add0x } from '@metamask/utils';
import { toWei } from '../../../../../util/number';
import { updateEditableParams } from '../../../../../util/transaction-controller';
Expand Down Expand Up @@ -34,9 +33,11 @@ export const updateTransactionToMaxValue = async ({

const maxTransactionValueHex = add0x(maxTransactionValueBN.toString(16));

const txMeta = (await updateEditableParams(transactionId, {
value: maxTransactionValueHex,
})) as TransactionMeta;
if (transactionId) {
await updateEditableParams(transactionId, {
value: maxTransactionValueHex,
});
}

setTransactionValue(txMeta.txParams.value as string);
setTransactionValue(maxTransactionValueHex);
};
Loading