Skip to content

Commit

Permalink
updating the importTokens with addTokens for token detection token im…
Browse files Browse the repository at this point in the history
…port, updating array type for ignortoken and TOKEN_DETECTION_V2 flag in token-details-page
  • Loading branch information
NiranjanaBinoy committed Jun 17, 2022
1 parent 0e7ad24 commit eb8f0bf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
4 changes: 1 addition & 3 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1930,9 +1930,7 @@ export default class MetamaskController extends EventEmitter {
addDetectedTokens: tokensController.addDetectedTokens.bind(
tokensController,
),
importTokens: process.env.TOKEN_DETECTION_V2
? tokensController.importTokens.bind(tokensController)
: null,
addImportedTokens: tokensController.addTokens.bind(tokensController),
ignoreTokens: tokensController.ignoreTokens.bind(tokensController),
getBalancesInSingleCall: assetsContractController.getBalancesInSingleCall.bind(
assetsContractController,
Expand Down
9 changes: 6 additions & 3 deletions ui/components/app/detected-token/detected-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSelector, useDispatch } from 'react-redux';
import { chain } from 'lodash';

import {
importTokens,
addImportedTokens,
ignoreTokens,
setNewTokensImported,
} from '../../../store/actions';
Expand Down Expand Up @@ -63,7 +63,7 @@ const DetectedToken = ({ setShowDetectedTokens }) => {
},
});
});
await dispatch(importTokens(selectedTokens));
await dispatch(addImportedTokens(selectedTokens));
const tokenSymbols = selectedTokens.map(({ symbol }) => symbol);
dispatch(setNewTokensImported(tokenSymbols.join(', ')));
};
Expand All @@ -90,7 +90,10 @@ const DetectedToken = ({ setShowDetectedTokens }) => {
asset_type: ASSET_TYPES.TOKEN,
},
});
await dispatch(ignoreTokens(deSelectedTokens));
const deSelectedTokensAddresses = deSelectedTokens.map(
({ address }) => address,
);
await dispatch(ignoreTokens(deSelectedTokensAddresses));
setShowDetectedTokens(false);
};

Expand Down
8 changes: 2 additions & 6 deletions ui/pages/token-details/token-details-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useContext } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Redirect, useHistory, useParams } from 'react-router-dom';
import { getTokens } from '../../ducks/metamask/metamask';
import { getUseTokenDetection, getTokenList } from '../../selectors';
import { getTokenList } from '../../selectors';
import { useCopyToClipboard } from '../../hooks/useCopyToClipboard';
import Identicon from '../../components/ui/identicon';
import { I18nContext } from '../../contexts/i18n';
Expand Down Expand Up @@ -32,18 +32,14 @@ export default function TokenDetailsPage() {
const t = useContext(I18nContext);
const tokens = useSelector(getTokens);
const tokenList = useSelector(getTokenList);
const useTokenDetection = useSelector(getUseTokenDetection);

const { address: tokenAddress } = useParams();
const tokenMetadata = Object.values(tokenList).find((token) =>
isEqualCaseInsensitive(token.address, tokenAddress),
);
const aggregators = tokenMetadata?.aggregators?.join(', ');
const fileName = tokenMetadata?.iconUrl;
let imagePath = fileName;
if (!process.env.TOKEN_DETECTION_V2) {
imagePath = useTokenDetection ? fileName : `images/contract/${fileName}`;
}
const imagePath = fileName;

const token = tokens.find(({ address }) =>
isEqualCaseInsensitive(address, tokenAddress),
Expand Down
6 changes: 3 additions & 3 deletions ui/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1644,10 +1644,10 @@ export function addDetectedTokens(newDetectedTokens) {
*
* @param tokensToImport
*/
export function importTokens(tokensToImport) {
export function addImportedTokens(tokensToImport) {
return async (dispatch) => {
try {
await promisifiedBackground.importTokens(tokensToImport);
await promisifiedBackground.addImportedTokens(tokensToImport);
} catch (error) {
log.error(error);
} finally {
Expand All @@ -1657,7 +1657,7 @@ export function importTokens(tokensToImport) {
}

/**
* To add ignored tokens to state
* To add ignored token addresses to state
*
* @param tokensToIgnore
*/
Expand Down

0 comments on commit eb8f0bf

Please sign in to comment.