@moonwell-fi/moonwell-sdk
Version:
TypeScript Interface for Moonwell
76 lines • 3.46 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDiscussions = getDiscussions;
const lodash_1 = __importDefault(require("lodash"));
const index_js_1 = require("../../common/index.js");
const logger = __importStar(require("../../logger/console.js"));
const axiosWithRetry_js_1 = require("../axiosWithRetry.js");
const { isEqual, uniqWith } = lodash_1.default;
async function getDiscussions(_client) {
const logId = logger.start("getDiscussions", "Starting to get discussions...");
const moonwellProposalsResult = await (0, axiosWithRetry_js_1.getWithRetry)("https://forum.moonwell.fi/c/proposals/moonwell-improvement-proposals/9/l/latest.json");
if (moonwellProposalsResult.status !== 200 || !moonwellProposalsResult.data) {
throw new index_js_1.HttpRequestError(moonwellProposalsResult.statusText);
}
const communityProposalsResult = await (0, axiosWithRetry_js_1.getWithRetry)("https://forum.moonwell.fi/c/proposals/community-proposal/19/l/latest.json");
if (communityProposalsResult.status !== 200 ||
!communityProposalsResult.data) {
throw new index_js_1.HttpRequestError(communityProposalsResult.statusText);
}
logger.end(logId);
const toType = (item) => {
return item.topic_list.topics.map((topic) => {
const result = {
title: topic.title,
views: topic.views,
replies: topic.posts_count - 1,
createdAt: new Date(topic.created_at).getTime(),
tags: topic.tags.map((tag) => tag.name),
link: `https://forum.moonwell.fi/t/${topic.id}`,
};
return result;
});
};
const topics = [
...toType(moonwellProposalsResult.data),
...toType(communityProposalsResult.data),
];
return uniqWith(topics, isEqual).sort((a, b) => b.createdAt - a.createdAt);
}
//# sourceMappingURL=getDiscussions.js.map