As an exercise to learn Solidity and Nextjs, I started developing a presale smartcontract. It has gotten rather large but I am proud of how far I have come in two months. The contract mints a token, and users can buy this token in a presale. This functionality is implemented by the getAllocation
function.
I know it works because I have tried to run it on Remix IDE successfully.
I implemented a frontend with Next.js and I am using web3Modal to connect to users wallet. Connecting to Metamask or other wallets works fine, but when I try to purchase a token, there is a problem: the right amount of ether is passed and the transaction is recorded on blockchain, but user receives no custom tokens in exchange. The expected behaviour is that a user should receive an equivalent amount of presale tokens for ether sent.
Code gist for the smartcontract and the component that creates a connection (addresses used are standard issue from hardhat). https://gist.github.com/dragonskyside/85fe2ca082e1d0ac8f075b426a73585f Kindly show me what I'm doing wrong here, and anywhere else in the code.