Skip to content

Commit

Permalink
Merge pull request #5 from Ashtar-Global-Solutions-Dev/Hammad_Dev
Browse files Browse the repository at this point in the history
Hammad dev
  • Loading branch information
Aliyanishere authored Mar 6, 2024
2 parents 6d10641 + 0ef5500 commit 1b49713
Show file tree
Hide file tree
Showing 15 changed files with 743 additions and 223 deletions.
44 changes: 24 additions & 20 deletions components/home/inventory/all.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
import axios from "axios";
import { toast } from "react-toastify";
import { Spinner } from "@nextui-org/react";
import { useWallet } from "@solana/wallet-adapter-react";
import React, { useCallback, useEffect, useState } from "react";
import React, { useEffect, useState } from "react";

import NftCard from "@/components/common/nft-card";
import { API_URL } from "@/config/config";
import Utils from "@/lib/utils";

const AllTab = () => {
const { publicKey } = useWallet();
const [inventoryData, setInventoryData] = useState([]);
const [loading, setLoading] = useState(false);

const FetchInventory = useCallback(async () => {
setLoading(true);
await axios
.get(`${API_URL}resources/inventory/${publicKey}`)
.then((result) => {
setInventoryData(result?.data?.result);
setLoading(false);
})
.catch((err) => {
setLoading(false);
toast.error(err.data?.message || "Something went wrong");
});
}, [publicKey]);
const { fetchInventoryData } = Utils();

// const FetchInventory = useCallback(async () => {
// setLoading(true);
// await axios
// .get(`${API_URL}resources/inventory/${publicKey}`)
// .then((result) => {
// setInventoryData(result?.data?.result);
// setLoading(false);
// })
// .catch((err) => {
// setLoading(false);
// toast.error(err.data?.message || "Something went wrong");
// });
// }, [publicKey]);

useEffect(() => {
if (!publicKey) return;
FetchInventory();
}, [FetchInventory, publicKey]);
const fetchData = async () => {
const res = await fetchInventoryData("all", setLoading);
setInventoryData(res);
};

fetchData();
}, []);

return (
<div className="grid grid-cols-2 xl:grid-cols-3 gap-8 p-3">
Expand Down
63 changes: 63 additions & 0 deletions components/home/inventory/bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Spinner } from "@nextui-org/react";
import { useWallet } from "@solana/wallet-adapter-react";
import React, { useEffect, useState } from "react";

import NftCard from "@/components/common/nft-card";
import { API_URL } from "@/config/config";
import Utils from "@/lib/utils";

const BarTab = () => {
const { publicKey } = useWallet();
const [inventoryData, setInventoryData] = useState([]);
const [loading, setLoading] = useState(false);

const { fetchInventoryData } = Utils();

// const FetchInventory = useCallback(async () => {
// setLoading(true);
// await axios
// .get(`${API_URL}resources/inventory/${publicKey}`)
// .then((result) => {
// setInventoryData(result?.data?.result);
// setLoading(false);
// })
// .catch((err) => {
// setLoading(false);
// toast.error(err.data?.message || "Something went wrong");
// });
// }, [publicKey]);

useEffect(() => {
const fetchData = async () => {
const res = await fetchInventoryData("bar", setLoading);
setInventoryData(res);
};

fetchData();
}, []);

return (
<div className="grid grid-cols-2 xl:grid-cols-3 gap-8 p-3">
{loading ? (
<Spinner color="white" />
) : (
inventoryData.map((item, index) => (
<NftCard
key={index}
name={item.metadata.name}
picture={item.metadata.uri}
width={90}
imageWidth={70}
imageHeight={70}
nftNameStyle="text-[13px]"
btnStyle="bg-opacity-70 text-xs h-6"
btnDisabled
amount={item?.balance}
/>
))
)}
</div>
);
};

export default BarTab;
65 changes: 65 additions & 0 deletions components/home/inventory/ores.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import axios from "axios";
import { toast } from "react-toastify";
import { Spinner } from "@nextui-org/react";
import { useWallet } from "@solana/wallet-adapter-react";
import React, { useCallback, useEffect, useState } from "react";

import NftCard from "@/components/common/nft-card";

import Utils from "@/lib/utils";

const OresTab = () => {
const { publicKey } = useWallet();
const [inventoryData, setInventoryData] = useState([]);
const [loading, setLoading] = useState(false);

const { fetchInventoryData } = Utils();

// const FetchInventory = useCallback(async () => {
// setLoading(true);
// await axios
// .get(`${API_URL}resources/inventory/${publicKey}`)
// .then((result) => {
// setInventoryData(result?.data?.result);
// setLoading(false);
// })
// .catch((err) => {
// setLoading(false);
// toast.error(err.data?.message || "Something went wrong");
// });
// }, [publicKey]);

useEffect(() => {
const fetchData = async () => {
const res = await fetchInventoryData("bar", setLoading);
setInventoryData(res);
};

fetchData();
}, []);

return (
<div className="grid grid-cols-2 xl:grid-cols-3 gap-8 p-3">
{loading ? (
<Spinner color="white" />
) : (
inventoryData.map((item, index) => (
<NftCard
key={index}
name={item.metadata.name}
picture={item.metadata.uri}
width={90}
imageWidth={70}
imageHeight={70}
nftNameStyle="text-[13px]"
btnStyle="bg-opacity-70 text-xs h-6"
btnDisabled
amount={item?.balance}
/>
))
)}
</div>
);
};

export default OresTab;
83 changes: 62 additions & 21 deletions components/home/tabs/craft/tabs/adamantite.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,71 @@
import React from "react";
import axios from "axios";
import { toast } from "react-toastify";
import { Spinner } from "@nextui-org/react";
import { useWallet } from "@solana/wallet-adapter-react";
import React, { useEffect, useState } from "react";

import CraftData from "@/data/craft-adamantite-data.json";
import NftCard from "@/components/common/nft-card";
import Utils from "@/lib/utils";

//import filterResourcesByMetadataSymbols

const BronzeTab = () => {
const { publicKey } = useWallet();
const { createRecipe, fetchCraftData } = Utils();
const [craftData, setCraftData] = useState([]);
const [dataLoading, setDataLoading] = useState(false);
const [loading, setLoading] = useState({
name: "",
status: false,
});

useEffect(() => {
const fetchData = async () => {
const res = await fetchCraftData("adamantite", setDataLoading);
setCraftData(res);
};

fetchData();
}, []);

const AdamantiteTab = () => {
return (
<div className="grid grid-cols-3 gap-x-24 gap-y-8">
{CraftData.map((craftment, index) => (
<NftCard
divStyle="bg-black shadow-black shadow-xl rounded-xl p-2"
key={index}
name={craftment.name}
picture={craftment.picture}
buttonText="Craft"
width={165}
imageWidth={155}
imageHeight={140}
nftNameStyle="text-[15px] pr-1"
btnStyle="bg-gradient-to-b from-[#8E8B77] to-[#30302E] text-xs h-6 w-24 h-6 font-bold drop-shadow-lg"
creationFrom="cube"
materials={craftment.materials}
experience={craftment.experience}
/>
))}
{dataLoading ? (
<Spinner color="white" />
) : (
craftData?.map((craftment, index) => (
<>
<NftCard
divStyle="bg-black shadow-black shadow-xl rounded-xl p-2"
key={index}
name={craftment?.metadata?.name}
picture={craftment?.metadata?.uri}
buttonText="Craft"
width={165}
imageWidth={155}
imageHeight={140}
nftNameStyle="text-[15px]"
btnStyle="bg-gradient-to-b from-[#8E8B77] to-[#30302E] text-xs h-6 w-24 h-6 font-bold drop-shadow-lg"
materials={craftment?.material}
experience={45}
btnClick={async () => {
// await createRecipe(
// craftment?.addresses?.recipe,
// craftment?.metadata?.name,
// setLoading
// );
fetchCraftData("bronze", setDataLoading, true);
}}
loading={loading}
btnDisabled={
loading.status && loading.name === craftment?.metadata?.name
}
/>
</>
))
)}
</div>
);
};

export default AdamantiteTab;
export default BronzeTab;
85 changes: 40 additions & 45 deletions components/home/tabs/craft/tabs/bronze.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,66 @@ import axios from "axios";
import { toast } from "react-toastify";
import { Spinner } from "@nextui-org/react";
import { useWallet } from "@solana/wallet-adapter-react";
import React, { useCallback, useEffect, useState } from "react";
import React, { useEffect, useState } from "react";

import NftCard from "@/components/common/nft-card";
import Utils from "@/lib/utils";
import { API_URL } from "@/config/config";

//import filterResourcesByMetadataSymbols

const BronzeTab = () => {
const { publicKey } = useWallet();
const { createRecipe } = Utils();
const { createRecipe, fetchCraftData } = Utils();
const [craftData, setCraftData] = useState([]);
const [dataLoading, setDataLoading] = useState(false);
const [loading, setLoading] = useState({
name: "",
status: false,
});


const FetchCraft = useCallback(async () => {
setDataLoading(true);
await axios
.get(`${API_URL}resources/craft`)
.then((result) => {
setCraftData(result?.data?.result);
setDataLoading(false);
})
.catch((err) => {
setDataLoading(false);
toast.error(err.data?.message || "Something went wrong");
});
}, [publicKey]);

useEffect(() => {
if (!publicKey) return;
FetchCraft();
}, [FetchCraft, publicKey]);
const fetchData = async () => {
const res = await fetchCraftData("bronze", setDataLoading);
setCraftData(res);
};

fetchData();
}, []);

return (
<div className="grid grid-cols-3 gap-x-24 gap-y-8">
{dataLoading ? (
<Spinner color="white" />
) : (
craftData.map((craftment, index) => (
<NftCard
divStyle="bg-black shadow-black shadow-xl rounded-xl p-2"
key={index}
name={craftment?.metadata?.name}
picture={craftment?.metadata?.uri}
buttonText="Craft"
width={165}
imageWidth={155}
imageHeight={140}
nftNameStyle="text-[15px]"
btnStyle="bg-gradient-to-b from-[#8E8B77] to-[#30302E] text-xs h-6 w-24 h-6 font-bold drop-shadow-lg"
materials={craftment?.material}
experience={45}
btnClick={() =>
createRecipe(
craftment?.addresses?.recipe,
craftment?.metadata?.name,
setLoading
)
}
loading={loading}
btnDisabled={loading.status && loading.name === craftment?.metadata?.name}
/>
craftData?.map((craftment, index) => (
<>
<NftCard
divStyle="bg-black shadow-black shadow-xl rounded-xl p-2"
key={index}
name={craftment?.metadata?.name}
picture={craftment?.metadata?.uri}
buttonText="Craft"
width={165}
imageWidth={155}
imageHeight={140}
nftNameStyle="text-[15px]"
btnStyle="bg-gradient-to-b from-[#8E8B77] to-[#30302E] text-xs h-6 w-24 h-6 font-bold drop-shadow-lg"
materials={craftment?.material}
experience={45}
btnClick={async () => {
// await createRecipe(
// craftment?.addresses?.recipe,
// craftment?.metadata?.name,
// setLoading
// );
fetchCraftData("bronze", setDataLoading, true);
}}
loading={loading}
btnDisabled={
loading.status && loading.name === craftment?.metadata?.name
}
/>
</>
))
)}
</div>
Expand Down
Loading

0 comments on commit 1b49713

Please sign in to comment.