@dubsdotapp/expo 0.5.33 → 0.5.34
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 +62 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +31 -0
- package/src/hooks/useCreateGame.ts +10 -3
- 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,14 @@ 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!`;
|
|
2115
2135
|
const gameInvite = {
|
|
2116
2136
|
gameId: createResult.gameId,
|
|
2117
2137
|
gameAddress: createResult.gameAddress,
|
|
2118
2138
|
title: event?.title,
|
|
2119
2139
|
league: event?.league,
|
|
2120
2140
|
gameType: "sports",
|
|
2121
|
-
buyIn:
|
|
2141
|
+
buyIn: wagerAmount,
|
|
2122
2142
|
status: "waiting",
|
|
2123
2143
|
homeTeam: home,
|
|
2124
2144
|
awayTeam: away,
|
|
@@ -6067,7 +6087,7 @@ function JoinGameSheet({
|
|
|
6067
6087
|
const [showSuccess, setShowSuccess] = useState35(false);
|
|
6068
6088
|
const [useCredit, setUseCredit] = useState35(false);
|
|
6069
6089
|
const oldestCredit = credits.length > 0 ? credits[0] : null;
|
|
6070
|
-
const canUseCredit = !!oldestCredit && oldestCredit.amountSOL >= game.buyIn;
|
|
6090
|
+
const canUseCredit = !!oldestCredit && Math.round(oldestCredit.amountSOL * 1e9) >= Math.round(game.buyIn * 1e9);
|
|
6071
6091
|
const overlayOpacity = useRef10(new Animated4.Value(0)).current;
|
|
6072
6092
|
const successScale = useRef10(new Animated4.Value(0)).current;
|
|
6073
6093
|
const successOpacity = useRef10(new Animated4.Value(0)).current;
|
|
@@ -7620,9 +7640,13 @@ function CreateGameSheet({
|
|
|
7620
7640
|
const t = useDubsTheme();
|
|
7621
7641
|
const { wallet } = useDubs();
|
|
7622
7642
|
const mutation = useCreateGame();
|
|
7643
|
+
const { credits, refetch: refetchCredits } = useCredits();
|
|
7623
7644
|
const [selectedTeam, setSelectedTeam] = useState39(null);
|
|
7624
7645
|
const [wager, setWager] = useState39(0.01);
|
|
7625
7646
|
const [showSuccess, setShowSuccess] = useState39(false);
|
|
7647
|
+
const [useCredit, setUseCredit] = useState39(false);
|
|
7648
|
+
const oldestCredit = credits.length > 0 ? credits[0] : null;
|
|
7649
|
+
const canUseCredit = !!oldestCredit;
|
|
7626
7650
|
const overlayOpacity = useRef14(new Animated8.Value(0)).current;
|
|
7627
7651
|
const successScale = useRef14(new Animated8.Value(0)).current;
|
|
7628
7652
|
const successOpacity = useRef14(new Animated8.Value(0)).current;
|
|
@@ -7677,11 +7701,16 @@ function CreateGameSheet({
|
|
|
7677
7701
|
id: event.id,
|
|
7678
7702
|
playerWallet: wallet.publicKey.toBase58(),
|
|
7679
7703
|
teamChoice: selectedTeam,
|
|
7680
|
-
|
|
7704
|
+
// When sponsoring, the on-chain instruction forces buy-in to
|
|
7705
|
+
// the credit's amount; pass that so client-side wager state
|
|
7706
|
+
// matches what gets recorded.
|
|
7707
|
+
wagerAmount: useCredit && oldestCredit ? oldestCredit.amountSOL : wager,
|
|
7708
|
+
useCredit: useCredit && canUseCredit ? true : void 0
|
|
7681
7709
|
});
|
|
7710
|
+
if (useCredit) refetchCredits();
|
|
7682
7711
|
} catch {
|
|
7683
7712
|
}
|
|
7684
|
-
}, [selectedTeam, wallet.publicKey, mutation.execute, event.id, wager]);
|
|
7713
|
+
}, [selectedTeam, wallet.publicKey, mutation.execute, event.id, wager, useCredit, oldestCredit, canUseCredit, refetchCredits]);
|
|
7685
7714
|
const statusLabel = STATUS_LABELS6[mutation.status] || "";
|
|
7686
7715
|
const startTime = event.startTime ? new Date(event.startTime) : null;
|
|
7687
7716
|
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 +7785,26 @@ function CreateGameSheet({
|
|
|
7756
7785
|
/* @__PURE__ */ jsx23(Text21, { style: [styles20.summaryValue, { color: t.success }], children: "Set the odds" })
|
|
7757
7786
|
] })
|
|
7758
7787
|
] }),
|
|
7759
|
-
selectedTeam && /* @__PURE__ */
|
|
7788
|
+
selectedTeam && canUseCredit && oldestCredit && /* @__PURE__ */ jsxs20(
|
|
7789
|
+
TouchableOpacity16,
|
|
7790
|
+
{
|
|
7791
|
+
style: [styles20.creditRow, { backgroundColor: useCredit ? "#22C55E18" : t.surface, borderColor: useCredit ? "#22C55E" : t.border }],
|
|
7792
|
+
activeOpacity: 0.8,
|
|
7793
|
+
onPress: () => setUseCredit((v) => !v),
|
|
7794
|
+
children: [
|
|
7795
|
+
/* @__PURE__ */ jsxs20(View20, { style: styles20.creditRowText, children: [
|
|
7796
|
+
/* @__PURE__ */ jsxs20(Text21, { style: [styles20.creditTitle, { color: useCredit ? "#22C55E" : t.text }], children: [
|
|
7797
|
+
"\u{1F381} Use my ",
|
|
7798
|
+
formatSol2(oldestCredit.amountSOL),
|
|
7799
|
+
" SOL credit"
|
|
7800
|
+
] }),
|
|
7801
|
+
/* @__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` })
|
|
7802
|
+
] }),
|
|
7803
|
+
/* @__PURE__ */ jsx23(View20, { style: [styles20.creditCheckbox, useCredit && { backgroundColor: "#22C55E", borderColor: "#22C55E" }], children: useCredit && /* @__PURE__ */ jsx23(Text21, { style: styles20.creditCheck, children: "\u2713" }) })
|
|
7804
|
+
]
|
|
7805
|
+
}
|
|
7806
|
+
),
|
|
7807
|
+
selectedTeam && !useCredit && /* @__PURE__ */ jsx23(
|
|
7760
7808
|
SolSlider,
|
|
7761
7809
|
{
|
|
7762
7810
|
value: wager,
|
|
@@ -7810,6 +7858,12 @@ var styles20 = StyleSheet21.create({
|
|
|
7810
7858
|
ctaButton: { marginTop: 16, height: 54, borderRadius: 14, justifyContent: "center", alignItems: "center" },
|
|
7811
7859
|
ctaText: { color: "#FFFFFF", fontSize: 16, fontWeight: "700" },
|
|
7812
7860
|
ctaLoading: { flexDirection: "row", alignItems: "center", gap: 10 },
|
|
7861
|
+
creditRow: { flexDirection: "row", alignItems: "center", gap: 12, marginTop: 12, padding: 12, borderRadius: 12, borderWidth: 1.5 },
|
|
7862
|
+
creditRowText: { flex: 1, gap: 2 },
|
|
7863
|
+
creditTitle: { fontSize: 14, fontWeight: "700" },
|
|
7864
|
+
creditSub: { fontSize: 12, fontWeight: "500" },
|
|
7865
|
+
creditCheckbox: { width: 22, height: 22, borderRadius: 11, borderWidth: 2, borderColor: "#3A3A3C", alignItems: "center", justifyContent: "center" },
|
|
7866
|
+
creditCheck: { color: "#FFFFFF", fontSize: 14, fontWeight: "900" },
|
|
7813
7867
|
successOverlay: { ...StyleSheet21.absoluteFillObject, zIndex: 100, alignItems: "center", justifyContent: "center", backgroundColor: "rgba(0,0,0,0.85)" },
|
|
7814
7868
|
successContent: { alignItems: "center", gap: 12 },
|
|
7815
7869
|
successEmoji: { fontSize: 64 },
|