import './wdyr' ; import React from 'react' ; import ReactDOM from 'react-dom' ; import Views from './views' ; import { Message } from '@/utils' ; import { getUITypeName } from 'ui/utils' ; import eventBus from '@/eventBus' ; import * as Sentry from '@sentry/react' ; import { Integrations } from '@sentry/tracing' ; import i18n , { addResourceBundle } from 'src/i18n' ; import { EVENTS } from 'consts' ; import '../i18n' ; import './style/index.less' ; if ( process . env . NODE_ENV === 'production' ) { Sentry . init ( { dsn : 'https://e871ee64a51b4e8c91ea5fa50b67be6b@o460488.ingest.sentry.io/5831390' , integrations : [ new Integrations . BrowserTracing ( ) ] , release : process . env . release , tracesSampleRate : 1.0 , } ) ; } if ( window . screenLeft < 0 || window . screenTop < 0 || window . screenLeft > window . screen . width || window . screenTop > window . screen . height ) { chrome . runtime . getPlatformInfo ( function ( info ) { if ( info . os === 'mac' ) { const fontFaceSheet = new CSSStyleSheet ( ) ; fontFaceSheet . insertRule ( `
        @keyframes redraw {
          0% {
            opacity: 1;
          }
          100% {
            opacity: .99;
          }
        }
      ` ) ; fontFaceSheet . insertRule ( `
        html {
          animation: redraw 1s linear infinite;
        }
      ` ) ; ( document as any ) . adoptedStyleSheets = [ ... ( document as any ) . adoptedStyleSheets , fontFaceSheet , ] ; } } ) ; } function initAppMeta ( ) { const head = document . querySelector ( 'head' ) ; const icon = document . createElement ( 'link' ) ; icon . href = 'https://rabby.io/assets/images/logo-128.png' ; icon . rel = 'icon' ; head ?. appendChild ( icon ) ; const name = document . createElement ( 'meta' ) ; name . name = 'name' ; name . content = 'Rabby' ; head ?. appendChild ( name ) ; const description = document . createElement ( 'meta' ) ; description . name = 'description' ; description . content = i18n . t ( 'appDescription' ) ; head ?. appendChild ( description ) ; } initAppMeta ( ) ; const { PortMessage } = Message ; const portMessageChannel = new PortMessage ( ) ; portMessageChannel . connect ( getUITypeName ( ) ) ; const wallet = new Proxy ( { } , { get ( obj , key ) { switch ( key ) { case 'openapi' : return new Proxy ( { } , { get ( obj , key ) { return function ( ... params ) { return portMessageChannel . request ( { type : 'openapi' , method : key , params , } ) ; } ; } , } ) ; break ; default : return function ( ... params ) { return portMessageChannel . request ( { type : 'controller' , method : key , params , } ) ; } ; } } , } ) ; portMessageChannel . listen ( ( data ) => { if ( data . type === 'broadcast' ) { eventBus . emit ( data . method , data . params ) ; } } ) ; eventBus . addEventListener ( EVENTS . broadcastToBackground , ( data ) => { portMessageChannel . request ( { type : 'broadcast' , method : data . method , params : data . data , } ) ; } ) ; wallet . getLocale ( ) . then ( ( locale ) => { addResourceBundle ( locale ) . then ( ( ) => { i18n . changeLanguage ( locale ) ; ReactDOM . render ( < Views wallet = { wallet } / > , document . getElementById ( 'root' ) ) ; } ) ; } ) ;