|
| 1 | +import React from "react"; |
| 2 | +import styled, { css } from "styled-components"; |
| 3 | + |
| 4 | +import { useSearchParams } from "react-router-dom"; |
| 5 | +import { formatUnits } from "viem"; |
| 6 | + |
| 7 | +import LockerIcon from "svgs/icons/locker.svg"; |
| 8 | +import PnkIcon from "svgs/icons/pnk.svg"; |
| 9 | + |
| 10 | +import { isUndefined } from "utils/index"; |
| 11 | + |
| 12 | +import { landscapeStyle } from "styles/landscapeStyle"; |
| 13 | +import { responsiveSize } from "styles/responsiveSize"; |
| 14 | + |
| 15 | +import NumberDisplay from "components/NumberDisplay"; |
| 16 | + |
| 17 | +const Container = styled.div` |
| 18 | + display: flex; |
| 19 | + flex-direction: row; |
| 20 | + flex-wrap: wrap; |
| 21 | + width: 100%; |
| 22 | + gap: 4px 16px; |
| 23 | + align-items: center; |
| 24 | + margin-bottom: ${responsiveSize(16, 24)}; |
| 25 | +
|
| 26 | + ${landscapeStyle( |
| 27 | + () => css` |
| 28 | + justify-content: space-between; |
| 29 | + ` |
| 30 | + )} |
| 31 | +`; |
| 32 | + |
| 33 | +const LockedPnk = styled.div` |
| 34 | + display: flex; |
| 35 | + flex-wrap: nowrap; |
| 36 | + gap: 8px; |
| 37 | + align-items: center; |
| 38 | + justify-content: center; |
| 39 | +`; |
| 40 | + |
| 41 | +const StakesGroup = styled.div` |
| 42 | + display: flex; |
| 43 | + gap: 12px 24px; |
| 44 | + align-items: center; |
| 45 | + flex-wrap: wrap; |
| 46 | +`; |
| 47 | + |
| 48 | +const AvailablePnk = styled.div` |
| 49 | + display: flex; |
| 50 | + flex-wrap: nowrap; |
| 51 | + gap: 8px; |
| 52 | + align-items: center; |
| 53 | + justify-content: center; |
| 54 | +`; |
| 55 | + |
| 56 | +const EffectivePnk = styled.div` |
| 57 | + display: flex; |
| 58 | + flex-wrap: nowrap; |
| 59 | + gap: 8px; |
| 60 | + align-items: center; |
| 61 | + justify-content: center; |
| 62 | +`; |
| 63 | + |
| 64 | +const StyledTitle = styled.h1` |
| 65 | + margin-bottom: 0; |
| 66 | + font-size: ${responsiveSize(20, 24)}; |
| 67 | +`; |
| 68 | + |
| 69 | +const StyledLockerIcon = styled(LockerIcon)` |
| 70 | + fill: ${({ theme }) => theme.secondaryPurple}; |
| 71 | + width: 14px; |
| 72 | + height: 14px; |
| 73 | + margin-bottom: 1px; |
| 74 | +`; |
| 75 | + |
| 76 | +const StyledPnkIcon = styled(PnkIcon)` |
| 77 | + fill: ${({ theme }) => theme.secondaryPurple}; |
| 78 | + width: 14px; |
| 79 | + height: 14px; |
| 80 | + margin-bottom: 1px; |
| 81 | +`; |
| 82 | + |
| 83 | +const StyledEffectivePnkIcon = styled(PnkIcon)` |
| 84 | + fill: ${({ theme }) => theme.secondaryPurple}; |
| 85 | + width: 14px; |
| 86 | + height: 14px; |
| 87 | + margin-bottom: 1px; |
| 88 | +`; |
| 89 | + |
| 90 | +interface IHeader { |
| 91 | + availableStake?: bigint; |
| 92 | + lockedStake?: bigint; |
| 93 | + effectiveStake?: bigint; |
| 94 | +} |
| 95 | + |
| 96 | +const Header: React.FC<IHeader> = ({ availableStake, lockedStake, effectiveStake }) => { |
| 97 | + const formattedAvailableStake = !isUndefined(availableStake) && formatUnits(availableStake, 18); |
| 98 | + const formattedLockedStake = !isUndefined(lockedStake) && formatUnits(lockedStake, 18); |
| 99 | + const formattedEffectiveStake = !isUndefined(effectiveStake) && formatUnits(effectiveStake, 18); |
| 100 | + const [searchParams] = useSearchParams(); |
| 101 | + const searchParamAddress = searchParams.get("address")?.toLowerCase(); |
| 102 | + |
| 103 | + return ( |
| 104 | + <Container> |
| 105 | + <StyledTitle>{searchParamAddress ? "Their" : "My"} Stakes</StyledTitle> |
| 106 | + <StakesGroup> |
| 107 | + {!isUndefined(availableStake) ? ( |
| 108 | + <AvailablePnk> |
| 109 | + <StyledPnkIcon /> |
| 110 | + <label> Available: </label> |
| 111 | + <small> |
| 112 | + <NumberDisplay value={formattedAvailableStake.toString()} unit="PNK" /> |
| 113 | + </small> |
| 114 | + </AvailablePnk> |
| 115 | + ) : null} |
| 116 | + {!isUndefined(effectiveStake) ? ( |
| 117 | + <EffectivePnk> |
| 118 | + <StyledEffectivePnkIcon /> |
| 119 | + <label> Staked: </label> |
| 120 | + <small> |
| 121 | + <NumberDisplay value={formattedEffectiveStake.toString()} unit="PNK" /> |
| 122 | + </small> |
| 123 | + </EffectivePnk> |
| 124 | + ) : null} |
| 125 | + {!isUndefined(lockedStake) ? ( |
| 126 | + <LockedPnk> |
| 127 | + <StyledLockerIcon /> |
| 128 | + <label> Locked: </label> |
| 129 | + <small> |
| 130 | + <NumberDisplay value={formattedLockedStake.toString()} unit="PNK" /> |
| 131 | + </small> |
| 132 | + </LockedPnk> |
| 133 | + ) : null} |
| 134 | + </StakesGroup> |
| 135 | + </Container> |
| 136 | + ); |
| 137 | +}; |
| 138 | + |
| 139 | +export default Header; |
0 commit comments