Skip to content
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
98 changes: 40 additions & 58 deletions src/pages/stakingPage/components/RewardsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { EthLogo } from '@/components/commons/Logo/EthLogo';
import { AssetPriceResponse } from '@/types/api';
import { claim, compound } from '@/web3Config/staking/hooks';

import { useVesting } from '../hooks/useVesting';

type RewardsCardProps = {
data: {
claimable: string;
Expand All @@ -24,7 +22,6 @@ export const RewardsCard = ({ data, refetchData }: RewardsCardProps): JSX.Elemen
const [isClaiming, setIsClaiming] = useState(false);
const [isCompounding, setIsCompounding] = useState(false);
const [grixPrice, setGrixPrice] = useState<number | null>(null);
const { totalStaked } = useVesting();
const toast = useToast();

// Fetch GRIX price from CoinGecko
Expand Down Expand Up @@ -113,65 +110,50 @@ export const RewardsCard = ({ data, refetchData }: RewardsCardProps): JSX.Elemen
_hover={{ borderColor: 'gray.800' }}
>
<VStack spacing={3} align="stretch">
<HStack justify="space-between">
<HStack spacing={2}>
<EthLogo boxSize="14px" />
<Text color="white" fontWeight="600" fontSize="sm" letterSpacing="-0.01em">
WETH
</Text>
<VStack align="stretch" spacing={1}>
<HStack justify="space-between" align="flex-start">
<HStack spacing={1} align="center">
<EthLogo boxSize="12px" />
<Text color="gray.500" fontSize="xs">
WETH Rewards
</Text>
</HStack>
<VStack align="flex-end" spacing={0}>
<Text color="white" fontSize="sm" fontWeight="600">
≤{(0.0001).toFixed(4)} WETH
</Text>
<Text color="gray.400" fontSize="xs">
≤${(0.01).toFixed(2)}
</Text>
</VStack>
</HStack>
<Text color="gray.400" fontSize="sm" fontWeight="500" flexShrink={0}>
≤{(0.0001).toFixed(4)} WETH (≤${(0.01).toFixed(2)})
</Text>
</HStack>
</VStack>

<HStack justify="space-between">
<HStack spacing={2}>
<GrixLogo boxSize="14px" />
<Text color="white" fontWeight="600" fontSize="sm" letterSpacing="-0.01em">
Claimable Rewards
</Text>
</HStack>
<Text color="gray.400" fontSize="sm" fontWeight="500" flexShrink={0} textAlign="right">
{data?.claimable ? Number(data.claimable).toFixed(4) : '0.0000'} esGRIX
{grixPrice && data?.claimable && (
<Text as="span" color="green.300" fontWeight="600" fontSize="sm" letterSpacing="-0.01em">
&nbsp;($
{(Number(data.claimable) * grixPrice).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}
)
<VStack align="stretch" spacing={1}>
<HStack justify="space-between" align="flex-start">
<HStack spacing={1} align="center">
<GrixLogo boxSize="12px" />
<Text color="gray.500" fontSize="xs">
Claimable Rewards
</Text>
)}
</Text>
</HStack>

<HStack justify="space-between" pt={2} borderTop="1px solid" borderColor="gray.800">
<HStack spacing={2}>
<GrixLogo boxSize="14px" />
<Text color="white" fontWeight="600" fontSize="sm" letterSpacing="-0.01em">
Total Staked
</Text>
</HStack>
<Text color="gray.400" fontSize="sm" fontWeight="500" flexShrink={0} textAlign="right">
{Number(totalStaked).toLocaleString(undefined, {
minimumFractionDigits: 1,
maximumFractionDigits: 1,
})}{' '}
GRIX
{grixPrice && Number(totalStaked) > 0 && (
<Text as="span" color="green.300" fontWeight="600" fontSize="sm" letterSpacing="-0.01em">
&nbsp;($
{(Number(totalStaked) * grixPrice).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}
)
</HStack>
<VStack align="flex-end" spacing={0}>
<Text color="white" fontSize="sm" fontWeight="600">
{data?.claimable ? Number(data.claimable).toFixed(4) : '0.00'} esGRIX
</Text>
)}
</Text>
</HStack>
{grixPrice && data?.claimable && Number(data.claimable) > 0 && (
<Text color="green.300" fontSize="xs" fontWeight="500">
$
{(Number(data.claimable) * grixPrice).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}
</Text>
)}
</VStack>
</HStack>
</VStack>

<Button
onClick={() => void handleClaim()}
isLoading={isClaiming}
Expand Down
111 changes: 88 additions & 23 deletions src/pages/stakingPage/components/StakeUnstakeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ export const StakeUnstakeModal: React.FC<StakeUnstakeModalProps> = ({
<ModalContent bg="#0D0F12" maxW="400px">
<Box px={6} py={4}>
<Flex justify="space-between" align="center" mb={4}>
<Text color="white" fontSize="xl" fontWeight="600">
<Text color="white" fontSize="sm" fontWeight="600">
{title}
</Text>
<ModalCloseButton position="static" color="gray.400" />
</Flex>

<VStack spacing={4} align="stretch">
<Text color="gray.500" fontSize="md" mb={1}>
<Text color="gray.500" fontSize="xs" mb={1}>
{isStakeMode ? 'Stake Amount' : 'Unstake Amount'}
</Text>

Expand All @@ -116,7 +116,7 @@ export const StakeUnstakeModal: React.FC<StakeUnstakeModalProps> = ({
<Box bg="#1E2328" p={2} borderRadius="lg">
<GrixLogo boxSize="24px" />
</Box>
<Text color="white" fontSize="lg" fontWeight="600">
<Text color="white" fontSize="sm" fontWeight="600">
{isEsGrix ? 'esGRIX' : 'GRIX'}
</Text>
</HStack>
Expand All @@ -127,17 +127,17 @@ export const StakeUnstakeModal: React.FC<StakeUnstakeModalProps> = ({
variant="unstyled"
textAlign="right"
color="white"
fontSize="lg"
fontSize="sm"
width="auto"
/>
</Flex>
</Box>

<Flex justify="space-between" align="center">
<Text color="gray.500" fontSize="md">
<Text color="gray.500" fontSize="xs">
{isStakeMode ? 'Available balance' : 'Staked balance'}
</Text>
<Text color="white" fontSize="md">
<Text color="white" fontSize="sm">
{formatBalance(availableAmount)} {isEsGrix ? 'esGRIX' : 'GRIX'}
</Text>
</Flex>
Expand All @@ -147,14 +147,39 @@ export const StakeUnstakeModal: React.FC<StakeUnstakeModalProps> = ({
<Button
key={percentage}
onClick={() => handlePercentageClick(percentage)}
bg="#1E2328"
color="white"
size="md"
variant="outline"
bg="gray.800"
color="gray.300"
borderColor="gray.600"
size="sm"
flex={1}
height="32px"
fontSize="xs"
fontWeight="500"
isDisabled={!hasBalance}
opacity={hasBalance ? 1 : 0.5}
_hover={{ bg: hasBalance ? '#2A3038' : '#1E2328' }}
_active={{ bg: hasBalance ? '#2A3038' : '#1E2328' }}
_hover={{
bg: hasBalance ? 'gray.700' : 'gray.800',
borderColor: hasBalance ? 'gray.500' : 'gray.600',
color: hasBalance ? 'white' : 'gray.300',
transform: hasBalance ? 'translateY(-1px)' : 'none',
boxShadow: hasBalance ? 'sm' : 'none',
}}
_active={{
bg: hasBalance ? 'gray.600' : 'gray.800',
transform: hasBalance ? 'translateY(0)' : 'none',
}}
_disabled={{
opacity: 0.5,
cursor: 'not-allowed',
_hover: {
bg: 'gray.800',
borderColor: 'gray.600',
color: 'gray.300',
transform: 'none',
boxShadow: 'none',
},
}}
transition="all 0.2s"
>
{percentage}%
</Button>
Expand All @@ -167,7 +192,7 @@ export const StakeUnstakeModal: React.FC<StakeUnstakeModalProps> = ({
<Box as="span" color="#3B82F6" fontSize="lg">
</Box>
<Text color="#3B82F6" fontSize="sm">
<Text color="#3B82F6" fontSize="xs">
You might not be able to unstake your desired {isEsGrix ? 'esGRIX' : 'GRIX'} if there is an active
vesting position.
</Text>
Expand All @@ -181,15 +206,35 @@ export const StakeUnstakeModal: React.FC<StakeUnstakeModalProps> = ({
isLoading={isApproving}
loadingText="Approving"
onClick={handleApprove}
bg="#2F6C60"
variant="solid"
bg="teal.500"
color="white"
size="lg"
size="md"
width="full"
height="48px"
height="40px"
fontSize="sm"
fontWeight="500"
isDisabled={!isAmountValid()}
_hover={{ bg: '#2A5F54' }}
_active={{ bg: '#264F46' }}
_hover={{
bg: 'teal.600',
transform: 'translateY(-1px)',
boxShadow: 'md',
}}
_active={{
bg: 'teal.700',
transform: 'translateY(0)',
}}
_disabled={{
bg: 'gray.700',
color: 'gray.500',
cursor: 'not-allowed',
_hover: {
bg: 'gray.700',
transform: 'none',
boxShadow: 'none',
},
}}
transition="all 0.2s"
>
Approve
</Button>
Expand All @@ -198,15 +243,35 @@ export const StakeUnstakeModal: React.FC<StakeUnstakeModalProps> = ({
isLoading={isLoading}
loadingText={isStakeMode ? 'Staking' : 'Unstaking'}
onClick={onSubmit}
bg="#2F6C60"
variant="solid"
bg="teal.500"
color="white"
size="lg"
size="md"
width="full"
height="48px"
height="40px"
fontSize="sm"
fontWeight="500"
isDisabled={!isAmountValid() || !amount}
_hover={{ bg: '#2A5F54' }}
_active={{ bg: '#264F46' }}
_hover={{
bg: 'teal.600',
transform: 'translateY(-1px)',
boxShadow: 'md',
}}
_active={{
bg: 'teal.700',
transform: 'translateY(0)',
}}
_disabled={{
bg: 'gray.700',
color: 'gray.500',
cursor: 'not-allowed',
_hover: {
bg: 'gray.700',
transform: 'none',
boxShadow: 'none',
},
}}
transition="all 0.2s"
>
{isStakeMode ? 'Stake' : 'Unstake'}
</Button>
Expand Down
Loading