Skip to content

Commit

Permalink
feat: use permitBaseUrl instead of hardcoded
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Sep 24, 2023
1 parent e344906 commit 2df5613
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/handlers/comment/handlers/payout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getBotContext, getLogger } from "../../../bindings";
import { getBotConfig, getBotContext, getLogger } from "../../../bindings";
import { Payload } from "../../../types";
import { IssueCommentCommands } from "../commands";
import {
Expand All @@ -14,6 +14,9 @@ import { GLOBAL_STRINGS } from "../../../configs";

export const payout = async (body: string) => {
const { payload: _payload } = getBotContext();
const {
payout: { permitBaseUrl },
} = getBotConfig();
const logger = getLogger();
if (body != IssueCommentCommands.PAYOUT && body.replace(/`/g, "") != IssueCommentCommands.PAYOUT) {
logger.info(`Skipping to payout. body: ${body}`);
Expand All @@ -39,7 +42,7 @@ export const payout = async (body: string) => {
return `Permit generation failed due to internal GitHub Error`;
}

const hasPosted = IssueComments.find((e) => e.user.type === "Bot" && e.body.includes("https://pay.ubq.fi?claim"));
const hasPosted = IssueComments.find((e) => e.user.type === "Bot" && e.body.includes(permitBaseUrl));
if (hasPosted) {
logger.info(`Permit already generated for ${payload.issue?.number}`);
return;
Expand Down
17 changes: 13 additions & 4 deletions src/handlers/payout/post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getWalletAddress } from "../../adapters/supabase";
import { getBotContext, getLogger } from "../../bindings";
import { getBotConfig, getBotContext, getLogger } from "../../bindings";
import { getAllIssueComments, getAllPullRequestReviews, getIssueDescription, parseComments } from "../../helpers";
import { getLatestPullRequest, gitLinkedPrParser } from "../../helpers/parser";
import { Incentives, MarkdownItem, Payload, UserType } from "../../types";
Expand Down Expand Up @@ -29,11 +29,14 @@ export const calculateIssueConversationReward = async (calculateIncentives: Ince
const logger = getLogger();

const context = getBotContext();
const {
payout: { permitBaseUrl },
} = getBotConfig();
const payload = context.payload as Payload;
const issue = payload.issue;

const permitComments = calculateIncentives.comments.filter(
(content) => content.body.includes(title) && content.body.includes("https://pay.ubq.fi?claim=") && content.user.type == UserType.Bot
(content) => content.body.includes(title) && content.body.includes(permitBaseUrl) && content.user.type == UserType.Bot
);
if (permitComments.length > 0) {
logger.info(`incentivizeComments: skip to generate a permit url because it has been already posted`);
Expand Down Expand Up @@ -105,6 +108,9 @@ export const calculateIssueConversationReward = async (calculateIncentives: Ince
export const calculateIssueCreatorReward = async (incentivesCalculation: IncentivesCalculationResult): Promise<RewardsResponse> => {
const title = `Task Creator`;
const logger = getLogger();
const {
payout: { permitBaseUrl },
} = getBotConfig();

const issueDetailed = bountyInfo(incentivesCalculation.issue);
if (!issueDetailed.isBounty) {
Expand All @@ -114,7 +120,7 @@ export const calculateIssueCreatorReward = async (incentivesCalculation: Incenti

const comments = await getAllIssueComments(incentivesCalculation.issue.number);
const permitComments = comments.filter(
(content) => content.body.includes(title) && content.body.includes("https://pay.ubq.fi?claim=") && content.user.type == UserType.Bot
(content) => content.body.includes(title) && content.body.includes(permitBaseUrl) && content.user.type == UserType.Bot
);
if (permitComments.length > 0) {
logger.info(`incentivizeCreatorComment: skip to generate a permit url because it has been already posted`);
Expand Down Expand Up @@ -172,6 +178,9 @@ export const calculateIssueCreatorReward = async (incentivesCalculation: Incenti
export const calculatePullRequestReviewsReward = async (incentivesCalculation: IncentivesCalculationResult): Promise<RewardsResponse> => {
const logger = getLogger();
const context = getBotContext();
const {
payout: { permitBaseUrl },
} = getBotConfig();
const title = "Reviewer";

const linkedPullRequest = await gitLinkedPrParser({
Expand All @@ -189,7 +198,7 @@ export const calculatePullRequestReviewsReward = async (incentivesCalculation: I

const comments = await getAllIssueComments(incentivesCalculation.issue.number);
const permitComments = comments.filter(
(content) => content.body.includes(title) && content.body.includes("https://pay.ubq.fi?claim=") && content.user.type == UserType.Bot
(content) => content.body.includes(title) && content.body.includes(permitBaseUrl) && content.user.type == UserType.Bot
);
if (permitComments.length > 0) {
logger.info(`calculatePullRequestReviewsReward: skip to generate a permit url because it has been already posted`);
Expand Down

0 comments on commit 2df5613

Please sign in to comment.