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

fix: Candy Machine Details and env variables #25

Open
wants to merge 1 commit into
base: main
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

#config
/config/conf.json
/config
# dependencies
/node_modules
/.pnp
Expand Down
6 changes: 3 additions & 3 deletions config/conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"owner": "CteftmQggr8XxKKfDRFLiyW6yVtdiNgqpvHKdwoC1KVD",
"accesstoken": "7CjHg2jxB21rzUM3s9ooNdpaMEBn4mbbuSthcc8f89Xb",
"candyMachineID": "2Y3g6hoQ6PgDHFboPzjG4rDaqS2RBfHVnhmeQhZ3YjfE",
"owner": "GH8WFNxj5aCrEMAs2R7MBuKXCmSN4JAL2gS75QP7SNmu",
"accesstoken": "DwbpKqwVMKadm2h7Xi2wavEhrSnkgwymYo5kZ5kHQWYB",
"candyMachineID": "6DZfgy1g6ESdffZXji4XLy618geGMpdLNm2N1tjW9ZBt",
"rpcHost": "https://explorer-api.devnet.solana.com",
"network": "devnet"
}
23 changes: 14 additions & 9 deletions pages/homepg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@ import React, {useEffect, useState} from "react";
import Modal from "../components/modal";
import NtfData from "./nft"
import { WalletMultiButton } from '@solana/wallet-adapter-react-ui'
import envConfig from "../config/conf.json";
/* import envConfig from "../config/conf.json";
import { useWallet } from "@solana/wallet-adapter-react";

const candyMachineId = new anchor.web3.PublicKey(
process.env.NEXT_PUBLIC_CANDY_MACHINE_ID! || envConfig.candyMachineID
);
let candyMachineId: any;
try{
candyMachineId = new anchor.web3.PublicKey(
process.env.NEXT_PUBLIC_CANDY_MACHINE_ID! || envConfig.candyMachineID
);
}catch(e){
candyMachineId = ""
} */

export default function Homepg() {
const [showpo, setShowpo] = useState(false);
const wallet = useWallet();
/* const wallet = useWallet();
const rpcHost = process.env.NEXT_PUBLIC_SOLANA_RPC_HOST! || envConfig.rpcHost;
const connection = new anchor.web3.Connection(rpcHost);
const [candyMachine, setCandyMachine] = useState<CandyMachine>();
useEffect(() => {
const connection = new anchor.web3.Connection(rpcHost);
const [candyMachine, setCandyMachine] = useState<CandyMachine>(); */
/* useEffect(() => {
try{
(async () => {
const anchorWallet = {
Expand All @@ -38,7 +43,7 @@ const connection = new anchor.web3.Connection(rpcHost);
}catch(err){
console.log(err)
}
},[wallet, candyMachineId, connection,])
},[wallet, candyMachineId, connection,]) */

return (
<div className="flex w-full justify-center items-center">
Expand Down
83 changes: 58 additions & 25 deletions pages/nft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,34 @@ import {
import { useEffect, useState } from "react";

import { LAMPORTS_PER_SOL } from "@solana/web3.js";
import envConfig from "../config/conf.json"
var envConfig;
try{
envConfig = require("../config/conf.json")
}catch(e){
envConfig = null;
}

import { useWallet } from "@solana/wallet-adapter-react";

const candyMachineId = new anchor.web3.PublicKey(
process.env.NEXT_PUBLIC_CANDY_MACHINE_ID! || envConfig.candyMachineID
);
let candyMachineId: any;
try{
candyMachineId = new anchor.web3.PublicKey(
process.env.NEXT_PUBLIC_CANDY_MACHINE_ID! || envConfig.candyMachineID
);
}catch(e){
candyMachineId = ""
}

let rpcHost: any;
let connection: any;
try{
rpcHost = process.env.NEXT_PUBLIC_SOLANA_RPC_HOST! || envConfig.rpcHost;
connection = new anchor.web3.Connection(rpcHost);
}catch(e){
rpcHost = null;
connection = null;
}

const rpcHost = process.env.NEXT_PUBLIC_SOLANA_RPC_HOST! || envConfig.rpcHost;
const connection = new anchor.web3.Connection(rpcHost);

export default function NtfData():any {
const wallet = useWallet();
Expand All @@ -26,41 +45,55 @@ export default function NtfData():any {
const [goLiveDate,setGoLiveDate]= useState<Date>();
const [itemsAvailable,setItemsAvailable]= useState(0);
const [price, setPrice]= useState(0);
const [show, setShow]= useState("No");



useEffect(() => {
try{
(async () => {
const anchorWallet = {
publicKey: wallet.publicKey
} as anchor.Wallet;

const data =
await getCandyMachineState(
anchorWallet,
candyMachineId,
connection
);
const { candyMachine, itemsRedeemed, itemsAvailable, goLiveDate } = data
const { state } = candyMachine
const price = state.data.price
setCandyMachine(candyMachine);
setPrice(price);
setItemsRedeemed(itemsRedeemed);
setGoLiveDate(goLiveDate);
setItemsAvailable(itemsAvailable);
if(candyMachineId == ""){

}else{
const anchorWallet = {
publicKey: wallet.publicKey
} as anchor.Wallet;

const data =
await getCandyMachineState(
anchorWallet,
candyMachineId,
connection
);
console.log(data)
const { candyMachine, itemsRedeemed, itemsAvailable, goLiveDate } = data
const { state } = candyMachine
const price = state.data.price
setCandyMachine(candyMachine);
setPrice(price);
setItemsRedeemed(itemsRedeemed);
setGoLiveDate(goLiveDate);
setItemsAvailable(itemsAvailable);
setShow("Yes")
}
})();
}catch(e){
console.log(e)
}

}, [wallet, candyMachineId, connection]);

return ( candyMachine &&
return ( candyMachine?
<div className="machine-container">
<p className="text-1.5xl text-white text-gradient py-1">{`Drop Date: ${goLiveDate}`}</p>
<p className="text-1.5xl text-white text-gradient py-1">{`Items Minted: ${itemsRedeemed} / ${itemsAvailable}`}</p>
<p className="text-1.5xl text-white text-gradient py-1">{`Nft Price: ${price/LAMPORTS_PER_SOL} SOL`}</p>
</div> :
<div className="items- center text-white font-serif text-green-500 text-2xl">
<p>Cannot retrieve Candy Machine Data.</p>
<p>Please Ensure Data is correct in the Config file</p>
<p>If app has not been configured yet,</p>
<p>Use <span className="text-red-500">/config</span> Endpoint to add data</p>
</div>
)
}
2 changes: 1 addition & 1 deletion pages/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default function wallet(){


router.push({pathname: '/confirmed',
query: { from: "Wallet", NFTAdded: `${numberOfNFTAdded}`, token: "SOL" , amount: cost.toFixed(3), sign: `${mintSignature[0]}`, verify: `${verifyMintSignatureResult[0]}` }})
query: { from: "Wallet", NFTAdded: `${numberOfNFTAdded}`, token: "SOL" , amount: cost.toFixed(3), verify: `${verifyMintSignatureResult[0]}` }})
} catch (e) {
if (e instanceof FindReferenceError) {
// No transaction found yet, ignore this error
Expand Down