@@ -10,6 +10,7 @@ import {
10
10
AddApprovalRequest ,
11
11
} from '@metamask/approval-controller' ;
12
12
import { Json } from '@metamask/utils' ;
13
+ import { Browser } from 'webextension-polyfill' ;
13
14
import { METAMASK_CONTROLLER_EVENTS } from '../metamask-controller' ;
14
15
import { MINUTE } from '../../../shared/constants/time' ;
15
16
import { AUTO_LOCK_TIMEOUT_ALARM } from '../../../shared/constants/alarms' ;
@@ -24,7 +25,7 @@ import {
24
25
} from '../../../shared/constants/app' ;
25
26
import { DEFAULT_AUTO_LOCK_TIME_LIMIT } from '../../../shared/constants/preferences' ;
26
27
import { LastInteractedConfirmationInfo } from '../../../shared/types/confirm' ;
27
- import { SecurityAlertSource } from '../../../shared/constants/security-provider ' ;
28
+ import { SecurityAlertResponse } from '../lib/ppom/types ' ;
28
29
import type {
29
30
Preferences ,
30
31
PreferencesControllerStateChangeEvent ,
@@ -126,33 +127,34 @@ type PollingTokenType =
126
127
| 'notificationGasPollTokens'
127
128
| 'fullScreenGasPollTokens' ;
128
129
129
- type SecurityAlertResponse = {
130
- block ?: number ;
131
- description ?: string ;
132
- features ?: string [ ] ;
133
- providerRequestsCount ?: Record < string , number > ;
134
- reason : string ;
135
- result_type : string ;
136
- securityAlertId ?: string ;
137
- source ?: SecurityAlertSource ;
138
- } ;
130
+ type AppStateControllerInitState = Partial <
131
+ Omit <
132
+ AppStateControllerState ,
133
+ | 'qrHardware'
134
+ | 'nftsDropdownState'
135
+ | 'usedNetworks'
136
+ | 'surveyLinkLastClickedOrClosed'
137
+ | 'signatureSecurityAlertResponses'
138
+ | 'switchedNetworkDetails'
139
+ | 'switchedNetworkNeverShowMessage'
140
+ | 'currentExtensionPopupId'
141
+ >
142
+ > ;
139
143
140
144
type AppStateControllerOptions = {
141
145
addUnlockListener : ( callback : ( ) => void ) => void ;
142
146
isUnlocked : ( ) => boolean ;
143
- initState ?: Partial < AppStateControllerState > ;
147
+ initState ?: AppStateControllerInitState ;
144
148
onInactiveTimeout ?: ( ) => void ;
145
149
// TODO: Remove this as soon as PreferencesController upgrade to BaseControllerV2 merges with develop
146
150
// eslint-disable-next-line @typescript-eslint/no-explicit-any
147
151
preferencesStore : any ;
148
152
messenger : AppStateControllerMessenger ;
149
- // TODO: Replace `any` with type
150
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
151
- extension : any ;
153
+ extension : Browser ;
152
154
} ;
153
155
154
- const getInitState = (
155
- initState ?: Partial < AppStateControllerState > ,
156
+ const getDefaultAppStateControllerState = (
157
+ initState ?: AppStateControllerInitState ,
156
158
) : AppStateControllerState => ( {
157
159
timeoutMinutes : DEFAULT_AUTO_LOCK_TIME_LIMIT ,
158
160
connectedStatusPopoverHasBeenShown : true ,
@@ -190,10 +192,8 @@ const getInitState = (
190
192
currentExtensionPopupId : 0 ,
191
193
} ) ;
192
194
193
- export default class AppStateController extends EventEmitter {
194
- // TODO: Replace `any` with type
195
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
196
- private extension : any ;
195
+ export class AppStateController extends EventEmitter {
196
+ private extension : AppStateControllerOptions [ 'extension' ] ;
197
197
198
198
private onInactiveTimeout : ( ) => void ;
199
199
@@ -207,7 +207,7 @@ export default class AppStateController extends EventEmitter {
207
207
208
208
private messagingSystem : AppStateControllerMessenger ;
209
209
210
- private _approvalRequestId : string | null ;
210
+ #approvalRequestId : string | null ;
211
211
212
212
constructor ( opts : AppStateControllerOptions ) {
213
213
const {
@@ -223,7 +223,9 @@ export default class AppStateController extends EventEmitter {
223
223
224
224
this . extension = extension ;
225
225
this . onInactiveTimeout = onInactiveTimeout || ( ( ) => undefined ) ;
226
- this . store = new ObservableStore ( getInitState ( initState ) ) ;
226
+ this . store = new ObservableStore (
227
+ getDefaultAppStateControllerState ( initState ) ,
228
+ ) ;
227
229
this . timer = null ;
228
230
229
231
this . isUnlocked = isUnlocked ;
@@ -258,7 +260,7 @@ export default class AppStateController extends EventEmitter {
258
260
}
259
261
260
262
this . messagingSystem = messenger ;
261
- this . _approvalRequestId = null ;
263
+ this . #approvalRequestId = null ;
262
264
}
263
265
264
266
/**
@@ -816,24 +818,24 @@ export default class AppStateController extends EventEmitter {
816
818
817
819
private _requestApproval ( ) : void {
818
820
// If we already have a pending request this is a no-op
819
- if ( this . _approvalRequestId ) {
821
+ if ( this . #approvalRequestId ) {
820
822
return ;
821
823
}
822
- this . _approvalRequestId = uuid ( ) ;
824
+ this . #approvalRequestId = uuid ( ) ;
823
825
824
826
this . messagingSystem
825
827
. call (
826
828
'ApprovalController:addRequest' ,
827
829
{
828
- id : this . _approvalRequestId ,
830
+ id : this . #approvalRequestId ,
829
831
origin : ORIGIN_METAMASK ,
830
832
type : ApprovalType . Unlock ,
831
833
} ,
832
834
true ,
833
835
)
834
836
. catch ( ( ) => {
835
837
// If the promise fails, we allow a new popup to be triggered
836
- this . _approvalRequestId = null ;
838
+ this . #approvalRequestId = null ;
837
839
} ) ;
838
840
}
839
841
@@ -843,18 +845,18 @@ export default class AppStateController extends EventEmitter {
843
845
}
844
846
845
847
private _acceptApproval ( ) : void {
846
- if ( ! this . _approvalRequestId ) {
848
+ if ( ! this . #approvalRequestId ) {
847
849
return ;
848
850
}
849
851
try {
850
852
this . messagingSystem . call (
851
853
'ApprovalController:acceptRequest' ,
852
- this . _approvalRequestId ,
854
+ this . #approvalRequestId ,
853
855
) ;
854
856
} catch ( error ) {
855
857
log . error ( 'Failed to unlock approval request' , error ) ;
856
858
}
857
859
858
- this . _approvalRequestId = null ;
860
+ this . #approvalRequestId = null ;
859
861
}
860
862
}
0 commit comments