forked from input-output-hk/daedalus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4797f4f
commit 79190d9
Showing
7 changed files
with
107 additions
and
110 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
5 changes: 5 additions & 0 deletions
5
source/renderer/app/components/staking/stake-pools/hooks/index.ts
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,5 @@ | ||
export { useCreateColumns } from './useCreateColumns'; | ||
export { | ||
useSortedStakePoolList, | ||
StakePoolsOrder, | ||
} from './useSortedStakePoolList'; |
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
54 changes: 54 additions & 0 deletions
54
source/renderer/app/components/staking/stake-pools/hooks/useSortedStakePoolList.tsx
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,54 @@ | ||
import { useMemo } from 'react'; | ||
import { orderBy } from 'lodash'; | ||
import StakePool from '../../../../domains/StakePool'; | ||
|
||
export enum StakePoolsOrder { | ||
Asc = 'asc', | ||
Desc = 'desc', | ||
} | ||
|
||
interface UseSortedStakePoolListArgs { | ||
stakePoolList: StakePool[]; | ||
sortBy: keyof StakePool; | ||
order: StakePoolsOrder; | ||
} | ||
|
||
export const useSortedStakePoolList = ({ | ||
stakePoolList, | ||
sortBy, | ||
order, | ||
}: UseSortedStakePoolListArgs) => | ||
useMemo( | ||
() => | ||
orderBy( | ||
stakePoolList.map((stakePool) => { | ||
let calculatedPledge; | ||
let calculatedCost; | ||
let formattedTicker; | ||
|
||
if (sortBy === 'ticker') { | ||
formattedTicker = stakePool.ticker | ||
.replace(/[^\w\s]/gi, '') | ||
.toLowerCase(); | ||
} | ||
|
||
if (sortBy === 'pledge') { | ||
calculatedPledge = parseFloat(stakePool.pledge.toFixed(2)); | ||
} | ||
|
||
if (sortBy === 'cost') { | ||
calculatedCost = parseFloat(stakePool.cost.toFixed(2)); | ||
} | ||
|
||
return { | ||
...stakePool, | ||
calculatedPledge, | ||
calculatedCost, | ||
formattedTicker, | ||
}; | ||
}), | ||
['formattedTicker', 'calculatedPledge', 'calculatedCost', sortBy], | ||
[order, order, order, order] | ||
), | ||
[stakePoolList, order, sortBy] | ||
); |
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