app/scripts/contentscript.js
/**
 * Establishes listeners for requests to fully-enable the provider from the dapp context
 * and for full-provider approvals and rejections from the background script context. Dapps
 * should not post messages directly and should instead call provider.enable(), which
 * handles posting these messages internally.
 */
Establishes listeners for requests to fully-enable the provider from the dapp context
and for full-provider approvals and rejections from the background script context. Dapps
should not post messages directly and should instead call provider.enable(), which
handles posting these messages internally.
Establishes listeners for requests to fully - enable the provider from the dapp context and for full - provider approvals and rejections from the background script context . Dapps should not post messages directly and should instead call provider . enable () which handles posting these messages internally .
function listenForProviderRequest () {
  window.addEventListener('message', ({ source, data }) => {
    if (source !== window || !data || !data.type) { return }
    switch (data.type) {
      case 'JingtumMask_IS_UNLOCKED':
        extension.runtime.sendMessage({
          action: 'init-is-unlocked',
        })
        break
    }
  })
  extension.runtime.onMessage.addListener(({ action = '', isApproved, caching, isUnlocked, selectedAddress }) => {
    switch (action) {
      case 'answer-is-unlocked':
        window.postMessage({ type: 'JingtumMaskisunlocked', isUnlocked }, '*')
        break
      case 'metamask-set-locked':
        isEnabled = false
        window.postMessage({ type: 'JingtumMasksetlocked' }, '*')
        break
    }
  })
}
function listenForProviderRequest ( ) { window . addEventListener ( 'message' , ( { source , data } ) => { if ( source !== window || ! data || ! data . type ) { return } switch ( data . type ) { case 'JingtumMask_IS_UNLOCKED' : extension . runtime . sendMessage ( { action : 'init-is-unlocked' , } ) break } } ) extension . runtime . onMessage . addListener ( ( { action = '' , isApproved , caching , isUnlocked , selectedAddress } ) => { switch ( action ) { case 'answer-is-unlocked' : window . postMessage ( { type : 'JingtumMaskisunlocked' , isUnlocked } , '*' ) break case 'metamask-set-locked' : isEnabled = false window . postMessage ( { type : 'JingtumMasksetlocked' } , '*' ) break } } ) }
Establishes listeners for requests to fully-enable the provider from the dapp context
 and for full-provider approvals and rejections from the background script context.
Establishes listeners for requests to fully - enable the provider from the dapp context and for full - provider approvals and rejections from the background script context .