update
This commit is contained in:
+65
-2
@@ -32,13 +32,39 @@ export const api = {
|
||||
logout: () => request('/api/auth/logout', { method: 'POST' }),
|
||||
cases: () => request('/api/cases'),
|
||||
case: (id) => request(`/api/cases/${id}`),
|
||||
openCase: (id) => request(`/api/cases/${id}/open`, { method: 'POST' }),
|
||||
catalog: () => request('/api/catalog'),
|
||||
prestige: () => request('/api/prestige'),
|
||||
doPrestige: (choice) =>
|
||||
request('/api/prestige', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ choice }),
|
||||
}),
|
||||
openCase: (id, count = 1) =>
|
||||
request(`/api/cases/${id}/open`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ count }),
|
||||
}),
|
||||
inventory: () => request('/api/inventory'),
|
||||
sellInventory: (inventoryItemIds) =>
|
||||
request('/api/inventory/sell', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ inventoryItemIds }),
|
||||
}),
|
||||
updateAutoSell: (body) =>
|
||||
request('/api/inventory/auto-sell', {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(body),
|
||||
}),
|
||||
applyPendingAutoSell: (inventoryItemIds) =>
|
||||
request('/api/inventory/auto-sell/apply', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ inventoryItemIds }),
|
||||
}),
|
||||
setInventoryFavorite: (inventoryItemIds, favorite) =>
|
||||
request('/api/inventory/favorite', {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ inventoryItemIds, favorite }),
|
||||
}),
|
||||
shop: () => request('/api/shop'),
|
||||
shopBuy: (packageId) =>
|
||||
request('/api/shop/buy', {
|
||||
@@ -47,6 +73,15 @@ export const api = {
|
||||
}),
|
||||
shopAd: () => request('/api/shop/ad', { method: 'POST' }),
|
||||
feed: () => request('/api/feed'),
|
||||
feedAnnounce: (inventoryItemIds, caseName) => {
|
||||
const ids = Array.isArray(inventoryItemIds)
|
||||
? inventoryItemIds
|
||||
: [inventoryItemIds];
|
||||
return request('/api/feed/announce', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ inventoryItemIds: ids, caseName }),
|
||||
});
|
||||
},
|
||||
leaderboard: () => request('/api/leaderboard'),
|
||||
jackpot: () => request('/api/jackpot'),
|
||||
jackpotBet: (inventoryItemIds) =>
|
||||
@@ -72,6 +107,9 @@ export const api = {
|
||||
duelCancel: (id) => request(`/api/duels/${id}/cancel`, { method: 'POST' }),
|
||||
duelStart: (id) => request(`/api/duels/${id}/start`, { method: 'POST' }),
|
||||
profile: () => request('/api/profile'),
|
||||
playerProfile: (username) =>
|
||||
request(`/api/profile/player/${encodeURIComponent(username)}`),
|
||||
achievements: () => request('/api/achievements'),
|
||||
updateProfile: (body) =>
|
||||
request('/api/profile', { method: 'PATCH', body: JSON.stringify(body) }),
|
||||
changePassword: (currentPassword, newPassword) =>
|
||||
@@ -122,9 +160,34 @@ export const api = {
|
||||
};
|
||||
|
||||
export function formatCredits(cents) {
|
||||
return (Number(cents) / 100).toFixed(2);
|
||||
const fixed = (Number(cents) / 100).toFixed(2);
|
||||
const neg = fixed.startsWith('-');
|
||||
const body = neg ? fixed.slice(1) : fixed;
|
||||
const [intPart, dec] = body.split('.');
|
||||
const grouped = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, '\u202f');
|
||||
return `${neg ? '-' : ''}${grouped}.${dec}`;
|
||||
}
|
||||
|
||||
export function formatChance(pct) {
|
||||
return `${Number(pct || 0).toFixed(1)}%`;
|
||||
}
|
||||
|
||||
/** Format seconds as e.g. "2h 15m" or "45m". */
|
||||
export function formatPlayTime(seconds) {
|
||||
const s = Math.max(0, Math.floor(Number(seconds) || 0));
|
||||
const h = Math.floor(s / 3600);
|
||||
const m = Math.floor((s % 3600) / 60);
|
||||
if (h <= 0 && m <= 0) return s > 0 ? `${s}s` : '0m';
|
||||
if (h <= 0) return `${m}m`;
|
||||
if (m <= 0) return `${h}h`;
|
||||
return `${h}h ${m}m`;
|
||||
}
|
||||
|
||||
export function formatLastConnection(iso) {
|
||||
if (!iso) return 'Never';
|
||||
try {
|
||||
return new Date(iso).toLocaleString();
|
||||
} catch {
|
||||
return '—';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user