Skip to content

Commit

Permalink
Merge pull request #238 from layerx-labs/dev
Browse files Browse the repository at this point in the history
BEPRO 2.31
  • Loading branch information
ickas authored Aug 26, 2024
2 parents 36c1d9b + d9ec005 commit 1e88c77
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 95 deletions.
3 changes: 2 additions & 1 deletion src/actions/get-proposal-created-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export async function action(block: DecodedLog<BountyProposalCreatedEvent['retur
bountyId: dbBounty.id, bountyContractId: dbBounty.contractId,
deliverableId: dbDeliverable.id, deliverableContractId: dbDeliverable.prContractId,
proposalId: createProposal.id, proposalContractId: createProposal.contractId,
actor: proposal.creator
actor: proposal.creator,
title: dbBounty.title,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/actions/get-pullrequest-created-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function action(block: DecodedLog<BountyPullRequestCreatedEvent['re
bountyId: dbBounty.id, bountyContractId: dbBounty.contractId,
deliverableId: dbDeliverable.id, deliverableContractId: pullRequestId,
actor: pullRequest.creator,
title: dbBounty.title,
title: dbDeliverable.title,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/actions/get-pullrequest-ready-for-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
bountyId: dbBounty.id, bountyContractId: dbBounty.contractId,
deliverableId: dbDeliverable.id, deliverableContractId: pullRequestId,
actor: pullRequest.creator,
title: dbDeliverable.title,
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Deliverable <a href="{{deliverable.link}}">#{{deliverable.id}}</a> created for task #{{task.id}}
</span>
{{#if task.title}}
<span class="sm-regular mb-3 text-white-50">
<span class="sm-regular mb-3 text-white-50 capitalize-first">
{{task.title}}
</span>
{{/if}}
<div class="d-flex gap-2 text-white-50">
<span class="sm-regular">{{task.network}}</span>
<span class="sm-regular capitalize-first">{{task.network}}</span>
<span>•</span>
<span class="sm-regular">%DATE%</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Deliverable <a href="{{deliverable.link}}">#{{deliverable.id}}</a> marked as ready for review
</span>
{{#if deliverable.title}}
<span class="sm-regular mb-3 text-white-50">
<span class="sm-regular mb-3 text-white- capitalize-first">
{{deliverable.title}}
</span>
{{/if}}
<div class="d-flex gap-2 text-white-50">
<span class="sm-regular">{{task.network}}</span>
<span class="sm-regular capitalize-first">{{task.network}}</span>
<span>•</span>
<span class="sm-regular">%DATE%</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Proposal <a href="{{proposal.link}}">#{{proposal.id}}</a> was disputed with {{proposal.disputes}} votes
</span>
{{#if deliverable.title}}
<span class="sm-regular mb-3 text-white-50">
<span class="sm-regular mb-3 text-white-50 capitalize-first">
{{deliverable.title}}
</span>
{{/if}}
<div class="d-flex gap-2 text-white-50">
<span class="sm-regular">{{task.network}}</span>
<span class="sm-regular capitalize-first">{{task.network}}</span>
<span>•</span>
<span class="sm-regular">%DATE%</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Proposal <a href="{{proposal.link}}">#{{proposal.id}}</a> created for deliverable #{{deliverable.id}}
</span>
{{#if deliverable.title}}
<span class="sm-regular mb-3 text-white-50">
<span class="sm-regular mb-3 text-white-50 capitalize-first">
{{deliverable.title}}
</span>
{{/if}}
<div class="d-flex gap-2 text-white-50">
<span class="sm-regular">{{task.network}}</span>
<span class="sm-regular capitalize-first">{{task.network}}</span>
<span>•</span>
<span class="sm-regular">%DATE%</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Task <a href="{{task.link}}">#{{task.id}}</a> closed
</span>
{{#if task.title}}
<span class="sm-regular mb-3 text-white-50">
<span class="sm-regular mb-3 text-white-50 capitalize-first">
{{task.title}}
</span>
{{/if}}
<div class="d-flex gap-2 text-white-50">
<span class="sm-regular">{{task.network}}</span>
<span class="sm-regular capitalize-first">{{task.network}}</span>
<span>•</span>
<span class="sm-regular">%DATE%</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Task <a href="{{task.link}}">#{{task.id}}</a> created
</span>
{{#if task.title}}
<span class="sm-regular mb-3 text-white-50">
<span class="sm-regular mb-3 text-white-50 capitalize-first">
{{task.title}}
</span>
{{/if}}
<div class="d-flex gap-2 text-white-50">
<span class="sm-regular">{{task.network}}</span>
<span class="sm-regular capitalize-first">{{task.network}}</span>
<span>•</span>
<span class="sm-regular">%DATE%</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Funding <a href="{{task.link}}">#{{task.id}}</a> created
</span>
{{#if task.title}}
<span class="sm-regular mb-3 text-white-50">
<span class="sm-regular mb-3 text-white-50 capitalize-first">
{{task.title}}
</span>
{{/if}}
<div class="d-flex gap-2 text-white-50">
<span class="sm-regular">{{task.network}}</span>
<span class="sm-regular capitalize-first">{{task.network}}</span>
<span>•</span>
<span class="sm-regular">%DATE%</span>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/integrations/notifications/templates/notif-template.hbs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{{> avatar}}
<div id="link">{{notification.link}}</div>
<div class="d-flex flex-column ms-3">
<span class="xs-medium notification-title text-white mb-3">
<span class="xs-medium notification-title text-white mb-3 capitalize-first">
{{notification.title}}
</span>
{{#if notification.subTitle}}
<span class="sm-regular mb-3 text-white-50">
<span class="sm-regular mb-3 text-white-50 capitalize-first">
{{notification.subTitle}}
</span>
{{/if}}
<div class="d-flex gap-2 text-white-50">
<span class="sm-regular">{{notification.network}}</span>
<span class="sm-regular capitalize-first">{{notification.network}}</span>
<span>•</span>
<span class="sm-regular">%DATE%</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {EmailService} from "../email-service/email-service";
import {Templates} from "./templates";
import {EmailNotificationSubjects} from "./templates/email-info";
import {getEmailNotificationSubject} from "./templates/email-info";
import {EmailTemplate} from "../../../services/templating/email-template";
import {users} from "../../../db/models/users";
import {v4 as uuidv4} from "uuid";
import {format} from "node:util"
import {getEventTargets} from "../../../utils/get-event-targets";
import { CollectEventPayloadParams } from "src/services/analytics/types/analytics";
import { AnalyticEventName } from "src/services/analytics/types/events";
Expand All @@ -26,7 +25,7 @@ export class EmailNotification {
for (const [index, to] of recipients.filter(e => e).entries()) {
const uuid = uuidv4();
await EmailService.sendEmail(
format(EmailNotificationSubjects[this.type]!, (this.payload as any)?.network?.name ?? "BEPRO"),
getEmailNotificationSubject(this.type, this.payload),
[to],
new EmailTemplate().compile({...this.payload, type: this.type, template: templateName, uuid})
);
Expand Down
7 changes: 3 additions & 4 deletions src/integrations/send-grid/notifications/templater.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {readFileSync} from "node:fs";
import {join, resolve} from "node:path";
import process from "process";
import {EmailNotificationSubjects} from "./templates/email-info";
import {format} from "node:util";
import {getEmailNotificationBodyTitle, getEmailNotificationSubject} from "./templates/email-info";

export class Templater {

Expand All @@ -22,8 +21,8 @@ export class Templater {
compile(payload: any) {

const templateData = {
pageTitle: format(EmailNotificationSubjects[payload.template], payload.network.name),
notificationTitleHeading: format(EmailNotificationSubjects[payload.template], payload.network.name),
pageTitle: getEmailNotificationSubject(payload.type, payload),
notificationTitleHeading: getEmailNotificationBodyTitle(payload.type, payload),
taskTitleParagraph: payload.title,
actionHref: `https://app.bepro.network/${payload.network.name}/task/${payload.bountyId}/?fromEmail=${payload.uuid}`
};
Expand Down
51 changes: 44 additions & 7 deletions src/integrations/send-grid/notifications/templates/email-info.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
import {Templates} from "./index";
import { format } from "node:util";
import { CollectEventPayloadParams } from "src/services/analytics/types/analytics";
import { AnalyticEventName } from "src/services/analytics/types/events";
import { Templates } from "./index";

export const EmailNotificationSubjects: { [k in keyof typeof Templates]: string } = {
BOUNTY_CREATED: "%s @ BEPRO | A task has been created!",
BOUNTY_CLOSED: "%s @ BEPRO | A task has been closed!",
FUNDING_REQUEST_CREATED: "%s @ BEPRO | A funding request has been created!",
PULL_REQUEST_OPEN: `%s @ BEPRO | A new deliverable has been created on "%s"!`,
PULL_REQUEST_READY: `%s @ BEPRO | A deliverable has been marked as ready for review on "%s"!`,
MERGE_PROPOSAL_OPEN: `%s @ BEPRO | A new proposal was created on "%s"!`,
MERGE_PROPOSAL_READY: `%s @ BEPRO | A deliverable is ready to be accepted on "%s"!`,
}

export const EmailNotificationBodyTitles: { [k in keyof typeof Templates]: string } = {
BOUNTY_CREATED: "A task has been created on %s!",
BOUNTY_CLOSED: "A task has bee closed!",
FUNDING_REQUEST_CREATED: "New funding request has been created on %s!",
PULL_REQUEST_OPEN: "A new deliverable has been created!",
PULL_REQUEST_READY: "A deliverable has been marked as \"ready for review\"!",
MERGE_PROPOSAL_OPEN: "A new proposal was created!",
MERGE_PROPOSAL_READY: "A deliverable is ready to be accepted!",
BOUNTY_CLOSED: "A task has been closed on %s!",
FUNDING_REQUEST_CREATED: "A funding request has been created on %s!",
PULL_REQUEST_OPEN: `A new deliverable has been created on "%s"!`,
PULL_REQUEST_READY: `A deliverable has been marked as ready for review on "%s"!`,
MERGE_PROPOSAL_OPEN: `A new proposal was created on "%s"!`,
MERGE_PROPOSAL_READY: `A deliverable is ready to be accepted on "%s"!`,
}

export function getEmailNotificationSubject(type: AnalyticEventName, payload: CollectEventPayloadParams) {
const marketplace = payload.network.name?.toUpperCase();
switch(type) {
case "BOUNTY_CREATED":
case "BOUNTY_CLOSED":
case "FUNDING_REQUEST_CREATED":
return format(EmailNotificationSubjects[type], marketplace);
default:
return format(EmailNotificationSubjects[type], marketplace, payload.title);
}
}

export function getEmailNotificationBodyTitle(type: AnalyticEventName, payload: CollectEventPayloadParams) {
const marketplace = payload.network.name?.toUpperCase();
switch(type) {
case "BOUNTY_CREATED":
case "BOUNTY_CLOSED":
case "FUNDING_REQUEST_CREATED":
return format(EmailNotificationBodyTitles[type], marketplace);
default:
return format(EmailNotificationBodyTitles[type], payload.title);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,40 @@
{{> styles}}
</head>
<body id="body">
<table id="container" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
{{> logo}}
<h1>{{notificationTitleHeading}}</h1>
<table id="action-card" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<p>{{taskTitleParagraph}}</p>
<a id="action-button" href="{{actionHref}}">View task</a>
</td>
</tr>
</table>
<div id="notification-manage">Manage your BEPRO notifications</div>
<table id="links" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<a href="https://app.bepro.network" class="link-item">App</a>
<a href="https://bepro.network" class="link-item">Website</a>
<a href="https://discord.gg/layerx" class="link-item">Discord</a>
<a href="https://twitter.com/bepronet" class="link-item">Twitter</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<div class="main">
<table id="container" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
{{> logo}}
<h1>{{notificationTitleHeading}}</h1>
<table id="action-card" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<p>{{taskTitleParagraph}}</p>
<a id="action-button" href="{{actionHref}}">View task</a>
</td>
</tr>
</table>

<table id="links" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<a href="https://app.bepro.network/dashboard" id="manage-link">Manage your Bepro Notifications</a>
</td>
</tr>

<tr>
<td>
<a href="https://app.bepro.network" class="link-item">App</a>
<a href="https://bepro.network" class="link-item">Website</a>
<a href="https://discord.gg/layerx" class="link-item">Discord</a>
<a href="https://twitter.com/bepronet" class="link-item">Twitter</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<img src="https://app.bepro.network/images/bepro-icon.png" alt="Bepro Logo" height="40" width="40"/>
<img src="https://app.bepro.network/images/Bepro_Logo_Light.svg" alt="Bepro Logo" height="24" width="90"/>
Loading

0 comments on commit 1e88c77

Please sign in to comment.