1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Ledger trezor display (#18637)

* gst

* Only display ledger info on approval screen for ledger hardware wallets
This commit is contained in:
Dan J Miller 2023-04-18 17:19:49 -02:30 committed by GitHub
parent 599bef9dc5
commit 39f6042e65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 10 deletions

View File

@ -200,6 +200,7 @@ export default function ConfirmApprove({
toAddress={toAddress} toAddress={toAddress}
tokenSymbol={tokenSymbol} tokenSymbol={tokenSymbol}
decimals={decimals} decimals={decimals}
fromAddressIsLedger={fromAddressIsLedger}
/> />
{showCustomizeGasPopover && !supportsEIP1559 && ( {showCustomizeGasPopover && !supportsEIP1559 && (
<EditGasPopover <EditGasPopover

View File

@ -35,7 +35,6 @@ import {
getUnapprovedTxCount, getUnapprovedTxCount,
getUnapprovedTransactions, getUnapprovedTransactions,
getUseCurrencyRateCheck, getUseCurrencyRateCheck,
isHardwareWallet,
} from '../../selectors'; } from '../../selectors';
import { NETWORK_TO_NAME_MAP } from '../../../shared/constants/network'; import { NETWORK_TO_NAME_MAP } from '../../../shared/constants/network';
import { import {
@ -95,6 +94,7 @@ export default function TokenAllowance({
currentTokenBalance, currentTokenBalance,
toAddress, toAddress,
tokenSymbol, tokenSymbol,
fromAddressIsLedger,
}) { }) {
const t = useContext(I18nContext); const t = useContext(I18nContext);
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -122,7 +122,6 @@ export default function TokenAllowance({
const unapprovedTxCount = useSelector(getUnapprovedTxCount); const unapprovedTxCount = useSelector(getUnapprovedTxCount);
const unapprovedTxs = useSelector(getUnapprovedTransactions); const unapprovedTxs = useSelector(getUnapprovedTransactions);
const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck); const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck);
const isHardwareWalletConnected = useSelector(isHardwareWallet);
let customTokenAmount = useSelector(getCustomTokenAmount); let customTokenAmount = useSelector(getCustomTokenAmount);
if (thisOriginIsAllowedToSkipFirstPage && dappProposedTokenAmount) { if (thisOriginIsAllowedToSkipFirstPage && dappProposedTokenAmount) {
customTokenAmount = dappProposedTokenAmount; customTokenAmount = dappProposedTokenAmount;
@ -516,7 +515,7 @@ export default function TokenAllowance({
</Box> </Box>
</Box> </Box>
) : null} ) : null}
{!isFirstPage && isHardwareWalletConnected && ( {!isFirstPage && fromAddressIsLedger && (
<Box paddingLeft={2} paddingRight={2}> <Box paddingLeft={2} paddingRight={2}>
<LedgerInstructionField showDataInstruction /> <LedgerInstructionField showDataInstruction />
</Box> </Box>
@ -643,4 +642,8 @@ TokenAllowance.propTypes = {
* Symbol of the token that is waiting to be allowed * Symbol of the token that is waiting to be allowed
*/ */
tokenSymbol: PropTypes.string, tokenSymbol: PropTypes.string,
/**
* Whether the address sending the transaction is a ledger address
*/
fromAddressIsLedger: PropTypes.bool,
}; };

View File

@ -65,10 +65,10 @@ const state = {
}, },
], ],
unapprovedTxs: {}, unapprovedTxs: {},
keyringTypes: [KeyringType.ledger], keyringTypes: [],
keyrings: [ keyrings: [
{ {
type: KeyringType.ledger, type: KeyringType.hdKeyTree,
accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'], accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
}, },
], ],
@ -256,9 +256,9 @@ describe('TokenAllowancePage', () => {
expect(gotIt).not.toBeInTheDocument(); expect(gotIt).not.toBeInTheDocument();
}); });
it('should show hardware wallet info text', () => { it('should show ledger info text if the sending address is ledger', () => {
const { queryByText, getByText, getByTestId } = renderWithProvider( const { queryByText, getByText, getByTestId } = renderWithProvider(
<TokenAllowance {...props} />, <TokenAllowance {...props} fromAddressIsLedger />,
store, store,
); );
@ -273,12 +273,20 @@ describe('TokenAllowancePage', () => {
expect(queryByText('Prior to clicking confirm:')).toBeInTheDocument(); expect(queryByText('Prior to clicking confirm:')).toBeInTheDocument();
}); });
it('should not show hardware wallet info text', () => { it('should not show ledger info text if the sending address is not ledger', () => {
const { queryByText } = renderWithProvider( const { queryByText, getByText, getByTestId } = renderWithProvider(
<TokenAllowance {...props} />, <TokenAllowance {...props} fromAddressIsLedger={false} />,
store, store,
); );
const textField = getByTestId('custom-spending-cap-input');
fireEvent.change(textField, { target: { value: '1' } });
expect(queryByText('Prior to clicking confirm:')).toBeNull();
const nextButton = getByText('Next');
fireEvent.click(nextButton);
expect(queryByText('Prior to clicking confirm:')).toBeNull(); expect(queryByText('Prior to clicking confirm:')).toBeNull();
}); });