Skip to content

Commit 077c31f

Browse files
feat(wallet-backend): handle manual approve flow (#1752)
* feat(wallet-backend): gatehub userState is now stored on wallet User even if it was manually approved log user connected to gateway * chore(wallet/backend): move log * chore(wallet/backend): format * chore(wallet/backend): format * chore(wallet/backend): format * fix(wallet/backend): eslint no-case-declarations (add block to switch case) * fix(wallet/backend): change wh triggered addUserToGateway condition * feat(wallet/backend): keep drop firstName condition
1 parent d213f63 commit 077c31f

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

packages/wallet/backend/src/gatehub/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export class GateHubController implements IGateHubController {
3333
) => {
3434
try {
3535
const userId = req.session.user.id
36-
const { isUserApproved, customerId } =
36+
const { isApproved, customerId } =
3737
await this.gateHubService.addUserToGateway(userId)
3838

39-
if (isUserApproved) {
39+
if (isApproved) {
4040
req.session.user.needsIDProof = false
4141
}
4242

packages/wallet/backend/src/gatehub/service.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,42 @@ export class GateHubService {
3939
this.logger.debug(`GateHub webhook event received: ${JSON.stringify(data)}`)
4040
// TODO: handle other webhook types
4141
switch (data.event_type) {
42-
case 'id.verification.accepted':
43-
await this.markUserAsVerified(data.user_uuid)
42+
case 'id.verification.accepted': {
43+
const gateHubUserId = data.user_uuid
44+
const user = await User.query().findOne({ gateHubUserId })
45+
46+
// if user is already verified (for manual verify cases)
47+
// we skip the approveUserToGateway and overrideRiskLevel in addUserToGateway
48+
// but still execute the function in order to store gatehub userState
49+
if (user && !user.kycVerified && !user.lastName) {
50+
await this.addUserToGateway(gateHubUserId, true)
51+
}
52+
53+
await this.markUserAsVerified(gateHubUserId)
54+
4455
break
56+
}
4557
}
4658
}
4759

4860
async addUserToGateway(
49-
userId: string
50-
): Promise<{ isUserApproved: boolean; customerId?: string }> {
61+
userId: string,
62+
isApproved = false
63+
): Promise<{ isApproved: boolean; customerId?: string }> {
5164
const user = await User.query().findById(userId)
5265
if (!user || !user.gateHubUserId) {
5366
throw new NotFound()
5467
}
5568

56-
const isUserApproved = await this.gateHubClient.connectUserToGateway(
57-
user.gateHubUserId,
58-
this.env.GATEHUB_GATEWAY_UUID
69+
if (!isApproved) {
70+
isApproved = await this.gateHubClient.connectUserToGateway(
71+
user.gateHubUserId,
72+
this.env.GATEHUB_GATEWAY_UUID
73+
)
74+
}
75+
76+
this.logger.info(
77+
`User ${user.id} with gatehub id ${user.gateHubUserId} CONNECTED TO GATEWAY`
5978
)
6079

6180
const userState = await this.gateHubClient.getUserState(user.gateHubUserId)
@@ -73,7 +92,7 @@ export class GateHubService {
7392
.join(', ')
7493
}
7594

76-
if (isUserApproved) {
95+
if (isApproved) {
7796
userDetails.kycVerified = true
7897
}
7998

@@ -104,7 +123,7 @@ export class GateHubService {
104123
await this.createDefaultAccountAndWAForManagedUser(userId)
105124
}
106125

107-
return { isUserApproved, customerId }
126+
return { isApproved, customerId }
108127
}
109128

110129
private async createDefaultAccountAndWAForManagedUser(
@@ -220,5 +239,7 @@ export class GateHubService {
220239
await User.query().findById(user.id).patch({
221240
kycVerified: true
222241
})
242+
243+
this.logger.info(`USER ${user.id} with gatehub id ${uuid} VERIFIED`)
223244
}
224245
}

0 commit comments

Comments
 (0)