Skip to content

Commit

Permalink
Merge pull request #241 from Plex-Engineer/lp-allowance-fix
Browse files Browse the repository at this point in the history
add allowance completion check
  • Loading branch information
dsudit01 authored Apr 27, 2023
2 parents a59a73d + b4a14f8 commit e9f7c67
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/pages/dexLP/modals/addModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ const AddAllowanceButton = (props: AddAllowanceProps) => {
useEffect(() => {
if (
props.pair.allowance.token1.lt(props.pair.balances.token1) ||
props.pair.allowance.token2.lt(props.pair.balances.token2)
props.pair.allowance.token2.lt(props.pair.balances.token2) ||
props.pair.allowance.token1.isZero() ||
props.pair.allowance.token2.isZero()
) {
setModalType(ModalType.ENABLE);
}
Expand Down
41 changes: 31 additions & 10 deletions src/pages/dexLP/modals/enableModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const AddSingleAllowanceButton = (props: AddSingleAllowanceProps) => {

return (
<PrimaryButton
disabled={props.tokenAllowance.gte(props.tokenBalance)}
disabled={
props.tokenAllowance.gte(props.tokenBalance) &&
!props.tokenAllowance.isZero()
}
onClick={() =>
props.addAllowance(
routerAddress,
Expand Down Expand Up @@ -81,22 +84,40 @@ const EnableModal = ({ activePair, chainId, setModal }: Props) => {

const prevModalType = useModals((state) => state.prevModalType);

function doneAllowance(
allowance: BigNumber,
balance: BigNumber,
status: TransactionState
) {
return (
(allowance.gte(balance) && !allowance.isZero()) || status == "Success"
);
}

//bring us to the next modal if we are done enabling
useEffect(() => {
if (prevModalType == ModalType.ADD) {
const doneAllowance1 =
activePair.allowance.token1.gt(activePair.balances.token1) ||
addAllowanceA.status == "Success";
const doneAllowance2 =
activePair.allowance.token2.gt(activePair.balances.token2) ||
addAllowanceB.status == "Success";
if (doneAllowance1 && doneAllowance2) {
if (
doneAllowance(
activePair.allowance.token1,
activePair.balances.token1,
addAllowanceA.status
) &&
doneAllowance(
activePair.allowance.token2,
activePair.balances.token2,
addAllowanceB.status
)
) {
setModal(ModalType.NONE);
}
} else if (
prevModalType == ModalType.REMOVE &&
(activePair.allowance.LPtoken.gt(activePair.userSupply.totalLP) ||
addLPAllowance.status == "Success")
doneAllowance(
activePair.allowance.LPtoken,
activePair.userSupply.totalLP,
addLPAllowance.status
)
) {
setModal(ModalType.NONE);
}
Expand Down

0 comments on commit e9f7c67

Please sign in to comment.