Skip to content

Commit

Permalink
claim flt page
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalbit committed Apr 26, 2024
1 parent 16180a7 commit d093aca
Show file tree
Hide file tree
Showing 8 changed files with 391 additions and 0 deletions.
1 change: 1 addition & 0 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Claiming flow 10 - Route "/finish"
- Claiming flow 11 - Route "/not-found"
- Claiming flow 12 - Route "/claimed"
- Claiming FLT from FLT-DROP - Route "/claim-flt"

#

Expand Down
3 changes: 3 additions & 0 deletions web/src/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import {
ROUTE_INDEX,
ROUTE_NOT_FOUND,
ROUTE_PROOF,
ROUTE_CLAIM_FLT,
ROUTE_WALLET
} from "../../constants/routes";
import { catchError } from "../../utils";
import { fetchCurrentAward, fetchMerkleRoot, fetchNextHalvePeriod } from "../../store/actions/distributor";
import { useVh } from "../../hooks/useVh";
import { ClaimFltPage } from "../../pages/claim-flt-page/claim-flt-page";

function App() {
const { network, address, provider } = useWeb3Connection();
Expand Down Expand Up @@ -71,6 +73,7 @@ function App() {
<Route exact path={ROUTE_FINISH} element={<FinishPage />} />
<Route exact path={ROUTE_NOT_FOUND} element={<AccountNotFound />} />
<Route exact path={ROUTE_CLAIMED} element={<ClaimedPage />} />
<Route exact path={ROUTE_CLAIM_FLT} element={<ClaimFltPage />} />
<Route path="*" element={<Navigate to="/" />} />
</Routes>
</div>
Expand Down
4 changes: 4 additions & 0 deletions web/src/constants/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ export const governanceContracts = {
token: "0x236501327e701692a281934230AF0b6BE8Df3353",
devRewardDistributor: "0x6081d7F04a8c31e929f25152d4ad37c83638C62b",
},
// fuji: {
// token: "0x236501327e701692a281934230AF0b6BE8Df3353",
// devRewardDistributor: "0x9Fe90893E9F8Bb5F7772B7f422d04709020A9BFE",
// },
};
18 changes: 18 additions & 0 deletions web/src/constants/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ const supportedChains = [
balance: "",
},
},
// NEXT CHAIN FOR TESTING ONLY
// {
// name: "Fuji C-Chain",
// short_name: "fuji",
// chain: "C-CHAIN",
// network: "fuji",
// chain_id: 43113,
// network_id: 43113,
// explorer_url: "https://explorer.cchain.dev",
// rpc_url: "https://api.avax-test.network/ext/bc/C/rpc",
// native_currency: {
// symbol: "AVAX",
// name: "C-Chain",
// decimals: "18",
// contractAddress: "",
// balance: "",
// },
// }
];

export default supportedChains;
1 change: 1 addition & 0 deletions web/src/constants/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export const ROUTE_DONE = "/done";
export const ROUTE_FINISH = "/finish";
export const ROUTE_NOT_FOUND = "/not-found";
export const ROUTE_CLAIMED = "/claimed";
export const ROUTE_CLAIM_FLT = "/claim-flt";
155 changes: 155 additions & 0 deletions web/src/pages/claim-flt-page/claim-flt-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { memo, useEffect, useState } from "react";
import { useWeb3Connection } from "../../hooks/useWeb3Connection";
import { ethers } from "ethers";
import ConnectWallet from "../../components/ConnectWallet/ConnectWallet";
import styles from "./claim-flt-page.module.css";
import Header from "../../components/Header/Header";
import Title from "../../components/Title/Title";
import Dashboard from "../../components/Dashboard/Dashboard";
import DefinitionList from "../../components/DefinitionList/DefinitionList";
import Text from "../../components/Text/Text";
import Footer from "../../components/Footer/Footer";
import { governanceContracts } from "../../constants";
import abis from "../../contracts";
import { formatSeconds } from "./helpers";
import Button from "../../components/Button/Button";
import supportedChains from "../../constants/chains";


export const ClaimFltPage = memo(() => {
const { address, provider, network } = useWeb3Connection();
const [amountAndDate, setAmountAndDate] = useState(null);
const [secondsLeft, setSecondsLeft] = useState(null);

useEffect(() => {
if (!amountAndDate || !address) {
return;
}

const updateSecondsLeft = () => {
const now = Date.now();
const unlockTime = amountAndDate.unlockTime.getTime() / 1000;
const newSecondsLeft = Math.floor((unlockTime - now / 1000));
setSecondsLeft(newSecondsLeft);
};

updateSecondsLeft();

let intervalId;
if (!secondsLeft || secondsLeft > 0) {
intervalId = setInterval(updateSecondsLeft, 500);
}
return () => clearInterval(intervalId);
}, [amountAndDate, address, network]);

useEffect(() => {
if (!provider) return;
(async () => {
const contract = new ethers.Contract(
governanceContracts[network.name].devRewardDistributor,
abis.DevRewardDistributor.abi,
provider
);
if (address) {
const data = await contract.functions.lockedBalances(address);
const { amount, unlockTime } = data;
const _amount = +ethers.utils.formatEther(amount);
const _unlockTime = new Date(unlockTime.toNumber() * 1000);
setAmountAndDate({ amount: _amount, unlockTime: _unlockTime });
}
})();
}, [address, provider, network]);

const [waitForSigning, setWaitForSigning] = useState(false);
const [waitForReceipt, setWaitForReceipt] = useState(false);
const [confirmedTxHash, setConfirmedTxHash] = useState(null);

const handleClaim = async () => {
const contract = new ethers.Contract(
governanceContracts[network.name].devRewardDistributor,
abis.DevRewardDistributor.abi,
provider.getSigner(),
);
setWaitForSigning(true);
const response = await contract.functions.transfer(address, amountAndDate.amount, { from: address });
setWaitForSigning(false);
setWaitForReceipt(true);
const receipt = await response.wait();
setWaitForReceipt(false);
setConfirmedTxHash(receipt.transactionHash);
}

const dateInFuture = amountAndDate?.unlockTime > new Date();

return (
<>
<div className={styles.background}>
<Header />
<div className="container">
<main className={`main ${styles.main}`}>
<div className={styles.title}>
<Title type="h1" size="large" text="FLT-DROP Claim" icon="" />
</div>
<div className={styles.dashboard}>
<Dashboard>
<div className={styles["dashboard__flex-container"]}>
<div className={styles.dashboard__logo} />
<div className={styles.definition}>
{amountAndDate?.unlockTime ? <>
{amountAndDate.amount !== 0 && <DefinitionList
dd={`${amountAndDate.amount} FLT`}
dt={dateInFuture ? formatSeconds(secondsLeft) : "ready to be claimed"}
colorD="orange"
colorT="black"
/>}
{amountAndDate.amount === 0 && "No FLT to claim"}
</> : (
<>
{(!address || !network) && "Connect your wallet"}
{address && network && "Loading data..."}
</>
)}
</div>
</div>
<div className={styles.dashboard__text}>
<Text color="black" type="large">
Claiming is a transfer of tokens to yourself or another address
</Text>
</div>
<ol className={styles.dashboard__list}>
<li className={styles.dashboard__item}>
Connect an Ethereum wallet
</li>
<li className={styles.dashboard__item}>
Press claim and sign a transaction
</li>
<li className={styles.dashboard__item}>
Or just use metamask or another wallet – transfer tokens to yourself
</li>
{secondsLeft > 0 && <li className={styles.dashboard__item}>
You will be able to claim at {amountAndDate.unlockTime.toLocaleString()}
</li>}
</ol>
<div className={styles.dashboard__caption}>
<Text color="grey" type="small"></Text>
</div>
<div className={styles["dashboard__flex-container-flat"]}>
<div className={styles.dashboard__button}>
<ConnectWallet />
</div>
{!dateInFuture && Boolean(amountAndDate?.amount) && <div className={styles.dashboard__button}>
{waitForSigning && "Please sign tx in your wallet"}
{waitForReceipt && "Confirming..."}
{confirmedTxHash && <a href={supportedChains[0].explorer_url + "/tx/" + confirmedTxHash} target="_blank" rel="noreferrer">Transaction confirmed</a>}
{!waitForSigning && !waitForReceipt && !confirmedTxHash && <Button callback={handleClaim} text={`Claim FLT`} />}
</div>}
</div>
</Dashboard>
</div>
</main>
</div>
<Footer />
</div>
</>
);
});
Loading

0 comments on commit d093aca

Please sign in to comment.