60 lines
1.6 KiB
Markdown
60 lines
1.6 KiB
Markdown
# Player profile + wallets — `client.player`
|
|
|
|
`PlayerDomain` (source: `src/domains/PlayerDomain.ts`) — the observable player
|
|
profile: identity plus currency wallets. Synced under revision key `profile`.
|
|
|
|
There is no separate wallet service in this SDK. Wallet balances are read from
|
|
the profile and are credited/debited server-side (admin wallet adjust, module
|
|
functions).
|
|
|
|
## Surface
|
|
|
|
`client.player` is a `SyncedState<PlayerProfile>`:
|
|
|
|
```ts
|
|
client.player.data // PlayerProfile | undefined
|
|
client.player.status // 'idle' | 'loading' | 'ready' | 'error'
|
|
client.player.onChange((snapshot) => { /* fires immediately */ });
|
|
await client.player.load();
|
|
await client.player.reload(); // force refetch
|
|
```
|
|
|
|
## Types
|
|
|
|
```ts
|
|
interface PlayerProfile {
|
|
identities?: PlayerProfileIdentity[];
|
|
player?: Player;
|
|
wallets?: Wallet[];
|
|
}
|
|
|
|
interface PlayerProfileIdentity {
|
|
createdAt: string;
|
|
provider: string; // 'device' | 'google' | 'apple' | 'custom' | 'custom:<name>'
|
|
subject: string;
|
|
}
|
|
|
|
interface Player {
|
|
createdAt?: string;
|
|
id?: string;
|
|
language?: string;
|
|
nickname?: string;
|
|
projectId?: string;
|
|
region?: string;
|
|
}
|
|
|
|
interface Wallet {
|
|
balance?: number;
|
|
currency?: string; // currency code configured in the dashboard
|
|
}
|
|
```
|
|
|
|
## Behavior notes
|
|
|
|
- Warmed automatically at login (with catalog).
|
|
- Kept fresh by the revision poll; call `reload()` after a module function
|
|
that mutates wallets.
|
|
- All fields are optional on the wire (`?`); code defensively.
|
|
- React: `useSyncExternalStore` maps directly onto `onChange` (see the SDK
|
|
README "React recipe").
|