@dubsdotapp/expo 0.5.31 → 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.mjs CHANGED
@@ -271,6 +271,19 @@ var DubsClient = class {
271
271
  };
272
272
  }
273
273
  async joinGame(params) {
274
+ if (params.useCredit) {
275
+ const res2 = await this.request("POST", "/games/join-sponsored", {
276
+ gameId: params.gameId,
277
+ teamChoice: params.teamChoice
278
+ });
279
+ return {
280
+ gameId: res2.gameId,
281
+ transaction: res2.transaction,
282
+ gameAddress: res2.gameAddress,
283
+ promoCode: res2.promoCode,
284
+ sponsorWallet: res2.sponsorWallet
285
+ };
286
+ }
274
287
  const res = await this.request(
275
288
  "POST",
276
289
  "/games/join",
@@ -2170,7 +2183,10 @@ function useJoinGame() {
2170
2183
  teamChoice: params.teamChoice,
2171
2184
  wagerAmount: params.amount,
2172
2185
  role: "joiner",
2173
- gameAddress: joinResult.gameAddress
2186
+ gameAddress: joinResult.gameAddress,
2187
+ // Pass through when this was a sponsored join — server marks
2188
+ // the credit as used after the on-chain confirm succeeds.
2189
+ promoCode: joinResult.promoCode
2174
2190
  };
2175
2191
  console.log("[useJoinGame] Step 3: Confirming with backend...", confirmParams);
2176
2192
  const confirmResult = await client.confirmGame(confirmParams);
@@ -3271,6 +3287,32 @@ function useEnterJackpot() {
3271
3287
 
3272
3288
  // src/hooks/useCredits.ts
3273
3289
  import { useState as useState26, useEffect as useEffect17, useCallback as useCallback24 } from "react";
3290
+ function useCredits() {
3291
+ const { client } = useDubs();
3292
+ const [credits, setCredits] = useState26([]);
3293
+ const [totalLamports, setTotalLamports] = useState26(0);
3294
+ const [totalSOL, setTotalSOL] = useState26(0);
3295
+ const [loading, setLoading] = useState26(false);
3296
+ const [error, setError] = useState26(null);
3297
+ const fetch2 = useCallback24(async () => {
3298
+ setLoading(true);
3299
+ setError(null);
3300
+ try {
3301
+ const result = await client.getCredits();
3302
+ setCredits(result.credits);
3303
+ setTotalLamports(result.totalLamports);
3304
+ setTotalSOL(result.totalSOL);
3305
+ } catch (err) {
3306
+ setError(err instanceof Error ? err : new Error(String(err)));
3307
+ } finally {
3308
+ setLoading(false);
3309
+ }
3310
+ }, [client]);
3311
+ useEffect17(() => {
3312
+ fetch2();
3313
+ }, [fetch2]);
3314
+ return { credits, totalLamports, totalSOL, loading, error, refetch: fetch2 };
3315
+ }
3274
3316
 
3275
3317
  // src/ui/AvatarEditor.tsx
3276
3318
  import {
@@ -6018,10 +6060,14 @@ function JoinGameSheet({
6018
6060
  const t = useDubsTheme();
6019
6061
  const { wallet } = useDubs();
6020
6062
  const mutation = useJoinGame();
6063
+ const { credits, refetch: refetchCredits } = useCredits();
6021
6064
  const isCustomGame = game.gameMode === CUSTOM_GAME_MODE;
6022
6065
  const [selectedTeam, setSelectedTeam] = useState35(null);
6023
6066
  const [wager, setWager] = useState35(game.buyIn);
6024
6067
  const [showSuccess, setShowSuccess] = useState35(false);
6068
+ const [useCredit, setUseCredit] = useState35(false);
6069
+ const oldestCredit = credits.length > 0 ? credits[0] : null;
6070
+ const canUseCredit = !!oldestCredit && oldestCredit.amountSOL >= game.buyIn;
6025
6071
  const overlayOpacity = useRef10(new Animated4.Value(0)).current;
6026
6072
  const successScale = useRef10(new Animated4.Value(0)).current;
6027
6073
  const successOpacity = useRef10(new Animated4.Value(0)).current;
@@ -6110,11 +6156,15 @@ function JoinGameSheet({
6110
6156
  playerWallet: wallet.publicKey.toBase58(),
6111
6157
  gameId: game.gameId,
6112
6158
  teamChoice: selectedTeam,
6113
- amount: wager
6159
+ // When useCredit is on, the on-chain instruction transfers
6160
+ // exactly the credit's amount; pass that as the wager.
6161
+ amount: useCredit && oldestCredit ? oldestCredit.amountSOL : wager,
6162
+ useCredit: useCredit && canUseCredit ? true : void 0
6114
6163
  });
6164
+ if (useCredit) refetchCredits();
6115
6165
  } catch {
6116
6166
  }
6117
- }, [selectedTeam, wallet.publicKey, mutation.execute, game.gameId, wager]);
6167
+ }, [selectedTeam, wallet.publicKey, mutation.execute, game.gameId, wager, useCredit, oldestCredit, canUseCredit, refetchCredits]);
6118
6168
  const statusLabel = STATUS_LABELS3[mutation.status] || "";
6119
6169
  return /* @__PURE__ */ jsxs15(
6120
6170
  Modal3,
@@ -6317,7 +6367,26 @@ function JoinGameSheet({
6317
6367
  ] })
6318
6368
  ] })
6319
6369
  ] }),
6320
- selectedTeam && !isPoolModeEnabled && !alreadyJoined && /* @__PURE__ */ jsx18(
6370
+ selectedTeam && !alreadyJoined && canUseCredit && oldestCredit && /* @__PURE__ */ jsxs15(
6371
+ TouchableOpacity11,
6372
+ {
6373
+ style: [styles15.creditRow, { backgroundColor: useCredit ? "#22C55E18" : t.surface, borderColor: useCredit ? "#22C55E" : t.border }],
6374
+ activeOpacity: 0.8,
6375
+ onPress: () => setUseCredit((v) => !v),
6376
+ children: [
6377
+ /* @__PURE__ */ jsxs15(View16, { style: styles15.creditRowText, children: [
6378
+ /* @__PURE__ */ jsxs15(Text16, { style: [styles15.creditTitle, { color: useCredit ? "#22C55E" : t.text }], children: [
6379
+ "\u{1F381} Use my ",
6380
+ formatSol(oldestCredit.amountSOL),
6381
+ " SOL credit"
6382
+ ] }),
6383
+ /* @__PURE__ */ jsx18(Text16, { 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` })
6384
+ ] }),
6385
+ /* @__PURE__ */ jsx18(View16, { style: [styles15.creditCheckbox, useCredit && { backgroundColor: "#22C55E", borderColor: "#22C55E" }], children: useCredit && /* @__PURE__ */ jsx18(Text16, { style: styles15.creditCheck, children: "\u2713" }) })
6386
+ ]
6387
+ }
6388
+ ),
6389
+ selectedTeam && !isPoolModeEnabled && !alreadyJoined && !useCredit && /* @__PURE__ */ jsx18(
6321
6390
  SolSlider,
6322
6391
  {
6323
6392
  value: wager,
@@ -6655,6 +6724,41 @@ var styles15 = StyleSheet16.create({
6655
6724
  flexDirection: "row",
6656
6725
  alignItems: "center",
6657
6726
  gap: 10
6727
+ },
6728
+ creditRow: {
6729
+ flexDirection: "row",
6730
+ alignItems: "center",
6731
+ gap: 12,
6732
+ marginTop: 12,
6733
+ padding: 12,
6734
+ borderRadius: 12,
6735
+ borderWidth: 1.5
6736
+ },
6737
+ creditRowText: {
6738
+ flex: 1,
6739
+ gap: 2
6740
+ },
6741
+ creditTitle: {
6742
+ fontSize: 14,
6743
+ fontWeight: "700"
6744
+ },
6745
+ creditSub: {
6746
+ fontSize: 12,
6747
+ fontWeight: "500"
6748
+ },
6749
+ creditCheckbox: {
6750
+ width: 22,
6751
+ height: 22,
6752
+ borderRadius: 11,
6753
+ borderWidth: 2,
6754
+ borderColor: "#3A3A3C",
6755
+ alignItems: "center",
6756
+ justifyContent: "center"
6757
+ },
6758
+ creditCheck: {
6759
+ color: "#FFFFFF",
6760
+ fontSize: 14,
6761
+ fontWeight: "900"
6658
6762
  }
6659
6763
  });
6660
6764
 
@@ -9400,6 +9504,7 @@ export {
9400
9504
  useConversations,
9401
9505
  useCreateCustomGame,
9402
9506
  useCreateGame,
9507
+ useCredits,
9403
9508
  useDirectMessages,
9404
9509
  useDubs,
9405
9510
  useDubsTheme,