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

'Use Max' fixes #1710

Merged
merged 4 commits into from
Jul 24, 2020
Merged
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
35 changes: 28 additions & 7 deletions app/components/Views/SendFlow/Amount/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { getTicker, generateTransferData, getEther } from '../../../../util/tran
import { util } from '@metamask/controllers';
import FadeIn from 'react-native-fade-in-image';
import ErrorMessage from '../ErrorMessage';
import { fetchBasicGasEstimates, apiEstimateModifiedToWEI } from '../../../../util/custom-gas';
import { fetchBasicGasEstimates, convertApiValueToGWEI } from '../../../../util/custom-gas';
import Engine from '../../../../core/Engine';
import CollectibleImage from '../../../UI/CollectibleImage';
import collectiblesTransferInformation from '../../../../util/collectibles-transfer';
Expand Down Expand Up @@ -445,8 +445,27 @@ class Amount extends PureComponent {
providerType,
onConfirm
} = this.props;
const { inputValue, inputValueConversion, internalPrimaryCurrencyIsCrypto, hasExchangeRate } = this.state;
const value = internalPrimaryCurrencyIsCrypto || !hasExchangeRate ? inputValue : inputValueConversion;
const {
inputValue,
inputValueConversion,
internalPrimaryCurrencyIsCrypto,
hasExchangeRate,
maxFiatInput
} = this.state;

let value;
if (internalPrimaryCurrencyIsCrypto || !hasExchangeRate) {
value = inputValue;
} else {
value = inputValueConversion;
if (maxFiatInput) {
value = `${renderFromWei(
fiatNumberToWei(handleWeiNumber(maxFiatInput), this.props.conversionRate),
18
)}`;
}
}

if (!selectedAsset.tokenId && this.validateAmount(value)) {
return;
} else if (selectedAsset.tokenId) {
Expand Down Expand Up @@ -636,7 +655,7 @@ class Amount extends PureComponent {
basicGasEstimates = { average: 20 };
}
const gas = hexToBN(estimation.gas);
const gasPrice = apiEstimateModifiedToWEI(basicGasEstimates.average);
const gasPrice = toWei(convertApiValueToGWEI(basicGasEstimates.average), 'gwei');
return gas.mul(gasPrice);
};

Expand All @@ -662,6 +681,7 @@ class Amount extends PureComponent {
input = fromWei(maxValue);
} else {
input = `${weiToFiatNumber(maxValue, conversionRate)}`;
this.setState({ maxFiatInput: `${weiToFiatNumber(maxValue, conversionRate, 12)}` });
}
} else {
const exchangeRate = contractExchangeRates[selectedAsset.address];
Expand All @@ -675,10 +695,10 @@ class Amount extends PureComponent {
)}`;
}
}
this.onInputChange(input);
this.onInputChange(input, undefined, true);
};

onInputChange = (inputValue, selectedAsset) => {
onInputChange = (inputValue, selectedAsset, useMax) => {
const { contractExchangeRates, conversionRate, currentCurrency, ticker } = this.props;
const { internalPrimaryCurrencyIsCrypto } = this.state;
let inputValueConversion, renderableInputValueConversion, hasExchangeRate, comma;
Expand Down Expand Up @@ -737,7 +757,8 @@ class Amount extends PureComponent {
inputValueConversion,
renderableInputValueConversion,
amountError: undefined,
hasExchangeRate
hasExchangeRate,
maxFiatInput: !useMax && undefined
});
};

Expand Down