Skip to content

Commit 3306058

Browse files
committed
type fixes
1 parent 8883fd1 commit 3306058

7 files changed

Lines changed: 2068 additions & 4825 deletions

File tree

backend/src/auth/providers/auth.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ export class AuthService {
116116
return /^[GM][A-Z2-7]{55}$/.test(address);
117117
}
118118

119-
120119
/**
121120
* Handles refreshing of access tokens
122121
* @param refreshTokenDto - DTO containing the refresh token

backend/src/auth/providers/nonce.service.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ export class NonceService {
77
{ walletAddress: string; expiresAt: number; used: boolean }
88
>();
99

10-
public storeNonce(nonce: string, walletAddress: string, expiresAt: number): void {
10+
public storeNonce(
11+
nonce: string,
12+
walletAddress: string,
13+
expiresAt: number,
14+
): void {
1115
this.nonces.set(nonce, {
1216
walletAddress,
1317
expiresAt,
1418
used: false,
1519
});
16-
console.log(`[NonceService] Stored nonce: ${nonce}. Total: ${this.nonces.size}`);
20+
console.log(
21+
`[NonceService] Stored nonce: ${nonce}. Total: ${this.nonces.size}`,
22+
);
1723
}
1824

1925
public getNonce(nonce: string) {
@@ -29,12 +35,16 @@ export class NonceService {
2935
}
3036

3137
public verifyAndUseNonce(nonce: string, walletAddress: string): void {
32-
console.log(`[NonceService] Verifying nonce: ${nonce} for wallet ${walletAddress}`);
38+
console.log(
39+
`[NonceService] Verifying nonce: ${nonce} for wallet ${walletAddress}`,
40+
);
3341
const nonceData = this.nonces.get(nonce);
3442

3543
if (!nonceData) {
3644
const known = Array.from(this.nonces.keys()).join(', ');
37-
console.error(`[NonceService] Nonce NOT FOUND: ${nonce}. Map size: ${this.nonces.size}. Known nonces: ${known}`);
45+
console.error(
46+
`[NonceService] Nonce NOT FOUND: ${nonce}. Map size: ${this.nonces.size}. Known nonces: ${known}`,
47+
);
3848
throw new BadRequestException('Invalid nonce');
3949
}
4050

backend/src/auth/providers/wallet-login.provider.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
forwardRef,
3-
Inject,
4-
Injectable,
5-
UnauthorizedException,
6-
} from '@nestjs/common';
1+
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common';
72
import { JwtService } from '@nestjs/jwt';
83
import { ConfigType } from '@nestjs/config';
94
import { UsersService } from '../../users/providers/users.service';
@@ -14,6 +9,7 @@ import * as crypto from 'crypto';
149
import { StellarWalletLoginDto } from '../dtos/walletLogin.dto';
1510
import { ChallengeLevel } from '../../users/enums/challengeLevel.enum';
1611
import { AgeGroup } from '../../users/enums/ageGroup.enum';
12+
import { User } from 'src/users/user.entity';
1713

1814
@Injectable()
1915
export class StellarWalletLoginProvider {
@@ -58,13 +54,15 @@ export class StellarWalletLoginProvider {
5854
}
5955

6056
// Check if user exists in db
61-
let user: any = null;
57+
let user: User | null = null;
6258
try {
6359
user = await this.userService.getOneByWallet(dto.walletAddress);
64-
} catch (error) {
60+
} catch {
6561
// If user doesn't exist, getOneByWallet throws UnauthorizedException
6662
// We catch it here so we can proceed to auto-create the user
67-
console.log(`User not found for wallet ${dto.walletAddress}, will attempt auto-creation.`);
63+
console.log(
64+
`User not found for wallet ${dto.walletAddress}, will attempt auto-creation.`,
65+
);
6866
}
6967

7068
if (!user) {
@@ -138,9 +136,7 @@ export class StellarWalletLoginProvider {
138136
`[Signature Verification Result] FAILED for ${publicKey}`,
139137
);
140138
} else {
141-
console.log(
142-
`[Signature Verification Result] SUCCESS for ${publicKey}`,
143-
);
139+
console.log(`[Signature Verification Result] SUCCESS for ${publicKey}`);
144140
}
145141

146142
return isValid;

frontend/app/auth/signin/page.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Image from 'next/image';
1010
import ErrorBoundary from '@/components/ErrorBoundary';
1111
import { useToast } from '@/components/ui/ToastProvider';
1212
import { useStellarWalletAuth } from '@/hooks/useStellarWalletAuth';
13+
import { WalletType } from '@/lib/stellar/types';
1314

1415
const SignInPage = () => {
1516
const router = useRouter();
@@ -18,7 +19,6 @@ const SignInPage = () => {
1819
isConnecting,
1920
isSigning,
2021
isLoggingIn,
21-
error: walletError,
2222
connectAndLogin,
2323
clearError,
2424
} = useStellarWalletAuth();
@@ -163,14 +163,19 @@ const SignInPage = () => {
163163
clearError();
164164

165165
try {
166-
await connectAndLogin('freighter' as any);
166+
await connectAndLogin('freighter' as WalletType);
167167

168168
// Success - show toast and redirect
169169
showSuccess('Login Successful', 'Welcome back!');
170170
router.push('/dashboard');
171-
} catch (error: any) {
171+
} catch (error) {
172172
console.error("Wallet Connection Error:", error);
173173
// Error handling with user-friendly messages
174+
175+
const isErrorWithCode = (e: unknown): e is { code?: string; message?: string } => {
176+
return typeof e === 'object' && e !== null;
177+
};
178+
if (isErrorWithCode(error)) {
174179
if (error?.code === 'WALLET_NOT_INSTALLED') {
175180
showError(
176181
'Wallet Not Installed',
@@ -188,6 +193,7 @@ const SignInPage = () => {
188193
showError('Login Failed', error?.message || 'An unexpected error occurred');
189194
}
190195
}
196+
}
191197
};
192198

193199
return (

frontend/app/auth/signup/page.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Image from "next/image";
1010
import ErrorBoundary from "@/components/ErrorBoundary";
1111
import { useToast } from "@/components/ui/ToastProvider";
1212
import { useStellarWalletAuth } from "@/hooks/useStellarWalletAuth";
13+
import { WalletType } from "@/lib/stellar/types";
1314

1415

1516
const SignUpPage = () => {
@@ -271,15 +272,20 @@ const SignUpPage = () => {
271272
clearError();
272273

273274
try {
274-
await connectAndLogin("freighter" as any);
275+
await connectAndLogin("freighter" as WalletType);
275276

276277
// Success - show toast and redirect
277278
showSuccess("Login Successful", "Welcome back!");
278279
router.push("/dashboard");
279-
} catch (error: any) {
280+
} catch (error) {
280281
console.error("Wallet Connection Error:", error);
281-
// Error handling with user-friendly messages
282-
if (error?.code === "WALLET_NOT_INSTALLED") {
282+
const isErrorWithCode = (e: unknown): e is { code?: string; message?: string } => {
283+
return typeof e === 'object' && e !== null;
284+
};
285+
286+
if (isErrorWithCode(error)) {
287+
if (error.code === "WALLET_NOT_INSTALLED") {
288+
283289
showError(
284290
"Wallet Not Installed",
285291
"Please install Freighter wallet from freighter.app to continue",
@@ -302,6 +308,7 @@ const SignUpPage = () => {
302308
);
303309
}
304310
}
311+
}
305312
};
306313

307314
return (

frontend/lib/stellar/wallets.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
import freighterApi from '@stellar/freighter-api';
42
import type { WalletType } from './types';
53
import { StellarAuthError } from './types';
@@ -148,9 +146,9 @@ export async function signMessageWithWallet(
148146

149147
if (typeof signed === 'string') {
150148
signature = signed;
151-
} else if (signed instanceof Uint8Array || (signed && typeof (signed as any).length === 'number')) {
149+
} else if (signed instanceof Uint8Array || (signed && typeof (signed as ArrayLike<number>).length === 'number')) {
152150
// Robust conversion for Uint8Array to base64 in browser
153-
const binary = Array.from(new Uint8Array(signed as any))
151+
const binary = Array.from(new Uint8Array(signed as ArrayLike<number>))
154152
.map(b => String.fromCharCode(b))
155153
.join('');
156154
signature = window.btoa(binary);

0 commit comments

Comments
 (0)