@dubsdotapp/expo 0.5.32 → 0.5.33

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 CHANGED
@@ -131,11 +131,25 @@ interface JoinGameParams {
131
131
  gameId: string;
132
132
  teamChoice: 'home' | 'away' | 'draw';
133
133
  amount: number;
134
+ /**
135
+ * When true, spend one of the user's active 0.01 SOL streak credits
136
+ * instead of paying buy-in from the player's own wallet. The SDK
137
+ * picks the oldest credit (FIFO). The treasury covers buy-in + tx
138
+ * fee; the player only signs to consent. No-op if the user has no
139
+ * active credits — call useCredits() to check before enabling.
140
+ */
141
+ useCredit?: boolean;
134
142
  }
135
143
  interface JoinGameResult {
136
144
  gameId: string;
137
145
  transaction: string;
138
146
  gameAddress: string;
147
+ /**
148
+ * Set when this join was sponsored. The mutation hook echoes this
149
+ * back to confirmGame so the server can mark the credit as used.
150
+ */
151
+ promoCode?: string;
152
+ sponsorWallet?: string;
139
153
  }
140
154
  interface ConfirmGameParams {
141
155
  gameId: string;
@@ -145,6 +159,8 @@ interface ConfirmGameParams {
145
159
  wagerAmount?: number;
146
160
  role?: 'creator' | 'joiner';
147
161
  gameAddress?: string;
162
+ /** Echoed back from a sponsored joinGame so the server marks the credit as used. */
163
+ promoCode?: string;
148
164
  }
149
165
  interface ConfirmGameResult {
150
166
  gameId: string;
package/dist/index.d.ts CHANGED
@@ -131,11 +131,25 @@ interface JoinGameParams {
131
131
  gameId: string;
132
132
  teamChoice: 'home' | 'away' | 'draw';
133
133
  amount: number;
134
+ /**
135
+ * When true, spend one of the user's active 0.01 SOL streak credits
136
+ * instead of paying buy-in from the player's own wallet. The SDK
137
+ * picks the oldest credit (FIFO). The treasury covers buy-in + tx
138
+ * fee; the player only signs to consent. No-op if the user has no
139
+ * active credits — call useCredits() to check before enabling.
140
+ */
141
+ useCredit?: boolean;
134
142
  }
135
143
  interface JoinGameResult {
136
144
  gameId: string;
137
145
  transaction: string;
138
146
  gameAddress: string;
147
+ /**
148
+ * Set when this join was sponsored. The mutation hook echoes this
149
+ * back to confirmGame so the server can mark the credit as used.
150
+ */
151
+ promoCode?: string;
152
+ sponsorWallet?: string;
139
153
  }
140
154
  interface ConfirmGameParams {
141
155
  gameId: string;
@@ -145,6 +159,8 @@ interface ConfirmGameParams {
145
159
  wagerAmount?: number;
146
160
  role?: 'creator' | 'joiner';
147
161
  gameAddress?: string;
162
+ /** Echoed back from a sponsored joinGame so the server marks the credit as used. */
163
+ promoCode?: string;
148
164
  }
149
165
  interface ConfirmGameResult {
150
166
  gameId: string;
package/dist/index.js CHANGED
@@ -384,6 +384,19 @@ var DubsClient = class {
384
384
  };
385
385
  }
386
386
  async joinGame(params) {
387
+ if (params.useCredit) {
388
+ const res2 = await this.request("POST", "/games/join-sponsored", {
389
+ gameId: params.gameId,
390
+ teamChoice: params.teamChoice
391
+ });
392
+ return {
393
+ gameId: res2.gameId,
394
+ transaction: res2.transaction,
395
+ gameAddress: res2.gameAddress,
396
+ promoCode: res2.promoCode,
397
+ sponsorWallet: res2.sponsorWallet
398
+ };
399
+ }
387
400
  const res = await this.request(
388
401
  "POST",
389
402
  "/games/join",
@@ -2263,7 +2276,10 @@ function useJoinGame() {
2263
2276
  teamChoice: params.teamChoice,
2264
2277
  wagerAmount: params.amount,
2265
2278
  role: "joiner",
2266
- gameAddress: joinResult.gameAddress
2279
+ gameAddress: joinResult.gameAddress,
2280
+ // Pass through when this was a sponsored join — server marks
2281
+ // the credit as used after the on-chain confirm succeeds.
2282
+ promoCode: joinResult.promoCode
2267
2283
  };
2268
2284
  console.log("[useJoinGame] Step 3: Confirming with backend...", confirmParams);
2269
2285
  const confirmResult = await client.confirmGame(confirmParams);
@@ -6077,10 +6093,14 @@ function JoinGameSheet({
6077
6093
  const t = useDubsTheme();
6078
6094
  const { wallet } = useDubs();
6079
6095
  const mutation = useJoinGame();
6096
+ const { credits, refetch: refetchCredits } = useCredits();
6080
6097
  const isCustomGame = game.gameMode === CUSTOM_GAME_MODE;
6081
6098
  const [selectedTeam, setSelectedTeam] = (0, import_react41.useState)(null);
6082
6099
  const [wager, setWager] = (0, import_react41.useState)(game.buyIn);
6083
6100
  const [showSuccess, setShowSuccess] = (0, import_react41.useState)(false);
6101
+ const [useCredit, setUseCredit] = (0, import_react41.useState)(false);
6102
+ const oldestCredit = credits.length > 0 ? credits[0] : null;
6103
+ const canUseCredit = !!oldestCredit && oldestCredit.amountSOL >= game.buyIn;
6084
6104
  const overlayOpacity = (0, import_react41.useRef)(new import_react_native21.Animated.Value(0)).current;
6085
6105
  const successScale = (0, import_react41.useRef)(new import_react_native21.Animated.Value(0)).current;
6086
6106
  const successOpacity = (0, import_react41.useRef)(new import_react_native21.Animated.Value(0)).current;
@@ -6169,11 +6189,15 @@ function JoinGameSheet({
6169
6189
  playerWallet: wallet.publicKey.toBase58(),
6170
6190
  gameId: game.gameId,
6171
6191
  teamChoice: selectedTeam,
6172
- amount: wager
6192
+ // When useCredit is on, the on-chain instruction transfers
6193
+ // exactly the credit's amount; pass that as the wager.
6194
+ amount: useCredit && oldestCredit ? oldestCredit.amountSOL : wager,
6195
+ useCredit: useCredit && canUseCredit ? true : void 0
6173
6196
  });
6197
+ if (useCredit) refetchCredits();
6174
6198
  } catch {
6175
6199
  }
6176
- }, [selectedTeam, wallet.publicKey, mutation.execute, game.gameId, wager]);
6200
+ }, [selectedTeam, wallet.publicKey, mutation.execute, game.gameId, wager, useCredit, oldestCredit, canUseCredit, refetchCredits]);
6177
6201
  const statusLabel = STATUS_LABELS3[mutation.status] || "";
6178
6202
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
6179
6203
  import_react_native21.Modal,
@@ -6376,7 +6400,26 @@ function JoinGameSheet({
6376
6400
  ] })
6377
6401
  ] })
6378
6402
  ] }),
6379
- selectedTeam && !isPoolModeEnabled && !alreadyJoined && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
6403
+ selectedTeam && !alreadyJoined && canUseCredit && oldestCredit && /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
6404
+ import_react_native21.TouchableOpacity,
6405
+ {
6406
+ style: [styles15.creditRow, { backgroundColor: useCredit ? "#22C55E18" : t.surface, borderColor: useCredit ? "#22C55E" : t.border }],
6407
+ activeOpacity: 0.8,
6408
+ onPress: () => setUseCredit((v) => !v),
6409
+ children: [
6410
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_react_native21.View, { style: styles15.creditRowText, children: [
6411
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_react_native21.Text, { style: [styles15.creditTitle, { color: useCredit ? "#22C55E" : t.text }], children: [
6412
+ "\u{1F381} Use my ",
6413
+ formatSol(oldestCredit.amountSOL),
6414
+ " SOL credit"
6415
+ ] }),
6416
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_native21.Text, { style: [styles15.creditSub, { color: t.textMuted }], children: useCredit ? "Treasury covers this bet \u2014 wager locked to credit amount" : `${credits.length} credit${credits.length === 1 ? "" : "s"} available from your streak` })
6417
+ ] }),
6418
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_native21.View, { style: [styles15.creditCheckbox, useCredit && { backgroundColor: "#22C55E", borderColor: "#22C55E" }], children: useCredit && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_native21.Text, { style: styles15.creditCheck, children: "\u2713" }) })
6419
+ ]
6420
+ }
6421
+ ),
6422
+ selectedTeam && !isPoolModeEnabled && !alreadyJoined && !useCredit && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
6380
6423
  SolSlider,
6381
6424
  {
6382
6425
  value: wager,
@@ -6714,6 +6757,41 @@ var styles15 = import_react_native21.StyleSheet.create({
6714
6757
  flexDirection: "row",
6715
6758
  alignItems: "center",
6716
6759
  gap: 10
6760
+ },
6761
+ creditRow: {
6762
+ flexDirection: "row",
6763
+ alignItems: "center",
6764
+ gap: 12,
6765
+ marginTop: 12,
6766
+ padding: 12,
6767
+ borderRadius: 12,
6768
+ borderWidth: 1.5
6769
+ },
6770
+ creditRowText: {
6771
+ flex: 1,
6772
+ gap: 2
6773
+ },
6774
+ creditTitle: {
6775
+ fontSize: 14,
6776
+ fontWeight: "700"
6777
+ },
6778
+ creditSub: {
6779
+ fontSize: 12,
6780
+ fontWeight: "500"
6781
+ },
6782
+ creditCheckbox: {
6783
+ width: 22,
6784
+ height: 22,
6785
+ borderRadius: 11,
6786
+ borderWidth: 2,
6787
+ borderColor: "#3A3A3C",
6788
+ alignItems: "center",
6789
+ justifyContent: "center"
6790
+ },
6791
+ creditCheck: {
6792
+ color: "#FFFFFF",
6793
+ fontSize: 14,
6794
+ fontWeight: "900"
6717
6795
  }
6718
6796
  });
6719
6797