-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read project data from contracts (#219)
Why: * We had hardcoded values that needed to be replaced by the real values Also: - Adds functional allowance and contribution --------- Co-authored-by: Luís Torres <[email protected]> Co-authored-by: Luís Torres <[email protected]>
- Loading branch information
1 parent
5094602
commit 918355b
Showing
6 changed files
with
268 additions
and
104 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
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
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
96 changes: 96 additions & 0 deletions
96
packages/web-app/app/_ui/project/contribution/DataFields.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,96 @@ | ||
import { | ||
useReadCtzndSaleMaxContribution, | ||
useReadCtzndSaleMinContribution, | ||
useReadCtzndSaleInvestorCount, | ||
useReadCtzndSaleMaxTarget, | ||
useReadCtzndSaleMinTarget, | ||
} from '@/wagmi.generated'; | ||
import { formatEther } from 'viem'; | ||
import { usdValue } from '../../utils/intl-formaters/usd-value'; | ||
import { number } from '../../utils/intl-formaters/number'; | ||
|
||
const useMaxParticipants = () => { | ||
const { | ||
data: maxTarget, | ||
isLoading: maxLoading, | ||
error: maxError, | ||
} = useReadCtzndSaleMaxTarget(); | ||
const { | ||
data: minTarget, | ||
isLoading: minLoading, | ||
error: minError, | ||
} = useReadCtzndSaleMinTarget(); | ||
|
||
return { | ||
data: | ||
maxTarget === undefined || minTarget === undefined | ||
? undefined | ||
: BigInt(maxTarget) - BigInt(minTarget), | ||
isLoading: maxLoading || minLoading, | ||
error: maxError || minError, | ||
}; | ||
}; | ||
|
||
const LoadingField = () => ( | ||
<div className="h-5 w-full animate-pulse rounded-md bg-gradient-to-br from-mono-50 to-mono-200" /> | ||
); | ||
|
||
export const DataFields = () => { | ||
const { data: maxContribution } = useReadCtzndSaleMaxContribution(); | ||
const { data: minContribution } = useReadCtzndSaleMinContribution(); | ||
const { data: investorCount } = useReadCtzndSaleInvestorCount({ | ||
query: { | ||
refetchInterval: 1000 * 60, // every minute | ||
}, | ||
}); | ||
const { data: maxParticipants } = useMaxParticipants(); | ||
|
||
return ( | ||
<> | ||
<div className="md:col-span-2"> | ||
<div className="text-mono-800">Current price</div> | ||
<div>0.1 USDC*</div> | ||
</div> | ||
<div> | ||
<div className="text-mono-800">Min. contribution</div> | ||
<div> | ||
{minContribution !== undefined ? ( | ||
usdValue(formatEther(minContribution)) | ||
) : ( | ||
<LoadingField /> | ||
)} | ||
</div> | ||
</div> | ||
<div> | ||
<div className="text-mono-800">Max. contribution</div> | ||
<div> | ||
{maxContribution !== undefined ? ( | ||
usdValue(formatEther(maxContribution)) | ||
) : ( | ||
<LoadingField /> | ||
)} | ||
</div> | ||
</div> | ||
<div> | ||
<div className="text-mono-800">Current contributors</div> | ||
<div> | ||
{investorCount !== undefined ? ( | ||
number(investorCount) | ||
) : ( | ||
<LoadingField /> | ||
)} | ||
</div> | ||
</div> | ||
<div> | ||
<div className="text-mono-800">Max. participants</div> | ||
<div> | ||
{maxParticipants !== undefined ? ( | ||
number(maxParticipants) | ||
) : ( | ||
<LoadingField /> | ||
)} | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; |
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
Oops, something went wrong.