axios#AxiosStatic TypeScript Examples

The following examples show how to use axios#AxiosStatic. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: get.agent.logs.ts    From forta-bot-sdk with MIT License 6 votes vote down vote up
export function provideGetAgentLogs(
  axios: AxiosStatic,
  fortaApiUrl: string,
): GetAgentLogs {
  assertExists(axios, 'axios')
  assertIsNonEmptyString(fortaApiUrl, 'fortaApiUrl')

  return async function getAgentLogs(agentId: string, minute?: Date) {
    const { data } = await axios.get(`${fortaApiUrl}/logs/agents/${agentId}`, {
      headers: {
        "accept": "application/json",
      },
      params: {
        ...(minute ? {minute: minute.toISOString()} : {})
      }
    });

    if (data?.error) throw new Error(data.error.message);

    return data;
  }
}
Example #2
Source File: conduit.test.tsx    From ts-redux-react-realworld-example-app with MIT License 5 votes vote down vote up
mockedAxios = axios as jest.Mocked<AxiosStatic>
Example #3
Source File: axios.ts    From che-dashboard-next with Eclipse Public License 2.0 5 votes vote down vote up
mockAxios = jest.genMockFromModule<AxiosStatic>('axios')
Example #4
Source File: ContentDeliveryAPI.ts    From foundation-lib-spa-core with Apache License 2.0 5 votes vote down vote up
private _axiosStatic : AxiosStatic
Example #5
Source File: get.trace.data.ts    From forta-bot-sdk with MIT License 5 votes vote down vote up
export function provideGetTraceData(
  traceRpcUrl: string,
  traceBlockMethod: string,
  traceTransactionMethod: string,
  axios: AxiosStatic,
  cache: Cache
): GetTraceData {
  assertIsNonEmptyString(traceBlockMethod, 'traceBlockMethod')
  assertIsNonEmptyString(traceTransactionMethod, 'traceTransactionMethod')
  assertExists(axios, 'axios')
  assertExists(cache, 'cache')

  return async function getTraceData(blockNumberOrTxHash: number | string) {
    if (!traceRpcUrl?.length) return []

    // check cache first
    const cacheKey = getCacheKey(blockNumberOrTxHash)
    const cachedTraceData = cache.getKey(cacheKey)
    if (cachedTraceData) return cachedTraceData

    // fetch trace data
    const isBlockNumber = typeof blockNumberOrTxHash === 'number'
    try {
      const { data } = await axios.post(traceRpcUrl, {
        method: isBlockNumber ? traceBlockMethod : traceTransactionMethod,
        params: isBlockNumber ? [`0x${blockNumberOrTxHash.toString(16)}`] : [blockNumberOrTxHash],
        jsonrpc: "2.0",
        id: Date.now(),
      }, {
        headers: {
          "Content-Type": "application/json",
      }});

      if (data.error) throw new Error(data.error.message)
      // if block/tx has not yet been detected by tracing node, result can be null
      if (!data.result) throw new Error(`unknown ${isBlockNumber ? 'block' : 'transaction'} ${blockNumberOrTxHash}`)

      cache.setKey(cacheKey, data.result)
      return data.result
    } catch (e) {
      console.log(`error getting trace data: ${e.message}`)
    }
    
    return []
  }
}