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

bugfix: issue #2763 #2808

Merged
merged 10 commits into from
Aug 5, 2021
47 changes: 26 additions & 21 deletions app/components/UI/PaymentRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import currencySymbols from '../../../util/currency-symbols.json';
import { NetworksChainId } from '@metamask/controllers';
import { getTicker } from '../../../util/transactions';
import { toLowerCaseEquals } from '../../../util/general';
import { utils as ethersUtils } from 'ethers';

const KEYBOARD_OFFSET = 120;
const styles = StyleSheet.create({
Expand Down Expand Up @@ -444,10 +445,9 @@ class PaymentRequest extends PureComponent {
const { selectedAsset } = this.state;
let secondaryAmount;
const symbol = selectedAsset.symbol;
const undefAmount = (isDecimal(amount) && amount) || 0;
const undefAmount = isDecimal(amount) && !ethersUtils.isHexString(amount) ? amount : 0;
const cryptoAmount = amount;
const exchangeRate = selectedAsset && selectedAsset.address && contractExchangeRates[selectedAsset.address];

if (selectedAsset.symbol !== 'ETH') {
secondaryAmount = exchangeRate
? balanceToFiat(undefAmount, conversionRate, exchangeRate, currentCurrency)
Expand Down Expand Up @@ -502,9 +502,9 @@ class PaymentRequest extends PureComponent {
// If primary currency is not crypo we need to know if there are conversion and exchange rates to handle0,
// fiat conversion for the payment request
if (internalPrimaryCurrency !== 'ETH' && conversionRate && (exchangeRate || selectedAsset.isETH)) {
res = this.handleFiatPrimaryCurrency(amount && amount.replace(',', '.'));
res = this.handleFiatPrimaryCurrency(amount?.replace(',', '.'));
} else {
res = this.handleETHPrimaryCurrency(amount && amount.replace(',', '.'));
res = this.handleETHPrimaryCurrency(amount?.replace(',', '.'));
}
const { cryptoAmount, symbol } = res;
if (amount && amount[0] === currencySymbol) amount = amount.substr(1);
Expand Down Expand Up @@ -541,26 +541,31 @@ class PaymentRequest extends PureComponent {
onNext = () => {
const { selectedAddress, navigation, chainId } = this.props;
const { cryptoAmount, selectedAsset } = this.state;

try {
let eth_link;
if (selectedAsset.isETH) {
const amount = toWei(cryptoAmount).toString();
eth_link = generateETHLink(selectedAddress, amount, chainId);
} else {
const amount = toTokenMinimalUnit(cryptoAmount, selectedAsset.decimals).toString();
eth_link = generateERC20Link(selectedAddress, selectedAsset.address, amount, chainId);
}
if (cryptoAmount && cryptoAmount > '0') {
let eth_link;
if (selectedAsset.isETH) {
const amount = toWei(cryptoAmount).toString();
eth_link = generateETHLink(selectedAddress, amount, chainId);
} else {
const amount = toTokenMinimalUnit(cryptoAmount, selectedAsset.decimals).toString();
eth_link = generateERC20Link(selectedAddress, selectedAsset.address, amount, chainId);
}

// Convert to universal link / app link
const link = generateUniversalLinkRequest(eth_link);
// Convert to universal link / app link
const link = generateUniversalLinkRequest(eth_link);

navigation &&
navigation.replace('PaymentRequestSuccess', {
link,
qrLink: eth_link,
amount: cryptoAmount,
symbol: selectedAsset.symbol
});
navigation &&
navigation.replace('PaymentRequestSuccess', {
link,
qrLink: eth_link,
amount: cryptoAmount,
symbol: selectedAsset.symbol
});
} else {
this.setState({ showError: true });
}
} catch (e) {
this.setState({ showError: true });
}
Expand Down