2021-02-04 19:15:23 +01:00
|
|
|
import { MESSAGE_TYPE } from '../../../../../shared/constants/app';
|
2020-12-02 17:49:49 +01:00
|
|
|
|
|
|
|
const watchAsset = {
|
|
|
|
methodNames: [MESSAGE_TYPE.WATCH_ASSET, MESSAGE_TYPE.WATCH_ASSET_LEGACY],
|
|
|
|
implementation: watchAssetHandler,
|
2021-11-16 00:11:51 +01:00
|
|
|
hookNames: {
|
|
|
|
handleWatchAssetRequest: true,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
export default watchAsset;
|
2020-12-02 17:49:49 +01:00
|
|
|
|
|
|
|
/**
|
2022-07-27 15:28:05 +02:00
|
|
|
* @typedef {object} WatchAssetOptions
|
2020-12-02 17:49:49 +01:00
|
|
|
* @property {Function} handleWatchAssetRequest - The wallet_watchAsset method implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2022-07-27 15:28:05 +02:00
|
|
|
* @typedef {object} WatchAssetParam
|
2020-12-02 17:49:49 +01:00
|
|
|
* @property {string} type - The type of the asset to watch.
|
2022-07-27 15:28:05 +02:00
|
|
|
* @property {object} options - Watch options for the asset.
|
2020-12-02 17:49:49 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 {
|
2021-09-10 19:37:19 +02:00
|
|
|
const { options: asset, type } = req.params;
|
2023-06-05 22:13:22 +02:00
|
|
|
await handleWatchAssetRequest(asset, type);
|
2022-04-27 16:47:10 +02:00
|
|
|
res.result = true;
|
2021-02-04 19:15:23 +01:00
|
|
|
return end();
|
2020-12-02 17:49:49 +01:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return end(error);
|
2020-12-02 17:49:49 +01:00
|
|
|
}
|
|
|
|
}
|