UNPKG

@moonwell-fi/moonwell-sdk

Version:

TypeScript Interface for Moonwell

66 lines 3.06 kB
"use strict"; 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 (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __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 axios_1 = __importDefault(require("axios")); const lodash_1 = __importDefault(require("lodash")); const index_js_1 = require("../../common/index.js"); const logger = __importStar(require("../../logger/console.js")); const { isEqual, uniqWith } = lodash_1.default; async function getDiscussions(_client) { const logId = logger.start("getDiscussions", "Starting to get discussions..."); const moonwellProposalsResult = await axios_1.default.get("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 axios_1.default.get("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, 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