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

Add audit label #322

Merged
merged 12 commits into from
Jan 4, 2025
44 changes: 32 additions & 12 deletions src/containers/HeaderWrapper/HeaderWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,39 @@ export const HeaderWrapper: React.FC = () => {
}, [])

const shouldResetRpc = useMemo(() => {
const defaultRpcNumber = localStorage.getItem(`INVARIANT_DEFAULT_RPC_NUMBER`)
console.log(defaultRpcNumber)
const currentRpcNumber =
RECOMMENDED_RPC_ADDRESS[NetworkType.Mainnet].slice(-12, -1) +
RECOMMENDED_RPC_ADDRESS[NetworkType.Testnet].slice(-15, -5) +
RECOMMENDED_RPC_ADDRESS[NetworkType.Devnet].slice(-15, -5)
console.log(currentRpcNumber)

if (defaultRpcNumber === null || currentRpcNumber !== defaultRpcNumber) {
localStorage.setItem(`INVARIANT_DEFAULT_RPC_NUMBER`, currentRpcNumber)
return true
} else {
const generateHash = (str: string): string => {
let hash = 0

for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i)
hash = (hash << 5) - hash + char
hash = hash & hash
}

return Math.abs(hash).toString(16).padStart(8, '0')
}

const STORAGE_KEY = 'INVARIANT_RPC_HASH'

const currentAddresses =
RECOMMENDED_RPC_ADDRESS[NetworkType.Mainnet] +
RECOMMENDED_RPC_ADDRESS[NetworkType.Testnet] +
RECOMMENDED_RPC_ADDRESS[NetworkType.Devnet]

const currentHash = generateHash(currentAddresses)

try {
const storedHash = localStorage.getItem(STORAGE_KEY)

if (storedHash === null || currentHash !== storedHash) {
localStorage.setItem(STORAGE_KEY, currentHash)
return true
}

return false
} catch (error) {
console.error('Error accessing localStorage:', error)
return true
}
}, [])

Expand Down
21 changes: 21 additions & 0 deletions src/pages/LeaderboardPage/components/AuditLabel/AuditLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Box, Typography } from '@mui/material'
import { colors, typography } from '@static/theme'
import icons from '@static/icons'
export const AuditLabel = () => {
return (
<Box
sx={{
display: 'flex',
width: '100%',
justifyContent: 'center',
margin: '20px 0',
opacity: 0.3,
alignItems: 'center'
}}>
<img src={icons.auditIcon} alt='Shield' />
<Typography style={{ color: colors.invariant.text, ...typography.body3, marginLeft: '8px' }}>
Audited by Sec3
</Typography>
</Box>
)
}
2 changes: 2 additions & 0 deletions src/pages/RootPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { actions } from '@store/reducers/positions'
import { NormalBanner } from './LeaderboardPage/components/LeaderboardBanner/NormalBanner'
import { NetworkType } from '@store/consts/static'
import { network } from '@store/selectors/solanaConnection'
import { AuditLabel } from './LeaderboardPage/components/AuditLabel/AuditLabel'

const BANNER_STORAGE_KEY = 'invariant-banner-state'
const BANNER_HIDE_DURATION = 1000 * 60 * 60 * 24 // 24 hours
Expand Down Expand Up @@ -114,6 +115,7 @@ const RootPage: React.FC = memo(() => {
<HeaderWrapper />
<Grid className={classes.body}>
<Outlet />
<AuditLabel />
</Grid>
<FooterWrapper />
</Grid>
Expand Down
4 changes: 3 additions & 1 deletion src/static/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import lockIcon from './svg/lockIcon.svg'
import airdrop from './svg/airdrop.svg'
import nightly from './svg/nightly.svg'
import airdropRainbow from './svg/airdropRainbow.svg'
import auditIcon from './svg/auditIcon.svg'

const icons: { [key: string]: string } = {
clear: clearIcon,
Expand Down Expand Up @@ -101,7 +102,8 @@ const icons: { [key: string]: string } = {
lockIcon,
airdrop,
nightly,
airdropRainbow
airdropRainbow,
auditIcon
}

export default icons
3 changes: 3 additions & 0 deletions src/static/svg/auditIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading