Skip to content

Commit

Permalink
chore: format files
Browse files Browse the repository at this point in the history
  • Loading branch information
ogous committed Aug 15, 2024
1 parent 79ea63f commit 1dd403c
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 188 deletions.
6 changes: 3 additions & 3 deletions web/src/app/stake/MyPositions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ export const MyPositions = () => {
const showDemoData = useFeatureFlag("ui show demo data");
const showClaimAllYield = useFeatureFlag("ui show claim all yield");

const { positions: walletData } = usePositions()
const { positions: walletData } = usePositions();

// this is every position, with their respective pools
const pools = useMemo((): Pool[] | undefined => {
if (showDemoData && address) return mockMyPositions;

return walletData.
map((position) => ({
return walletData
.map((position) => ({
positionId: position.positionId,
id: position.pool.token.address,
duration: 0,
Expand Down
46 changes: 27 additions & 19 deletions web/src/app/stake/pool/confirm-withdraw/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
} from "wagmi";
import { fUSDC } from "@/config/tokens";
import { sqrtPriceX96ToPrice } from "@/lib/math";
import { getFormattedPriceFromAmount, getUsdTokenAmountsForPosition } from "@/lib/amounts";
import {
getFormattedPriceFromAmount,
getUsdTokenAmountsForPosition,
} from "@/lib/amounts";
import Confirm from "@/components/sequence/Confirm";
import { Success } from "@/components/sequence/Success";
import { Fail } from "@/components/sequence/Fail";
Expand All @@ -38,7 +41,7 @@ export default function ConfirmWithdrawLiquidity() {
const { token0, token0Amount, token0AmountRaw, token1, token1Amount, delta } =
useStakeStore();

const { positions, updatePositionLocal } = usePositions()
const { positions, updatePositionLocal } = usePositions();

// Current liquidity of the position
const { data: positionLiquidity } = useSimulateContract({
Expand Down Expand Up @@ -136,28 +139,33 @@ export default function ConfirmWithdrawLiquidity() {

useEffect(() => {
if (updatePositionResult.isSuccess) {
const position = positions.find(p => p.positionId === Number(positionId))
const position = positions.find(
(p) => p.positionId === Number(positionId),
);
if (position) {
getUsdTokenAmountsForPosition(position, token0, Number(tokenPrice)).then(([amount0, amount1]) =>
getUsdTokenAmountsForPosition(
position,
token0,
Number(tokenPrice),
).then(([amount0, amount1]) =>
updatePositionLocal({
...position,
served: {
timestamp: Math.round(new Date().getTime() / 1000)
timestamp: Math.round(new Date().getTime() / 1000),
},
liquidity: {
fusdc: {
valueUsd: String(amount1),
},
token1: {
valueUsd: String(amount0),
}
}
})
)
},
},
}),
);
}
}
}, [updatePositionResult.isSuccess])

}, [updatePositionResult.isSuccess]);

// step 1 - collect yield from position if emptying entire balance
if (
Expand Down Expand Up @@ -239,10 +247,10 @@ export default function ConfirmWithdrawLiquidity() {
{token0.address === fUSDC.address
? token0Amount
: getFormattedPriceFromAmount(
token0Amount,
tokenPrice,
fUSDC.decimals,
)}
token0Amount,
tokenPrice,
fUSDC.decimals,
)}
</div>
</div>

Expand All @@ -257,10 +265,10 @@ export default function ConfirmWithdrawLiquidity() {
{token1.address === fUSDC.address
? token1Amount
: getFormattedPriceFromAmount(
token1Amount,
tokenPrice,
fUSDC.decimals,
)}
token1Amount,
tokenPrice,
fUSDC.decimals,
)}
</div>
</div>

Expand Down
42 changes: 20 additions & 22 deletions web/src/app/stake/pool/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import {
getFormattedPriceFromTick,
} from "@/lib/amounts";
import { getFormattedPriceFromTick } from "@/lib/amounts";
import { useStakeStore } from "@/stores/useStakeStore";
import { useSwapStore } from "@/stores/useSwapStore";
import { ammAddress } from "@/lib/addresses";
Expand Down Expand Up @@ -68,15 +66,15 @@ export default function PoolPage() {

const { data: globalData } = useGraphqlGlobal();
const allPoolsData = useFragment(ManagePoolFragment, globalData?.pools);
const { positions: positionsData_, updatePositionLocal } = usePositions()
const { positions: positionsData_, updatePositionLocal } = usePositions();
const positionsData = useMemo(
() =>
positionsData_.filter(
(p) =>
p.pool.token.address === id &&
parseFloat(p.liquidity.fusdc.valueUsd) +
parseFloat(p.liquidity.token1.valueUsd) >
0,
parseFloat(p.liquidity.token1.valueUsd) >
0,
),
[id, positionsData_],
);
Expand Down Expand Up @@ -119,12 +117,12 @@ export default function PoolPage() {
usdFormat(
positionsData
? positionsData.reduce(
(total, { liquidity: { fusdc, token1 } }) =>
total +
parseFloat(fusdc.valueUsd) +
parseFloat(token1.valueUsd),
0,
)
(total, { liquidity: { fusdc, token1 } }) =>
total +
parseFloat(fusdc.valueUsd) +
parseFloat(token1.valueUsd),
0,
)
: 0,
),
[poolData],
Expand Down Expand Up @@ -207,8 +205,8 @@ export default function PoolPage() {
);
return usdFormat(
(amount0 * Number(tokenPrice)) /
10 ** (token0.decimals + fUSDC.decimals) +
amount1 / 10 ** token1.decimals,
10 ** (token0.decimals + fUSDC.decimals) +
amount1 / 10 ** token1.decimals,
);
}, [position, positionLiquidity, tokenPrice, token0, token1, curTick]);

Expand Down Expand Up @@ -370,18 +368,18 @@ export default function PoolPage() {
<div className="text-xl md:text-2xl">
{lowerTick
? getFormattedPriceFromTick(
lowerTick,
token0.decimals,
token1.decimals,
)
lowerTick,
token0.decimals,
token1.decimals,
)
: usdFormat(0)}
-
{upperTick
? getFormattedPriceFromTick(
upperTick,
token0.decimals,
token1.decimals,
)
upperTick,
token0.decimals,
token1.decimals,
)
: usdFormat(0)}
</div>
</div>
Expand Down
93 changes: 51 additions & 42 deletions web/src/components/ConfirmStake.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@ import Confirm from "@/components/sequence/Confirm";
import { EnableSpending } from "@/components/sequence/EnableSpending";
import { Fail } from "@/components/sequence/Fail";
import { Success } from "@/components/sequence/Success";
import { getFormattedPriceFromAmount, getUsdTokenAmountsForPosition } from "@/lib/amounts";
import {
getFormattedPriceFromAmount,
getUsdTokenAmountsForPosition,
} from "@/lib/amounts";
import { fUSDC } from "@/config/tokens";
import { TokenIcon } from "./TokenIcon";
import { useFeatureFlag } from "@/hooks/useFeatureFlag";
import { usePositions } from "@/hooks/usePostions";

type ConfirmStakeProps =
| {
mode: "new";
positionId?: never;
}
mode: "new";
positionId?: never;
}
| {
mode: "existing";
positionId: number;
};
mode: "existing";
positionId: number;
};

export const ConfirmStake = ({ mode, positionId }: ConfirmStakeProps) => {
const router = useRouter();
Expand All @@ -67,7 +70,7 @@ export const ConfirmStake = ({ mode, positionId }: ConfirmStakeProps) => {
multiSingleToken,
} = useStakeStore();

const { positions, updatePositionLocal } = usePositions()
const { positions, updatePositionLocal } = usePositions();

// Price of the current pool
const { data: poolSqrtPriceX96 } = useSimulateContract({
Expand Down Expand Up @@ -169,12 +172,12 @@ export const ConfirmStake = ({ mode, positionId }: ConfirmStakeProps) => {
!curTick || tickLower === undefined || tickUpper === undefined
? 0n
: getLiquidityForAmounts(
curTick.result,
BigInt(tickLower),
BigInt(tickUpper),
BigInt(token0AmountRaw),
BigInt(token1AmountRaw),
),
curTick.result,
BigInt(tickLower),
BigInt(tickUpper),
BigInt(token0AmountRaw),
BigInt(token1AmountRaw),
),
[curTick, tickLower, tickUpper, token0AmountRaw, token1AmountRaw],
);

Expand Down Expand Up @@ -312,36 +315,39 @@ export const ConfirmStake = ({ mode, positionId }: ConfirmStakeProps) => {
});
useEffect(() => {
if (updatePositionResult.isSuccess) {
const id = positionId ?? Number(mintPositionId)
const id = positionId ?? Number(mintPositionId);
if (id && tickLower && tickUpper) {
const position = positions.find(p => p.positionId === id) ?? {
const position = positions.find((p) => p.positionId === id) ?? {
positionId: id,
pool: {
token: token0,
},
lower: tickLower,
upper: tickUpper,
}
getUsdTokenAmountsForPosition(position, token0, Number(tokenPrice)).then(([amount0, amount1]) =>
};
getUsdTokenAmountsForPosition(
position,
token0,
Number(tokenPrice),
).then(([amount0, amount1]) =>
updatePositionLocal({
...position,
served: {
timestamp: Math.round(new Date().getTime() / 1000)
timestamp: Math.round(new Date().getTime() / 1000),
},
liquidity: {
fusdc: {
valueUsd: String(amount1),
},
token1: {
valueUsd: String(amount0),
}
}
})
)
},
},
}),
);
}

}
}, [updatePositionResult.isSuccess])
}, [updatePositionResult.isSuccess]);

// step 1 pending
if (isMintPending || (mintData && result?.isPending)) {
Expand Down Expand Up @@ -386,27 +392,30 @@ export const ConfirmStake = ({ mode, positionId }: ConfirmStakeProps) => {
isUpdatePositionPending ||
(updatePositionData && updatePositionResult?.isPending)
) {
return <Confirm
text={"Stake"}
fromAsset={{ symbol: token0.symbol, amount: token0Amount ?? "0" }}
toAsset={{ symbol: token1.symbol, amount: token1Amount ?? "0" }}
transactionHash={updatePositionData}
/>;
return (
<Confirm
text={"Stake"}
fromAsset={{ symbol: token0.symbol, amount: token0Amount ?? "0" }}
toAsset={{ symbol: token1.symbol, amount: token1Amount ?? "0" }}
transactionHash={updatePositionData}
/>
);
}


// success
if (updatePositionResult.data) {
return <Success
transactionHash={updatePositionResult.data.transactionHash}
onDone={() => {
resetUpdatePosition()
resetApproveToken0()
resetApproveToken1()
updatePositionResult.refetch()
router.push("/stake")
}}
/>;
return (
<Success
transactionHash={updatePositionResult.data.transactionHash}
onDone={() => {
resetUpdatePosition();
resetApproveToken0();
resetApproveToken1();
updatePositionResult.refetch();
router.push("/stake");
}}
/>
);
}

// error
Expand Down
Loading

0 comments on commit 1dd403c

Please sign in to comment.