import https from "../utils/https";
import {ContentType, Method} from "axios-mapper";

var data: any = null;

export async function getTokenData(coinType: any) {
  if (!data) {
    try {
      const res: any = await (await https(true)).request('/admin/token/get', Method.GET, undefined, ContentType.json);

      data = JSON.parse(res.data.data);
    } catch (e) {
      data = {
        eth: [],
        tron: [],
      };
    }
  }
  return data[coinType];
}

export async function saveTokenData() {
  return (await https(true, true)).request('/admin/token/set', Method.POST, {
    data: JSON.stringify(data),
  }, ContentType.json);

}
