mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-30 16:18:07 +01:00
3bf94164ac
* @metamask/inpage-provider@^8.0.0 * Replace public config store with JSON-RPC notifications * Encapsulate notification permissioning in permissions controller * Update prefix of certain internal RPC methods and notifications * Add accounts to getProviderState * Send accounts with isUnlocked notification (#10007) * Rename provider streams, notify provider of stream failures (#10006)
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
import { MESSAGE_TYPE } from '../../enums'
|
|
|
|
/**
|
|
* This RPC method gets background state relevant to the provider.
|
|
* The background sends RPC notifications on state changes, but the provider
|
|
* first requests state on initialization.
|
|
*/
|
|
|
|
const getProviderState = {
|
|
methodNames: [MESSAGE_TYPE.GET_PROVIDER_STATE],
|
|
implementation: getProviderStateHandler,
|
|
}
|
|
export default getProviderState
|
|
|
|
/**
|
|
* @typedef {Object} ProviderStateHandlerResult
|
|
* @property {string} chainId - The current chain ID.
|
|
* @property {boolean} isUnlocked - Whether the extension is unlocked or not.
|
|
* @property {string} networkVersion - The current network ID.
|
|
*/
|
|
|
|
/**
|
|
* @typedef {Object} ProviderStateHandlerOptions
|
|
* @property {() => ProviderStateHandlerResult} getProviderState - A function that
|
|
* gets the current provider state.
|
|
*/
|
|
|
|
/**
|
|
* @param {import('json-rpc-engine').JsonRpcRequest<[]>} req - The JSON-RPC request object.
|
|
* @param {import('json-rpc-engine').JsonRpcResponse<ProviderStateHandlerResult>} res - The JSON-RPC response object.
|
|
* @param {Function} _next - The json-rpc-engine 'next' callback.
|
|
* @param {Function} end - The json-rpc-engine 'end' callback.
|
|
* @param {ProviderStateHandlerOptions} options
|
|
*/
|
|
async function getProviderStateHandler(
|
|
req,
|
|
res,
|
|
_next,
|
|
end,
|
|
{ getProviderState: _getProviderState },
|
|
) {
|
|
res.result = {
|
|
...(await _getProviderState(req.origin)),
|
|
}
|
|
return end()
|
|
}
|