1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

Fix broken NFT import and auto-detect flows (#17384)

* Fix broken NFT import and auto-detect flows
This commit is contained in:
Alex Donesky 2023-01-25 10:33:06 -06:00 committed by GitHub
parent 073718d965
commit 3d87f65d9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 7 deletions

View File

@ -342,6 +342,7 @@ export default class MetamaskController extends EventEmitter {
...networkState,
providerConfig: {
...networkState.provider,
chainId: hexToDecimal(networkState.provider.chainId),
},
};
return cb(modifiedNetworkState);
@ -972,8 +973,11 @@ export default class MetamaskController extends EventEmitter {
getTokenValueParam(transactionData);
const { allNfts } = this.nftController.state;
const chainIdAsDecimal = hexToDecimal(chainId);
// check if its a known collectible
const knownCollectible = allNfts?.[userAddress]?.[chainId].find(
const knownCollectible = allNfts?.[userAddress]?.[
chainIdAsDecimal
]?.find(
({ address, tokenId }) =>
isEqualCaseInsensitive(address, contractAddress) &&
tokenId === transactionDataTokenId,
@ -984,7 +988,7 @@ export default class MetamaskController extends EventEmitter {
this.nftController.checkAndUpdateSingleNftOwnershipStatus(
knownCollectible,
false,
{ userAddress, chainId },
{ userAddress, chainId: chainIdAsDecimal },
);
}
}

View File

@ -5,6 +5,7 @@ import configureStore from '../../../store/store';
import { renderWithProvider } from '../../../../test/jest/rendering';
import { EXPERIMENTAL_ROUTE } from '../../../helpers/constants/routes';
import { setBackgroundConnection } from '../../../../test/jest';
import { hexToDecimal } from '../../../../shared/modules/conversion.utils';
import CollectiblesTab from '.';
const COLLECTIBLES = [
@ -153,16 +154,17 @@ const render = ({
useNftDetection,
onAddNFT = jest.fn(),
}) => {
const chainIdAsDecimal = hexToDecimal(chainId);
const store = configureStore({
metamask: {
allNfts: {
[ACCOUNT_1]: {
[chainId]: collectibles,
[chainIdAsDecimal]: collectibles,
},
},
allNftContracts: {
[ACCOUNT_1]: {
[chainId]: collectibleContracts,
[chainIdAsDecimal]: collectibleContracts,
},
},
provider: { chainId },

View File

@ -17,7 +17,10 @@ import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck';
import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets';
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
import { stripHexPrefix } from '../../../shared/modules/hexstring-utils';
import { decGWEIToHexWEI } from '../../../shared/modules/conversion.utils';
import {
decGWEIToHexWEI,
hexToDecimal,
} from '../../../shared/modules/conversion.utils';
export default function reduceMetamask(state = {}, action) {
const metamaskState = {
@ -280,7 +283,9 @@ export const getCollectibles = (state) => {
},
} = state;
return allNfts?.[selectedAddress]?.[chainId] ?? [];
const chainIdAsDecimal = hexToDecimal(chainId);
return allNfts?.[selectedAddress]?.[chainIdAsDecimal] ?? [];
};
export const getCollectibleContracts = (state) => {
@ -292,7 +297,9 @@ export const getCollectibleContracts = (state) => {
},
} = state;
return allNftContracts?.[selectedAddress]?.[chainId] ?? [];
const chainIdAsDecimal = hexToDecimal(chainId);
return allNftContracts?.[selectedAddress]?.[chainIdAsDecimal] ?? [];
};
export function getBlockGasLimit(state) {