@dubsdotapp/expo 0.5.33 → 0.5.35
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 +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +64 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +31 -0
- package/src/hooks/useCreateGame.ts +19 -4
- package/src/types.ts +13 -0
- package/src/ui/game/CreateGameSheet.tsx +49 -4
- package/src/ui/game/JoinGameSheet.tsx +6 -1
package/dist/index.mjs
CHANGED
|
@@ -257,6 +257,22 @@ var DubsClient = class {
|
|
|
257
257
|
};
|
|
258
258
|
}
|
|
259
259
|
async createGame(params) {
|
|
260
|
+
if (params.useCredit) {
|
|
261
|
+
const res2 = await this.request("POST", "/games/create-sponsored", {
|
|
262
|
+
id: params.id,
|
|
263
|
+
teamChoice: params.teamChoice
|
|
264
|
+
});
|
|
265
|
+
return {
|
|
266
|
+
gameId: res2.gameId,
|
|
267
|
+
gameAddress: res2.gameAddress,
|
|
268
|
+
transaction: res2.transaction,
|
|
269
|
+
lockTimestamp: res2.lockTimestamp,
|
|
270
|
+
event: res2.event,
|
|
271
|
+
promoCode: res2.promoCode,
|
|
272
|
+
sponsorWallet: res2.sponsorWallet,
|
|
273
|
+
wagerAmount: res2.wagerAmount
|
|
274
|
+
};
|
|
275
|
+
}
|
|
260
276
|
const res = await this.request(
|
|
261
277
|
"POST",
|
|
262
278
|
"/games/create",
|
|
@@ -2087,14 +2103,18 @@ function useCreateGame() {
|
|
|
2087
2103
|
console.log("[useCreateGame] Step 2 done. Signature:", signature);
|
|
2088
2104
|
setStatus("confirming");
|
|
2089
2105
|
console.log("[useCreateGame] Step 3: Confirming with backend...");
|
|
2106
|
+
const wagerAmount = createResult.wagerAmount ?? params.wagerAmount;
|
|
2090
2107
|
const confirmResult = await client.confirmGame({
|
|
2091
2108
|
gameId: createResult.gameId,
|
|
2092
2109
|
playerWallet: params.playerWallet,
|
|
2093
2110
|
signature,
|
|
2094
2111
|
teamChoice: params.teamChoice,
|
|
2095
|
-
wagerAmount
|
|
2112
|
+
wagerAmount,
|
|
2096
2113
|
role: "creator",
|
|
2097
|
-
gameAddress: createResult.gameAddress
|
|
2114
|
+
gameAddress: createResult.gameAddress,
|
|
2115
|
+
// Echo the credit code through so the server marks it as used
|
|
2116
|
+
// after the on-chain confirm succeeds.
|
|
2117
|
+
promoCode: createResult.promoCode
|
|
2098
2118
|
});
|
|
2099
2119
|
console.log("[useCreateGame] Step 3 done.");
|
|
2100
2120
|
const result = {
|
|
@@ -2111,14 +2131,15 @@ function useCreateGame() {
|
|
|
2111
2131
|
const home = event?.opponents?.[0]?.name ?? null;
|
|
2112
2132
|
const away = event?.opponents?.[1]?.name ?? null;
|
|
2113
2133
|
const teamLabel = params.teamChoice === "home" ? teamNickname(home) : params.teamChoice === "away" ? teamNickname(away) : "Draw";
|
|
2114
|
-
const message = `I just placed a ${
|
|
2134
|
+
const message = `I just placed a ${wagerAmount} SOL bet on ${teamLabel} - Join me!`;
|
|
2135
|
+
const strTimestamp = typeof event?.startTime === "string" ? event.startTime.replace(/Z$/, "") : null;
|
|
2115
2136
|
const gameInvite = {
|
|
2116
2137
|
gameId: createResult.gameId,
|
|
2117
2138
|
gameAddress: createResult.gameAddress,
|
|
2118
2139
|
title: event?.title,
|
|
2119
2140
|
league: event?.league,
|
|
2120
2141
|
gameType: "sports",
|
|
2121
|
-
buyIn:
|
|
2142
|
+
buyIn: wagerAmount,
|
|
2122
2143
|
status: "waiting",
|
|
2123
2144
|
homeTeam: home,
|
|
2124
2145
|
awayTeam: away,
|
|
@@ -2127,7 +2148,7 @@ function useCreateGame() {
|
|
|
2127
2148
|
imageUrl: event?.media?.thumbnail ?? null,
|
|
2128
2149
|
strThumb: event?.media?.thumbnail ?? null,
|
|
2129
2150
|
strPoster: event?.media?.poster ?? null,
|
|
2130
|
-
strTimestamp
|
|
2151
|
+
strTimestamp,
|
|
2131
2152
|
creatorTeam: params.teamChoice,
|
|
2132
2153
|
creatorWallet: params.playerWallet
|
|
2133
2154
|
};
|
|
@@ -6067,7 +6088,7 @@ function JoinGameSheet({
|
|
|
6067
6088
|
const [showSuccess, setShowSuccess] = useState35(false);
|
|
6068
6089
|
const [useCredit, setUseCredit] = useState35(false);
|
|
6069
6090
|
const oldestCredit = credits.length > 0 ? credits[0] : null;
|
|
6070
|
-
const canUseCredit = !!oldestCredit && oldestCredit.amountSOL >= game.buyIn;
|
|
6091
|
+
const canUseCredit = !!oldestCredit && Math.round(oldestCredit.amountSOL * 1e9) >= Math.round(game.buyIn * 1e9);
|
|
6071
6092
|
const overlayOpacity = useRef10(new Animated4.Value(0)).current;
|
|
6072
6093
|
const successScale = useRef10(new Animated4.Value(0)).current;
|
|
6073
6094
|
const successOpacity = useRef10(new Animated4.Value(0)).current;
|
|
@@ -7620,9 +7641,13 @@ function CreateGameSheet({
|
|
|
7620
7641
|
const t = useDubsTheme();
|
|
7621
7642
|
const { wallet } = useDubs();
|
|
7622
7643
|
const mutation = useCreateGame();
|
|
7644
|
+
const { credits, refetch: refetchCredits } = useCredits();
|
|
7623
7645
|
const [selectedTeam, setSelectedTeam] = useState39(null);
|
|
7624
7646
|
const [wager, setWager] = useState39(0.01);
|
|
7625
7647
|
const [showSuccess, setShowSuccess] = useState39(false);
|
|
7648
|
+
const [useCredit, setUseCredit] = useState39(false);
|
|
7649
|
+
const oldestCredit = credits.length > 0 ? credits[0] : null;
|
|
7650
|
+
const canUseCredit = !!oldestCredit;
|
|
7626
7651
|
const overlayOpacity = useRef14(new Animated8.Value(0)).current;
|
|
7627
7652
|
const successScale = useRef14(new Animated8.Value(0)).current;
|
|
7628
7653
|
const successOpacity = useRef14(new Animated8.Value(0)).current;
|
|
@@ -7677,11 +7702,16 @@ function CreateGameSheet({
|
|
|
7677
7702
|
id: event.id,
|
|
7678
7703
|
playerWallet: wallet.publicKey.toBase58(),
|
|
7679
7704
|
teamChoice: selectedTeam,
|
|
7680
|
-
|
|
7705
|
+
// When sponsoring, the on-chain instruction forces buy-in to
|
|
7706
|
+
// the credit's amount; pass that so client-side wager state
|
|
7707
|
+
// matches what gets recorded.
|
|
7708
|
+
wagerAmount: useCredit && oldestCredit ? oldestCredit.amountSOL : wager,
|
|
7709
|
+
useCredit: useCredit && canUseCredit ? true : void 0
|
|
7681
7710
|
});
|
|
7711
|
+
if (useCredit) refetchCredits();
|
|
7682
7712
|
} catch {
|
|
7683
7713
|
}
|
|
7684
|
-
}, [selectedTeam, wallet.publicKey, mutation.execute, event.id, wager]);
|
|
7714
|
+
}, [selectedTeam, wallet.publicKey, mutation.execute, event.id, wager, useCredit, oldestCredit, canUseCredit, refetchCredits]);
|
|
7685
7715
|
const statusLabel = STATUS_LABELS6[mutation.status] || "";
|
|
7686
7716
|
const startTime = event.startTime ? new Date(event.startTime) : null;
|
|
7687
7717
|
const timeLabel = startTime ? startTime.toLocaleDateString("en-US", { weekday: "short", month: "short", day: "numeric" }) + " at " + startTime.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit" }) : "TBD";
|
|
@@ -7756,7 +7786,26 @@ function CreateGameSheet({
|
|
|
7756
7786
|
/* @__PURE__ */ jsx23(Text21, { style: [styles20.summaryValue, { color: t.success }], children: "Set the odds" })
|
|
7757
7787
|
] })
|
|
7758
7788
|
] }),
|
|
7759
|
-
selectedTeam && /* @__PURE__ */
|
|
7789
|
+
selectedTeam && canUseCredit && oldestCredit && /* @__PURE__ */ jsxs20(
|
|
7790
|
+
TouchableOpacity16,
|
|
7791
|
+
{
|
|
7792
|
+
style: [styles20.creditRow, { backgroundColor: useCredit ? "#22C55E18" : t.surface, borderColor: useCredit ? "#22C55E" : t.border }],
|
|
7793
|
+
activeOpacity: 0.8,
|
|
7794
|
+
onPress: () => setUseCredit((v) => !v),
|
|
7795
|
+
children: [
|
|
7796
|
+
/* @__PURE__ */ jsxs20(View20, { style: styles20.creditRowText, children: [
|
|
7797
|
+
/* @__PURE__ */ jsxs20(Text21, { style: [styles20.creditTitle, { color: useCredit ? "#22C55E" : t.text }], children: [
|
|
7798
|
+
"\u{1F381} Use my ",
|
|
7799
|
+
formatSol2(oldestCredit.amountSOL),
|
|
7800
|
+
" SOL credit"
|
|
7801
|
+
] }),
|
|
7802
|
+
/* @__PURE__ */ jsx23(Text21, { style: [styles20.creditSub, { color: t.textMuted }], children: useCredit ? "Treasury covers rent + buy-in" : `${credits.length} credit${credits.length === 1 ? "" : "s"} from your streak` })
|
|
7803
|
+
] }),
|
|
7804
|
+
/* @__PURE__ */ jsx23(View20, { style: [styles20.creditCheckbox, useCredit && { backgroundColor: "#22C55E", borderColor: "#22C55E" }], children: useCredit && /* @__PURE__ */ jsx23(Text21, { style: styles20.creditCheck, children: "\u2713" }) })
|
|
7805
|
+
]
|
|
7806
|
+
}
|
|
7807
|
+
),
|
|
7808
|
+
selectedTeam && !useCredit && /* @__PURE__ */ jsx23(
|
|
7760
7809
|
SolSlider,
|
|
7761
7810
|
{
|
|
7762
7811
|
value: wager,
|
|
@@ -7810,6 +7859,12 @@ var styles20 = StyleSheet21.create({
|
|
|
7810
7859
|
ctaButton: { marginTop: 16, height: 54, borderRadius: 14, justifyContent: "center", alignItems: "center" },
|
|
7811
7860
|
ctaText: { color: "#FFFFFF", fontSize: 16, fontWeight: "700" },
|
|
7812
7861
|
ctaLoading: { flexDirection: "row", alignItems: "center", gap: 10 },
|
|
7862
|
+
creditRow: { flexDirection: "row", alignItems: "center", gap: 12, marginTop: 12, padding: 12, borderRadius: 12, borderWidth: 1.5 },
|
|
7863
|
+
creditRowText: { flex: 1, gap: 2 },
|
|
7864
|
+
creditTitle: { fontSize: 14, fontWeight: "700" },
|
|
7865
|
+
creditSub: { fontSize: 12, fontWeight: "500" },
|
|
7866
|
+
creditCheckbox: { width: 22, height: 22, borderRadius: 11, borderWidth: 2, borderColor: "#3A3A3C", alignItems: "center", justifyContent: "center" },
|
|
7867
|
+
creditCheck: { color: "#FFFFFF", fontSize: 14, fontWeight: "900" },
|
|
7813
7868
|
successOverlay: { ...StyleSheet21.absoluteFillObject, zIndex: 100, alignItems: "center", justifyContent: "center", backgroundColor: "rgba(0,0,0,0.85)" },
|
|
7814
7869
|
successContent: { alignItems: "center", gap: 12 },
|
|
7815
7870
|
successEmoji: { fontSize: 64 },
|