Skip to content

Commit

Permalink
fix: make onMintMultiple wait for all mints
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinfaveri committed Sep 27, 2021
1 parent 1c2478c commit 4676f11
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/hooks/use-candy-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import toast from 'react-hot-toast';
import useWalletBalance from "./use-wallet-balance";
import { LAMPORTS_PER_SOL } from "@solana/web3.js";
import { sleep } from "../utils/utility";

const MINT_PRICE_SOL = 1

const treasury = new anchor.web3.PublicKey(
process.env.NEXT_PUBLIC_TREASURY_ADDRESS!
);
Expand Down Expand Up @@ -143,7 +146,8 @@ export default function useCandyMachine() {
try {
setIsMinting(true);
if (wallet.connected && candyMachine?.program && wallet.publicKey) {
const oldBalance = await connection.getBalance(wallet?.publicKey);
const oldBalance = await connection.getBalance(wallet?.publicKey) / LAMPORTS_PER_SOL;
const futureBalance = oldBalance - (MINT_PRICE_SOL * quantity)

const signedTransactions: any = await mintMultipleToken(
candyMachine,
Expand All @@ -154,6 +158,7 @@ export default function useCandyMachine() {
);

const promiseArray = []


for (let index = 0; index < signedTransactions.length; index++) {
const tx = signedTransactions[index];
Expand All @@ -179,11 +184,11 @@ export default function useCandyMachine() {
}
}

let newBalance = await connection.getBalance(wallet?.publicKey);
let newBalance = await connection.getBalance(wallet?.publicKey) / LAMPORTS_PER_SOL;

while(oldBalance === newBalance) {
while(newBalance > futureBalance) {
await sleep(1000)
newBalance = await connection.getBalance(wallet?.publicKey);
newBalance = await connection.getBalance(wallet?.publicKey) / LAMPORTS_PER_SOL;
}

if(totalSuccess) {
Expand Down

0 comments on commit 4676f11

Please sign in to comment.