Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sandoche/other fixes #54

Merged
merged 10 commits into from
Sep 13, 2024
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const nextConfig = {
protocol: 'https',
hostname: 'raw.githubusercontent.com',
port: '',
pathname: 'm/evmos/chain-token-registry/main/assets/tokens/',
pathname: '/evmos/chain-token-registry/main/assets/tokens/',
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion src/app/_components/BiddingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const BiddingForm = ({ evmosToUsdRate, priceError }: { evmosToUsdRate: nu
placeholder="Amount"
value={state.context.bidAmount}
onChange={(e) => send({ type: 'SET_BID_AMOUNT', value: e.target.value })}
disabled={isSubmitDisabled}
disabled={state.matches('submitting') || state.matches('success')}
/>
<Image src="/icons/evmos.svg" alt="EVMOS" width={24} height={24} className="absolute right-3 top-1/2 transform -translate-y-1/2 pointer-events-none" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/_components/Countdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type TimeLeft = {
};

const REFRESH_INTERVAL = 1000;
const DELAY_BEFORE_RELOAD_AFTER_COUNTDOWN_GOES_TO_ZERO = 5000;
export const DELAY_BEFORE_RELOAD_AFTER_COUNTDOWN_GOES_TO_ZERO = 5000;

const calculateTimeLeft = (date: Date): TimeLeft => {
const difference = +date - +new Date();
Expand Down
54 changes: 54 additions & 0 deletions src/app/_components/__tests__/Countdown.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright Tharsis Labs Ltd.(Evmos)
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/burn-auction-dapp/blob/main/LICENSE)

import { render, act, screen } from '@testing-library/react';
import { expect, describe, it, beforeEach, afterEach, vi } from 'vitest';

import { Countdown, DELAY_BEFORE_RELOAD_AFTER_COUNTDOWN_GOES_TO_ZERO } from '../Countdown';
import * as reloadDataModule from '../../_actions/reloadData';

const ONE_SECOND = 1000;
const ONE_HOUR_ONE_MINUTE_AND_TEN_SECONDS = 3670000;

// Mock the entire module
vi.mock('../../_actions/reloadData');

describe('Countdown Component', () => {
beforeEach(() => {
vi.useFakeTimers();
// Create a mock function for reloadData
vi.spyOn(reloadDataModule, 'default').mockImplementation(vi.fn());
});

afterEach(() => {
vi.clearAllTimers();
vi.clearAllMocks();
});

it('renders correctly', () => {
const targetDate: Date = new Date(Date.now() + ONE_HOUR_ONE_MINUTE_AND_TEN_SECONDS);
render(<Countdown date={targetDate} />);
expect(screen.getByText(/0d/)).toBeDefined();
expect(screen.getByText(/1h/)).toBeDefined();
expect(screen.getByText(/1m/)).toBeDefined();
expect(screen.getByText(/10s/)).toBeDefined();
});

it('reloads when reaching 0', () => {
const targetDate = new Date(Date.now() + ONE_SECOND); // Set to 1 second in the future
render(<Countdown date={targetDate} />);

// Fast-forward time to just after the countdown should reach zero
act(() => {
vi.advanceTimersByTime(ONE_SECOND + 1);
});

// Fast-forward time to trigger the delayed reload
act(() => {
vi.advanceTimersByTime(DELAY_BEFORE_RELOAD_AFTER_COUNTDOWN_GOES_TO_ZERO);
});

// Check if reloadData was called
expect(reloadDataModule.default).toHaveBeenCalledTimes(1);
});
});
24 changes: 24 additions & 0 deletions src/app/_components/__tests__/DiscountChip.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Tharsis Labs Ltd.(Evmos)
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/burn-auction-dapp/blob/main/LICENSE)

import { render, screen } from '@testing-library/react';
import { expect, describe, it } from 'vitest';

import { DiscountChip } from '../DiscountChip';

describe('DiscountChip Component', () => {
it('displays the correct message when highestBidUsd is 0', () => {
render(<DiscountChip currentValueUsd={1000} highestBidUsd={0} />);
expect(screen.getByText('🤯 Be the first to bid')).toBeDefined();
});

it('displays the correct discount message when highestBidUsd is less than currentValueUsd', () => {
render(<DiscountChip currentValueUsd={1000} highestBidUsd={500} />);
expect(screen.getByText('🔥 2x cheaper than market value')).toBeDefined();
});

it('does not render anything when highestBidUsd is greater than currentValueUsd', () => {
const { container } = render(<DiscountChip currentValueUsd={1000} highestBidUsd={1500} />);
expect(container.firstChild).toBeNull();
});
});
2 changes: 2 additions & 0 deletions src/app/api/v1/indexer/auction-end-events/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ export async function GET() {
return Response.json({ error: 'Failed to index auction end events' }, { status: 500 });
}
}

export const dynamic = 'force-dynamic';
2 changes: 2 additions & 0 deletions src/app/api/v1/indexer/bid-events/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ export async function GET() {
return Response.json({ error: 'Failed to index bid events' }, { status: 500 });
}
}

export const dynamic = 'force-dynamic';
8 changes: 8 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ const RootLayout = ({
</nav>
<main>{children}</main>
</div>
<p className="text-center text-sm text-evmos-lightish mt-8 opacity-50">
Data provided by{' '}
<a target="_blank" rel="noreferrer" className="font-bold" href="https://www.coingecko.com">
CoinGecko
</a>
</p>
</body>
</html>
);
};

export default RootLayout;

export const dynamic = 'force-dynamic';
2 changes: 1 addition & 1 deletion src/queries/prismaFetchAuctionEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const prismaFetchAuctionEvents = async (page: number, itemsPerPage: numbe
include: {
coins: true,
},
skip: (page - 1) * itemsPerPage,
skip: page > 0 ? (page - 1) * itemsPerPage : 0,
take: itemsPerPage,
}),
);
Expand Down
Loading