mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 18:41:38 +01:00
c3eb272af9
* Use method middleware for watchAsset * Update validation error messages * Make addSuggestedERC20Asset private * Remove redundant check in _handleWatchAssetERC20
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import { MESSAGE_TYPE } from '../../enums'
|
|
|
|
const watchAsset = {
|
|
methodNames: [MESSAGE_TYPE.WATCH_ASSET, MESSAGE_TYPE.WATCH_ASSET_LEGACY],
|
|
implementation: watchAssetHandler,
|
|
}
|
|
export default watchAsset
|
|
|
|
/**
|
|
* @typedef {Object} WatchAssetOptions
|
|
* @property {Function} handleWatchAssetRequest - The wallet_watchAsset method implementation.
|
|
*/
|
|
|
|
/**
|
|
* @typedef {Object} WatchAssetParam
|
|
* @property {string} type - The type of the asset to watch.
|
|
* @property {Object} options - Watch options for the asset.
|
|
*/
|
|
|
|
/**
|
|
* @param {import('json-rpc-engine').JsonRpcRequest<WatchAssetParam>} 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 {WatchAssetOptions} options
|
|
*/
|
|
async function watchAssetHandler(
|
|
req,
|
|
res,
|
|
_next,
|
|
end,
|
|
{ handleWatchAssetRequest },
|
|
) {
|
|
try {
|
|
res.result = await handleWatchAssetRequest(req)
|
|
return end()
|
|
} catch (error) {
|
|
return end(error)
|
|
}
|
|
}
|