-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from multiversx/frontend-sort
Account Tokens Table
- Loading branch information
Showing
30 changed files
with
774 additions
and
75 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
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
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,48 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
interface GetItemsPageType { | ||
currentPage: number; | ||
itemsPerPage: number; | ||
items: any[]; | ||
} | ||
|
||
export const getItemsPage = ({ | ||
items, | ||
currentPage, | ||
itemsPerPage | ||
}: GetItemsPageType) => { | ||
const itemsPerPageBigNumber = new BigNumber(itemsPerPage); | ||
const currentPageBigNumber = new BigNumber(currentPage); | ||
const itemsLengthBigNumber = new BigNumber(items.length); | ||
|
||
const totalPages = Math.ceil( | ||
itemsLengthBigNumber.dividedBy(itemsPerPage).toNumber() | ||
); | ||
|
||
const totalPagesArray = Array.from({ length: totalPages }); | ||
const ranges = totalPagesArray.map((_, index) => [ | ||
itemsPerPageBigNumber.times(index), | ||
itemsPerPageBigNumber.times(new BigNumber(index).plus(1)) | ||
]); | ||
|
||
const rangesLengthBigNumber = new BigNumber(ranges.length); | ||
const currentRange = ranges.find((_, index) => { | ||
if (rangesLengthBigNumber.lte(currentPage)) { | ||
return rangesLengthBigNumber.minus(1).isEqualTo(index); | ||
} | ||
|
||
return currentPageBigNumber.minus(1).isEqualTo(index); | ||
}); | ||
|
||
if (!currentRange) { | ||
return items; | ||
} | ||
|
||
const [currentRangeStart, currentRangeEnd] = currentRange; | ||
const slicedTokensArray = items.slice( | ||
currentRangeStart.toNumber(), | ||
currentRangeEnd.toNumber() | ||
); | ||
|
||
return slicedTokensArray; | ||
}; |
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,14 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { LOW_LIQUIDITY_DISPLAY_TRESHOLD } from 'appConstants'; | ||
import { TokenType } from 'types'; | ||
|
||
export const isValidTokenValue = (token: TokenType) => { | ||
return Boolean( | ||
token.valueUsd && | ||
(!token.isLowLiquidity || | ||
new BigNumber(token.valueUsd).isLessThan( | ||
LOW_LIQUIDITY_DISPLAY_TRESHOLD | ||
)) | ||
); | ||
}; |
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
Oops, something went wrong.