mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 02:10:12 +01:00
36 lines
935 B
TypeScript
36 lines
935 B
TypeScript
import { ApprovalControllerState } from '@metamask/approval-controller';
|
|
import { ApprovalType } from '@metamask/controller-utils';
|
|
import { TransactionMeta } from '../../shared/constants/transaction';
|
|
|
|
type ApprovalsMetaMaskState = {
|
|
metamask: {
|
|
pendingApprovals: ApprovalControllerState['pendingApprovals'];
|
|
unapprovedTxs: {
|
|
[transactionId: string]: TransactionMeta;
|
|
};
|
|
};
|
|
};
|
|
|
|
export const getApprovalRequestsByType = (
|
|
state: ApprovalsMetaMaskState,
|
|
approvalType: ApprovalType,
|
|
) => {
|
|
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,
|
|
);
|
|
|
|
return pendingApprovalRequests.length > 0;
|
|
}
|