Skip to content

Commit

Permalink
Check QUI balance before redemption
Browse files Browse the repository at this point in the history
  • Loading branch information
danielattilasimon committed Apr 13, 2020
1 parent d5709f7 commit 07cd822
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const LiquityFrontend: React.FC<LiquityFrontendProps> = ({ loader }) => {
<>
<TroveManager {...{ liquity, trove, price, total, quiBalance }} />
<StabilityDepositManager {...{ liquity, deposit, trove, price, quiBalance }} />
<RedemptionManager {...{ liquity, price }} />
<RedemptionManager {...{ liquity, price, quiBalance }} />
</>
)}
</Box>
Expand Down
27 changes: 23 additions & 4 deletions packages/frontend/src/components/RedemptionManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type RedemptionActionProps = {
setExchangedQui: (exchangedQui: Decimal) => void;
changePending: boolean;
setChangePending: (isPending: boolean) => void;
quiBalance: Decimal;
};

const RedemptionAction: React.FC<RedemptionActionProps> = ({
Expand All @@ -22,7 +23,8 @@ const RedemptionAction: React.FC<RedemptionActionProps> = ({
exchangedQui,
setExchangedQui,
changePending,
setChangePending
setChangePending,
quiBalance
}) => {
const myTransactionId = "redemption";
const myTransactionState = useMyTransactionState(myTransactionId);
Expand Down Expand Up @@ -57,7 +59,11 @@ const RedemptionAction: React.FC<RedemptionActionProps> = ({
</Flex>
) : changePending ? null : (
<Flex mt={4} justifyContent="center">
<Transaction id={myTransactionId} {...{ send }}>
<Transaction
id={myTransactionId}
requires={[[quiBalance.gte(exchangedQui), "You don't have enough QUI"]]}
{...{ send }}
>
<Button mx={2}>Exchange {exchangedQui.prettify()} QUI</Button>
</Transaction>
</Flex>
Expand All @@ -67,9 +73,14 @@ const RedemptionAction: React.FC<RedemptionActionProps> = ({
type RedemptionManagerProps = {
liquity: Liquity;
price: Decimal;
quiBalance: Decimal;
};

export const RedemptionManager: React.FC<RedemptionManagerProps> = ({ liquity, price }) => {
export const RedemptionManager: React.FC<RedemptionManagerProps> = ({
liquity,
price,
quiBalance
}) => {
const zero = Decimal.from(0);
const [exchangedQui, setExchangedQui] = useState(zero);
const [changePending, setChangePending] = useState(false);
Expand Down Expand Up @@ -140,7 +151,15 @@ export const RedemptionManager: React.FC<RedemptionManagerProps> = ({ liquity, p
</Box>

<RedemptionAction
{...{ liquity, price, exchangedQui, setExchangedQui, changePending, setChangePending }}
{...{
liquity,
price,
exchangedQui,
setExchangedQui,
changePending,
setChangePending,
quiBalance
}}
/>
</>
);
Expand Down

0 comments on commit 07cd822

Please sign in to comment.