1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 03:20:23 +01:00
metamask-extension/ui/selectors/approvals.ts

36 lines
935 B
TypeScript
Raw Normal View History

2023-04-25 11:47:49 +02:00
import { ApprovalControllerState } from '@metamask/approval-controller';
import { ApprovalType } from '@metamask/controller-utils';
import { TransactionMeta } from '../../shared/constants/transaction';
2023-04-25 11:47:49 +02:00
type ApprovalsMetaMaskState = {
metamask: {
pendingApprovals: ApprovalControllerState['pendingApprovals'];
unapprovedTxs: {
[transactionId: string]: TransactionMeta;
};
2023-04-25 11:47:49 +02:00
};
};
export const getApprovalRequestsByType = (
2023-04-25 11:47:49 +02:00
state: ApprovalsMetaMaskState,
approvalType: ApprovalType,
) => {
2023-04-25 11:47:49 +02:00
const pendingApprovalRequests = Object.values(
state.metamask.pendingApprovals,
).filter(({ type }) => type === approvalType);
return pendingApprovalRequests;
};
export function hasPendingApprovals(
state: ApprovalsMetaMaskState,
approvalType: ApprovalType,
) {
const pendingApprovalRequests = getApprovalRequestsByType(
state,
approvalType,
);
2023-04-25 11:47:49 +02:00
return pendingApprovalRequests.length > 0;
}