Skip to content

Commit

Permalink
Fixes type issues and incorrect error messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwellfortney committed Oct 24, 2021
1 parent 1032826 commit 24aba92
Show file tree
Hide file tree
Showing 3 changed files with 434 additions and 419 deletions.
8 changes: 4 additions & 4 deletions hooks/useCandyMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ export default function useCandyMachine() {
}
}
} catch (error: any) {
let message = error.msg || "Minting failed! Please try again!";
if (!error.msg) {
let message = error.message || "Minting failed! Please try again!";
if (!error.message) {
if (error.message.indexOf("0x138")) {
} else if (error.message.indexOf("0x137")) {
message = `SOLD OUT!`;
Expand Down Expand Up @@ -233,8 +233,8 @@ export default function useCandyMachine() {
}
}
} catch (error: any) {
let message = error.msg || "Minting failed! Please try again!";
if (!error.msg) {
let message = error.message || "Minting failed! Please try again!";
if (!error.message) {
if (error.message.indexOf("0x138")) {
} else if (error.message.indexOf("0x137")) {
message = `SOLD OUT!`;
Expand Down
118 changes: 60 additions & 58 deletions hooks/useHashTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,73 +11,75 @@ export const MAX_SYMBOL_LENGTH = 10;
export const MAX_CREATOR_LEN = 32 + 1 + 1;

export async function fetchHashTable(
hash: string,
metadataEnabled?: boolean
hash: string,
metadataEnabled?: boolean
): Promise<any[]> {
const metadataAccounts = await MetadataProgram.getProgramAccounts(
connection,
{
filters: [
const metadataAccounts = await MetadataProgram.getProgramAccounts(
connection,
{
memcmp: {
offset:
1 +
32 +
32 +
4 +
MAX_NAME_LENGTH +
4 +
MAX_URI_LENGTH +
4 +
MAX_SYMBOL_LENGTH +
2 +
1 +
4 +
0 * MAX_CREATOR_LEN,
bytes: hash,
},
},
],
}
);
filters: [
{
memcmp: {
offset:
1 +
32 +
32 +
4 +
MAX_NAME_LENGTH +
4 +
MAX_URI_LENGTH +
4 +
MAX_SYMBOL_LENGTH +
2 +
1 +
4 +
0 * MAX_CREATOR_LEN,
bytes: hash,
},
},
],
}
);

const mintHashes: any = [];
const mintHashes: any = [];

for (let index = 0; index < metadataAccounts.length; index++) {
const account = metadataAccounts[index];
const accountInfo = await connection.getParsedAccountInfo(account.pubkey);
const metadata: any = new Metadata(hash.toString(), accountInfo.value);
if (metadataEnabled) mintHashes.push(metadata.data);
else mintHashes.push(metadata.data.mint);
}
for (let index = 0; index < metadataAccounts.length; index++) {
const account = metadataAccounts[index];
const accountInfo: any = await connection.getParsedAccountInfo(
account.pubkey
);
const metadata: any = new Metadata(hash.toString(), accountInfo.value);
if (metadataEnabled) mintHashes.push(metadata.data);
else mintHashes.push(metadata.data.mint);
}

return mintHashes;
return mintHashes;
}

export function useHashTable(candyMachineId: string, metadataEnabled: boolean) {
const [hashTable, setHashTable] = useState<any[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [hashTable, setHashTable] = useState<any[]>([]);
const [isLoading, setIsLoading] = useState(false);

const getHashTable = async () => {
if (!candyMachineId || !candyMachineId.length) {
toast.error("Please type the Candy Machine ID in the input box.");
const getHashTable = async () => {
if (!candyMachineId || !candyMachineId.length) {
toast.error("Please type the Candy Machine ID in the input box.");

return;
}
try {
setIsLoading(true);
const data = await fetchHashTable(candyMachineId, metadataEnabled);
setHashTable(data);
if (data.length === 0)
toast.success(
"Zero mint hashes have been found so far for this candy machine."
);
} catch (error) {
console.error(error);
toast.error("An error happened! Please try again later!");
}
setIsLoading(false);
};
return;
}
try {
setIsLoading(true);
const data = await fetchHashTable(candyMachineId, metadataEnabled);
setHashTable(data);
if (data.length === 0)
toast.success(
"Zero mint hashes have been found so far for this candy machine."
);
} catch (error) {
console.error(error);
toast.error("An error happened! Please try again later!");
}
setIsLoading(false);
};

return { hashTable, isLoading, getHashTable };
return { hashTable, isLoading, getHashTable };
}
Loading

0 comments on commit 24aba92

Please sign in to comment.