chore: market app build
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from "vue";
|
||||
import { polylanSubmitterApiGetUserInfo, marketApiCreateBet, marketApiListUserBets, marketApiCloseMarket, marketApiResolveMarket } from "../api";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { marketApiCreateBet, marketApiCloseMarket, marketApiResolveMarket } from "../api";
|
||||
import { useMarketStore } from "../stores/market";
|
||||
import type { Market, MarketOption } from "../types";
|
||||
import type { UserInfoOut, UserBetSchema } from "../api/types.gen";
|
||||
import type { UserBetSchema } from "../api/types.gen";
|
||||
|
||||
const props = defineProps<{
|
||||
market: Market;
|
||||
@@ -12,12 +14,13 @@ const emit = defineEmits<{
|
||||
refresh: [];
|
||||
}>();
|
||||
|
||||
const marketStore = useMarketStore();
|
||||
const { userInfo, userBets } = storeToRefs(marketStore);
|
||||
|
||||
const selectedOption = ref<string | null>(null);
|
||||
const betAmount = ref<number>(0);
|
||||
const loading = ref(false);
|
||||
const error = ref<string>("");
|
||||
const userInfo = ref<UserInfoOut | undefined>();
|
||||
const userBets = ref<UserBetSchema[]>([]);
|
||||
const existingBet = ref<UserBetSchema | null>(null);
|
||||
const showResolveModal = ref(false);
|
||||
const selectedWinningOption = ref<string | null>(null);
|
||||
@@ -139,7 +142,8 @@ const placeBet = async () => {
|
||||
|
||||
if (!response.error) {
|
||||
// Reload user bets to reflect the new bet
|
||||
await loadUserBets();
|
||||
await marketStore.loadUserBets();
|
||||
updateExistingBet();
|
||||
betAmount.value = 0;
|
||||
} else {
|
||||
const err = response.error as any;
|
||||
@@ -158,32 +162,20 @@ const placeBet = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const initializeUserInfo = async () => {
|
||||
const response = await polylanSubmitterApiGetUserInfo();
|
||||
if (response.data) {
|
||||
userInfo.value = response.data;
|
||||
}
|
||||
};
|
||||
onMounted(() => {
|
||||
// Update existing bet when component mounts or userBets changes
|
||||
updateExistingBet();
|
||||
});
|
||||
|
||||
const loadUserBets = async () => {
|
||||
const response = await marketApiListUserBets();
|
||||
if (response.data) {
|
||||
userBets.value = response.data;
|
||||
// Find if user has a bet on this market
|
||||
existingBet.value = response.data.find(bet => bet.market?.uuid === props.market.uuid) || null;
|
||||
const updateExistingBet = () => {
|
||||
if (userBets.value) {
|
||||
existingBet.value = userBets.value.find(bet => bet.market?.uuid === props.market.uuid) || null;
|
||||
if (existingBet.value) {
|
||||
selectedOption.value = existingBet.value.option.uuid;
|
||||
betAmount.value = existingBet.value.amount;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
await initializeUserInfo();
|
||||
if (userInfo.value?.is_authenticated) {
|
||||
await loadUserBets();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, computed } from "vue";
|
||||
import { marketApiListUserBets } from "../api";
|
||||
import type { UserBetSchema } from "../api/types.gen";
|
||||
import { computed } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useMarketStore } from "../stores/market";
|
||||
|
||||
defineEmits<{
|
||||
refresh: [];
|
||||
}>();
|
||||
|
||||
const userBets = ref<UserBetSchema[]>([]);
|
||||
const loading = ref(true);
|
||||
const marketStore = useMarketStore();
|
||||
const { userBets } = storeToRefs(marketStore);
|
||||
const loading = computed(() => marketStore.isLoading);
|
||||
|
||||
const totalBetAmount = computed(() => {
|
||||
return userBets.value.reduce((sum, bet) => sum + bet.amount, 0);
|
||||
@@ -35,14 +36,6 @@ const openBets = computed(() => {
|
||||
const totalWinnings = computed(() => {
|
||||
return winningBets.value.reduce((sum, bet) => sum + bet.amount, 0);
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
const response = await marketApiListUserBets();
|
||||
if (response.data) {
|
||||
userBets.value = response.data;
|
||||
}
|
||||
loading.value = false;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user