Skip to content

Commit

Permalink
feat(webapp): allow non kyc (#366)
Browse files Browse the repository at this point in the history
* feat(hapi): send reject mail

* feat(hasura): add action permissions

* refactor(hapi): update mail template

* fix(webapp): remove kyc validation

* feat(webapp): allow user to apply without kyc

* refactor(webapp): call correct recursive function

* refactor(webapp): update mail content

* refactor(webapp): remove final point
  • Loading branch information
leisterfrancisco committed Jan 19, 2022
1 parent 9da0196 commit 97fe060
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 29 deletions.
14 changes: 13 additions & 1 deletion hapi/src/routes/add-join-request.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const Joi = require('joi')
const Boom = require('@hapi/boom')

const { joinRequestService, affiliateService } = require('../services')
const { mailUtil } = require('../utils')
const { mailTemplate } = require('../utils/templates')

module.exports = {
method: 'POST',
Expand All @@ -14,9 +16,19 @@ module.exports = {
const joinRequest = await joinRequestService.findByAccount(input.account)
const hasKYC = await affiliateService.checkKyc(input.account)

if (isAnInvitee || joinRequest?.length || !hasKYC)
if (isAnInvitee || joinRequest?.length)
throw Boom.badRequest('Account does not meet requirements')

if (!hasKYC) {
mailUtil.send({
account: input.account,
to: input.email,
subject:
'Further action is required to activate your Proton Affiliate account',
template: mailTemplate.generateRejectionByKYC
})
}

const transaction = await joinRequestService.addJoinRequest(input)

return { id: transaction.id }
Expand Down
10 changes: 7 additions & 3 deletions hapi/src/routes/send-confirmation.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ const Joi = require('joi')
const Boom = require('@hapi/boom')

const {
mailUtil: { sendConfirmation }
mailUtil: { send }
} = require('../utils')
const {
mailTemplate: { generateConfirmation }
} = require('../utils/templates')
const {
joinRequestService: { findByAccount }
} = require('../services')
Expand All @@ -15,10 +18,11 @@ module.exports = {
try {
for (const account of input.accounts) {
const { email } = await findByAccount(account)
await sendConfirmation({
await send({
account: account,
to: email,
subject: 'You are ready to share your Proton referral link!'
subject: 'Welcome to the Proton Affiliate Program!',
template: generateConfirmation
})
}

Expand Down
9 changes: 3 additions & 6 deletions hapi/src/utils/mail.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ const nodemailer = require('nodemailer')
const {
mailConfig: { host, port, user, pass }
} = require('../config')
const {
mailTemplate: { generateConfirmationMail }
} = require('./templates')

const sendConfirmation = async ({ account, to, subject }) => {
const send = async ({ account, to, subject, template }) => {
try {
const transporter = nodemailer.createTransport({
host,
Expand All @@ -20,13 +17,13 @@ const sendConfirmation = async ({ account, to, subject }) => {
from: `Proton Affiliate <${user}>`,
to,
subject,
html: generateConfirmationMail({ account })
html: template({ account })
})
} catch (error) {
console.log(error)
}
}

module.exports = {
sendConfirmation
send
}
77 changes: 75 additions & 2 deletions hapi/src/utils/templates/mail.template.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const generateConfirmationMail = ({ account }) => {
const generateConfirmation = ({ account }) => {
return `
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -74,6 +74,79 @@ const generateConfirmationMail = ({ account }) => {
`
}

const generateRejectionByKYC = ({ 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="margin-left: auto; margin-right: auto;">
<tr>
<div style="max-width: 640px; margin-left: auto; margin-right: auto;">
<a href="https://earnproton.com" style="text-decoration: none; margin: 40px 0px 0px 16px; width: 178px; height: 53px;">
<img style="object-fit: scale-down;" src="https://earnproton.com/icons/proton.png"/>
</a>
<p align="left" style="margin: 24px 16px 24px; 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;">
${account} - Regarding Your Proton On-Chain Referral Program Request
</p>
<p align="left" style="margin: 0px 16px 8px; 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 not ready yet. To begin using the Proton Referral Program and start earning rewards, you must first complete the KYC (Know Your Client) authentication process in the Proton wallet.
</p>
<br>
<p align="left" style="margin: 0px 16px 24px; 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;">
Please, go to the Proton wallet app and submit your KYC application. Once completed, you can start using your referral link. To find out what countries can complete a KYC, go to the Proton wallet app or ask in the Proton Telegram chat: https://t.me/protonxpr. If you're still having problems after confirming this information, please get in touch with us through Telegram: https://t.me/eoscr.
</p>
<p align="left" style="margin: 0px 16px 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>
<br>
<p align="left" style="margin: 0px 16px 35px; 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>
</div>
</tr>
<tr>
<div style="background-color: #000; margin-left: auto; margin-right: auto; padding-top: 20px;">
<p align="left" style="width: 348px; margin: 0px auto 8px auto; 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>
<p align="left" style="flex-grow: 0; margin: 0px 16px 14px; 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>
<div style="padding-bottom: 8px; text-align: center;">
<a href="https://www.facebook.com/protonxpr" style="text-decoration: none;">
<img style="width: 32px; height: 32px; margin-right: 16px;" src="https://earnproton.com/icons/facebook.png">
</a>
<a href="https://www.instagram.com/protonxpr" style="text-decoration: none;">
<img style="width: 32px; height: 32px; margin-right: 16px;" src="https://earnproton.com/icons/instagram.png">
</a>
<a href="https://twitter.com/protonxpr" style="text-decoration: none;">
<img style="width: 32px; height: 32px; margin-right: 16px;" src="https://earnproton.com/icons/twitter.png">
</a>
<a href="https://www.reddit.com/r/ProtonChain" style="text-decoration: none;">
<img style="width: 32px; height: 32px; margin-right: 16px;" src="https://earnproton.com/icons/reddit.png">
</a>
<a href="https://github.com/eoscostarica/proton-affiliate" style="text-decoration: none;">
<img style="width: 32px; height: 32px; margin-right: 16px;" src="https://earnproton.com/icons/github.png">
</a>
<a href="https://t.me/protonxpr" style="text-decoration: none;">
<img style="width: 32px; height: 32px;" src="https://earnproton.com/icons/telegram.png">
</a>
</div>
</div>
</tr>
</table>
</body>
`
}

module.exports = {
generateConfirmationMail
generateConfirmation,
generateRejectionByKYC
}
4 changes: 4 additions & 0 deletions hasura/metadata/actions.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ type AddJoinRequestOutput {
id: String!
}

type SendJoinRequestRejectionOutput {
success: Boolean!
}

1 change: 1 addition & 0 deletions hasura/metadata/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ custom_types:
- name: AddReferralOutput
- name: SendConfirmationOutput
- name: AddJoinRequestOutput
- name: SendJoinRequestRejectionOutput
scalars: []
1 change: 1 addition & 0 deletions hasura/metadata/databases/default/functions/functions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
2 changes: 2 additions & 0 deletions webapp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.DS_Store
11 changes: 7 additions & 4 deletions webapp/src/routes/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ const Home = () => {
})
setChecked(false)
setEmail('')
setIsValidAccount({
showHelper: true,
isValid: false,
message: t('accountHelperError2')
})
} catch (error) {
showMessage({ type: 'error', content: error.message })
}
Expand Down Expand Up @@ -203,12 +208,10 @@ const Home = () => {
state: { _eq: affiliateUtil.JOIN_REQUEST_STATUS.pending }
}
})
const hasKyc = await affiliateUtil.checkKyc(account)
const isValid = !isAnInvitee && !joinRequest.length && hasKyc
const isValid = !isAnInvitee && !joinRequest.length
const errorMessageTag =
(isAnInvitee ? 'accountHelperError' : '') ||
(joinRequest.length ? 'accountHelperError2' : '') ||
(!hasKyc ? 'accountHelperError3' : 'accountHelperText')
(joinRequest.length ? 'accountHelperError2' : 'accountHelperText')

setIsValidAccount({
showHelper: true,
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/utils/affiliate.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ const getReferralsByStatus = async (lowerBound, filterRowsBy) => {
rows: tempRows,
cursor: tempCursor,
hasMore: tempHasMore
} = await getReferrals(users.cursor, filterRowsBy)
} = await getReferralsByStatus(users.cursor, filterRowsBy)

return {
rows: tempRows ? [...filteredUsers, ...tempRows] : filteredUsers,
Expand Down
24 changes: 12 additions & 12 deletions webapp/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8005,20 +8005,20 @@ fsevents@^1.2.7:

"fsevents@patch:fsevents@^1.2.7#~builtin<compat/fsevents>":
version: 1.2.13
resolution: "fsevents@patch:fsevents@npm%3A1.2.13#~builtin<compat/fsevents>::version=1.2.13&hash=1cc4b2"
resolution: "fsevents@patch:fsevents@npm%3A1.2.13#~builtin<compat/fsevents>::version=1.2.13&hash=18f3a7"
dependencies:
bindings: ^1.5.0
nan: ^2.12.1
checksum: b264407498db2cfdcc2a05287334a4160c985a88e4a989e2f2f8dcc6afc8b04a4fcd82c797266442452e11c1fb07d7747d138b078fe4bb1f8f4fd2a6f2484d7e
checksum: 2587e64097c1251ae549440b6347954ef3c5ce390061f9e0f0810e83d5d604bb7222c382e7e3c39fc2ba4da53f115b118ea5359ca3bb0bcb96576596bc685d5a
languageName: node
linkType: hard

"fsevents@patch:fsevents@^2.1.2#~builtin<compat/fsevents>, fsevents@patch:fsevents@^2.1.3#~builtin<compat/fsevents>, fsevents@patch:fsevents@~2.3.2#~builtin<compat/fsevents>":
version: 2.3.2
resolution: "fsevents@patch:fsevents@npm%3A2.3.2#~builtin<compat/fsevents>::version=2.3.2&hash=1cc4b2"
resolution: "fsevents@patch:fsevents@npm%3A2.3.2#~builtin<compat/fsevents>::version=2.3.2&hash=18f3a7"
dependencies:
node-gyp: latest
checksum: 78db9daf1f6526a49cefee3917cc988f62dc7f25b5dd80ad6de4ffc4af7f0cab7491ac737626ff53e482a111bc53aac9e411fe3602458eca36f6a003ecf69c16
checksum: edbd0fd80be379c14409605f77e52fdc78a119e17f875e8b90a220c3e5b29e54a1477c21d91fd30b957ea4866406dc3ff87b61432d2840ff8866b309e5866140
languageName: node
linkType: hard

Expand Down Expand Up @@ -14650,31 +14650,31 @@ resolve@^2.0.0-next.3:

"resolve@patch:resolve@1.18.1#~builtin<compat/resolve>":
version: 1.18.1
resolution: "resolve@patch:resolve@npm%3A1.18.1#~builtin<compat/resolve>::version=1.18.1&hash=00b1ff"
resolution: "resolve@patch:resolve@npm%3A1.18.1#~builtin<compat/resolve>::version=1.18.1&hash=d4691f"
dependencies:
is-core-module: ^2.0.0
path-parse: ^1.0.6
checksum: 3a5051499a570cf94d74353d494cacadbfa489107def201f87e26cabd80d000bd8abccbe247783b86b06d86ce2c646eee5c55900c71cbf1ad2043a67a92b0242
checksum: 32933bdf7bcc93bb7e01646f60a471b2cee0262b465449170ce02f4efea71868e4a9624aded28ce3935bc333028c2cc10885ac2b578125381a9de6481e8c1ce2
languageName: node
linkType: hard

"resolve@patch:resolve@^1.10.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.10.1#~builtin<compat/resolve>, resolve@patch:resolve@^1.12.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.14.2#~builtin<compat/resolve>, resolve@patch:resolve@^1.17.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.18.1#~builtin<compat/resolve>, resolve@patch:resolve@^1.20.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.3.2#~builtin<compat/resolve>, resolve@patch:resolve@^1.8.1#~builtin<compat/resolve>":
version: 1.20.0
resolution: "resolve@patch:resolve@npm%3A1.20.0#~builtin<compat/resolve>::version=1.20.0&hash=00b1ff"
resolution: "resolve@patch:resolve@npm%3A1.20.0#~builtin<compat/resolve>::version=1.20.0&hash=d4691f"
dependencies:
is-core-module: ^2.2.0
path-parse: ^1.0.6
checksum: bed00be983cd20a8af0e7840664f655c4b269786dbd9595c5f156cd9d8a0050e65cdbbbdafc30ee9b6245b230c78a2c8ab6447a52545b582f476c29adb188cc5
checksum: 028141533a81a4515c8ac07e38a0ccde5e2722a0fa6bb83ac53ec463a764f1b7c021dcb98fc9a511a4f6e403f354d034bf250fcf9b7b8399bceb2a889ddf78ff
languageName: node
linkType: hard

"resolve@patch:resolve@^2.0.0-next.3#~builtin<compat/resolve>":
version: 2.0.0-next.3
resolution: "resolve@patch:resolve@npm%3A2.0.0-next.3#~builtin<compat/resolve>::version=2.0.0-next.3&hash=00b1ff"
resolution: "resolve@patch:resolve@npm%3A2.0.0-next.3#~builtin<compat/resolve>::version=2.0.0-next.3&hash=d4691f"
dependencies:
is-core-module: ^2.2.0
path-parse: ^1.0.6
checksum: eb88c5e53843bc022215744307a5f5664446c0fdb8f43c33456dce98d5ee6b3162d0cd0a177bb6f1c3d5c8bf01391ac7ab2de0e936e35318725fb40ba7efdaf6
checksum: 2b145f11f797d477c355e53dc70a1b991d95e7954ea6ab258bc1905d4c1658d477a7bcf912eda56c9643080206fe1f44a53fe96559e8da17140347447ce9c025
languageName: node
linkType: hard

Expand Down Expand Up @@ -16541,11 +16541,11 @@ typescript@*:

"typescript@patch:typescript@*#~builtin<compat/typescript>":
version: 4.4.4
resolution: "typescript@patch:typescript@npm%3A4.4.4#~builtin<compat/typescript>::version=4.4.4&hash=d8b4e7"
resolution: "typescript@patch:typescript@npm%3A4.4.4#~builtin<compat/typescript>::version=4.4.4&hash=6454cb"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 4a639b6886be13616582ab82abdb4ffbbf5b0458069d13c10cd5d44fc1cafa33eab005e8ac8691ad8fae249fee85844bb7d523263c4568fe9a2ca31cd3c91c3d
checksum: aaf433508f31ca748d391e488ccb10485407f5920084fff35926076e6089009474929c1c43d0d5a0dafca65fec51550e032e0f0b28ce63c68432adc70b1bc9b3
languageName: node
linkType: hard

Expand Down

0 comments on commit 97fe060

Please sign in to comment.