import { wellKnownChains , ConnectionManager } from "./ConnectionManager" ; import { logger } from "@polkadot/util" ; import { isEmpty } from "../utils/utils" ; import settings from "./settings.json" ; export interface Background extends Window { manager : ConnectionManager ; } declare let window ; const manager = ( window . manager = new ConnectionManager ( ) ) ; const l = logger ( "Extension" ) ; export interface RequestRpcSend { method : string ; params : unknown [ ] ; } const init = async ( ) => { try { manager . initSmoldot ( ) ; for ( const [ key , value ] of wellKnownChains . entries ( ) ) { const rpcCallback = ( rpc ) => { console . warn ( `Got RPC from ${ key } dummy chain: ${ rpc }` ) ; } ; await manager . addChain ( value , rpcCallback ) . catch ( ( err ) => l . error ( "Error" , err ) ) ; } } catch ( e ) { l . error ( `Error creating smoldot: ${ e }` ) ; } } ; chrome . runtime . onInstalled . addListener ( ( ) => { init ( ) . catch ( console . error ) ; } ) ; chrome . runtime . onStartup . addListener ( ( ) => { init ( ) . catch ( console . error ) ; } ) ; chrome . runtime . onConnect . addListener ( ( port ) => { manager . addApp ( port ) ; } ) ; chrome . storage . sync . get ( [ "notifications" ] , ( result ) => { if ( isEmpty ( result ) ) { chrome . storage . sync . set ( { notifications : settings . notifications } , ( ) => { if ( chrome . runtime . lastError ) { console . error ( chrome . runtime . lastError ) ; } } ) ; } } ) ;