UNPKG

@ledgerhq/hw-app-eth

Version:
40 lines 1.53 kB
import axios from "axios"; import { getLoadConfig } from "./loadConfig"; import { log } from "@ledgerhq/logs"; /** * Retrieve the metadatas a given contract address and a method selector */ export const loadInfosForContractMethod = async (contractAddress, selector, chainId, userLoadConfig) => { const { pluginBaseURL, extraPlugins } = getLoadConfig(userLoadConfig); let data = {}; if (pluginBaseURL) { const url = `${pluginBaseURL}/plugins/ethereum.json`; data = await axios .get(`${pluginBaseURL}/plugins/ethereum.json`) .then(r => r.data) .catch(e => { log("error", "could not fetch from " + url + ": " + String(e)); return null; }); } if (extraPlugins) { data = { ...data, ...extraPlugins }; } if (!data) return; const lcSelector = selector.toLowerCase(); const lcContractAddress = contractAddress.toLowerCase(); if (lcContractAddress in data) { const contractSelectors = data[lcContractAddress]; if (lcSelector in contractSelectors) { return { payload: contractSelectors[lcSelector]["serialized_data"], signature: contractSelectors[lcSelector]["signature"], plugin: contractSelectors[lcSelector]["plugin"], erc20OfInterest: contractSelectors[lcSelector]["erc20OfInterest"], abi: contractSelectors["abi"], }; } } }; //# sourceMappingURL=contracts.js.map