Skip to content

Commit

Permalink
fix(app): reset staking data at disconnect (#2701)
Browse files Browse the repository at this point in the history
* Reset the staking data when switching the wallet

* Fixed the error when wallet disconnecting

* Fix the escrow data reset

* Cleaned the code and dropped the unnecessary file

* Remove the staking v2 reverse migration banner

* Reset the estimated rewards and claimable rewards when swtiching the wallet

* Updated the claimable rewards after switching the wallet, no need to access to staking page

* Fixed the naming
  • Loading branch information
LeifuChen authored Jul 31, 2023
1 parent 6ace686 commit b48959f
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 439 deletions.
2 changes: 1 addition & 1 deletion packages/app/src/constants/announcement.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MILLISECONDS_PER_DAY } from '@kwenta/sdk/constants'

// Shows or hides the home page banner entirely when set to true/false
export const BANNER_ENABLED = true
export const BANNER_ENABLED = false
// Sets the link destination for the banner component, or renders the banner as
// plain, un-clickable text if set to a falsey value (`false`, `null`, '', etc...)
export const BANNER_LINK_URL =
Expand Down

This file was deleted.

21 changes: 0 additions & 21 deletions packages/app/src/sections/dashboard/Stake/RedemptionTab.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import ROUTES from 'constants/routes'
import { selectTradePreview } from 'state/futures/selectors'
import { useAppSelector } from 'state/hooks'
import {
selectStakedEscrowedKwentaBalanceV2,
selectStakedKwentaBalanceV2,
selectStakedEscrowedKwentaBalance,
selectStakedKwentaBalance,
} from 'state/staking/selectors'
import { selectWallet } from 'state/wallet/selectors'

Expand All @@ -36,8 +36,8 @@ export const TradePanelFeeInfo = memo(() => {
const TradingRewardRow = memo(() => {
const { t } = useTranslation()
const walletAddress = useAppSelector(selectWallet)
const stakedEscrowedKwentaBalance = useAppSelector(selectStakedEscrowedKwentaBalanceV2)
const stakedKwentaBalance = useAppSelector(selectStakedKwentaBalanceV2)
const stakedEscrowedKwentaBalance = useAppSelector(selectStakedEscrowedKwentaBalance)
const stakedKwentaBalance = useAppSelector(selectStakedKwentaBalance)

const isRewardEligible = useMemo(
() => !!walletAddress && stakedKwentaBalance.add(stakedEscrowedKwentaBalance).gt(0),
Expand Down
11 changes: 2 additions & 9 deletions packages/app/src/sections/shared/Layout/HomeLayout/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,14 @@ const Banner = memo(() => {
const dispatch = useAppDispatch()
const showBanner = useAppSelector(selectShowBanner)
const storedTime: number = localStore.get('bannerIsClicked') || 0
const router = useRouter()

useEffect(
() => {
const currentTime = new Date().getTime()
dispatch(
setShowBanner(
currentTime - storedTime >= BANNER_WAITING_TIME &&
BANNER_ENABLED &&
router.pathname.includes('staking')
)
)
dispatch(setShowBanner(currentTime - storedTime >= BANNER_WAITING_TIME && BANNER_ENABLED))
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[storedTime, router.pathname]
[storedTime]
)

const handleDismiss = useCallback(
Expand Down
14 changes: 2 additions & 12 deletions packages/app/src/state/futures/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { useAppSelector, useFetchAction, usePollAction } from 'state/hooks'
import { fetchStakeMigrateData, fetchStakingV2Data } from 'state/staking/actions'
import {
selectSelectedEpoch,
selectStakingSupportedNetwork,
selectTradingRewardsSupportedNetwork,
} from 'state/staking/selectors'
import { fetchStakeMigrateData } from 'state/staking/actions'
import { selectSelectedEpoch, selectStakingSupportedNetwork } from 'state/staking/selectors'
import { selectNetwork, selectWallet } from 'state/wallet/selectors'

import {
Expand Down Expand Up @@ -38,18 +34,12 @@ export const usePollMarketFuturesData = () => {
const selectedAccountType = useAppSelector(selectFuturesType)
const networkSupportsCrossMargin = useAppSelector(selectFuturesSupportedNetwork)
const networkSupportsFutures = useAppSelector(selectFuturesSupportedNetwork)
const networkSupportsTradingRewards = useAppSelector(selectTradingRewardsSupportedNetwork)

useFetchAction(fetchCrossMarginAccount, {
dependencies: [networkId, wallet],
disabled: !wallet || !networkSupportsCrossMargin || selectedAccountType === 'isolated_margin',
})

useFetchAction(fetchStakingV2Data, {
dependencies: [networkId, wallet],
disabled: !wallet || !networkSupportsTradingRewards,
})

useFetchAction(fetchMarginTransfers, { dependencies: [networkId, wallet, selectedAccountType] })
usePollAction('fetchSharedFuturesData', fetchSharedFuturesData, {
dependencies: [networkId],
Expand Down
Loading

0 comments on commit b48959f

Please sign in to comment.