From 90e9d43bfa99197acb34516fc1de82fb05b996f6 Mon Sep 17 00:00:00 2001 From: Vinicius Stevam Date: Tue, 4 Jul 2023 13:39:40 +0100 Subject: [PATCH 1/5] add approval flow success and error --- app/components/Nav/Main/RootRPCMethodsUI.js | 53 +- .../__snapshots__/index.test.tsx.snap | 0 .../ApprovalFlowLoader/index.js | 8 +- .../ApprovalFlowLoader/index.test.tsx | 2 +- .../ApprovalFlowResult.styles.ts | 60 ++ .../ApprovalFlowResult.test.tsx | 51 ++ .../ApprovalFlowResult/ApprovalFlowResult.tsx | 92 +++ .../ApprovalFlow/ApprovalFlowResult/index.ts | 4 + app/constants/test-ids.js | 3 + locales/languages/en.json | 5 + .../@metamask+approval-controller+3.3.0.patch | 763 ++++++++++++++++++ 11 files changed, 1035 insertions(+), 6 deletions(-) rename app/components/UI/{ => ApprovalFlow}/ApprovalFlowLoader/__snapshots__/index.test.tsx.snap (100%) rename app/components/UI/{ => ApprovalFlow}/ApprovalFlowLoader/index.js (86%) rename app/components/UI/{ => ApprovalFlow}/ApprovalFlowLoader/index.test.tsx (86%) create mode 100644 app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.styles.ts create mode 100644 app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.test.tsx create mode 100644 app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.tsx create mode 100644 app/components/UI/ApprovalFlow/ApprovalFlowResult/index.ts create mode 100644 patches/@metamask+approval-controller+3.3.0.patch diff --git a/app/components/Nav/Main/RootRPCMethodsUI.js b/app/components/Nav/Main/RootRPCMethodsUI.js index 2500c634865..ee06b3e664b 100644 --- a/app/components/Nav/Main/RootRPCMethodsUI.js +++ b/app/components/Nav/Main/RootRPCMethodsUI.js @@ -31,7 +31,7 @@ import { import { BN } from 'ethereumjs-util'; import Logger from '../../../util/Logger'; import Approve from '../../Views/ApproveView/Approve'; -import ApprovalFlowLoader from '../../UI/ApprovalFlowLoader'; +import ApprovalFlowLoader from '../../UI/ApprovalFlow/ApprovalFlowLoader'; import WatchAssetRequest from '../../UI/WatchAssetRequest'; import AccountApproval from '../../UI/AccountApproval'; import TransactionTypes from '../../../core/TransactionTypes'; @@ -58,6 +58,11 @@ import { selectProviderType, } from '../../../selectors/networkController'; import { createAccountConnectNavDetails } from '../../Views/AccountConnect'; +import { ApprovalFlowResult } from '../../UI/ApprovalFlow/ApprovalFlowResult'; +import { + APPROVAL_TYPE_RESULT_ERROR, + APPROVAL_TYPE_RESULT_SUCCESS, +} from '@metamask/approval-controller'; const APPROVAL_TYPES_WITH_DISABLED_CLOSE_ON_APPROVE = [ ApprovalTypes.TRANSACTION, @@ -91,6 +96,8 @@ const RootRPCMethodsUI = (props) => { const [watchAsset, setWatchAsset] = useState(undefined); + const [approvalFlowResult, setApprovalFlowResult] = useState(undefined); + const [signMessageParams, setSignMessageParams] = useState(undefined); const setTransactionObject = props.setTransactionObject; @@ -403,6 +410,41 @@ const RootRPCMethodsUI = (props) => { ); + const onApprovalFlowResultConfirm = () => { + setShowPendingApproval(false); + acceptPendingApproval(approvalFlowResult.id, approvalFlowResult.data); + setApprovalFlowResult(undefined); + }; + + const renderApprovalFlowResultModal = () => { + if ( + showPendingApproval?.type !== APPROVAL_TYPE_RESULT_SUCCESS && + showPendingApproval?.type !== APPROVAL_TYPE_RESULT_ERROR + ) { + return null; + } + return ( + + + + ); + }; + const renderQRSigningModal = () => { const { isSigningQRObject, QRState } = props; @@ -789,6 +831,14 @@ const RootRPCMethodsUI = (props) => { origin: request.origin, }); break; + case APPROVAL_TYPE_RESULT_SUCCESS: + case APPROVAL_TYPE_RESULT_ERROR: + setApprovalFlowResult({ data: requestData, id: request.id }); + showPendingApprovalModal({ + type: request.type, + origin: request.origin, + }); + break; default: break; } @@ -850,6 +900,7 @@ const RootRPCMethodsUI = (props) => { {renderQRSigningModal()} {renderAccountsApprovalModal()} {renderApprovalFlowModal()} + {renderApprovalFlowResultModal()} ); }; diff --git a/app/components/UI/ApprovalFlowLoader/__snapshots__/index.test.tsx.snap b/app/components/UI/ApprovalFlow/ApprovalFlowLoader/__snapshots__/index.test.tsx.snap similarity index 100% rename from app/components/UI/ApprovalFlowLoader/__snapshots__/index.test.tsx.snap rename to app/components/UI/ApprovalFlow/ApprovalFlowLoader/__snapshots__/index.test.tsx.snap diff --git a/app/components/UI/ApprovalFlowLoader/index.js b/app/components/UI/ApprovalFlow/ApprovalFlowLoader/index.js similarity index 86% rename from app/components/UI/ApprovalFlowLoader/index.js rename to app/components/UI/ApprovalFlow/ApprovalFlowLoader/index.js index acacd5a0ebc..637e05eb536 100644 --- a/app/components/UI/ApprovalFlowLoader/index.js +++ b/app/components/UI/ApprovalFlow/ApprovalFlowLoader/index.js @@ -1,10 +1,10 @@ import React from 'react'; import { StyleSheet, View } from 'react-native'; import PropTypes from 'prop-types'; -import Device from '../../../util/device'; -import { useTheme } from '../../../util/theme'; -import Text from '../../Base/Text'; -import Spinner from '../AnimatedSpinner'; +import Device from '../../../../util/device'; +import { useTheme } from '../../../../util/theme'; +import Text from '../../../Base/Text'; +import Spinner from '../../AnimatedSpinner'; const createStyles = (colors) => StyleSheet.create({ diff --git a/app/components/UI/ApprovalFlowLoader/index.test.tsx b/app/components/UI/ApprovalFlow/ApprovalFlowLoader/index.test.tsx similarity index 86% rename from app/components/UI/ApprovalFlowLoader/index.test.tsx rename to app/components/UI/ApprovalFlow/ApprovalFlowLoader/index.test.tsx index dcc3f445e0f..2752a7d4836 100644 --- a/app/components/UI/ApprovalFlowLoader/index.test.tsx +++ b/app/components/UI/ApprovalFlow/ApprovalFlowLoader/index.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { shallow } from 'enzyme'; -import ApprovalFlowLoader from './'; +import ApprovalFlowLoader from '.'; describe('ApprovalFlowLoader', () => { it('should render correctly', () => { diff --git a/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.styles.ts b/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.styles.ts new file mode 100644 index 00000000000..1f2c1c087ec --- /dev/null +++ b/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.styles.ts @@ -0,0 +1,60 @@ +import { StyleSheet } from 'react-native'; +import { Theme } from '../../../../util/theme/models'; +import Device from '../../../../util/device'; + +/** + * + * @param params Style sheet params. + * @param params.theme App theme from ThemeContext. + * @param params.vars Inputs that the style sheet depends on. + * @returns StyleSheet object. + */ +const styleSheet = (params: { theme: Theme }) => { + const { theme } = params; + const { colors } = theme; + return StyleSheet.create({ + root: { + backgroundColor: colors.background.default, + paddingTop: 24, + borderTopLeftRadius: 20, + borderTopRightRadius: 20, + minHeight: 200, + paddingBottom: Device.isIphoneX() ? 20 : 0, + }, + accountCardWrapper: { + paddingHorizontal: 24, + }, + actionContainer: { + flex: 0, + paddingVertical: 16, + justifyContent: 'center', + }, + description: { + textAlign: 'center', + paddingBottom: 16, + }, + snapCell: { + marginVertical: 16, + }, + snapPermissionContainer: { + maxHeight: 300, + borderWidth: 1, + borderRadius: 8, + borderColor: colors.border.muted, + }, + iconContainer: { + justifyContent: 'center', + alignItems: 'center', + }, + iconWrapper: { + width: 48, + height: 48, + borderRadius: 24, + backgroundColor: colors.success.muted, + justifyContent: 'center', + alignItems: 'center', + }, + }); +}; + +export default styleSheet; diff --git a/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.test.tsx b/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.test.tsx new file mode 100644 index 00000000000..9aa1c251254 --- /dev/null +++ b/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.test.tsx @@ -0,0 +1,51 @@ +import React from 'react'; +import { render, fireEvent } from '@testing-library/react-native'; +import ApprovalFlowResult from './ApprovalFlowResult'; + +describe('ApprovalFlowResult', () => { + const mockProps = { + requestData: { + data: { + message: 'Success message', + }, + }, + onConfirm: jest.fn(), + requestType: 'result_success', + }; + + it('renders approval flow result with success type and confirms', () => { + const { getByTestId, getByText } = render( + , + ); + + expect(getByTestId('approval-flow-result')).toBeTruthy(); + expect(getByText('Success')).toBeTruthy(); + expect(getByText(mockProps.requestData.data.message)).toBeTruthy(); + fireEvent.press(getByText('OK')); + + expect(mockProps.onConfirm).toHaveBeenCalled(); + }); + + it('renders approval flow result with error type and confirms', () => { + const errorMockProps = { + ...mockProps, + requestData: { + data: { + error: 'Error message', + }, + }, + requestType: 'result_error', + }; + + const { getByTestId, getByText } = render( + , + ); + + expect(getByTestId('approval-flow-result')).toBeTruthy(); + expect(getByText('Error')).toBeTruthy(); + expect(getByText(errorMockProps.requestData.data.error)).toBeTruthy(); + fireEvent.press(getByText('OK')); + + expect(mockProps.onConfirm).toHaveBeenCalled(); + }); +}); diff --git a/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.tsx b/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.tsx new file mode 100644 index 00000000000..cafa8bf03c6 --- /dev/null +++ b/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.tsx @@ -0,0 +1,92 @@ +import React from 'react'; +import { View } from 'react-native'; +import stylesheet from './ApprovalFlowResult.styles'; +import { strings } from '../../../../../locales/i18n'; +import SheetHeader from '../../../../component-library/components/Sheet/SheetHeader'; +import Text, { + TextVariant, +} from '../../../../component-library/components/Texts/Text'; +import Icon, { + IconColor, + IconName, + IconSize, +} from '../../../../component-library/components/Icons/Icon'; +import { + ButtonSize, + ButtonVariants, +} from '../../../../component-library/components/Buttons/Button'; +import BottomSheetFooter, { + ButtonsAlignment, +} from '../../../../component-library/components/BottomSheets/BottomSheetFooter'; +import { ButtonProps } from '../../../../component-library/components/Buttons/Button/Button.types'; +import { useStyles } from '../../../hooks/useStyles'; +import { APPROVAL_TYPE_RESULT_SUCCESS } from '@metamask/approval-controller'; +import { APPROVAL_FLOW_RESULT_ID } from '../../../../constants/test-ids'; + +interface ApprovalFlowResultProps { + requestData: any; + onConfirm: () => void; + requestType: string; +} + +const ApprovalFlowResult = ({ + requestData, + onConfirm, + requestType, +}: ApprovalFlowResultProps) => { + const { styles } = useStyles(stylesheet, {}); + + const isApprovalTypeResultSuccess = (type: string) => + APPROVAL_TYPE_RESULT_SUCCESS === type; + + const okButtonProps: ButtonProps = { + variant: ButtonVariants.Primary, + label: strings('approval_flow.ok'), + size: ButtonSize.Lg, + onPress: onConfirm, + }; + + return ( + + + + + + + + + + {isApprovalTypeResultSuccess(requestType) + ? requestData?.data?.message + : requestData?.data?.error} + + + + + + + ); +}; + +export default ApprovalFlowResult; diff --git a/app/components/UI/ApprovalFlow/ApprovalFlowResult/index.ts b/app/components/UI/ApprovalFlow/ApprovalFlowResult/index.ts new file mode 100644 index 00000000000..be94133855a --- /dev/null +++ b/app/components/UI/ApprovalFlow/ApprovalFlowResult/index.ts @@ -0,0 +1,4 @@ +/* eslint-disable import/prefer-default-export */ +import ApprovalFlowResult from './ApprovalFlowResult'; + +export { ApprovalFlowResult }; diff --git a/app/constants/test-ids.js b/app/constants/test-ids.js index 89167a62d4d..8c7f1d9234a 100644 --- a/app/constants/test-ids.js +++ b/app/constants/test-ids.js @@ -101,3 +101,6 @@ export const SIGNATURE_MODAL_CANCEL_BUTTON_ID = // Advanced Settings export const ADVANCED_SETTINGS_CONTAINER_ID = 'advanced-settings'; export const ETH_SIGN_SWITCH_ID = 'eth-sign-switch'; + +// Approval Flow +export const APPROVAL_FLOW_RESULT_ID = 'approval-flow-result'; diff --git a/locales/languages/en.json b/locales/languages/en.json index 83b21410a38..b1ca462c280 100644 --- a/locales/languages/en.json +++ b/locales/languages/en.json @@ -430,6 +430,11 @@ "cta_no_thanks": "No thanks", "cta_i_agree": "I agree" }, + "approval_flow": { + "ok": "OK", + "success": "Success", + "error": "Error" + }, "token": { "token_symbol": "Token Symbol", "token_address": "Token Address", diff --git a/patches/@metamask+approval-controller+3.3.0.patch b/patches/@metamask+approval-controller+3.3.0.patch new file mode 100644 index 00000000000..97d2002781a --- /dev/null +++ b/patches/@metamask+approval-controller+3.3.0.patch @@ -0,0 +1,763 @@ +diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts b/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts +index 4ffc763..29de2a5 100644 +--- a/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts ++++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts +@@ -2,9 +2,20 @@ import type { Patch } from 'immer'; + import { EthereumRpcError } from 'eth-rpc-errors'; + import { BaseControllerV2, RestrictedControllerMessenger } from '@metamask/base-controller'; + import { Json, OptionalField } from '@metamask/utils'; ++export declare const ORIGIN_METAMASK = "metamask"; ++export declare const APPROVAL_TYPE_RESULT_ERROR = "result_error"; ++export declare const APPROVAL_TYPE_RESULT_SUCCESS = "result_success"; + declare const controllerName = "ApprovalController"; + declare type ApprovalRequestData = Record | null; + declare type ApprovalRequestState = Record | null; ++declare type ApprovalFlow = { ++ id: string; ++ loadingText: string | null; ++}; ++declare type ResultOptions = { ++ flowToEnd?: string; ++ header?: (string | ResultComponent)[]; ++}; + export declare type ApprovalRequest = { + /** + * The ID of the approval request. +@@ -36,26 +47,39 @@ export declare type ApprovalRequest = { + */ + expectsResult: boolean; + }; +-declare type ShowApprovalRequest = () => void | Promise; +-declare type ApprovalFlow = { +- id: string; +- loadingText: string | null; +-}; + export declare type ApprovalFlowState = ApprovalFlow; + export declare type ApprovalControllerState = { + pendingApprovals: Record>>; + pendingApprovalCount: number; + approvalFlows: ApprovalFlowState[]; + }; +-export declare type GetApprovalsState = { +- type: `${typeof controllerName}:getState`; +- handler: () => ApprovalControllerState; ++export declare type ApprovalControllerMessenger = RestrictedControllerMessenger; ++export declare type ShowApprovalRequest = () => void | Promise; ++export declare type ResultComponent = { ++ /** ++ * A unique identifier for this instance of the component. ++ */ ++ key: string; ++ /** ++ * The name of the component to render. ++ */ ++ name: string; ++ /** ++ * Any properties required by the component. ++ */ ++ properties?: Record; ++ /** ++ * Any child components to render inside the component. ++ */ ++ children?: string | ResultComponent | (string | ResultComponent)[]; + }; +-export declare type ClearApprovalRequests = { +- type: `${typeof controllerName}:clearRequests`; +- handler: (error: EthereumRpcError) => void; ++export declare type ApprovalControllerOptions = { ++ messenger: ApprovalControllerMessenger; ++ showApprovalRequest: ShowApprovalRequest; ++ state?: Partial; ++ typesExcludedFromRateLimiting?: string[]; + }; +-declare type AddApprovalOptions = { ++export declare type AddApprovalOptions = { + id?: string; + origin: string; + type: string; +@@ -63,30 +87,10 @@ declare type AddApprovalOptions = { + requestState?: Record; + expectsResult?: boolean; + }; +-export declare type AddApprovalRequest = { +- type: `${typeof controllerName}:addRequest`; +- handler: (opts: AddApprovalOptions, shouldShowRequest: boolean) => ReturnType; +-}; +-export declare type HasApprovalRequest = { +- type: `${typeof controllerName}:hasRequest`; +- handler: ApprovalController['has']; +-}; +-export declare type AcceptRequest = { +- type: `${typeof controllerName}:acceptRequest`; +- handler: ApprovalController['accept']; +-}; +-export declare type RejectRequest = { +- type: `${typeof controllerName}:rejectRequest`; +- handler: ApprovalController['reject']; +-}; +-declare type UpdateRequestStateOptions = { ++export declare type UpdateRequestStateOptions = { + id: string; + requestState: Record; + }; +-export declare type UpdateRequestState = { +- type: `${typeof controllerName}:updateRequestState`; +- handler: ApprovalController['updateRequestState']; +-}; + export declare type AcceptOptions = { + /** + * Whether to resolve the returned promise only when the request creator indicates the success of the +@@ -95,11 +99,14 @@ export declare type AcceptOptions = { + */ + waitForResult?: boolean; + }; +-export declare type AcceptResult = { +- /** +- * An optional value provided by the request creator when indicating a successful result. +- */ +- value?: unknown; ++export declare type StartFlowOptions = OptionalField; ++export declare type EndFlowOptions = Pick; ++export declare type SetFlowLoadingTextOptions = ApprovalFlow; ++export declare type SuccessOptions = ResultOptions & { ++ message?: string | ResultComponent | (string | ResultComponent)[]; ++}; ++export declare type ErrorOptions = ResultOptions & { ++ error?: string | ResultComponent | (string | ResultComponent)[]; + }; + export declare type AcceptResultCallbacks = { + /** +@@ -126,10 +133,48 @@ export declare type AddResult = { + */ + resultCallbacks?: AcceptResultCallbacks; + }; +-export declare type StartFlowOptions = OptionalField; ++export declare type AcceptResult = { ++ /** ++ * An optional value provided by the request creator when indicating a successful result. ++ */ ++ value?: unknown; ++}; + export declare type ApprovalFlowStartResult = ApprovalFlow; +-export declare type EndFlowOptions = Pick; +-export declare type SetFlowLoadingTextOptions = ApprovalFlow; ++export declare type SuccessResult = Record; ++export declare type ErrorResult = Record; ++export declare type ApprovalStateChange = { ++ type: `${typeof controllerName}:stateChange`; ++ payload: [ApprovalControllerState, Patch[]]; ++}; ++export declare type ApprovalControllerEvents = ApprovalStateChange; ++export declare type GetApprovalsState = { ++ type: `${typeof controllerName}:getState`; ++ handler: () => ApprovalControllerState; ++}; ++export declare type ClearApprovalRequests = { ++ type: `${typeof controllerName}:clearRequests`; ++ handler: (error: EthereumRpcError) => void; ++}; ++export declare type AddApprovalRequest = { ++ type: `${typeof controllerName}:addRequest`; ++ handler: (opts: AddApprovalOptions, shouldShowRequest: boolean) => ReturnType; ++}; ++export declare type HasApprovalRequest = { ++ type: `${typeof controllerName}:hasRequest`; ++ handler: ApprovalController['has']; ++}; ++export declare type AcceptRequest = { ++ type: `${typeof controllerName}:acceptRequest`; ++ handler: ApprovalController['accept']; ++}; ++export declare type RejectRequest = { ++ type: `${typeof controllerName}:rejectRequest`; ++ handler: ApprovalController['reject']; ++}; ++export declare type UpdateRequestState = { ++ type: `${typeof controllerName}:updateRequestState`; ++ handler: ApprovalController['updateRequestState']; ++}; + export declare type StartFlow = { + type: `${typeof controllerName}:startFlow`; + handler: ApprovalController['startFlow']; +@@ -142,19 +187,15 @@ export declare type SetFlowLoadingText = { + type: `${typeof controllerName}:setFlowLoadingText`; + handler: ApprovalController['setFlowLoadingText']; + }; +-export declare type ApprovalControllerActions = GetApprovalsState | ClearApprovalRequests | AddApprovalRequest | HasApprovalRequest | AcceptRequest | RejectRequest | UpdateRequestState | StartFlow | EndFlow | SetFlowLoadingText; +-export declare type ApprovalStateChange = { +- type: `${typeof controllerName}:stateChange`; +- payload: [ApprovalControllerState, Patch[]]; ++export declare type ShowSuccess = { ++ type: `${typeof controllerName}:showSuccess`; ++ handler: ApprovalController['success']; + }; +-export declare type ApprovalControllerEvents = ApprovalStateChange; +-export declare type ApprovalControllerMessenger = RestrictedControllerMessenger; +-declare type ApprovalControllerOptions = { +- messenger: ApprovalControllerMessenger; +- showApprovalRequest: ShowApprovalRequest; +- state?: Partial; +- typesExcludedFromRateLimiting?: string[]; ++export declare type ShowError = { ++ type: `${typeof controllerName}:showError`; ++ handler: ApprovalController['error']; + }; ++export declare type ApprovalControllerActions = GetApprovalsState | ClearApprovalRequests | AddApprovalRequest | HasApprovalRequest | AcceptRequest | RejectRequest | UpdateRequestState | StartFlow | EndFlow | SetFlowLoadingText | ShowSuccess | ShowError; + /** + * Controller for managing requests that require user approval. + * +@@ -165,10 +206,7 @@ declare type ApprovalControllerOptions = { + * is approved or denied, respectively. + */ + export declare class ApprovalController extends BaseControllerV2 { +- private _approvals; +- private _origins; +- private _showApprovalRequest; +- private _typesExcludedFromRateLimiting; ++ #private; + /** + * Construct an Approval controller. + * +@@ -373,65 +411,25 @@ export declare class ApprovalController extends BaseControllerV2; + /** +- * Gets the approval callbacks for the given id, deletes the entry, and then +- * returns the callbacks for promise resolution. +- * Throws an error if no approval is found for the given id. ++ * Show an error page. + * +- * @param id - The id of the approval request. +- * @returns The promise callbacks associated with the approval request. ++ * @param opts - Options bag. ++ * @param opts.message - The message text or components to display in the page. ++ * @param opts.header - The text or components to display in the header of the page. ++ * @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved. ++ * @returns Empty object to support future additions. + */ +- private _deleteApprovalAndGetCallbacks; ++ error(opts?: ErrorOptions): Promise; + } + export default ApprovalController; + //# sourceMappingURL=ApprovalController.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts.map b/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts.map +index cbd9ac2..ad5e004 100644 +--- a/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts.map ++++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"ApprovalController.d.ts","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAa,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAStD,QAAA,MAAM,cAAc,uBAAuB,CAAC;AAM5C,aAAK,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;AAEvD,aAAK,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;AAOxD,oBAAY,eAAe,CAAC,WAAW,SAAS,mBAAmB,IAAI;IACrE;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAC;IAEzB;;OAEG;IACH,YAAY,EAAE,oBAAoB,CAAC;IAEnC;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,aAAK,mBAAmB,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtD,aAAK,YAAY,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,oBAAY,iBAAiB,GAAG,YAAY,CAAC;AAE7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;;;;;;;;;OAUG;IACH,MAAM,CACJ,EAAE,EAAE,MAAM,EACV,KAAK,CAAC,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,CAAC;IA8BxB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAIxC;;;;;OAKG;IACH,KAAK,CAAC,cAAc,EAAE,gBAAgB,CAAC,OAAO,CAAC,GAAG,IAAI;IAWtD;;;;;;OAMG;IACH,kBAAkB,CAAC,IAAI,EAAE,yBAAyB,GAAG,IAAI;IAYzD;;;;;;;OAOG;IACH,SAAS,CAAC,IAAI,GAAE,gBAAqB,GAAG,uBAAuB;IAa/D;;;;;OAKG;IACH,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,cAAc;IAmB9B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,yBAAyB;IAcjE;;;;;;;;;;OAUG;IACH,OAAO,CAAC,IAAI;IAmCZ;;;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB;IAiC1B;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IAYjC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,WAAW;IA2BnB;;;;;;;OAOG;IACH,OAAO,CAAC,OAAO;IA0Bf;;;;;;;OAOG;IACH,OAAO,CAAC,8BAA8B;CASvC;AACD,eAAe,kBAAkB,CAAC"} +\ No newline at end of file ++{"version":3,"file":"ApprovalController.d.ts","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAa,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,i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,EAAE,EAAE,cAAc;IAmB9B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,yBAAyB;IAcjE;;;;;;;;OAQG;IACG,OAAO,CAAC,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;IAQhE;;;;;;;;OAQG;IACG,KAAK,CAAC,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;CAoO3D;AAED,eAAe,kBAAkB,CAAC"} +\ No newline at end of file +diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.js b/node_modules/@metamask/approval-controller/dist/ApprovalController.js +index 8a0acb5..e31f7dd 100644 +--- a/node_modules/@metamask/approval-controller/dist/ApprovalController.js ++++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.js +@@ -1,10 +1,36 @@ + "use strict"; ++var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { ++ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } ++ return new (P || (P = Promise))(function (resolve, reject) { ++ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } ++ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } ++ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } ++ step((generator = generator.apply(thisArg, _arguments || [])).next()); ++ }); ++}; ++var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { ++ if (kind === "m") throw new TypeError("Private method is not writable"); ++ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); ++ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); ++ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; ++}; ++var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { ++ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); ++ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); ++ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); ++}; ++var _ApprovalController_instances, _ApprovalController_approvals, _ApprovalController_origins, _ApprovalController_showApprovalRequest, _ApprovalController_typesExcludedFromRateLimiting, _ApprovalController_add, _ApprovalController_validateAddParams, _ApprovalController_addPendingApprovalOrigin, _ApprovalController_addToStore, _ApprovalController_delete, _ApprovalController_deleteApprovalAndGetCallbacks, _ApprovalController_result; + Object.defineProperty(exports, "__esModule", { value: true }); +-exports.ApprovalController = void 0; ++exports.ApprovalController = exports.APPROVAL_TYPE_RESULT_SUCCESS = exports.APPROVAL_TYPE_RESULT_ERROR = exports.ORIGIN_METAMASK = void 0; + const eth_rpc_errors_1 = require("eth-rpc-errors"); + const nanoid_1 = require("nanoid"); + const base_controller_1 = require("@metamask/base-controller"); + const errors_1 = require("./errors"); ++// Constants ++// Avoiding dependency on controller-utils ++exports.ORIGIN_METAMASK = 'metamask'; ++exports.APPROVAL_TYPE_RESULT_ERROR = 'result_error'; ++exports.APPROVAL_TYPE_RESULT_SUCCESS = 'result_success'; + const controllerName = 'ApprovalController'; + const stateMetadata = { + pendingApprovals: { persist: false, anonymous: true }, +@@ -46,10 +72,15 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { + messenger, + state: Object.assign(Object.assign({}, getDefaultState()), state), + }); +- this._approvals = new Map(); +- this._origins = new Map(); +- this._showApprovalRequest = showApprovalRequest; +- this._typesExcludedFromRateLimiting = typesExcludedFromRateLimiting; ++ _ApprovalController_instances.add(this); ++ _ApprovalController_approvals.set(this, void 0); ++ _ApprovalController_origins.set(this, void 0); ++ _ApprovalController_showApprovalRequest.set(this, void 0); ++ _ApprovalController_typesExcludedFromRateLimiting.set(this, void 0); ++ __classPrivateFieldSet(this, _ApprovalController_approvals, new Map(), "f"); ++ __classPrivateFieldSet(this, _ApprovalController_origins, new Map(), "f"); ++ __classPrivateFieldSet(this, _ApprovalController_showApprovalRequest, showApprovalRequest, "f"); ++ __classPrivateFieldSet(this, _ApprovalController_typesExcludedFromRateLimiting, typesExcludedFromRateLimiting, "f"); + this.registerMessageHandlers(); + } + /** +@@ -71,14 +102,16 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { + this.messagingSystem.registerActionHandler(`${controllerName}:startFlow`, this.startFlow.bind(this)); + this.messagingSystem.registerActionHandler(`${controllerName}:endFlow`, this.endFlow.bind(this)); + this.messagingSystem.registerActionHandler(`${controllerName}:setFlowLoadingText`, this.setFlowLoadingText.bind(this)); ++ this.messagingSystem.registerActionHandler(`${controllerName}:showSuccess`, this.success.bind(this)); ++ this.messagingSystem.registerActionHandler(`${controllerName}:showError`, this.error.bind(this)); + } + addAndShowApprovalRequest(opts) { +- const promise = this._add(opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult); +- this._showApprovalRequest(); ++ const promise = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_add).call(this, opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult); ++ __classPrivateFieldGet(this, _ApprovalController_showApprovalRequest, "f").call(this); + return promise; + } + add(opts) { +- return this._add(opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult); ++ return __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_add).call(this, opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult); + } + /** + * Gets the info for the approval request with the given id. +@@ -111,10 +144,10 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { + } + const { origin, type: _type } = opts; + if (origin && _type) { +- return ((_a = this._origins.get(origin)) === null || _a === void 0 ? void 0 : _a.get(_type)) || 0; ++ return ((_a = __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin)) === null || _a === void 0 ? void 0 : _a.get(_type)) || 0; + } + if (origin) { +- return Array.from((this._origins.get(origin) || new Map()).values()).reduce((total, value) => total + value, 0); ++ return Array.from((__classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin) || new Map()).values()).reduce((total, value) => total + value, 0); + } + // Only "type" was specified + let count = 0; +@@ -155,7 +188,7 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { + if (typeof id !== 'string') { + throw new Error('May not specify non-string id.'); + } +- return this._approvals.has(id); ++ return __classPrivateFieldGet(this, _ApprovalController_approvals, "f").has(id); + } + if (_type && typeof _type !== 'string') { + throw new Error('May not specify non-string type.'); +@@ -166,9 +199,9 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { + } + // Check origin and type pair if type also specified + if (_type) { +- return Boolean((_a = this._origins.get(origin)) === null || _a === void 0 ? void 0 : _a.get(_type)); ++ return Boolean((_a = __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin)) === null || _a === void 0 ? void 0 : _a.get(_type)); + } +- return this._origins.has(origin); ++ return __classPrivateFieldGet(this, _ApprovalController_origins, "f").has(origin); + } + if (_type) { + for (const approval of Object.values(this.state.pendingApprovals)) { +@@ -194,7 +227,7 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { + accept(id, value, options) { + // Safe to cast as the delete method below will throw if the ID is not found + const approval = this.get(id); +- const requestPromise = this._deleteApprovalAndGetCallbacks(id); ++ const requestPromise = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_deleteApprovalAndGetCallbacks).call(this, id); + return new Promise((resolve, reject) => { + const resultCallbacks = { + success: (acceptValue) => resolve({ value: acceptValue }), +@@ -222,7 +255,7 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { + * @param error - The error to reject the approval promise with. + */ + reject(id, error) { +- this._deleteApprovalAndGetCallbacks(id).reject(error); ++ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_deleteApprovalAndGetCallbacks).call(this, id).reject(error); + } + /** + * Rejects and deletes all approval requests. +@@ -231,10 +264,10 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { + * requests with. + */ + clear(rejectionError) { +- for (const id of this._approvals.keys()) { ++ for (const id of __classPrivateFieldGet(this, _ApprovalController_approvals, "f").keys()) { + this.reject(id, rejectionError); + } +- this._origins.clear(); ++ __classPrivateFieldGet(this, _ApprovalController_origins, "f").clear(); + this.update((draftState) => { + draftState.pendingApprovals = {}; + draftState.pendingApprovalCount = 0; +@@ -272,7 +305,7 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { + this.update((draftState) => { + draftState.approvalFlows.push({ id, loadingText }); + }); +- this._showApprovalRequest(); ++ __classPrivateFieldGet(this, _ApprovalController_showApprovalRequest, "f").call(this); + return { id, loadingText }; + } + /** +@@ -310,152 +343,152 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { + }); + } + /** +- * Implementation of add operation. ++ * Show a success page. + * +- * @param origin - The origin of the approval request. +- * @param type - The type associated with the approval request. +- * @param id - The id of the approval request. +- * @param requestData - The request data associated with the approval request. +- * @param requestState - The request state associated with the approval request. +- * @param expectsResult - Whether the approval request expects a result object to be returned. +- * @returns The approval promise. ++ * @param opts - Options bag. ++ * @param opts.message - The message text or components to display in the page. ++ * @param opts.header - The text or components to display in the header of the page. ++ * @param opts.flowToEnd - The ID of the approval flow to end once the success page is approved. ++ * @returns Empty object to support future additions. + */ +- _add(origin, type, id = (0, nanoid_1.nanoid)(), requestData, requestState, expectsResult) { +- this._validateAddParams(id, origin, type, requestData, requestState); +- if (!this._typesExcludedFromRateLimiting.includes(type) && +- this.has({ origin, type })) { +- throw eth_rpc_errors_1.ethErrors.rpc.resourceUnavailable(getAlreadyPendingMessage(origin, type)); +- } +- // add pending approval +- return new Promise((resolve, reject) => { +- this._approvals.set(id, { resolve, reject }); +- this._addPendingApprovalOrigin(origin, type); +- this._addToStore(id, origin, type, requestData, requestState, expectsResult); ++ success(opts = {}) { ++ return __awaiter(this, void 0, void 0, function* () { ++ yield __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, exports.APPROVAL_TYPE_RESULT_SUCCESS, opts, { ++ message: opts.message, ++ header: opts.header, ++ }); ++ return {}; + }); + } + /** +- * Validates parameters to the add method. ++ * Show an error page. + * +- * @param id - The id of the approval request. +- * @param origin - The origin of the approval request. +- * @param type - The type associated with the approval request. +- * @param requestData - The request data associated with the approval request. +- * @param requestState - The request state associated with the approval request. ++ * @param opts - Options bag. ++ * @param opts.message - The message text or components to display in the page. ++ * @param opts.header - The text or components to display in the header of the page. ++ * @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved. ++ * @returns Empty object to support future additions. + */ +- _validateAddParams(id, origin, type, requestData, requestState) { +- let errorMessage = null; +- if (!id || typeof id !== 'string') { +- errorMessage = 'Must specify non-empty string id.'; +- } +- else if (this._approvals.has(id)) { +- errorMessage = `Approval request with id '${id}' already exists.`; +- } +- else if (!origin || typeof origin !== 'string') { +- errorMessage = 'Must specify non-empty string origin.'; +- } +- else if (!type || typeof type !== 'string') { +- errorMessage = 'Must specify non-empty string type.'; +- } +- else if (requestData && +- (typeof requestData !== 'object' || Array.isArray(requestData))) { +- errorMessage = 'Request data must be a plain object if specified.'; +- } +- else if (requestState && +- (typeof requestState !== 'object' || Array.isArray(requestState))) { +- errorMessage = 'Request state must be a plain object if specified.'; +- } +- if (errorMessage) { +- throw eth_rpc_errors_1.ethErrors.rpc.internal(errorMessage); +- } ++ error(opts = {}) { ++ return __awaiter(this, void 0, void 0, function* () { ++ yield __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, exports.APPROVAL_TYPE_RESULT_ERROR, opts, { ++ error: opts.error, ++ header: opts.header, ++ }); ++ return {}; ++ }); + } +- /** +- * Adds an entry to _origins. +- * Performs no validation. +- * +- * @param origin - The origin of the approval request. +- * @param type - The type associated with the approval request. +- */ +- _addPendingApprovalOrigin(origin, type) { +- let originMap = this._origins.get(origin); +- if (!originMap) { +- originMap = new Map(); +- this._origins.set(origin, originMap); +- } +- const currentValue = originMap.get(type) || 0; +- originMap.set(type, currentValue + 1); ++} ++exports.ApprovalController = ApprovalController; ++_ApprovalController_approvals = new WeakMap(), _ApprovalController_origins = new WeakMap(), _ApprovalController_showApprovalRequest = new WeakMap(), _ApprovalController_typesExcludedFromRateLimiting = new WeakMap(), _ApprovalController_instances = new WeakSet(), _ApprovalController_add = function _ApprovalController_add(origin, type, id = (0, nanoid_1.nanoid)(), requestData, requestState, expectsResult) { ++ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_validateAddParams).call(this, id, origin, type, requestData, requestState); ++ if (!__classPrivateFieldGet(this, _ApprovalController_typesExcludedFromRateLimiting, "f").includes(type) && ++ this.has({ origin, type })) { ++ throw eth_rpc_errors_1.ethErrors.rpc.resourceUnavailable(getAlreadyPendingMessage(origin, type)); + } +- /** +- * Adds an entry to the store. +- * Performs no validation. +- * +- * @param id - The id of the approval request. +- * @param origin - The origin of the approval request. +- * @param type - The type associated with the approval request. +- * @param requestData - The request data associated with the approval request. +- * @param requestState - The request state associated with the approval request. +- * @param expectsResult - Whether the request expects a result object to be returned. +- */ +- _addToStore(id, origin, type, requestData, requestState, expectsResult) { +- const approval = { +- id, +- origin, +- type, +- time: Date.now(), +- requestData: requestData || null, +- requestState: requestState || null, +- expectsResult: expectsResult || false, +- }; +- this.update((draftState) => { +- // Typecast: ts(2589) +- draftState.pendingApprovals[id] = approval; +- draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length; +- }); ++ // add pending approval ++ return new Promise((resolve, reject) => { ++ __classPrivateFieldGet(this, _ApprovalController_approvals, "f").set(id, { resolve, reject }); ++ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_addPendingApprovalOrigin).call(this, origin, type); ++ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_addToStore).call(this, id, origin, type, requestData, requestState, expectsResult); ++ }); ++}, _ApprovalController_validateAddParams = function _ApprovalController_validateAddParams(id, origin, type, requestData, requestState) { ++ let errorMessage = null; ++ if (!id || typeof id !== 'string') { ++ errorMessage = 'Must specify non-empty string id.'; + } +- /** +- * Deletes the approval with the given id. The approval promise must be +- * resolved or reject before this method is called. +- * Deletion is an internal operation because approval state is solely +- * managed by this controller. +- * +- * @param id - The id of the approval request to be deleted. +- */ +- _delete(id) { +- this._approvals.delete(id); +- // This method is only called after verifying that the approval with the +- // specified id exists. +- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion +- const { origin, type } = this.state.pendingApprovals[id]; +- const originMap = this._origins.get(origin); +- const originTotalCount = this.getApprovalCount({ origin }); +- const originTypeCount = originMap.get(type); +- if (originTotalCount === 1) { +- this._origins.delete(origin); ++ else if (__classPrivateFieldGet(this, _ApprovalController_approvals, "f").has(id)) { ++ errorMessage = `Approval request with id '${id}' already exists.`; ++ } ++ else if (!origin || typeof origin !== 'string') { ++ errorMessage = 'Must specify non-empty string origin.'; ++ } ++ else if (!type || typeof type !== 'string') { ++ errorMessage = 'Must specify non-empty string type.'; ++ } ++ else if (requestData && ++ (typeof requestData !== 'object' || Array.isArray(requestData))) { ++ errorMessage = 'Request data must be a plain object if specified.'; ++ } ++ else if (requestState && ++ (typeof requestState !== 'object' || Array.isArray(requestState))) { ++ errorMessage = 'Request state must be a plain object if specified.'; ++ } ++ if (errorMessage) { ++ throw eth_rpc_errors_1.ethErrors.rpc.internal(errorMessage); ++ } ++}, _ApprovalController_addPendingApprovalOrigin = function _ApprovalController_addPendingApprovalOrigin(origin, type) { ++ let originMap = __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin); ++ if (!originMap) { ++ originMap = new Map(); ++ __classPrivateFieldGet(this, _ApprovalController_origins, "f").set(origin, originMap); ++ } ++ const currentValue = originMap.get(type) || 0; ++ originMap.set(type, currentValue + 1); ++}, _ApprovalController_addToStore = function _ApprovalController_addToStore(id, origin, type, requestData, requestState, expectsResult) { ++ const approval = { ++ id, ++ origin, ++ type, ++ time: Date.now(), ++ requestData: requestData || null, ++ requestState: requestState || null, ++ expectsResult: expectsResult || false, ++ }; ++ this.update((draftState) => { ++ // Typecast: ts(2589) ++ draftState.pendingApprovals[id] = approval; ++ draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length; ++ }); ++}, _ApprovalController_delete = function _ApprovalController_delete(id) { ++ __classPrivateFieldGet(this, _ApprovalController_approvals, "f").delete(id); ++ // This method is only called after verifying that the approval with the ++ // specified id exists. ++ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion ++ const { origin, type } = this.state.pendingApprovals[id]; ++ const originMap = __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin); ++ const originTotalCount = this.getApprovalCount({ origin }); ++ const originTypeCount = originMap.get(type); ++ if (originTotalCount === 1) { ++ __classPrivateFieldGet(this, _ApprovalController_origins, "f").delete(origin); ++ } ++ else { ++ originMap.set(type, originTypeCount - 1); ++ } ++ this.update((draftState) => { ++ delete draftState.pendingApprovals[id]; ++ draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length; ++ }); ++}, _ApprovalController_deleteApprovalAndGetCallbacks = function _ApprovalController_deleteApprovalAndGetCallbacks(id) { ++ const callbacks = __classPrivateFieldGet(this, _ApprovalController_approvals, "f").get(id); ++ if (!callbacks) { ++ throw new errors_1.ApprovalRequestNotFoundError(id); ++ } ++ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id); ++ return callbacks; ++}, _ApprovalController_result = function _ApprovalController_result(type, opts, requestData) { ++ return __awaiter(this, void 0, void 0, function* () { ++ try { ++ yield this.addAndShowApprovalRequest({ ++ origin: exports.ORIGIN_METAMASK, ++ type, ++ requestData, ++ }); + } +- else { +- originMap.set(type, originTypeCount - 1); ++ catch (error) { ++ console.info('Failed to display result page', error); + } +- this.update((draftState) => { +- delete draftState.pendingApprovals[id]; +- draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length; +- }); +- } +- /** +- * Gets the approval callbacks for the given id, deletes the entry, and then +- * returns the callbacks for promise resolution. +- * Throws an error if no approval is found for the given id. +- * +- * @param id - The id of the approval request. +- * @returns The promise callbacks associated with the approval request. +- */ +- _deleteApprovalAndGetCallbacks(id) { +- const callbacks = this._approvals.get(id); +- if (!callbacks) { +- throw new errors_1.ApprovalRequestNotFoundError(id); ++ finally { ++ if (opts.flowToEnd) { ++ try { ++ this.endFlow({ id: opts.flowToEnd }); ++ } ++ catch (error) { ++ console.info('Failed to end flow', { id: opts.flowToEnd, error }); ++ } ++ } + } +- this._delete(id); +- return callbacks; +- } +-} +-exports.ApprovalController = ApprovalController; ++ }); ++}; + exports.default = ApprovalController; + //# sourceMappingURL=ApprovalController.js.map +\ No newline at end of file +diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.js.map b/node_modules/@metamask/approval-controller/dist/ApprovalController.js.map +index 8252be3..c1982a6 100644 +--- a/node_modules/@metamask/approval-controller/dist/ApprovalController.js.map ++++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.js.map +@@ -1 +1 @@ +-{"version":3,"file":"ApprovalController.js","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":";;;AACA,mDAA6D;AAC7D,mCAAgC;AAChC,+DAGmC;AAEnC,qCAMkB;AAElB,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAoE5C,MAAM,aAAa,GAAG;IACpB,gBAAgB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE;IACrD,oBAAoB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;IAC1D,aAAa,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;CACpD,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAAC,MAAc,EAAE,IAAY,EAAE,EAAE,CAChE,oBAAoB,IAAI,gCAAgC,MAAM,gBAAgB,CAAC;AAEjF,MAAM,eAAe,GAAG,GAA4B,EAAE;IACpD,OAAO;QACL,gBAAgB,EAAE,EAAE;QACpB,oBAAoB,EAAE,CAAC;QACvB,aAAa,EAAE,EAAE;KAClB,CAAC;AACJ,CAAC,CAAC;AA+JF;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ACd,MAAM,IAAI,qCAA4B,CAAC,EAAE,CAAC,CAAC;SAC5C;QAED,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACjB,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA9pBD,gDA8pBC;AACD,kBAAe,kBAAkB,CAAC","sourcesContent":["import type { Patch } from 'immer';\nimport { EthereumRpcError, ethErrors } from 'eth-rpc-errors';\nimport { nanoid } from 'nanoid';\nimport {\n BaseControllerV2,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { Json, OptionalField } from '@metamask/utils';\nimport {\n ApprovalRequestNotFoundError,\n ApprovalRequestNoResultSupportError,\n EndInvalidFlowError,\n NoApprovalFlowsError,\n MissingApprovalFlowError,\n} from './errors';\n\nconst controllerName = 'ApprovalController';\n\ntype ApprovalPromiseResolve = (value?: unknown | AddResult) => void;\n\ntype ApprovalPromiseReject = (error?: unknown) => void;\n\ntype ApprovalRequestData = Record | null;\n\ntype ApprovalRequestState = Record | null;\n\ntype ApprovalCallbacks = {\n resolve: ApprovalPromiseResolve;\n reject: ApprovalPromiseReject;\n};\n\nexport type ApprovalRequest = {\n /**\n * The ID of the approval request.\n */\n id: string;\n\n /**\n * The origin of the approval request.\n */\n origin: string;\n\n /**\n * The time that the request was received, per Date.now().\n */\n time: number;\n\n /**\n * The type of the approval request.\n */\n type: string;\n\n /**\n * Additional data associated with the request.\n * TODO:TS4.4 make optional\n */\n requestData: RequestData;\n\n /**\n * Additional mutable state associated with the request\n */\n requestState: ApprovalRequestState;\n\n /**\n * Whether the request expects a result object to be returned instead of just the approval value.\n */\n expectsResult: boolean;\n};\n\ntype ShowApprovalRequest = () => void | Promise;\n\ntype ApprovalFlow = {\n id: string;\n loadingText: string | null;\n};\n\nexport type ApprovalFlowState = ApprovalFlow;\n\nexport type ApprovalControllerState = {\n pendingApprovals: Record>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nconst stateMetadata = {\n pendingApprovals: { persist: false, anonymous: true },\n pendingApprovalCount: { persist: false, anonymous: false },\n approvalFlows: { persist: false, anonymous: false },\n};\n\nconst getAlreadyPendingMessage = (origin: string, type: string) =>\n `Request of type '${type}' already pending for origin ${origin}. Please wait.`;\n\nconst getDefaultState = (): ApprovalControllerState => {\n return {\n pendingApprovals: {},\n pendingApprovalCount: 0,\n approvalFlows: [],\n };\n};\n\nexport type GetApprovalsState = {\n type: `${typeof controllerName}:getState`;\n handler: () => ApprovalControllerState;\n};\n\nexport type ClearApprovalRequests = {\n type: `${typeof controllerName}:clearRequests`;\n handler: (error: EthereumRpcError) => void;\n};\n\ntype AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record;\n requestState?: Record;\n expectsResult?: boolean;\n};\n\nexport type AddApprovalRequest = {\n type: `${typeof controllerName}:addRequest`;\n handler: (\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ) => ReturnType;\n};\n\nexport type HasApprovalRequest = {\n type: `${typeof controllerName}:hasRequest`;\n handler: ApprovalController['has'];\n};\n\nexport type AcceptRequest = {\n type: `${typeof controllerName}:acceptRequest`;\n handler: ApprovalController['accept'];\n};\n\nexport type RejectRequest = {\n type: `${typeof controllerName}:rejectRequest`;\n handler: ApprovalController['reject'];\n};\n\ntype UpdateRequestStateOptions = {\n id: string;\n requestState: Record;\n};\n\nexport type UpdateRequestState = {\n type: `${typeof controllerName}:updateRequestState`;\n handler: ApprovalController['updateRequestState'];\n};\n\nexport type AcceptOptions = {\n /**\n * Whether to resolve the returned promise only when the request creator indicates the success of the\n * post-approval logic using the result callbacks.\n * If false or unspecified, the promise will resolve immediately.\n */\n waitForResult?: boolean;\n};\n\nexport type AcceptResult = {\n /**\n * An optional value provided by the request creator when indicating a successful result.\n */\n value?: unknown;\n};\n\nexport type AcceptResultCallbacks = {\n /**\n * Inform the request acceptor that the post-approval logic was successful.\n *\n * @param value - An optional value generated by the post-approval logic.\n */\n success: (value?: unknown) => void;\n\n /**\n * Inform the request acceptor that the post-approval logic failed.\n *\n * @param error - The reason for the failure.\n */\n error: (error: Error) => void;\n};\n\nexport type AddResult = {\n /**\n * An optional value provided by the request acceptor.\n */\n value?: unknown;\n\n /**\n * Callback functions that must be used to indicate to the request acceptor whether the post-approval logic was successful or not.\n * Will be undefined if the request acceptor did not specify that they want to wait for a result.\n */\n resultCallbacks?: AcceptResultCallbacks;\n};\n\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n>;\n\nexport type ApprovalFlowStartResult = ApprovalFlow;\n\nexport type EndFlowOptions = Pick;\n\nexport type SetFlowLoadingTextOptions = ApprovalFlow;\n\nexport type StartFlow = {\n type: `${typeof controllerName}:startFlow`;\n handler: ApprovalController['startFlow'];\n};\n\nexport type EndFlow = {\n type: `${typeof controllerName}:endFlow`;\n handler: ApprovalController['endFlow'];\n};\n\nexport type SetFlowLoadingText = {\n type: `${typeof controllerName}:setFlowLoadingText`;\n handler: ApprovalController['setFlowLoadingText'];\n};\n\nexport type ApprovalControllerActions =\n | GetApprovalsState\n | ClearApprovalRequests\n | AddApprovalRequest\n | HasApprovalRequest\n | AcceptRequest\n | RejectRequest\n | UpdateRequestState\n | StartFlow\n | EndFlow\n | SetFlowLoadingText;\n\nexport type ApprovalStateChange = {\n type: `${typeof controllerName}:stateChange`;\n payload: [ApprovalControllerState, Patch[]];\n};\n\nexport type ApprovalControllerEvents = ApprovalStateChange;\n\nexport type ApprovalControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents,\n string,\n string\n>;\n\ntype ApprovalControllerOptions = {\n messenger: ApprovalControllerMessenger;\n showApprovalRequest: ShowApprovalRequest;\n state?: Partial;\n typesExcludedFromRateLimiting?: string[];\n};\n\n/**\n * Controller for managing requests that require user approval.\n *\n * Enables limiting the number of pending requests by origin and type, counting\n * pending requests, and more.\n *\n * Adding a request returns a promise that resolves or rejects when the request\n * is approved or denied, respectively.\n */\nexport class ApprovalController extends BaseControllerV2<\n typeof controllerName,\n ApprovalControllerState,\n ApprovalControllerMessenger\n> {\n private _approvals: Map;\n\n private _origins: Map>;\n\n private _showApprovalRequest: () => void;\n\n private _typesExcludedFromRateLimiting: string[];\n\n /**\n * Construct an Approval controller.\n *\n * @param options - The controller options.\n * @param options.showApprovalRequest - Function for opening the UI such that\n * the request can be displayed to the user.\n * @param options.messenger - The restricted controller messenger for the Approval controller.\n * @param options.state - The initial controller state.\n * @param options.typesExcludedFromRateLimiting - Array of aproval types which allow multiple pending approval requests from the same origin.\n */\n constructor({\n messenger,\n showApprovalRequest,\n state = {},\n typesExcludedFromRateLimiting = [],\n }: ApprovalControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this._approvals = new Map();\n this._origins = new Map();\n this._showApprovalRequest = showApprovalRequest;\n this._typesExcludedFromRateLimiting = typesExcludedFromRateLimiting;\n this.registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n private registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:clearRequests` as const,\n this.clear.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:addRequest` as const,\n (opts: AddApprovalOptions, shouldShowRequest: boolean) => {\n if (shouldShowRequest) {\n return this.addAndShowApprovalRequest(opts);\n }\n return this.add(opts);\n },\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:hasRequest` as const,\n this.has.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:acceptRequest` as const,\n this.accept.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:rejectRequest` as const,\n this.reject.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateRequestState` as const,\n this.updateRequestState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:startFlow` as const,\n this.startFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:endFlow` as const,\n this.endFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setFlowLoadingText` as const,\n this.setFlowLoadingText.bind(this),\n );\n }\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving to\n * an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n addAndShowApprovalRequest(\n opts: AddApprovalOptions & { expectsResult: true },\n ): Promise;\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving\n * to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise {\n const promise = this._add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n this._showApprovalRequest();\n return promise;\n }\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n add(opts: AddApprovalOptions & { expectsResult: true }): Promise;\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n add(opts: AddApprovalOptions): Promise;\n\n add(opts: AddApprovalOptions): Promise {\n return this._add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n }\n\n /**\n * Gets the info for the approval request with the given id.\n *\n * @param id - The id of the approval request.\n * @returns The approval request data associated with the id.\n */\n get(id: string): ApprovalRequest | undefined {\n return this.state.pendingApprovals[id];\n }\n\n /**\n * Gets the number of pending approvals, by origin and/or type.\n *\n * If only `origin` is specified, all approvals for that origin will be\n * counted, regardless of type.\n * If only `type` is specified, all approvals for that type will be counted,\n * regardless of origin.\n * If both `origin` and `type` are specified, 0 or 1 will be returned.\n *\n * @param opts - The approval count options.\n * @param opts.origin - An approval origin.\n * @param opts.type - The type of the approval request.\n * @returns The current approval request count for the given origin and/or\n * type.\n */\n getApprovalCount(opts: { origin?: string; type?: string } = {}): number {\n if (!opts.origin && !opts.type) {\n throw new Error('Must specify origin, type, or both.');\n }\n const { origin, type: _type } = opts;\n\n if (origin && _type) {\n return this._origins.get(origin)?.get(_type) || 0;\n }\n\n if (origin) {\n return Array.from(\n (this._origins.get(origin) || new Map()).values(),\n ).reduce((total, value) => total + value, 0);\n }\n\n // Only \"type\" was specified\n let count = 0;\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n count += 1;\n }\n }\n return count;\n }\n\n /**\n * Get the total count of all pending approval requests for all origins.\n *\n * @returns The total pending approval request count.\n */\n getTotalApprovalCount(): number {\n return this.state.pendingApprovalCount;\n }\n\n /**\n * Checks if there's a pending approval request per the given parameters.\n * At least one parameter must be specified. An error will be thrown if the\n * parameters are invalid.\n *\n * If `id` is specified, all other parameters will be ignored.\n * If `id` is not specified, the method will check for requests that match\n * all of the specified parameters.\n *\n * @param opts - Options bag.\n * @param opts.id - The ID to check for.\n * @param opts.origin - The origin to check for.\n * @param opts.type - The type to check for.\n * @returns `true` if a matching approval is found, and `false` otherwise.\n */\n has(opts: { id?: string; origin?: string; type?: string } = {}): boolean {\n const { id, origin, type: _type } = opts;\n\n if (id) {\n if (typeof id !== 'string') {\n throw new Error('May not specify non-string id.');\n }\n return this._approvals.has(id);\n }\n\n if (_type && typeof _type !== 'string') {\n throw new Error('May not specify non-string type.');\n }\n\n if (origin) {\n if (typeof origin !== 'string') {\n throw new Error('May not specify non-string origin.');\n }\n\n // Check origin and type pair if type also specified\n if (_type) {\n return Boolean(this._origins.get(origin)?.get(_type));\n }\n return this._origins.has(origin);\n }\n\n if (_type) {\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n return true;\n }\n }\n return false;\n }\n throw new Error(\n 'Must specify a valid combination of id, origin, and type.',\n );\n }\n\n /**\n * Resolves the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param value - The value to resolve the approval promise with.\n * @param options - Options bag.\n * @returns A promise that either resolves once a result is provided by\n * the creator of the approval request, or immediately if `options.waitForResult`\n * is `false` or `undefined`.\n */\n accept(\n id: string,\n value?: unknown,\n options?: AcceptOptions,\n ): Promise {\n // Safe to cast as the delete method below will throw if the ID is not found\n const approval = this.get(id) as ApprovalRequest;\n const requestPromise = this._deleteApprovalAndGetCallbacks(id);\n\n return new Promise((resolve, reject) => {\n const resultCallbacks: AcceptResultCallbacks = {\n success: (acceptValue?: unknown) => resolve({ value: acceptValue }),\n error: reject,\n };\n\n if (options?.waitForResult && !approval.expectsResult) {\n reject(new ApprovalRequestNoResultSupportError(id));\n return;\n }\n\n const resultValue = options?.waitForResult ? resultCallbacks : undefined;\n\n const resolveValue = approval.expectsResult\n ? { value, resultCallbacks: resultValue }\n : value;\n\n requestPromise.resolve(resolveValue);\n\n if (!options?.waitForResult) {\n resolve({ value: undefined });\n }\n });\n }\n\n /**\n * Rejects the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param error - The error to reject the approval promise with.\n */\n reject(id: string, error: unknown): void {\n this._deleteApprovalAndGetCallbacks(id).reject(error);\n }\n\n /**\n * Rejects and deletes all approval requests.\n *\n * @param rejectionError - The EthereumRpcError to reject the approval\n * requests with.\n */\n clear(rejectionError: EthereumRpcError): void {\n for (const id of this._approvals.keys()) {\n this.reject(id, rejectionError);\n }\n this._origins.clear();\n this.update((draftState) => {\n draftState.pendingApprovals = {};\n draftState.pendingApprovalCount = 0;\n });\n }\n\n /**\n * Updates the request state of the approval with the given id.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request.\n * @param opts.requestState - Additional data associated with the request\n */\n updateRequestState(opts: UpdateRequestStateOptions): void {\n if (!this.state.pendingApprovals[opts.id]) {\n throw new ApprovalRequestNotFoundError(opts.id);\n }\n\n this.update((draftState) => {\n // Typecast: ts(2589)\n draftState.pendingApprovals[opts.id].requestState =\n opts.requestState as any;\n });\n }\n\n /**\n * Starts a new approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n * @returns The object containing the approval flow id.\n */\n startFlow(opts: StartFlowOptions = {}): ApprovalFlowStartResult {\n const id = opts.id ?? nanoid();\n const loadingText = opts.loadingText ?? null;\n\n this.update((draftState) => {\n draftState.approvalFlows.push({ id, loadingText });\n });\n\n this._showApprovalRequest();\n\n return { id, loadingText };\n }\n\n /**\n * Ends the current approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow that will be finished.\n */\n endFlow({ id }: EndFlowOptions) {\n if (!this.state.approvalFlows.length) {\n throw new NoApprovalFlowsError();\n }\n\n const currentFlow = this.state.approvalFlows.slice(-1)[0];\n\n if (id !== currentFlow.id) {\n throw new EndInvalidFlowError(\n id,\n this.state.approvalFlows.map((flow) => flow.id),\n );\n }\n\n this.update((draftState) => {\n draftState.approvalFlows.pop();\n });\n }\n\n /**\n * Sets the loading text for the approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The approval flow loading text that will be displayed.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n */\n setFlowLoadingText({ id, loadingText }: SetFlowLoadingTextOptions) {\n const flowIndex = this.state.approvalFlows.findIndex(\n (flow) => flow.id === id,\n );\n\n if (flowIndex === -1) {\n throw new MissingApprovalFlowError(id);\n }\n\n this.update((draftState) => {\n draftState.approvalFlows[flowIndex].loadingText = loadingText;\n });\n }\n\n /**\n * Implementation of add operation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param id - The id of the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the approval request expects a result object to be returned.\n * @returns The approval promise.\n */\n private _add(\n origin: string,\n type: string,\n id: string = nanoid(),\n requestData?: Record,\n requestState?: Record,\n expectsResult?: boolean,\n ): Promise {\n this._validateAddParams(id, origin, type, requestData, requestState);\n\n if (\n !this._typesExcludedFromRateLimiting.includes(type) &&\n this.has({ origin, type })\n ) {\n throw ethErrors.rpc.resourceUnavailable(\n getAlreadyPendingMessage(origin, type),\n );\n }\n\n // add pending approval\n return new Promise((resolve, reject) => {\n this._approvals.set(id, { resolve, reject });\n this._addPendingApprovalOrigin(origin, type);\n\n this._addToStore(\n id,\n origin,\n type,\n requestData,\n requestState,\n expectsResult,\n );\n });\n }\n\n /**\n * Validates parameters to the add method.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n */\n private _validateAddParams(\n id: string,\n origin: string,\n type: string,\n requestData?: Record,\n requestState?: Record,\n ): void {\n let errorMessage = null;\n if (!id || typeof id !== 'string') {\n errorMessage = 'Must specify non-empty string id.';\n } else if (this._approvals.has(id)) {\n errorMessage = `Approval request with id '${id}' already exists.`;\n } else if (!origin || typeof origin !== 'string') {\n errorMessage = 'Must specify non-empty string origin.';\n } else if (!type || typeof type !== 'string') {\n errorMessage = 'Must specify non-empty string type.';\n } else if (\n requestData &&\n (typeof requestData !== 'object' || Array.isArray(requestData))\n ) {\n errorMessage = 'Request data must be a plain object if specified.';\n } else if (\n requestState &&\n (typeof requestState !== 'object' || Array.isArray(requestState))\n ) {\n errorMessage = 'Request state must be a plain object if specified.';\n }\n\n if (errorMessage) {\n throw ethErrors.rpc.internal(errorMessage);\n }\n }\n\n /**\n * Adds an entry to _origins.\n * Performs no validation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n */\n private _addPendingApprovalOrigin(origin: string, type: string): void {\n let originMap = this._origins.get(origin);\n\n if (!originMap) {\n originMap = new Map();\n this._origins.set(origin, originMap);\n }\n\n const currentValue = originMap.get(type) || 0;\n originMap.set(type, currentValue + 1);\n }\n\n /**\n * Adds an entry to the store.\n * Performs no validation.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the request expects a result object to be returned.\n */\n private _addToStore(\n id: string,\n origin: string,\n type: string,\n requestData?: Record,\n requestState?: Record,\n expectsResult?: boolean,\n ): void {\n const approval: ApprovalRequest | null> = {\n id,\n origin,\n type,\n time: Date.now(),\n requestData: requestData || null,\n requestState: requestState || null,\n expectsResult: expectsResult || false,\n };\n\n this.update((draftState) => {\n // Typecast: ts(2589)\n draftState.pendingApprovals[id] = approval as any;\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Deletes the approval with the given id. The approval promise must be\n * resolved or reject before this method is called.\n * Deletion is an internal operation because approval state is solely\n * managed by this controller.\n *\n * @param id - The id of the approval request to be deleted.\n */\n private _delete(id: string): void {\n this._approvals.delete(id);\n\n // This method is only called after verifying that the approval with the\n // specified id exists.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { origin, type } = this.state.pendingApprovals[id]!;\n\n const originMap = this._origins.get(origin) as Map;\n const originTotalCount = this.getApprovalCount({ origin });\n const originTypeCount = originMap.get(type) as number;\n\n if (originTotalCount === 1) {\n this._origins.delete(origin);\n } else {\n originMap.set(type, originTypeCount - 1);\n }\n\n this.update((draftState) => {\n delete draftState.pendingApprovals[id];\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Gets the approval callbacks for the given id, deletes the entry, and then\n * returns the callbacks for promise resolution.\n * Throws an error if no approval is found for the given id.\n *\n * @param id - The id of the approval request.\n * @returns The promise callbacks associated with the approval request.\n */\n private _deleteApprovalAndGetCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this._approvals.get(id);\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this._delete(id);\n return callbacks;\n }\n}\nexport default ApprovalController;\n"]} +\ No newline at end of file ++{"version":3,"file":"ApprovalController.js","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,mDAA6D;AAC7D,mCAAgC;AAChC,+DAGmC;AAEnC,qCAMkB;AAElB,YAAY;AAEZ,0CAA0C;AAC7B,QAAA,eAAe,GAAG,UAAU,CAAC;AAC7B,QAAA,0BAA0B,GAAG,cAAc,CAAC;AAC5C,QAAA,4BAA4B,GAAG,gBAAgB,CAAC;AAE7D,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAE5C,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;IACX,CAAC,CAAC,CAAC;AACL,CAAC,iHAU8B,EAAU;IACvC,MAAM,SAAS,GAAG,uBAAA,IAAI,qCAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC1C,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,qCAA4B,CAAC,EAAE,CAAC,CAAC;KAC5C;IAED,uBAAA,IAAI,iEAAQ,MAAZ,IAAI,EAAS,EAAE,CAAC,CAAC;IACjB,OAAO,SAAS,CAAC;AACnB,CAAC,mEAGC,IAAY,EACZ,IAAmB,EACnB,WAAiC;;QAEjC,IAAI;YACF,MAAM,IAAI,CAAC,yBAAyB,CAAC;gBACnC,MAAM,EAAE,uBAAe;gBACvB,IAAI;gBACJ,WAAW;aACZ,CAAC,CAAC;SACJ;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;SACtD;gBAAS;YACR,IAAI,IAAI,CAAC,SAAS,EAAE;gBAClB,IAAI;oBACF,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;iBACtC;gBAAC,OAAO,KAAK,EAAE;oBACd,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;iBACnE;aACF;SACF;IACH,CAAC;;AAGH,kBAAe,kBAAkB,CAAC","sourcesContent":["import type { Patch } from 'immer';\nimport { EthereumRpcError, ethErrors } from 'eth-rpc-errors';\nimport { nanoid } from 'nanoid';\nimport {\n BaseControllerV2,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { Json, OptionalField } from '@metamask/utils';\nimport {\n ApprovalRequestNotFoundError,\n ApprovalRequestNoResultSupportError,\n EndInvalidFlowError,\n NoApprovalFlowsError,\n MissingApprovalFlowError,\n} from './errors';\n\n// Constants\n\n// Avoiding dependency on controller-utils\nexport const ORIGIN_METAMASK = 'metamask';\nexport const APPROVAL_TYPE_RESULT_ERROR = 'result_error';\nexport const APPROVAL_TYPE_RESULT_SUCCESS = 'result_success';\n\nconst controllerName = 'ApprovalController';\n\nconst stateMetadata = {\n pendingApprovals: { persist: false, anonymous: true },\n pendingApprovalCount: { persist: false, anonymous: false },\n approvalFlows: { persist: false, anonymous: false },\n};\n\nconst getAlreadyPendingMessage = (origin: string, type: string) =>\n `Request of type '${type}' already pending for origin ${origin}. Please wait.`;\n\nconst getDefaultState = (): ApprovalControllerState => {\n return {\n pendingApprovals: {},\n pendingApprovalCount: 0,\n approvalFlows: [],\n };\n};\n\n// Internal Types\n\ntype ApprovalPromiseResolve = (value?: unknown | AddResult) => void;\n\ntype ApprovalPromiseReject = (error?: unknown) => void;\n\ntype ApprovalRequestData = Record | null;\n\ntype ApprovalRequestState = Record | null;\n\ntype ApprovalCallbacks = {\n resolve: ApprovalPromiseResolve;\n reject: ApprovalPromiseReject;\n};\n\ntype ApprovalFlow = {\n id: string;\n loadingText: string | null;\n};\n\ntype ResultOptions = {\n flowToEnd?: string;\n header?: (string | ResultComponent)[];\n};\n\n// Miscellaneous Types\n\nexport type ApprovalRequest = {\n /**\n * The ID of the approval request.\n */\n id: string;\n\n /**\n * The origin of the approval request.\n */\n origin: string;\n\n /**\n * The time that the request was received, per Date.now().\n */\n time: number;\n\n /**\n * The type of the approval request.\n */\n type: string;\n\n /**\n * Additional data associated with the request.\n * TODO:TS4.4 make optional\n */\n requestData: RequestData;\n\n /**\n * Additional mutable state associated with the request\n */\n requestState: ApprovalRequestState;\n\n /**\n * Whether the request expects a result object to be returned instead of just the approval value.\n */\n expectsResult: boolean;\n};\n\nexport type ApprovalFlowState = ApprovalFlow;\n\nexport type ApprovalControllerState = {\n pendingApprovals: Record>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nexport type ApprovalControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents,\n string,\n string\n>;\n\n// Option Types\n\nexport type ShowApprovalRequest = () => void | Promise;\n\nexport type ResultComponent = {\n /**\n * A unique identifier for this instance of the component.\n */\n key: string;\n\n /**\n * The name of the component to render.\n */\n name: string;\n\n /**\n * Any properties required by the component.\n */\n properties?: Record;\n\n /**\n * Any child components to render inside the component.\n */\n children?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ApprovalControllerOptions = {\n messenger: ApprovalControllerMessenger;\n showApprovalRequest: ShowApprovalRequest;\n state?: Partial;\n typesExcludedFromRateLimiting?: string[];\n};\n\nexport type AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record;\n requestState?: Record;\n expectsResult?: boolean;\n};\n\nexport type UpdateRequestStateOptions = {\n id: string;\n requestState: Record;\n};\n\nexport type AcceptOptions = {\n /**\n * Whether to resolve the returned promise only when the request creator indicates the success of the\n * post-approval logic using the result callbacks.\n * If false or unspecified, the promise will resolve immediately.\n */\n waitForResult?: boolean;\n};\n\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n>;\n\nexport type EndFlowOptions = Pick;\n\nexport type SetFlowLoadingTextOptions = ApprovalFlow;\n\nexport type SuccessOptions = ResultOptions & {\n message?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ErrorOptions = ResultOptions & {\n error?: string | ResultComponent | (string | ResultComponent)[];\n};\n\n// Result Types\n\nexport type AcceptResultCallbacks = {\n /**\n * Inform the request acceptor that the post-approval logic was successful.\n *\n * @param value - An optional value generated by the post-approval logic.\n */\n success: (value?: unknown) => void;\n\n /**\n * Inform the request acceptor that the post-approval logic failed.\n *\n * @param error - The reason for the failure.\n */\n error: (error: Error) => void;\n};\n\nexport type AddResult = {\n /**\n * An optional value provided by the request acceptor.\n */\n value?: unknown;\n\n /**\n * Callback functions that must be used to indicate to the request acceptor whether the post-approval logic was successful or not.\n * Will be undefined if the request acceptor did not specify that they want to wait for a result.\n */\n resultCallbacks?: AcceptResultCallbacks;\n};\n\nexport type AcceptResult = {\n /**\n * An optional value provided by the request creator when indicating a successful result.\n */\n value?: unknown;\n};\n\nexport type ApprovalFlowStartResult = ApprovalFlow;\n\nexport type SuccessResult = Record;\n\nexport type ErrorResult = Record;\n\n// Event Types\n\nexport type ApprovalStateChange = {\n type: `${typeof controllerName}:stateChange`;\n payload: [ApprovalControllerState, Patch[]];\n};\n\nexport type ApprovalControllerEvents = ApprovalStateChange;\n\n// Action Types\n\nexport type GetApprovalsState = {\n type: `${typeof controllerName}:getState`;\n handler: () => ApprovalControllerState;\n};\n\nexport type ClearApprovalRequests = {\n type: `${typeof controllerName}:clearRequests`;\n handler: (error: EthereumRpcError) => void;\n};\n\nexport type AddApprovalRequest = {\n type: `${typeof controllerName}:addRequest`;\n handler: (\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ) => ReturnType;\n};\n\nexport type HasApprovalRequest = {\n type: `${typeof controllerName}:hasRequest`;\n handler: ApprovalController['has'];\n};\n\nexport type AcceptRequest = {\n type: `${typeof controllerName}:acceptRequest`;\n handler: ApprovalController['accept'];\n};\n\nexport type RejectRequest = {\n type: `${typeof controllerName}:rejectRequest`;\n handler: ApprovalController['reject'];\n};\n\nexport type UpdateRequestState = {\n type: `${typeof controllerName}:updateRequestState`;\n handler: ApprovalController['updateRequestState'];\n};\n\nexport type StartFlow = {\n type: `${typeof controllerName}:startFlow`;\n handler: ApprovalController['startFlow'];\n};\n\nexport type EndFlow = {\n type: `${typeof controllerName}:endFlow`;\n handler: ApprovalController['endFlow'];\n};\n\nexport type SetFlowLoadingText = {\n type: `${typeof controllerName}:setFlowLoadingText`;\n handler: ApprovalController['setFlowLoadingText'];\n};\n\nexport type ShowSuccess = {\n type: `${typeof controllerName}:showSuccess`;\n handler: ApprovalController['success'];\n};\n\nexport type ShowError = {\n type: `${typeof controllerName}:showError`;\n handler: ApprovalController['error'];\n};\n\nexport type ApprovalControllerActions =\n | GetApprovalsState\n | ClearApprovalRequests\n | AddApprovalRequest\n | HasApprovalRequest\n | AcceptRequest\n | RejectRequest\n | UpdateRequestState\n | StartFlow\n | EndFlow\n | SetFlowLoadingText\n | ShowSuccess\n | ShowError;\n\n/**\n * Controller for managing requests that require user approval.\n *\n * Enables limiting the number of pending requests by origin and type, counting\n * pending requests, and more.\n *\n * Adding a request returns a promise that resolves or rejects when the request\n * is approved or denied, respectively.\n */\nexport class ApprovalController extends BaseControllerV2<\n typeof controllerName,\n ApprovalControllerState,\n ApprovalControllerMessenger\n> {\n #approvals: Map;\n\n #origins: Map>;\n\n #showApprovalRequest: () => void;\n\n #typesExcludedFromRateLimiting: string[];\n\n /**\n * Construct an Approval controller.\n *\n * @param options - The controller options.\n * @param options.showApprovalRequest - Function for opening the UI such that\n * the request can be displayed to the user.\n * @param options.messenger - The restricted controller messenger for the Approval controller.\n * @param options.state - The initial controller state.\n * @param options.typesExcludedFromRateLimiting - Array of aproval types which allow multiple pending approval requests from the same origin.\n */\n constructor({\n messenger,\n showApprovalRequest,\n state = {},\n typesExcludedFromRateLimiting = [],\n }: ApprovalControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#approvals = new Map();\n this.#origins = new Map();\n this.#showApprovalRequest = showApprovalRequest;\n this.#typesExcludedFromRateLimiting = typesExcludedFromRateLimiting;\n this.registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n private registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:clearRequests` as const,\n this.clear.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:addRequest` as const,\n (opts: AddApprovalOptions, shouldShowRequest: boolean) => {\n if (shouldShowRequest) {\n return this.addAndShowApprovalRequest(opts);\n }\n return this.add(opts);\n },\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:hasRequest` as const,\n this.has.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:acceptRequest` as const,\n this.accept.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:rejectRequest` as const,\n this.reject.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateRequestState` as const,\n this.updateRequestState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:startFlow` as const,\n this.startFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:endFlow` as const,\n this.endFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setFlowLoadingText` as const,\n this.setFlowLoadingText.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:showSuccess` as const,\n this.success.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:showError` as const,\n this.error.bind(this),\n );\n }\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving to\n * an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n addAndShowApprovalRequest(\n opts: AddApprovalOptions & { expectsResult: true },\n ): Promise;\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving\n * to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise {\n const promise = this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n this.#showApprovalRequest();\n return promise;\n }\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n add(opts: AddApprovalOptions & { expectsResult: true }): Promise;\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n add(opts: AddApprovalOptions): Promise;\n\n add(opts: AddApprovalOptions): Promise {\n return this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n }\n\n /**\n * Gets the info for the approval request with the given id.\n *\n * @param id - The id of the approval request.\n * @returns The approval request data associated with the id.\n */\n get(id: string): ApprovalRequest | undefined {\n return this.state.pendingApprovals[id];\n }\n\n /**\n * Gets the number of pending approvals, by origin and/or type.\n *\n * If only `origin` is specified, all approvals for that origin will be\n * counted, regardless of type.\n * If only `type` is specified, all approvals for that type will be counted,\n * regardless of origin.\n * If both `origin` and `type` are specified, 0 or 1 will be returned.\n *\n * @param opts - The approval count options.\n * @param opts.origin - An approval origin.\n * @param opts.type - The type of the approval request.\n * @returns The current approval request count for the given origin and/or\n * type.\n */\n getApprovalCount(opts: { origin?: string; type?: string } = {}): number {\n if (!opts.origin && !opts.type) {\n throw new Error('Must specify origin, type, or both.');\n }\n const { origin, type: _type } = opts;\n\n if (origin && _type) {\n return this.#origins.get(origin)?.get(_type) || 0;\n }\n\n if (origin) {\n return Array.from(\n (this.#origins.get(origin) || new Map()).values(),\n ).reduce((total, value) => total + value, 0);\n }\n\n // Only \"type\" was specified\n let count = 0;\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n count += 1;\n }\n }\n return count;\n }\n\n /**\n * Get the total count of all pending approval requests for all origins.\n *\n * @returns The total pending approval request count.\n */\n getTotalApprovalCount(): number {\n return this.state.pendingApprovalCount;\n }\n\n /**\n * Checks if there's a pending approval request per the given parameters.\n * At least one parameter must be specified. An error will be thrown if the\n * parameters are invalid.\n *\n * If `id` is specified, all other parameters will be ignored.\n * If `id` is not specified, the method will check for requests that match\n * all of the specified parameters.\n *\n * @param opts - Options bag.\n * @param opts.id - The ID to check for.\n * @param opts.origin - The origin to check for.\n * @param opts.type - The type to check for.\n * @returns `true` if a matching approval is found, and `false` otherwise.\n */\n has(opts: { id?: string; origin?: string; type?: string } = {}): boolean {\n const { id, origin, type: _type } = opts;\n\n if (id) {\n if (typeof id !== 'string') {\n throw new Error('May not specify non-string id.');\n }\n return this.#approvals.has(id);\n }\n\n if (_type && typeof _type !== 'string') {\n throw new Error('May not specify non-string type.');\n }\n\n if (origin) {\n if (typeof origin !== 'string') {\n throw new Error('May not specify non-string origin.');\n }\n\n // Check origin and type pair if type also specified\n if (_type) {\n return Boolean(this.#origins.get(origin)?.get(_type));\n }\n return this.#origins.has(origin);\n }\n\n if (_type) {\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n return true;\n }\n }\n return false;\n }\n throw new Error(\n 'Must specify a valid combination of id, origin, and type.',\n );\n }\n\n /**\n * Resolves the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param value - The value to resolve the approval promise with.\n * @param options - Options bag.\n * @returns A promise that either resolves once a result is provided by\n * the creator of the approval request, or immediately if `options.waitForResult`\n * is `false` or `undefined`.\n */\n accept(\n id: string,\n value?: unknown,\n options?: AcceptOptions,\n ): Promise {\n // Safe to cast as the delete method below will throw if the ID is not found\n const approval = this.get(id) as ApprovalRequest;\n const requestPromise = this.#deleteApprovalAndGetCallbacks(id);\n\n return new Promise((resolve, reject) => {\n const resultCallbacks: AcceptResultCallbacks = {\n success: (acceptValue?: unknown) => resolve({ value: acceptValue }),\n error: reject,\n };\n\n if (options?.waitForResult && !approval.expectsResult) {\n reject(new ApprovalRequestNoResultSupportError(id));\n return;\n }\n\n const resultValue = options?.waitForResult ? resultCallbacks : undefined;\n\n const resolveValue = approval.expectsResult\n ? { value, resultCallbacks: resultValue }\n : value;\n\n requestPromise.resolve(resolveValue);\n\n if (!options?.waitForResult) {\n resolve({ value: undefined });\n }\n });\n }\n\n /**\n * Rejects the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param error - The error to reject the approval promise with.\n */\n reject(id: string, error: unknown): void {\n this.#deleteApprovalAndGetCallbacks(id).reject(error);\n }\n\n /**\n * Rejects and deletes all approval requests.\n *\n * @param rejectionError - The EthereumRpcError to reject the approval\n * requests with.\n */\n clear(rejectionError: EthereumRpcError): void {\n for (const id of this.#approvals.keys()) {\n this.reject(id, rejectionError);\n }\n this.#origins.clear();\n this.update((draftState) => {\n draftState.pendingApprovals = {};\n draftState.pendingApprovalCount = 0;\n });\n }\n\n /**\n * Updates the request state of the approval with the given id.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request.\n * @param opts.requestState - Additional data associated with the request\n */\n updateRequestState(opts: UpdateRequestStateOptions): void {\n if (!this.state.pendingApprovals[opts.id]) {\n throw new ApprovalRequestNotFoundError(opts.id);\n }\n\n this.update((draftState) => {\n // Typecast: ts(2589)\n draftState.pendingApprovals[opts.id].requestState =\n opts.requestState as any;\n });\n }\n\n /**\n * Starts a new approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n * @returns The object containing the approval flow id.\n */\n startFlow(opts: StartFlowOptions = {}): ApprovalFlowStartResult {\n const id = opts.id ?? nanoid();\n const loadingText = opts.loadingText ?? null;\n\n this.update((draftState) => {\n draftState.approvalFlows.push({ id, loadingText });\n });\n\n this.#showApprovalRequest();\n\n return { id, loadingText };\n }\n\n /**\n * Ends the current approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow that will be finished.\n */\n endFlow({ id }: EndFlowOptions) {\n if (!this.state.approvalFlows.length) {\n throw new NoApprovalFlowsError();\n }\n\n const currentFlow = this.state.approvalFlows.slice(-1)[0];\n\n if (id !== currentFlow.id) {\n throw new EndInvalidFlowError(\n id,\n this.state.approvalFlows.map((flow) => flow.id),\n );\n }\n\n this.update((draftState) => {\n draftState.approvalFlows.pop();\n });\n }\n\n /**\n * Sets the loading text for the approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The approval flow loading text that will be displayed.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n */\n setFlowLoadingText({ id, loadingText }: SetFlowLoadingTextOptions) {\n const flowIndex = this.state.approvalFlows.findIndex(\n (flow) => flow.id === id,\n );\n\n if (flowIndex === -1) {\n throw new MissingApprovalFlowError(id);\n }\n\n this.update((draftState) => {\n draftState.approvalFlows[flowIndex].loadingText = loadingText;\n });\n }\n\n /**\n * Show a success page.\n *\n * @param opts - Options bag.\n * @param opts.message - The message text or components to display in the page.\n * @param opts.header - The text or components to display in the header of the page.\n * @param opts.flowToEnd - The ID of the approval flow to end once the success page is approved.\n * @returns Empty object to support future additions.\n */\n async success(opts: SuccessOptions = {}): Promise {\n await this.#result(APPROVAL_TYPE_RESULT_SUCCESS, opts, {\n message: opts.message,\n header: opts.header,\n } as any);\n return {};\n }\n\n /**\n * Show an error page.\n *\n * @param opts - Options bag.\n * @param opts.message - The message text or components to display in the page.\n * @param opts.header - The text or components to display in the header of the page.\n * @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved.\n * @returns Empty object to support future additions.\n */\n async error(opts: ErrorOptions = {}): Promise {\n await this.#result(APPROVAL_TYPE_RESULT_ERROR, opts, {\n error: opts.error,\n header: opts.header,\n } as any);\n return {};\n }\n\n /**\n * Implementation of add operation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param id - The id of the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the approval request expects a result object to be returned.\n * @returns The approval promise.\n */\n #add(\n origin: string,\n type: string,\n id: string = nanoid(),\n requestData?: Record,\n requestState?: Record,\n expectsResult?: boolean,\n ): Promise {\n this.#validateAddParams(id, origin, type, requestData, requestState);\n\n if (\n !this.#typesExcludedFromRateLimiting.includes(type) &&\n this.has({ origin, type })\n ) {\n throw ethErrors.rpc.resourceUnavailable(\n getAlreadyPendingMessage(origin, type),\n );\n }\n\n // add pending approval\n return new Promise((resolve, reject) => {\n this.#approvals.set(id, { resolve, reject });\n this.#addPendingApprovalOrigin(origin, type);\n\n this.#addToStore(\n id,\n origin,\n type,\n requestData,\n requestState,\n expectsResult,\n );\n });\n }\n\n /**\n * Validates parameters to the add method.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n */\n #validateAddParams(\n id: string,\n origin: string,\n type: string,\n requestData?: Record,\n requestState?: Record,\n ): void {\n let errorMessage = null;\n if (!id || typeof id !== 'string') {\n errorMessage = 'Must specify non-empty string id.';\n } else if (this.#approvals.has(id)) {\n errorMessage = `Approval request with id '${id}' already exists.`;\n } else if (!origin || typeof origin !== 'string') {\n errorMessage = 'Must specify non-empty string origin.';\n } else if (!type || typeof type !== 'string') {\n errorMessage = 'Must specify non-empty string type.';\n } else if (\n requestData &&\n (typeof requestData !== 'object' || Array.isArray(requestData))\n ) {\n errorMessage = 'Request data must be a plain object if specified.';\n } else if (\n requestState &&\n (typeof requestState !== 'object' || Array.isArray(requestState))\n ) {\n errorMessage = 'Request state must be a plain object if specified.';\n }\n\n if (errorMessage) {\n throw ethErrors.rpc.internal(errorMessage);\n }\n }\n\n /**\n * Adds an entry to _origins.\n * Performs no validation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n */\n #addPendingApprovalOrigin(origin: string, type: string): void {\n let originMap = this.#origins.get(origin);\n\n if (!originMap) {\n originMap = new Map();\n this.#origins.set(origin, originMap);\n }\n\n const currentValue = originMap.get(type) || 0;\n originMap.set(type, currentValue + 1);\n }\n\n /**\n * Adds an entry to the store.\n * Performs no validation.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the request expects a result object to be returned.\n */\n #addToStore(\n id: string,\n origin: string,\n type: string,\n requestData?: Record,\n requestState?: Record,\n expectsResult?: boolean,\n ): void {\n const approval: ApprovalRequest | null> = {\n id,\n origin,\n type,\n time: Date.now(),\n requestData: requestData || null,\n requestState: requestState || null,\n expectsResult: expectsResult || false,\n };\n\n this.update((draftState) => {\n // Typecast: ts(2589)\n draftState.pendingApprovals[id] = approval as any;\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Deletes the approval with the given id. The approval promise must be\n * resolved or reject before this method is called.\n * Deletion is an internal operation because approval state is solely\n * managed by this controller.\n *\n * @param id - The id of the approval request to be deleted.\n */\n #delete(id: string): void {\n this.#approvals.delete(id);\n\n // This method is only called after verifying that the approval with the\n // specified id exists.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { origin, type } = this.state.pendingApprovals[id]!;\n\n const originMap = this.#origins.get(origin) as Map;\n const originTotalCount = this.getApprovalCount({ origin });\n const originTypeCount = originMap.get(type) as number;\n\n if (originTotalCount === 1) {\n this.#origins.delete(origin);\n } else {\n originMap.set(type, originTypeCount - 1);\n }\n\n this.update((draftState) => {\n delete draftState.pendingApprovals[id];\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Gets the approval callbacks for the given id, deletes the entry, and then\n * returns the callbacks for promise resolution.\n * Throws an error if no approval is found for the given id.\n *\n * @param id - The id of the approval request.\n * @returns The promise callbacks associated with the approval request.\n */\n #deleteApprovalAndGetCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this.#approvals.get(id);\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this.#delete(id);\n return callbacks;\n }\n\n async #result(\n type: string,\n opts: ResultOptions,\n requestData: Record,\n ) {\n try {\n await this.addAndShowApprovalRequest({\n origin: ORIGIN_METAMASK,\n type,\n requestData,\n });\n } catch (error) {\n console.info('Failed to display result page', error);\n } finally {\n if (opts.flowToEnd) {\n try {\n this.endFlow({ id: opts.flowToEnd });\n } catch (error) {\n console.info('Failed to end flow', { id: opts.flowToEnd, error });\n }\n }\n }\n }\n}\n\nexport default ApprovalController;\n"]} +\ No newline at end of file From 1abef86ef7242d7ebda57bae6d1f33a3e8a3801f Mon Sep 17 00:00:00 2001 From: Vinicius Stevam Date: Fri, 7 Jul 2023 15:34:51 +0100 Subject: [PATCH 2/5] removing patch and applied suggestions from review --- app/components/Nav/Main/RootRPCMethodsUI.js | 46 +- .../__snapshots__/index.test.tsx.snap | 0 .../ApprovalFlowLoader/index.js | 0 .../ApprovalFlowLoader/index.test.tsx | 0 .../ApprovalResult/ApprovalResult.styles.ts} | 0 .../ApprovalResult/ApprovalResult.test.tsx | 33 + .../ApprovalResult/ApprovalResult.tsx} | 41 +- .../UI/Approval/ApprovalResult/index.ts | 4 + .../ApprovalFlowResult.test.tsx | 51 -- .../ApprovalFlow/ApprovalFlowResult/index.ts | 4 - app/constants/test-ids.js | 3 - app/core/RPCMethods/RPCMethodMiddleware.ts | 2 + locales/languages/en.json | 2 +- package.json | 4 +- .../@metamask+approval-controller+3.3.0.patch | 763 ------------------ yarn.lock | 8 +- 16 files changed, 96 insertions(+), 865 deletions(-) rename app/components/UI/{ApprovalFlow => Approval}/ApprovalFlowLoader/__snapshots__/index.test.tsx.snap (100%) rename app/components/UI/{ApprovalFlow => Approval}/ApprovalFlowLoader/index.js (100%) rename app/components/UI/{ApprovalFlow => Approval}/ApprovalFlowLoader/index.test.tsx (100%) rename app/components/UI/{ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.styles.ts => Approval/ApprovalResult/ApprovalResult.styles.ts} (100%) create mode 100644 app/components/UI/Approval/ApprovalResult/ApprovalResult.test.tsx rename app/components/UI/{ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.tsx => Approval/ApprovalResult/ApprovalResult.tsx} (75%) create mode 100644 app/components/UI/Approval/ApprovalResult/index.ts delete mode 100644 app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.test.tsx delete mode 100644 app/components/UI/ApprovalFlow/ApprovalFlowResult/index.ts delete mode 100644 patches/@metamask+approval-controller+3.3.0.patch diff --git a/app/components/Nav/Main/RootRPCMethodsUI.js b/app/components/Nav/Main/RootRPCMethodsUI.js index ee06b3e664b..267dbca2723 100644 --- a/app/components/Nav/Main/RootRPCMethodsUI.js +++ b/app/components/Nav/Main/RootRPCMethodsUI.js @@ -31,7 +31,7 @@ import { import { BN } from 'ethereumjs-util'; import Logger from '../../../util/Logger'; import Approve from '../../Views/ApproveView/Approve'; -import ApprovalFlowLoader from '../../UI/ApprovalFlow/ApprovalFlowLoader'; +import ApprovalFlowLoader from '../../UI/Approval/ApprovalFlowLoader'; import WatchAssetRequest from '../../UI/WatchAssetRequest'; import AccountApproval from '../../UI/AccountApproval'; import TransactionTypes from '../../../core/TransactionTypes'; @@ -58,11 +58,8 @@ import { selectProviderType, } from '../../../selectors/networkController'; import { createAccountConnectNavDetails } from '../../Views/AccountConnect'; -import { ApprovalFlowResult } from '../../UI/ApprovalFlow/ApprovalFlowResult'; -import { - APPROVAL_TYPE_RESULT_ERROR, - APPROVAL_TYPE_RESULT_SUCCESS, -} from '@metamask/approval-controller'; +import { ApprovalResult } from '../../UI/Approval/ApprovalResult'; +import { ApprovalResultType } from '../../UI/Approval/ApprovalResult/ApprovalResult'; const APPROVAL_TYPES_WITH_DISABLED_CLOSE_ON_APPROVE = [ ApprovalTypes.TRANSACTION, @@ -96,7 +93,7 @@ const RootRPCMethodsUI = (props) => { const [watchAsset, setWatchAsset] = useState(undefined); - const [approvalFlowResult, setApprovalFlowResult] = useState(undefined); + const [approvalResult, setApprovalResult] = useState(undefined); const [signMessageParams, setSignMessageParams] = useState(undefined); @@ -410,16 +407,18 @@ const RootRPCMethodsUI = (props) => { ); - const onApprovalFlowResultConfirm = () => { + const onApprovalResultConfirm = () => { setShowPendingApproval(false); - acceptPendingApproval(approvalFlowResult.id, approvalFlowResult.data); - setApprovalFlowResult(undefined); + acceptPendingApproval(approvalResult.id, approvalResult.data); + setApprovalResult(undefined); }; - const renderApprovalFlowResultModal = () => { + const renderApprovalResultModal = () => { if ( - showPendingApproval?.type !== APPROVAL_TYPE_RESULT_SUCCESS && - showPendingApproval?.type !== APPROVAL_TYPE_RESULT_ERROR + ![ + ApprovalTypes.APPROVAL_TYPE_RESULT_SUCCESS, + ApprovalTypes.APPROVAL_TYPE_RESULT_ERROR, + ].includes(showPendingApproval?.type) ) { return null; } @@ -436,10 +435,15 @@ const RootRPCMethodsUI = (props) => { swipeDirection={'down'} propagateSwipe > - ); @@ -831,9 +835,9 @@ const RootRPCMethodsUI = (props) => { origin: request.origin, }); break; - case APPROVAL_TYPE_RESULT_SUCCESS: - case APPROVAL_TYPE_RESULT_ERROR: - setApprovalFlowResult({ data: requestData, id: request.id }); + case ApprovalTypes.APPROVAL_TYPE_RESULT_SUCCESS: + case ApprovalTypes.APPROVAL_TYPE_RESULT_ERROR: + setApprovalResult({ data: requestData, id: request.id }); showPendingApprovalModal({ type: request.type, origin: request.origin, @@ -900,7 +904,7 @@ const RootRPCMethodsUI = (props) => { {renderQRSigningModal()} {renderAccountsApprovalModal()} {renderApprovalFlowModal()} - {renderApprovalFlowResultModal()} + {renderApprovalResultModal()} ); }; diff --git a/app/components/UI/ApprovalFlow/ApprovalFlowLoader/__snapshots__/index.test.tsx.snap b/app/components/UI/Approval/ApprovalFlowLoader/__snapshots__/index.test.tsx.snap similarity index 100% rename from app/components/UI/ApprovalFlow/ApprovalFlowLoader/__snapshots__/index.test.tsx.snap rename to app/components/UI/Approval/ApprovalFlowLoader/__snapshots__/index.test.tsx.snap diff --git a/app/components/UI/ApprovalFlow/ApprovalFlowLoader/index.js b/app/components/UI/Approval/ApprovalFlowLoader/index.js similarity index 100% rename from app/components/UI/ApprovalFlow/ApprovalFlowLoader/index.js rename to app/components/UI/Approval/ApprovalFlowLoader/index.js diff --git a/app/components/UI/ApprovalFlow/ApprovalFlowLoader/index.test.tsx b/app/components/UI/Approval/ApprovalFlowLoader/index.test.tsx similarity index 100% rename from app/components/UI/ApprovalFlow/ApprovalFlowLoader/index.test.tsx rename to app/components/UI/Approval/ApprovalFlowLoader/index.test.tsx diff --git a/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.styles.ts b/app/components/UI/Approval/ApprovalResult/ApprovalResult.styles.ts similarity index 100% rename from app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.styles.ts rename to app/components/UI/Approval/ApprovalResult/ApprovalResult.styles.ts diff --git a/app/components/UI/Approval/ApprovalResult/ApprovalResult.test.tsx b/app/components/UI/Approval/ApprovalResult/ApprovalResult.test.tsx new file mode 100644 index 00000000000..77b43028b46 --- /dev/null +++ b/app/components/UI/Approval/ApprovalResult/ApprovalResult.test.tsx @@ -0,0 +1,33 @@ +import React from 'react'; +import { render } from '@testing-library/react-native'; +import ApprovalResult, { ApprovalResultType } from './ApprovalResult'; + +describe('ApprovalResult', () => { + const mockProps = { + requestData: { + message: 'Success message', + }, + onConfirm: jest.fn(), + requestType: ApprovalResultType.Success, + }; + + it('renders approval result with success type', () => { + const wrapper = render(); + + expect(wrapper).toMatchSnapshot(); + }); + + it('renders approval result with error type', () => { + const errorMockProps = { + ...mockProps, + requestData: { + error: 'Error message', + }, + requestType: ApprovalResultType.Failure, + }; + + const wrapper = render(); + + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.tsx b/app/components/UI/Approval/ApprovalResult/ApprovalResult.tsx similarity index 75% rename from app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.tsx rename to app/components/UI/Approval/ApprovalResult/ApprovalResult.tsx index cafa8bf03c6..25f3bb0ad11 100644 --- a/app/components/UI/ApprovalFlow/ApprovalFlowResult/ApprovalFlowResult.tsx +++ b/app/components/UI/Approval/ApprovalResult/ApprovalResult.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { View } from 'react-native'; -import stylesheet from './ApprovalFlowResult.styles'; +import stylesheet from './ApprovalResult.styles'; import { strings } from '../../../../../locales/i18n'; import SheetHeader from '../../../../component-library/components/Sheet/SheetHeader'; import Text, { @@ -20,34 +20,43 @@ import BottomSheetFooter, { } from '../../../../component-library/components/BottomSheets/BottomSheetFooter'; import { ButtonProps } from '../../../../component-library/components/Buttons/Button/Button.types'; import { useStyles } from '../../../hooks/useStyles'; -import { APPROVAL_TYPE_RESULT_SUCCESS } from '@metamask/approval-controller'; -import { APPROVAL_FLOW_RESULT_ID } from '../../../../constants/test-ids'; -interface ApprovalFlowResultProps { - requestData: any; +export enum ApprovalResultType { + Success = 'success', + Failure = 'failure', +} + +export interface ApprovalResultData { + message?: string; + error?: string; + header?: unknown; +} + +export interface ApprovalResultProps { + requestData: ApprovalResultData; onConfirm: () => void; - requestType: string; + requestType: ApprovalResultType; } -const ApprovalFlowResult = ({ +const ApprovalResult = ({ requestData, onConfirm, requestType, -}: ApprovalFlowResultProps) => { +}: ApprovalResultProps) => { const { styles } = useStyles(stylesheet, {}); const isApprovalTypeResultSuccess = (type: string) => - APPROVAL_TYPE_RESULT_SUCCESS === type; + ApprovalResultType.Success === type; const okButtonProps: ButtonProps = { variant: ButtonVariants.Primary, - label: strings('approval_flow.ok'), + label: strings('approval_result.ok'), size: ButtonSize.Lg, onPress: onConfirm, }; return ( - + @@ -69,14 +78,14 @@ const ApprovalFlowResult = ({ {isApprovalTypeResultSuccess(requestType) - ? requestData?.data?.message - : requestData?.data?.error} + ? requestData?.message + : requestData?.error} { - const mockProps = { - requestData: { - data: { - message: 'Success message', - }, - }, - onConfirm: jest.fn(), - requestType: 'result_success', - }; - - it('renders approval flow result with success type and confirms', () => { - const { getByTestId, getByText } = render( - , - ); - - expect(getByTestId('approval-flow-result')).toBeTruthy(); - expect(getByText('Success')).toBeTruthy(); - expect(getByText(mockProps.requestData.data.message)).toBeTruthy(); - fireEvent.press(getByText('OK')); - - expect(mockProps.onConfirm).toHaveBeenCalled(); - }); - - it('renders approval flow result with error type and confirms', () => { - const errorMockProps = { - ...mockProps, - requestData: { - data: { - error: 'Error message', - }, - }, - requestType: 'result_error', - }; - - const { getByTestId, getByText } = render( - , - ); - - expect(getByTestId('approval-flow-result')).toBeTruthy(); - expect(getByText('Error')).toBeTruthy(); - expect(getByText(errorMockProps.requestData.data.error)).toBeTruthy(); - fireEvent.press(getByText('OK')); - - expect(mockProps.onConfirm).toHaveBeenCalled(); - }); -}); diff --git a/app/components/UI/ApprovalFlow/ApprovalFlowResult/index.ts b/app/components/UI/ApprovalFlow/ApprovalFlowResult/index.ts deleted file mode 100644 index be94133855a..00000000000 --- a/app/components/UI/ApprovalFlow/ApprovalFlowResult/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -/* eslint-disable import/prefer-default-export */ -import ApprovalFlowResult from './ApprovalFlowResult'; - -export { ApprovalFlowResult }; diff --git a/app/constants/test-ids.js b/app/constants/test-ids.js index 8c7f1d9234a..89167a62d4d 100644 --- a/app/constants/test-ids.js +++ b/app/constants/test-ids.js @@ -101,6 +101,3 @@ export const SIGNATURE_MODAL_CANCEL_BUTTON_ID = // Advanced Settings export const ADVANCED_SETTINGS_CONTAINER_ID = 'advanced-settings'; export const ETH_SIGN_SWITCH_ID = 'eth-sign-switch'; - -// Approval Flow -export const APPROVAL_FLOW_RESULT_ID = 'approval-flow-result'; diff --git a/app/core/RPCMethods/RPCMethodMiddleware.ts b/app/core/RPCMethods/RPCMethodMiddleware.ts index ee5f185c1ed..e83711c714b 100644 --- a/app/core/RPCMethods/RPCMethodMiddleware.ts +++ b/app/core/RPCMethods/RPCMethodMiddleware.ts @@ -43,6 +43,8 @@ export enum ApprovalTypes { ETH_SIGN_TYPED_DATA = 'eth_signTypedData', WATCH_ASSET = 'wallet_watchAsset', TRANSACTION = 'transaction', + APPROVAL_TYPE_RESULT_ERROR = 'result_error', + APPROVAL_TYPE_RESULT_SUCCESS = 'result_success', } interface RPCMethodsMiddleParameters { diff --git a/locales/languages/en.json b/locales/languages/en.json index b1ca462c280..ed480a26229 100644 --- a/locales/languages/en.json +++ b/locales/languages/en.json @@ -430,7 +430,7 @@ "cta_no_thanks": "No thanks", "cta_i_agree": "I agree" }, - "approval_flow": { + "approval_result": { "ok": "OK", "success": "Success", "error": "Error" diff --git a/package.json b/package.json index 6c29e6be1c1..f778eca22a3 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,7 @@ "react-native-level-fs/**/semver": "^4.3.2", "@metamask/contract-metadata": "^2.1.0", "@metamask/controller-utils": "~3.0.0", - "@metamask/approval-controller": "3.3.0", + "@metamask/approval-controller": "3.4.0", "@exodus/react-native-payments/validator": "^13.7.0", "react-devtools-core": "4.22.1", "**/got": "^11.8.5", @@ -149,7 +149,7 @@ "@keystonehq/metamask-airgapped-keyring": "^0.3.0", "@keystonehq/ur-decoder": "^0.6.1", "@metamask/address-book-controller": "^2.0.0", - "@metamask/approval-controller": "^3.3.0", + "@metamask/approval-controller": "^3.4.0", "@metamask/assets-controllers": "5.0.0", "@metamask/base-controller": "^2.0.0", "@metamask/composable-controller": "^2.0.0", diff --git a/patches/@metamask+approval-controller+3.3.0.patch b/patches/@metamask+approval-controller+3.3.0.patch deleted file mode 100644 index 97d2002781a..00000000000 --- a/patches/@metamask+approval-controller+3.3.0.patch +++ /dev/null @@ -1,763 +0,0 @@ -diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts b/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts -index 4ffc763..29de2a5 100644 ---- a/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts -+++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts -@@ -2,9 +2,20 @@ import type { Patch } from 'immer'; - import { EthereumRpcError } from 'eth-rpc-errors'; - import { BaseControllerV2, RestrictedControllerMessenger } from '@metamask/base-controller'; - import { Json, OptionalField } from '@metamask/utils'; -+export declare const ORIGIN_METAMASK = "metamask"; -+export declare const APPROVAL_TYPE_RESULT_ERROR = "result_error"; -+export declare const APPROVAL_TYPE_RESULT_SUCCESS = "result_success"; - declare const controllerName = "ApprovalController"; - declare type ApprovalRequestData = Record | null; - declare type ApprovalRequestState = Record | null; -+declare type ApprovalFlow = { -+ id: string; -+ loadingText: string | null; -+}; -+declare type ResultOptions = { -+ flowToEnd?: string; -+ header?: (string | ResultComponent)[]; -+}; - export declare type ApprovalRequest = { - /** - * The ID of the approval request. -@@ -36,26 +47,39 @@ export declare type ApprovalRequest = { - */ - expectsResult: boolean; - }; --declare type ShowApprovalRequest = () => void | Promise; --declare type ApprovalFlow = { -- id: string; -- loadingText: string | null; --}; - export declare type ApprovalFlowState = ApprovalFlow; - export declare type ApprovalControllerState = { - pendingApprovals: Record>>; - pendingApprovalCount: number; - approvalFlows: ApprovalFlowState[]; - }; --export declare type GetApprovalsState = { -- type: `${typeof controllerName}:getState`; -- handler: () => ApprovalControllerState; -+export declare type ApprovalControllerMessenger = RestrictedControllerMessenger; -+export declare type ShowApprovalRequest = () => void | Promise; -+export declare type ResultComponent = { -+ /** -+ * A unique identifier for this instance of the component. -+ */ -+ key: string; -+ /** -+ * The name of the component to render. -+ */ -+ name: string; -+ /** -+ * Any properties required by the component. -+ */ -+ properties?: Record; -+ /** -+ * Any child components to render inside the component. -+ */ -+ children?: string | ResultComponent | (string | ResultComponent)[]; - }; --export declare type ClearApprovalRequests = { -- type: `${typeof controllerName}:clearRequests`; -- handler: (error: EthereumRpcError) => void; -+export declare type ApprovalControllerOptions = { -+ messenger: ApprovalControllerMessenger; -+ showApprovalRequest: ShowApprovalRequest; -+ state?: Partial; -+ typesExcludedFromRateLimiting?: string[]; - }; --declare type AddApprovalOptions = { -+export declare type AddApprovalOptions = { - id?: string; - origin: string; - type: string; -@@ -63,30 +87,10 @@ declare type AddApprovalOptions = { - requestState?: Record; - expectsResult?: boolean; - }; --export declare type AddApprovalRequest = { -- type: `${typeof controllerName}:addRequest`; -- handler: (opts: AddApprovalOptions, shouldShowRequest: boolean) => ReturnType; --}; --export declare type HasApprovalRequest = { -- type: `${typeof controllerName}:hasRequest`; -- handler: ApprovalController['has']; --}; --export declare type AcceptRequest = { -- type: `${typeof controllerName}:acceptRequest`; -- handler: ApprovalController['accept']; --}; --export declare type RejectRequest = { -- type: `${typeof controllerName}:rejectRequest`; -- handler: ApprovalController['reject']; --}; --declare type UpdateRequestStateOptions = { -+export declare type UpdateRequestStateOptions = { - id: string; - requestState: Record; - }; --export declare type UpdateRequestState = { -- type: `${typeof controllerName}:updateRequestState`; -- handler: ApprovalController['updateRequestState']; --}; - export declare type AcceptOptions = { - /** - * Whether to resolve the returned promise only when the request creator indicates the success of the -@@ -95,11 +99,14 @@ export declare type AcceptOptions = { - */ - waitForResult?: boolean; - }; --export declare type AcceptResult = { -- /** -- * An optional value provided by the request creator when indicating a successful result. -- */ -- value?: unknown; -+export declare type StartFlowOptions = OptionalField; -+export declare type EndFlowOptions = Pick; -+export declare type SetFlowLoadingTextOptions = ApprovalFlow; -+export declare type SuccessOptions = ResultOptions & { -+ message?: string | ResultComponent | (string | ResultComponent)[]; -+}; -+export declare type ErrorOptions = ResultOptions & { -+ error?: string | ResultComponent | (string | ResultComponent)[]; - }; - export declare type AcceptResultCallbacks = { - /** -@@ -126,10 +133,48 @@ export declare type AddResult = { - */ - resultCallbacks?: AcceptResultCallbacks; - }; --export declare type StartFlowOptions = OptionalField; -+export declare type AcceptResult = { -+ /** -+ * An optional value provided by the request creator when indicating a successful result. -+ */ -+ value?: unknown; -+}; - export declare type ApprovalFlowStartResult = ApprovalFlow; --export declare type EndFlowOptions = Pick; --export declare type SetFlowLoadingTextOptions = ApprovalFlow; -+export declare type SuccessResult = Record; -+export declare type ErrorResult = Record; -+export declare type ApprovalStateChange = { -+ type: `${typeof controllerName}:stateChange`; -+ payload: [ApprovalControllerState, Patch[]]; -+}; -+export declare type ApprovalControllerEvents = ApprovalStateChange; -+export declare type GetApprovalsState = { -+ type: `${typeof controllerName}:getState`; -+ handler: () => ApprovalControllerState; -+}; -+export declare type ClearApprovalRequests = { -+ type: `${typeof controllerName}:clearRequests`; -+ handler: (error: EthereumRpcError) => void; -+}; -+export declare type AddApprovalRequest = { -+ type: `${typeof controllerName}:addRequest`; -+ handler: (opts: AddApprovalOptions, shouldShowRequest: boolean) => ReturnType; -+}; -+export declare type HasApprovalRequest = { -+ type: `${typeof controllerName}:hasRequest`; -+ handler: ApprovalController['has']; -+}; -+export declare type AcceptRequest = { -+ type: `${typeof controllerName}:acceptRequest`; -+ handler: ApprovalController['accept']; -+}; -+export declare type RejectRequest = { -+ type: `${typeof controllerName}:rejectRequest`; -+ handler: ApprovalController['reject']; -+}; -+export declare type UpdateRequestState = { -+ type: `${typeof controllerName}:updateRequestState`; -+ handler: ApprovalController['updateRequestState']; -+}; - export declare type StartFlow = { - type: `${typeof controllerName}:startFlow`; - handler: ApprovalController['startFlow']; -@@ -142,19 +187,15 @@ export declare type SetFlowLoadingText = { - type: `${typeof controllerName}:setFlowLoadingText`; - handler: ApprovalController['setFlowLoadingText']; - }; --export declare type ApprovalControllerActions = GetApprovalsState | ClearApprovalRequests | AddApprovalRequest | HasApprovalRequest | AcceptRequest | RejectRequest | UpdateRequestState | StartFlow | EndFlow | SetFlowLoadingText; --export declare type ApprovalStateChange = { -- type: `${typeof controllerName}:stateChange`; -- payload: [ApprovalControllerState, Patch[]]; -+export declare type ShowSuccess = { -+ type: `${typeof controllerName}:showSuccess`; -+ handler: ApprovalController['success']; - }; --export declare type ApprovalControllerEvents = ApprovalStateChange; --export declare type ApprovalControllerMessenger = RestrictedControllerMessenger; --declare type ApprovalControllerOptions = { -- messenger: ApprovalControllerMessenger; -- showApprovalRequest: ShowApprovalRequest; -- state?: Partial; -- typesExcludedFromRateLimiting?: string[]; -+export declare type ShowError = { -+ type: `${typeof controllerName}:showError`; -+ handler: ApprovalController['error']; - }; -+export declare type ApprovalControllerActions = GetApprovalsState | ClearApprovalRequests | AddApprovalRequest | HasApprovalRequest | AcceptRequest | RejectRequest | UpdateRequestState | StartFlow | EndFlow | SetFlowLoadingText | ShowSuccess | ShowError; - /** - * Controller for managing requests that require user approval. - * -@@ -165,10 +206,7 @@ declare type ApprovalControllerOptions = { - * is approved or denied, respectively. - */ - export declare class ApprovalController extends BaseControllerV2 { -- private _approvals; -- private _origins; -- private _showApprovalRequest; -- private _typesExcludedFromRateLimiting; -+ #private; - /** - * Construct an Approval controller. - * -@@ -373,65 +411,25 @@ export declare class ApprovalController extends BaseControllerV2; - /** -- * Gets the approval callbacks for the given id, deletes the entry, and then -- * returns the callbacks for promise resolution. -- * Throws an error if no approval is found for the given id. -+ * Show an error page. - * -- * @param id - The id of the approval request. -- * @returns The promise callbacks associated with the approval request. -+ * @param opts - Options bag. -+ * @param opts.message - The message text or components to display in the page. -+ * @param opts.header - The text or components to display in the header of the page. -+ * @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved. -+ * @returns Empty object to support future additions. - */ -- private _deleteApprovalAndGetCallbacks; -+ error(opts?: ErrorOptions): Promise; - } - export default ApprovalController; - //# sourceMappingURL=ApprovalController.d.ts.map -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts.map b/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts.map -index cbd9ac2..ad5e004 100644 ---- a/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts.map -+++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.d.ts.map -@@ -1 +1 @@ --{"version":3,"file":"ApprovalController.d.ts","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAa,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAStD,QAAA,MAAM,cAAc,uBAAuB,CAAC;AAM5C,aAAK,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;AAEvD,aAAK,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;AAOxD,oBAAY,eAAe,CAAC,WAAW,SAAS,mBAAmB,IAAI;IACrE;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAC;IAEzB;;OAEG;IACH,YAAY,EAAE,oBAAoB,CAAC;IAEnC;;OAEG;IACH,aAAa,EAAE,OAAO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K,CAAC,cAAc,EAAE,gBAAgB,CAAC,OAAO,CAAC,GAAG,IAAI;IAWtD;;;;;;OAMG;IACH,kBAAkB,CAAC,IAAI,EAAE,yBAAyB,GAAG,IAAI;IAYzD;;;;;;;OAOG;IACH,SAAS,CAAC,IAAI,GAAE,gBAAqB,GAAG,uBAAuB;IAa/D;;;;;OAKG;IACH,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,cAAc;IAmB9B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,yBAAyB;IAcjE;;;;;;;;OAQG;IACG,OAAO,CAAC,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;IAQhE;;;;;;;;OAQG;IACG,KAAK,CAAC,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;CAoO3D;AAED,eAAe,kBAAkB,CAAC"} -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.js b/node_modules/@metamask/approval-controller/dist/ApprovalController.js -index 8a0acb5..e31f7dd 100644 ---- a/node_modules/@metamask/approval-controller/dist/ApprovalController.js -+++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.js -@@ -1,10 +1,36 @@ - "use strict"; -+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { -+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } -+ return new (P || (P = Promise))(function (resolve, reject) { -+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } -+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } -+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } -+ step((generator = generator.apply(thisArg, _arguments || [])).next()); -+ }); -+}; -+var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { -+ if (kind === "m") throw new TypeError("Private method is not writable"); -+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); -+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); -+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; -+}; -+var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { -+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); -+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); -+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); -+}; -+var _ApprovalController_instances, _ApprovalController_approvals, _ApprovalController_origins, _ApprovalController_showApprovalRequest, _ApprovalController_typesExcludedFromRateLimiting, _ApprovalController_add, _ApprovalController_validateAddParams, _ApprovalController_addPendingApprovalOrigin, _ApprovalController_addToStore, _ApprovalController_delete, _ApprovalController_deleteApprovalAndGetCallbacks, _ApprovalController_result; - Object.defineProperty(exports, "__esModule", { value: true }); --exports.ApprovalController = void 0; -+exports.ApprovalController = exports.APPROVAL_TYPE_RESULT_SUCCESS = exports.APPROVAL_TYPE_RESULT_ERROR = exports.ORIGIN_METAMASK = void 0; - const eth_rpc_errors_1 = require("eth-rpc-errors"); - const nanoid_1 = require("nanoid"); - const base_controller_1 = require("@metamask/base-controller"); - const errors_1 = require("./errors"); -+// Constants -+// Avoiding dependency on controller-utils -+exports.ORIGIN_METAMASK = 'metamask'; -+exports.APPROVAL_TYPE_RESULT_ERROR = 'result_error'; -+exports.APPROVAL_TYPE_RESULT_SUCCESS = 'result_success'; - const controllerName = 'ApprovalController'; - const stateMetadata = { - pendingApprovals: { persist: false, anonymous: true }, -@@ -46,10 +72,15 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { - messenger, - state: Object.assign(Object.assign({}, getDefaultState()), state), - }); -- this._approvals = new Map(); -- this._origins = new Map(); -- this._showApprovalRequest = showApprovalRequest; -- this._typesExcludedFromRateLimiting = typesExcludedFromRateLimiting; -+ _ApprovalController_instances.add(this); -+ _ApprovalController_approvals.set(this, void 0); -+ _ApprovalController_origins.set(this, void 0); -+ _ApprovalController_showApprovalRequest.set(this, void 0); -+ _ApprovalController_typesExcludedFromRateLimiting.set(this, void 0); -+ __classPrivateFieldSet(this, _ApprovalController_approvals, new Map(), "f"); -+ __classPrivateFieldSet(this, _ApprovalController_origins, new Map(), "f"); -+ __classPrivateFieldSet(this, _ApprovalController_showApprovalRequest, showApprovalRequest, "f"); -+ __classPrivateFieldSet(this, _ApprovalController_typesExcludedFromRateLimiting, typesExcludedFromRateLimiting, "f"); - this.registerMessageHandlers(); - } - /** -@@ -71,14 +102,16 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { - this.messagingSystem.registerActionHandler(`${controllerName}:startFlow`, this.startFlow.bind(this)); - this.messagingSystem.registerActionHandler(`${controllerName}:endFlow`, this.endFlow.bind(this)); - this.messagingSystem.registerActionHandler(`${controllerName}:setFlowLoadingText`, this.setFlowLoadingText.bind(this)); -+ this.messagingSystem.registerActionHandler(`${controllerName}:showSuccess`, this.success.bind(this)); -+ this.messagingSystem.registerActionHandler(`${controllerName}:showError`, this.error.bind(this)); - } - addAndShowApprovalRequest(opts) { -- const promise = this._add(opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult); -- this._showApprovalRequest(); -+ const promise = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_add).call(this, opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult); -+ __classPrivateFieldGet(this, _ApprovalController_showApprovalRequest, "f").call(this); - return promise; - } - add(opts) { -- return this._add(opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult); -+ return __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_add).call(this, opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult); - } - /** - * Gets the info for the approval request with the given id. -@@ -111,10 +144,10 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { - } - const { origin, type: _type } = opts; - if (origin && _type) { -- return ((_a = this._origins.get(origin)) === null || _a === void 0 ? void 0 : _a.get(_type)) || 0; -+ return ((_a = __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin)) === null || _a === void 0 ? void 0 : _a.get(_type)) || 0; - } - if (origin) { -- return Array.from((this._origins.get(origin) || new Map()).values()).reduce((total, value) => total + value, 0); -+ return Array.from((__classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin) || new Map()).values()).reduce((total, value) => total + value, 0); - } - // Only "type" was specified - let count = 0; -@@ -155,7 +188,7 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { - if (typeof id !== 'string') { - throw new Error('May not specify non-string id.'); - } -- return this._approvals.has(id); -+ return __classPrivateFieldGet(this, _ApprovalController_approvals, "f").has(id); - } - if (_type && typeof _type !== 'string') { - throw new Error('May not specify non-string type.'); -@@ -166,9 +199,9 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { - } - // Check origin and type pair if type also specified - if (_type) { -- return Boolean((_a = this._origins.get(origin)) === null || _a === void 0 ? void 0 : _a.get(_type)); -+ return Boolean((_a = __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin)) === null || _a === void 0 ? void 0 : _a.get(_type)); - } -- return this._origins.has(origin); -+ return __classPrivateFieldGet(this, _ApprovalController_origins, "f").has(origin); - } - if (_type) { - for (const approval of Object.values(this.state.pendingApprovals)) { -@@ -194,7 +227,7 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { - accept(id, value, options) { - // Safe to cast as the delete method below will throw if the ID is not found - const approval = this.get(id); -- const requestPromise = this._deleteApprovalAndGetCallbacks(id); -+ const requestPromise = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_deleteApprovalAndGetCallbacks).call(this, id); - return new Promise((resolve, reject) => { - const resultCallbacks = { - success: (acceptValue) => resolve({ value: acceptValue }), -@@ -222,7 +255,7 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { - * @param error - The error to reject the approval promise with. - */ - reject(id, error) { -- this._deleteApprovalAndGetCallbacks(id).reject(error); -+ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_deleteApprovalAndGetCallbacks).call(this, id).reject(error); - } - /** - * Rejects and deletes all approval requests. -@@ -231,10 +264,10 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { - * requests with. - */ - clear(rejectionError) { -- for (const id of this._approvals.keys()) { -+ for (const id of __classPrivateFieldGet(this, _ApprovalController_approvals, "f").keys()) { - this.reject(id, rejectionError); - } -- this._origins.clear(); -+ __classPrivateFieldGet(this, _ApprovalController_origins, "f").clear(); - this.update((draftState) => { - draftState.pendingApprovals = {}; - draftState.pendingApprovalCount = 0; -@@ -272,7 +305,7 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { - this.update((draftState) => { - draftState.approvalFlows.push({ id, loadingText }); - }); -- this._showApprovalRequest(); -+ __classPrivateFieldGet(this, _ApprovalController_showApprovalRequest, "f").call(this); - return { id, loadingText }; - } - /** -@@ -310,152 +343,152 @@ class ApprovalController extends base_controller_1.BaseControllerV2 { - }); - } - /** -- * Implementation of add operation. -+ * Show a success page. - * -- * @param origin - The origin of the approval request. -- * @param type - The type associated with the approval request. -- * @param id - The id of the approval request. -- * @param requestData - The request data associated with the approval request. -- * @param requestState - The request state associated with the approval request. -- * @param expectsResult - Whether the approval request expects a result object to be returned. -- * @returns The approval promise. -+ * @param opts - Options bag. -+ * @param opts.message - The message text or components to display in the page. -+ * @param opts.header - The text or components to display in the header of the page. -+ * @param opts.flowToEnd - The ID of the approval flow to end once the success page is approved. -+ * @returns Empty object to support future additions. - */ -- _add(origin, type, id = (0, nanoid_1.nanoid)(), requestData, requestState, expectsResult) { -- this._validateAddParams(id, origin, type, requestData, requestState); -- if (!this._typesExcludedFromRateLimiting.includes(type) && -- this.has({ origin, type })) { -- throw eth_rpc_errors_1.ethErrors.rpc.resourceUnavailable(getAlreadyPendingMessage(origin, type)); -- } -- // add pending approval -- return new Promise((resolve, reject) => { -- this._approvals.set(id, { resolve, reject }); -- this._addPendingApprovalOrigin(origin, type); -- this._addToStore(id, origin, type, requestData, requestState, expectsResult); -+ success(opts = {}) { -+ return __awaiter(this, void 0, void 0, function* () { -+ yield __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, exports.APPROVAL_TYPE_RESULT_SUCCESS, opts, { -+ message: opts.message, -+ header: opts.header, -+ }); -+ return {}; - }); - } - /** -- * Validates parameters to the add method. -+ * Show an error page. - * -- * @param id - The id of the approval request. -- * @param origin - The origin of the approval request. -- * @param type - The type associated with the approval request. -- * @param requestData - The request data associated with the approval request. -- * @param requestState - The request state associated with the approval request. -+ * @param opts - Options bag. -+ * @param opts.message - The message text or components to display in the page. -+ * @param opts.header - The text or components to display in the header of the page. -+ * @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved. -+ * @returns Empty object to support future additions. - */ -- _validateAddParams(id, origin, type, requestData, requestState) { -- let errorMessage = null; -- if (!id || typeof id !== 'string') { -- errorMessage = 'Must specify non-empty string id.'; -- } -- else if (this._approvals.has(id)) { -- errorMessage = `Approval request with id '${id}' already exists.`; -- } -- else if (!origin || typeof origin !== 'string') { -- errorMessage = 'Must specify non-empty string origin.'; -- } -- else if (!type || typeof type !== 'string') { -- errorMessage = 'Must specify non-empty string type.'; -- } -- else if (requestData && -- (typeof requestData !== 'object' || Array.isArray(requestData))) { -- errorMessage = 'Request data must be a plain object if specified.'; -- } -- else if (requestState && -- (typeof requestState !== 'object' || Array.isArray(requestState))) { -- errorMessage = 'Request state must be a plain object if specified.'; -- } -- if (errorMessage) { -- throw eth_rpc_errors_1.ethErrors.rpc.internal(errorMessage); -- } -+ error(opts = {}) { -+ return __awaiter(this, void 0, void 0, function* () { -+ yield __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, exports.APPROVAL_TYPE_RESULT_ERROR, opts, { -+ error: opts.error, -+ header: opts.header, -+ }); -+ return {}; -+ }); - } -- /** -- * Adds an entry to _origins. -- * Performs no validation. -- * -- * @param origin - The origin of the approval request. -- * @param type - The type associated with the approval request. -- */ -- _addPendingApprovalOrigin(origin, type) { -- let originMap = this._origins.get(origin); -- if (!originMap) { -- originMap = new Map(); -- this._origins.set(origin, originMap); -- } -- const currentValue = originMap.get(type) || 0; -- originMap.set(type, currentValue + 1); -+} -+exports.ApprovalController = ApprovalController; -+_ApprovalController_approvals = new WeakMap(), _ApprovalController_origins = new WeakMap(), _ApprovalController_showApprovalRequest = new WeakMap(), _ApprovalController_typesExcludedFromRateLimiting = new WeakMap(), _ApprovalController_instances = new WeakSet(), _ApprovalController_add = function _ApprovalController_add(origin, type, id = (0, nanoid_1.nanoid)(), requestData, requestState, expectsResult) { -+ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_validateAddParams).call(this, id, origin, type, requestData, requestState); -+ if (!__classPrivateFieldGet(this, _ApprovalController_typesExcludedFromRateLimiting, "f").includes(type) && -+ this.has({ origin, type })) { -+ throw eth_rpc_errors_1.ethErrors.rpc.resourceUnavailable(getAlreadyPendingMessage(origin, type)); - } -- /** -- * Adds an entry to the store. -- * Performs no validation. -- * -- * @param id - The id of the approval request. -- * @param origin - The origin of the approval request. -- * @param type - The type associated with the approval request. -- * @param requestData - The request data associated with the approval request. -- * @param requestState - The request state associated with the approval request. -- * @param expectsResult - Whether the request expects a result object to be returned. -- */ -- _addToStore(id, origin, type, requestData, requestState, expectsResult) { -- const approval = { -- id, -- origin, -- type, -- time: Date.now(), -- requestData: requestData || null, -- requestState: requestState || null, -- expectsResult: expectsResult || false, -- }; -- this.update((draftState) => { -- // Typecast: ts(2589) -- draftState.pendingApprovals[id] = approval; -- draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length; -- }); -+ // add pending approval -+ return new Promise((resolve, reject) => { -+ __classPrivateFieldGet(this, _ApprovalController_approvals, "f").set(id, { resolve, reject }); -+ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_addPendingApprovalOrigin).call(this, origin, type); -+ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_addToStore).call(this, id, origin, type, requestData, requestState, expectsResult); -+ }); -+}, _ApprovalController_validateAddParams = function _ApprovalController_validateAddParams(id, origin, type, requestData, requestState) { -+ let errorMessage = null; -+ if (!id || typeof id !== 'string') { -+ errorMessage = 'Must specify non-empty string id.'; - } -- /** -- * Deletes the approval with the given id. The approval promise must be -- * resolved or reject before this method is called. -- * Deletion is an internal operation because approval state is solely -- * managed by this controller. -- * -- * @param id - The id of the approval request to be deleted. -- */ -- _delete(id) { -- this._approvals.delete(id); -- // This method is only called after verifying that the approval with the -- // specified id exists. -- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- const { origin, type } = this.state.pendingApprovals[id]; -- const originMap = this._origins.get(origin); -- const originTotalCount = this.getApprovalCount({ origin }); -- const originTypeCount = originMap.get(type); -- if (originTotalCount === 1) { -- this._origins.delete(origin); -+ else if (__classPrivateFieldGet(this, _ApprovalController_approvals, "f").has(id)) { -+ errorMessage = `Approval request with id '${id}' already exists.`; -+ } -+ else if (!origin || typeof origin !== 'string') { -+ errorMessage = 'Must specify non-empty string origin.'; -+ } -+ else if (!type || typeof type !== 'string') { -+ errorMessage = 'Must specify non-empty string type.'; -+ } -+ else if (requestData && -+ (typeof requestData !== 'object' || Array.isArray(requestData))) { -+ errorMessage = 'Request data must be a plain object if specified.'; -+ } -+ else if (requestState && -+ (typeof requestState !== 'object' || Array.isArray(requestState))) { -+ errorMessage = 'Request state must be a plain object if specified.'; -+ } -+ if (errorMessage) { -+ throw eth_rpc_errors_1.ethErrors.rpc.internal(errorMessage); -+ } -+}, _ApprovalController_addPendingApprovalOrigin = function _ApprovalController_addPendingApprovalOrigin(origin, type) { -+ let originMap = __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin); -+ if (!originMap) { -+ originMap = new Map(); -+ __classPrivateFieldGet(this, _ApprovalController_origins, "f").set(origin, originMap); -+ } -+ const currentValue = originMap.get(type) || 0; -+ originMap.set(type, currentValue + 1); -+}, _ApprovalController_addToStore = function _ApprovalController_addToStore(id, origin, type, requestData, requestState, expectsResult) { -+ const approval = { -+ id, -+ origin, -+ type, -+ time: Date.now(), -+ requestData: requestData || null, -+ requestState: requestState || null, -+ expectsResult: expectsResult || false, -+ }; -+ this.update((draftState) => { -+ // Typecast: ts(2589) -+ draftState.pendingApprovals[id] = approval; -+ draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length; -+ }); -+}, _ApprovalController_delete = function _ApprovalController_delete(id) { -+ __classPrivateFieldGet(this, _ApprovalController_approvals, "f").delete(id); -+ // This method is only called after verifying that the approval with the -+ // specified id exists. -+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -+ const { origin, type } = this.state.pendingApprovals[id]; -+ const originMap = __classPrivateFieldGet(this, _ApprovalController_origins, "f").get(origin); -+ const originTotalCount = this.getApprovalCount({ origin }); -+ const originTypeCount = originMap.get(type); -+ if (originTotalCount === 1) { -+ __classPrivateFieldGet(this, _ApprovalController_origins, "f").delete(origin); -+ } -+ else { -+ originMap.set(type, originTypeCount - 1); -+ } -+ this.update((draftState) => { -+ delete draftState.pendingApprovals[id]; -+ draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length; -+ }); -+}, _ApprovalController_deleteApprovalAndGetCallbacks = function _ApprovalController_deleteApprovalAndGetCallbacks(id) { -+ const callbacks = __classPrivateFieldGet(this, _ApprovalController_approvals, "f").get(id); -+ if (!callbacks) { -+ throw new errors_1.ApprovalRequestNotFoundError(id); -+ } -+ __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id); -+ return callbacks; -+}, _ApprovalController_result = function _ApprovalController_result(type, opts, requestData) { -+ return __awaiter(this, void 0, void 0, function* () { -+ try { -+ yield this.addAndShowApprovalRequest({ -+ origin: exports.ORIGIN_METAMASK, -+ type, -+ requestData, -+ }); - } -- else { -- originMap.set(type, originTypeCount - 1); -+ catch (error) { -+ console.info('Failed to display result page', error); - } -- this.update((draftState) => { -- delete draftState.pendingApprovals[id]; -- draftState.pendingApprovalCount = Object.keys(draftState.pendingApprovals).length; -- }); -- } -- /** -- * Gets the approval callbacks for the given id, deletes the entry, and then -- * returns the callbacks for promise resolution. -- * Throws an error if no approval is found for the given id. -- * -- * @param id - The id of the approval request. -- * @returns The promise callbacks associated with the approval request. -- */ -- _deleteApprovalAndGetCallbacks(id) { -- const callbacks = this._approvals.get(id); -- if (!callbacks) { -- throw new errors_1.ApprovalRequestNotFoundError(id); -+ finally { -+ if (opts.flowToEnd) { -+ try { -+ this.endFlow({ id: opts.flowToEnd }); -+ } -+ catch (error) { -+ console.info('Failed to end flow', { id: opts.flowToEnd, error }); -+ } -+ } - } -- this._delete(id); -- return callbacks; -- } --} --exports.ApprovalController = ApprovalController; -+ }); -+}; - exports.default = ApprovalController; - //# sourceMappingURL=ApprovalController.js.map -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.js.map b/node_modules/@metamask/approval-controller/dist/ApprovalController.js.map -index 8252be3..c1982a6 100644 ---- a/node_modules/@metamask/approval-controller/dist/ApprovalController.js.map -+++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.js.map -@@ -1 +1 @@ --{"version":3,"file":"ApprovalController.js","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":";;;AACA,mDAA6D;AAC7D,mCAAgC;AAChC,+DAGmC;AAEnC,qCAMkB;AAElB,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAoE5C,MAAM,aAAa,GAAG;IACpB,gBAAgB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE;IACrD,oBAAoB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;IAC1D,aAAa,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;CACpD,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAAC,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,CAC3C,UAAU,CAAC,gBAAgB,CAC5B,CAAC,MAAM,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACK,8BAA8B,CAAC,EAAU;QAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,qCAA4B,CAAC,EAAE,CAAC,CAAC;SAC5C;QAED,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACjB,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA9pBD,gDA8pBC;AACD,kBAAe,kBAAkB,CAAC","sourcesContent":["import type { Patch } from 'immer';\nimport { EthereumRpcError, ethErrors } from 'eth-rpc-errors';\nimport { nanoid } from 'nanoid';\nimport {\n BaseControllerV2,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { Json, OptionalField } from '@metamask/utils';\nimport {\n ApprovalRequestNotFoundError,\n ApprovalRequestNoResultSupportError,\n EndInvalidFlowError,\n NoApprovalFlowsError,\n MissingApprovalFlowError,\n} from './errors';\n\nconst controllerName = 'ApprovalController';\n\ntype ApprovalPromiseResolve = (value?: unknown | AddResult) => void;\n\ntype ApprovalPromiseReject = (error?: unknown) => void;\n\ntype ApprovalRequestData = Record | null;\n\ntype ApprovalRequestState = Record | null;\n\ntype ApprovalCallbacks = {\n resolve: ApprovalPromiseResolve;\n reject: ApprovalPromiseReject;\n};\n\nexport type ApprovalRequest = {\n /**\n * The ID of the approval request.\n */\n id: string;\n\n /**\n * The origin of the approval request.\n */\n origin: string;\n\n /**\n * The time that the request was received, per Date.now().\n */\n time: number;\n\n /**\n * The type of the approval request.\n */\n type: string;\n\n /**\n * Additional data associated with the request.\n * TODO:TS4.4 make optional\n */\n requestData: RequestData;\n\n /**\n * Additional mutable state associated with the request\n */\n requestState: ApprovalRequestState;\n\n /**\n * Whether the request expects a result object to be returned instead of just the approval value.\n */\n expectsResult: boolean;\n};\n\ntype ShowApprovalRequest = () => void | Promise;\n\ntype ApprovalFlow = {\n id: string;\n loadingText: string | null;\n};\n\nexport type ApprovalFlowState = ApprovalFlow;\n\nexport type ApprovalControllerState = {\n pendingApprovals: Record>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nconst stateMetadata = {\n pendingApprovals: { persist: false, anonymous: true },\n pendingApprovalCount: { persist: false, anonymous: false },\n approvalFlows: { persist: false, anonymous: false },\n};\n\nconst getAlreadyPendingMessage = (origin: string, type: string) =>\n `Request of type '${type}' already pending for origin ${origin}. Please wait.`;\n\nconst getDefaultState = (): ApprovalControllerState => {\n return {\n pendingApprovals: {},\n pendingApprovalCount: 0,\n approvalFlows: [],\n };\n};\n\nexport type GetApprovalsState = {\n type: `${typeof controllerName}:getState`;\n handler: () => ApprovalControllerState;\n};\n\nexport type ClearApprovalRequests = {\n type: `${typeof controllerName}:clearRequests`;\n handler: (error: EthereumRpcError) => void;\n};\n\ntype AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record;\n requestState?: Record;\n expectsResult?: boolean;\n};\n\nexport type AddApprovalRequest = {\n type: `${typeof controllerName}:addRequest`;\n handler: (\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ) => ReturnType;\n};\n\nexport type HasApprovalRequest = {\n type: `${typeof controllerName}:hasRequest`;\n handler: ApprovalController['has'];\n};\n\nexport type AcceptRequest = {\n type: `${typeof controllerName}:acceptRequest`;\n handler: ApprovalController['accept'];\n};\n\nexport type RejectRequest = {\n type: `${typeof controllerName}:rejectRequest`;\n handler: ApprovalController['reject'];\n};\n\ntype UpdateRequestStateOptions = {\n id: string;\n requestState: Record;\n};\n\nexport type UpdateRequestState = {\n type: `${typeof controllerName}:updateRequestState`;\n handler: ApprovalController['updateRequestState'];\n};\n\nexport type AcceptOptions = {\n /**\n * Whether to resolve the returned promise only when the request creator indicates the success of the\n * post-approval logic using the result callbacks.\n * If false or unspecified, the promise will resolve immediately.\n */\n waitForResult?: boolean;\n};\n\nexport type AcceptResult = {\n /**\n * An optional value provided by the request creator when indicating a successful result.\n */\n value?: unknown;\n};\n\nexport type AcceptResultCallbacks = {\n /**\n * Inform the request acceptor that the post-approval logic was successful.\n *\n * @param value - An optional value generated by the post-approval logic.\n */\n success: (value?: unknown) => void;\n\n /**\n * Inform the request acceptor that the post-approval logic failed.\n *\n * @param error - The reason for the failure.\n */\n error: (error: Error) => void;\n};\n\nexport type AddResult = {\n /**\n * An optional value provided by the request acceptor.\n */\n value?: unknown;\n\n /**\n * Callback functions that must be used to indicate to the request acceptor whether the post-approval logic was successful or not.\n * Will be undefined if the request acceptor did not specify that they want to wait for a result.\n */\n resultCallbacks?: AcceptResultCallbacks;\n};\n\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n>;\n\nexport type ApprovalFlowStartResult = ApprovalFlow;\n\nexport type EndFlowOptions = Pick;\n\nexport type SetFlowLoadingTextOptions = ApprovalFlow;\n\nexport type StartFlow = {\n type: `${typeof controllerName}:startFlow`;\n handler: ApprovalController['startFlow'];\n};\n\nexport type EndFlow = {\n type: `${typeof controllerName}:endFlow`;\n handler: ApprovalController['endFlow'];\n};\n\nexport type SetFlowLoadingText = {\n type: `${typeof controllerName}:setFlowLoadingText`;\n handler: ApprovalController['setFlowLoadingText'];\n};\n\nexport type ApprovalControllerActions =\n | GetApprovalsState\n | ClearApprovalRequests\n | AddApprovalRequest\n | HasApprovalRequest\n | AcceptRequest\n | RejectRequest\n | UpdateRequestState\n | StartFlow\n | EndFlow\n | SetFlowLoadingText;\n\nexport type ApprovalStateChange = {\n type: `${typeof controllerName}:stateChange`;\n payload: [ApprovalControllerState, Patch[]];\n};\n\nexport type ApprovalControllerEvents = ApprovalStateChange;\n\nexport type ApprovalControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents,\n string,\n string\n>;\n\ntype ApprovalControllerOptions = {\n messenger: ApprovalControllerMessenger;\n showApprovalRequest: ShowApprovalRequest;\n state?: Partial;\n typesExcludedFromRateLimiting?: string[];\n};\n\n/**\n * Controller for managing requests that require user approval.\n *\n * Enables limiting the number of pending requests by origin and type, counting\n * pending requests, and more.\n *\n * Adding a request returns a promise that resolves or rejects when the request\n * is approved or denied, respectively.\n */\nexport class ApprovalController extends BaseControllerV2<\n typeof controllerName,\n ApprovalControllerState,\n ApprovalControllerMessenger\n> {\n private _approvals: Map;\n\n private _origins: Map>;\n\n private _showApprovalRequest: () => void;\n\n private _typesExcludedFromRateLimiting: string[];\n\n /**\n * Construct an Approval controller.\n *\n * @param options - The controller options.\n * @param options.showApprovalRequest - Function for opening the UI such that\n * the request can be displayed to the user.\n * @param options.messenger - The restricted controller messenger for the Approval controller.\n * @param options.state - The initial controller state.\n * @param options.typesExcludedFromRateLimiting - Array of aproval types which allow multiple pending approval requests from the same origin.\n */\n constructor({\n messenger,\n showApprovalRequest,\n state = {},\n typesExcludedFromRateLimiting = [],\n }: ApprovalControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this._approvals = new Map();\n this._origins = new Map();\n this._showApprovalRequest = showApprovalRequest;\n this._typesExcludedFromRateLimiting = typesExcludedFromRateLimiting;\n this.registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n private registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:clearRequests` as const,\n this.clear.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:addRequest` as const,\n (opts: AddApprovalOptions, shouldShowRequest: boolean) => {\n if (shouldShowRequest) {\n return this.addAndShowApprovalRequest(opts);\n }\n return this.add(opts);\n },\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:hasRequest` as const,\n this.has.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:acceptRequest` as const,\n this.accept.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:rejectRequest` as const,\n this.reject.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateRequestState` as const,\n this.updateRequestState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:startFlow` as const,\n this.startFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:endFlow` as const,\n this.endFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setFlowLoadingText` as const,\n this.setFlowLoadingText.bind(this),\n );\n }\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving to\n * an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n addAndShowApprovalRequest(\n opts: AddApprovalOptions & { expectsResult: true },\n ): Promise;\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving\n * to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise {\n const promise = this._add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n this._showApprovalRequest();\n return promise;\n }\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n add(opts: AddApprovalOptions & { expectsResult: true }): Promise;\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n add(opts: AddApprovalOptions): Promise;\n\n add(opts: AddApprovalOptions): Promise {\n return this._add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n }\n\n /**\n * Gets the info for the approval request with the given id.\n *\n * @param id - The id of the approval request.\n * @returns The approval request data associated with the id.\n */\n get(id: string): ApprovalRequest | undefined {\n return this.state.pendingApprovals[id];\n }\n\n /**\n * Gets the number of pending approvals, by origin and/or type.\n *\n * If only `origin` is specified, all approvals for that origin will be\n * counted, regardless of type.\n * If only `type` is specified, all approvals for that type will be counted,\n * regardless of origin.\n * If both `origin` and `type` are specified, 0 or 1 will be returned.\n *\n * @param opts - The approval count options.\n * @param opts.origin - An approval origin.\n * @param opts.type - The type of the approval request.\n * @returns The current approval request count for the given origin and/or\n * type.\n */\n getApprovalCount(opts: { origin?: string; type?: string } = {}): number {\n if (!opts.origin && !opts.type) {\n throw new Error('Must specify origin, type, or both.');\n }\n const { origin, type: _type } = opts;\n\n if (origin && _type) {\n return this._origins.get(origin)?.get(_type) || 0;\n }\n\n if (origin) {\n return Array.from(\n (this._origins.get(origin) || new Map()).values(),\n ).reduce((total, value) => total + value, 0);\n }\n\n // Only \"type\" was specified\n let count = 0;\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n count += 1;\n }\n }\n return count;\n }\n\n /**\n * Get the total count of all pending approval requests for all origins.\n *\n * @returns The total pending approval request count.\n */\n getTotalApprovalCount(): number {\n return this.state.pendingApprovalCount;\n }\n\n /**\n * Checks if there's a pending approval request per the given parameters.\n * At least one parameter must be specified. An error will be thrown if the\n * parameters are invalid.\n *\n * If `id` is specified, all other parameters will be ignored.\n * If `id` is not specified, the method will check for requests that match\n * all of the specified parameters.\n *\n * @param opts - Options bag.\n * @param opts.id - The ID to check for.\n * @param opts.origin - The origin to check for.\n * @param opts.type - The type to check for.\n * @returns `true` if a matching approval is found, and `false` otherwise.\n */\n has(opts: { id?: string; origin?: string; type?: string } = {}): boolean {\n const { id, origin, type: _type } = opts;\n\n if (id) {\n if (typeof id !== 'string') {\n throw new Error('May not specify non-string id.');\n }\n return this._approvals.has(id);\n }\n\n if (_type && typeof _type !== 'string') {\n throw new Error('May not specify non-string type.');\n }\n\n if (origin) {\n if (typeof origin !== 'string') {\n throw new Error('May not specify non-string origin.');\n }\n\n // Check origin and type pair if type also specified\n if (_type) {\n return Boolean(this._origins.get(origin)?.get(_type));\n }\n return this._origins.has(origin);\n }\n\n if (_type) {\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n return true;\n }\n }\n return false;\n }\n throw new Error(\n 'Must specify a valid combination of id, origin, and type.',\n );\n }\n\n /**\n * Resolves the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param value - The value to resolve the approval promise with.\n * @param options - Options bag.\n * @returns A promise that either resolves once a result is provided by\n * the creator of the approval request, or immediately if `options.waitForResult`\n * is `false` or `undefined`.\n */\n accept(\n id: string,\n value?: unknown,\n options?: AcceptOptions,\n ): Promise {\n // Safe to cast as the delete method below will throw if the ID is not found\n const approval = this.get(id) as ApprovalRequest;\n const requestPromise = this._deleteApprovalAndGetCallbacks(id);\n\n return new Promise((resolve, reject) => {\n const resultCallbacks: AcceptResultCallbacks = {\n success: (acceptValue?: unknown) => resolve({ value: acceptValue }),\n error: reject,\n };\n\n if (options?.waitForResult && !approval.expectsResult) {\n reject(new ApprovalRequestNoResultSupportError(id));\n return;\n }\n\n const resultValue = options?.waitForResult ? resultCallbacks : undefined;\n\n const resolveValue = approval.expectsResult\n ? { value, resultCallbacks: resultValue }\n : value;\n\n requestPromise.resolve(resolveValue);\n\n if (!options?.waitForResult) {\n resolve({ value: undefined });\n }\n });\n }\n\n /**\n * Rejects the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param error - The error to reject the approval promise with.\n */\n reject(id: string, error: unknown): void {\n this._deleteApprovalAndGetCallbacks(id).reject(error);\n }\n\n /**\n * Rejects and deletes all approval requests.\n *\n * @param rejectionError - The EthereumRpcError to reject the approval\n * requests with.\n */\n clear(rejectionError: EthereumRpcError): void {\n for (const id of this._approvals.keys()) {\n this.reject(id, rejectionError);\n }\n this._origins.clear();\n this.update((draftState) => {\n draftState.pendingApprovals = {};\n draftState.pendingApprovalCount = 0;\n });\n }\n\n /**\n * Updates the request state of the approval with the given id.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request.\n * @param opts.requestState - Additional data associated with the request\n */\n updateRequestState(opts: UpdateRequestStateOptions): void {\n if (!this.state.pendingApprovals[opts.id]) {\n throw new ApprovalRequestNotFoundError(opts.id);\n }\n\n this.update((draftState) => {\n // Typecast: ts(2589)\n draftState.pendingApprovals[opts.id].requestState =\n opts.requestState as any;\n });\n }\n\n /**\n * Starts a new approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n * @returns The object containing the approval flow id.\n */\n startFlow(opts: StartFlowOptions = {}): ApprovalFlowStartResult {\n const id = opts.id ?? nanoid();\n const loadingText = opts.loadingText ?? null;\n\n this.update((draftState) => {\n draftState.approvalFlows.push({ id, loadingText });\n });\n\n this._showApprovalRequest();\n\n return { id, loadingText };\n }\n\n /**\n * Ends the current approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow that will be finished.\n */\n endFlow({ id }: EndFlowOptions) {\n if (!this.state.approvalFlows.length) {\n throw new NoApprovalFlowsError();\n }\n\n const currentFlow = this.state.approvalFlows.slice(-1)[0];\n\n if (id !== currentFlow.id) {\n throw new EndInvalidFlowError(\n id,\n this.state.approvalFlows.map((flow) => flow.id),\n );\n }\n\n this.update((draftState) => {\n draftState.approvalFlows.pop();\n });\n }\n\n /**\n * Sets the loading text for the approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The approval flow loading text that will be displayed.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n */\n setFlowLoadingText({ id, loadingText }: SetFlowLoadingTextOptions) {\n const flowIndex = this.state.approvalFlows.findIndex(\n (flow) => flow.id === id,\n );\n\n if (flowIndex === -1) {\n throw new MissingApprovalFlowError(id);\n }\n\n this.update((draftState) => {\n draftState.approvalFlows[flowIndex].loadingText = loadingText;\n });\n }\n\n /**\n * Implementation of add operation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param id - The id of the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the approval request expects a result object to be returned.\n * @returns The approval promise.\n */\n private _add(\n origin: string,\n type: string,\n id: string = nanoid(),\n requestData?: Record,\n requestState?: Record,\n expectsResult?: boolean,\n ): Promise {\n this._validateAddParams(id, origin, type, requestData, requestState);\n\n if (\n !this._typesExcludedFromRateLimiting.includes(type) &&\n this.has({ origin, type })\n ) {\n throw ethErrors.rpc.resourceUnavailable(\n getAlreadyPendingMessage(origin, type),\n );\n }\n\n // add pending approval\n return new Promise((resolve, reject) => {\n this._approvals.set(id, { resolve, reject });\n this._addPendingApprovalOrigin(origin, type);\n\n this._addToStore(\n id,\n origin,\n type,\n requestData,\n requestState,\n expectsResult,\n );\n });\n }\n\n /**\n * Validates parameters to the add method.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n */\n private _validateAddParams(\n id: string,\n origin: string,\n type: string,\n requestData?: Record,\n requestState?: Record,\n ): void {\n let errorMessage = null;\n if (!id || typeof id !== 'string') {\n errorMessage = 'Must specify non-empty string id.';\n } else if (this._approvals.has(id)) {\n errorMessage = `Approval request with id '${id}' already exists.`;\n } else if (!origin || typeof origin !== 'string') {\n errorMessage = 'Must specify non-empty string origin.';\n } else if (!type || typeof type !== 'string') {\n errorMessage = 'Must specify non-empty string type.';\n } else if (\n requestData &&\n (typeof requestData !== 'object' || Array.isArray(requestData))\n ) {\n errorMessage = 'Request data must be a plain object if specified.';\n } else if (\n requestState &&\n (typeof requestState !== 'object' || Array.isArray(requestState))\n ) {\n errorMessage = 'Request state must be a plain object if specified.';\n }\n\n if (errorMessage) {\n throw ethErrors.rpc.internal(errorMessage);\n }\n }\n\n /**\n * Adds an entry to _origins.\n * Performs no validation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n */\n private _addPendingApprovalOrigin(origin: string, type: string): void {\n let originMap = this._origins.get(origin);\n\n if (!originMap) {\n originMap = new Map();\n this._origins.set(origin, originMap);\n }\n\n const currentValue = originMap.get(type) || 0;\n originMap.set(type, currentValue + 1);\n }\n\n /**\n * Adds an entry to the store.\n * Performs no validation.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the request expects a result object to be returned.\n */\n private _addToStore(\n id: string,\n origin: string,\n type: string,\n requestData?: Record,\n requestState?: Record,\n expectsResult?: boolean,\n ): void {\n const approval: ApprovalRequest | null> = {\n id,\n origin,\n type,\n time: Date.now(),\n requestData: requestData || null,\n requestState: requestState || null,\n expectsResult: expectsResult || false,\n };\n\n this.update((draftState) => {\n // Typecast: ts(2589)\n draftState.pendingApprovals[id] = approval as any;\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Deletes the approval with the given id. The approval promise must be\n * resolved or reject before this method is called.\n * Deletion is an internal operation because approval state is solely\n * managed by this controller.\n *\n * @param id - The id of the approval request to be deleted.\n */\n private _delete(id: string): void {\n this._approvals.delete(id);\n\n // This method is only called after verifying that the approval with the\n // specified id exists.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { origin, type } = this.state.pendingApprovals[id]!;\n\n const originMap = this._origins.get(origin) as Map;\n const originTotalCount = this.getApprovalCount({ origin });\n const originTypeCount = originMap.get(type) as number;\n\n if (originTotalCount === 1) {\n this._origins.delete(origin);\n } else {\n originMap.set(type, originTypeCount - 1);\n }\n\n this.update((draftState) => {\n delete draftState.pendingApprovals[id];\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Gets the approval callbacks for the given id, deletes the entry, and then\n * returns the callbacks for promise resolution.\n * Throws an error if no approval is found for the given id.\n *\n * @param id - The id of the approval request.\n * @returns The promise callbacks associated with the approval request.\n */\n private _deleteApprovalAndGetCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this._approvals.get(id);\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this._delete(id);\n return callbacks;\n }\n}\nexport default ApprovalController;\n"]} -\ No newline at end of file -+{"version":3,"file":"ApprovalController.js","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,mDAA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anoid } from 'nanoid';\nimport {\n BaseControllerV2,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { Json, OptionalField } from '@metamask/utils';\nimport {\n ApprovalRequestNotFoundError,\n ApprovalRequestNoResultSupportError,\n EndInvalidFlowError,\n NoApprovalFlowsError,\n MissingApprovalFlowError,\n} from './errors';\n\n// Constants\n\n// Avoiding dependency on controller-utils\nexport const ORIGIN_METAMASK = 'metamask';\nexport const APPROVAL_TYPE_RESULT_ERROR = 'result_error';\nexport const APPROVAL_TYPE_RESULT_SUCCESS = 'result_success';\n\nconst controllerName = 'ApprovalController';\n\nconst stateMetadata = {\n pendingApprovals: { persist: false, anonymous: true },\n pendingApprovalCount: { persist: false, anonymous: false },\n approvalFlows: { persist: false, anonymous: false },\n};\n\nconst getAlreadyPendingMessage = (origin: string, type: string) =>\n `Request of type '${type}' already pending for origin ${origin}. Please wait.`;\n\nconst getDefaultState = (): ApprovalControllerState => {\n return {\n pendingApprovals: {},\n pendingApprovalCount: 0,\n approvalFlows: [],\n };\n};\n\n// Internal Types\n\ntype ApprovalPromiseResolve = (value?: unknown | AddResult) => void;\n\ntype ApprovalPromiseReject = (error?: unknown) => void;\n\ntype ApprovalRequestData = Record | null;\n\ntype ApprovalRequestState = Record | null;\n\ntype ApprovalCallbacks = {\n resolve: ApprovalPromiseResolve;\n reject: ApprovalPromiseReject;\n};\n\ntype ApprovalFlow = {\n id: string;\n loadingText: string | null;\n};\n\ntype ResultOptions = {\n flowToEnd?: string;\n header?: (string | ResultComponent)[];\n};\n\n// Miscellaneous Types\n\nexport type ApprovalRequest = {\n /**\n * The ID of the approval request.\n */\n id: string;\n\n /**\n * The origin of the approval request.\n */\n origin: string;\n\n /**\n * The time that the request was received, per Date.now().\n */\n time: number;\n\n /**\n * The type of the approval request.\n */\n type: string;\n\n /**\n * Additional data associated with the request.\n * TODO:TS4.4 make optional\n */\n requestData: RequestData;\n\n /**\n * Additional mutable state associated with the request\n */\n requestState: ApprovalRequestState;\n\n /**\n * Whether the request expects a result object to be returned instead of just the approval value.\n */\n expectsResult: boolean;\n};\n\nexport type ApprovalFlowState = ApprovalFlow;\n\nexport type ApprovalControllerState = {\n pendingApprovals: Record>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nexport type ApprovalControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents,\n string,\n string\n>;\n\n// Option Types\n\nexport type ShowApprovalRequest = () => void | Promise;\n\nexport type ResultComponent = {\n /**\n * A unique identifier for this instance of the component.\n */\n key: string;\n\n /**\n * The name of the component to render.\n */\n name: string;\n\n /**\n * Any properties required by the component.\n */\n properties?: Record;\n\n /**\n * Any child components to render inside the component.\n */\n children?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ApprovalControllerOptions = {\n messenger: ApprovalControllerMessenger;\n showApprovalRequest: ShowApprovalRequest;\n state?: Partial;\n typesExcludedFromRateLimiting?: string[];\n};\n\nexport type AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record;\n requestState?: Record;\n expectsResult?: boolean;\n};\n\nexport type UpdateRequestStateOptions = {\n id: string;\n requestState: Record;\n};\n\nexport type AcceptOptions = {\n /**\n * Whether to resolve the returned promise only when the request creator indicates the success of the\n * post-approval logic using the result callbacks.\n * If false or unspecified, the promise will resolve immediately.\n */\n waitForResult?: boolean;\n};\n\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n>;\n\nexport type EndFlowOptions = Pick;\n\nexport type SetFlowLoadingTextOptions = ApprovalFlow;\n\nexport type SuccessOptions = ResultOptions & {\n message?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ErrorOptions = ResultOptions & {\n error?: string | ResultComponent | (string | ResultComponent)[];\n};\n\n// Result Types\n\nexport type AcceptResultCallbacks = {\n /**\n * Inform the request acceptor that the post-approval logic was successful.\n *\n * @param value - An optional value generated by the post-approval logic.\n */\n success: (value?: unknown) => void;\n\n /**\n * Inform the request acceptor that the post-approval logic failed.\n *\n * @param error - The reason for the failure.\n */\n error: (error: Error) => void;\n};\n\nexport type AddResult = {\n /**\n * An optional value provided by the request acceptor.\n */\n value?: unknown;\n\n /**\n * Callback functions that must be used to indicate to the request acceptor whether the post-approval logic was successful or not.\n * Will be undefined if the request acceptor did not specify that they want to wait for a result.\n */\n resultCallbacks?: AcceptResultCallbacks;\n};\n\nexport type AcceptResult = {\n /**\n * An optional value provided by the request creator when indicating a successful result.\n */\n value?: unknown;\n};\n\nexport type ApprovalFlowStartResult = ApprovalFlow;\n\nexport type SuccessResult = Record;\n\nexport type ErrorResult = Record;\n\n// Event Types\n\nexport type ApprovalStateChange = {\n type: `${typeof controllerName}:stateChange`;\n payload: [ApprovalControllerState, Patch[]];\n};\n\nexport type ApprovalControllerEvents = ApprovalStateChange;\n\n// Action Types\n\nexport type GetApprovalsState = {\n type: `${typeof controllerName}:getState`;\n handler: () => ApprovalControllerState;\n};\n\nexport type ClearApprovalRequests = {\n type: `${typeof controllerName}:clearRequests`;\n handler: (error: EthereumRpcError) => void;\n};\n\nexport type AddApprovalRequest = {\n type: `${typeof controllerName}:addRequest`;\n handler: (\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ) => ReturnType;\n};\n\nexport type HasApprovalRequest = {\n type: `${typeof controllerName}:hasRequest`;\n handler: ApprovalController['has'];\n};\n\nexport type AcceptRequest = {\n type: `${typeof controllerName}:acceptRequest`;\n handler: ApprovalController['accept'];\n};\n\nexport type RejectRequest = {\n type: `${typeof controllerName}:rejectRequest`;\n handler: ApprovalController['reject'];\n};\n\nexport type UpdateRequestState = {\n type: `${typeof controllerName}:updateRequestState`;\n handler: ApprovalController['updateRequestState'];\n};\n\nexport type StartFlow = {\n type: `${typeof controllerName}:startFlow`;\n handler: ApprovalController['startFlow'];\n};\n\nexport type EndFlow = {\n type: `${typeof controllerName}:endFlow`;\n handler: ApprovalController['endFlow'];\n};\n\nexport type SetFlowLoadingText = {\n type: `${typeof controllerName}:setFlowLoadingText`;\n handler: ApprovalController['setFlowLoadingText'];\n};\n\nexport type ShowSuccess = {\n type: `${typeof controllerName}:showSuccess`;\n handler: ApprovalController['success'];\n};\n\nexport type ShowError = {\n type: `${typeof controllerName}:showError`;\n handler: ApprovalController['error'];\n};\n\nexport type ApprovalControllerActions =\n | GetApprovalsState\n | ClearApprovalRequests\n | AddApprovalRequest\n | HasApprovalRequest\n | AcceptRequest\n | RejectRequest\n | UpdateRequestState\n | StartFlow\n | EndFlow\n | SetFlowLoadingText\n | ShowSuccess\n | ShowError;\n\n/**\n * Controller for managing requests that require user approval.\n *\n * Enables limiting the number of pending requests by origin and type, counting\n * pending requests, and more.\n *\n * Adding a request returns a promise that resolves or rejects when the request\n * is approved or denied, respectively.\n */\nexport class ApprovalController extends BaseControllerV2<\n typeof controllerName,\n ApprovalControllerState,\n ApprovalControllerMessenger\n> {\n #approvals: Map;\n\n #origins: Map>;\n\n #showApprovalRequest: () => void;\n\n #typesExcludedFromRateLimiting: string[];\n\n /**\n * Construct an Approval controller.\n *\n * @param options - The controller options.\n * @param options.showApprovalRequest - Function for opening the UI such that\n * the request can be displayed to the user.\n * @param options.messenger - The restricted controller messenger for the Approval controller.\n * @param options.state - The initial controller state.\n * @param options.typesExcludedFromRateLimiting - Array of aproval types which allow multiple pending approval requests from the same origin.\n */\n constructor({\n messenger,\n showApprovalRequest,\n state = {},\n typesExcludedFromRateLimiting = [],\n }: ApprovalControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#approvals = new Map();\n this.#origins = new Map();\n this.#showApprovalRequest = showApprovalRequest;\n this.#typesExcludedFromRateLimiting = typesExcludedFromRateLimiting;\n this.registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n private registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:clearRequests` as const,\n this.clear.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:addRequest` as const,\n (opts: AddApprovalOptions, shouldShowRequest: boolean) => {\n if (shouldShowRequest) {\n return this.addAndShowApprovalRequest(opts);\n }\n return this.add(opts);\n },\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:hasRequest` as const,\n this.has.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:acceptRequest` as const,\n this.accept.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:rejectRequest` as const,\n this.reject.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateRequestState` as const,\n this.updateRequestState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:startFlow` as const,\n this.startFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:endFlow` as const,\n this.endFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setFlowLoadingText` as const,\n this.setFlowLoadingText.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:showSuccess` as const,\n this.success.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:showError` as const,\n this.error.bind(this),\n );\n }\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving to\n * an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n addAndShowApprovalRequest(\n opts: AddApprovalOptions & { expectsResult: true },\n ): Promise;\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving\n * to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise {\n const promise = this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n this.#showApprovalRequest();\n return promise;\n }\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n add(opts: AddApprovalOptions & { expectsResult: true }): Promise;\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n add(opts: AddApprovalOptions): Promise;\n\n add(opts: AddApprovalOptions): Promise {\n return this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n }\n\n /**\n * Gets the info for the approval request with the given id.\n *\n * @param id - The id of the approval request.\n * @returns The approval request data associated with the id.\n */\n get(id: string): ApprovalRequest | undefined {\n return this.state.pendingApprovals[id];\n }\n\n /**\n * Gets the number of pending approvals, by origin and/or type.\n *\n * If only `origin` is specified, all approvals for that origin will be\n * counted, regardless of type.\n * If only `type` is specified, all approvals for that type will be counted,\n * regardless of origin.\n * If both `origin` and `type` are specified, 0 or 1 will be returned.\n *\n * @param opts - The approval count options.\n * @param opts.origin - An approval origin.\n * @param opts.type - The type of the approval request.\n * @returns The current approval request count for the given origin and/or\n * type.\n */\n getApprovalCount(opts: { origin?: string; type?: string } = {}): number {\n if (!opts.origin && !opts.type) {\n throw new Error('Must specify origin, type, or both.');\n }\n const { origin, type: _type } = opts;\n\n if (origin && _type) {\n return this.#origins.get(origin)?.get(_type) || 0;\n }\n\n if (origin) {\n return Array.from(\n (this.#origins.get(origin) || new Map()).values(),\n ).reduce((total, value) => total + value, 0);\n }\n\n // Only \"type\" was specified\n let count = 0;\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n count += 1;\n }\n }\n return count;\n }\n\n /**\n * Get the total count of all pending approval requests for all origins.\n *\n * @returns The total pending approval request count.\n */\n getTotalApprovalCount(): number {\n return this.state.pendingApprovalCount;\n }\n\n /**\n * Checks if there's a pending approval request per the given parameters.\n * At least one parameter must be specified. An error will be thrown if the\n * parameters are invalid.\n *\n * If `id` is specified, all other parameters will be ignored.\n * If `id` is not specified, the method will check for requests that match\n * all of the specified parameters.\n *\n * @param opts - Options bag.\n * @param opts.id - The ID to check for.\n * @param opts.origin - The origin to check for.\n * @param opts.type - The type to check for.\n * @returns `true` if a matching approval is found, and `false` otherwise.\n */\n has(opts: { id?: string; origin?: string; type?: string } = {}): boolean {\n const { id, origin, type: _type } = opts;\n\n if (id) {\n if (typeof id !== 'string') {\n throw new Error('May not specify non-string id.');\n }\n return this.#approvals.has(id);\n }\n\n if (_type && typeof _type !== 'string') {\n throw new Error('May not specify non-string type.');\n }\n\n if (origin) {\n if (typeof origin !== 'string') {\n throw new Error('May not specify non-string origin.');\n }\n\n // Check origin and type pair if type also specified\n if (_type) {\n return Boolean(this.#origins.get(origin)?.get(_type));\n }\n return this.#origins.has(origin);\n }\n\n if (_type) {\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n return true;\n }\n }\n return false;\n }\n throw new Error(\n 'Must specify a valid combination of id, origin, and type.',\n );\n }\n\n /**\n * Resolves the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param value - The value to resolve the approval promise with.\n * @param options - Options bag.\n * @returns A promise that either resolves once a result is provided by\n * the creator of the approval request, or immediately if `options.waitForResult`\n * is `false` or `undefined`.\n */\n accept(\n id: string,\n value?: unknown,\n options?: AcceptOptions,\n ): Promise {\n // Safe to cast as the delete method below will throw if the ID is not found\n const approval = this.get(id) as ApprovalRequest;\n const requestPromise = this.#deleteApprovalAndGetCallbacks(id);\n\n return new Promise((resolve, reject) => {\n const resultCallbacks: AcceptResultCallbacks = {\n success: (acceptValue?: unknown) => resolve({ value: acceptValue }),\n error: reject,\n };\n\n if (options?.waitForResult && !approval.expectsResult) {\n reject(new ApprovalRequestNoResultSupportError(id));\n return;\n }\n\n const resultValue = options?.waitForResult ? resultCallbacks : undefined;\n\n const resolveValue = approval.expectsResult\n ? { value, resultCallbacks: resultValue }\n : value;\n\n requestPromise.resolve(resolveValue);\n\n if (!options?.waitForResult) {\n resolve({ value: undefined });\n }\n });\n }\n\n /**\n * Rejects the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param error - The error to reject the approval promise with.\n */\n reject(id: string, error: unknown): void {\n this.#deleteApprovalAndGetCallbacks(id).reject(error);\n }\n\n /**\n * Rejects and deletes all approval requests.\n *\n * @param rejectionError - The EthereumRpcError to reject the approval\n * requests with.\n */\n clear(rejectionError: EthereumRpcError): void {\n for (const id of this.#approvals.keys()) {\n this.reject(id, rejectionError);\n }\n this.#origins.clear();\n this.update((draftState) => {\n draftState.pendingApprovals = {};\n draftState.pendingApprovalCount = 0;\n });\n }\n\n /**\n * Updates the request state of the approval with the given id.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request.\n * @param opts.requestState - Additional data associated with the request\n */\n updateRequestState(opts: UpdateRequestStateOptions): void {\n if (!this.state.pendingApprovals[opts.id]) {\n throw new ApprovalRequestNotFoundError(opts.id);\n }\n\n this.update((draftState) => {\n // Typecast: ts(2589)\n draftState.pendingApprovals[opts.id].requestState =\n opts.requestState as any;\n });\n }\n\n /**\n * Starts a new approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n * @returns The object containing the approval flow id.\n */\n startFlow(opts: StartFlowOptions = {}): ApprovalFlowStartResult {\n const id = opts.id ?? nanoid();\n const loadingText = opts.loadingText ?? null;\n\n this.update((draftState) => {\n draftState.approvalFlows.push({ id, loadingText });\n });\n\n this.#showApprovalRequest();\n\n return { id, loadingText };\n }\n\n /**\n * Ends the current approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow that will be finished.\n */\n endFlow({ id }: EndFlowOptions) {\n if (!this.state.approvalFlows.length) {\n throw new NoApprovalFlowsError();\n }\n\n const currentFlow = this.state.approvalFlows.slice(-1)[0];\n\n if (id !== currentFlow.id) {\n throw new EndInvalidFlowError(\n id,\n this.state.approvalFlows.map((flow) => flow.id),\n );\n }\n\n this.update((draftState) => {\n draftState.approvalFlows.pop();\n });\n }\n\n /**\n * Sets the loading text for the approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The approval flow loading text that will be displayed.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n */\n setFlowLoadingText({ id, loadingText }: SetFlowLoadingTextOptions) {\n const flowIndex = this.state.approvalFlows.findIndex(\n (flow) => flow.id === id,\n );\n\n if (flowIndex === -1) {\n throw new MissingApprovalFlowError(id);\n }\n\n this.update((draftState) => {\n draftState.approvalFlows[flowIndex].loadingText = loadingText;\n });\n }\n\n /**\n * Show a success page.\n *\n * @param opts - Options bag.\n * @param opts.message - The message text or components to display in the page.\n * @param opts.header - The text or components to display in the header of the page.\n * @param opts.flowToEnd - The ID of the approval flow to end once the success page is approved.\n * @returns Empty object to support future additions.\n */\n async success(opts: SuccessOptions = {}): Promise {\n await this.#result(APPROVAL_TYPE_RESULT_SUCCESS, opts, {\n message: opts.message,\n header: opts.header,\n } as any);\n return {};\n }\n\n /**\n * Show an error page.\n *\n * @param opts - Options bag.\n * @param opts.message - The message text or components to display in the page.\n * @param opts.header - The text or components to display in the header of the page.\n * @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved.\n * @returns Empty object to support future additions.\n */\n async error(opts: ErrorOptions = {}): Promise {\n await this.#result(APPROVAL_TYPE_RESULT_ERROR, opts, {\n error: opts.error,\n header: opts.header,\n } as any);\n return {};\n }\n\n /**\n * Implementation of add operation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param id - The id of the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the approval request expects a result object to be returned.\n * @returns The approval promise.\n */\n #add(\n origin: string,\n type: string,\n id: string = nanoid(),\n requestData?: Record,\n requestState?: Record,\n expectsResult?: boolean,\n ): Promise {\n this.#validateAddParams(id, origin, type, requestData, requestState);\n\n if (\n !this.#typesExcludedFromRateLimiting.includes(type) &&\n this.has({ origin, type })\n ) {\n throw ethErrors.rpc.resourceUnavailable(\n getAlreadyPendingMessage(origin, type),\n );\n }\n\n // add pending approval\n return new Promise((resolve, reject) => {\n this.#approvals.set(id, { resolve, reject });\n this.#addPendingApprovalOrigin(origin, type);\n\n this.#addToStore(\n id,\n origin,\n type,\n requestData,\n requestState,\n expectsResult,\n );\n });\n }\n\n /**\n * Validates parameters to the add method.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n */\n #validateAddParams(\n id: string,\n origin: string,\n type: string,\n requestData?: Record,\n requestState?: Record,\n ): void {\n let errorMessage = null;\n if (!id || typeof id !== 'string') {\n errorMessage = 'Must specify non-empty string id.';\n } else if (this.#approvals.has(id)) {\n errorMessage = `Approval request with id '${id}' already exists.`;\n } else if (!origin || typeof origin !== 'string') {\n errorMessage = 'Must specify non-empty string origin.';\n } else if (!type || typeof type !== 'string') {\n errorMessage = 'Must specify non-empty string type.';\n } else if (\n requestData &&\n (typeof requestData !== 'object' || Array.isArray(requestData))\n ) {\n errorMessage = 'Request data must be a plain object if specified.';\n } else if (\n requestState &&\n (typeof requestState !== 'object' || Array.isArray(requestState))\n ) {\n errorMessage = 'Request state must be a plain object if specified.';\n }\n\n if (errorMessage) {\n throw ethErrors.rpc.internal(errorMessage);\n }\n }\n\n /**\n * Adds an entry to _origins.\n * Performs no validation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n */\n #addPendingApprovalOrigin(origin: string, type: string): void {\n let originMap = this.#origins.get(origin);\n\n if (!originMap) {\n originMap = new Map();\n this.#origins.set(origin, originMap);\n }\n\n const currentValue = originMap.get(type) || 0;\n originMap.set(type, currentValue + 1);\n }\n\n /**\n * Adds an entry to the store.\n * Performs no validation.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the request expects a result object to be returned.\n */\n #addToStore(\n id: string,\n origin: string,\n type: string,\n requestData?: Record,\n requestState?: Record,\n expectsResult?: boolean,\n ): void {\n const approval: ApprovalRequest | null> = {\n id,\n origin,\n type,\n time: Date.now(),\n requestData: requestData || null,\n requestState: requestState || null,\n expectsResult: expectsResult || false,\n };\n\n this.update((draftState) => {\n // Typecast: ts(2589)\n draftState.pendingApprovals[id] = approval as any;\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Deletes the approval with the given id. The approval promise must be\n * resolved or reject before this method is called.\n * Deletion is an internal operation because approval state is solely\n * managed by this controller.\n *\n * @param id - The id of the approval request to be deleted.\n */\n #delete(id: string): void {\n this.#approvals.delete(id);\n\n // This method is only called after verifying that the approval with the\n // specified id exists.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { origin, type } = this.state.pendingApprovals[id]!;\n\n const originMap = this.#origins.get(origin) as Map;\n const originTotalCount = this.getApprovalCount({ origin });\n const originTypeCount = originMap.get(type) as number;\n\n if (originTotalCount === 1) {\n this.#origins.delete(origin);\n } else {\n originMap.set(type, originTypeCount - 1);\n }\n\n this.update((draftState) => {\n delete draftState.pendingApprovals[id];\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Gets the approval callbacks for the given id, deletes the entry, and then\n * returns the callbacks for promise resolution.\n * Throws an error if no approval is found for the given id.\n *\n * @param id - The id of the approval request.\n * @returns The promise callbacks associated with the approval request.\n */\n #deleteApprovalAndGetCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this.#approvals.get(id);\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this.#delete(id);\n return callbacks;\n }\n\n async #result(\n type: string,\n opts: ResultOptions,\n requestData: Record,\n ) {\n try {\n await this.addAndShowApprovalRequest({\n origin: ORIGIN_METAMASK,\n type,\n requestData,\n });\n } catch (error) {\n console.info('Failed to display result page', error);\n } finally {\n if (opts.flowToEnd) {\n try {\n this.endFlow({ id: opts.flowToEnd });\n } catch (error) {\n console.info('Failed to end flow', { id: opts.flowToEnd, error });\n }\n }\n }\n }\n}\n\nexport default ApprovalController;\n"]} -\ No newline at end of file diff --git a/yarn.lock b/yarn.lock index aeb4620eb74..0643ac3fda7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5107,10 +5107,10 @@ "@metamask/base-controller" "^2.0.0" "@metamask/controller-utils" "^3.0.0" -"@metamask/approval-controller@3.3.0", "@metamask/approval-controller@^2.0.0", "@metamask/approval-controller@^2.1.1", "@metamask/approval-controller@^3.3.0": - version "3.3.0" - resolved "https://registry.yarnpkg.com/@metamask/approval-controller/-/approval-controller-3.3.0.tgz#8e98de054ea92af82e50d90d300dc5222c444f3b" - integrity sha512-UlnNWm/mewteLbVNv+e4yepPkwov1cxHGtJWa5OKN+jE8ZoxX1MGUFBr6G4JczyOmv6JSR03mx0jP7T04ZN0nw== +"@metamask/approval-controller@3.4.0", "@metamask/approval-controller@^2.0.0", "@metamask/approval-controller@^2.1.1", "@metamask/approval-controller@^3.4.0": + version "3.4.0" + resolved "https://registry.yarnpkg.com/@metamask/approval-controller/-/approval-controller-3.4.0.tgz#282900361d42f785578728b45014ff8cb5e557ea" + integrity sha512-DjqrhiX9+W/Fh6Crr7FPJ87Y/uhPWzBvfXGtekv1LHZNmEtUxkrA7aelddUM0fpTdURIGT4aNGBoQudFidc+Lw== dependencies: "@metamask/base-controller" "^3.0.0" "@metamask/utils" "^5.0.2" From b79742a0bdbaa915f1d0d95d8fe3acada426b74a Mon Sep 17 00:00:00 2001 From: Vinicius Stevam Date: Fri, 7 Jul 2023 16:17:29 +0100 Subject: [PATCH 3/5] add snapshot --- .../ApprovalResult.test.tsx.snap | 349 ++++++++++++++++++ 1 file changed, 349 insertions(+) create mode 100644 app/components/UI/Approval/ApprovalResult/__snapshots__/ApprovalResult.test.tsx.snap diff --git a/app/components/UI/Approval/ApprovalResult/__snapshots__/ApprovalResult.test.tsx.snap b/app/components/UI/Approval/ApprovalResult/__snapshots__/ApprovalResult.test.tsx.snap new file mode 100644 index 00000000000..0d76cb93da9 --- /dev/null +++ b/app/components/UI/Approval/ApprovalResult/__snapshots__/ApprovalResult.test.tsx.snap @@ -0,0 +1,349 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ApprovalResult renders approval result with error type 1`] = ` + + + + + + + + + + + Error + + + + + Error message + + + + + + OK + + + + + + +`; + +exports[`ApprovalResult renders approval result with success type 1`] = ` + + + + + + + + + + + Success + + + + + Success message + + + + + + OK + + + + + + +`; From 3904a4a1756faea71bb84b9fe190b9cb40a7ed55 Mon Sep 17 00:00:00 2001 From: Vinicius Stevam Date: Mon, 10 Jul 2023 10:43:41 +0100 Subject: [PATCH 4/5] update snapshot --- .../ApprovalResult.test.tsx.snap | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/app/components/UI/Approval/ApprovalResult/__snapshots__/ApprovalResult.test.tsx.snap b/app/components/UI/Approval/ApprovalResult/__snapshots__/ApprovalResult.test.tsx.snap index 0d76cb93da9..c927307a618 100644 --- a/app/components/UI/Approval/ApprovalResult/__snapshots__/ApprovalResult.test.tsx.snap +++ b/app/components/UI/Approval/ApprovalResult/__snapshots__/ApprovalResult.test.tsx.snap @@ -3,7 +3,7 @@ exports[`ApprovalResult renders approval result with error type 1`] = ` Date: Tue, 11 Jul 2023 11:19:59 +0100 Subject: [PATCH 5/5] add fallback message --- app/components/Nav/Main/RootRPCMethodsUI.js | 24 +++++++------- .../ApprovalResult/ApprovalResult.tsx | 31 +++++++++++++------ app/core/RPCMethods/RPCMethodMiddleware.ts | 4 +-- locales/languages/en.json | 4 ++- 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/app/components/Nav/Main/RootRPCMethodsUI.js b/app/components/Nav/Main/RootRPCMethodsUI.js index 267dbca2723..eaf3b7f68b5 100644 --- a/app/components/Nav/Main/RootRPCMethodsUI.js +++ b/app/components/Nav/Main/RootRPCMethodsUI.js @@ -93,7 +93,7 @@ const RootRPCMethodsUI = (props) => { const [watchAsset, setWatchAsset] = useState(undefined); - const [approvalResult, setApprovalResult] = useState(undefined); + const [approvalResultRequest, setApprovalResultRequest] = useState(undefined); const [signMessageParams, setSignMessageParams] = useState(undefined); @@ -409,16 +409,15 @@ const RootRPCMethodsUI = (props) => { const onApprovalResultConfirm = () => { setShowPendingApproval(false); - acceptPendingApproval(approvalResult.id, approvalResult.data); - setApprovalResult(undefined); + acceptPendingApproval(approvalResultRequest.id, approvalResultRequest.data); + setApprovalResultRequest(undefined); }; const renderApprovalResultModal = () => { if ( - ![ - ApprovalTypes.APPROVAL_TYPE_RESULT_SUCCESS, - ApprovalTypes.APPROVAL_TYPE_RESULT_ERROR, - ].includes(showPendingApproval?.type) + ![ApprovalTypes.RESULT_SUCCESS, ApprovalTypes.RESULT_ERROR].includes( + showPendingApproval?.type, + ) ) { return null; } @@ -436,11 +435,10 @@ const RootRPCMethodsUI = (props) => { propagateSwipe > { origin: request.origin, }); break; - case ApprovalTypes.APPROVAL_TYPE_RESULT_SUCCESS: - case ApprovalTypes.APPROVAL_TYPE_RESULT_ERROR: - setApprovalResult({ data: requestData, id: request.id }); + case ApprovalTypes.RESULT_SUCCESS: + case ApprovalTypes.RESULT_ERROR: + setApprovalResultRequest({ data: requestData, id: request.id }); showPendingApprovalModal({ type: request.type, origin: request.origin, diff --git a/app/components/UI/Approval/ApprovalResult/ApprovalResult.tsx b/app/components/UI/Approval/ApprovalResult/ApprovalResult.tsx index 25f3bb0ad11..d2b94f49065 100644 --- a/app/components/UI/Approval/ApprovalResult/ApprovalResult.tsx +++ b/app/components/UI/Approval/ApprovalResult/ApprovalResult.tsx @@ -37,6 +37,24 @@ export interface ApprovalResultProps { onConfirm: () => void; requestType: ApprovalResultType; } +const isApprovalResultTypeSuccess = (type: string) => + ApprovalResultType.Success === type; + +const processMessage = ( + requestData: ApprovalResultData, + requestType: ApprovalResultType, +) => { + if (isApprovalResultTypeSuccess(requestType)) { + return ( + requestData?.message ?? + strings('approval_result.resultPageSuccessDefaultMessage') + ); + } + return ( + requestData?.error ?? + strings('approval_result.resultPageErrorDefaultMessage') + ); +}; const ApprovalResult = ({ requestData, @@ -45,9 +63,6 @@ const ApprovalResult = ({ }: ApprovalResultProps) => { const { styles } = useStyles(stylesheet, {}); - const isApprovalTypeResultSuccess = (type: string) => - ApprovalResultType.Success === type; - const okButtonProps: ButtonProps = { variant: ButtonVariants.Primary, label: strings('approval_result.ok'), @@ -62,12 +77,12 @@ const ApprovalResult = ({ - {isApprovalTypeResultSuccess(requestType) - ? requestData?.message - : requestData?.error} + {processMessage(requestData, requestType)}