Skip to content

Commit

Permalink
remove comments and add preview link in the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazeeh21 committed Nov 28, 2024
1 parent 108d35d commit 99257e9
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 250 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ All examples are maintained by official Sway contributors and will be kept up to
#### Token Airdrop

- Learn how to work with merkle trees in Sway to distrubute native tokens across multiple addresses.
- [demo](https://fuellabs.github.io/sway-examples/pr-preview/pr-18/airdrop/)

#### [Counter Dapp](./counter/README.md)

Expand Down
1 change: 0 additions & 1 deletion airdrop/src/components/HomeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const HomeCard = ({
height: "142px",
width: "280px",
opacity: isEligible ? 1 : 0.5,
// pointerEvents: isEligible ? "auto" : "none",
}}
className={`${!isEligible ? "hover:bg-[#4db6ac] hover:text-black" : "hover:bg-slate-950"}`}
>
Expand Down
8 changes: 0 additions & 8 deletions airdrop/src/components/NavMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ export const NavMenu = () => {
const { connect } = useConnectUI();
const { disconnect } = useDisconnect();

// const [isDarkMode, setIsDarkMode] = useState(() => {
// return (
// localStorage.getItem("theme") === "dark" ||
// (!localStorage.getItem("theme") &&
// window.matchMedia("(prefers-color-scheme: dark)").matches)
// );
// });

const tryToAddNetwork = () => {
return alert(
`Please add the network ${NODE_URL} to your Fuel wallet, or swtich to it if you have it already, and refresh the page.`
Expand Down
2 changes: 1 addition & 1 deletion airdrop/src/components/WalletDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface WalletDisplayProps {

export const WalletDisplay: React.FC<WalletDisplayProps> = () => {
const { wallet, walletBalance } = useActiveWallet();
// const CopyIcon = darkMode ? CopyIconDark : CopyIconLight;

return (
wallet && (
<div className="flex gap-2 md:gap-4 items-center">
Expand Down
27 changes: 0 additions & 27 deletions airdrop/src/components/ui/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,3 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
Textarea.displayName = "Textarea"

export { Textarea }



// export const MultilineInput: React.FC<{
// value?: string;
// onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
// placeholder?: string;
// className?: string;
// type?: string;
// maxRows?: number;
// }> = ({ value, onChange, placeholder, className, type, maxRows }) => {
// return (
// <TextField
// value={value}
// className={clsx([
// ...inputStyle,
// className,
// "placeholder:text-zinc-400 text-zinc-50!important",
// ])}
// onChange={onChange}
// placeholder={placeholder}
// type={type}
// multiline
// maxRows={maxRows}
// />
// );
// };
8 changes: 6 additions & 2 deletions airdrop/src/hooks/useGetAirdropActive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AirdropQueryKeys } from "@/queryKeys";
import { TestContract } from "@/sway-api";
import { useQuery } from "@tanstack/react-query";
import { AbstractAddress, Provider } from "fuels";
import toast from "react-hot-toast";

type ContractId = string | AbstractAddress;

Expand All @@ -19,10 +20,13 @@ export const useGetAirdropActive = ({contractId}: Params) => {

const contract = new TestContract(contractId, provider!);

// const isActive = await contract.functions.
const isActive = await contract.functions.is_paused();
return isActive;
} catch (error) {

console.log(error);
toast.error("Failed to fetch airdrop status");
}
}
})
return query;
}
2 changes: 1 addition & 1 deletion airdrop/src/hooks/useGetAirdropData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const pinata = new PinataSDK({
export const useGetAirdropData = () => {
return useQuery<ContractIdData>({
queryKey: ["airdropData"],
// @ts-expect-error
// @ts-expect-error - revisit this later
queryFn: async () => {
try {
const options = {
Expand Down
14 changes: 2 additions & 12 deletions airdrop/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ const env = getEnv();
* `VITE_DAPP_DAPP_ENVIRONMENT` environment variable.
* If it's not set, the default is `local`.
*/
export const CURRENT_ENVIRONMENT: Environment = "testnet";
// (process.env.VITE_DAPP_DAPP_ENVIRONMENT as Environment) || Environments.LOCAL;
export const CURRENT_ENVIRONMENT: Environment = (process.env.VITE_PUBLIC_DAPP_ENVIRONMENT as Environment) || Environments.LOCAL;

const TESTNET_NETWORK_URL = "https://testnet.fuel.network/v1/graphql";
// The node URL is determined by the current environment too.
export const NODE_URL = TESTNET_NETWORK_URL;
// CURRENT_ENVIRONMENT === Environments.LOCAL
// ? `http://127.0.0.1:${process.env.VITE_FUEL_NODE_PORT || 4000}/v1/graphql`
// : TESTNET_NETWORK_URL;

export interface AppWallet {
wallet?: Account;
Expand All @@ -42,18 +38,12 @@ export interface AppWallet {

export const TESTNET_FAUCET_LINK = "https://faucet-testnet.fuel.network/";

export const FAUCET_LINK =
// @ts-expect-error will fix it once the build succeeds
CURRENT_ENVIRONMENT === Environments.LOCAL ? "/faucet" : TESTNET_FAUCET_LINK;
export const FAUCET_LINK = TESTNET_FAUCET_LINK

export const FAUCET_PRIVATE_KEY = "0x01";

export const DOCS_URL = "https://docs.fuel.network";

// export const GATEWAY_URL = process.env.VITE_PUBLIC_GATEWAY_URL
// ? process.env.VITE_PUBLIC_GATEWAY_URL
// : "https://beige-ready-porcupine-957.mypinata.cloud";

export const GATEWAY_URL = "https://beige-ready-porcupine-957.mypinata.cloud";

export const PINATA_JWT = env.VITE_PINATA_JWT;
Expand Down
14 changes: 1 addition & 13 deletions airdrop/src/routes/airdrop/claim/$slug.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { createLazyFileRoute, useParams } from "@tanstack/react-router";

// import { IdentityInput } from "@/contract-types/aidrop-contracts/contracts/AirdropContract";
// import { Vec } from "@/contract-types/aidrop-contracts/contracts/common";
// import { useClaimAirdrop } from "@/hooks/useClaimAirdrop";
// import { createMerkleTree, generateProof } from "@/utils/merkleTrees";
import {
copyToClipboard,
getTruncatedAddress,
Expand Down Expand Up @@ -34,10 +29,8 @@ import {
Recipient,
} from "../../../utils/merkleTrees";

// import { useGetOwner } from "@/hooks/useGetAirdropContractData";

export const Route = createLazyFileRoute("/airdrop/claim/$slug")({
// validateSearch: z.array(z.object({ address: z.string(), amount: z.string() })),
component: () => <ClaimAirdrop />,
});

Expand All @@ -49,8 +42,7 @@ function ClaimAirdrop() {
const { recipient } = Route.useSearch();
const contractId = slug as string;
const recipients = recipient as RecipientData;
// const recipients = JSON.parse(useSearchParams().get('recipient') as string)
// const { data: airdropData } = useGetAirdropData();

const {
mutate: claim,
error: claimError,
Expand Down Expand Up @@ -92,8 +84,6 @@ function ClaimAirdrop() {
refetch: refetchIsIntialized,
} = useGetIsInitialized({ contractId });

// console.log(endTime?.toNumber())

useEffect(() => {
console.log({ wallet });
if (recipients && wallet) {
Expand Down Expand Up @@ -142,9 +132,7 @@ function ClaimAirdrop() {
const { tree, root, leaves } = createMerkleTree(
recipients as RecipientData
);
// const { isValid } = verifyMerkleProof(possibleRecipient, root, tree);

// console.log("isValid", isValid);
const proof = generateProof(possibleRecipient, tree, treeIndex as number);
console.log("root", root);
console.log("tree", tree);
Expand Down
23 changes: 0 additions & 23 deletions airdrop/src/routes/airdrop/create.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createLazyFileRoute } from "@tanstack/react-router";
import { AssetId, BytesLike, DateTime } from "fuels";
import { useCallback, useEffect, useState } from "react";
import toast from "react-hot-toast";
// import { Button } from "../../components/Button";
import { Button } from "@/components/ui/button";
import {
copyToClipboard,
Expand Down Expand Up @@ -71,7 +70,6 @@ function Airdrop() {
const baseAssetId =
"0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07";

// const {mutateAsync, data: ipfsData, isSuccess: uploadToIpfsSuccess} = useUploadAirdropData();
const {
mutate: deployAirdrop,
isSuccess: deployAirdropSuccess,
Expand Down Expand Up @@ -135,16 +133,8 @@ function Airdrop() {
return;
}

// stringifyObj(recipients);
const { root, tree, leaves } = createMerkleTree(recipients);
console.log("root: ", root);
// const { isValid } = verifyMerkleProof(recipients[0], root, tree);

// console.log("Merkle proof valid:", isValid);
// console.log(
// "logging address: ",
// Address.fromDynamicInput(wallet?.address).toB256()
// );

// Define new configurable values
const configurableConstants = {
Expand Down Expand Up @@ -183,7 +173,6 @@ function Airdrop() {
initializeData?.transactionId &&
initializeSuccess
) {
// toast.success("Airdrop initialized successfully");
navigate({
to: VITE_BASE_URL + "/airdrop",
});
Expand Down Expand Up @@ -286,15 +275,3 @@ function Airdrop() {
</div>
);
}

// 0x6c49291704adc561074d887603c0c5e98b162b8662b746a1c945bb1c71e40f79, 0.001
// 0x4a30b5cc74a9094c16a6e86680e09c7bef7d4bfe5f52d577fc78efa87a1ac085, 0.001
// 0x4a30b5cc74a9094c16a6e86680e09c7bef7d4bfe5f52d577fc78efa87a1ac085, 0.001
// 0x4a30b5cc74a9094c16a6e86680e09c7bef7d4bfe5f52d577fc78efa87a1ac085, 0.001

// const dummy_recipients = [
// { address: "0x6c49291704adc561074d887603c0c5e98b162b86s62b746a1c945bb1c71e40f79", amount: BigInt(4000000000) },
// { address: "0x9a30b5cc74a9094c16a6e86680e09c7bef7d4bfe5f52d577fc78efa87a1ac085", amount: BigInt(4000000000) },
// ];

//base assetId=0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07
20 changes: 2 additions & 18 deletions airdrop/src/routes/airdrop/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createLazyFileRoute } from "@tanstack/react-router";
// import { HomeCard } from "@/components/HomeCard";
import { Text } from "../../components/Text";

import { FuelLogo } from "@/components/FuelLogo";
Expand All @@ -9,9 +8,8 @@ import { checkEligibility } from "@/utils/airdropEligibility";
import { Grid } from "@mui/material";
import { useNavigate } from "@tanstack/react-router";
import { useEffect } from "react";
import useAsync from "react-use/lib/useAsync";
import { Button } from "../../components/ui/button";
import { HomeCard } from "../../components/HomeCard";
import { Button } from "../../components/ui/button";
import { useGetAirdropData } from "../../hooks/useGetAirdropData";

export const Route = createLazyFileRoute("/airdrop/")({
Expand All @@ -27,18 +25,7 @@ function Index() {
console.log("airdropData: ", airdropData);
}, [airdropData, isFetching]);

/**
* useAsync is a wrapper around useEffect that allows us to run asynchronous code
* See: https://github.com/streamich/react-use/blob/master/docs/useAsync.md
*/
useAsync(async () => {
if (wallet) {
// Create a new instance of the contract
// const testContract = new TestContract(contractId, wallet);
// setContract(testContract);
}
}, [wallet]);


return (
<>
<div className="flex gap-4 items-center">
Expand Down Expand Up @@ -68,7 +55,6 @@ function Index() {
onClick={() =>
navigate({
to: "/airdrop/create",
// to: VITE_BASE_URL + "/airdrop/create",
})
}
>
Expand All @@ -94,8 +80,6 @@ function Index() {
>
<Text key={index}>
{getTruncatedAddress(contractId)}
{/* {contractId.toString().slice(0, 10)}....
{contractId.toString().slice(-3)} */}
</Text>
</HomeCard>
</Grid>
Expand Down
26 changes: 4 additions & 22 deletions airdrop/src/routes/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { createLazyFileRoute, useNavigate } from "@tanstack/react-router";
// import contractIds from "../sway-api/contract-ids.json";
import { FuelLogo } from "../components/FuelLogo";
// import { bn } from "fuels";
import { useGetAirdropData } from "@/hooks/useGetAirdropData";
import { useEffect } from "react";
import useAsync from "react-use/lib/useAsync";

import { useActiveWallet } from "../hooks/useActiveWallet";
import { HomeCard } from "@/components/HomeCard";
import { Text } from "@/components/Text";
import { Button } from "@/components/ui/button";
import { checkEligibility } from "@/utils/airdropEligibility";
import { Grid } from "@mui/material";
import { HomeCard } from "@/components/HomeCard";
import { VITE_BASE_URL } from "../lib";
import { getTruncatedAddress } from "../components/WalletDisplay";
import { checkEligibility } from "@/utils/airdropEligibility";
import { Button } from "@/components/ui/button";
import { useActiveWallet } from "../hooks/useActiveWallet";

export const Route = createLazyFileRoute("/")({
component: Index,
Expand All @@ -28,17 +24,6 @@ function Index() {
console.log("airdropData: ", airdropData);
}, [airdropData, isFetching]);

/**
* useAsync is a wrapper around useEffect that allows us to run asynchronous code
* See: https://github.com/streamich/react-use/blob/master/docs/useAsync.md
*/
useAsync(async () => {
if (wallet) {
// Create a new instance of the contract
// const testContract = new TestContract(contractId, wallet);
// setContract(testContract);
}
}, [wallet]);

return (
<>
Expand Down Expand Up @@ -69,7 +54,6 @@ function Index() {
onClick={() =>
navigate({
to: "/airdrop/create",
// to: VITE_BASE_URL + "/airdrop/create",
})
}
>
Expand All @@ -95,8 +79,6 @@ function Index() {
>
<Text key={index}>
{getTruncatedAddress(contractId)}
{/* {contractId.toString().slice(0, 10)}....
{contractId.toString().slice(-3)} */}
</Text>
</HomeCard>
</Grid>
Expand Down
Loading

0 comments on commit 99257e9

Please sign in to comment.