Files
HokmPlay/src/lib/session-store.ts
T
soroush.asadi cb27a16dc1 feat: UNO-style table, social hub, cosmetics, speed mode, store IAB
Game table & play
- UNO-style restyle: suit-aware bolder cards (+xl size), pulsing playable glow,
  big "YOUR TURN" pill, active-seat ring, trick-win particle burst, round
  confetti, match coin-rain.
- Per-league turn time via turnMsForStake: 15s starter/AI, 10s pro, 7s expert;
  mirrored server-side in GameRoom.TurnMs.
- Speed (Blitz) mode for vs-AI/private: 5s turns, race to 5, ~halved pacing.
- Matchmaking waits ~15s (randomized 12-18s) then fills bots; elapsed timer + hint.

Rewards / gifts
- Richer post-match modal (floating coins, XP bar), celebration overlay reveals
  the unlocked sticker pack, boosted daily rewards (client+server synced),
  themed 7-day daily with special day-7.

Social
- Public profile modal (identity, stats, achievement board) from leaderboard /
  friends / discover / end-of-game roster; rate-limited add-friend (10/hour).
- Social hub: Friends / Discover (player search + suggestions) / Messages inbox.
- Profile gender (shown in finder/profile) + social links with public/friends/
  hidden visibility, enforced server-side.

Cosmetics
- Distinct card backs: per-design pattern families (stripes/argyle/grid/dots/
  rays/scales/crosshatch/royal/filigree/gem) + luxury motifs (lib/cardBack.ts),
  consistent on table/shop/profile; +Peacock/Rose-Gold backs.
- Purchasable titles (shop Titles section); title shown under the seat on the
  table and in discover/public profile.
- 10 new sticker packs (banter/kol-kol, Persian trends, court cards, moods).
- Persistent level+XP bar on Home and every inner screen.

Payments
- Buy-coins gateway opens in a new tab (no SPA dead-end) + focus refresh.
- Store IAB scaffolding: Cafe Bazaar deep-link purchase + redirect-token capture,
  Myket native-bridge contract, server-side IabService.Verify for both stores,
  config-driven via Iab__* env. POST /api/coins/iab/verify (JWT).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-06 18:39:24 +03:30

104 lines
3.0 KiB
TypeScript

"use client";
import { create } from "zustand";
import { getService } from "./online/service";
import { AuthSession, UserProfile } from "./online/types";
interface SessionStore {
session: AuthSession | null;
profile: UserProfile | null;
loading: boolean;
isAuthed: boolean;
init: () => Promise<void>;
refreshProfile: () => Promise<void>;
setProfile: (p: UserProfile) => void;
requestOtp: (phone: string) => Promise<{ devCode?: string }>;
verifyOtp: (phone: string, code: string) => Promise<void>;
signInEmail: (email: string, password: string) => Promise<void>;
signUpEmail: (email: string, password: string, name: string) => Promise<void>;
signInGoogle: () => Promise<void>;
signOut: () => Promise<void>;
updateProfile: (
patch: Partial<
Pick<
UserProfile,
| "displayName" | "avatar" | "avatarImage" | "title" | "cardFront" | "cardBack"
| "gender" | "socials" | "socialsVisibility"
>
>
) => Promise<void>;
upgradePlan: () => Promise<void>;
}
export const useSessionStore = create<SessionStore>((set, get) => ({
session: null,
profile: null,
loading: true,
isAuthed: false,
init: async () => {
const svc = getService();
// keep the profile in sync with server-pushed updates (entry charge, reward…)
svc.onProfile((p) => set({ profile: p }));
const restored = await svc.restore();
if (restored) {
set({ session: restored.session, profile: restored.profile, isAuthed: true, loading: false });
} else {
// ensure a (guest) profile exists so the top bar can render
const profile = await svc.getProfile();
set({ profile, isAuthed: false, loading: false });
}
},
refreshProfile: async () => {
const profile = await getService().getProfile();
set({ profile });
},
setProfile: (p) => set({ profile: p }),
requestOtp: (phone) => getService().requestOtp(phone),
verifyOtp: async (phone, code) => {
const session = await getService().verifyOtp(phone, code);
const profile = await getService().getProfile();
set({ session, profile, isAuthed: true });
},
signInEmail: async (email, password) => {
const session = await getService().signInEmail(email, password);
const profile = await getService().getProfile();
set({ session, profile, isAuthed: true });
},
signUpEmail: async (email, password, name) => {
const session = await getService().signUpEmail(email, password, name);
const profile = await getService().getProfile();
set({ session, profile, isAuthed: true });
},
signInGoogle: async () => {
const session = await getService().signInGoogle();
const profile = await getService().getProfile();
set({ session, profile, isAuthed: true });
},
signOut: async () => {
await getService().signOut();
set({ session: null, isAuthed: false });
},
updateProfile: async (patch) => {
const profile = await getService().updateProfile(patch);
set({ profile });
},
upgradePlan: async () => {
const profile = await getService().upgradePlan();
set({ profile });
},
}));