diff --git a/src/app/Components/Accounts/Account.tsx b/src/app/Components/Accounts/Account.tsx index a6b9461..9252091 100644 --- a/src/app/Components/Accounts/Account.tsx +++ b/src/app/Components/Accounts/Account.tsx @@ -3,6 +3,7 @@ import React, { useEffect, useState } from "react"; import { IResourceAccount, IConversionPair, IGameConfig } from "typings"; import { resourceToFc, resourceToBg } from "../../../utils/helpers"; import ResourceModal from "./ResourceModal"; +import { BiLoaderAlt } from "react-icons/bi"; const ResourceAccount = (props: { account: IResourceAccount; @@ -14,6 +15,7 @@ const ResourceAccount = (props: { IConversionPair | undefined >(undefined); const [conversionRate, setConversionRate] = useState(0); + const [isLoading, setIsLoading] = useState(false); const handleConversionPair = (amount: number, resourceType: string) => { const updatedPair = { @@ -31,9 +33,20 @@ const ResourceAccount = (props: { return rate; }; - const handleSellResource = () => { - conversionPair && props.sellResource([conversionPair]); - setShowModal(false); + const handleSellResource = async () => { + if (conversionPair) { + setIsLoading(true); + try { + await props.sellResource([conversionPair]); + } catch (error) { + // Show error here + } finally { + setShowModal(false); + } + conversionPair && props.sellResource([conversionPair]); + setIsLoading(false); + setShowModal(false); + } }; useEffect(() => { @@ -67,7 +80,12 @@ const ResourceAccount = (props: { /> -
+
+ {isLoading && ( +
+ +
+ )} { + setIsLoading(true); + try { + // Create the source + await props.upgradeInventoryItem( + props.inventoryItem.id, + props.inventoryItem.storeItem.id + ); + } catch (error) { + // Handle error if needed (e.g., show a notification or log the error) + } finally { + setIsLoading(false); + } + }; + const renderUpgradeButton = () => { // If no staking source if (!props.stakes) return "No staking source"; @@ -37,30 +56,31 @@ const InventoryItem = (props: { // Show price return ( <> - + ) : ( + + + + + + )} {`$${ props.inventoryItem.storeItem.upgrades[currentTierIndex + 1].price diff --git a/src/app/Components/Staking/StakingSource.tsx b/src/app/Components/Staking/StakingSource.tsx index 3542a07..8e07fe0 100644 --- a/src/app/Components/Staking/StakingSource.tsx +++ b/src/app/Components/Staking/StakingSource.tsx @@ -6,6 +6,7 @@ import { } from "../../../utils/helpers"; import SelectDropdown from "../SelectDropdown"; import Image from "next/image"; +import { BiLoaderAlt } from "react-icons/bi"; const StakingSource = (props: { stakingSource: IStakingSource; @@ -25,7 +26,7 @@ const StakingSource = (props: { null ); const [selectedWellId, setSelectedWellId] = useState(null); - const [showInfo, setShowInfo] = useState(false); + const [isLoading, setIsLoading] = useState(false); // Check if claimable every second useEffect(() => { @@ -54,18 +55,33 @@ const StakingSource = (props: { }; }); - const handleStartMining = () => { + const handleStartMining = async () => { if (selectedInventoryItemId && selectedWellId && selectedStoreItemId) { - props.startStake( - selectedInventoryItemId, - selectedStoreItemId, - selectedWellId - ); + setIsLoading(true); + + try { + await props.startStake( + selectedInventoryItemId, + selectedStoreItemId, + selectedWellId + ); + } catch (error) { + // Handle error if needed (e.g., show a notification or log the error) + } finally { + setIsLoading(false); + } } }; - const handleClaim = (stakingEventId: number) => { - props.claimStake(stakingEventId); + const handleClaim = async (stakingEventId: number) => { + setIsLoading(true); + try { + await props.claimStake(stakingEventId); + } catch (error) { + // Handle error if needed (e.g., show a notification or log the error) + } finally { + setIsLoading(false); + } }; const handleSelectChange = ( @@ -129,8 +145,13 @@ const StakingSource = (props: { className="mr-4" />
-
-
+
+ {isLoading && ( +
+ +
+ )} +

{props.stakingSource.name}{" "} @@ -144,10 +165,9 @@ const StakingSource = (props: {

{props.stakingSource.description}

-

Inventory

-
+
{activeStakes.length > 0 && ( -
+ <> {activeStakes.map((stake, id) => (
))} -
+ )} {props.inventoryItems && (
diff --git a/src/app/Components/Staking/StakingSourcesView.tsx b/src/app/Components/Staking/StakingSourcesView.tsx index 91644c2..2fad0bd 100644 --- a/src/app/Components/Staking/StakingSourcesView.tsx +++ b/src/app/Components/Staking/StakingSourcesView.tsx @@ -1,7 +1,8 @@ "use client"; -import React from "react"; +import React, { useState } from "react"; import { IInventoryItem, IStakingSource } from "typings"; import StakingSource from "./StakingSource"; +import { BiLoaderAlt } from "react-icons/bi"; const StakingSourcesView = (props: { stakingSources: IStakingSource[] | null; @@ -14,30 +15,50 @@ const StakingSourcesView = (props: { ) => void; createStakingSource: () => void; }) => { + const [isLoading, setIsLoading] = useState(false); + + const handleCreateStakingSource = async () => { + setIsLoading(true); + try { + // Create the source + await props.createStakingSource(); + } catch (error) { + // Handle error if needed (e.g., show a notification or log the error) + } finally { + setIsLoading(false); + } + }; + return (

Your Moons

- + ) : ( + + + + + + )}
{props.stakingSources ? ( diff --git a/src/app/Components/Staking/StakingSourcesViewBackup.tsx b/src/app/Components/Staking/StakingSourcesViewBackup.tsx deleted file mode 100644 index ff13c59..0000000 --- a/src/app/Components/Staking/StakingSourcesViewBackup.tsx +++ /dev/null @@ -1,58 +0,0 @@ -"use client"; -import React from "react"; -import { IInventoryItem, IStakingSource } from "typings"; -import StakingSource from "./StakingSource"; - -const StakingSourcesView = (props: { - stakingSources: IStakingSource[] | null; - inventoryItems: IInventoryItem[] | null | undefined; - claimStake: (stakingEventId: number) => void; - startStake: ( - inventoryItemId: number, - storeItemId: string, - wellId: number - ) => void; - createStakingSource: () => void; -}) => { - return ( -
-
-

Your Moons

- -
-
- {props.stakingSources && - props.stakingSources.length > 0 && - props.stakingSources.map((stakingSource, id) => ( - - ))} -
-
- ); -}; - -export default StakingSourcesView; diff --git a/src/app/Components/Store/StoreItem.tsx b/src/app/Components/Store/StoreItem.tsx index 13afbb9..447cfd9 100644 --- a/src/app/Components/Store/StoreItem.tsx +++ b/src/app/Components/Store/StoreItem.tsx @@ -1,13 +1,28 @@ "use client"; -import React from "react"; +import React, { useState } from "react"; import { IStoreItem } from "typings"; import CardLayout from "../../Layouts/CardLayout"; import Image from "next/image"; +import { BiLoaderAlt } from "react-icons/bi"; const StoreItem = (props: { storeItem: IStoreItem; buyStoreItem: (storeItemId: number) => void; }) => { + const [isLoading, setIsLoading] = useState(false); + + const handleBuyStoreItem = async () => { + setIsLoading(true); + try { + // Create the source + await props.buyStoreItem(props.storeItem.id); + } catch (error) { + // Handle error if needed (e.g., show a notification or log the error) + } finally { + setIsLoading(false); + } + }; + return (
@@ -15,12 +30,18 @@ const StoreItem = (props: {

{props.storeItem.name}

{props.storeItem.description}

- + {isLoading ? ( + + ) : ( + + )}
diff --git a/src/app/page.tsx b/src/app/page.tsx index 8171ce2..4aa6af7 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -338,7 +338,11 @@ export default function Home() { return ( <> -

Please login

+
+

+ Connect Your Wallet to Continue +

+
); @@ -346,7 +350,6 @@ export default function Home() { return

Loading...

; } - console.log(storeItems); return ( <>