Skip to content
Open
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
3 changes: 2 additions & 1 deletion packages/backend/configs/approved_admins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"admins": [
"0x23e67597f0898f747Fa3291C8920168adF9455D0",
"0x55A3B8e137104f50f2147d2Dc846dE38a16829d3",
"0x84fa5B3980ab22354504A05a7AFD640FD200122d"
"0x84fa5B3980ab22354504A05a7AFD640FD200122d",
"0x276f6d0a52bBd84A6fA6F3727E8e344aa63993C3"

]
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ export class BlockchainService {
});

this.logger.log(`Transaction submitted: ${hash}, waiting for confirmation...`);
await this.publicClient.waitForTransactionReceipt({
await this.publicClient.waitForTransactionReceipt({
hash,
timeout: 300_000, // 5 minutes timeout
pollingInterval: 2_000,
});
this.logger.log(`Identity registration confirmed for ${walletAddress}`);
return hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
HttpCode,
HttpStatus,
BadRequestException,
NotFoundException,
} from '@nestjs/common';
import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard';
import { SolvencyBlockchainService } from '../services/solvency-blockchain.service';
Expand Down Expand Up @@ -211,16 +212,35 @@ export class SolvencyController {
* Called after investor deposits collateral directly via contract
*/
@Post('sync-position')
@HttpCode(HttpStatus.CREATED)
@HttpCode(HttpStatus.OK)
async syncPosition(@Request() req: any, @Body() dto: { positionId: string; txHash: string; blockNumber: number }) {
const userAddress = req.user.walletAddress;

if (!dto.positionId || !dto.txHash) {
throw new BadRequestException('Missing required fields: positionId, txHash');
}

// Fetch position details from chain
const positionId = parseInt(dto.positionId);

// Check if position already exists to prevent duplicate key error
try {
const existingPosition = await this.positionService.getPosition(positionId);
if (existingPosition) {
return {
success: true,
message: 'Position already exists.',
position: existingPosition,
};
}
Comment on lines +228 to +234

Copilot AI Jan 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duplicate check logic has an issue. According to the service implementation, getPosition throws a NotFoundException when a position is not found. This means that if the position doesn't exist, the code will catch the exception at line 235, check if it's a NotFoundException at line 238, and then continue execution. However, the check at line 228 'if (existingPosition)' will never be reached when the position doesn't exist because an exception is thrown before the return statement. The early return at lines 229-233 will only execute when the position exists, which is the intended behavior, but the try-catch structure is confusing and could be simplified.

Suggested change
if (existingPosition) {
return {
success: true,
message: 'Position already exists.',
position: existingPosition,
};
}
return {
success: true,
message: 'Position already exists.',
position: existingPosition,
};

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaushalya4s5s7 look into these comments once

} catch (error) {
// If it's a NotFoundException, we can safely proceed to create the position.
// Otherwise, rethrow the error.
if (!(error instanceof NotFoundException)) {
throw error;
}
}

// Fetch position details from chain
const positionData = await this.blockchainService.getPositionFromChain(positionId);

// Verify position belongs to user
Expand Down