Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ define(['./workbox-20a2f87f'], (function (workbox) { 'use strict';
"revision": "3ca0b8505b4bec776b69afdba2768812"
}, {
"url": "index.html",
"revision": "0.8j5p84f6nhg"
"revision": "0.tvrddraj1fg"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
Expand Down
31 changes: 8 additions & 23 deletions client/src/components/SpawnBeast/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// React and external libraries
import { useEffect, useMemo, useState } from "react";
import { useEffect, useState } from "react";
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useAccount } from "@starknet-react/core";
import { Account, addAddressPadding } from "starknet";
import { Account } from "starknet";
import { useDojoSDK } from "@dojoengine/sdk/react";

// Internal components
Expand All @@ -13,7 +13,6 @@ import ProgressBar from '../ProgressBar/index.tsx';
// Hooks and Contexts
import { useSystemCalls } from "../../dojo/useSystemCalls.ts";
import { usePlayer } from "../../hooks/usePlayers.tsx";
import { useBeasts, fetchBeastsData } from "../../hooks/useBeasts";

// Types
import type {
Expand All @@ -38,13 +37,6 @@ const SpawnBeast: React.FC<SpawnBeastProps> = ({ className = '' }) => {
const navigate = useNavigate();
const [searchParams] = useSearchParams();

const userAddress = useMemo(() =>
account ? addAddressPadding(account.address).toLowerCase() : '',
[account]
);

const { myBeastsData, refetch } = useBeasts(userAddress);

// State
const [state, setState] = useState<SpawnBeastState>({
loading: false,
Expand Down Expand Up @@ -82,7 +74,7 @@ const SpawnBeast: React.FC<SpawnBeastProps> = ({ className = '' }) => {

// Esperar un momento para que se actualice el player
await new Promise(resolve => setTimeout(resolve, 2000));
setSpawnProgress({ progress: 40, message: 'Player account created!' });
if(spawnPlayerTx) setSpawnProgress({ progress: 40, message: 'Player account created!' });
}

setSpawnProgress({ progress: 50, message: 'Generating your beast' });
Expand All @@ -91,18 +83,11 @@ const SpawnBeast: React.FC<SpawnBeastProps> = ({ className = '' }) => {
await new Promise(resolve => setTimeout(resolve, 2000));

if (spawnTx && spawnTx.code === "SUCCESS") {
refetch();
const beastsData = await fetchBeastsData();
console.log('beastsData', beastsData);
setSpawnProgress({ progress: 70, message: 'Beast generated! Setting as current' });
const newBeast = myBeastsData[0];
if (newBeast) {
setSpawnProgress({ progress: 90, message: 'Finalizing setup' });
setSpawnProgress({ progress: 100, message: 'Your beast is ready!' });
setTimeout(() => {
navigate('/play');
}, 1000);
}
setSpawnProgress({ progress: 70, message: 'Beast generated!' });
setTimeout(() => {
setSpawnProgress({ progress: 100, message: 'Finalizing setup' });
navigate('/play');
}, 2000);
}
} catch (error) {
console.error('Error spawning player:', error);
Expand Down