createMiddleware ({ origin, getSiteMetadata }) {
    return createAsyncMiddleware(async (req, res, next) => {
      // only handle requestAccounts
      if (req.method !== 'eth_requestAccounts') return next()
      // if already approved or privacy mode disabled, return early
      const isUnlocked = this.keyringController.memStore.getState().isUnlocked
      if (this.shouldExposeAccounts(origin) && isUnlocked) {
        res.result = [this.preferencesController.getSelectedAddress()]
        return
      }
      // register the provider request
      const metadata = await getSiteMetadata(origin)
      this._handleProviderRequest(origin, metadata.name, metadata.icon, false, null)
      // wait for resolution of request
      const approved = await new Promise(resolve => this.once(`resolvedRequest:${origin}`, ({ approved }) => resolve(approved)))
      if (approved) {
        res.result = [this.preferencesController.getSelectedAddress()]
      } else {
        throw new Error('User denied account authorization')
      }
    })
  }
/**
   * Called when a user approves access to a full Ethereum provider API
   *
   * @param {object} opts - opts for the middleware contains the origin for the middleware
   */
Called when a user approves access to a full Ethereum provider API
@param {object} opts - opts for the middleware contains the origin for the middleware
Called when a user approves access to a full Ethereum provider API @param { object } opts - opts for the middleware contains the origin for the middleware
createMiddleware ({ origin, getSiteMetadata }) {
    return createAsyncMiddleware(async (req, res, next) => {
      if (req.method !== 'eth_requestAccounts') return next()
      const isUnlocked = this.keyringController.memStore.getState().isUnlocked
      if (this.shouldExposeAccounts(origin) && isUnlocked) {
        res.result = [this.preferencesController.getSelectedAddress()]
        return
      }
      const metadata = await getSiteMetadata(origin)
      this._handleProviderRequest(origin, metadata.name, metadata.icon, false, null)
      const approved = await new Promise(resolve => this.once(`resolvedRequest:${origin}`, ({ approved }) => resolve(approved)))
      if (approved) {
        res.result = [this.preferencesController.getSelectedAddress()]
      } else {
        throw new Error('User denied account authorization')
      }
    })
  }
createMiddleware ( { origin , getSiteMetadata } ) { return createAsyncMiddleware ( async ( req , res , next ) => { if ( req . method !== 'eth_requestAccounts' ) return next ( ) const isUnlocked = this . keyringController . memStore . getState ( ) . isUnlocked if ( this . shouldExposeAccounts ( origin ) && isUnlocked ) { res . result = [ this . preferencesController . getSelectedAddress ( ) ] return } const metadata = await getSiteMetadata ( origin ) this . _handleProviderRequest ( origin , metadata . name , metadata . icon , false , null ) const approved = await new Promise ( resolve => this . once ( ` ${ origin } ` , ( { approved } ) => resolve ( approved ) ) ) if ( approved ) { res . result = [ this . preferencesController . getSelectedAddress ( ) ] } else { throw new Error ( 'User denied account authorization' ) } } ) }
Called when a user approves access to a full Ethereum provider API
 @param {object} opts - opts for the middleware contains the origin for the middleware
Called when a user approves access to a full Ethereum provider API @param { object } opts - opts for the middleware contains the origin for the middleware
// only handle requestAccounts // if already approved or privacy mode disabled, return early // register the provider request // wait for resolution of request