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(synapse-interface): post transaction balances #2079

Merged
merged 55 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
697af40
Track when transaction receipt error occurs
bigboydiamonds Feb 14, 2024
a445716
isTransactionReceiptError util, fetch origin balances if error is tra…
bigboydiamonds Feb 14, 2024
11c086d
Bump timeout to 60s
bigboydiamonds Feb 14, 2024
a246e11
Create more robust error handling for checking if transaction receipt…
bigboydiamonds Feb 14, 2024
c2e1d3d
Clean, revert back to 60s timeout
bigboydiamonds Feb 14, 2024
cc14af2
Log when isTransactionReceiptError
bigboydiamonds Feb 14, 2024
c5132f8
RM log, ready for merge
bigboydiamonds Feb 21, 2024
78d5279
Refetch pool data after withdraw tx
bigboydiamonds Mar 1, 2024
f11b74d
Update pool balances after Deposit
bigboydiamonds Mar 1, 2024
211de20
Add isFetching prop to PoolDataState to track initial load, separate …
bigboydiamonds Mar 1, 2024
0503608
Add stakedBalance to poolUserData slice
bigboydiamonds Mar 1, 2024
61d414c
Refetch pool token balances after withdraw
bigboydiamonds Mar 1, 2024
5694476
Post deposit + withdraw updates all pool data including user
bigboydiamonds Mar 1, 2024
dd9d2a2
onSuccessWithdraw()
bigboydiamonds Mar 1, 2024
e2f3e30
onSuccessDeposit()
bigboydiamonds Mar 1, 2024
7b24378
Trim lp balance in Stake pool
bigboydiamonds Mar 1, 2024
b8bf576
Set initial stakedBalance amount/reward to bigint
bigboydiamonds Mar 1, 2024
f2f6917
Update User pool token staked balance on individual pool body
bigboydiamonds Mar 1, 2024
db739c7
Refactor; use poolUserData slice to display staked balance in individ…
bigboydiamonds Mar 1, 2024
03b1980
Update Pool LP balances after stake/unstake so pools page shows accur…
bigboydiamonds Mar 1, 2024
46f78be
Clean
bigboydiamonds Mar 1, 2024
133c890
Clean
bigboydiamonds Mar 1, 2024
e587148
Remove isFetching, use isLoading for fetched pool attributes instead
bigboydiamonds Mar 1, 2024
af0ed0e
Add pools convenience store hooks
bigboydiamonds Mar 1, 2024
ffa7dbc
Use pools state hooks to replace useSelector instances
bigboydiamonds Mar 1, 2024
167f5f7
Remove unused imports
bigboydiamonds Mar 1, 2024
744c086
Clean + organize imports
bigboydiamonds Mar 1, 2024
0a3a83d
Update User LP staked balances when navigating to new pool
bigboydiamonds Mar 1, 2024
7608194
Use isLoading to display loading dots on pool data
bigboydiamonds Mar 1, 2024
f77f4df
isTransactionUserRejectedError
bigboydiamonds Mar 1, 2024
8a6cdcc
Throw error if transaction is rejected by User, ensure depositTxn() f…
bigboydiamonds Mar 1, 2024
e2c0c05
Apply User rejected flow in withdrawTxn()
bigboydiamonds Mar 1, 2024
daffaa6
Update isTransactionReceiptError to also check for TransactionNotFoun…
bigboydiamonds Mar 2, 2024
722cece
Clean
bigboydiamonds Mar 2, 2024
2922dd5
Merge branch 'master' into fe/post-transaction-balance
bigboydiamonds Mar 2, 2024
1cbcf47
Merge branch 'fe/post-transaction-balance' into fe/pool-transaction-b…
bigboydiamonds Mar 2, 2024
b177047
Merge pull request #2180 from synapsecns/fe/pool-transaction-balance
bigboydiamonds Mar 2, 2024
f4e6b83
Update balances on Swap after transacion receipt returned
bigboydiamonds Mar 2, 2024
3c7607e
onSuccessSwap
bigboydiamonds Mar 2, 2024
d4a3059
Clear swap input after successful swap executed
bigboydiamonds Mar 2, 2024
a7aa01c
Merge pull request #2194 from synapsecns/fe/swap-transaction-balance
bigboydiamonds Mar 2, 2024
704c2f0
Rename withdraw/deposit reset function
bigboydiamonds Mar 4, 2024
5e6727f
getUserStakedBalance()
bigboydiamonds Mar 4, 2024
35484cf
Update claim flow to refetch staked balance after tx executes
bigboydiamonds Mar 4, 2024
6617eba
resetUserStakeData()
bigboydiamonds Mar 4, 2024
b7c84c6
Refactor; getUserLpTokenAllowance, clean up useEffects with refactore…
bigboydiamonds Mar 4, 2024
02c2223
Remove unused tx state
bigboydiamonds Mar 4, 2024
ccf06a6
Merge pull request #2208 from synapsecns/fe/claim-transaction-balance
bigboydiamonds Mar 4, 2024
b6b334f
Clarify function that catches error in Stake
bigboydiamonds Mar 4, 2024
4adf4b1
Clean imports on StakeCard
bigboydiamonds Mar 4, 2024
0484f20
Refetch allowances after allowance tx executes
bigboydiamonds Mar 4, 2024
ab98920
Improve error handling
bigboydiamonds Mar 5, 2024
f506554
Remove unnecessary prop for LoadingDots
bigboydiamonds Mar 6, 2024
8f7f5dd
Merge branch 'master' into fe/post-transaction-balance
bigboydiamonds Mar 7, 2024
120b836
Merge branch 'master' into fe/post-transaction-balance
abtestingalpha Mar 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { SwapChainSelector } from './SwapChainSelector'
import { SwapFromTokenSelector } from './SwapFromTokenSelector'
import { usePortfolioState } from '@/slices/portfolio/hooks'
import { updateSwapFromValue } from '@/slices/swap/reducer'
import { initialState, updateSwapFromValue } from '@/slices/swap/reducer'
import { useSwapState } from '@/slices/swap/hooks'

export const SwapInputContainer = () => {
Expand Down Expand Up @@ -51,6 +51,10 @@ export const SwapInputContainer = () => {
) {
setShowValue(swapFromValue)
}

if (swapFromValue === initialState.swapFromValue) {
setShowValue(initialState.swapFromValue)
}
}, [swapFromValue, swapChainId, swapFromToken])

const handleFromValueChange = (
Expand Down
4 changes: 2 additions & 2 deletions packages/synapse-interface/pages/pool/NoPoolBody.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Card from '@tw/Card'
import Grid from '@tw/Grid'
import { getNetworkTextColor } from '@styles/chains'
import { CHAINS_BY_ID } from '@constants/chains'
import { Token } from '@types'
import { CHAINS_BY_ID } from '@constants/chains'
import { getNetworkTextColor } from '@styles/chains'

const NoPoolBody = ({
pool,
Expand Down
50 changes: 13 additions & 37 deletions packages/synapse-interface/pages/pool/PoolBody.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import numeral from 'numeral'
import Link from 'next/link'
import { Address } from '@wagmi/core'
import { useEffect, useState } from 'react'
import { useAccount, useSwitchNetwork } from 'wagmi'
import { ChevronLeftIcon } from '@heroicons/react/outline'
import { POOLS_PATH } from '@urls'
import Card from '@tw/Card'
import Grid from '@tw/Grid'
import PoolInfoSection from './PoolInfoSection'
import PoolManagement from './poolManagement'
import { zeroAddress } from 'viem'
import { useSelector } from 'react-redux'
import { RootState } from '@/store/store'
import { Address } from '@wagmi/core'
import { useAccount, useSwitchNetwork } from 'wagmi'
import { PoolActionOptions } from '@/components/Pools/PoolActionOptions'
import { TransactionButton } from '@/components/buttons/TransactionButton'
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { segmentAnalyticsEvent } from '@/contexts/SegmentAnalyticsProvider'
import { useEffect, useState } from 'react'
import { PoolActionOptions } from '@/components/Pools/PoolActionOptions'
import PoolTitle from './components/PoolTitle'
import { DisplayBalances } from '../pools/PoolCard'
import { getStakedBalance } from '@/utils/actions/getStakedBalance'
import { usePoolDataState, usePoolUserDataState } from '@/slices/pools/hooks'
import { POOLS_PATH } from '@urls'
import PoolTitle from './components/PoolTitle'
import PoolInfoSection from './PoolInfoSection'
import PoolManagement from './poolManagement'

const PoolBody = ({
address,
Expand All @@ -30,16 +28,10 @@ const PoolBody = ({
const [isClient, setIsClient] = useState(false)
const { chains, switchNetwork } = useSwitchNetwork()
const { openConnectModal } = useConnectModal()

const { isConnected } = useAccount()

const { pool, poolAPYData } = useSelector(
(state: RootState) => state.poolData
)
const [stakedBalance, setStakedBalance] = useState({
amount: 0n,
reward: 0n,
})
const { poolUserData } = usePoolUserDataState()
const { pool, poolAPYData } = usePoolDataState()

useEffect(() => {
setIsClient(true)
Expand All @@ -51,29 +43,13 @@ const PoolBody = ({
poolName: pool?.poolName,
})
}
if (address && isClient) {
getStakedBalance(
address as Address,
pool.chainId,
pool.poolId[pool.chainId],
pool
)
.then((res) => {
setStakedBalance(res)
})
.catch((err) => {
console.log('Could not get staked balances: ', err)
})
} else {
setStakedBalance({ amount: 0n, reward: 0n })
}
}, [isClient, address, pool])

if (!pool) return null

return (
<>
<div className="">
<div id="pool-body">
<Link href={POOLS_PATH}>
<div className="inline-flex items-center mb-3 text-sm font-light text-white hover:text-opacity-100">
<ChevronLeftIcon className="w-4 h-4" />
Expand All @@ -87,7 +63,7 @@ const PoolBody = ({
<DisplayBalances
pool={pool}
address={address}
stakedBalance={stakedBalance}
stakedBalance={poolUserData?.stakedBalance}
showIcon={false}
/>
</div>
Expand Down
21 changes: 10 additions & 11 deletions packages/synapse-interface/pages/pool/PoolInfoSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
formatBigIntToPercentString,
formatBigIntToString,
} from '@/utils/bigint/format'
import { useSelector } from 'react-redux'
import { RootState } from '@/store/store'
import { usePoolDataState } from '@/slices/pools/hooks'

const PoolInfoSection = () => {
const { pool, poolData } = useSelector((state: RootState) => state.poolData)
const { pool, poolData, isLoading } = usePoolDataState()

const usdFormat = poolData.totalLockedUSD > 1000000 ? '$0,0.0' : '$0,0'

Expand All @@ -22,49 +21,49 @@ const PoolInfoSection = () => {
<InfoListItem
labelText="Trading Fee"
content={
poolData && poolData.swapFee ? (
poolData && poolData.swapFee && !isLoading ? (
formatBigIntToPercentString(poolData.swapFee, 8, 2, false)
) : (
<LoadingDots />
<LoadingDots className="mr-4" />
)
}
/>
<InfoListItem
labelText="Virtual Price"
content={
poolData && poolData?.virtualPrice ? (
poolData && poolData?.virtualPrice && !isLoading ? (
<AugmentWithUnits
content={formatBigIntToString(poolData.virtualPrice, 18, 5)}
label={pool.priceUnits}
/>
) : (
<LoadingDots />
<LoadingDots className="mr-4" />
)
}
/>
<InfoListItem
labelText="Total Liquidity"
content={
poolData && poolData?.totalLocked ? (
poolData && poolData?.totalLocked && !isLoading ? (
<AugmentWithUnits
content={numeral(poolData.totalLocked).format('0,0')}
label={pool.priceUnits}
/>
) : (
<LoadingDots />
<LoadingDots className="mr-4" />
)
}
/>
<InfoListItem
labelText="Total Liquidity USD"
content={
poolData && poolData?.totalLockedUSD ? (
poolData && poolData?.totalLockedUSD && !isLoading ? (
<AugmentWithUnits
content={numeral(poolData.totalLockedUSD).format(usdFormat)}
label="USD"
/>
) : (
<LoadingDots />
<LoadingDots className="mr-4" />
)
}
/>
Expand Down
36 changes: 23 additions & 13 deletions packages/synapse-interface/pages/pool/[poolId].tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import _ from 'lodash'
import { useEffect, useState } from 'react'
import { useAccount, useNetwork } from 'wagmi'
import { useDispatch, useSelector } from 'react-redux'
import { useRouter } from 'next/router'
import StandardPageContainer from '@layouts/StandardPageContainer'
import { LandingPageWrapper } from '@layouts/LandingPageWrapper'
import { DEFAULT_FROM_CHAIN } from '@/constants/swap'
import PoolBody from './PoolBody'
import NoPoolBody from './NoPoolBody'
import { useAccount, useNetwork } from 'wagmi'
import { useAppDispatch } from '@/store/hooks'
import { fetchPoolData, resetPoolData } from '@/slices/poolDataSlice'
import { RootState } from '@/store/store'
import { resetPoolDeposit } from '@/slices/poolDepositSlice'
import { resetPoolWithdraw } from '@/slices/poolWithdrawSlice'
import LoadingDots from '@/components/ui/tailwind/LoadingDots'
import {
fetchPoolUserData,
resetPoolUserData,
} from '@/slices/poolUserDataSlice'
import { usePoolDataState } from '@/slices/pools/hooks'
import { DEFAULT_FROM_CHAIN } from '@/constants/swap'
import { LandingPageWrapper } from '@layouts/LandingPageWrapper'
import { POOL_BY_ROUTER_INDEX } from '@constants/tokens'
import PoolBody from './PoolBody'
import NoPoolBody from './NoPoolBody'
import LoadingDots from '@/components/ui/tailwind/LoadingDots'
import StandardPageContainer from '@layouts/StandardPageContainer'

export const getStaticPaths = async () => {
const paths = Object.keys(POOL_BY_ROUTER_INDEX).map((key) => ({
Expand All @@ -31,16 +35,15 @@ export const getStaticProps = async (context) => {
}

const PoolPage = () => {
const dispatch = useAppDispatch()
const router = useRouter()
const { poolId } = router.query
const { address } = useAccount()
const { chain } = useNetwork()
const [connectedChainId, setConnectedChainId] = useState(0)
const [isClient, setIsClient] = useState(false)

const { pool, isLoading } = useSelector((state: RootState) => state.poolData)

const dispatch: any = useDispatch()
const { pool } = usePoolDataState()

useEffect(() => {
setIsClient(true)
Expand All @@ -51,6 +54,7 @@ const PoolPage = () => {
dispatch(resetPoolData())
dispatch(resetPoolDeposit())
dispatch(resetPoolWithdraw())
dispatch(resetPoolUserData())
}

router.events.on('routeChangeStart', handleRouteChange)
Expand All @@ -71,13 +75,19 @@ const PoolPage = () => {
}
}, [poolId, address, isClient])

useEffect(() => {
if (pool && address) {
dispatch(fetchPoolUserData({ pool, address }))
}
}, [pool])

return (
<LandingPageWrapper>
<StandardPageContainer
connectedChainId={connectedChainId}
address={address}
>
{!pool || isLoading || !poolId ? (
{!pool || !poolId ? (
<div className="flex items-center justify-center">
<LoadingDots />
</div>
Expand Down
Loading
Loading