Skip to content

Commit

Permalink
Add operator closures to every ActionCard
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Oct 25, 2022
1 parent 2812bc9 commit c4157dc
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 8 deletions.
10 changes: 9 additions & 1 deletion prime/src/components/borrow/actions/AloeAddMarginActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Dropdown, DropdownOption } from 'shared/lib/components/common/Dropdown'

import { getTransferInActionArgs } from '../../../data/actions/ActionArgs';
import { ActionID } from '../../../data/actions/ActionID';
import { transferInOperator } from '../../../data/actions/ActionOperators';
import {
ActionCardProps,
ActionProviders,
Expand Down Expand Up @@ -67,6 +68,10 @@ export function AloeAddMarginActionCard(prop: ActionCardProps) {
selectedToken: selectedToken,
},
uniswapResult: null,
operator(operand) {
if (!operand || selectedToken == null) return null;
return transferInOperator(operand, selectedToken, parsedValue);
},
});
};

Expand Down Expand Up @@ -95,12 +100,15 @@ export function AloeAddMarginActionCard(prop: ActionCardProps) {
<Dropdown
options={dropdownOptions}
selectedOption={selectedTokenOption}
onSelect={(option) => {
onSelect={(option: DropdownOption) => {
if (option.value !== selectedTokenOption.value) {
onChange({
actionId: ActionID.TRANSFER_IN,
aloeResult: { selectedToken: parseSelectedToken(option.value) },
uniswapResult: null,
operator(operand) {
return null;
},
});
}
}}
Expand Down
10 changes: 9 additions & 1 deletion prime/src/components/borrow/actions/AloeBorrowActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Dropdown, DropdownOption } from 'shared/lib/components/common/Dropdown'

import { getBorrowActionArgs } from '../../../data/actions/ActionArgs';
import { ActionID } from '../../../data/actions/ActionID';
import { borrowOperator } from '../../../data/actions/ActionOperators';
import {
ActionCardProps,
ActionProviders,
Expand Down Expand Up @@ -56,6 +57,10 @@ export function AloeBorrowActionCard(prop: ActionCardProps) {
selectedToken: selectedToken,
},
uniswapResult: null,
operator(operand) {
if (!operand || selectedToken == null) return null;
return borrowOperator(operand, selectedToken, Math.max(amount0, amount1));
},
});
};

Expand All @@ -75,12 +80,15 @@ export function AloeBorrowActionCard(prop: ActionCardProps) {
<Dropdown
options={dropdownOptions}
selectedOption={selectedTokenOption}
onSelect={(option) => {
onSelect={(option: DropdownOption) => {
if (option.value !== selectedTokenOption.value) {
onChange({
actionId: ActionID.BORROW,
aloeResult: { selectedToken: parseSelectedToken(option.value) },
uniswapResult: null,
operator(operand) {
return null;
},
});
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Dropdown, DropdownOption } from 'shared/lib/components/common/Dropdown'

import { getBurnActionArgs } from '../../../data/actions/ActionArgs';
import { ActionID } from '../../../data/actions/ActionID';
import { burnOperator } from '../../../data/actions/ActionOperators';
import {
ActionCardProps,
ActionProviders,
Expand Down Expand Up @@ -56,6 +57,10 @@ export function AloeBurnTokenPlusActionCard(prop: ActionCardProps) {
selectedToken: selectedToken,
},
uniswapResult: null,
operator(operand) {
if (!operand || selectedToken == null) return null;
return burnOperator(operand, selectedToken, parsedValue);
},
});
};

Expand All @@ -77,12 +82,15 @@ export function AloeBurnTokenPlusActionCard(prop: ActionCardProps) {
<Dropdown
options={dropdownOptions}
selectedOption={selectedTokenOption}
onSelect={(option) => {
onSelect={(option: DropdownOption) => {
if (option.value !== selectedTokenOption.value) {
onChange({
actionId: ActionID.BURN,
aloeResult: { selectedToken: parseSelectedToken(option.value) },
uniswapResult: null,
operator(operand) {
return null;
},
});
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Dropdown, DropdownOption } from 'shared/lib/components/common/Dropdown'

import { getMintActionArgs } from '../../../data/actions/ActionArgs';
import { ActionID } from '../../../data/actions/ActionID';
import { mintOperator } from '../../../data/actions/ActionOperators';
import {
ActionCardProps,
ActionProviders,
Expand Down Expand Up @@ -55,6 +56,10 @@ export function AloeMintTokenPlusActionCard(prop: ActionCardProps) {
selectedToken: selectedToken,
},
uniswapResult: null,
operator(operand) {
if (!operand || selectedToken == null) return null;
return mintOperator(operand, selectedToken, parsedValue);
},
});
};

Expand All @@ -76,12 +81,15 @@ export function AloeMintTokenPlusActionCard(prop: ActionCardProps) {
<Dropdown
options={dropdownOptions}
selectedOption={selectedTokenOption}
onSelect={(option) => {
onSelect={(option: DropdownOption) => {
if (option.value !== selectedTokenOption.value) {
onChange({
actionId: ActionID.MINT,
aloeResult: { selectedToken: parseSelectedToken(option.value) },
uniswapResult: null,
operator(operand) {
return null;
},
});
}
}}
Expand Down
10 changes: 9 additions & 1 deletion prime/src/components/borrow/actions/AloeRepayActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Dropdown, DropdownOption } from 'shared/lib/components/common/Dropdown'

import { getRepayActionArgs } from '../../../data/actions/ActionArgs';
import { ActionID } from '../../../data/actions/ActionID';
import { repayOperator } from '../../../data/actions/ActionOperators';
import {
ActionCardProps,
ActionProviders,
Expand Down Expand Up @@ -56,6 +57,10 @@ export function AloeRepayActionCard(prop: ActionCardProps) {
selectedToken: selectedToken,
},
uniswapResult: null,
operator(operand) {
if (!operand || selectedToken == null) return null;
return repayOperator(operand, selectedToken, Math.max(amount0, amount1));
},
});
};

Expand All @@ -78,12 +83,15 @@ export function AloeRepayActionCard(prop: ActionCardProps) {
<Dropdown
options={dropdownOptions}
selectedOption={selectedTokenOption}
onSelect={(option) => {
onSelect={(option: DropdownOption) => {
if (option.value !== selectedTokenOption.value) {
onChange({
actionId: ActionID.REPAY,
aloeResult: { selectedToken: parseSelectedToken(option.value) },
uniswapResult: null,
operator(operand) {
return null;
},
});
}
}}
Expand Down
10 changes: 9 additions & 1 deletion prime/src/components/borrow/actions/AloeWithdrawActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Dropdown, DropdownOption } from 'shared/lib/components/common/Dropdown'

import { getTransferOutActionArgs } from '../../../data/actions/ActionArgs';
import { ActionID } from '../../../data/actions/ActionID';
import { transferOutOperator } from '../../../data/actions/ActionOperators';
import {
ActionCardProps,
ActionProviders,
Expand Down Expand Up @@ -66,6 +67,10 @@ export function AloeWithdrawActionCard(prop: ActionCardProps) {
selectedToken: selectedToken,
},
uniswapResult: null,
operator(operand) {
if (!operand || selectedToken == null) return null;
return transferOutOperator(operand, selectedToken, parsedValue);
},
});
};

Expand All @@ -85,12 +90,15 @@ export function AloeWithdrawActionCard(prop: ActionCardProps) {
<Dropdown
options={dropdownOptions}
selectedOption={selectedTokenOption}
onSelect={(option) => {
onSelect={(option: DropdownOption) => {
if (option.value !== selectedTokenOption.value) {
onChange({
actionId: ActionID.TRANSFER_OUT,
aloeResult: { selectedToken: parseSelectedToken(option.value) },
uniswapResult: null,
operator(operand) {
return null;
},
});
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { useEffect, useState } from 'react';

import { TickMath } from '@uniswap/v3-sdk';
import JSBI from 'jsbi';
import { useProvider } from 'wagmi';
import { Address, useProvider } from 'wagmi';

import { getAddLiquidityActionArgs } from '../../../data/actions/ActionArgs';
import { ActionID } from '../../../data/actions/ActionID';
import { addLiquidityOperator } from '../../../data/actions/ActionOperators';
import { ActionCardProps, ActionProviders } from '../../../data/actions/Actions';
import useEffectOnce from '../../../data/hooks/UseEffectOnce';
import { roundDownToNearestN, roundUpToNearestN } from '../../../util/Numbers';
Expand Down Expand Up @@ -257,6 +258,19 @@ export default function UniswapAddLiquidityActionCard(props: ActionCardProps) {
isAmount0LastUpdated: localIsAmount0UserDefined,
isToken0Selected: isToken0Selected,
},
operator(operand) {
if (!operand || lowerTick == null || upperTick == null || currentTick == null) return null;
return addLiquidityOperator(
operand,
marginAccount.address as Address,
liquidity,
lowerTick,
upperTick,
currentTick,
token0.decimals,
token1.decimals
);
},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import JSBI from 'jsbi';
import { DropdownOption, DropdownWithPlaceholder } from 'shared/lib/components/common/Dropdown';
import { Text } from 'shared/lib/components/common/Typography';
import styled from 'styled-components';
import { Address } from 'wagmi';

import { ReactComponent as InboxIcon } from '../../../assets/svg/inbox.svg';
import { getRemoveLiquidityActionArgs } from '../../../data/actions/ActionArgs';
import { ActionID } from '../../../data/actions/ActionID';
import { removeLiquidityOperator } from '../../../data/actions/ActionOperators';
import { ActionCardProps, ActionProviders, UniswapPosition } from '../../../data/actions/Actions';
import { sqrtRatioToTick } from '../../../util/Uniswap';
import { BaseActionCard } from '../BaseActionCard';

//TOOD: merge this with the existing UniswapPosition?
Expand All @@ -29,7 +32,8 @@ const SVGIconWrapper = styled.div.attrs((props: { width: number; height: number
`;

export default function UnsiwapClaimFeesActionCard(props: ActionCardProps) {
const { uniswapPositions, previousActionCardState, isCausingError, onChange, onRemove } = props;
const { marginAccount, uniswapPositions, previousActionCardState, isCausingError, onChange, onRemove } = props;
const { token0, token1 } = marginAccount;

const dropdownOptions = uniswapPositions.map((lp, index) => {
return {
Expand Down Expand Up @@ -72,6 +76,19 @@ export default function UnsiwapClaimFeesActionCard(props: ActionCardProps) {
isAmount0LastUpdated: undefined,
isToken0Selected: undefined,
},
operator(operand) {
if (!operand || lower == null || upper == null) return null;
return removeLiquidityOperator(
operand,
marginAccount.address as Address,
updatedLiquidity,
lower,
upper,
sqrtRatioToTick(marginAccount.sqrtPriceX96),
token0.decimals,
token1.decimals
);
},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { DropdownOption, DropdownWithPlaceholder } from 'shared/lib/components/c
import { SquareInputWithTrailingUnit } from 'shared/lib/components/common/Input';
import { Text } from 'shared/lib/components/common/Typography';
import styled from 'styled-components';
import { Address } from 'wagmi';

import { ReactComponent as InboxIcon } from '../../../assets/svg/inbox.svg';
import { ReactComponent as RightArrowIcon } from '../../../assets/svg/small_right_arrow.svg';
import { getRemoveLiquidityActionArgs } from '../../../data/actions/ActionArgs';
import { ActionID } from '../../../data/actions/ActionID';
import { removeLiquidityOperator } from '../../../data/actions/ActionOperators';
import { ActionCardProps, ActionProviders, UniswapPosition } from '../../../data/actions/Actions';
import useEffectOnce from '../../../data/hooks/UseEffectOnce';
import { formatNumberInput, formatTokenAmount } from '../../../util/Numbers';
Expand Down Expand Up @@ -137,6 +139,19 @@ export default function UniswapRemoveLiquidityActionCard(props: ActionCardProps)
isAmount0LastUpdated: undefined,
isToken0Selected: undefined,
},
operator(operand) {
if (!operand || lower == null || upper == null) return null;
return removeLiquidityOperator(
operand,
marginAccount.address as Address,
liquidityToRemove,
lower,
upper,
sqrtRatioToTick(marginAccount.sqrtPriceX96),
token0.decimals,
token1.decimals
);
},
});
}

Expand Down
Loading

0 comments on commit c4157dc

Please # to comment.