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

feat: add staked position parts to be visible in Pool position table #446

Merged
merged 2 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 22 additions & 8 deletions src/pages/Pool/MyPositionTableCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { EditedPosition } from '../MyLiquidity/useEditLiquidity';
import { guessInvertedOrder } from '../../lib/web3/utils/pairs';
import { useSimplePrice } from '../../lib/tokenPrices';
import { matchTokens } from '../../lib/web3/hooks/useTokens';
import { useStake } from '../MyLiquidity/useStaking';

import TableCard from '../../components/cards/TableCard';
import ValueBar from '../../components/Table/ValueBar';
Expand Down Expand Up @@ -320,12 +321,19 @@ export function MyEditedPositionTableCard({
);
}, [poolValues]);

const [, sendStakeRequest] = useStake();

const data = editedUserPosition
? sortedPosition.map(
(
{ tickDiff0, tickDiff1, deposit, token0Context, token1Context },
index
) => {
? sortedPosition.map((userPosition, index) => {
if (userPosition) {
const {
tickDiff0,
tickDiff1,
deposit,
token0Context,
token1Context,
stakeContext,
} = userPosition;
const reserveA = !invertedTokenOrder
? tickDiff0.plus(token0Context?.userReserves || 0)
: tickDiff1.plus(token1Context?.userReserves || 0);
Expand Down Expand Up @@ -404,8 +412,13 @@ export function MyEditedPositionTableCard({
(reserveA.isZero() || reserveB.isZero()) && (
<button
type="button"
className="button button-light ml-auto"
className={`button ${
stakeContext ? 'button-primary-outline' : 'button-light'
} ml-auto`}
onClick={() => {
if (stakeContext) {
return sendStakeRequest([], [userPosition]);
}
setEditedUserPosition((ticks) => {
return ticks.map((tick) => {
return tick.deposit.centerTickIndex1To0.toNumber() ===
Expand All @@ -426,7 +439,7 @@ export function MyEditedPositionTableCard({
});
}}
>
Withdraw
{stakeContext ? <>Unstake</> : <>Withdraw</>}
</button>
)}
{(!tickDiff0.isZero() || !tickDiff1.isZero()) && (
Expand Down Expand Up @@ -457,7 +470,8 @@ export function MyEditedPositionTableCard({
</tr>
) : null;
}
)
return null;
})
: null;

return (
Expand Down
9 changes: 8 additions & 1 deletion src/pages/Pool/PoolManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,14 @@ export default function PoolManagement({
const pairPoolDepositFilter = usePoolDepositFilterForPair(
tokenA && tokenB ? [tokenA, tokenB] : ['', '']
);
const userPositionsContext = useUserPositionsContext(pairPoolDepositFilter);
const userUnstakedContext = useUserPositionsContext(pairPoolDepositFilter);
const userStakedContext = useUserPositionsContext(
pairPoolDepositFilter,
true
);
const userPositionsContext = useMemo(() => {
return [...userUnstakedContext, ...userStakedContext];
}, [userStakedContext, userUnstakedContext]);

const [{ isValidating: isValidatingEdit }, sendEditRequest] =
useEditLiquidity();
Expand Down