@dubsdotapp/expo 0.5.28 → 0.5.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +47 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +15 -2
- package/src/hooks/useCreateGame.ts +52 -0
- package/src/ui/game/JoinGameSheet.tsx +14 -7
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -651,8 +651,21 @@ export class DubsClient {
|
|
|
651
651
|
return this.request('GET', `/chat/messages${query ? `?${query}` : ''}`);
|
|
652
652
|
}
|
|
653
653
|
|
|
654
|
-
/**
|
|
655
|
-
|
|
654
|
+
/**
|
|
655
|
+
* Send a message to global chat. Mirrors the same payload accepted by
|
|
656
|
+
* the chat socket's `send_message` event so REST callers (e.g. the
|
|
657
|
+
* useCreateGame auto-share) can attach a `gameInvite` chip, GIF, P&L
|
|
658
|
+
* share, payment signature, or @mention IDs alongside the text.
|
|
659
|
+
*/
|
|
660
|
+
async sendChatMessage(params: {
|
|
661
|
+
message: string;
|
|
662
|
+
replyToId?: number;
|
|
663
|
+
gameInvite?: Record<string, unknown>;
|
|
664
|
+
mentions?: number[];
|
|
665
|
+
gifUrl?: string;
|
|
666
|
+
pnlShare?: Record<string, unknown>;
|
|
667
|
+
paymentSignature?: string;
|
|
668
|
+
}): Promise<{ message: any }> {
|
|
656
669
|
return this.request('POST', '/chat/message', params);
|
|
657
670
|
}
|
|
658
671
|
|
|
@@ -3,6 +3,18 @@ import { useDubs } from '../provider';
|
|
|
3
3
|
import { signAndSendBase64Transaction } from '../utils/transaction';
|
|
4
4
|
import type { CreateGameParams, MutationStatus } from '../types';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Pull a short, recognisable team name from a long display name. Mirrors
|
|
8
|
+
* the `getTeamNickname` helper the website uses when composing the
|
|
9
|
+
* "I just placed a bet on X" share message — keeps the chat-feed text
|
|
10
|
+
* tight ("Mariners" rather than "Seattle Mariners").
|
|
11
|
+
*/
|
|
12
|
+
function teamNickname(name: string | null | undefined): string {
|
|
13
|
+
if (!name) return 'TBD';
|
|
14
|
+
const parts = name.split(' ');
|
|
15
|
+
return parts.length > 2 ? parts[parts.length - 1] : name;
|
|
16
|
+
}
|
|
17
|
+
|
|
6
18
|
export interface CreateGameMutationResult {
|
|
7
19
|
gameId: string;
|
|
8
20
|
gameAddress: string;
|
|
@@ -67,6 +79,46 @@ export function useCreateGame() {
|
|
|
67
79
|
setData(result);
|
|
68
80
|
setStatus('success');
|
|
69
81
|
console.log('[useCreateGame] Complete!');
|
|
82
|
+
|
|
83
|
+
// Auto-share to global chat. Mirrors the dubs.app website's
|
|
84
|
+
// BetCreationModal behaviour so a bet placed from any client surfaces
|
|
85
|
+
// in chat with a tappable game-invite chip and a "Join me!" CTA.
|
|
86
|
+
// Fire-and-forget: a chat-broadcast failure must not surface as a
|
|
87
|
+
// create-game error, the on-chain bet is already settled.
|
|
88
|
+
try {
|
|
89
|
+
const event = createResult.event;
|
|
90
|
+
const home = event?.opponents?.[0]?.name ?? null;
|
|
91
|
+
const away = event?.opponents?.[1]?.name ?? null;
|
|
92
|
+
const teamLabel =
|
|
93
|
+
params.teamChoice === 'home' ? teamNickname(home) :
|
|
94
|
+
params.teamChoice === 'away' ? teamNickname(away) :
|
|
95
|
+
'Draw';
|
|
96
|
+
|
|
97
|
+
const message = `I just placed a ${params.wagerAmount} SOL bet on ${teamLabel} - Join me!`;
|
|
98
|
+
const gameInvite = {
|
|
99
|
+
gameId: createResult.gameId,
|
|
100
|
+
gameAddress: createResult.gameAddress,
|
|
101
|
+
title: event?.title,
|
|
102
|
+
league: event?.league,
|
|
103
|
+
gameType: 'sports',
|
|
104
|
+
buyIn: params.wagerAmount,
|
|
105
|
+
status: 'waiting',
|
|
106
|
+
homeTeam: home,
|
|
107
|
+
awayTeam: away,
|
|
108
|
+
homeTeamBadge: event?.opponents?.[0]?.imageUrl ?? null,
|
|
109
|
+
awayTeamBadge: event?.opponents?.[1]?.imageUrl ?? null,
|
|
110
|
+
imageUrl: event?.media?.thumbnail ?? null,
|
|
111
|
+
strThumb: event?.media?.thumbnail ?? null,
|
|
112
|
+
strPoster: event?.media?.poster ?? null,
|
|
113
|
+
strTimestamp: event?.startTime ?? null,
|
|
114
|
+
creatorTeam: params.teamChoice,
|
|
115
|
+
creatorWallet: params.playerWallet,
|
|
116
|
+
} as Record<string, unknown>;
|
|
117
|
+
await client.sendChatMessage({ message, gameInvite });
|
|
118
|
+
} catch (chatErr) {
|
|
119
|
+
console.warn('[useCreateGame] Auto chat-share failed (non-fatal):', chatErr);
|
|
120
|
+
}
|
|
121
|
+
|
|
70
122
|
return result;
|
|
71
123
|
} catch (err) {
|
|
72
124
|
console.error('[useCreateGame] FAILED:', err);
|
|
@@ -167,19 +167,26 @@ export function JoinGameSheet({
|
|
|
167
167
|
const homeBetsCount = bettors.filter(b => b.team === 'home').length;
|
|
168
168
|
const awayBetsCount = bettors.filter(b => b.team === 'away').length;
|
|
169
169
|
const drawBetsCount = bettors.filter(b => b.team === 'draw').length;
|
|
170
|
+
// Show comparable odds for every side by computing each as "if I bet
|
|
171
|
+
// `wager` on this team". Total pool grows by `wager` regardless of
|
|
172
|
+
// which side you pick, so newPool is constant; only the side pool
|
|
173
|
+
// shifts. Previously this only added `wager` to the *selected* side,
|
|
174
|
+
// which left an unbetted side with sidePool === 0 → odds shown as
|
|
175
|
+
// "—". Empty sides now show their (high) implied multiplier so the
|
|
176
|
+
// user can actually compare risk/return before committing.
|
|
170
177
|
const newPool = totalPool + wager;
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
const
|
|
178
|
+
const homeWith = homePool + wager;
|
|
179
|
+
const awayWith = awayPool + wager;
|
|
180
|
+
const drawWith = drawPool + wager;
|
|
174
181
|
return {
|
|
175
|
-
homeOdds:
|
|
176
|
-
awayOdds:
|
|
177
|
-
drawOdds:
|
|
182
|
+
homeOdds: homeWith > 0 ? (newPool / homeWith).toFixed(2) : '—',
|
|
183
|
+
awayOdds: awayWith > 0 ? (newPool / awayWith).toFixed(2) : '—',
|
|
184
|
+
drawOdds: drawWith > 0 ? (newPool / drawWith).toFixed(2) : '—',
|
|
178
185
|
homeBets: homeBetsCount,
|
|
179
186
|
awayBets: awayBetsCount,
|
|
180
187
|
drawBets: drawBetsCount,
|
|
181
188
|
};
|
|
182
|
-
}, [totalPool, homePool, awayPool, drawPool, bettors, wager
|
|
189
|
+
}, [totalPool, homePool, awayPool, drawPool, bettors, wager]);
|
|
183
190
|
|
|
184
191
|
const selectedOdds = selectedTeam === 'home' ? homeOdds : selectedTeam === 'away' ? awayOdds : selectedTeam === 'draw' ? drawOdds : '—';
|
|
185
192
|
const potentialWinnings = selectedOdds !== '—' ? formatSol(parseFloat(selectedOdds) * wager) : '—';
|