update balance table when performing an action (#56)
* update balance table when performing an action * filter assets with no amount as a result of an action * feat: slippage tolerance input added * update default slippage to 1%
This commit is contained in:
parent
ee71260429
commit
8aaeb36efa
@ -310,7 +310,7 @@ const BorrowModal = ({ show, onClose, tokenDenom }: Props) => {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{positionsData?.coins.map((coin) => (
|
{accountStats?.assets.map((coin) => (
|
||||||
<tr key={coin.denom} className='text-xs text-white/50'>
|
<tr key={coin.denom} className='text-xs text-white/50'>
|
||||||
<td>{getTokenSymbol(coin.denom)}</td>
|
<td>{getTokenSymbol(coin.denom)}</td>
|
||||||
<td>
|
<td>
|
||||||
@ -327,7 +327,7 @@ const BorrowModal = ({ show, onClose, tokenDenom }: Props) => {
|
|||||||
<td className='text-right'>-</td>
|
<td className='text-right'>-</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
{positionsData?.debts.map((coin) => (
|
{accountStats?.debts.map((coin) => (
|
||||||
<tr key={coin.denom} className='text-xs text-red-500'>
|
<tr key={coin.denom} className='text-xs text-red-500'>
|
||||||
<td className='text-white/50'>{getTokenSymbol(coin.denom)}</td>
|
<td className='text-white/50'>{getTokenSymbol(coin.denom)}</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -27,6 +27,7 @@ const TradeActionModule = () => {
|
|||||||
const [selectedTokenOut, setSelectedTokenOut] = useState('')
|
const [selectedTokenOut, setSelectedTokenOut] = useState('')
|
||||||
const [amountIn, setAmountIn] = useState(0)
|
const [amountIn, setAmountIn] = useState(0)
|
||||||
const [amountOut, setAmountOut] = useState(0)
|
const [amountOut, setAmountOut] = useState(0)
|
||||||
|
const [slippageTolerance, setSlippageTolerance] = useState(1)
|
||||||
const [fundingMode, setFundingMode] = useState<FundingMode>(FundingMode.WalletAndAccount)
|
const [fundingMode, setFundingMode] = useState<FundingMode>(FundingMode.WalletAndAccount)
|
||||||
|
|
||||||
const [isMarginEnabled, setIsMarginEnabled] = React.useState(false)
|
const [isMarginEnabled, setIsMarginEnabled] = React.useState(false)
|
||||||
@ -87,7 +88,7 @@ const TradeActionModule = () => {
|
|||||||
depositAmount,
|
depositAmount,
|
||||||
selectedTokenIn,
|
selectedTokenIn,
|
||||||
selectedTokenOut,
|
selectedTokenOut,
|
||||||
0.1,
|
slippageTolerance / 100,
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success(
|
toast.success(
|
||||||
@ -320,8 +321,18 @@ const TradeActionModule = () => {
|
|||||||
<p>{isMarginEnabled ? `${(borrowRate * 100).toFixed(2)}%` : '-'}</p>
|
<p>{isMarginEnabled ? `${(borrowRate * 100).toFixed(2)}%` : '-'}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='h-[100px] p-2'>
|
<div className='p-2'>
|
||||||
<div className='mb-6'>OTHER INFO PLACEHOLDER</div>
|
<div className='mb-6'>OTHER INFO PLACEHOLDER</div>
|
||||||
|
<div className='mb-2 flex justify-between'>
|
||||||
|
<p>Slippage Tolerance:</p>
|
||||||
|
<input
|
||||||
|
type='number'
|
||||||
|
step='0.1'
|
||||||
|
className='w-20 px-2 text-black'
|
||||||
|
onChange={(e) => setSlippageTolerance(e.target.valueAsNumber)}
|
||||||
|
value={slippageTolerance}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className='flex justify-between'>
|
<div className='flex justify-between'>
|
||||||
<p>Funded From</p>
|
<p>Funded From</p>
|
||||||
<select value={fundingMode} className='text-black' onChange={handleFundingModeChange}>
|
<select value={fundingMode} className='text-black' onChange={handleFundingModeChange}>
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { Dialog, Switch, Transition } from '@headlessui/react'
|
import { Dialog, Switch, Transition } from '@headlessui/react'
|
||||||
import * as RSlider from '@radix-ui/react-slider'
|
|
||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
import React, { useEffect, useMemo, useState } from 'react'
|
import React, { useEffect, useMemo, useState } from 'react'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
@ -303,7 +302,7 @@ const WithdrawModal = ({ show, onClose }: any) => {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{positionsData?.coins.map((coin) => (
|
{accountStats?.assets.map((coin) => (
|
||||||
<tr key={coin.denom} className='text-xs text-white/50'>
|
<tr key={coin.denom} className='text-xs text-white/50'>
|
||||||
<td>{getTokenSymbol(coin.denom)}</td>
|
<td>{getTokenSymbol(coin.denom)}</td>
|
||||||
<td>
|
<td>
|
||||||
@ -320,7 +319,7 @@ const WithdrawModal = ({ show, onClose }: any) => {
|
|||||||
<td className='text-right'>-</td>
|
<td className='text-right'>-</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
{positionsData?.debts.map((coin) => (
|
{accountStats?.debts.map((coin) => (
|
||||||
<tr key={coin.denom} className='text-xs text-red-500'>
|
<tr key={coin.denom} className='text-xs text-red-500'>
|
||||||
<td className='text-white/50'>{getTokenSymbol(coin.denom)}</td>
|
<td className='text-white/50'>{getTokenSymbol(coin.denom)}</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -124,6 +124,8 @@ const useAccountStats = (actions?: AccountStatsAction[]) => {
|
|||||||
risk,
|
risk,
|
||||||
totalPosition,
|
totalPosition,
|
||||||
totalDebt,
|
totalDebt,
|
||||||
|
assets,
|
||||||
|
debts,
|
||||||
}
|
}
|
||||||
}, [marketsData, positionsData, tokenPrices])
|
}, [marketsData, positionsData, tokenPrices])
|
||||||
|
|
||||||
@ -215,16 +217,18 @@ const useAccountStats = (actions?: AccountStatsAction[]) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const assets = resultPositionsCoins.map((coin) => {
|
const assets = resultPositionsCoins
|
||||||
const market = marketsData[coin.denom]
|
.filter((coin) => coin.amount !== '0')
|
||||||
|
.map((coin) => {
|
||||||
|
const market = marketsData[coin.denom]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
amount: coin.amount,
|
amount: coin.amount,
|
||||||
denom: coin.denom,
|
denom: coin.denom,
|
||||||
liquidationThreshold: market.liquidation_threshold,
|
liquidationThreshold: market.liquidation_threshold,
|
||||||
basePrice: tokenPrices[coin.denom],
|
basePrice: tokenPrices[coin.denom],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const debts = resultPositionsDebts.map((debt) => {
|
const debts = resultPositionsDebts.map((debt) => {
|
||||||
return {
|
return {
|
||||||
@ -245,6 +249,8 @@ const useAccountStats = (actions?: AccountStatsAction[]) => {
|
|||||||
risk,
|
risk,
|
||||||
totalPosition,
|
totalPosition,
|
||||||
totalDebt,
|
totalDebt,
|
||||||
|
assets,
|
||||||
|
debts,
|
||||||
}
|
}
|
||||||
}, [actions, marketsData, positionsData, tokenPrices])
|
}, [actions, marketsData, positionsData, tokenPrices])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user