Skip to content

Commit

Permalink
Feat/sort new affiliate (#382)
Browse files Browse the repository at this point in the history
* feat(webapp): add new users status filter

* feat(hapi): add kyc worker updater

* feat(webapp): implement logic to status

* feat(webapp): improve filter logic

* feat(hapi): kyc worker

* refactor(webapp): remove unused variables

* fix(webapp): merge conflicts

* reafactor(hapi): remove unneded code

* reafactor(hapi): clean code

* refactor(webapp): update variable name
  • Loading branch information
leisterfrancisco committed Feb 3, 2022
1 parent 1735fe1 commit 52e2989
Show file tree
Hide file tree
Showing 18 changed files with 218 additions and 70 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ HAPI_AFFILIATE_PASSWORD=PW...
HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL=3600
HAPI_AFFILIATE_CLEAR_REFERRALS_INTERVAL=86400
HAPI_AFFILIATE_SET_RATE_INTERVAL=86400
HAPI_AFFILIATE_UPDATE_KYC_INTERVAL=18000
HAPI_AFFILIATE_UPDATE_REQUESTER_INTERVAL=86400
HAPI_HYPERION_API=https://testnet.protonchain.com
HAPI_HYPERION_START_AT=2021-06-02T00:00:00.000+00:00
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push-dev-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL: 3600
HAPI_AFFILIATE_CLEAR_REFERRALS_INTERVAL: 86400
HAPI_AFFILIATE_SET_RATE_INTERVAL: 86400
HAPI_AFFILIATE_UPDATE_KYC_INTERVAL: 18000
HAPI_AFFILIATE_UPDATE_REQUESTER_INTERVAL: 86400
HAPI_HYPERION_API: 'https://testnet.protonchain.com'
HAPI_HYPERION_START_AT: '2021-06-02T00:00:00.000+00:00'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push-prod-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL: 3600
HAPI_AFFILIATE_CLEAR_REFERRALS_INTERVAL: 86400
HAPI_AFFILIATE_SET_RATE_INTERVAL: 86400
HAPI_AFFILIATE_UPDATE_KYC_INTERVAL: 18000
HAPI_AFFILIATE_UPDATE_REQUESTER_INTERVAL: 86400
HAPI_HYPERION_API: ${{ secrets.HAPI_HYPERION_API }}
HAPI_HYPERION_START_AT: '2021-06-02T00:00:00.000+00:00'
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ services:
HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL: '${HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL}'
HAPI_AFFILIATE_CLEAR_REFERRALS_INTERVAL: '${HAPI_AFFILIATE_CLEAR_REFERRALS_INTERVAL}'
HAPI_AFFILIATE_SET_RATE_INTERVAL: '${HAPI_AFFILIATE_SET_RATE_INTERVAL}'
HAPI_AFFILIATE_UPDATE_KYC_INTERVAL: '${HAPI_AFFILIATE_UPDATE_KYC_INTERVAL}'
HAPI_AFFILIATE_UPDATE_REQUESTER_INTERVAL: '${HAPI_AFFILIATE_UPDATE_REQUESTER_INTERVAL}'
HAPI_HYPERION_API: '${HAPI_HYPERION_API}'
HAPI_HYPERION_START_AT: '${HAPI_HYPERION_START_AT}'
Expand Down
3 changes: 3 additions & 0 deletions hapi/src/config/affiliate.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = {
setRateInterval: parseInt(
process.env.HAPI_AFFILIATE_SET_RATE_INTERVAL || 86400
),
updateKycInterval: parseInt(
process.env.HAPI_AFFILIATE_UPDATE_KYC_INTERVAL || 18000
),
updateRequesterInterval: parseInt(
process.env.HAPI_AFFILIATE_UPDATE_REQUESTER_INTERVAL || 86400
)
Expand Down
76 changes: 70 additions & 6 deletions hapi/src/services/join-request.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const { mailTemplate } = require('../utils/templates')
const { hasuraUtil, eosUtil, mailUtil } = require('../utils')
const affiliateService = require('./affiliate.service')

const JOIN_REQUEST_STATUS_IDS = {
PENDING_KYC: 1,
PENDING_APPROVAL: 2,
APPROVED: 3
}

const addJoinRequest = async payload => {
const mutation = `
mutation ($payload: join_request_insert_input!) {
Expand Down Expand Up @@ -49,33 +55,82 @@ const findByAccount = async account => {
return data.join_request.length ? data.join_request[0] : null
}

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

return join_request.length ? join_request : null
}

const update = async (account, payload) => {
const mutation = `
mutation ($account: String!, $payload: join_request_set_input) {
update_join_request(where: {account: {_eq: $account}}, _set: $payload) {
affected_rows
}
}
`

await hasuraUtil.instance.request(mutation, { account, payload })
}

// This function is intended to make a soft database update to replace state value for status
// WARNING: Removed after a production version of this function
const updateStatus = async () => {
const requesters = await findByStatus(JOIN_REQUEST_STATUS_IDS.PENDING_KYC)
const { rows } = await eosUtil.getTableRows({
code: affiliateConfig.account,
scope: affiliateConfig.account,
table: 'users'
})

for (const requester of requesters) {
const isUser = rows.some(({ user }) => user === requester.account)

if (!isUser) continue

await update(requester.account, {
status: JOIN_REQUEST_STATUS_IDS.APPROVED
})
}
}

const updateKYC = async () => {
await updateStatus()

const requesters = await findByStatus(JOIN_REQUEST_STATUS_IDS.PENDING_KYC)

for (const requester of requesters) {
const hasKYC = await affiliateService.checkKyc(requester.account)

if (!hasKYC) continue

await update(requester.account, {
status: JOIN_REQUEST_STATUS_IDS.PENDING_APPROVAL
})
}
}

const updateRequester = async () => {
const { rows } = await eosUtil.getTableRows({
code: affiliateConfig.account,
scope: affiliateConfig.account,
table: 'params'
})
const removeAfterDays = rows[0].expiration_days
const requesters = await findByState('pending')
const requesters = await findByStatus(JOIN_REQUEST_STATUS_IDS.PENDING_KYC)

for (const requester of requesters) {
const daysAfterJoin = moment().diff(moment(requester.created_at), 'days')
Expand Down Expand Up @@ -108,6 +163,14 @@ const updateRequester = async () => {
}
}

const kycWorker = () => {
return {
name: 'UPDATE KYC',
interval: affiliateConfig.updateKycInterval,
action: updateKYC
}
}

const removeWorker = () => {
return {
name: 'UPDATE REQUESTER',
Expand All @@ -120,5 +183,6 @@ module.exports = {
addJoinRequest,
removeJoinRequest,
findByAccount,
kycWorker,
removeWorker
}
1 change: 1 addition & 0 deletions hapi/src/services/worker.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const init = async () => {
run(affiliateService.verifyExpiredWorker())
run(affiliateService.clearReferralsWorker())
run(affiliateService.setRateWorker())
run(joinRequestService.kycWorker())
run(joinRequestService.removeWorker())
run(hyperionService.syncWorker())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."join_request" add column "status" integer
-- not null default '1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."join_request" add column "status" integer
not null default '1';
1 change: 1 addition & 0 deletions kubernetes/proton-affiliate-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data:
HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL: '${HAPI_AFFILIATE_VERIFY_EXPIRED_INTERVAL}'
HAPI_AFFILIATE_CLEAR_REFERRALS_INTERVAL: '${HAPI_AFFILIATE_CLEAR_REFERRALS_INTERVAL}'
HAPI_AFFILIATE_SET_RATE_INTERVAL: '${HAPI_AFFILIATE_SET_RATE_INTERVAL}'
HAPI_AFFILIATE_UPDATE_KYC_INTERVAL: '${HAPI_AFFILIATE_UPDATE_KYC_INTERVAL}'
HAPI_AFFILIATE_UPDATE_REQUESTER_INTERVAL: '${HAPI_AFFILIATE_UPDATE_REQUESTER_INTERVAL}'
HAPI_HYPERION_API: '${HAPI_HYPERION_API}'
HAPI_HYPERION_START_AT: '${HAPI_HYPERION_START_AT}'
Expand Down
13 changes: 7 additions & 6 deletions webapp/src/components/Accordion/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import { makeStyles } from '@material-ui/core/styles'
import { useTranslation } from 'react-i18next'
import Accordion from '@material-ui/core/Accordion'
import AccordionSummary from '@material-ui/core/AccordionSummary'
import AccordionDetails from '@material-ui/core/AccordionDetails'
Expand All @@ -26,6 +27,7 @@ const AccordionComponent = ({
filterRowsBy
}) => {
const classes = useStyles()
const { t } = useTranslation('adminRoute')
const [expanded, setExpanded] = useState(false)
const [anchorEl, setAnchorEl] = useState(null)

Expand Down Expand Up @@ -82,19 +84,18 @@ const AccordionComponent = ({
}}
onClose={handleClose}
>
{(filterValues || []).map((item, index) => {
{(filterValues || []).map(({ label, value }) => {
return (
<MenuItem
key={index}
key={value}
className={classes.menu}
onClick={() => {
handleClose()
handleOnFilter(index)
handleOnFilter(value)
}}
>
<Typography className={classes.menuLabel}>{item}</Typography>

{index === filterRowsBy && (
<Typography className={classes.menuLabel}>{t(label)}</Typography>
{(value || 0) === filterRowsBy && (
<ListItemIcon>
<CheckIcon className={classes.checkIcon} fontSize="small" />
</ListItemIcon>
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/gql/affiliate.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const GET_JOIN_REQUEST = gql`
) {
account
email
state
status
id
receive_news
created_at
Expand All @@ -166,10 +166,10 @@ export const REJECT_JOIN_REQUEST_MUTATION = gql`
`

export const UPDATE_JOIN_REQUEST_MUTATION = gql`
mutation ($account: [String!], $state: String!) {
mutation ($account: [String!], $status: Int!) {
update_join_request(
where: { account: { _in: $account } }
_set: { state: $state }
_set: { status: $status }
) {
affected_rows
}
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"darkMode": "Dark Mode",
"empty": "No data",
"loadMore": "Load More",
"VERIFIED_KYC_VERIFICATION": "Verified KYC",
"PENDING_USER_REGISTRATION": "Pending",
"PENDING_KYC_VERIFICATION": "Pending KYC",
"PENDING_PAYMENT": "Pending payment",
Expand Down Expand Up @@ -167,8 +168,7 @@
"rejectMemo": "Rejection memo",
"menuAllRoles": "All roles",
"menuAdminRole": "Admin only",
"menuReferrerRole": "Referrers only",
"verified": "Verified"
"menuReferrerRole": "Referrers only"
},
"footer": {
"poweredBy": "Powered by",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/language/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"signOut": "Salir",
"lightMode": "Modo Claro",
"darkMode": "Modo Oscuro",
"VERIFIED_KYC_VERIFICATION": "KYC verificado",
"PENDING_USER_REGISTRATION": "Pendiente",
"PENDING_KYC_VERIFICATION": "KYC pendiente",
"PENDING_PAYMENT": "Pago pendiente",
Expand Down
Loading

0 comments on commit 52e2989

Please sign in to comment.