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

notify reward email #99

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
90 changes: 24 additions & 66 deletions deployments/mailService/mailService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const axios = require("axios");
const moment = require("moment");
const { dappMailerUrl, givethDevMailList, dappMailerSecret } = process.env;
const sendNotification = require("./notificationCeneterAdapter/notificationCenterAdapter");
const { givethDevMailList } = process.env;

const sendReportEmail = async ({
pool,
Expand All @@ -22,74 +23,31 @@ const sendReportEmail = async ({
* You can see the dapp-mail code here @see{@link https://github.com/Giveth/dapp-mailer/blob/master/src/services/send/send.hooks.js}
*/
const now = moment().format("YYYY-MM-DD HH:m:s");
const data = {
template: "notification",
subject: `Notify reward ${farm} ${now}`,
image: "Giveth-review-banner-email.png",
text: `
<table style='${tableStyle}'>
<tr>
<td style='${tableCellStyle}'>Farm</td>
<td style='${tableCellStyle}'>${farm}</td>
</tr>
<tr>
<td style='${tableCellStyle}'>Network</td>
<td style='${tableCellStyle}'>${network}</td>
</tr>
<tr>
<td style='${tableCellStyle}'>Contract address</td>
<td style='${tableCellStyle}'>${pool}</td>
</tr>
<tr>
<td style='${tableCellStyle}'>Amount</td>
<td style='${tableCellStyle}'>${amount}</td>
</tr>
<tr>
<td style='${tableCellStyle}'>Transaction Hash</td>
<td style='${tableCellStyle}'>${transactionHash}</td>
</tr>
<tr>
<td style='${tableCellStyle}'>Round</td>
<td style='${tableCellStyle}'>${round}</td>
</tr>
<tr>
<td style='${tableCellStyle}'>Script</td>
<td style='${tableCellStyle}'>${script}</td>
</tr>
<tr>
<td style='${tableCellStyle}'>Date</td>
<td style='${tableCellStyle}'>${now}</td>
</tr>
<tr>
<td style='${tableCellStyle}'>message</td>
<td style='${tableCellStyle}'>${message || ""}</td>
</tr>

</table>
`,
// cta: `Manage Trace`,
// ctaRelativeUrl: `/campaigns/${data.campaignId}/milestones/${data.traceId}`,
unsubscribeType: "notifyReward-report",
unsubscribeReason: `You receive this email because you are in Giv power team`,
// message: data.message,
const payload = {
round,
date: now,
amount: amount.toString(),
contractAddress: pool,
farm,
message,
network,
script,
transactionHash,
};

const summaryMessage = `Notify reward report for ${farm}`;
data.title = summaryMessage;
data.secretIntro = summaryMessage;
const data = {
sendEmail: true,
sendSegment: true,
eventName: "Notify reward amount",
metadata: null,
creationTime: Date.now(),
segment: {
payload,
},
};
const promises = givethDevMailList.split(",").map((recipient) => {
return axios.post(
`${dappMailerUrl}/send`,
{
...data,
recipient,
},
{
headers: {
Authorization: dappMailerSecret,
},
},
);
data.segment.payload.email = recipient;
return sendNotification(data);
});
return (await Promise.all(promises)).map((response) => response.data);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const axios = require("axios");

const notificationCenterUsername = process.env.NOTIFICATION_CENTER_USERNAME;
const notificationCenterPassword = process.env.NOTIFICATION_CENTER_PASSWORD;
const notificationCenterBaseUrl = process.env.NOTIFICATION_CENTER_BASE_URL;
const disableNotificationCenter = process.env.DISABLE_NOTIFICATION_CENTER;

function createAuthenticationHeader() {
const str = `${notificationCenterUsername}:${notificationCenterPassword}`;
return `Basic ${Buffer.from(str).toString("base64")}`;
}

async function sendNotification(data) {
try {
if (disableNotificationCenter !== "true") {
await axios.post(
`${notificationCenterBaseUrl}/thirdParty/notifications`,
data,
{
headers: {
Authorization: createAuthenticationHeader(),
},
},
);
}
} catch (e) {
console.error("SendNotification error", {
errorResponse: e?.response?.data,
data,
});
}
}

export default sendNotification;
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,30 @@ const distro = [

const initTime = 1715709600; // Timestamp of first round in seconds: Tuesday, MAY 14, 2024 18:00:00 GMT

let UnipoolTokenDistributor, currentTime, nonce;
async function main() {
console.log("Trying to call notifyRewardAmount...", {
date: new Date().toString(),
});
currentTime = Math.floor(Date.now() / 1000);
const currentTime = Math.floor(Date.now() / 1000);
const [signer, ...addrs] = await ethers.getSigners();
nonce = await signer.getTransactionCount();
UnipoolTokenDistributor = await ethers.getContractFactory(
const nonce = await signer.getTransactionCount();
const UnipoolTokenDistributor = await ethers.getContractFactory(
"UnipoolTokenDistributor",
);
await notifyRewardAmount(pools[0]);
await notifyRewardAmount(
pools[0],
UnipoolTokenDistributor,
nonce,
currentTime,
);
}

async function notifyRewardAmount(pool) {
async function notifyRewardAmount(
pool,
UnipoolTokenDistributor,
nonce,
currentTime,
) {
const unipoolTokenDistributor = await UnipoolTokenDistributor.attach(
pool.address,
);
Expand All @@ -59,7 +68,6 @@ async function notifyRewardAmount(pool) {
const tx = await (
await unipoolTokenDistributor.notifyRewardAmount(amount, { nonce })
).wait();
nonce += 1;
console.log("tx:", tx);
await sendReportEmail({
farm: "Giv power",
Expand Down
Loading