Compare commits

..

No commits in common. "7aefe67aa06a0dcac3df2453c7b336d6747fecaa" and "98668a3fb07612cfc5c81f85c2a5d4febb0f13fc" have entirely different histories.

10 changed files with 158 additions and 216 deletions

View file

@ -54,13 +54,12 @@ public class SlotService {
SpinResult spinResult = new SpinResult(); SpinResult spinResult = new SpinResult();
spinResult.setStatus(status.name().toLowerCase()); spinResult.setStatus(status.name().toLowerCase());
this.balanceService.subtractFunds(user, betAmount);
if (status == Status.WIN) { if (status == Status.WIN) {
BigDecimal winAmount = betAmount.multiply(winSymbol.getPayoutMultiplier()); BigDecimal winAmount = betAmount.multiply(winSymbol.getPayoutMultiplier());
this.balanceService.addFunds(user, winAmount); this.balanceService.addFunds(user, winAmount);
spinResult.setAmount(winAmount); spinResult.setAmount(winAmount);
} else { } else {
this.balanceService.subtractFunds(user, betAmount);
spinResult.setAmount(betAmount); spinResult.setAmount(betAmount);
} }

View file

@ -51,19 +51,11 @@ export default class BlackjackComponent implements OnInit {
debtAmount = signal(0); debtAmount = signal(0);
ngOnInit(): void { ngOnInit(): void {
// Initial user load from server
this.userService.getCurrentUser().subscribe((user) => { this.userService.getCurrentUser().subscribe((user) => {
if (user) { if (user) {
this.balance.set(user.balance); this.balance.set(user.balance);
} }
}); });
// Subscribe to user updates for real-time balance changes
this.userService.currentUser$.subscribe((user) => {
if (user) {
this.balance.set(user.balance);
}
});
} }
private updateGameState(game: BlackjackGame) { private updateGameState(game: BlackjackGame) {
@ -92,19 +84,9 @@ export default class BlackjackComponent implements OnInit {
if (isGameOver) { if (isGameOver) {
console.log('Game is over, state:', game.state); console.log('Game is over, state:', game.state);
this.userService.refreshCurrentUser(); this.userService.refreshCurrentUser();
timer(1500).subscribe(() => {
// Get the latest balance before showing the result dialog this.showGameResult.set(true);
timer(1000).subscribe(() => { console.log('Game result dialog shown after delay');
this.userService.getCurrentUser().subscribe((user) => {
if (user) {
this.balance.set(user.balance);
// Show the result dialog after updating the balance
timer(500).subscribe(() => {
this.showGameResult.set(true);
console.log('Game result dialog shown after delay');
});
}
});
}); });
} }
} }
@ -183,20 +165,12 @@ export default class BlackjackComponent implements OnInit {
this.blackjackService.doubleDown(this.currentGameId()!).subscribe({ this.blackjackService.doubleDown(this.currentGameId()!).subscribe({
next: (game) => { next: (game) => {
this.updateGameState(game); this.updateGameState(game);
this.userService.getCurrentUser().subscribe((user) => {
// Wait a bit to ensure the backend has finished processing if (user && user.balance < 0) {
timer(1000).subscribe(() => { this.debtAmount.set(Math.abs(user.balance));
this.userService.getCurrentUser().subscribe((user) => { this.showDebtDialog.set(true);
if (user) { }
this.balance.set(user.balance);
if (user.balance < 0) {
this.debtAmount.set(Math.abs(user.balance));
this.showDebtDialog.set(true);
}
}
});
}); });
this.isActionInProgress.set(false); this.isActionInProgress.set(false);
}, },
error: (error) => { error: (error) => {
@ -210,13 +184,7 @@ export default class BlackjackComponent implements OnInit {
onCloseGameResult(): void { onCloseGameResult(): void {
console.log('Closing game result dialog'); console.log('Closing game result dialog');
this.showGameResult.set(false); this.showGameResult.set(false);
this.userService.refreshCurrentUser();
// Refresh the balance when dialog is closed and update local state
this.userService.getCurrentUser().subscribe((user) => {
if (user) {
this.balance.set(user.balance);
}
});
} }
onCloseDebtDialog(): void { onCloseDebtDialog(): void {

View file

@ -1,3 +1,15 @@
/* Open button styling - Matches lootbox component style */
.open-btn {
background: linear-gradient(90deg, #4338ca 0%, #8b5cf6 100%);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
transition: all 0.2s ease;
}
.open-btn:hover {
background: linear-gradient(90deg, #4f46e5 0%, #a78bfa 100%);
transform: translateY(-2px);
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.3);
}
/* Symbol colors */ /* Symbol colors */
.symbol-BAR { .symbol-BAR {
color: var(--color-accent-yellow); color: var(--color-accent-yellow);

View file

@ -74,8 +74,9 @@
<button <button
(click)="spin()" (click)="spin()"
class="button-primary px-4 py-1.5 font-bold" class="px-4 py-1.5 font-bold rounded"
[ngClass]="{ [ngClass]="{
'open-btn': hasEnoughBalance(),
'bg-gray-500 cursor-not-allowed': !hasEnoughBalance(), 'bg-gray-500 cursor-not-allowed': !hasEnoughBalance(),
}" }"
[disabled]="isSpinning || !hasEnoughBalance()" [disabled]="isSpinning || !hasEnoughBalance()"

View file

@ -114,15 +114,12 @@ export default class SlotsComponent implements OnInit, OnDestroy {
this.userService.updateLocalBalance(result.amount); this.userService.updateLocalBalance(result.amount);
} }
this.userService.refreshCurrentUser();
this.isSpinning = false; this.isSpinning = false;
}, 1500); }, 1500);
}, },
error: (err) => { error: (err) => {
console.error('Error spinning slot machine:', err); console.error('Error spinning slot machine:', err);
this.userService.updateLocalBalance(betAmount); this.userService.updateLocalBalance(betAmount);
this.userService.refreshCurrentUser();
this.isSpinning = false; this.isSpinning = false;
}, },
}); });

View file

@ -1,11 +1,4 @@
import { import { ChangeDetectionStrategy, Component, EventEmitter, inject, Input, Output } from '@angular/core';
ChangeDetectionStrategy,
Component,
EventEmitter,
inject,
Input,
Output,
} from '@angular/core';
import { TransactionService } from '@service/transaction.service'; import { TransactionService } from '@service/transaction.service';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { AsyncPipe, CurrencyPipe, DatePipe, NgIf } from '@angular/common'; import { AsyncPipe, CurrencyPipe, DatePipe, NgIf } from '@angular/common';

View file

@ -13,19 +13,6 @@ export class UserService {
private http: HttpClient = inject(HttpClient); private http: HttpClient = inject(HttpClient);
private authService = inject(AuthService); private authService = inject(AuthService);
constructor() {
// Initialize with the current user from AuthService if available
const currentUser = this.authService.getUser();
if (currentUser) {
this.currentUserSubject.next(currentUser);
}
// Subscribe to auth service user updates
this.authService.userSubject.subscribe(user => {
this.currentUserSubject.next(user);
});
}
public getCurrentUser(): Observable<User | null> { public getCurrentUser(): Observable<User | null> {
return this.http.get<User | null>('/backend/users/me').pipe( return this.http.get<User | null>('/backend/users/me').pipe(
catchError(() => EMPTY), catchError(() => EMPTY),

View file

@ -10,7 +10,6 @@ import { RouterModule } from '@angular/router';
import { AuthService } from '@service/auth.service'; import { AuthService } from '@service/auth.service';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { AnimatedNumberComponent } from '@blackjack/components/animated-number/animated-number.component'; import { AnimatedNumberComponent } from '@blackjack/components/animated-number/animated-number.component';
import { UserService } from '@service/user.service';
@Component({ @Component({
selector: 'app-navbar', selector: 'app-navbar',
@ -22,11 +21,9 @@ import { UserService } from '@service/user.service';
export class NavbarComponent implements OnInit, OnDestroy { export class NavbarComponent implements OnInit, OnDestroy {
isMenuOpen = false; isMenuOpen = false;
private authService: AuthService = inject(AuthService); private authService: AuthService = inject(AuthService);
private userService: UserService = inject(UserService);
isLoggedIn = this.authService.isLoggedIn(); isLoggedIn = this.authService.isLoggedIn();
private authSubscription!: Subscription; private authSubscription!: Subscription;
private userSubscription!: Subscription;
public balance = signal(0); public balance = signal(0);
ngOnInit() { ngOnInit() {
@ -35,22 +32,10 @@ export class NavbarComponent implements OnInit, OnDestroy {
this.balance.set(user?.balance ?? 0); this.balance.set(user?.balance ?? 0);
}, },
}); });
// Also subscribe to UserService for real-time balance updates
this.userSubscription = this.userService.currentUser$.subscribe({
next: (user) => {
if (user) {
this.balance.set(user.balance);
}
},
});
} }
ngOnDestroy() { ngOnDestroy() {
this.authSubscription.unsubscribe(); this.authSubscription.unsubscribe();
if (this.userSubscription) {
this.userSubscription.unsubscribe();
}
} }
logout() { logout() {