-
Notifications
You must be signed in to change notification settings - Fork 22
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
569fb4b
commit 412f3b6
Showing
5 changed files
with
42 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"swaylend-dapp": patch | ||
--- | ||
|
||
Fixes wrong calculation of available liquidity on the dapp |
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 |
---|---|---|
@@ -1,32 +1,41 @@ | ||
import { useMarketStore } from '@/stores'; | ||
import { formatUnits } from '@/utils'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import BigNumber from 'bignumber.js'; | ||
import { useMarketBasics } from './useMarketBasics'; | ||
import { useMarketConfiguration } from './useMarketConfiguration'; | ||
import { useTotalReserves } from './useTotalReserves'; | ||
|
||
export const useMarketBalanceOfBase = (marketParam?: string) => { | ||
const { data: marketBasics } = useMarketBasics(marketParam); | ||
const { data: marketConfiguration } = useMarketConfiguration(marketParam); | ||
const { data: totalReserves } = useTotalReserves(marketParam); | ||
const { market: storeMarket } = useMarketStore(); | ||
const market = marketParam ?? storeMarket; | ||
|
||
if ( | ||
!marketBasics || | ||
!marketBasics.total_borrow_base || | ||
!marketBasics.total_supply_base || | ||
!marketConfiguration | ||
) | ||
return { | ||
raw: BigNumber(0), | ||
formatted: BigNumber(0), | ||
}; | ||
return useQuery({ | ||
queryKey: ['marketBalanceOfBase', market], | ||
queryFn: async () => { | ||
if (!marketBasics || !marketConfiguration || !totalReserves) { | ||
return { | ||
raw: BigNumber(0), | ||
formatted: BigNumber(0), | ||
}; | ||
} | ||
|
||
const balanceOfBase = BigNumber( | ||
marketBasics.total_supply_base.toString() | ||
).minus(BigNumber(marketBasics.total_borrow_base.toString())); | ||
const balanceOfBase = BigNumber(marketBasics.total_supply_base.toString()) | ||
.minus(BigNumber(marketBasics.total_borrow_base.toString())) | ||
.plus(totalReserves); | ||
|
||
return { | ||
raw: balanceOfBase, | ||
formatted: formatUnits( | ||
balanceOfBase, | ||
marketConfiguration.baseTokenDecimals | ||
), | ||
}; | ||
return { | ||
raw: balanceOfBase, | ||
formatted: formatUnits( | ||
balanceOfBase, | ||
marketConfiguration.baseTokenDecimals | ||
), | ||
}; | ||
}, | ||
refetchOnWindowFocus: false, | ||
enabled: !!marketBasics && !!marketConfiguration && !!totalReserves, | ||
}); | ||
}; |
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