Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed address #366

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
]
},
"devDependencies": {
"@types/gtag.js": "0.0.10"
"@types/gtag.js": "0.0.10",
"@types/react-lazy-load-image-component": "^1.5.2"
}
}
141 changes: 65 additions & 76 deletions src/hooks/useNFT.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useEffect} from "react";
import {RigelNFT, RigelNFTTwo} from "../utils/Contracts";
import { SMARTSWAPNFTSALES, SMARTSWAPNFTTWO} from "../utils/addresses";
import { IPFS, SMARTSWAPNFTSALES, SMARTSWAPNFTTWO} from "../utils/addresses";
import {useActiveWeb3React} from "../utils/hooks/useActiveWeb3React";
import {getERC20Token, useProvider} from "../utils/utilsFunctions";
import {useSelector} from "react-redux";
Expand All @@ -25,7 +25,10 @@ export const useNft = (id: number) => {
const [prices, setPrices] = useState({firstTokenPrice: '', secondTokenPrice: ''});
const [unsoldItems, setUnsoldItems] = useState<number>(0);
const [nftId, setNftId, nftIdRef] = useState<number[]>([]);
const [nftClass, setNftClass, nftClassRef] = useState<number>();
const [loadData, setLoadData] = useState(false);
const [mint, setMint] = useState(false);
const [nftNameInfo,setID] = useState(0);


const trxState = useSelector<RootState>((state) => state.application.modal?.trxState);
Expand All @@ -38,68 +41,66 @@ export const useNft = (id: number) => {


useEffect(() => {

setLoadData(true);

if (chainId === SupportedChainId.POLYGONTEST || chainId === Number(SupportedChainId.POLYGON)) {
const nftArray = getNftTokenPolygon(id);
setNftClass(id);
setNftId(nftArray);
} else if (chainId === SupportedChainId.BINANCETEST || chainId === Number(SupportedChainId.BINANCE)) {
const nftArray = getNftToken(id);
setNftId(nftArray);
setNftId(nftArray)
setNftClass(id);
}
const fetchNftData = async () => {
if (chainId !== undefined) {
try {
// try {
const nftContract = await RigelNFT(validSmartAddress, library);
const purchaseData = await nftContract.nftsPurchaseData(nftClassRef.current);
const checkMint = await nftContract.checkStatus()

const purchaseData = await nftContract.nftPurchaseData(nftIdRef.current[0]);

const tokenOne = await getERC20Token(purchaseData.token1, library);
const tokenA = await nftContract.tokenA();
const tokenB = await nftContract.tokenB();
setMint(checkMint)
const tokenOne = await getERC20Token(tokenA, library);
const [tokenOneSymbol, tokenOneBalance, tokenOneDecimals] = await Promise.all(
[tokenOne.symbol(), tokenOne.balanceOf(account), tokenOne.decimals()]);

setFirstToken({symbol: tokenOneSymbol,
balance: parseFloat(ethers.utils.formatUnits(tokenOneBalance, tokenOneDecimals)).toFixed(4),
address: purchaseData.token1});
address: tokenA});

const tokenTwo = await getERC20Token(purchaseData.token2, library);
const tokenTwo = await getERC20Token(tokenB, library);
const [tokenTwoSymbol, tokenTwoBalance, tokenTwoDecimals] = await Promise.all(
[tokenTwo.symbol(), tokenTwo.balanceOf(account), tokenTwo.decimals()]);
setID(purchaseData.nextAvailableID.toString())
setSecondToken({symbol: tokenTwoSymbol,
balance: parseFloat(ethers.utils.formatUnits(tokenTwoBalance, tokenTwoDecimals)).toFixed(4),
address: purchaseData.token2});

setPrices({firstTokenPrice: formatAmount(purchaseData.token1Price, tokenOneDecimals),
secondTokenPrice: formatAmount(purchaseData.token2Price, tokenTwoDecimals)});

const allID = nftIdRef.current;

for (let i = allID[0]; i <= allID.slice(-1)[0]; i++) {
const views = await nftContract.sold(i);
if (!views) {
setUnsoldItems(i);
break;
}
}
address: tokenB});
setPrices({firstTokenPrice: formatAmount(purchaseData.tokenPrice, tokenOneDecimals),
secondTokenPrice: formatAmount(purchaseData.tokenPrice, tokenTwoDecimals)});

const views = await nftContract.getAllNFTsSoldFromClass(id);
if (views) {
setUnsoldItems(views.all.toString());
// break;
}
setLoadData(false);
} catch (e) {
console.log(e.message);
setLoadData(false);
}
}
};
fetchNftData();
}, [account, chainId, stateChanged]);

return {firstToken, secondToken, prices, unsoldItems, nftId, loadData}
return {firstToken, secondToken, prices, unsoldItems, nftId, loadData,mint,nftNameInfo}
};

export const useNFTAllowance = (
checkTokenApproval: number,
token1Price: string,
token2Price: string,
tokenPrice: string,
currency: string,
id: number
id: number,
tokenA:string,
tokenB:string
) => {
const { account, chainId, library } = useActiveWeb3React();
const [hasTokenABeenApproved, setHasTokenABeenApproved] = useState(false);
Expand All @@ -108,28 +109,24 @@ export const useNFTAllowance = (

useEffect( () => {
const getAllowance = async () => {
if (account) {
if (account && tokenPrice) {
//
try {
setLoadInfo(true);
const nftContract = await RigelNFT(SMARTSWAPNFTSALES[chainId as number], library);
const nftToken = await nftContract.nftPurchaseData(id);

if (nftToken.token1 && nftToken.token2) {
const [tokenA, tokenB] = await Promise.all([
getERC20Token(nftToken.token1 as string, library),
getERC20Token(nftToken.token2 as string, library),

if (tokenA && tokenB) {
const [tokenAData, tokenBData] = await Promise.all([
getERC20Token(tokenA as string, library),
getERC20Token(tokenB as string, library),
]);

const [allowanceA, allowanceB, decimalsA, decimalsB] = await Promise.all([
tokenA.allowance(account, SMARTSWAPNFTSALES[chainId as number]),
tokenB.allowance(account, SMARTSWAPNFTSALES[chainId as number]),
tokenA.decimals(),
tokenB.decimals()
tokenAData.allowance(account, SMARTSWAPNFTSALES[chainId as number]),
tokenBData.allowance(account, SMARTSWAPNFTSALES[chainId as number]),
tokenAData.decimals(),
tokenBData.decimals()
]);

const isTokenAApproved = allowanceA.toString() > parseFloat(ethers.utils.parseUnits(token1Price, decimalsA).toString());
const isTokenBApproved = allowanceB.toString() > parseFloat(ethers.utils.parseUnits(token2Price, decimalsB).toString());

const isTokenAApproved = allowanceA.toString() > parseFloat(ethers.utils.parseUnits(tokenPrice, decimalsA).toString());
const isTokenBApproved = allowanceB.toString() > parseFloat(ethers.utils.parseUnits(tokenPrice, decimalsB).toString());
setHasTokenABeenApproved(isTokenAApproved);
setHasTokenBBeenApproved(isTokenBApproved);
setLoadInfo(false);
Expand All @@ -140,13 +137,13 @@ export const useNFTAllowance = (
}
};
getAllowance();
}, [checkTokenApproval, currency, id, account]);
}, [checkTokenApproval, currency, id, account,tokenPrice]);

return { hasTokenABeenApproved, hasTokenBBeenApproved, loadInfo };
};


export const useNftName = (id: number) => {
export const useNftName = (id: number,nftID:number) => {
const { chainId, library } = useActiveWeb3React();
const [name, setName] = useState('');
const [nftImage, setNftImage] = useState('');
Expand All @@ -158,48 +155,40 @@ export const useNftName = (id: number) => {
const lib = library ? library : prov;

let validSmartAddress: string;
if (SMARTSWAPNFTTWO[ChainId as number] !== "0x") {
validSmartAddress = SMARTSWAPNFTTWO[ChainId as number];
if (SMARTSWAPNFTSALES[ChainId as number] !== "0x") {
validSmartAddress = SMARTSWAPNFTSALES[ChainId as number];
}


useEffect(() => {
setLoading(true);
const fetchDetails = async () => {

if (ChainId === SupportedChainId.POLYGONTEST || ChainId === Number(SupportedChainId.POLYGON)) {
const nftArray = getNftTokenPolygon(id);
let nftArray
if (chainId === SupportedChainId.POLYGONTEST || chainId === Number(SupportedChainId.POLYGON)) {
nftArray = getNftTokenPolygon(id);
setNftId(nftArray);
} else if (ChainId === SupportedChainId.BINANCETEST || ChainId === Number(SupportedChainId.BINANCE)) {
const nftArray = getNftToken(id);

} else if (chainId === SupportedChainId.BINANCETEST || chainId === Number(SupportedChainId.BINANCE)) {
nftArray = getNftToken(id);
setNftId(nftArray);
}

try {
const nftContract = await RigelNFTTwo(validSmartAddress, lib);

const nftDetails = await nftContract.uri(nftIdRef.current[0]);
const newArray = nftDetails.split('/');

let url;

if (ChainId === SupportedChainId.BINANCETEST) {
url = `https://ipfs.io/ipfs/${newArray[2]}/${nftIdRef.current[0]}.json`;
} else {
url = `https://ipfs.io/ipfs/${newArray[2]}/RigelJson/${nftIdRef.current[0]}.json`;
}
const chain = chainId ?? ChainId as number
let url=`https://ipfs.io/ipfs/${IPFS[chain]}/${nftArray[0]}.json`
const data = await fetch(url);
const jsonData = await data.json();

const nftName = jsonData.name;
setName(nftName);
const totalName = nftName.split("#")[0] + `#${nftID}`;
setName(totalName);

const imageArr = jsonData.image.split('/');
let imageUrl;

if (ChainId === SupportedChainId.BINANCETEST) {
imageUrl = `https://ipfs.io/ipfs/${imageArr[2]}/${nftIdRef.current[0]}.png`;
imageUrl = `https://ipfs.io/ipfs/${imageArr[2]}`;
// imageUrl = `https://ipfs.io/ipfs/Qmc52oSqkRbJi5w7et2JJaKzAMgkYFuveb7opiLxbDXnsr`
} else {
imageUrl = `https://ipfs.io/ipfs/${imageArr[2]}/Rigel/${nftIdRef.current[0]}.png`;
imageUrl = `https://ipfs.io/ipfs/${imageArr[2]}`;
}
setNftImage(imageUrl);
setLoading(false);
Expand All @@ -211,7 +200,7 @@ export const useNftName = (id: number) => {
};
fetchDetails();

}, [ChainId, library]);
}, [ChainId, library,id,nftID]);

return {name, nftImage, loading}

Expand Down
6 changes: 3 additions & 3 deletions src/pages/Nft/Components/FeaturedNft.tsx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const FeaturedNft = function ({ id }: {id: number}) {
const { chainId, account } = useActiveWeb3React();
const [isMobileDevice] = useMediaQuery("(max-width: 750px)");

const { firstToken, secondToken ,prices, unsoldItems , nftId, loadData} = useNft(id);
const { firstToken, secondToken ,prices, unsoldItems , nftId, loadData,mint,nftNameInfo} = useNft(id);

const {name, nftImage, loading} = useNftName(id);
const {name, nftImage, loading} = useNftName(id,nftNameInfo);

const rgpPrice = (100.54 * parseFloat(prices.firstTokenPrice)).toFixed(2);

Expand Down Expand Up @@ -122,7 +122,7 @@ export const FeaturedNft = function ({ id }: {id: number}) {
</Stack>
</Stack>
</Center>
<ComfirmPurchase isOpen={purchaseModal} close={()=>setOpenPerchaseModal(false)} id={1} image={nftImage} name={name} />
<ComfirmPurchase isOpen={purchaseModal} close={()=>setOpenPerchaseModal(false)} id={1} image={nftImage} name={name} mint ={mint} />
</Box>

</>
Expand Down
7 changes: 4 additions & 3 deletions src/pages/Nft/Components/Nft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export const Nft = function ({ nftName, image, number, id, priceUSD, priceRGP, i
const [ purchaseModal,setOpenPerchaseModal] = useState(false);
const [isMobileDevice] = useMediaQuery("(max-width: 767px)");

const { firstToken, secondToken ,prices, unsoldItems , nftId, loadData} = useNft(id);
const { firstToken, secondToken ,prices, unsoldItems , nftId, loadData,mint,nftNameInfo} = useNft(id);
const { account } = useActiveWeb3React();

const {name, nftImage, loading} = useNftName(id);
const {name, nftImage, loading} = useNftName(id,nftNameInfo);

const rgpPrice = (100.54 * parseFloat(prices.firstTokenPrice)).toFixed(2);

Expand Down Expand Up @@ -84,7 +84,7 @@ export const Nft = function ({ nftName, image, number, id, priceUSD, priceRGP, i
<Flex mt="2" justifyContent="space-between" alignContent="center">
<Text textColor={lightTextColor}>Sold:</Text>
{loadData ? <Skeleton height={'20px'} w={'80px'}/> :
<Text color={textColor}>{unsoldItems - nftId[0]} of {nftId.length}</Text> }
<Text color={textColor}>{unsoldItems} of {nftId.length}</Text> }
</Flex>

<Flex mt="2" justifyContent="space-between" alignContent="center">
Expand Down Expand Up @@ -137,6 +137,7 @@ export const Nft = function ({ nftName, image, number, id, priceUSD, priceRGP, i
id={id}
image={nftImage}
name={name}
mint={mint}
/>
</Box>
)
Expand Down
Loading