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 Jan 13, 2022
2 parents a2470b2 + aca5202 commit 196fdfb
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 70 deletions.
38 changes: 38 additions & 0 deletions hapi/src/routes/add-join-request.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const Joi = require('joi')
const Boom = require('@hapi/boom')

const { joinRequestService, affiliateService } = require('../services')

module.exports = {
method: 'POST',
path: '/add-join-request',
handler: async ({ payload: { input } }) => {
try {
const isAnInvitee = await affiliateService.isAccountValidAsInvitee(
input.account
)
const joinRequest = await joinRequestService.findByAccount(input.account)
const hasKYC = await affiliateService.checkKyc(input.account)

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

const transaction = await joinRequestService.addJoinRequest(input)

return { id: transaction.id }
} catch (error) {
throw Boom.badRequest(error.message, { code: 'BAD_REQUEST' })
}
},
options: {
validate: {
payload: Joi.object({
input: Joi.object({
account: Joi.string().required(),
email: Joi.string().required(),
receive_news: Joi.boolean().required()
}).required()
}).options({ stripUnknown: true })
}
}
}
8 changes: 7 additions & 1 deletion hapi/src/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const addJoinRequest = require('./add-join-request.route')
const addReferralRoute = require('./add-referral.route')
const sendConfirmationRoute = require('./send-confirmation.route')
const healthzRoute = require('./healthz.route')

module.exports = [addReferralRoute, sendConfirmationRoute, healthzRoute]
module.exports = [
addJoinRequest,
addReferralRoute,
sendConfirmationRoute,
healthzRoute
]
28 changes: 28 additions & 0 deletions hapi/src/services/affiliate.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ const verifyKYC = async invitee => {
return transaction
}

const checkKyc = async acc => {
const { rows } = await eosUtil.getTableRows({
code: 'eosio.proton',
scope: 'eosio.proton',
table: 'usersinfo',
lower_bound: acc,
upper_bound: acc
})

return !!rows[0]?.kyc?.length
}

const isAccountValidAsInvitee = async account => {
if (!account) {
return false
}

try {
const data = await eosUtil.getAccount(account)

return !data
} catch (error) {}

return true
}

const verifyExpired = async () => {
const transaction = await eosUtil.transact(
[
Expand Down Expand Up @@ -163,6 +189,8 @@ const setRateWorker = () => {
}

module.exports = {
checkKyc,
isAccountValidAsInvitee,
verifyAccount,
verifyKYC,
verifyExpired,
Expand Down
14 changes: 14 additions & 0 deletions hapi/src/services/join-request.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
const { hasuraUtil } = require('../utils')

const addJoinRequest = async payload => {
const mutation = `
mutation ($payload: join_request_insert_input!) {
insert_join_request_one(object: $payload) {
id
}
}
`
const data = await hasuraUtil.instance.request(mutation, { payload })

return data.insert_join_request_one
}

const findByAccount = async account => {
const query = `
query ($account: String!) {
Expand All @@ -19,5 +32,6 @@ const findByAccount = async account => {
}

module.exports = {
addJoinRequest,
findByAccount
}
20 changes: 13 additions & 7 deletions hasura/metadata/actions.graphql
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
type Mutation {
add_referral(
referrer: String!
invitee: String!
): AddReferralOutput
add_join_request(
account: String!
email: String!
receive_news: Boolean!
): AddJoinRequestOutput
}

type Mutation {
send_confirmation(
accounts: [String]!
): SendConfirmationOutput
add_referral(referrer: String!, invitee: String!): AddReferralOutput
}

type Mutation {
send_confirmation(accounts: [String]!): SendConfirmationOutput
}

type AddReferralOutput {
Expand All @@ -19,3 +22,6 @@ type SendConfirmationOutput {
success: Boolean!
}

type AddJoinRequestOutput {
id: String!
}
35 changes: 20 additions & 15 deletions hasura/metadata/actions.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
actions:
- name: add_referral
definition:
kind: synchronous
handler: '{{HASURA_GRAPHQL_ACTION_BASE_URL}}/add-referral'
forward_client_headers: true
permissions:
- role: guest
- name: send_confirmation
definition:
kind: synchronous
handler: '{{HASURA_GRAPHQL_ACTION_BASE_URL}}/send-confirmation'
permissions:
- role: guest
- name: add_join_request
definition:
kind: synchronous
handler: '{{HASURA_GRAPHQL_ACTION_BASE_URL}}/add-join-request'
- name: add_referral
definition:
kind: synchronous
handler: '{{HASURA_GRAPHQL_ACTION_BASE_URL}}/add-referral'
forward_client_headers: true
permissions:
- role: guest
- name: send_confirmation
definition:
kind: synchronous
handler: '{{HASURA_GRAPHQL_ACTION_BASE_URL}}/send-confirmation'
permissions:
- role: guest
custom_types:
enums: []
input_objects: []
objects:
- name: AddReferralOutput
- name: SendConfirmationOutput
- name: AddReferralOutput
- name: SendConfirmationOutput
- name: AddJoinRequestOutput
scalars: []
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
table:
name: join_request
schema: public
insert_permissions:
- permission:
backend_only: false
check: {}
columns:
- account
- email
- receive_news
role: guest
select_permissions:
- permission:
allow_aggregations: true
Expand Down
1 change: 1 addition & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"react": "~17.0.1",
"react-dom": "~17.0.1",
"react-feather": "^2.0.9",
"react-ga": "^3.3.0",
"react-helmet": "^6.1.0",
"react-i18next": "^11.8.8",
"react-is": "^17.0.1",
Expand Down
8 changes: 7 additions & 1 deletion webapp/src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Suspense, useMemo } from 'react'
import React, { Suspense, useEffect, useMemo } from 'react'
import { BrowserRouter, Route, Switch } from 'react-router-dom'
import DateFnsUtils from '@date-io/date-fns'
import { MuiPickersUtilsProvider } from '@material-ui/pickers'
Expand All @@ -15,6 +15,7 @@ import DashboardLayout from './layouts/Dashboard'
import { useSharedState } from './context/state.context'
import getTheme from './theme'
import './i18n'
import ReactGA from 'react-ga'

const generateClassName = createGenerateClassName({
productionPrefix: 'proton'
Expand All @@ -41,6 +42,11 @@ const App = () => {

const theme = useMemo(() => getTheme(state.useDarkMode), [state.useDarkMode])

useEffect(() => {
ReactGA.initialize('G-XC2N8PX4V6')
ReactGA.pageview(window.location.pathname + window.location.search)
}, [])

return (
<BrowserRouter>
<StylesProvider generateClassName={generateClassName}>
Expand Down
12 changes: 10 additions & 2 deletions webapp/src/gql/affiliate.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,16 @@ export const GET_MY_REFERRALS = gql`
`

export const ADD_JOIN_REQUEST_MUTATION = gql`
mutation addJoinRequest($user: join_request_insert_input!) {
userJoin: insert_join_request_one(object: $user) {
mutation addJoinRequest(
$account: String!
$email: String!
$receive_news: Boolean!
) {
userJoin: add_join_request(
account: $account
email: $email
receive_news: $receive_news
) {
id
}
}
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@
"rejectMemo": "Rejection memo",
"menuAllRoles": "All roles",
"menuAdminRole": "Admin only",
"menuReferrerRole": "Referrers only"
"menuReferrerRole": "Referrers only",
"verified": "Verified",
"pending": "Pending"
},
"footer": {
"poweredBy": "Powered by",
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/language/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"adminRoute": {
"menuAllRoles": "Todos los roles",
"menuAdminRole": "Solo admin",
"menuReferrerRole": "Solo referidos"
"menuReferrerRole": "Solo referidos",
"verified": "Verificado",
"pending": "Pendiente"
}
}
54 changes: 40 additions & 14 deletions webapp/src/routes/Admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ const headCellNewUsers = [
rowLink: true,
label: 'account'
},
{
id: 'kyc',
align: 'center',
useMainColor: false,
rowLink: false,
label: 'kyc'
},
{
id: 'applied',
align: 'center',
Expand Down Expand Up @@ -678,18 +685,28 @@ const Admin = () => {
useEffect(() => {
if (loading || !joinRequest) return

const data = (joinRequest || []).map(item => ({
...item,
account: item.account,
applied: dateFormat(item.created_at),
email: item.email
}))
const setUserData = async () => {
const data = await Promise.all(
(joinRequest || []).map(async item => {
const hasKYC = await affiliateUtil.checkKyc(item.account)
return {
...item,
account: item.account,
kyc: hasKYC ? t('verified') : t('pending'),
applied: dateFormat(item.created_at),
email: item.email
}
})
)

setNewUsersPagination({
...newUsersPagination,
count: infoJoin.aggregate.count
})
setNewUserRows(data)
setNewUsersPagination({
...newUsersPagination,
count: infoJoin.aggregate.count
})
setNewUserRows(data)
}

setUserData()
}, [loading, joinRequest, infoJoin])

useEffect(() => {
Expand Down Expand Up @@ -818,14 +835,23 @@ const Admin = () => {
setOpenInfoModal(true)
setOpenFAB(false)
}}
onClickRemoveUsers={handleOnRemoveUsers}
onClickApprovePayment={handleOnApprovePayment}
onClickRemoveUsers={() => {
handleOnRemoveUsers()
setOpenFAB(false)
}}
onClickApprovePayment={() => {
handleOnApprovePayment()
setOpenFAB(false)
}}
onClickRejectPayment={() => {
setRejectPayment({ isOpen: true, previousModal: 'optionFAB' })
setOpenFAB(false)
}}
allowPayment={allowPayment}
onClickApproveNewUser={approveNewUser}
onClickApproveNewUser={() => {
approveNewUser()
setOpenFAB(false)
}}
/>
</Box>
</FloatingMenu>
Expand Down
11 changes: 4 additions & 7 deletions webapp/src/routes/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ const Home = () => {
try {
await addJoinRequest({
variables: {
user: {
account,
email,
receive_news: checked
}
account,
email,
receive_news: checked
}
})

Expand Down Expand Up @@ -206,7 +204,6 @@ const Home = () => {
}
})
const hasKyc = await affiliateUtil.checkKyc(account)

const isValid = !isAnInvitee && !joinRequest.length && hasKyc
const errorMessageTag =
(isAnInvitee ? 'accountHelperError' : '') ||
Expand Down Expand Up @@ -344,7 +341,7 @@ const Home = () => {
<Button
color="primary"
onClick={handleAddJoinRequest}
disabled={!isValidEmail.isValid}
disabled={!isValidAccount.isValid || !isValidEmail.isValid}
>
{loadingJoin ? (
<CircularProgress color="primary" size={24} />
Expand Down
Loading

0 comments on commit 196fdfb

Please sign in to comment.