mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
c16b35c029
* Extend wallet_watchAsset to support ERC721 and ERC1155 tokens
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
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 function hasPendingApprovals(
|
|
state: ApprovalsMetaMaskState,
|
|
approvalType: ApprovalType,
|
|
predicate?: (
|
|
approval: ApprovalControllerState['pendingApprovals'][string],
|
|
) => boolean,
|
|
) {
|
|
const pendingApprovalRequests = Object.values(
|
|
state.metamask.pendingApprovals,
|
|
).filter(({ type }) => type === approvalType);
|
|
|
|
if (predicate) {
|
|
return pendingApprovalRequests.some(predicate);
|
|
}
|
|
|
|
return pendingApprovalRequests.length > 0;
|
|
}
|
|
|
|
export const getApprovalRequestsByType = (
|
|
state: ApprovalsMetaMaskState,
|
|
approvalType: ApprovalType,
|
|
predicate?: (
|
|
approval: ApprovalControllerState['pendingApprovals'][string],
|
|
) => boolean,
|
|
) => {
|
|
const pendingApprovalRequests = Object.values(
|
|
state.metamask.pendingApprovals,
|
|
).filter(({ type }) => type === approvalType);
|
|
|
|
if (predicate) {
|
|
return pendingApprovalRequests.filter(predicate);
|
|
}
|
|
|
|
return pendingApprovalRequests;
|
|
};
|