Skip to content

Commit

Permalink
Update sale endpoint (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideSilva authored Apr 9, 2024
1 parent 24e0138 commit afac3b6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/web-app/app/_server/sales.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use server';

import { ctzndSaleAbi, ctzndSaleAddress } from '@/wagmi.generated';
import { headers } from 'next/headers';
import { createWalletClient, getContract, http, publicActions } from 'viem';
import { sepolia } from 'viem/chains';

Expand All @@ -15,11 +16,35 @@ const contract = getContract({
client,
});

const projectStatus = async () => {
const start = await contract.read.start();
const end = await contract.read.end();
const current = Date.now();

if (current > end) {
return 'completed';
}

if (current < start) {
return 'upcoming';
}

return 'live';
};

export const saleDetails = async () => {
try {
const headersList = headers();
const host = headersList.get('host');

return [
{
project: 'Citizend',
status: await projectStatus(),
url: `${host}/projects/citizend`,
logo: `${host}/project-citizend-logo.svg`,
background: `${host}/citizend-card-desktop.png`,
backgroundMobile: `${host}/citizend-card-mobile.png`,
rate: await contract.read.rate(),
minTarget: await contract.read.minTarget(),
maxTarget: await contract.read.maxTarget(),
Expand Down
43 changes: 43 additions & 0 deletions packages/web-app/public/project-citizend-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit afac3b6

Please sign in to comment.