import { browser } from "webextension-polyfill-ts" ; import { EXTERNAL_SERVICE_TYPES , SERVICE_TYPES , } from "@shared/constants/services" ; import { popupMessageListener } from "./messageListener/popupMessageListener" ; import { freighterApiMessageListener } from "./messageListener/freighterApiMessageListener" ; export const initMessageListener = ( ) => { browser . runtime . onMessage . addListener ( async ( request , sender ) => { let res ; if ( Object . values ( SERVICE_TYPES ) . includes ( request . type ) ) { res = await popupMessageListener ( request ) ; } if ( Object . values ( EXTERNAL_SERVICE_TYPES ) . includes ( request . type ) ) { res = await freighterApiMessageListener ( request , sender ) ; } return res ; } ) ; } ;