@@ -91,6 +91,35 @@ describe('DappsController', () => {
9191 expect ( lido . chainIds ) . toEqual ( [ 1 ] ) // other networks should be excluded because the are not in our networks list
9292 expect ( lido . blacklisted ) . toEqual ( 'VERIFIED' )
9393 } )
94+ test ( 'should preserve account preferences while fetching and updating dapps' , async ( ) => {
95+ const accountPreferences = {
96+ enabled : true ,
97+ selectedAccount : '0x16c81367c30c71d6B712355255A07FCe8fd3b5bB' ,
98+ accounts : [ '0x16c81367c30c71d6B712355255A07FCe8fd3b5bB' ]
99+ }
100+ const storedAave = makeDapp ( {
101+ id : 'aave.com' ,
102+ name : 'Aave' ,
103+ url : 'https://aave.com' ,
104+ isConnected : true ,
105+ connectedSources : [ 'injected' ] ,
106+ accountPreferences
107+ } )
108+
109+ const { controller, mainCtrl } = await prepareTest ( async ( storageCtrl ) => {
110+ await storageCtrl . set ( 'dappsV2' , [ storedAave ] )
111+ await storageCtrl . set ( 'lastDappsUpdateVersion' , 'test-version' )
112+ } )
113+
114+ await controller . fetchAndUpdatePromise
115+
116+ expect ( controller . getDapp ( 'aave.com' ) ! . accountPreferences ) . toEqual ( accountPreferences )
117+
118+ const stored = await mainCtrl . storage . get ( 'dappsV2' , [ ] )
119+ expect ( stored . find ( ( dapp ) => dapp . id === 'aave.com' ) ! . accountPreferences ) . toEqual (
120+ accountPreferences
121+ )
122+ } )
94123 test ( 'should skip fetch and update' , async ( ) => {
95124 const { controller } = await prepareTest ( async ( storageCtrl ) => {
96125 await storageCtrl . set ( 'dappsV2' , predefinedDapps )
@@ -938,9 +967,9 @@ describe('DappsController', () => {
938967 describe ( 'connection sources' , ( ) => {
939968 const baseDapp = ( ) : Dapp =>
940969 makeDapp ( {
941- id : 'sources-dapp .com' ,
942- name : 'Sources Dapp ' ,
943- url : 'https://sources-dapp .com' ,
970+ id : 'aave .com' ,
971+ name : 'Aave ' ,
972+ url : 'https://aave .com' ,
944973 isCustom : true ,
945974 isConnected : true ,
946975 chainId : 1 ,
@@ -955,7 +984,7 @@ describe('DappsController', () => {
955984
956985 await controller . addDapp ( baseDapp ( ) )
957986
958- const stored = controller . getDapp ( 'sources-dapp .com' ) !
987+ const stored = controller . getDapp ( 'aave .com' ) !
959988 expect ( stored . connectedSources ) . toEqual ( [ 'injected' ] )
960989 expect ( stored . isConnected ) . toBe ( true )
961990 } )
@@ -970,8 +999,34 @@ describe('DappsController', () => {
970999 await controller . addDapp ( baseDapp ( ) , 'wc' )
9711000 await controller . addDapp ( baseDapp ( ) , 'wc' ) // duplicate
9721001
973- const stored = controller . getDapp ( 'sources-dapp.com' ) !
1002+ const stored = controller . getDapp ( 'aave.com' ) !
1003+ expect ( stored . connectedSources ) . toEqual ( [ 'injected' , 'wc' ] )
1004+ } )
1005+
1006+ test ( 'addDapp preserves existing account preferences when merging a source' , async ( ) => {
1007+ const accountPreferences = {
1008+ enabled : true ,
1009+ selectedAccount : '0x16c81367c30c71d6B712355255A07FCe8fd3b5bB' ,
1010+ accounts : [ '0x16c81367c30c71d6B712355255A07FCe8fd3b5bB' ]
1011+ }
1012+ const { controller } = await prepareTest ( async ( storageCtrl ) => {
1013+ await storageCtrl . set ( 'dappsV2' , [
1014+ {
1015+ ...baseDapp ( ) ,
1016+ connectedSources : [ 'injected' ] ,
1017+ accountPreferences
1018+ }
1019+ ] )
1020+ await storageCtrl . set ( 'lastDappsUpdateVersion' , 'force-dapp-refetch' )
1021+ } )
1022+
1023+ await controller . fetchAndUpdatePromise
1024+
1025+ await controller . addDapp ( baseDapp ( ) , 'wc' )
1026+
1027+ const stored = controller . getDapp ( 'aave.com' ) !
9741028 expect ( stored . connectedSources ) . toEqual ( [ 'injected' , 'wc' ] )
1029+ expect ( stored . accountPreferences ) . toEqual ( accountPreferences )
9751030 } )
9761031
9771032 test ( 'hasPermission(id, source) is source-scoped; hasPermission(id) is any-source' , async ( ) => {
@@ -982,10 +1037,10 @@ describe('DappsController', () => {
9821037
9831038 await controller . addDapp ( baseDapp ( ) , 'wc' )
9841039
985- expect ( controller . hasPermission ( 'sources-dapp .com' ) ) . toBe ( true )
986- expect ( controller . hasPermission ( 'sources-dapp .com' , 'wc' ) ) . toBe ( true )
1040+ expect ( controller . hasPermission ( 'aave .com' ) ) . toBe ( true )
1041+ expect ( controller . hasPermission ( 'aave .com' , 'wc' ) ) . toBe ( true )
9871042 // Core behavior change: an injected request must still re-prompt even when WC is connected.
988- expect ( controller . hasPermission ( 'sources-dapp .com' , 'injected' ) ) . toBe ( false )
1043+ expect ( controller . hasPermission ( 'aave .com' , 'injected' ) ) . toBe ( false )
9891044 } )
9901045
9911046 // BUG: a stored dapp whose isConnected and connectedSources had drifted (isConnected: true
@@ -1078,12 +1133,12 @@ describe('DappsController', () => {
10781133 } )
10791134
10801135 await controller . addDapp ( baseDapp ( ) , 'wc' )
1081- expect ( controller . getDapp ( 'sources-dapp .com' ) ) . toBeDefined ( )
1136+ expect ( controller . getDapp ( 'aave .com' ) ) . toBeDefined ( )
10821137
1083- await controller . disconnectDappSource ( 'sources-dapp .com' , 'wc' )
1138+ await controller . disconnectDappSource ( 'aave .com' , 'wc' )
10841139
10851140 // Custom dapps that lose their last source are removed from the catalog.
1086- expect ( controller . getDapp ( 'sources-dapp .com' ) ) . toBeUndefined ( )
1141+ expect ( controller . getDapp ( 'aave .com' ) ) . toBeUndefined ( )
10871142 } )
10881143 } )
10891144
0 commit comments