mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Use DesktopManager in background script to redirect internal and external connections to the desktop app. Include DesktopController in the MetaMask controller. Support desktop keyrings in MetaMask controller via the overrides object. Create middleware handler to connect to the desktop app while UI code is pending. Add build system support for desktop specific configuration variables.
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
import { MESSAGE_TYPE } from '../../../../../../shared/constants/app';
|
|
|
|
/**
|
|
* A wrapper for `eth_accounts` that returns an empty array when permission is denied.
|
|
*/
|
|
|
|
const requestEthereumAccounts = {
|
|
methodNames: [MESSAGE_TYPE.ENABLE_DESKTOP],
|
|
implementation: enableDesktop,
|
|
hookNames: {
|
|
testDesktopConnection: true,
|
|
generateOtp: true,
|
|
},
|
|
};
|
|
export default requestEthereumAccounts;
|
|
|
|
/**
|
|
* @typedef {Record<string, Function>} EthAccountsOptions
|
|
* @property {Function} getAccounts - Gets the accounts for the requesting
|
|
* origin.
|
|
*/
|
|
|
|
/**
|
|
*
|
|
* @param {import('json-rpc-engine').JsonRpcRequest<unknown>} _req - The JSON-RPC request object.
|
|
* @param {import('json-rpc-engine').JsonRpcResponse<true>} 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 {EthAccountsOptions} options - The RPC method hooks.
|
|
*/
|
|
async function enableDesktop(
|
|
_req,
|
|
res,
|
|
_next,
|
|
end,
|
|
{ testDesktopConnection, generateOtp },
|
|
) {
|
|
const testResult = await testDesktopConnection();
|
|
const otp = testResult.isConnected ? await generateOtp() : undefined;
|
|
|
|
res.result = { ...testResult, otp };
|
|
return end();
|
|
}
|