You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
43 lines
1.4 KiB
import { ethErrors } from 'eth-rpc-errors';
|
|
import { MESSAGE_TYPE } from '../../../../../shared/constants/app';
|
|
|
|
/**
|
|
* This internal method is used by our external provider to send metadata about
|
|
* permission subjects so that we can e.g. display a proper name and icon in
|
|
* our UI.
|
|
*/
|
|
|
|
const sendMetadata = {
|
|
methodNames: [MESSAGE_TYPE.SEND_METADATA],
|
|
implementation: sendMetadataHandler,
|
|
hookNames: {
|
|
addSubjectMetadata: true,
|
|
},
|
|
};
|
|
export default sendMetadata;
|
|
|
|
/**
|
|
* @typedef {Record<string, Function>} SendMetadataOptions
|
|
* @property {Function} addSubjectMetadata - A function that records subject
|
|
* metadata, bound to 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 {SendMetadataOptions} options
|
|
*/
|
|
function sendMetadataHandler(req, res, _next, end, { addSubjectMetadata }) {
|
|
const { params } = req;
|
|
if (params && typeof params === 'object' && !Array.isArray(params)) {
|
|
const { icon = null, name = null, ...remainingParams } = params;
|
|
addSubjectMetadata({ ...remainingParams, iconUrl: icon, name });
|
|
} else {
|
|
return end(ethErrors.rpc.invalidParams({ data: params }));
|
|
}
|
|
|
|
res.result = true;
|
|
return end();
|
|
}
|
|
|