Skip to content

Commit

Permalink
feat: fetch wheel price from api (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodiaslobo authored Nov 4, 2023
1 parent f8d5cc9 commit 4060a35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 14 additions & 4 deletions layout/Attendee/Wheel/Wheel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {

import ErrorMessage from "@components/ErrorMessage";

import { getWheelPrizes, getWheelLatestWins, spinWheel } from "@lib/api";
import {
getWheelPrizes,
getWheelPrice,
getWheelLatestWins,
spinWheel,
} from "@lib/api";

/*
Gets how long ago the given date/time was in a user friendly way (10 seconds ago, 1 minute ago, etc)
Expand Down Expand Up @@ -55,6 +60,7 @@ function WheelPage() {
const { user, refetchUser } = useAuth();

const [prizes, updatePrizes] = useState([]);
const [price, updatePrice] = useState(null);
const [latestWins, updateLatestWins] = useState([]);
const [error, updateError] = useState(false);
const [wheelMessage, updateWheelMessage] = useState(<></>);
Expand All @@ -65,6 +71,10 @@ function WheelPage() {
.then((response) => updatePrizes(response.data))
.catch((_) => updateError(true));

getWheelPrice()
.then((response) => updatePrice(response.price))
.catch((_) => updateError(true));

getWheelLatestWins()
.then((response) => updateLatestWins(response.data))
.catch((_) => updateError(true));
Expand All @@ -73,13 +83,13 @@ function WheelPage() {
useEffect(requestAllInfo, []);

const canSpin = () => {
return user.token_balance >= 20 && !isSpinning;
return user.token_balance >= price && !isSpinning;
};

const spinTheWheel = () => {
setIsSpinning(true);
updateState({ angle: 0, speed: angleSpeed });
user.token_balance -= 20;
user.token_balance -= price;
setTimeout(() => {
spinWheel()
.then((response) => {
Expand Down Expand Up @@ -202,7 +212,7 @@ function WheelPage() {
onClick={spinTheWheel}
>
<p className="select-none font-ibold font-bold">SPIN THE WHEEL</p>
<p className="select-none font-iregular">20 tokens💰</p>
<p className="select-none font-iregular">{price} tokens💰</p>
</button>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ export async function getWheelPrizes() {
return response.data;
}

export async function getWheelPrice() {
const response = await API.get("/api/roulette/price");

return response.data;
}

export async function getWheelRedeemables(uuid) {
const response = await API.get(`/api/roulette/redeem/${uuid}`);

Expand Down

0 comments on commit 4060a35

Please sign in to comment.