chore(utils): split sort-by functions
This commit is contained in:
parent
cf195f8083
commit
71ab42ec4b
|
@ -0,0 +1,13 @@
|
|||
// @flow
|
||||
|
||||
import 'jest-dom/extend-expect';
|
||||
|
||||
import { sortByDescend } from '../../app/utils/sort-by-descend';
|
||||
|
||||
describe('truncateAddress', () => {
|
||||
test('should truncate ZEC address', () => {
|
||||
expect(
|
||||
sortByDescend('id')([{ id: 5 }, { id: 2 }, { id: 1 }, { id: 0 }, { id: 1 }, { id: 1 }]),
|
||||
).toEqual([{ id: 5 }, { id: 2 }, { id: 1 }, { id: 1 }, { id: 1 }, { id: 0 }]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,13 @@
|
|||
// @flow
|
||||
|
||||
import 'jest-dom/extend-expect';
|
||||
|
||||
import { sortBy } from '../../app/utils/sort-by';
|
||||
|
||||
describe('truncateAddress', () => {
|
||||
test('should truncate ZEC address', () => {
|
||||
expect(
|
||||
sortBy('id')([{ id: 5 }, { id: 2 }, { id: 1 }, { id: 0 }, { id: 1 }, { id: 1 }]),
|
||||
).toEqual([{ id: 0 }, { id: 1 }, { id: 1 }, { id: 1 }, { id: 2 }, { id: 5 }]);
|
||||
});
|
||||
});
|
|
@ -15,7 +15,7 @@ import {
|
|||
loadWalletSummarySuccess,
|
||||
loadWalletSummaryError,
|
||||
} from '../redux/modules/wallet';
|
||||
import { sortByDescend } from '../utils/sort-by';
|
||||
import { sortByDescend } from '../utils/sort-by-descend';
|
||||
|
||||
import type { AppState } from '../types/app-state';
|
||||
import type { Dispatch } from '../types/redux';
|
||||
|
|
|
@ -17,7 +17,7 @@ import rpc from '../../services/api';
|
|||
import { listShieldedTransactions } from '../../services/shielded-transactions';
|
||||
import store from '../../config/electron-store';
|
||||
|
||||
import { sortByDescend } from '../utils/sort-by';
|
||||
import { sortByDescend } from '../utils/sort-by-descend';
|
||||
|
||||
import type { AppState } from '../types/app-state';
|
||||
import type { Dispatch } from '../types/redux';
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// @flow
|
||||
/* eslint-disable max-len */
|
||||
|
||||
// $FlowFixMe
|
||||
export const sortByDescend = <T>(field: string) => (arr: T[]): T[] => arr.sort((a, b) => (a[field] < b[field] ? 1 : -1));
|
|
@ -3,6 +3,3 @@
|
|||
|
||||
// $FlowFixMe
|
||||
export const sortBy = <T>(field: string) => (arr: T[]): T[] => arr.sort((a, b) => (a[field] > b[field] ? 1 : -1));
|
||||
|
||||
// $FlowFixMe
|
||||
export const sortByDescend = <T>(field: string) => (arr: T[]): T[] => arr.sort((a, b) => (a[field] < b[field] ? 1 : -1));
|
||||
|
|
Loading…
Reference in New Issue