mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
Track when token balance is changed to update value on approval screen (#16964)
* Track when token balance is changed to update value on approval screen * Code refactor * Fix unit test * Fix sign approval balance * Refactor code
This commit is contained in:
parent
c61d44a3be
commit
362497ed64
@ -50,7 +50,6 @@ export default class SignatureRequestOriginal extends Component {
|
||||
};
|
||||
|
||||
state = {
|
||||
fromAccount: this.props.fromAccount,
|
||||
showSignatureRequestWarning: false,
|
||||
};
|
||||
|
||||
@ -274,11 +273,13 @@ export default class SignatureRequestOriginal extends Component {
|
||||
};
|
||||
|
||||
render = () => {
|
||||
const { messagesCount, conversionRate, nativeCurrency } = this.props;
|
||||
const {
|
||||
messagesCount,
|
||||
conversionRate,
|
||||
nativeCurrency,
|
||||
fromAccount: { address, balance, name },
|
||||
showSignatureRequestWarning,
|
||||
} = this.state;
|
||||
} = this.props;
|
||||
const { showSignatureRequestWarning } = this.state;
|
||||
const { t } = this.context;
|
||||
|
||||
const rejectNText = t('rejectRequestsN', [messagesCount]);
|
||||
|
@ -1,22 +1,33 @@
|
||||
import { isEqual } from 'lodash';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { getCollectibles } from '../ducks/metamask/metamask';
|
||||
import { getCollectibles, getTokens } from '../ducks/metamask/metamask';
|
||||
import { getAssetDetails } from '../helpers/utils/token-util';
|
||||
import { hideLoadingIndication, showLoadingIndication } from '../store/actions';
|
||||
import { isEqualCaseInsensitive } from '../../shared/modules/string-utils';
|
||||
import { usePrevious } from './usePrevious';
|
||||
import { useTokenTracker } from './useTokenTracker';
|
||||
|
||||
export function useAssetDetails(tokenAddress, userAddress, transactionData) {
|
||||
const dispatch = useDispatch();
|
||||
// state selectors
|
||||
const collectibles = useSelector(getCollectibles);
|
||||
const tokens = useSelector(getTokens, isEqual);
|
||||
const currentToken = tokens.find((token) =>
|
||||
isEqualCaseInsensitive(token.address, tokenAddress),
|
||||
);
|
||||
|
||||
// in-hook state
|
||||
const [currentAsset, setCurrentAsset] = useState(null);
|
||||
const { tokensWithBalances } = useTokenTracker(
|
||||
currentToken ? [currentToken] : [],
|
||||
);
|
||||
|
||||
// previous state checkers
|
||||
const prevTokenAddress = usePrevious(tokenAddress);
|
||||
const prevUserAddress = usePrevious(userAddress);
|
||||
const prevTransactionData = usePrevious(transactionData);
|
||||
const prevTokenBalance = usePrevious(tokensWithBalances);
|
||||
|
||||
useEffect(() => {
|
||||
async function getAndSetAssetDetails() {
|
||||
@ -33,7 +44,8 @@ export function useAssetDetails(tokenAddress, userAddress, transactionData) {
|
||||
if (
|
||||
tokenAddress !== prevTokenAddress ||
|
||||
userAddress !== prevUserAddress ||
|
||||
transactionData !== prevTransactionData
|
||||
transactionData !== prevTransactionData ||
|
||||
(prevTokenBalance && prevTokenBalance !== tokensWithBalances)
|
||||
) {
|
||||
getAndSetAssetDetails();
|
||||
}
|
||||
@ -46,6 +58,8 @@ export function useAssetDetails(tokenAddress, userAddress, transactionData) {
|
||||
userAddress,
|
||||
transactionData,
|
||||
collectibles,
|
||||
tokensWithBalances,
|
||||
prevTokenBalance,
|
||||
]);
|
||||
|
||||
if (currentAsset) {
|
||||
|
@ -19,6 +19,7 @@ const renderUseAssetDetails = ({
|
||||
chainId: '0x5',
|
||||
},
|
||||
tokenList: {},
|
||||
tokens: [],
|
||||
},
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user