99 type ApiGetDataWalletsResponse ,
1010 type ApiGetWalletsRequest ,
1111 type ApiGetWalletsResponse ,
12+ type CustomWallet ,
1213 type WcWallet ,
1314 PresetsUtil
1415} from '@reown/appkit-common-react-native' ;
@@ -140,6 +141,8 @@ export const ApiController = {
140141 const installed = results . filter ( ( { isInstalled } ) => isInstalled ) . map ( ( { id } ) => id ) ;
141142 const { excludeWalletIds } = OptionsController . state ;
142143
144+ // Collect API-sourced installed wallets
145+ let apiInstalledWallets : WcWallet [ ] = [ ] ;
143146 if ( installed . length > 0 ) {
144147 const walletResponse = await api . get < ApiGetWalletsResponse > ( {
145148 path : '/getWallets' ,
@@ -158,20 +161,32 @@ export const ApiController = {
158161 await CoreHelperUtil . allSettled (
159162 ( walletImages as string [ ] ) . map ( id => ApiController . _fetchWalletImage ( id ) )
160163 ) ;
161- state . installed = walletResponse . data ;
162- this . updateRecentWalletsInfo ( walletResponse . data ) ;
164+ apiInstalledWallets = walletResponse . data ;
163165 }
164166 }
165167
168+ // Collect custom installed wallets
169+ let customInstalledWallets : CustomWallet [ ] = [ ] ;
166170 if ( customPromises ?. length ) {
167171 const customResults = await Promise . all ( customPromises ) ;
168172 const customInstalled = customResults
169173 . filter ( ( { isInstalled } ) => isInstalled )
170174 . map ( ( { id } ) => id ) ;
171- const customInstalledWallets =
175+ customInstalledWallets =
172176 customWallets ?. filter ( wallet => customInstalled . includes ( wallet . id ) ) ?? [ ] ;
173- state . installed = [ ...state . installed , ...customInstalledWallets ] ;
174- this . updateRecentWalletsInfo ( state . installed ) ;
177+ }
178+
179+ // Merge and de-duplicate by id, preserving order (API first, then custom)
180+ const byId = new Map < string , WcWallet > ( ) ;
181+ [ ...apiInstalledWallets , ...customInstalledWallets ] . forEach ( wallet => {
182+ if ( ! byId . has ( wallet . id ) ) {
183+ byId . set ( wallet . id , wallet ) ;
184+ }
185+ } ) ;
186+ const combinedInstalled = Array . from ( byId . values ( ) ) ;
187+ state . installed = combinedInstalled ;
188+ if ( combinedInstalled . length ) {
189+ this . updateRecentWalletsInfo ( combinedInstalled ) ;
175190 }
176191 } ,
177192
0 commit comments