generated from scaffold-eth/scaffold-eth
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2180 from jk-labs-inc/staging
patch PR 5 of week ending 8/27/24
- Loading branch information
Showing
27 changed files
with
665 additions
and
607 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
.../react-app-revamp/components/ChargeLayout/components/Vote/components/ChargeInfo/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { chains } from "@config/wagmi"; | ||
import { extractPathSegments } from "@helpers/extractPath"; | ||
import { Charge, VoteType } from "@hooks/useDeployContest/types"; | ||
import { usePathname } from "next/navigation"; | ||
import React from "react"; | ||
import { formatEther } from "viem"; | ||
|
||
interface ChargeInfoProps { | ||
charge: Charge; | ||
} | ||
|
||
const ChargeInfo: React.FC<ChargeInfoProps> = ({ charge }) => { | ||
const asPath = usePathname(); | ||
const { chainName } = extractPathSegments(asPath ?? ""); | ||
const chainUnitLabel = chains.find((c: { name: string }) => c.name.toLowerCase() === chainName.toLowerCase()) | ||
?.nativeCurrency.symbol; | ||
const chargeAmount = charge.type.costToVote; | ||
const chargeLabel = charge.voteType === VoteType.PerVote ? "charge per vote" : "charge to vote"; | ||
const entryChargeFormatted = formatEther(BigInt(chargeAmount)); | ||
|
||
if (charge.type.costToPropose === 0 && charge.type.costToVote === 0) { | ||
return ( | ||
<div className="flex justify-between text-neutral-9 text-[16px]"> | ||
<p>charge to vote:</p> | ||
<p>gas fees only</p> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex justify-between text-neutral-9 text-[16px]"> | ||
<p>{chargeLabel}:</p> | ||
<p> | ||
{entryChargeFormatted} {chainUnitLabel} | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ChargeInfo; |
44 changes: 44 additions & 0 deletions
44
...ges/react-app-revamp/components/ChargeLayout/components/Vote/components/MyVotes/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { formatBalance } from "@helpers/formatBalance"; | ||
import { formatNumberAbbreviated } from "@helpers/formatNumber"; | ||
import { Charge, VoteType } from "@hooks/useDeployContest/types"; | ||
import React from "react"; | ||
import { useAccount, useBalance } from "wagmi"; | ||
|
||
interface MyVotesProps { | ||
amountOfVotes: number; | ||
charge: Charge | null; | ||
chainId?: number; | ||
} | ||
|
||
const MyVotes: React.FC<MyVotesProps> = ({ charge, amountOfVotes, chainId }) => { | ||
const { address } = useAccount(); | ||
const { data: balanceData } = useBalance({ | ||
address, | ||
chainId, | ||
}); | ||
|
||
const insufficientBalance = charge && balanceData ? balanceData.value < BigInt(charge.type.costToVote) : false; | ||
|
||
return ( | ||
<div | ||
className={`flex justify-between items-center text-[16px] ${insufficientBalance ? "text-negative-11" : "text-neutral-11"} transition-colors duration-300`} | ||
> | ||
<span className="text-neutral-11">my votes:</span> | ||
<div className="flex items-center gap-2"> | ||
{balanceData && charge?.voteType === VoteType.PerVote && ( | ||
<> | ||
<span className="text-neutral-14"> | ||
{formatBalance(balanceData.formatted)} {balanceData.symbol} | ||
</span> | ||
<span className="text-neutral-14">=</span> | ||
</> | ||
)} | ||
<span className="text-neutral-11"> | ||
{formatNumberAbbreviated(amountOfVotes)} vote{amountOfVotes !== 1 ? "s" : ""} | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MyVotes; |
50 changes: 50 additions & 0 deletions
50
...react-app-revamp/components/ChargeLayout/components/Vote/components/TotalCharge/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { chains } from "@config/wagmi"; | ||
import { extractPathSegments } from "@helpers/extractPath"; | ||
import { Charge } from "@hooks/useDeployContest/types"; | ||
import { usePathname } from "next/navigation"; | ||
import React, { useEffect, useState } from "react"; | ||
import { formatEther } from "viem"; | ||
interface TotalChargeProps { | ||
charge: Charge; | ||
amountOfVotes: number; | ||
} | ||
|
||
const TotalCharge: React.FC<TotalChargeProps> = ({ charge: contestCharge, amountOfVotes }) => { | ||
const [totalCharge, setTotalCharge] = useState("0"); | ||
const asPath = usePathname(); | ||
const { chainName } = extractPathSegments(asPath ?? ""); | ||
const chainUnitLabel = chains.find((c: { name: string }) => c.name.toLowerCase() === chainName.toLowerCase()) | ||
?.nativeCurrency.symbol; | ||
|
||
useEffect(() => { | ||
if (isNaN(amountOfVotes)) { | ||
setTotalCharge("0"); | ||
return; | ||
} | ||
|
||
if (contestCharge.type.costToVote === 0 && contestCharge.type.costToPropose === 0) { | ||
setTotalCharge("0"); | ||
return; | ||
} | ||
|
||
if (contestCharge.voteType === "PerVote") { | ||
const chargeAmount = parseFloat(formatEther(BigInt(contestCharge.type.costToVote))); | ||
const multipliedCharge = chargeAmount * amountOfVotes; | ||
const charge = +multipliedCharge.toFixed(6); | ||
setTotalCharge(charge.toString()); | ||
} else { | ||
setTotalCharge(formatEther(BigInt(contestCharge.type.costToVote))); | ||
} | ||
}, [contestCharge, amountOfVotes]); | ||
|
||
return ( | ||
<div className="flex items-center justify-between text-neutral-11 text-[16px]"> | ||
<p>total charge:</p> | ||
<p className="text-[24px] font-bold"> | ||
{totalCharge} {chainUnitLabel} | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TotalCharge; |
87 changes: 0 additions & 87 deletions
87
packages/react-app-revamp/components/ChargeLayout/components/Vote/index.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.