Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #557: View internal balances #633

Merged
merged 9 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/VaultBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const VaultBlock = ({ ...props }) => {
<div>{returnState(props.riskState) ? returnState(props.riskState) : 'Closed'}</div>
</Wrapper>
</Item>
{Number(props.internalCollateralBalance) > 0 && (
<Item>
<Label>{'Internal Balance'}</Label>
<Value>{formatWithCommas(props.internalCollateralBalance)}</Value>
</Item>
)}
</Block>
</BlockContainer>
</Link>
Expand Down
44 changes: 44 additions & 0 deletions src/components/VaultStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Tooltip as ReactTooltip } from 'react-tooltip'
import { generateSvg } from '@opendollar/svg-generator'
import { useWeb3React } from '@web3-react/core'
import { useAddress } from '~/hooks/useAddress'
import useGeb from '~/hooks/useGeb'

const VaultStats = ({
isModifying,
Expand All @@ -38,6 +39,7 @@ const VaultStats = ({
liquidationPrice: newLiquidationPrice,
account,
} = useSafeInfo(isModifying ? (isDeposit ? 'deposit_borrow' : 'repay_withdraw') : 'info')
const geb = useGeb()

const { safeModel: safeState } = useStoreState((state) => state)
const { singleSafe, liquidationData } = safeState
Expand Down Expand Up @@ -110,6 +112,21 @@ const VaultStats = ({
return false
}, [isModifying, parsedAmounts.leftInput, parsedAmounts.rightInput])

const handleClaimClick = async () => {
if (!account) return
try {
const proxy = await geb.getProxyAction(account)
await proxy.collectTokenCollateral(
geb.contracts.safeManager.address,
geb.contracts.tokenCollateralJoin[collateralName].address,
Number(singleSafe?.id),
Number(singleSafe?.internalCollateralBalance)
)
} catch (e) {
console.debug(e, 'Error in claiming internal balance')
}
}

return (
<>
<Flex>
Expand Down Expand Up @@ -330,6 +347,23 @@ const VaultStats = ({
</InfoIcon>
<SideValue>{`${returnRedRate()}%`}</SideValue>
</Side>
{Number(singleSafe?.internalCollateralBalance) > 0 ? (
<Side style={{ fontWeight: 'bold' }}>
<SideTitle>Internal Balance</SideTitle>
<InfoIcon
data-tooltip-id="vault-stats"
data-tooltip-content={t('internal_balance_tip')}
>
<Info size="16" />
</InfoIcon>
<ClaimLink onClick={handleClaimClick}>CLAIM</ClaimLink>
<SideValue>
{formatWithCommas(singleSafe?.internalCollateralBalance || '0', 2, 2)}
</SideValue>
</Side>
) : (
<></>
)}
</Inner>
</Right>
</Flex>
Expand Down Expand Up @@ -531,3 +565,13 @@ const InfoIcon = styled.div`
margin-top: 4px;
}
`

const ClaimLink = styled.span`
cursor: pointer;
font-family: 'Open Sans', sans-serif;
font-size: ${(props) => props.theme.font.xxSmall};
text-decoration: underline;
color: ${(props) => props.theme.colors.blueish};
margin-left: 5px;
padding-top: 1px;
`
1 change: 0 additions & 1 deletion src/containers/Earn/EarnBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import styled from 'styled-components'
import { formatWithCommas, getTokenLogo } from '~/utils'
import { Tooltip as ReactTooltip } from 'react-tooltip'

const Link = styled.a``
Expand Down
1 change: 1 addition & 0 deletions src/utils/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"repay_withdraw": "Repay & Withdraw",
"confirmations_info": "You need to wait for 10 block confirmations to make sure that your account address does not change.",
"annual_redemption_tip": "Rate at which OD is devalued or revalued over 1 year.",
"internal_balance_tip": "The internal balance of the Vault left in the system after the Vault is liquidated.",
"liquidation_price_tip": "Collateral price under which this Vault can get liquidated. The liquidation price varies with the redemption price.",
"liquidation_penalty_tip": "Liquidations ask for more OD than you have minted in your Vault, and apply a discount on the latest oracle price in order to incentivize bidding.",
"app": "App",
Expand Down
Loading