@dubsdotapp/expo 0.5.27 → 0.5.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dubsdotapp/expo",
3
- "version": "0.5.27",
3
+ "version": "0.5.29",
4
4
  "description": "React Native SDK for the Dubs betting platform",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -87,8 +87,11 @@ export function ChatProvider({ children, autoConnect = true }: ChatProviderProps
87
87
  const refreshMessages = useCallback(async () => {
88
88
  try {
89
89
  const res = await client.getChatMessages({ limit: 30 });
90
- // API returns newest-first keep that order for inverted FlatList
91
- setMessages(res.messages);
90
+ // The dev API returns messages oldest-first (chatService applies a
91
+ // .reverse() for legacy chat-order callers). Inverted chat FlatLists
92
+ // — and onNewMessage's prepend below — assume newest-first. Flip
93
+ // here so the internal store is consistent everywhere.
94
+ setMessages([...res.messages].reverse());
92
95
  } catch (err) {
93
96
  console.error('[Dubs:ChatProvider] Failed to load messages:', err);
94
97
  }
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
- /** Send a message to global chat */
655
- async sendChatMessage(params: { message: string; replyToId?: number }): Promise<{ message: any }> {
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);