Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
import { useAlerts } from '../../../context/alert-system-context';
import { AlertKeys } from '../../../constants/alerts';
import { useAccountNoFundsAlert } from '../../../hooks/alerts/useAccountNoFundsAlert';
import { useMMPayHardwareAccountAlert } from '../../../hooks/alerts/useMMPayHardwareAccountAlert';
import { useConfirmActions } from '../../../hooks/useConfirmActions';
import EngineService from '../../../../../../core/EngineService';
import Engine from '../../../../../../core/Engine';
Expand Down Expand Up @@ -527,8 +528,12 @@ function ConfirmButton({
useConfirmationContext();
const isLoading = useIsTransactionPayLoading();
const { onConfirm } = useConfirmActions();
// Not part of the alerts context, so checked separately here. The account
// can switch to a hardware wallet at any point via PayAccountSelector.
const hardwareAccountAlerts = useMMPayHardwareAccountAlert();
Comment thread
dan437 marked this conversation as resolved.
Outdated
const disabled =
hasBlockingAlerts ||
hardwareAccountAlerts.length > 0 ||
isLoading ||
Boolean(disableConfirm) ||
isHeadlessBuyInProgress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { AlertKeys } from '../../constants/alerts';
import { Alert, Severity } from '../../types/alerts';
import { strings } from '../../../../../../locales/i18n';
import { useTransactionMetadataRequest } from '../transactions/useTransactionMetadataRequest';
import { useTransactionAccountOverride } from '../transactions/useTransactionAccountOverride';
import { useTransactionPayFiatPayment } from '../pay/useTransactionPayData';
import { hasTransactionType } from '../../utils/transaction';
import {
isHardwareAccount,
Expand All @@ -14,6 +16,8 @@ import { selectMetaMaskPayHardwareFlags } from '../../../../../selectors/feature

export function useMMPayHardwareAccountAlert(): Alert[] {
const transactionMeta = useTransactionMetadataRequest();
const accountOverride = useTransactionAccountOverride();
const fiatPayment = useTransactionPayFiatPayment();
const { enabled: isHardwarePayEnabled } = useSelector(
selectMetaMaskPayHardwareFlags,
);
Expand All @@ -26,11 +30,25 @@ export function useMMPayHardwareAccountAlert(): Alert[] {
TransactionType.musdConversion,
]);

const isHardwareWallet = isHardwareAccount(from ?? '');
const isQRWallet = isQRHardwareAccount(from ?? '');
const isMoneyAccountDeposit = hasTransactionType(transactionMeta, [
TransactionType.moneyAccountDeposit,
]);

// Money account deposits are executed by the money account itself, so
// txParams.from is never the paying account. The account paying is the
// override selected in PayAccountSelector.
const payingAccount = isMoneyAccountDeposit ? accountOverride : from;
Comment thread
dan437 marked this conversation as resolved.
Outdated

const isHardwareWallet = isHardwareAccount(payingAccount ?? '');
const isQRWallet = isQRHardwareAccount(payingAccount ?? '');

// Fiat deposits are bought directly into the money account, so the
// hardware account never signs.
const isFiatMoneyAccountDeposit =
Comment thread
dan437 marked this conversation as resolved.
Outdated
isMoneyAccountDeposit && Boolean(fiatPayment?.selectedPaymentMethodId);

return useMemo(() => {
if (!isHardwareWallet) {
if (!isHardwareWallet || isFiatMoneyAccountDeposit) {
return [];
}

Expand All @@ -47,5 +65,11 @@ export function useMMPayHardwareAccountAlert(): Alert[] {
isBlocking: true,
},
];
}, [isHardwareWallet, isHardwarePayEnabled, isMusdConversion, isQRWallet]);
}, [
isFiatMoneyAccountDeposit,
isHardwareWallet,
isHardwarePayEnabled,
isMusdConversion,
isQRWallet,
]);
}
Loading