Skip to content

Commit

Permalink
rendered final components
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobHomanics committed Apr 6, 2024
1 parent ac1e8d4 commit 34b2a59
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 134 deletions.
2 changes: 1 addition & 1 deletion packages/foundry/lib/reputation
60 changes: 42 additions & 18 deletions packages/nextjs/app/rep-tokens-demo/_components/RepTokensDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { StylizedTokenCard } from "~~/components/rep-tokens/cards/stylized-cards
import { StylizedTokenCard2 } from "~~/components/rep-tokens/cards/stylized-cards/StylizedTokenCard2";
import { StylizedTokenCard3 } from "~~/components/rep-tokens/cards/stylized-cards/StylizedTokenCard3";
import {
// ReputationComponent,
ReputationComponent,
StylizedTokenGroupCard,
} from "~~/components/rep-tokens/cards/stylized-cards/StylizedTokenGroupCard";
import { AddressCard } from "~~/components/rep-tokens/cards/stylized-cards/token-properties/AddressCard";
Expand All @@ -23,35 +23,34 @@ import { NameCard } from "~~/components/rep-tokens/cards/stylized-cards/token-pr
// import { SoulboundCard } from "~~/components/rep-tokens/cards/stylized-cards/token-properties/SoulboundCard";
import { TokenTypeCard } from "~~/components/rep-tokens/cards/stylized-cards/token-properties/TokenTypeCard";
import { useGetRepToken, useRepTokens } from "~~/components/rep-tokens/hooks/Hooks";

// import { useScaffoldContract, useScaffoldContractWrite } from "~~/hooks/scaffold-eth";
import { useScaffoldContract, useScaffoldContractWrite } from "~~/hooks/scaffold-eth";

export function RepTokensDemo() {
console.log("Hello");
const { address } = useAccount();

const { token } = useGetRepToken(address, BigInt(0));
const { token, refetchBalance } = useGetRepToken(address, BigInt(0));

token.image = token?.image?.replace("ipfs://", "https://ipfs.io/ipfs/");

const { tokensData: tokens /*refetchBalances: refetchUserBalances*/ } = useRepTokens(address);
const { tokensData: tokens, refetchBalances: refetchUserBalances } = useRepTokens(address);

for (let i = 0; i < tokens.tokens.length; i++) {
tokens.tokens[i].image = tokens.tokens[i].image?.replace("ipfs://", "https://ipfs.io/ipfs/");
}

// const { writeAsync: claim } = useScaffoldContractWrite({
// contractName: "ReputationFaucet",
// functionName: "claim",
// });
const { writeAsync: claim } = useScaffoldContractWrite({
contractName: "ReputationFaucet",
functionName: "claim",
});

// const { data: faucet } = useScaffoldContract({ contractName: "ReputationFaucet" });
const { data: faucet } = useScaffoldContract({ contractName: "ReputationFaucet" });

// const { tokensData: faucetTokensData, refetchBalances: refetchFaucetBalances } = useRepTokens(faucet?.address);
const { tokensData: faucetTokens, refetchBalances: refetchFaucetBalances } = useRepTokens(faucet?.address);

// for (let i = 0; i < faucetTokensData.tokens.length; i++) {
// faucetTokensData.tokens[i].image = faucetTokensData.tokens[i].image?.replace("ipfs://", "https://ipfs.io/ipfs/");
// }
for (let i = 0; i < faucetTokens.tokens.length; i++) {
faucetTokens.tokens[i].image = faucetTokens.tokens[i].image?.replace("ipfs://", "https://ipfs.io/ipfs/");
}

// const mainComponents: ReputationComponent[] = [
// "Balance",
Expand All @@ -64,19 +63,38 @@ export function RepTokensDemo() {
// "MaxMintAmountPerTx",
// ];

// const widgetComponents: ReputationComponent[] = ["Balance", "Image"];
const widgetComponents: ReputationComponent[] = ["Balance", "Image"];

console.log(token);

return (
<>
<div className="py-5 space-y-5 flex flex-col justify-center items-center bg-[length:100%_100%] py-1 px-5 sm:px-0 lg:py-auto max-w-[100vw] ">
<p className="text-center text-4xl">Faucet</p>
<StylizedTokenGroupCard
tokens={faucetTokens}
components={widgetComponents}
isBalanceOverlayed={true}
size="xs"
/>
<button
className="btn btn-primary btn-sm font-normal gap-1"
onClick={async () => {
await claim();
await refetchUserBalances();
await refetchFaucetBalances();
await refetchBalance();
}}
>
Claim Tokens
</button>
{/* <StylizedTokenGroupCard
tokens={faucetTokensData.tokens}
components={widgetComponents}
isBalanceOverlayed={true}
size="xs"
>
<StylizedStringCard value={"Faucet"} />
</StylizedTokenGroupCard>
<button
Expand Down Expand Up @@ -168,10 +186,16 @@ export function RepTokensDemo() {
</div>
</div>
<p className="text-center text-4xl">Multi-Card</p>
<StylizedTokenGroupCard tokens={tokens} showTopLevelAddress={true} />

<StylizedTokenGroupCard tokens={tokens}>
<StylizedAddressCard address={tokens.address} isGroup={true} />
</StylizedTokenGroupCard>
<p className="text-center text-4xl">Multi-Card w/ Overlay</p>
<StylizedTokenGroupCard tokens={tokens} showTopLevelAddress={true} isBalanceOverlayed={true} />

<p className="text-center text-4xl">Small</p>
<StylizedTokenGroupCard tokens={tokens} components={widgetComponents} isBalanceOverlayed={true} size="sm" />

<p className="text-center text-4xl">Faucet</p>
<StylizedTokenGroupCard tokens={tokens} components={widgetComponents} isBalanceOverlayed={true} size="xs" />

{/*
<p className="text-center text-4xl">Multi-Card W/ Overlay</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
// import { BalanceImageOverlay } from "./BalanceImageOverlay";
// import { StylizedAddressCard } from "./StylizedAddressCard";
// import { StylizedBalanceCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedBalanceCard";
// import { StylizedImageCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedImageCard";
// import { StylizedStringCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedStringCard";
import {
/*Token,*/
TokenGroup,
} from "../../hooks/Hooks";
import { TokenGroup } from "../../hooks/Hooks";
import { StylizedAddressCard } from "./StylizedAddressCard";
import { StylizedTokenCard3 } from "./StylizedTokenCard3";

// import { StylizedTokenCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedTokenCard";

export interface TokenCardInternalProps {
tokens: TokenGroup;
components?: ReputationComponent[];
isBalanceOverlayed?: boolean;
size?: "xs" | "sm" | "base" | "lg" | "xl" | "2xl" | "3xl";
children?: React.ReactNode;
showTopLevelAddress?: boolean;
}

const sizeMap = {
Expand Down Expand Up @@ -44,97 +36,26 @@ export const StylizedTokenGroupCard = ({
isBalanceOverlayed,
children,
size = "base",
showTopLevelAddress,
}: TokenCardInternalProps) => {
const output: any[] = [];

for (let i = 0; i < tokens?.tokens?.length; i++) {
// const cardContent: any[] = [];

// for (let j = 0; j < components?.length; j++) {
// if (components[j] === "Balance") {
// if (isBalanceOverlayed) {
// let doesImageComponentExist;
// for (let k = 0; k < components?.length; k++) {
// if (k === j) continue;

// if (components[k] === "Image") {
// doesImageComponentExist = true;
// break;
// }
// }

// if (doesImageComponentExist) {
// cardContent.push(
// <BalanceImageOverlay key={j} balance={Number(tokens[i]?.balance)} image={tokens[i]?.image} size={size} />,
// );
// } else {
// cardContent.push(
// <StylizedBalanceCard key={j} value={Number(tokens[i]?.balance)} isOverlay={false} size={size} />,
// );
// }
// } else {
// cardContent.push(
// <StylizedBalanceCard key={j} value={Number(tokens[i]?.balance)} isOverlay={false} size={size} />,
// );
// }
// }

// if (!isBalanceOverlayed) {
// if (components[j] === "Image") {
// cardContent.push(<StylizedImageCard key={j} src={tokens[i]?.image} size={size} />);
// }
// }

// if (components[j] === "Name") {
// cardContent.push(<StylizedStringCard key={j} value={tokens[i]?.name} type="bold" />);
// }

// if (components[j] === "Description") {
// cardContent.push(<StylizedStringCard key={j} value={tokens[i]?.description} />);
// }

// if (components[j] === "IsSoulbound") {
// cardContent.push(
// <StylizedStringCard key={j} value={`Soulbound: ${tokens[i]?.properties.isSoulbound.toString()}`} />,
// );
// }

// if (components[j] === "IsRedeemable") {
// cardContent.push(
// <StylizedStringCard key={j} value={`Redeemable: ${tokens[i]?.properties.isRedeemable.toString()}`} />,
// );
// }

// if (components[j] === "MaxMintAmountPerTx") {
// cardContent.push(
// <StylizedStringCard
// key={j}
// value={`Max Mint Amount Per Tx: ${tokens[i]?.properties.maxMintAmountPerTx.toString()}`}
// />,
// );
// }

// if (components[j] === "Address") {
// cardContent.push(<StylizedAddressCard key={j} address={tokens[i].address} />);
// }
// }

const card = (
<StylizedTokenCard3
key={i}
size={size}
token={tokens.tokens[i]}
components={components}
isBalanceOverlayed={isBalanceOverlayed}
>
{/* {cardContent} */}
</StylizedTokenCard3>
/>
);
output.push(card);
}

return (
<div className={`bg-base-100 flex flex-col rounded-lg ${sizeMap[size]}`}>
{showTopLevelAddress ? <StylizedAddressCard address={tokens.address} isGroup={true} /> : <></>}
{children}
<div className={`flex flex-wrap justify-center ${sizeMap[size]} rounded-lg bg-base-200`}>{output}</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// import { BalanceImageOverlay } from "./BalanceImageOverlay";
// import { StylizedAddressCard } from "./StylizedAddressCard";
// import { StylizedBalanceCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedBalanceCard";
// import { StylizedImageCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedImageCard";
// import { StylizedStringCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedStringCard";
import {
/*Token,*/
TokenGroup,
} from "../../hooks/Hooks";
import { StylizedTokenCard3 } from "./StylizedTokenCard3";

// import { StylizedTokenCard } from "~~/components/rep-tokens/cards/stylized-cards/StylizedTokenCard";

export interface TokenCardInternalProps {
tokens: TokenGroup;
components?: ReputationComponent[];
isBalanceOverlayed?: boolean;
size?: "xs" | "sm" | "base" | "lg" | "xl" | "2xl" | "3xl";
children?: React.ReactNode;
}

const sizeMap = {
xs: "p-1",
sm: "p-5",
base: "p-5",
lg: "",
xl: "",
"2xl": "",
"3xl": "",
};

export type ReputationComponent =
| "Balance"
| "Image"
| "Name"
| "Description"
| "Address"
| "TokenType"
| "MaxMintAmountPerTx";

export const StylizedTokenGroupCard3 = ({
tokens,
components = ["Balance", "Image", "Name", "Description", "Address", "TokenType", "MaxMintAmountPerTx"],
isBalanceOverlayed,
children,
size = "base",
}: TokenCardInternalProps) => {
const output: any[] = [];

for (let i = 0; i < tokens?.tokens?.length; i++) {
// const cardContent: any[] = [];

// for (let j = 0; j < components?.length; j++) {
// if (components[j] === "Balance") {
// if (isBalanceOverlayed) {
// let doesImageComponentExist;
// for (let k = 0; k < components?.length; k++) {
// if (k === j) continue;

// if (components[k] === "Image") {
// doesImageComponentExist = true;
// break;
// }
// }

// if (doesImageComponentExist) {
// cardContent.push(
// <BalanceImageOverlay key={j} balance={Number(tokens[i]?.balance)} image={tokens[i]?.image} size={size} />,
// );
// } else {
// cardContent.push(
// <StylizedBalanceCard key={j} value={Number(tokens[i]?.balance)} isOverlay={false} size={size} />,
// );
// }
// } else {
// cardContent.push(
// <StylizedBalanceCard key={j} value={Number(tokens[i]?.balance)} isOverlay={false} size={size} />,
// );
// }
// }

// if (!isBalanceOverlayed) {
// if (components[j] === "Image") {
// cardContent.push(<StylizedImageCard key={j} src={tokens[i]?.image} size={size} />);
// }
// }

// if (components[j] === "Name") {
// cardContent.push(<StylizedStringCard key={j} value={tokens[i]?.name} type="bold" />);
// }

// if (components[j] === "Description") {
// cardContent.push(<StylizedStringCard key={j} value={tokens[i]?.description} />);
// }

// if (components[j] === "IsSoulbound") {
// cardContent.push(
// <StylizedStringCard key={j} value={`Soulbound: ${tokens[i]?.properties.isSoulbound.toString()}`} />,
// );
// }

// if (components[j] === "IsRedeemable") {
// cardContent.push(
// <StylizedStringCard key={j} value={`Redeemable: ${tokens[i]?.properties.isRedeemable.toString()}`} />,
// );
// }

// if (components[j] === "MaxMintAmountPerTx") {
// cardContent.push(
// <StylizedStringCard
// key={j}
// value={`Max Mint Amount Per Tx: ${tokens[i]?.properties.maxMintAmountPerTx.toString()}`}
// />,
// );
// }

// if (components[j] === "Address") {
// cardContent.push(<StylizedAddressCard key={j} address={tokens[i].address} />);
// }
// }

const card = (
<StylizedTokenCard3
key={i}
size={size}
token={tokens.tokens[i]}
components={components}
isBalanceOverlayed={isBalanceOverlayed}
>
{/* {cardContent} */}
</StylizedTokenCard3>
);
output.push(card);
}

return (
<div className={`bg-base-100 flex flex-col rounded-lg ${sizeMap[size]}`}>
{children}
<div className={`flex flex-wrap justify-center ${sizeMap[size]} rounded-lg bg-base-200`}>{output}</div>
</div>
);
};
Loading

0 comments on commit 34b2a59

Please sign in to comment.