-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update homepage * added TODOs * fix next config * update components * implement burn * implement renewals * fix * e2e tests for the home page * fixes * fix build error * fix purchase history --------- Co-authored-by: Sergej <[email protected]>
- Loading branch information
Showing
15 changed files
with
602 additions
and
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'cypress'; | ||
|
||
describe('E2E tests for the index page', () => { | ||
beforeEach(() => { | ||
cy.visit('/'); | ||
// Initializing the API connections and fetching data | ||
cy.get('[data-cy="loading"]').should('exist'); | ||
// Fetching complete | ||
cy.get('[data-cy="loading"]', { timeout: 60 * 1000 }).should('not.exist'); | ||
}); | ||
|
||
it('Test UI elements on the home page', () => { | ||
cy.get('[data-cy="upcoming-burn"]').should('exist'); | ||
cy.get('[data-cy="previous-burn"]').should('exist'); | ||
cy.get('[data-cy="total-burn"]').should('exist'); | ||
cy.get('[data-cy="cores-sold"]').should('exist'); | ||
cy.get('[data-cy="cores-on-sale"]').should('exist'); | ||
cy.get('[data-cy="current-price"]').should('exist'); | ||
cy.get('[data-cy="renewals"]').should('exist'); | ||
cy.get('[data-cy="renewal-cost"]').should('exist'); | ||
cy.get('[data-cy="price-increase"]').should('exist'); | ||
|
||
// Buttons | ||
cy.get('[data-cy="btn-purchase-a-core"]').should('exist'); | ||
cy.get('[data-cy="btn-manage-regions"]').should('exist'); | ||
cy.get('[data-cy="btn-manage-paras"]').should('exist'); | ||
cy.get('[data-cy="btn-track-consumption"]').should('exist'); | ||
|
||
// Purchase history table | ||
cy.get('[data-cy="purchase-history-table"]').should('exist'); | ||
}); | ||
|
||
it('Test button: Purchase a core', () => { | ||
cy.get('[data-cy="btn-purchase-a-core"]').click(); | ||
cy.url({ timeout: 60 * 1000 }).should('contain', 'purchase'); | ||
}); | ||
|
||
it('Test button: Manage your regions', () => { | ||
cy.get('[data-cy="btn-manage-regions"]').click(); | ||
cy.url({ timeout: 60 * 1000 }).should('contain', 'regions'); | ||
}); | ||
|
||
it('Test button: Parachain Dashboard', () => { | ||
cy.get('[data-cy="btn-manage-paras"]').click(); | ||
cy.url({ timeout: 60 * 1000 }).should('contain', 'paras'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { SUBSCAN_CORETIME_API } from '@/consts'; | ||
import { NetworkType } from '@/models'; | ||
|
||
export const fetchPurchaseHistoryData = async ( | ||
network: NetworkType, | ||
regionBegin: number, | ||
page: number, | ||
row: number | ||
) => { | ||
const res = await fetch( | ||
`${SUBSCAN_CORETIME_API[network]}/api/scan/broker/purchased`, | ||
{ | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
region_begin: regionBegin, | ||
row, | ||
page, | ||
}), | ||
} | ||
); | ||
return res; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
import { Button } from '@mui/material'; | ||
import { Box, useTheme } from '@mui/material'; | ||
import React from 'react'; | ||
|
||
interface LinkProps { | ||
href: string; | ||
target?: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
export const Link = ({ href, target = '_blank', children }: LinkProps) => { | ||
const theme = useTheme(); | ||
|
||
const onClick = () => { | ||
if (!href) return; | ||
window.open(href, target); | ||
}; | ||
|
||
return <Button onClick={onClick}>{children}</Button>; | ||
return ( | ||
<Box | ||
onClick={onClick} | ||
sx={{ | ||
width: 'fit-content', | ||
cursor: 'pointer', | ||
color: theme.palette.primary.main, | ||
}} | ||
> | ||
{children} | ||
</Box> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './parasInfo'; | ||
export * from './purchaseHistory'; | ||
export * from './renewableParas'; | ||
export * from './sale'; |
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,74 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { sleep } from '@/utils/functions'; | ||
|
||
import { fetchPurchaseHistoryData } from '@/apis'; | ||
import { NetworkType, PurchaseHistoryResponse } from '@/models'; | ||
|
||
import { useSaleHistory } from './saleHistory'; | ||
|
||
export const useBurnInfo = (network: NetworkType) => { | ||
const [totalBurn, setTotalBurn] = useState(0); | ||
const [loading, setLoading] = useState(false); | ||
const [currentBurn, setCurrentBurn] = useState(0); | ||
const [prevBurn, setPrevBurn] = useState(0); | ||
|
||
const saleHistory = useSaleHistory(network, 0, 100); | ||
|
||
useEffect(() => { | ||
const asyncFetchData = async () => { | ||
setLoading(false); | ||
setTotalBurn(0); | ||
setCurrentBurn(0); | ||
setPrevBurn(0); | ||
|
||
if (saleHistory.isError) { | ||
return; | ||
} | ||
if (saleHistory.loading) { | ||
setLoading(true); | ||
return; | ||
} | ||
|
||
const regionBegins = saleHistory.data | ||
.map((item) => item.region_begin) | ||
.sort((a, b) => b - a); | ||
|
||
await sleep(1000); // 5 req/s limit in free plan | ||
|
||
let total = 0; | ||
for (let idx = 0; idx < regionBegins.length; ++idx) { | ||
const regionBegin = regionBegins[idx]; | ||
|
||
const res = await fetchPurchaseHistoryData( | ||
network, | ||
regionBegin, | ||
0, | ||
1000 | ||
); | ||
if (res.status !== 200) { | ||
idx--; | ||
continue; | ||
} | ||
|
||
const { message, data } = await res.json(); | ||
if (message !== 'Success') continue; | ||
|
||
const { list } = data as PurchaseHistoryResponse; | ||
const burn = list | ||
? list.reduce((acc, { price }) => acc + parseInt(price), 0) | ||
: 0; | ||
total += burn; | ||
|
||
if (idx === 0) setCurrentBurn(burn); | ||
else if (idx === 1) setPrevBurn(burn); | ||
|
||
await sleep(500); | ||
} | ||
setTotalBurn(total); | ||
setLoading(false); | ||
}; | ||
asyncFetchData(); | ||
}, [network, saleHistory.loading, saleHistory.isError]); | ||
return { loading, totalBurn, currentBurn, prevBurn }; | ||
}; |
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,3 @@ | ||
export * from './burnInfo'; | ||
export * from './purchaseHistory'; | ||
export * from './saleHistory'; |
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.