diff --git a/utils/isValidAccountsFile.ts b/utils/isValidAccountsFile.ts index 91c3ded..8eda11f 100644 --- a/utils/isValidAccountsFile.ts +++ b/utils/isValidAccountsFile.ts @@ -4,13 +4,15 @@ import { isValidAddress } from './isValidAddress' export interface AirdropAllocation { address: string - amount: string + amount?: string + tokenId?: string } export const isValidAccountsFile = (file: AirdropAllocation[]) => { let sumOfAmounts = 0 file.forEach((allocation) => { sumOfAmounts += Number(allocation.amount) + console.log('sum: ', sumOfAmounts) }) if (sumOfAmounts > 10000) { toast.error(`Accounts file must cover less than 10000 tokens`) @@ -28,10 +30,19 @@ export const isValidAccountsFile = (file: AirdropAllocation[]) => { if (!account.address.trim().startsWith('stars') && !account.address.trim().endsWith('.stars')) { return { address: false } } + + if (!account.amount && !account.tokenId) { + return { amount: false, tokenId: false } + } + // Check if amount is valid - if (!Number.isInteger(Number(account.amount)) || !(Number(account.amount) > 0)) { + if (account.amount && (!Number.isInteger(Number(account.amount)) || !(Number(account.amount) > 0))) { return { amount: false } } + // Check if tokenId is valid + if (account.tokenId && (!Number.isInteger(Number(account.tokenId)) || !(Number(account.tokenId) > 0))) { + return { tokenId: false } + } return null }) @@ -47,11 +58,22 @@ export const isValidAccountsFile = (file: AirdropAllocation[]) => { toast.error('Invalid address in file') return false } + + if (checks.filter((check) => check?.amount === false && check.tokenId === false).length > 0) { + toast.error('No amount or token ID found in the file. Please check the header.') + return false + } + if (checks.filter((check) => check?.amount === false).length > 0) { toast.error('Invalid amount in file. Amount must be a positive integer.') return false } + if (checks.filter((check) => check?.tokenId === false).length > 0) { + toast.error('Invalid token ID in file. Token ID must be a positive integer.') + return false + } + // if (duplicateCheck.length > 0) { // toast.error('The file contains duplicate addresses.') // return false