Skip to content

Commit

Permalink
Fix token transfer to address (#3046)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimenta authored Aug 24, 2021
1 parent 46f5878 commit 532d964
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
32 changes: 21 additions & 11 deletions app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import Analytics from '../../../core/Analytics';
import { ANALYTICS_EVENT_OPTS } from '../../../util/analytics';
import BigNumber from 'bignumber.js';
import { setInfuraAvailabilityBlocked, setInfuraAvailabilityNotBlocked } from '../../../actions/infuraAvailability';
import { toLowerCaseEquals } from '../../../util/general';

const styles = StyleSheet.create({
flex: {
Expand Down Expand Up @@ -342,17 +343,26 @@ const Main = props => {
to &&
(await getMethodData(data)).name === TOKEN_METHOD_TRANSFER
) {
let asset = props.tokens.find(({ address }) => address === to);
if (!asset && contractMap[to]) {
asset = contractMap[to];
} else if (!asset) {
try {
asset = {};
asset.decimals = await AssetsContractController.getTokenDecimals(to);
asset.symbol = await AssetsContractController.getAssetSymbol(to);
} catch (e) {
// This could fail when requesting a transfer in other network
asset = { symbol: 'ERC20', decimals: new BN(0) };
let asset = props.tokens.find(({ address }) => toLowerCaseEquals(address, to));
if (!asset) {
// try to lookup contract by lowercased address `to`
const contractMapKey = Object.keys(contractMap).find(key => toLowerCaseEquals(key, to));
if (contractMapKey) {
asset = contractMap[contractMapKey];
}

if (!asset) {
try {
asset = {};
asset.decimals = await AssetsContractController.getTokenDecimals(to);
asset.symbol = await AssetsContractController.getAssetSymbol(to);
// adding `to` here as well
asset.address = to;
} catch (e) {
// This could fail when requesting a transfer in other network
// adding `to` here as well
asset = { symbol: 'ERC20', decimals: new BN(0), address: to };
}
}
}

Expand Down
1 change: 0 additions & 1 deletion app/components/Views/Approval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ class Approval extends PureComponent {
transactionToSend.gas = EIP1559GasData.gasLimitHex;
transactionToSend.maxFeePerGas = addHexPrefix(EIP1559GasData.suggestedMaxFeePerGasHex); //'0x2540be400'
transactionToSend.maxPriorityFeePerGas = addHexPrefix(EIP1559GasData.suggestedMaxPriorityFeePerGasHex); //'0x3b9aca00';
transactionToSend.to = safeToChecksumAddress(transaction.to);
delete transactionToSend.gasPrice;
} else {
transactionToSend.gas = BNToHex(transaction.gas);
Expand Down

0 comments on commit 532d964

Please sign in to comment.