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

Misc improvements #183

Open
wants to merge 3 commits 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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
-->
<title>React App</title>
<title>%REACT_APP_TITLE%</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
11 changes: 10 additions & 1 deletion src/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<AlertState>({
open: false,
Expand All @@ -67,6 +70,7 @@ const Home = (props: HomeProps) => {
itemsAvailable,
itemsRemaining,
itemsRedeemed,
mintPrice,
} = await getCandyMachineState(
wallet as anchor.Wallet,
props.candyMachineId,
Expand All @@ -76,6 +80,7 @@ const Home = (props: HomeProps) => {
setItemsAvailable(itemsAvailable);
setItemsRemaining(itemsRemaining);
setItemsRedeemed(itemsRedeemed);
setMintPrice(mintPrice);

setIsSoldOut(itemsRemaining === 0);
setStartDate(goLiveDate);
Expand Down Expand Up @@ -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!`;
Expand Down Expand Up @@ -175,6 +182,8 @@ const Home = (props: HomeProps) => {

{wallet && <p>Total Available: {itemsAvailable}</p>}

{wallet && <p>Mint price: {mintPrice / LAMPORTS_PER_SOL} SOL</p>}

{wallet && <p>Redeemed: {itemsRedeemed}</p>}

{wallet && <p>Remaining: {itemsRemaining}</p>}
Expand Down
4 changes: 4 additions & 0 deletions src/candy-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface CandyMachineState {
itemsRedeemed: number;
itemsRemaining: number;
goLiveDate: Date,
mintPrice: number,
}

export const awaitTransactionSignatureConfirmation = async (
Expand Down Expand Up @@ -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);
Expand All @@ -186,6 +188,7 @@ export const getCandyMachineState = async (
itemsRedeemed,
itemsRemaining,
goLiveDate,
mintPrice,
})

return {
Expand All @@ -194,6 +197,7 @@ export const getCandyMachineState = async (
itemsRedeemed,
itemsRemaining,
goLiveDate,
mintPrice,
};
}

Expand Down