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

Fix in approve header to show correct account name (#18849)

This commit is contained in:
Jyoti Puri 2023-04-28 13:29:53 +05:30 committed by GitHub
parent 89d4038351
commit 9d794e97b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 5 deletions

View File

@ -26,7 +26,6 @@ import ReviewSpendingCap from '../../components/ui/review-spending-cap/review-sp
import { PageContainerFooter } from '../../components/ui/page-container';
import ContractDetailsModal from '../../components/app/modals/contract-details-modal/contract-details-modal';
import {
getCurrentAccountWithSendEtherInfo,
getNetworkIdentifier,
transactionFeeSelector,
getKnownMethodData,
@ -35,6 +34,7 @@ import {
getUnapprovedTxCount,
getUnapprovedTransactions,
getUseCurrencyRateCheck,
getTargetAccountWithSendEtherInfo,
} from '../../selectors';
import { NETWORK_TO_NAME_MAP } from '../../../shared/constants/network';
import {
@ -115,7 +115,9 @@ export default function TokenAllowance({
const renderSimulationFailureWarning = useSimulationFailureWarning(
userAcknowledgedGasMissing,
);
const currentAccount = useSelector(getCurrentAccountWithSendEtherInfo);
const fromAccount = useSelector((state) =>
getTargetAccountWithSendEtherInfo(state, userAddress),
);
const networkIdentifier = useSelector(getNetworkIdentifier);
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider);
const unapprovedTxCount = useSelector(getUnapprovedTxCount);
@ -314,7 +316,7 @@ export default function TokenAllowance({
</Box>
<NetworkAccountBalanceHeader
networkName={networkName}
accountName={currentAccount.name}
accountName={fromAccount.name}
accountBalance={currentTokenBalance}
tokenName={tokenSymbol}
accountAddress={userAddress}

View File

@ -24,6 +24,10 @@ const state = {
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
name: 'Account 1',
},
'0xc42edfcc21ed14dda456aa0756c153f7985d8813': {
address: '0xc42edfcc21ed14dda456aa0756c153f7985d8813',
name: 'Account 2',
},
},
cachedBalances: {},
addressBook: [
@ -132,7 +136,7 @@ describe('TokenAllowancePage', () => {
hexTransactionTotal: '0x44364c5bb0000',
isMultiLayerFeeNetwork: false,
supportsEIP1559: true,
userAddress: '0xdd34b35ca1de17dfcdc07f79ff1f8f94868c40a1',
userAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
tokenAddress: '0x55797717b9947b31306f4aac7ad1365c6e3923bd',
data: '0x095ea7b30000000000000000000000009bc5baf874d2da8d216ae9f137804184ee5afef40000000000000000000000000000000000000000000000000000000000011170',
isSetApproveForAll: false,
@ -157,7 +161,7 @@ describe('TokenAllowancePage', () => {
},
sendFlowHistory: [],
txParams: {
from: '0xdd34b35ca1de17dfcdc07f79ff1f8f94868c40a1',
from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
to: '0x55797717b9947b31306f4aac7ad1365c6e3923bd',
value: '0x0',
data: '0x095ea7b30000000000000000000000009bc5baf874d2da8d216ae9f137804184ee5afef40000000000000000000000000000000000000000000000000000000000011170',
@ -311,4 +315,31 @@ describe('TokenAllowancePage', () => {
expect(getByText(securityProviderResponse.reason)).toBeInTheDocument();
});
it('should render from account name in header', () => {
const { getByText } = renderWithProvider(
<TokenAllowance {...props} />,
store,
);
expect(getByText('Account 1')).toBeInTheDocument();
});
it('should account name from transaction even if currently selected account is different', () => {
const newState = {
...state,
metamask: {
...state.metamask,
selectedAddress: '0xc42edfcc21ed14dda456aa0756c153f7985d8813',
},
};
const newStore = configureMockStore()(newState);
const { queryByText } = renderWithProvider(
<TokenAllowance {...props} />,
newStore,
);
expect(queryByText('Account 1')).toBeInTheDocument();
expect(queryByText('Account 2')).not.toBeInTheDocument();
});
});