Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync #19

Merged
merged 3 commits into from
Jun 15, 2024
Merged

sync #19

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ FRACTAL_RESOURCE_SERVER=https://resource.fractal.id
FRACTAL_VERIFIER_SERVER=https://verifierfractal.id
FRACTAL_REDIRECT_URL="https://bitgreen.org/"
FRACTAL_BASIC_SCOPE="contact:read verification.basic:read verification.basic.details:read verification.selfie:read verification.selfie.details:read verification.wallet-substrate:read verification.wallet-substrate.details:read"
FRACTAL_ADVANCED_SCOPE="contact:read verification.liveness:read verification.liveness.details:read verification.wallet-substrate:read verification.wallet-substrate.details:read"
FRACTAL_ADVANCED_SCOPE="contact:read verification.plus:read verification.plus.details:read verification.selfie:read verification.selfie.details:read verification.wallet-substrate:read verification.wallet-substrate.details:read"
FRACTAL_CLIENT_ID=""
FRACTAL_SECRET=""
FRACTAL_WEBHOOK_SECRET_VERIFICATION_APPROVED=""
Expand Down
23 changes: 20 additions & 3 deletions src/routes/ccMarketplace/kyc/kyc-approval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { VerificationStatus } from '@prisma/client';
import * as crypto from 'crypto';
import express, { Request, Response } from 'express';
import { prisma } from '../../../services/prisma';
import { submitExtrinsic } from '../../../utils/chain';
import {queryChain, submitExtrinsic} from '../../../utils/chain';
import {getAccessToken, getUserInformation, loginTemplate} from '../../../utils/fractal';
import { authKYC } from '../../authentification/auth-middleware';
import logger from "@/utils/logger";

const router = express.Router();

Expand Down Expand Up @@ -120,10 +121,26 @@ router.post('/webhook/kyc-approval', async (req: Request, res: Response) => {
.status(400)
.json({ status: false, message: 'KYC profile not found.' });

all_kyc.map(async (kyc) => {
all_kyc.map(async(kyc) => {
const existingData = await queryChain('kycPallet', 'members', [kyc.profileAddress])

const match = existingData?.data?.toString().match(/KYCLevel(\d+)/);
const existingLevel = match ? match[1] : null;
const newLevel = (level === 'plus') ? 4 : 1

// skip in some cases
if(level === 'basic' && Number(existingLevel) >= 1) {
return
}
if(level === 'plus' && Number(existingLevel) === 4) {
return
}

const call = Number(existingLevel) >= 1 ? 'modifyMember' : 'addMember'

// save on blockchain
// no need to do this in db since this is done by blockchain event listener later
await submitExtrinsic('kyc', 'addMember', [kyc.profileAddress]);
await submitExtrinsic('kycPallet', call, [kyc.profileAddress, `KYCLevel${newLevel}`]);
})

return res.status(200).json({ success: true });
Expand Down
Loading