import { formatEther } from "ethers"


export const divide = (toArray, amountArray) => {
    const bachArray = [];

    const batchSize = 200;
    const loopCount = Math.ceil(toArray.length / batchSize);
    
    for (let i = 0; i < loopCount; i++) 
    {
      const start = i * batchSize;
      const end = start + batchSize;

      const chunkAddresses = toArray.slice(start, end)
        .map(addr => addr.trim())
      const chunkAmounts = amountArray.slice(start, end);
      const chunkTotal = chunkAmounts.reduce((acc, amt) => acc + parseFloat(formatEther(amt)), 0);

      let chunkData =
      {
        chunkAddresses,
        chunkAmounts,
        chunkTotal,
        status: 2 // 전송 완료 여부
      }

      bachArray.push(chunkData)
    }

    return bachArray

}