diff --git a/config/game-config.json b/config/game-config.json index 1e2f9e6..31306d7 100644 --- a/config/game-config.json +++ b/config/game-config.json @@ -51,6 +51,51 @@ { "tier": 4, "price": 500, "claimBoost": 40 }, { "tier": 5, "price": 600, "claimBoost": 50 } ] - } + }, + { + "id": "item4", + "name": "Drill D", + "description": "This is drill D", + "price": 250, + "claimAmount": 50, + "completionTimeInMins": 5, + "upgrades": [ + { "tier": 1, "price": 200, "claimBoost": 10 }, + { "tier": 2, "price": 300, "claimBoost": 20 }, + { "tier": 3, "price": 400, "claimBoost": 30 }, + { "tier": 4, "price": 500, "claimBoost": 40 }, + { "tier": 5, "price": 600, "claimBoost": 50 } + ] + }, + { + "id": "item5", + "name": "Drill E", + "description": "This is drill E", + "price": 250, + "claimAmount": 50, + "completionTimeInMins": 5, + "upgrades": [ + { "tier": 1, "price": 200, "claimBoost": 10 }, + { "tier": 2, "price": 300, "claimBoost": 20 }, + { "tier": 3, "price": 400, "claimBoost": 30 }, + { "tier": 4, "price": 500, "claimBoost": 40 }, + { "tier": 5, "price": 600, "claimBoost": 50 } + ] +}, +{ + "id": "item6", + "name": "Drill F", + "description": "This is drill F", + "price": 250, + "claimAmount": 50, + "completionTimeInMins": 5, + "upgrades": [ + { "tier": 1, "price": 200, "claimBoost": 10 }, + { "tier": 2, "price": 300, "claimBoost": 20 }, + { "tier": 3, "price": 400, "claimBoost": 30 }, + { "tier": 4, "price": 500, "claimBoost": 40 }, + { "tier": 5, "price": 600, "claimBoost": 50 } + ] +} ] } diff --git a/database.db b/database.db index 4d5b84a..8f668b0 100644 Binary files a/database.db and b/database.db differ diff --git a/src/app/Components/StoreItem.tsx b/src/app/Components/StoreItem.tsx index ac5c005..ba0c04f 100644 --- a/src/app/Components/StoreItem.tsx +++ b/src/app/Components/StoreItem.tsx @@ -6,13 +6,12 @@ import CommonCardLayout from "../Layouts/CommonCardLayout"; const StoreItem = (props: { storeItem: IStoreItem; buyStoreItem: (itemId: string) => void; - owned: boolean | undefined; }) => { return (
- {props.owned ? ( + {props.storeItem.isOwned ? ( Owned ) : ( "" @@ -41,7 +40,7 @@ const StoreItem = (props: {
- {props.owned ? ( + {props.storeItem.isOwned ? ( diff --git a/src/app/Components/StoreItemView.tsx b/src/app/Components/StoreItemView.tsx index 695ed79..7542d12 100644 --- a/src/app/Components/StoreItemView.tsx +++ b/src/app/Components/StoreItemView.tsx @@ -3,34 +3,21 @@ import { IInventoryItem, IStoreItem } from "typings"; import StoreItem from "./StoreItem"; const StoreItemView = (props: { - storeItems: IStoreItem[] | null; inventoryItems: IInventoryItem[] | null | undefined; + storeItems: IStoreItem[]; buyStoreItem: (itemId: string) => void; }) => { - const isOwned = (storeItemId: string) => { - return props.inventoryItems?.some( - (item) => item.storeItem.id == storeItemId - ); - }; - - const storeItemsToRender = props.storeItems?.map((storeItem) => { - return { - ...storeItem, - owned: isOwned(storeItem.id), - }; - }); return (

Store

- {storeItemsToRender && - storeItemsToRender - .sort((a, b) => (a.owned === b.owned ? 0 : a.owned ? 1 : -1)) + {props.storeItems && + props.storeItems + .sort((a, b) => (a.isOwned === b.isOwned ? 0 : a.isOwned ? 1 : -1)) .map((storeItem, id) => ( ))}
diff --git a/src/app/page.tsx b/src/app/page.tsx index d502da5..8f3c8a9 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -8,13 +8,7 @@ import StoreItemView from "./Components/StoreItemView"; import ResourceStore from "./Components/ResourceStore"; import ErrorPopover from "./Components/ErrorPopover"; import { gameConfig } from "@/utils/gameLogic"; -import { - IStoreItem, - IInventoryItem, - IStakingSource, - IBankAccount, - IStake, -} from "typings"; +import { IInventoryItem, IStakingSource, IBankAccount, IStake } from "typings"; export default function Home() { const [inventoryItems, setInventoryItems] = useState< @@ -24,30 +18,21 @@ export default function Home() { [] ); const [bankAccount, setBankAccount] = useState(); - const [storeItems, setStoreItems] = useState([]); const [userStakes, setUserStakes] = useState([]); const [lightBoxIsActive, setLightBoxIsActive] = useState(false); const [userId, setUserId] = useState(null); const [error, setError] = useState(null); const [errorTime, setErrorTime] = useState(3); + const [storeItems, setStoreItems] = useState(gameConfig.store); + const [isLoading, setIsLoading] = useState(false); - // EMIL - // It should be possible to add infinite drills on each resource (however many the user has) - - // JOE - // Transaction table - // Add dev buttons to prototype - - // DONE POST /user/login check if user exists - // DONE GET /user/USER_ID/stakes get stake event - // DONE POST /user/USER_ID/stakes/claim claim stake - // DONE POST /user/USER_ID/stakes/start start stake - // DONE GET /user/USER_ID/bank-account get balance - // DONE PUT /user/USER_ID/bank-account sell resource - // DONE GET /user/USER_ID/inventory-items get inventory items - // DONE POST /user/USER_ID/inventory-items buy item - // DONE GET /user/USER_ID/staking-sources get staking sources - // DONE POST /user/USER_ID/staking-sources create staking source + const isOwned = (storeItemId: string) => { + if (inventoryItems) { + return inventoryItems?.some((item) => item.storeItem.id == storeItemId); + } else { + return false; + } + }; useEffect(() => { const fetchUser = async (wallet: string) => { @@ -104,14 +89,26 @@ export default function Home() { fetchUser("abcdefg"); // Public key goes here // Nico is there a better way of checking if a user is logged in? if (userId) { - setStoreItems(gameConfig.store); fetchBankAccount(); fetchStakingSources(); fetchInventoryItems(); fetchStakes(); } + + setIsLoading(!isLoading); }, [userId]); + // Update data + useEffect(() => { + const updatedStoreItems = storeItems.map((storeItem) => { + return { + ...storeItem, + isOwned: isOwned(storeItem.id), + }; + }); + updatedStoreItems && setStoreItems(updatedStoreItems); + }, [inventoryItems]); + // Hide error automatically useEffect(() => { if (error) { @@ -214,7 +211,7 @@ export default function Home() { if (response.status == 200) { // Return success message - console.log(data.message); + console.log(data); } if (response.status == 400) { @@ -249,7 +246,7 @@ export default function Home() { }; if (!userId) return

Please login

; - + console.log(inventoryItems); return ( <> {error && ( @@ -277,8 +274,8 @@ export default function Home() { upgradeInventoryItem={upgradeInventoryItem} />
diff --git a/typings.d.ts b/typings.d.ts index 0c82274..844224b 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -54,6 +54,7 @@ export interface IStoreItem { price: number; claimBoost: number; }[]; + isOwned: boolean; } export interface IResourceAccount {