Skip to content

Commit

Permalink
Pool list interface replacement (#542)
Browse files Browse the repository at this point in the history
* feat: add pagination

* feat: add pagination

* feat: add pools type condition

* feat: delete morepools id

* fix:fix pools search

* fix:pool list bug fix

* fix: fix pool list & and add mobile pagination

* feat:add pool detail interactive & fix some bug

* perf: change decimals

* feat: change search interface

* fix:  pagination currentpage

* fix: add farm_apy

* fix: fix pagination & add mobile pagination

* fix: client width error

* fix: tab change init currentpage

* feat: change 24vol interface

* fix: fix url

* fix: 24vol path fix

* fix: init currentpage when check farmonly and lowtvl

* fix: change tofixed

* feat: add locklp

* fix: add new format fn.

* perf: merge function

* feat: interface auth test

* update config

* feat: change url

* update signature.ts

* fix: pagination change

* perf: dcl pool loading

* update orderly tip

* perf: add default height

* feat: remove activeTab

---------

Co-authored-by: deep-path <[email protected]>
Co-authored-by: xieqian <[email protected]>
  • Loading branch information
3 people authored Jun 20, 2024
1 parent 3f5d293 commit 134db7a
Show file tree
Hide file tree
Showing 21 changed files with 1,371 additions and 457 deletions.
25 changes: 25 additions & 0 deletions src/components/icon/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@ import React from 'react';

const bgGridSmallImg = 'https://i.postimg.cc/43xZN5zd/bg-image2.png';

export function LoadingSmall() {
return (
<div className="slick-loader-new active">
<svg
width="100px"
height="100px"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 100 100"
preserveAspectRatio="xMidYMid"
className="lds-eclipse"
style={{ background: 'none' }}
>
{' '}
<path
ng-attr-d="{{config.pathCmd}}"
ng-attr-fill="{{config.color}}"
stroke="none"
d="M10 50A40 40 0 0 0 90 50A40 42 0 0 1 10 50"
fill="#10B981"
></path>{' '}
</svg>
</div>
);
}

export function Loading() {
return (
<div className="slick-loader active">
Expand Down
39 changes: 39 additions & 0 deletions src/components/icon/PoolsPagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';

export const PrePage = () => {
return (
<svg
width="11"
height="12"
viewBox="0 0 11 12"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M5.70711 1.91667V0L0 5.70711L5.70711 11.4142L5.70711 9.53304L1.82843 5.70711L5.70711 1.91667ZM10.7071 1.91667V0L5 5.70711L10.7071 11.4142L10.7071 9.53304L6.82843 5.70711L10.7071 1.91667Z"
fill="#7E8A93"
/>
</svg>
);
};

export const NextPage = () => {
return (
<svg
width="11"
height="12"
viewBox="0 0 11 12"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M4.99992 1.91667V0L10.707 5.70711L4.99992 11.4142L4.99992 9.53304L8.8786 5.70711L4.99992 1.91667ZM-7.62939e-05 1.91667V0L5.70703 5.70711L-7.53403e-05 11.4142L-7.72476e-05 9.53304L3.8786 5.70711L-7.62939e-05 1.91667Z"
fill="white"
/>
</svg>
);
};
10 changes: 8 additions & 2 deletions src/components/pool/PoolTabV3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getAllTvl,
getAllVolume24h,
getYourPools,
getAllPoolData,
} from '../../services/indexer';
import { PoolTabBanner, PoolTabBannerMask } from '../icon/Pool';
import {
Expand Down Expand Up @@ -73,8 +74,13 @@ export const PoolTabV3 = ({

const [allVolume24h, setAllVolume24h] = useState<string>();
useEffect(() => {
getAllTvl().then(setAllTVL);
getAllVolume24h().then(setAllVolume24h);
// getAllTvl().then(setAllTVL);
// getAllVolume24h().then(setAllVolume24h);

getAllPoolData().then((res) => {
setAllTVL(res.tvl);
setAllVolume24h(res.volume_24h);
});
}, []);

const isMobile = useClientMobile();
Expand Down
239 changes: 239 additions & 0 deletions src/components/poolsPagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
import React, { useState, useMemo, useEffect } from 'react';
import { isMobile } from '../../utils/device';

const Pagination = ({
totalItems,
itemsPerPage,
onChangePage,
onPageSizeChange,
}: {
totalItems: number;
itemsPerPage: number;
onChangePage: any;
onPageSizeChange: any;
}) => {
const pageCount = Math.ceil(totalItems / itemsPerPage);

const [currentPage, setCurrentPage] = useState(1);
const [pageSize, setPageSize] = useState(itemsPerPage);
useEffect(() => {
setCurrentPage(1);
onChangePage(1, 100);
}, [pageCount]);
const activePageStyle = { backgroundColor: '#566069' };
const disableStyle = { color: '#7E8A93' };
const activeLinkStyle = { color: '#fff' };

const disableStyleMobile = {
color: '#7E8A93',
width: '1.75rem',
height: '1.75rem',
borderRadius: '8px',
border: '1px solid #7E8A93',
fontSize: '12px',
};

const activeLinkStyleMobile = {
color: '#00FFD1',
width: '1.75rem',
height: '1.75rem',
borderRadius: '8px',
border: '1px solid #00FFD1',
fontSize: '12px',
};

const goToPage = (pageNumber) => {
if (pageNumber >= 1 && pageNumber <= pageCount && pageNumber !== '...') {
setCurrentPage(pageNumber);
onChangePage(pageNumber, pageSize);
}
};

const handlePageSizeChange = (newPageSize: number) => {
setPageSize(newPageSize);
onPageSizeChange(newPageSize);
goToPage(1);
};

const goPreOrNext = (index) => {
if (index + 1 > 5) {
onChangePage(currentPage + 5);
setCurrentPage((pre) => pre + 5);
} else {
onChangePage(currentPage - 5);
setCurrentPage((pre) => pre - 5);
}
};

const pageNumbersList = useMemo(() => {
const renderList = [];
if (pageCount <= 7) {
for (let i = 1; i <= pageCount; i++) {
renderList.push(i);
}
} else {
// Condition for current page
if (currentPage < 5) {
renderList.push(...[1, 2, 3, 4, 5, 6, '...', pageCount]);
} else if (currentPage >= 5 && currentPage < pageCount - 4) {
renderList.push(
...[
1,
'...',
currentPage - 2,
currentPage - 1,
currentPage,
currentPage + 1,
currentPage + 2,
'...',
pageCount,
]
);
} else if (currentPage >= pageCount - 4) {
renderList.push(
...[
1,
'...',
pageCount - 5,
pageCount - 4,
pageCount - 3,
pageCount - 2,
pageCount - 1,
pageCount,
]
);
}
}
return renderList;
}, [currentPage, pageCount]);

const pageNumbersListForMobile = useMemo(() => {
return (
<div>
<span className="text-white">{currentPage}</span>/
<span className="text-primaryText">{pageCount}</span>
</div>
);
}, [currentPage, pageCount]);

return (
pageCount > 0 && (
<div
className={`flex justify-center items-center text-white text-sm font-bold cursor-pointer`}
>
{isMobile() ? (
<div className="flex mr-auto">
<div
className="flex items-center justify-center"
style={
currentPage == 1 ? disableStyleMobile : activeLinkStyleMobile
}
onClick={() => currentPage > 1 && goToPage(1)}
>
{`|<`}
</div>
<div
className="mx-6 flex items-center justify-center"
style={
currentPage == 1 ? disableStyleMobile : activeLinkStyleMobile
}
onClick={() => currentPage > 1 && goToPage(currentPage - 1)}
>
{`<<`}
</div>
</div>
) : (
<div
style={currentPage == 1 ? disableStyle : activeLinkStyle}
onClick={() => currentPage > 1 && goToPage(currentPage - 1)}
className="mr-auto"
>
{`<< Previous`}
</div>
)}

{/* main page list */}
{!isMobile() ? (
<ul className="flex w-80 justify-center">
{pageNumbersList.map((item, index) => {
if (item === '...') {
return (
<li
key={`ellipsis-${index}`}
className="w-6 h-6 frcc rounded"
>
<span
className="page-link"
onClick={() => goPreOrNext(index)}
>
{item}
</span>
</li>
);
} else {
return (
<li
key={item}
className={`frcc w-6 h-6 rounded ${
index % 2 == 0 ? 'mx-2' : ''
}`}
style={currentPage == item ? activePageStyle : undefined}
>
<span className="page-link" onClick={() => goToPage(item)}>
{item}
</span>
</li>
);
}
})}
</ul>
) : (
pageNumbersListForMobile
)}

{isMobile() ? (
<div className="flex ml-auto">
<div
className="mx-6 flex items-center justify-center"
style={
pageCount == 1 || currentPage == pageCount
? disableStyleMobile
: activeLinkStyleMobile
}
onClick={() =>
currentPage < pageCount && goToPage(currentPage + 1)
}
>
{`>>`}
</div>
<div
className="flex items-center justify-center"
style={
pageCount == 1 || currentPage == pageCount
? disableStyleMobile
: activeLinkStyleMobile
}
onClick={() => currentPage < pageCount && goToPage(pageCount)}
>
{`>|`}
</div>
</div>
) : (
<div
style={
pageCount == 1 || currentPage == pageCount
? disableStyle
: activeLinkStyle
}
onClick={() => currentPage < pageCount && goToPage(currentPage + 1)}
className=" ml-auto"
>
{`Next >>`}
</div>
)}
</div>
)
);
};

export default Pagination;
5 changes: 3 additions & 2 deletions src/components/stableswap/CommonComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const TknImages = ({
if (icon)
return (
<div
key={token?.id + index}
className={`inline-block flex-shrink-0 ${
is_vertical && index > 1 ? '-mt-3' : 'relative z-10'
} h-${size || 10} w-${size || 10} rounded-full ${
Expand Down Expand Up @@ -389,13 +390,13 @@ export const StableTokens = ({
};
function add_to_watchlist_tip() {
const tip = intl.formatMessage({ id: 'add_to_watchlist' });
let result: string = `<div class="text-navHighLightText text-xs text-left font-normal">${tip}</div>`;
const result: string = `<div class="text-navHighLightText text-xs text-left font-normal">${tip}</div>`;
return result;
}

function remove_from_watchlist_tip() {
const tip = intl.formatMessage({ id: 'remove_from_watchlist' });
let result: string = `<div class="text-navHighLightText text-xs text-left font-normal">${tip}</div>`;
const result: string = `<div class="text-navHighLightText text-xs text-left font-normal">${tip}</div>`;
return result;
}
const isMobile = isClientMobie();
Expand Down
Loading

0 comments on commit 134db7a

Please sign in to comment.