Skip to content

Commit

Permalink
Merge pull request #3244 from Emurgo/fix/YOEXT-622/sorting-by-quantity
Browse files Browse the repository at this point in the history
fixing quantity sorting
  • Loading branch information
vsubhuman authored Jun 28, 2023
2 parents 0365f87 + 01a1710 commit 84e2a4f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const SORTING_COLUMNS = {
name: string,
id: string,
amount: string,
amountForSorting?: BigNumber,
|}
type Props = {|
+assetsList: Asset[],
Expand Down Expand Up @@ -136,6 +137,10 @@ export default class AssetsList extends Component<Props, State> {
this.setState({ sortingDirection: newSortDirection })

if (field === 'amount') {
const dedicatedField = 'amountForSorting';
if (a[dedicatedField] != null && b[dedicatedField] != null) {
return compareNumbers(a[dedicatedField], b[dedicatedField], newSortDirection)
}
return compareNumbers(a[field], b[field], newSortDirection)
}
// Other fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { Link } from 'react-router-dom';
import { ROUTES } from '../../../routes-config';
import CopyToClipboardText from '../../widgets/CopyToClipboardLabel';
import { ListEmpty } from './ListEmpty';
import BigNumber from 'bignumber.js';

const SORTING_DIRECTIONS = {
UP: 'UP',
Expand All @@ -48,6 +49,7 @@ export type Asset = {|
name: string,
id: string,
amount: string,
amountForSorting?: BigNumber,
|};
type Props = {|
+assetsList: Asset[],
Expand Down Expand Up @@ -90,6 +92,10 @@ function TokenList({ assetsList: list, shouldHideBalance, intl }: Props & Intl):
setState({ ...state, sortingDirection: newSortDirection });

if (field === SORTING_COLUMNS.AMOUNT) {
const dedicatedField = 'amountForSorting';
if (a[dedicatedField] != null && b[dedicatedField] != null) {
return compareNumbers(a[dedicatedField], b[dedicatedField], newSortDirection);
}
return compareNumbers(a[field], b[field], newSortDirection);
}
// Other fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class TokensPageRevamp extends Component<InjectedOrGenerated<Gene
name: truncateToken(getTokenStrictName(token.info) ?? '-'),
id: getTokenIdentifierIfExists(token.info) ?? '-',
amount: [beforeDecimal, afterDecimal].join(''),
amountForSorting: shiftedAmount,
}
});
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class WalletAssetsPage extends Component<InjectedOrGenerated<Gene
name: truncateToken(getTokenStrictName(token.info) ?? '-'),
id: (getTokenIdentifierIfExists(token.info) ?? '-'),
amount: [beforeDecimal, afterDecimal].join(''),
amountForSorting: shiftedAmount,
}
});
})();
Expand Down

0 comments on commit 84e2a4f

Please sign in to comment.