This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Savers overview table
- Loading branch information
Showing
18 changed files
with
508 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { getValueOfAsset1InAsset2, PoolData } from '@thorchain/asgardex-util' | ||
import { assetFromString, BaseAmount, baseAmount } from '@xchainjs/xchain-util' | ||
import * as A from 'fp-ts/lib/Array' | ||
import * as FP from 'fp-ts/lib/function' | ||
import * as O from 'fp-ts/lib/Option' | ||
import * as Ord from 'fp-ts/lib/Ord' | ||
|
||
import { PoolsWatchList } from '../../shared/api/io' | ||
import { Network } from '../../shared/api/types' | ||
import type { PoolDetails } from '../services/midgard/types' | ||
import { toPoolData } from '../services/midgard/utils' | ||
import { PoolDetail } from '../types/generated/midgard' | ||
import type { SaversTableRowData, SaversTableRowsData } from '../views/savers/Savers.types' | ||
import { eqAsset, eqString } from './fp/eq' | ||
import { ordBaseAmount } from './fp/ord' | ||
import { sequenceTOption, sequenceTOptionFromArray } from './fpHelpers' | ||
import { getDeepestPoolSymbol } from './poolHelper' | ||
|
||
/** | ||
* Order savers by depth price | ||
*/ | ||
export const ordSaversByDepth = Ord.Contravariant.contramap( | ||
ordBaseAmount, | ||
({ depthPrice }: { depthPrice: BaseAmount }) => depthPrice | ||
) | ||
|
||
export const getSaversTableRowData = ({ | ||
poolDetail, | ||
pricePoolData, | ||
watchlist, | ||
network | ||
}: { | ||
// TODO(@veado) Update Midgard types | ||
poolDetail: PoolDetail & { saversDepth?: string } | ||
pricePoolData: PoolData | ||
watchlist: PoolsWatchList | ||
network: Network | ||
}): O.Option<SaversTableRowData> => { | ||
return FP.pipe( | ||
poolDetail.asset, | ||
assetFromString, | ||
O.fromNullable, | ||
O.map((poolDetailAsset) => { | ||
const poolData = toPoolData(poolDetail) | ||
const depthAmount = baseAmount(poolDetail.saversDepth) | ||
const depthPrice = getValueOfAsset1InAsset2(depthAmount, poolData, pricePoolData) | ||
|
||
const watched: boolean = FP.pipe( | ||
watchlist, | ||
A.findFirst((poolInList) => eqAsset.equals(poolInList, poolDetailAsset)), | ||
O.isSome | ||
) | ||
|
||
return { | ||
asset: poolDetailAsset, | ||
depth: depthAmount, | ||
depthPrice, | ||
filled: 0, // TODO(@veado) Get dat from extra data | ||
count: 0, // TODO(@veado) Get dat from extra data | ||
key: poolDetailAsset.ticker, | ||
network, | ||
apr: 0, // get APR | ||
watched | ||
} | ||
}) | ||
) | ||
} | ||
|
||
export const getSaversTableRowsData = ({ | ||
poolDetails, | ||
pricePoolData, | ||
watchlist, | ||
network | ||
}: { | ||
poolDetails: PoolDetails | ||
pricePoolData: PoolData | ||
watchlist: PoolsWatchList | ||
network: Network | ||
}): SaversTableRowsData => { | ||
// get symbol of deepest pool | ||
const oDeepestPoolSymbol: O.Option<string> = getDeepestPoolSymbol(poolDetails) | ||
|
||
// Transform `PoolDetails` -> SaversTableRowData | ||
return FP.pipe( | ||
poolDetails, | ||
A.mapWithIndex<PoolDetail, O.Option<SaversTableRowData>>((index, poolDetail) => { | ||
// get symbol of PoolDetail | ||
const oPoolDetailSymbol: O.Option<string> = FP.pipe( | ||
O.fromNullable(assetFromString(poolDetail.asset ?? '')), | ||
O.map(({ symbol }) => symbol) | ||
) | ||
// compare symbols to set deepest pool | ||
const deepest = FP.pipe( | ||
sequenceTOption(oDeepestPoolSymbol, oPoolDetailSymbol), | ||
O.fold( | ||
() => false, | ||
([deepestPoolSymbol, poolDetailSymbol]) => eqString.equals(deepestPoolSymbol, poolDetailSymbol) | ||
) | ||
) | ||
|
||
return FP.pipe( | ||
getSaversTableRowData({ poolDetail, pricePoolData, watchlist, network }), | ||
O.map( | ||
(poolTableRowData) => | ||
({ | ||
...poolTableRowData, | ||
key: poolDetail?.asset || index.toString(), | ||
deepest | ||
} as SaversTableRowData) | ||
) | ||
) | ||
}), | ||
sequenceTOptionFromArray, | ||
O.getOrElse(() => [] as SaversTableRowsData), | ||
// Table does not accept `defaultSortOrder` for depth for any reason, | ||
// that's why we sort depth here | ||
A.sortBy([ordSaversByDepth]), | ||
// descending sort | ||
A.reverse | ||
) | ||
} |
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
Oops, something went wrong.