-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Staking] feat: add stake button, help tooltip; fix withdraw status d…
…isplay issues (#4186) * fix: hide active in if stake validation has started * fix: hide request withdraw status if ready to withdraw * feat: add help tooltip for withdraw in * feat: add stake button on assets page fix: add area-label to stake button
- Loading branch information
Showing
13 changed files
with
187 additions
and
36 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import CheckWallet from '@/components/common/CheckWallet' | ||
import Track from '@/components/common/Track' | ||
import { AppRoutes } from '@/config/routes' | ||
import useSpendingLimit from '@/hooks/useSpendingLimit' | ||
import { Button } from '@mui/material' | ||
import type { TokenInfo } from '@safe-global/safe-gateway-typescript-sdk' | ||
import { TokenType } from '@safe-global/safe-gateway-typescript-sdk' | ||
import { useRouter } from 'next/router' | ||
import type { ReactElement } from 'react' | ||
import StakeIcon from '@/public/images/common/stake.svg' | ||
import type { STAKE_LABELS } from '@/services/analytics/events/stake' | ||
import { STAKE_EVENTS } from '@/services/analytics/events/stake' | ||
import { useCurrentChain } from '@/hooks/useChains' | ||
|
||
const StakeButton = ({ | ||
tokenInfo, | ||
trackingLabel, | ||
}: { | ||
tokenInfo: TokenInfo | ||
trackingLabel: STAKE_LABELS | ||
}): ReactElement => { | ||
const spendingLimit = useSpendingLimit(tokenInfo) | ||
const chain = useCurrentChain() | ||
const router = useRouter() | ||
|
||
return ( | ||
<CheckWallet allowSpendingLimit={!!spendingLimit}> | ||
{(isOk) => ( | ||
<Track {...STAKE_EVENTS.OPEN_STAKE} label={trackingLabel}> | ||
<Button | ||
data-testid="stake-btn" | ||
aria-label="Stake" | ||
variant="text" | ||
color="info" | ||
size="small" | ||
startIcon={<StakeIcon />} | ||
onClick={() => { | ||
router.push({ | ||
pathname: AppRoutes.stake, | ||
query: { | ||
...router.query, | ||
asset: `${chain?.shortName}_${ | ||
tokenInfo.type === TokenType.NATIVE_TOKEN ? 'NATIVE_TOKEN' : tokenInfo.address | ||
}`, | ||
}, | ||
}) | ||
}} | ||
disabled={!isOk} | ||
> | ||
Stake | ||
</Button> | ||
</Track> | ||
)} | ||
</CheckWallet> | ||
) | ||
} | ||
|
||
export default StakeButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
export const STAKE_TITLE = 'Stake' | ||
|
||
export const WIDGET_PRODUCTION_URL = 'https://safe.widget.kiln.fi/earn' | ||
export const WIDGET_TESTNET_URL = 'https://safe.widget.testnet.kiln.fi/earn' | ||
|
||
export const widgetAppData = { | ||
url: WIDGET_PRODUCTION_URL, | ||
name: STAKE_TITLE, | ||
iconUrl: '/images/common/stake.svg', | ||
chainIds: ['17000', '11155111', '1', '42161', '137', '56', '8453', '10'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useDarkMode } from '@/hooks/useDarkMode' | ||
import useChainId from '@/hooks/useChainId' | ||
import useChains from '@/hooks/useChains' | ||
import { useMemo } from 'react' | ||
import { WIDGET_PRODUCTION_URL, WIDGET_TESTNET_URL } from '@/features/stake/constants' | ||
|
||
export const useGetStakeWidgetUrl = (asset?: string) => { | ||
let url = WIDGET_PRODUCTION_URL | ||
const isDarkMode = useDarkMode() | ||
const currentChainId = useChainId() | ||
const { configs } = useChains() | ||
const testChains = useMemo(() => configs.filter((chain) => chain.isTestnet), [configs]) | ||
if (testChains.some((chain) => chain.chainId === currentChainId)) { | ||
url = WIDGET_TESTNET_URL | ||
} | ||
const params = new URLSearchParams() | ||
params.append('theme', isDarkMode ? 'dark' : 'light') | ||
|
||
if (asset) { | ||
params.append('asset', asset) | ||
} | ||
|
||
return url + '?' + params.toString() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { GeoblockingContext } from '@/components/common/GeoblockingProvider' | ||
import { useHasFeature } from '@/hooks/useChains' | ||
import { FEATURES } from '@/utils/chains' | ||
import { useContext } from 'react' | ||
|
||
const useIsStakingFeatureEnabled = () => { | ||
const isBlockedCountry = useContext(GeoblockingContext) | ||
return useHasFeature(FEATURES.STAKING) && !isBlockedCountry | ||
} | ||
|
||
export default useIsStakingFeatureEnabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const STAKE_CATEGORY = 'stake' | ||
|
||
export const STAKE_EVENTS = { | ||
OPEN_STAKE: { | ||
action: 'Open stake', | ||
category: STAKE_CATEGORY, | ||
}, | ||
} | ||
|
||
export enum STAKE_LABELS { | ||
dashboard = 'dashboard', | ||
sidebar = 'sidebar', | ||
asset = 'asset', | ||
} |