Skip to content

Commit

Permalink
Merge pull request #13 from Apillon/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
MoMannn authored Feb 16, 2024
2 parents 00df59f + 441cf6e commit 7bb37a5
Show file tree
Hide file tree
Showing 20 changed files with 294 additions and 81 deletions.
2 changes: 1 addition & 1 deletion backend/build-image.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/i0e4n2k8
docker build -t ment-airdrop:latest .
docker tag ment-airdrop:latest public.ecr.aws/i0e4n2k8/ment-airdrop:latest
# docker push public.ecr.aws/i0e4n2k8/ment-airdrop:latest
docker push public.ecr.aws/i0e4n2k8/ment-airdrop:latest
43 changes: 43 additions & 0 deletions backend/docker-compose.proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
services:
proxy:
image: nginxproxy/nginx-proxy:latest
container_name: nginx-proxy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /app/certs:/etc/nginx/certs:ro
# - /etc/nginx/vhost.d
# - /usr/share/nginx/html
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
environment:
- HTTPS_METHOD=noredirect
networks:
- web

proxy-ssl:
image: nginxproxy/acme-companion
container_name: acme-companion
restart: unless-stopped
volumes_from:
- proxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /app/certs:/etc/nginx/certs:rw
- acme:/etc/acme.sh
environment:
- [email protected]
networks:
- web

volumes:
vhost:
html:
acme:

networks:
web:
name: web
33 changes: 11 additions & 22 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ services:
container_name: airdrop_db
env_file:
- .env.sql.deploy
# environment:
# MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
# MYSQL_DATABASE: ${MYSQL_DATABASE}
ports:
- '3306:3306'
restart: always
volumes:
- mysql-data:/var/lib/mysql
networks:
- db

airdrop_app:
image: public.ecr.aws/i0e4n2k8/ment-airdrop:latest
Expand All @@ -22,26 +21,16 @@ services:
- airdrop_db
env_file:
- .env.deploy
# environment:
# APP_SECRET: ${APP_SECRET}
# APP_URL: ${APP_URL}
# ADMIN_WALLET: ${ADMIN_WALLET}
# APILLON_KEY: ${APILLON_KEY}
# APILLON_SECRET: ${APILLON_SECRET}
# COLLECTION_UUID: ${COLLECTION_UUID}
# SMTP_HOST: ${SMTP_HOST}
# SMTP_PORT: ${SMTP_PORT}
# SMTP_USERNAME: ${SMTP_USERNAME}
# SMTP_PASSWORD: ${SMTP_PASSWORD}
# SMTP_EMAIL_FROM: ${SMTP_EMAIL_FROM}
# SMTP_NAME_FROM: ${SMTP_NAME_FROM}
# API_HOST: ${API_HOST}
# API_PORT: ${API_PORT}
# CAPTCHA_SECRET: ${CAPTCHA_SECRET}
# CLAIM_EXPIRES_IN: ${CLAIM_EXPIRES_IN}
ports:
- '8080:${API_PORT}'
restart: always
networks:
- web
- db

volumes:
mysql-data:

networks:
db:
web:
name: web
external: true
2 changes: 2 additions & 0 deletions backend/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ ADD ./ ${appDir}/

RUN npm install
RUN npm run build
RUN mkdir -p ./dist/templates/mail/
RUN cp ./src/templates/mail/*.html ./dist/templates/mail/

EXPOSE 3000
RUN chmod +x ./bin/docker-start.sh ./bin/create-database.sh
Expand Down
63 changes: 36 additions & 27 deletions backend/src/cron.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { CronJob } from 'cron';
import { AirdropStatus } from './models/user';
import { dateToSqlString } from './lib/sql-utils';
import { SqlModelStatus } from './models/base-sql-model';
import { MysqlConnectionManager } from './lib/mysql-connection-manager';
import { SmtpSendTemplate } from './lib/node-mailer';
import { env } from './config/env';
import { generateEmailAirdropToken } from './lib/jwt';
import { LogType, writeLog } from './lib/logger';
import { CronJob } from "cron";
import { AirdropStatus } from "./models/user";
import { dateToSqlString } from "./lib/sql-utils";
import { SqlModelStatus } from "./models/base-sql-model";
import { MysqlConnectionManager } from "./lib/mysql-connection-manager";
import { SmtpSendTemplate } from "./lib/node-mailer";
import { env } from "./config/env";
import { generateEmailAirdropToken } from "./lib/jwt";
import { LogType, writeLog } from "./lib/logger";

export class Cron {
private cronJobs: CronJob[] = [];

constructor() {
this.cronJobs.push(new CronJob('* * * * *', this.sendEmail, null, false));
this.cronJobs.push(new CronJob("* * * * *", this.sendEmail, null, false));
if (env.MAX_SUPPLY > 0) {
this.cronJobs.push(new CronJob('* * * * *', this.processExpiredClaims, null, false));
this.cronJobs.push(
new CronJob("* * * * *", this.processExpiredClaims, null, false)
);
}
}

Expand Down Expand Up @@ -73,10 +75,16 @@ export class Cron {
try {
if (!env.MAX_SUPPLY || i < availableNftLeft) {
const token = await generateEmailAirdropToken(users[i].email);
await SmtpSendTemplate([users[i].email], 'Claim your NFT', 'en-airdrop-claim', {
appUrl: env.APP_URL,
link: `${env.APP_URL}/claim?token=${token}`,
});
await SmtpSendTemplate(
[users[i].email],
"Claim your NFT",
"en-airdrop-claim",
{
appUrl: env.APP_URL,
link: `${env.APP_URL}/claim?token=${token}`,
claimExpiresIn: env.CLAIM_EXPIRES_IN,
}
);
updates.push(
`(${users[i].id}, '${users[i].email}', ${
AirdropStatus.EMAIL_SENT
Expand All @@ -86,8 +94,8 @@ export class Cron {
//Currently, waiting line for airdrop is full.Send info email and set appropriate status
await SmtpSendTemplate(
[users[i].email],
'You are in waiting line for NFT claim',
'en-airdrop-waiting-line',
"You are in waiting line for NFT claim",
"en-airdrop-waiting-line",
{
appUrl: env.APP_URL,
}
Expand All @@ -99,19 +107,19 @@ export class Cron {
);
}
} catch (e) {
writeLog(LogType.ERROR, e, 'cron.ts', 'sendEmail');
writeLog(LogType.ERROR, e, "cron.ts", "sendEmail");
updates.push(
`(${users[i].id}, '${users[i].email}', ${AirdropStatus.EMAIL_ERROR}, '${dateToSqlString(
new Date()
)}')`
`(${users[i].id}, '${users[i].email}', ${
AirdropStatus.EMAIL_ERROR
}, '${dateToSqlString(new Date())}')`
);
}
}

if (updates.length > 0) {
const sql = `
INSERT INTO user (id, email, airdrop_status, email_sent_time)
VALUES ${updates.join(',')}
VALUES ${updates.join(",")}
ON DUPLICATE KEY UPDATE
airdrop_status = VALUES(airdrop_status),
email_sent_time = VALUES(email_sent_time)`;
Expand All @@ -121,7 +129,7 @@ export class Cron {

await mysql.commit(conn);
} catch (e) {
writeLog(LogType.ERROR, e, 'cron.ts', 'sendEmail');
writeLog(LogType.ERROR, e, "cron.ts", "sendEmail");
await mysql.rollback(conn);
}
}
Expand All @@ -143,14 +151,14 @@ export class Cron {
null,
conn
)
).map(x => x.id);
).map((x) => x.id);

if (usersWithExpiredClaim.length) {
//Update those users to claim expired
await mysql.paramExecute(
`UPDATE user
SET airdrop_status = ${AirdropStatus.AIRDROP_CLAIM_EXPIRED}
WHERE id IN (${usersWithExpiredClaim.join(',')})
WHERE id IN (${usersWithExpiredClaim.join(",")})
;
`,
null,
Expand All @@ -163,6 +171,7 @@ export class Cron {
`SELECT * FROM user WHERE
airdrop_status = ${AirdropStatus.IN_WAITING_LINE}
AND status = ${SqlModelStatus.ACTIVE}
ORDER BY createTime ASC
LIMIT ${usersWithExpiredClaim.length}
FOR UPDATE
;
Expand All @@ -176,7 +185,7 @@ export class Cron {
await mysql.paramExecute(
`UPDATE user
SET airdrop_status = ${AirdropStatus.PENDING}
WHERE id IN (${usersInWaitingLine.map(x => x.id).join(',')})
WHERE id IN (${usersInWaitingLine.map((x) => x.id).join(",")})
;
`,
null,
Expand All @@ -187,7 +196,7 @@ export class Cron {

await mysql.commit(conn);
} catch (e) {
writeLog(LogType.ERROR, e, 'cron.ts', 'processExpiredClaims');
writeLog(LogType.ERROR, e, "cron.ts", "processExpiredClaims");
await mysql.rollback(conn);
}
}
Expand Down
36 changes: 24 additions & 12 deletions backend/src/templates/mail/en-airdrop-claim.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
height: 25px;
}

.logo {
width: 275px;
height: 81px;
}

a {
color: rgb(228, 178, 0);
}
Expand All @@ -67,10 +72,10 @@

.button {
border-style: solid;
border-color: #78dce8;
border-color: rgb(228, 178, 0);
border-width: 16px 40px 16px 40px;
display: inline-block;
background: #78dce8;
background: rgb(228, 178, 0);
font-size: 16px;
font-weight: 700;
font-family: 'IBM Plex Mono','arial','helvetica neue','helvetica','sans-serif';
Expand All @@ -94,7 +99,14 @@
<table class="main-content" align="center">
<tr>
<td align="left">
<img src="cid:logo.png" />
<a href="https://www.ment.si/">
<img
class="logo"
src="{{appUrl}}/images/logo/MENT_Logo-01.png"
title="MENT"
alt="MENT"
/>
</a>
</td>
</tr>
<tr>
Expand All @@ -104,26 +116,26 @@ <h1>Congrats!</h1>
</tr>
<tr>
<td>
<p><strong> Your MENT token has been reserved, you now have 72 hours to claim it.</strong></p>
<p><strong> Your MENT token has been reserved, you now have {{claimExpiresIn}} hours to claim it.</strong></p>
<br /><br />
<p>To fully own your value-packed MENT token, these are the steps to go through:</p>
<ol>
<li>Install a <strong>digital wallet</strong> - either as a mobile app or a desktop browser extension. The platform supports connectivity with:
<li><p>Install a <strong>digital wallet</strong> - either as a mobile app or a desktop browser extension. The platform supports connectivity with:</p>
<ul>
<li>MetaMask (<a href="https://support.metamask.io/hc/en-us/articles/360015489531-Getting-started-with-MetaMask">tutorials</a>)</li>
<li>Coinbase Wallet (<a href="https://www.coinbase.com/en-gb/wallet/tutorials">tutorials</a>)</li>
<li>WalletConnec (<a href="https://www.youtube.com/watch?v=63eiQD7AUwY">tutorials</a>)</li>
<li><p>MetaMask (<a href="https://support.metamask.io/hc/en-us/articles/360015489531-Getting-started-with-MetaMask">tutorials</a>)</p></li>
<li><p>Coinbase Wallet (<a href="https://www.coinbase.com/en-gb/wallet/tutorials">tutorials</a>)</p></li>
<li><p>WalletConnect (<a href="https://www.youtube.com/watch?v=63eiQD7AUwY">tutorials</a>)</p></li>
</ul>
</li>
<li>Proceed to <strong>the NFT platform</strong> (through the button below). The instructions will follow as you go.</li>
<li>Successfully connect your wallet and <strong>claim your MENT token.</strong></li>
<li>Own, admire and brag about your newly acquired collectibles.</li>
<li><p>Proceed to <strong>the NFT platform</strong> (through the button below). The instructions will follow as you go.</p></li>
<li><p>Successfully connect your wallet and <strong>claim your MENT token.</strong></p></li>
<li><p>Own, admire and brag about your newly acquired collectibles.</p></li>
</ol>
<p>
<a href="{{link}}" class="button">Claim MENT token</a>
</p>
<br /><br />
<p>If you need additional assistance, or you received this email in error, please contact <a>mail</a></p>
<p>If you need additional assistance, or you received this email in error, please contact <a href="mailto:[email protected]">[email protected]</a></p>
<br /><br />
<p>Best, <br />The MENT team</p>
<br /><br />
Expand Down
18 changes: 15 additions & 3 deletions backend/src/templates/mail/en-airdrop-waiting-line.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
height: 25px;
}

.logo {
width: 275px;
height: 81px;
}

a {
color: rgb(228, 178, 0);
}
Expand Down Expand Up @@ -74,7 +79,14 @@
<table class="main-content" align="center">
<tr>
<td align="left">
<img src="cid:logo.png" />
<a href="https://www.ment.si/">
<img
class="logo"
src="{{appUrl}}/images/logo/MENT_Logo-01.png"
title="MENT"
alt="MENT"
/>
</a>
</td>
</tr>
<tr>
Expand All @@ -84,9 +96,9 @@ <h1>Unfortunately, all the NFT-claim spots have been filled.</h1>
</tr>
<tr>
<td>
<p>You will be placed on a MENT token waitlist - in case someone before you doesn’t claim their token, you’ll be next in line! </p>
<p>You will be placed on a <strong>MENT token waitlist</strong> - in case someone before you doesn’t claim their token, you’ll be next in line! </p>
<p>If that happens, we will notify you via email and you’ll get the necessary information to proceed.</p>
<p>Should you need additional assistance, or you received this email in error, please contact <a>email</a></p>
<p>Should you need additional assistance, or you received this email in error, please contact <a href="mailto:[email protected]">[email protected]</a>.</p>
<br /><br />
<p>Best, <br />The MENT team</p>
<br /><br />
Expand Down
Loading

0 comments on commit 7bb37a5

Please sign in to comment.