Merge commit '4875c77c530978a69defb89ace7e3446971e8641' into edit-orders

This commit is contained in:
Adrian Brzeziński 2022-12-14 17:48:44 +01:00
commit e12707acc6
2 changed files with 41 additions and 33 deletions

View File

@ -56,7 +56,7 @@ export const getTokenInMax = (
group, group,
inputBank.mint, inputBank.mint,
outputBank.mint, outputBank.mint,
1 inputBank.uiPrice / outputBank.uiPrice
), ),
inputBank.mintDecimals inputBank.mintDecimals
) )

View File

@ -313,40 +313,48 @@ const AdvancedTradeForm = () => {
const maintProjectedHealth = useMemo(() => { const maintProjectedHealth = useMemo(() => {
const group = mangoStore.getState().group const group = mangoStore.getState().group
const mangoAccount = mangoStore.getState().mangoAccount.current const mangoAccount = mangoStore.getState().mangoAccount.current
if (!mangoAccount || !group || !Number(tradeForm.baseSize)) return 100 if (
!mangoAccount ||
!group ||
!Number.isInteger(Number(tradeForm.baseSize))
)
return 100
let simulatedHealthRatio = 0 let simulatedHealthRatio = 0
try {
if (selectedMarket instanceof Serum3Market) { if (selectedMarket instanceof Serum3Market) {
simulatedHealthRatio = simulatedHealthRatio =
tradeForm.side === 'sell' tradeForm.side === 'sell'
? mangoAccount.simHealthRatioWithSerum3AskUiChanges( ? mangoAccount.simHealthRatioWithSerum3AskUiChanges(
group, group,
parseFloat(tradeForm.baseSize), parseFloat(tradeForm.baseSize),
selectedMarket.serumMarketExternal, selectedMarket.serumMarketExternal,
HealthType.maint HealthType.maint
) )
: mangoAccount.simHealthRatioWithSerum3BidUiChanges( : mangoAccount.simHealthRatioWithSerum3BidUiChanges(
group, group,
parseFloat(tradeForm.baseSize), parseFloat(tradeForm.baseSize),
selectedMarket.serumMarketExternal, selectedMarket.serumMarketExternal,
HealthType.maint HealthType.maint
) )
} else if (selectedMarket instanceof PerpMarket) { } else if (selectedMarket instanceof PerpMarket) {
simulatedHealthRatio = simulatedHealthRatio =
tradeForm.side === 'sell' tradeForm.side === 'sell'
? mangoAccount.simHealthRatioWithPerpAskUiChanges( ? mangoAccount.simHealthRatioWithPerpAskUiChanges(
group, group,
selectedMarket.perpMarketIndex, selectedMarket.perpMarketIndex,
parseFloat(tradeForm.baseSize), parseFloat(tradeForm.baseSize),
parseFloat(tradeForm.price) parseFloat(tradeForm.price)
) )
: mangoAccount.simHealthRatioWithPerpBidUiChanges( : mangoAccount.simHealthRatioWithPerpBidUiChanges(
group, group,
selectedMarket.perpMarketIndex, selectedMarket.perpMarketIndex,
parseFloat(tradeForm.baseSize), parseFloat(tradeForm.baseSize),
parseFloat(tradeForm.price) parseFloat(tradeForm.price)
) )
}
} catch (e) {
console.warn('Error calculating projected health: ', e)
} }
return simulatedHealthRatio > 100 return simulatedHealthRatio > 100