Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/new-fee-column #163

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/helpers/fee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Decimal from "decimal.js";

export function generateFeeString(reward: number | Decimal, feeRate: number | Decimal) {
const originalReward = new Decimal(reward).div(new Decimal(feeRate));
return originalReward.minus(new Decimal(reward)).toFixed(2);
}
21 changes: 19 additions & 2 deletions src/parser/github-comment-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getOctokitInstance } from "../octokit";
import program from "./command-line";
import { GithubCommentScore, Module, Result } from "./processor";
import { GITHUB_COMMENT_PAYLOAD_LIMIT } from "../helpers/constants";
import { generateFeeString } from "../helpers/fee";

interface SortedTasks {
issues: { specification: GithubCommentScore | null; comments: GithubCommentScore[] };
Expand Down Expand Up @@ -157,12 +158,19 @@ export class GithubCommentModule implements Module {
count: number,
reward: number | Decimal | undefined
) {
let fee = undefined;
jaykayudo marked this conversation as resolved.
Show resolved Hide resolved
if (result.feeRate) {
if (reward) {
fee = generateFeeString(reward, result.feeRate);
}
}
return `
<tr>
<td>${view}</td>
<td>${contribution}</td>
<td>${count}</td>
<td>${reward || "-"}</td>
<td>${fee ?? "-"}</td>
</tr>`;
}

Expand Down Expand Up @@ -192,7 +200,7 @@ export class GithubCommentModule implements Module {
return content.join("");
}

_createIncentiveRows(sortedTasks: SortedTasks | undefined) {
_createIncentiveRows(sortedTasks: SortedTasks | undefined, feeRate: number | Decimal | undefined = undefined) {
const content: string[] = [];

if (!sortedTasks) {
Expand All @@ -212,6 +220,12 @@ export class GithubCommentModule implements Module {
.replaceAll(">", "&gt;")
.replaceAll("`", "&#96;")
.replace(/([\s\S]{64}).[\s\S]+/, "$1&hellip;");
let fee = undefined;
jaykayudo marked this conversation as resolved.
Show resolved Hide resolved
if (commentScore.score?.reward) {
if (feeRate) {
fee = generateFeeString(commentScore.score.reward, feeRate);
}
}
return `
<tr>
<td>
Expand All @@ -229,6 +243,7 @@ export class GithubCommentModule implements Module {
</td>
<td>${commentScore.score?.relevance ?? "-"}</td>
<td>${commentScore.score?.reward ?? "-"}</td>
<td>${fee ?? "-"}</td>
</tr>`;
}

Expand Down Expand Up @@ -288,6 +303,7 @@ export class GithubCommentModule implements Module {
<th>Contribution</th>
<th>Count</th>
<th>Reward</th>
<th>Fee</th>
</tr>
</thead>
<tbody>
Expand All @@ -304,10 +320,11 @@ export class GithubCommentModule implements Module {
<th>Formatting</th>
<th>Relevance</th>
<th>Reward</th>
<th>Fee</th>
</tr>
</thead>
<tbody>
${this._createIncentiveRows(sortedTasks)}
${this._createIncentiveRows(sortedTasks, result.feeRate)}
</tbody>
</table>`
: ""
Expand Down