Skip to content

Commit

Permalink
feat: Claim Form
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Dec 17, 2024
1 parent c34f5b6 commit e0e2692
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@parcel/transformer-typescript-tsc": "^2.13.0",
"@types/byte-size": "^8.1.2",
"@types/leaflet": "^1.9.15",
"@types/node": "^22.10.2",
"@types/react": "^19",
"@types/react-dom": "^19",
"@types/react-helmet": "^6.1.11",
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/App/pages/Presale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const PresaleBody = () => {

const now = new Date();

if (now < PRESALE_START_DATE) {
if (now < PRESALE_START_DATE && process.env.NODE_ENV !== 'development') {
return <WaitForPresale />;
}

Expand Down
102 changes: 102 additions & 0 deletions src/js/components/App/pages/Presale/ClaimForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import * as React from 'react';
import * as FiIcon from 'react-icons/fi';
import { useConnectedMetaMask } from 'metamask-react';

import Container from '../../../reusable/Container';
import Heading from '../../../reusable/Heading';
import {
convertToHumanReadable,
EKOKE_DECIMALS,
} from '../../../../utils/format';
import Button from '../../../reusable/Button';
import EkokePresaleClient from '../../../../web3/EkokePresaleClient';
import { ChainId } from '../../../MetamaskConnect';
import { useAppContext } from '../../AppContext';
import Paragraph from '../../../reusable/Paragraph';

const ClaimForm = () => {
const { setAppError, setAppSuccess } = useAppContext();
const { account, ethereum, chainId } = useConnectedMetaMask();

const [balance, setBalance] = React.useState<bigint>();
const [pendingTx, setPendingTx] = React.useState(false);
const [claimed, setClaimed] = React.useState(false);

const onClaimTokens = async () => {
setPendingTx(true);
const presaleClient = new EkokePresaleClient(
account,
ethereum,
chainId as ChainId,
);

try {
await presaleClient.claimTokens();
setClaimed(true);
setPendingTx(false);
setAppSuccess('Tokens claimed successfully');
} catch (e) {
console.error(`Failed to claim tokens: ${e}`);
setAppError('Failed to claim tokens');
setPendingTx(false);
}
};

React.useEffect(() => {
const presaleClient = new EkokePresaleClient(
account,
ethereum,
chainId as ChainId,
);
presaleClient
.ekokeBalance()
.then(setBalance)
.catch((err) => {
console.error(`Failed to get EKOKE balance: ${err}`);
setAppError('Failed to get EKOKE balance');
});
}, []);

if (balance === undefined) {
return null;
}

return (
<Container.FlexCols className="text-left gap-4">
<form onSubmit={onClaimTokens}>
<Container.FlexCols className="justify-center items-center">
<Heading.H3>Claim your EKOKE tokens</Heading.H3>
{balance > BigInt(0) && !claimed ? (
<Paragraph.Default className="block text-lg text-text !text-center">
You can claim{' '}
{convertToHumanReadable(balance, EKOKE_DECIMALS, true)} EKOKE
tokens
</Paragraph.Default>
) : (
<Paragraph.Default className="block text-lg text-text !text-center">
You have no EKOKE tokens to claim
</Paragraph.Default>
)}
{balance > BigInt(0) && (
<Button.Cta onClick={onClaimTokens} disabled={pendingTx || claimed}>
Claim your Tokens
{pendingTx ? (
<FiIcon.FiLoader
className="text-white animate-spin inline ml-2"
size={24}
/>
) : (
<FiIcon.FiArrowRight
className="text-white inline ml-2"
size={24}
/>
)}
</Button.Cta>
)}
</Container.FlexCols>
</form>
</Container.FlexCols>
);
};

export default ClaimForm;
18 changes: 16 additions & 2 deletions src/js/components/App/pages/Presale/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ const Info = () => {
</Paragraph.Default>
<ul className="list-disc mx-12">
<li>
<strong>20% - Up to 40.000$</strong>: Goes to the team for paying
<strong>20% - Up to 200.000$</strong>: Goes to the team for paying
the development costs.
</li>
<li>
<strong>20% - Up to 50.000$</strong>: Will be used for paying a
security audit.
</li>
<li>
<strong>20% - Up to 100.000$</strong>: Will be used for marketing
<strong>20% - Up to 150.000$</strong>: Will be used for marketing
and partnerships.
</li>
<li>
Expand All @@ -101,6 +101,20 @@ const Info = () => {
and to reserve even more liquidity for other exchanges.
</li>
</ul>
<Paragraph.Default className="!text-xs pt-2">
When we say <strong>up to</strong> we mean that we will reserve the{' '}
<strong>
Minimum value between the percentage and the maximum value
</strong>
. For instance if we raise 200.000$ we will reserve 40.000$ for the
team, 40.000$ for the security audit, 40.000$ for marketing and
partnerships and 80.000$ for the Liquidity Bootstrapping Pool.
<br />
While for instance if we raise 2.000.000$ we will reserve 200.000$
for the team, 50.000$ for the security audit, 150.000$ for marketing
and partnerships and more than 1.000.000$ for the Liquidity
Bootstrapping Pool.
</Paragraph.Default>
<Heading.H2 className="text-center">Presale details</Heading.H2>
<Paragraph.Default>
The presale will be held on the Ethereum blockchain using our
Expand Down
27 changes: 27 additions & 0 deletions src/js/components/App/pages/Presale/PresaleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import WaitForMetamask from '../../../reusable/WaitForMetamask';
import MetamaskConnect from '../../../MetamaskConnect';
import Paragraph from '../../../reusable/Paragraph';
import RemainingTime from './PresaleForm/RemainingTime';
import ClaimForm from './ClaimForm';

const BASE_PRICE_USD = 1;

Expand Down Expand Up @@ -43,6 +44,32 @@ const PresaleForm = (stats: PresaleStats) => {
<strong>{usdtProgress}</strong>
);

if (!stats.isOpen) {
return (
<Container.Container>
<Heading.H2 className="text-brand font-bold text-center">
🎉 Presale has ended 🎉
</Heading.H2>
<Paragraph.Leading className="!text-center">
The presale was a <strong>success</strong>! We've raised a total of{' '}
<strong>
{stats.usdtRaised.toLocaleString('en-US', {
style: 'currency',
currency: 'USD',
})}
</strong>{' '}
and sold a total of <strong>{stats.tokensSold} EKOKE</strong> tokens.
</Paragraph.Leading>
<Paragraph.Leading className="!text-center">
You can claim your tokens with the <strong>form below</strong>.
</Paragraph.Leading>
<WaitForMetamask otherwise={<LoginWithMetamask />}>
<ClaimForm />
</WaitForMetamask>
</Container.Container>
);
}

return (
<Container.Container>
<Container.FlexCols>
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/reusable/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
const Cta = (props: React.HTMLProps<HTMLButtonElement>) => (
<button
type={'button'}
className={`${props.className} text-white bg-brand hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 font-medium rounded-xl text-lg px-5 py-2.5 mr-2 mb-2 800 :bg-gray-700 :ring-gray-700 disabled:cursor-not-allowed`}
className={`${props.className} text-white bg-brand hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 font-medium rounded-xl text-lg px-5 py-2.5 mr-2 mb-2 800 :bg-gray-700 :ring-gray-700 disabled:bg-gray-800 disabled:cursor-not-allowed`}
disabled={props.disabled}
onClick={props.onClick}
>
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,13 @@
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.34.tgz#10964ba0dee6ac4cd462e2795b6bebd407303433"
integrity sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==

"@types/node@^22.10.2":
version "22.10.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.10.2.tgz#a485426e6d1fdafc7b0d4c7b24e2c78182ddabb9"
integrity sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==
dependencies:
undici-types "~6.20.0"

"@types/prop-types@*":
version "15.7.12"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.12.tgz#12bb1e2be27293c1406acb6af1c3f3a1481d98c6"
Expand Down Expand Up @@ -4055,6 +4062,11 @@ typescript@^5.3:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba"
integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==

undici-types@~6.20.0:
version "6.20.0"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.20.0.tgz#8171bf22c1f588d1554d55bf204bc624af388433"
integrity sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==

unified@^11.0.0:
version "11.0.5"
resolved "https://registry.yarnpkg.com/unified/-/unified-11.0.5.tgz#f66677610a5c0a9ee90cab2b8d4d66037026d9e1"
Expand Down

0 comments on commit e0e2692

Please sign in to comment.