Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
xavier506 committed Oct 31, 2021
2 parents ee389c1 + d152111 commit 1710c85
Show file tree
Hide file tree
Showing 21 changed files with 825 additions and 711 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ HAPI_NETWORK_CHAIN_ID=71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abea
HAPI_NETWORK_WALLET=http://wallet:9999
HAPI_HASURA_URL=http://hasura:8080/v1/graphql
HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_MAIL_HOST=host
HAPI_MAIL_PORT=port
HAPI_MAIL_USER=user
HAPI_MAIL_PASSWORD=password
HAPI_AFFILIATE_ACCOUNT=affiliate
HAPI_AFFILIATE_PASSWORD=PW...
HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL=3600
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/push-dev-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ jobs:
HAPI_NETWORK_WALLET: ${{ secrets.HAPI_NETWORK_WALLET }}
HAPI_HASURA_URL: ${{ secrets.HAPI_HASURA_URL }}
HAPI_HASURA_ADMIN_SECRET: ${{ secrets.HAPI_HASURA_ADMIN_SECRET }}
HAPI_MAIL_HOST: ${{ secrets.HAPI_MAIL_HOST }}
HAPI_MAIL_PORT: ${{ secrets.HAPI_MAIL_PORT }}
HAPI_MAIL_USER: ${{ secrets.HAPI_MAIL_USER }}
HAPI_MAIL_PASSWORD: ${{ secrets.HAPI_MAIL_PASSWORD }}
HAPI_AFFILIATE_ACCOUNT: ${{ secrets.HAPI_AFFILIATE_ACCOUNT }}
HAPI_AFFILIATE_PASSWORD: ${{ secrets.HAPI_AFFILIATE_PASSWORD }}
HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL: 3600
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/push-prod-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ jobs:
HAPI_NETWORK_WALLET: ${{ secrets.HAPI_NETWORK_WALLET }}
HAPI_HASURA_URL: ${{ secrets.HAPI_HASURA_URL }}
HAPI_HASURA_ADMIN_SECRET: ${{ secrets.HAPI_HASURA_ADMIN_SECRET }}
HAPI_MAIL_HOST: ${{ secrets.HAPI_MAIL_HOST }}
HAPI_MAIL_PORT: ${{ secrets.HAPI_MAIL_PORT }}
HAPI_MAIL_USER: ${{ secrets.HAPI_MAIL_USER }}
HAPI_MAIL_PASSWORD: ${{ secrets.HAPI_MAIL_PASSWORD }}
HAPI_AFFILIATE_ACCOUNT: ${{ secrets.HAPI_AFFILIATE_ACCOUNT }}
HAPI_AFFILIATE_PASSWORD: ${{ secrets.HAPI_AFFILIATE_PASSWORD }}
HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL: 3600
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ services:
HAPI_NETWORK_WALLET: '${HAPI_NETWORK_WALLET}'
HAPI_HASURA_URL: '${HAPI_HASURA_URL}'
HAPI_HASURA_ADMIN_SECRET: '${HAPI_HASURA_ADMIN_SECRET}'
HAPI_MAIL_HOST: '${HAPI_MAIL_HOST}'
HAPI_MAIL_PORT: '${HAPI_MAIL_PORT}'
HAPI_MAIL_USER: '${HAPI_MAIL_USER}'
HAPI_MAIL_PASSWORD: '${HAPI_MAIL_PASSWORD}'
HAPI_AFFILIATE_ACCOUNT: '${HAPI_AFFILIATE_ACCOUNT}'
HAPI_AFFILIATE_PASSWORD: '${HAPI_AFFILIATE_PASSWORD}'
HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL: '${HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL}'
Expand Down
3 changes: 2 additions & 1 deletion hapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"http-status-codes": "^1.4.0",
"joi": "^17.4.0",
"moment": "^2.29.1",
"node-fetch": "^2.6.1"
"node-fetch": "^2.6.1",
"nodemailer": "^6.7.0"
},
"devDependencies": {
"env-cmd": "^10.1.0",
Expand Down
3 changes: 2 additions & 1 deletion hapi/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ module.exports = {
hasuraConfig: require('./hasura.config'),
hyperionConfig: require('./hyperion.config'),
networkConfig: require('./network.config'),
serverConfig: require('./server.config')
serverConfig: require('./server.config'),
mailConfig: require('./mail.config')
}
6 changes: 6 additions & 0 deletions hapi/src/config/mail.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
host: process.env.HAPI_MAIL_HOST,
port: process.env.HAPI_MAIL_PORT,
user: process.env.HAPI_MAIL_USER,
pass: process.env.HAPI_MAIL_PASSWORD
}
3 changes: 2 additions & 1 deletion hapi/src/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const addReferralRoute = require('./add-referral.route')
const sendConfirmationRoute = require('./send-confirmation.route')
const healthzRoute = require('./healthz.route')

module.exports = [addReferralRoute, healthzRoute]
module.exports = [addReferralRoute, sendConfirmationRoute, healthzRoute]
39 changes: 39 additions & 0 deletions hapi/src/routes/send-confirmation.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const Joi = require('joi')
const Boom = require('@hapi/boom')

const {
mailUtil: { sendConfirmation }
} = require('../utils')
const {
joinRequestService: { findByAccount }
} = require('../services')

module.exports = {
method: 'POST',
path: '/send-confirmation',
handler: async ({ payload: { input } }) => {
try {
for (const account of input.accounts) {
const { email } = await findByAccount(account)
await sendConfirmation({
account: account,
to: email,
subject: 'You are ready to share your Proton referral link!'
})
}

return { success: true }
} catch (error) {
throw Boom.badRequest(error.message, { code: 'BAD_REQUEST' })
}
},
options: {
validate: {
payload: Joi.object({
input: Joi.object({
accounts: Joi.array().required()
}).required()
}).options({ stripUnknown: true })
}
}
}
2 changes: 2 additions & 0 deletions hapi/src/services/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const hyperionService = require('./hyperion')
const affiliateService = require('./affiliate.service')
const exchangeService = require('./exchange.service')
const joinRequestService = require('./join-request.service')
const referralsService = require('./referrals.service')
const workerService = require('./worker.service')

module.exports = {
hyperionService,
affiliateService,
exchangeService,
joinRequestService,
referralsService,
workerService
}
23 changes: 23 additions & 0 deletions hapi/src/services/join-request.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { hasuraUtil } = require('../utils')

const findByAccount = async account => {
const query = `
query ($account: String!) {
join_request(where: {account: {_eq: $account}}) {
id
account
email
receive_news
created_at
updated_at
}
}
`
const data = await hasuraUtil.instance.request(query, { account })

return data.join_request.length ? data.join_request[0] : null
}

module.exports = {
findByAccount
}
2 changes: 1 addition & 1 deletion hapi/src/services/referrals.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { hasuraUtil, eosUtil } = require('../utils')
const { hasuraUtil } = require('../utils')

const save = async payload => {
const mutation = `
Expand Down
3 changes: 2 additions & 1 deletion hapi/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module.exports = {
eosUtil: require('./eos.util'),
hasuraUtil: require('./hasura.util'),
sleepUtil: require('./sleep.util'),
walletUtil: require('./wallet.util')
walletUtil: require('./wallet.util'),
mailUtil: require('./mail.util')
}
32 changes: 32 additions & 0 deletions hapi/src/utils/mail.util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const nodemailer = require('nodemailer')
const {
mailConfig: { host, port, user, pass }
} = require('../config')
const {
mailTemplate: { generateConfirmationMail }
} = require('./templates')

const sendConfirmation = async ({ account, to, subject }) => {
try {
const transporter = nodemailer.createTransport({
host,
secure: false,
port,
auth: { user, pass },
tls: { rejectUnauthorized: false }
})

await transporter.sendMail({
from: `Proton Affiliate <${user}>`,
to,
subject,
html: generateConfirmationMail({ account })
})
} catch (error) {
console.log(error)
}
}

module.exports = {
sendConfirmation
}
3 changes: 3 additions & 0 deletions hapi/src/utils/templates/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
mailTemplate: require('./mail.template')
}
70 changes: 70 additions & 0 deletions hapi/src/utils/templates/mail.template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const generateConfirmationMail = ({ account }) => {
return `
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<table style="padding: 0px 16px 0px; margin-left: auto; margin-right: auto;">
<tr>
<table style="max-width: 640px; margin-left: auto; margin-right: auto;">
<tr>
<img style="margin: 0px 44px 24px 44px; width: 177.7px; height: 53px; object-fit: scale-down" src="https://earnproton.com/proton.png"/>
</tr>
<tr>
<p align="left" style="margin: 24px 96px; font-family: Arial; font-size: 21px; font-weight: normal; font-stretch: normal; font-style: normal; line-height: normal; letter-spacing: 0.15px; text-align: left; color: #000;">
Welcome to the Proton On-Chain Referral Program!
</p>
</tr>
<tr>
<p align="left" style="margin: 24px 96px; font-family: Arial; font-size: 16px; font-weight: normal; font-stretch: normal; font-style: normal; line-height: 1.5; letter-spacing: 0.44px; text-align: left; color: #000;">
Your Proton referral link is now active. You may share the following link with your friends to earn rewards when they complete new account registration and KYC on the Proton network:
</p>
</tr>
<tr>
<p align="center" style="margin: 24px 0 25px;">
<a href= https://earnproton.com/join/${account}" style="font-family: Arial; font-size: 16px; font-weight: bold; font-stretch: normal; font-style: normal; line-height: 1; letter-spacing: 0.4px; text-align: center; color: #582acb;">
https://earnproton.com/join/${account}
</a>
</p>
</tr>
<tr>
<p align="left" style="margin: 24px 96px; font-family: Arial; font-size: 16px; font-weight: normal; font-stretch: normal; font-style: normal; line-height: 1.5; letter-spacing: 0.44px; text-align: left; color: #000; overflow-wrap: break-word;">
To view your referrals and payments, login using your proton wallet at https://earnproton.com.
</p>
</tr>
<tr>
<p align="left" style="margin: 24px 96px 0px; font-family: Arial; font-size: 16px; font-weight: normal; font-stretch: normal; font-style: normal; line-height: 1.5; letter-spacing: 0.44px; text-align: left; color: #000;">
Best Regards,
</p>
</tr>
<tr>
<p align="left" style="margin: 8px 96px 24px; font-family: Arial; font-size: 16px; font-weight: bold; font-stretch: normal; font-style: normal; line-height: 1.5; letter-spacing: 0.44px; text-align: left; color: #000;">
The Proton Affiliate Team
<br>
(Edenia, SoftAtom)
</p>
</tr>
</table>
</tr>
<tr>
<table style="height: 157px; margin: 40px 0 0; padding: 22px 96px 15px; background-color: rgba(0, 0, 0, 0.87); margin-left: auto; margin-right: auto;">
<p align="left" style="flex-grow: 0; margin: 0 0 20px; font-family: Arial; font-size: 14px; font-weight: normal; font-stretch: normal; font-style: normal; line-height: 1.14; letter-spacing: 0.44px; text-align: center; color: #fff;">
<a href="https://forms.gle/GWHig5ciAvg5fdEH7" style="color: #fff;">
Apply Here for Funding
</a>
</p>
<p align="left" style="margin: 20px 218px 15px; font-family: Arial; font-size: 12px; font-weight: normal; font-stretch: normal; font-style: normal; line-height: 1.33; letter-spacing: 1.5px; text-align: center; color: #fff;">
THIS PROJECT WAS FUNDED THROUGH THE PROTON GOVERNANCE COMMITTEE WORKER PROPOSAL SYSTEM
</p>
</table>
</tr>
</table>
</body>
`
}

module.exports = {
generateConfirmationMail
}
Loading

0 comments on commit 1710c85

Please sign in to comment.