Skip to content

Commit

Permalink
Merge pull request #10934 from AugurProject/fix-approval-hook
Browse files Browse the repository at this point in the history
fix-approval-hook
  • Loading branch information
mergify[bot] authored Mar 29, 2021
2 parents 9532a6c + 2491ab5 commit d17f9c5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
48 changes: 30 additions & 18 deletions packages/augur-comps/src/stores/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,33 @@ export function useApprovalStatus({
actionType: ApprovalAction;
}) {
const {
account,
loginAccount,
transactions,
} = useUserStore();
const [isApproved, setIsApproved] = useState(UNKNOWN);
const forceCheck = useRef(false);
const {
addresses: { WethWrapperForAMMExchange, AMMFactory },
} = PARA_CONFIG;
const marketCashType = cash?.name;
const tokenAddress = cash?.address;
const { shareToken } = cash;
const {
name: marketCashType,
address: tokenAddress,
shareToken,
} = cash;
const invalidPoolId = amm?.invalidPool?.id;
const ammId = amm?.id;
const isETH = marketCashType === ETH;

useEffect(() => {
let isMounted = true;
// if we switch make sure to check if we are approved.
if (isApproved === APPROVED && isMounted) forceCheck.current = true;
return () => {
isMounted = false;
};
}, [marketCashType, tokenAddress, shareToken, ammId, invalidPoolId, actionType, account]);

useEffect(() => {
let isMounted = true;
const checkIfApproved = async () => {
Expand All @@ -275,16 +290,16 @@ export function useApprovalStatus({
break;
}
case REMOVE_LIQUIDITY: {
address = amm?.invalidPool?.id;
address = invalidPoolId;
break;
}
case TRANSFER_LIQUIDITY: {
address = amm?.id;
address = ammId;
break;
}
case ENTER_POSITION:
case ADD_LIQUIDITY: {
address = isETH ? null : cash?.address;
address = isETH ? null : tokenAddress;
checkApprovalFunction = isETH ? async () => APPROVED : checkAllowance;
break;
}
Expand All @@ -299,30 +314,27 @@ export function useApprovalStatus({
loginAccount,
transactions
);

approvalCheck !== UNKNOWN && isMounted && setIsApproved(approvalCheck);

(forceCheck.current || approvalCheck !== isApproved) && isMounted && setIsApproved(approvalCheck);
if (forceCheck.current) forceCheck.current = false;
};

if (isApproved !== APPROVED && loginAccount?.account) {
if ((forceCheck.current || isApproved !== APPROVED) && account) {
checkIfApproved();
}
return () => {
isMounted = false;
};
}, [
loginAccount,
account,
isApproved,
actionType,
amm,
invalidPoolId,
ammId,
PARA_CONFIG,
tokenAddress,
transactions,
AMMFactory,
WethWrapperForAMMExchange,
cash?.address,
isETH,
marketCashType,
shareToken,
tokenAddress,
shareToken
]);

return isApproved;
Expand Down
4 changes: 2 additions & 2 deletions packages/augur-simplified/src/modules/common/labels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import {
LabelComps,
} from '@augurproject/augur-comps';
const { CREATE, USDC, ETH, MODAL_ADD_LIQUIDITY, MARKET, ADD } = Constants;
const { ValueLabel, IconLabel } = LabelComps;
const { ValueLabel } = LabelComps;
const {
PathUtils: { parsePath },
Formatter: { formatCash },
} = Utils;
const { USDCIcon, EthIcon, PlusIcon, UsdIcon } = Icons;
const { USDCIcon, EthIcon, PlusIcon } = Icons;

const handleValue = (value, cashName = USDC) =>
formatCash(value, cashName, {
Expand Down

0 comments on commit d17f9c5

Please sign in to comment.