diff --git a/.env.example b/.env.example index cf011e232..ac76cb03b 100644 --- a/.env.example +++ b/.env.example @@ -5,3 +5,5 @@ REACT_APP_CANDY_START_DATE=__PLACEHOLDER__ REACT_APP_SOLANA_NETWORK=devnet REACT_APP_SOLANA_RPC_HOST=https://explorer-api.devnet.solana.com + +REACT_APP_TITLE=My Candy Machine diff --git a/public/index.html b/public/index.html index aa069f27c..2e4b7e528 100644 --- a/public/index.html +++ b/public/index.html @@ -24,7 +24,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - React App + %REACT_APP_TITLE% diff --git a/src/Home.tsx b/src/Home.tsx index 93bcf2b62..62e2cfb63 100644 --- a/src/Home.tsx +++ b/src/Home.tsx @@ -11,6 +11,8 @@ import { LAMPORTS_PER_SOL } from "@solana/web3.js"; import { useAnchorWallet } from "@solana/wallet-adapter-react"; import { WalletDialogButton } from "@solana/wallet-adapter-material-ui"; +import { WalletSignTransactionError } from "@solana/wallet-adapter-base"; + import { CandyMachine, awaitTransactionSignatureConfirmation, @@ -45,6 +47,7 @@ const Home = (props: HomeProps) => { const [itemsAvailable, setItemsAvailable] = useState(0); const [itemsRedeemed, setItemsRedeemed] = useState(0); const [itemsRemaining, setItemsRemaining] = useState(0); + const [mintPrice, setMintPrice] = useState(0); const [alertState, setAlertState] = useState({ open: false, @@ -67,6 +70,7 @@ const Home = (props: HomeProps) => { itemsAvailable, itemsRemaining, itemsRedeemed, + mintPrice, } = await getCandyMachineState( wallet as anchor.Wallet, props.candyMachineId, @@ -76,6 +80,7 @@ const Home = (props: HomeProps) => { setItemsAvailable(itemsAvailable); setItemsRemaining(itemsRemaining); setItemsRedeemed(itemsRedeemed); + setMintPrice(mintPrice); setIsSoldOut(itemsRemaining === 0); setStartDate(goLiveDate); @@ -119,7 +124,9 @@ const Home = (props: HomeProps) => { } catch (error: any) { // TODO: blech: let message = error.msg || "Minting failed! Please try again!"; - if (!error.msg) { + if (error instanceof WalletSignTransactionError) { + message = `Wrong Wallet. Please refresh page to reconnect Wallet.`; + } else if (!error.msg) { if (error.message.indexOf("0x138")) { } else if (error.message.indexOf("0x137")) { message = `SOLD OUT!`; @@ -175,6 +182,8 @@ const Home = (props: HomeProps) => { {wallet &&

Total Available: {itemsAvailable}

} + {wallet &&

Mint price: {mintPrice / LAMPORTS_PER_SOL} SOL

} + {wallet &&

Redeemed: {itemsRedeemed}

} {wallet &&

Remaining: {itemsRemaining}

} diff --git a/src/candy-machine.ts b/src/candy-machine.ts index 0608fbd25..efa4a6f19 100644 --- a/src/candy-machine.ts +++ b/src/candy-machine.ts @@ -30,6 +30,7 @@ interface CandyMachineState { itemsRedeemed: number; itemsRemaining: number; goLiveDate: Date, + mintPrice: number, } export const awaitTransactionSignatureConfirmation = async ( @@ -177,6 +178,7 @@ export const getCandyMachineState = async ( const itemsAvailable = state.data.itemsAvailable.toNumber(); const itemsRedeemed = state.itemsRedeemed.toNumber(); const itemsRemaining = itemsAvailable - itemsRedeemed; + const mintPrice = state.data.price.toNumber(); let goLiveDate = state.data.goLiveDate.toNumber(); goLiveDate = new Date(goLiveDate * 1000); @@ -186,6 +188,7 @@ export const getCandyMachineState = async ( itemsRedeemed, itemsRemaining, goLiveDate, + mintPrice, }) return { @@ -194,6 +197,7 @@ export const getCandyMachineState = async ( itemsRedeemed, itemsRemaining, goLiveDate, + mintPrice, }; }