Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b443e3e
feat: go plus security plugin setup
Lanttcat Mar 14, 2022
e750608
feat: add get supported chain for go plus lab
Lanttcat Mar 14, 2022
98b4833
feat: plugin frame step 1
Lanttcat Mar 17, 2022
f2d07d0
feat: add risk rules
Lanttcat Mar 18, 2022
fc8ace7
feat: search box style
Lanttcat Mar 21, 2022
5791f68
feat: panel layout
Lanttcat Mar 21, 2022
4d00a18
feat: panel style
Lanttcat Mar 21, 2022
97f3384
feat: update i18n
Lanttcat Mar 21, 2022
86db012
feat: update rules
Lanttcat Mar 22, 2022
65f9eef
style: improve
Lanttcat Mar 22, 2022
594b531
style: interaction design improve
Lanttcat Mar 22, 2022
daca893
feat: add default safa item card
Lanttcat Mar 24, 2022
f302593
feat: all the field is optional
Lanttcat Mar 24, 2022
5d68f5d
feat: use go plus lab url proxy
Lanttcat Mar 24, 2022
21344c0
chore: lock file
Lanttcat Mar 24, 2022
5331b63
feat: improve
Lanttcat Mar 25, 2022
075792b
fix: cspell
Lanttcat Mar 25, 2022
cb8cb5a
feat: link to explorer
Lanttcat Mar 25, 2022
3ae61da
chore: migrate mask message
hanszhoou Mar 24, 2022
a9e762a
feat: configurable app board
hanszhoou Mar 24, 2022
e09e66d
Revert "chore: migrate mask message"
hanszhoou Mar 28, 2022
00696a5
chore: resolve conflict
hanszhoou Mar 28, 2022
d5df311
chore: resolve conflict
hanszhoou Mar 28, 2022
520d835
feat: open from application entry
Lanttcat Mar 28, 2022
7ffeaef
feat: dialog background
Lanttcat Mar 28, 2022
1dd3beb
feat: update base info
Lanttcat Mar 29, 2022
508676d
feat: footer goto go plus website
Lanttcat Mar 29, 2022
ef57f96
fix: order by risk
Lanttcat Mar 29, 2022
f6f2fc5
style: security panel height
Lanttcat Mar 29, 2022
0fce29c
refactor: create token panel component
Lanttcat Mar 29, 2022
6b8e115
feat: use transition for token info collapse
Lanttcat Mar 29, 2022
8771a42
fix: should clear state when close dialog
Lanttcat Mar 29, 2022
ffae6ba
fix: remove debug code
Lanttcat Mar 29, 2022
c712d59
fix: rename network to chain
Lanttcat Mar 29, 2022
f8e438e
fix: feedback
Lanttcat Mar 30, 2022
c39fdbe
style: dialog size
Lanttcat Mar 30, 2022
6ca4e68
refactor: convert chain's id type from string to chain id
Lanttcat Mar 31, 2022
ec95436
refactor: code review feedback
Lanttcat Mar 31, 2022
af0e7d9
Merge branch 'develop' into feat/token-security-application
guanbinrui Mar 31, 2022
c5fd1ba
fix: should can be use when not connect wallet
Lanttcat Mar 31, 2022
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
12 changes: 12 additions & 0 deletions .i18n-codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@
"trans": "Translate",
"sourceMap": "inline"
}
},
{
"input": "./packages/plugins/GoPlusSecurity/src/locales/en-US.json",
"output": "./packages/plugins/GoPlusSecurity/src/locales/i18n_generated",
"parser": "i18next",
"generator": {
"type": "i18next/react-hooks",
"hooks": "useI18N",
"namespace": "io.gopluslabs.security",
"trans": "Translate",
"sourceMap": "inline"
}
}
]
}
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
"gamification",
"getdodoroute",
"getx",
"gopluslabs",
"gorli",
"gusd",
"gwapj",
Expand Down Expand Up @@ -347,6 +348,7 @@
"nyfi",
"onflow",
"openocean",
"pausable",
"pkts",
"pnpm",
"poap",
Expand Down
4 changes: 2 additions & 2 deletions packages/icons/general/Risk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export const RiskIcon = createIcon(
<path
opacity="0.4"
d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z"
fill="white"
fill="#F4212E"
/>
<path
d="M10.3626 17.3559L14.9955 12.723L12.5428 11.0878L13.6329 7L9 11.6329L11.4527 13.268L10.3626 17.3559Z"
fill="white"
fill="#F4212E"
/>
</g>,
'0 0 24 24',
Expand Down
1 change: 1 addition & 0 deletions packages/mask/.webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function createConfiguration(rawFlags: BuildFlags): Configuration {
'@masknet/plugin-wallet': join(__dirname, '../../plugins/Wallet/src/'),
'@masknet/plugin-file-service': join(__dirname, '../../plugins/FileService/src/'),
'@masknet/plugin-cyberconnect': join(__dirname, '../../plugins/CyberConnect/src/'),
'@masknet/plugin-go-plus-security': join(__dirname, '../../plugins/GoPlusSecurity/src/'),
'@masknet/external-plugin-previewer': join(__dirname, '../../external-plugin-previewer/src/'),
'@masknet/public-api': join(__dirname, '../../public-api/src/'),
'@masknet/sdk': join(__dirname, '../../mask-sdk/server/'),
Expand Down
1 change: 1 addition & 0 deletions packages/mask/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@masknet/plugin-rss3": "workspace:*",
"@masknet/plugin-solana": "workspace:*",
"@masknet/plugin-wallet": "workspace:*",
"@masknet/plugin-go-plus-security": "workspace:*",
"@masknet/public-api": "workspace:*",
"@masknet/sdk": "workspace:*",
"@masknet/shared": "workspace:*",
Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/plugin-infra/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '@masknet/plugin-rss3'
import '@masknet/plugin-dao'
import '@masknet/plugin-solana'
import '@masknet/plugin-cyberconnect'
import '@masknet/plugin-go-plus-security'
import '../plugins/Wallet'
import '../plugins/EVM'
import '../plugins/RedPacket'
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-infra/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ export enum PluginId {
UnlockProtocol = 'com.maskbook.unlockprotocol',
FileService = 'com.maskbook.fileservice',
CyberConnect = 'me.cyberconnect.app',
GoPlusSecurity = 'io.gopluslabs.security',
// @masknet/scripts: insert-here
}

Expand Down
20 changes: 20 additions & 0 deletions packages/plugins/GoPlusSecurity/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@masknet/plugin-go-plus-security",
"private": true,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"dependencies": {
"react-feather": "^2.0.9",
"@masknet/icons": "workspace:*",
"@masknet/plugin-infra": "workspace:*",
"@masknet/shared": "workspace:*",
"@masknet/shared-base-ui": "workspace:*",
"@masknet/shared-base": "workspace:*",
"@masknet/theme": "workspace:*",
"@masknet/web3-providers": "workspace:*",
"@masknet/web3-shared-evm": "workspace:*",
"react-use": "^17.3.2",
"bignumber.js": "^9.0.2",
"urlcat": "^2.0.4"
}
}
9 changes: 9 additions & 0 deletions packages/plugins/GoPlusSecurity/src/Dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Plugin } from '@masknet/plugin-infra'
import { base } from '../base'

const dashboard: Plugin.Dashboard.Definition = {
...base,
init(signal) {},
}

export default dashboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Box, DialogContent, Stack } from '@mui/material'
import { makeStyles, MaskDialog, useStylesExtends } from '@masknet/theme'
import { useI18N } from '../locales'
import { SearchBox } from './components/SearchBox'
import { useAsyncFn } from 'react-use'
import { GoPlusLabs } from '@masknet/web3-providers'
import { Searching } from './components/Searching'
import { SecurityPanel } from './components/SecurityPanel'
import { Footer } from './components/Footer'
import { Center, TokenSecurity } from './components/Common'
import { DefaultPlaceholder } from './components/DefaultPlaceholder'
import { NotFound } from './components/NotFound'
import type { ChainId } from '@masknet/web3-shared-evm'

const useStyles = makeStyles()((theme) => ({
root: {
width: 600,
},
paperRoot: {
backgroundImage: 'none',
'&>h2': {
height: 30,
border: `1px solid ${theme.palette.divider}`,
padding: theme.spacing(1.875, 2.5, 1.875, 2.5),
marginBottom: 24,
},
},
content: {
width: 552,
height: 510,
maxHeight: 510,
paddingBottom: theme.spacing(3),
},
}))

export interface BuyTokenDialogProps extends withClasses<never | 'root'> {
open: boolean
onClose(): void
}

export function CheckSecurityDialog(props: BuyTokenDialogProps) {
const t = useI18N()
const classes = useStylesExtends(useStyles(), props)
const { open, onClose } = props

const [{ value, loading: searching, error }, onSearch] = useAsyncFn(async (chainId: ChainId, content: string) => {
const values = await GoPlusLabs.getTokenSecurity(chainId, [content.trim()])
if (!Object.keys(values ?? {}).length) throw new Error('Contract Not Found')
return Object.entries(values ?? {}).map((x) => ({ ...x[1], contract: x[0], chainId }))[0] as
| TokenSecurity
| undefined
}, [])

return (
<MaskDialog
DialogProps={{ classes: { paper: classes.paperRoot } }}
title={t.dialog_title()}
open={open}
onBack={onClose}>
<DialogContent className={classes.content}>
<Stack height="100%" spacing={2}>
<Box>
<SearchBox onSearch={onSearch} />
</Box>
<Stack flex={1}>
{searching && (
<Center>
<Searching />
</Center>
)}
{error && !searching && <NotFound />}
{!error && !searching && value && <SecurityPanel tokenSecurity={value} />}
{!error && !searching && !value && (
<Center>
<DefaultPlaceholder />
</Center>
)}
</Stack>
<Box>
<Footer />
</Box>
</Stack>
</DialogContent>
</MaskDialog>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { SecurityAPI } from '@masknet/web3-providers'
import { InfoIcon, RiskIcon, SuccessIcon } from '@masknet/icons'
import { memo, ReactNode } from 'react'
import { Stack } from '@mui/material'
import type { useI18N } from '../../locales'
import type { ChainId } from '@masknet/web3-shared-evm'

export type TokenSecurity = SecurityAPI.ContractSecurity &
SecurityAPI.TokenSecurity &
SecurityAPI.TradingSecurity & { contract: string; chainId: ChainId }

export enum SecurityMessageLevel {
High = 'High',
Medium = 'Medium',
Safe = 'Safe',
}

export const Center = memo(({ children }) => (
<Stack height="100%" justifyContent="center" alignItems="center">
{children}
</Stack>
))

type DefineMapping = {
[key in SecurityMessageLevel]: {
i18nKey: keyof ReturnType<typeof useI18N>
bgColor: string
titleColor: string
icon(size?: number): ReactNode
}
}

export const DefineMapping: DefineMapping = {
[SecurityMessageLevel.High]: {
i18nKey: 'high_risk',
titleColor: '#FF5F5F',
bgColor: 'rgba(255, 95, 95, 0.1)',
icon: (size: number) => <RiskIcon sx={{ fontSize: size ?? 24 }} />,
},
[SecurityMessageLevel.Medium]: {
i18nKey: 'medium_risk',
titleColor: '#FFB915',
bgColor: 'rgba(255, 185, 21, 0.1)',
icon: (size: number) => <InfoIcon sx={{ fontSize: size ?? 24, color: '#FFB915' }} />,
},
[SecurityMessageLevel.Safe]: {
i18nKey: 'low_risk',
titleColor: '#60DFAB',
bgColor: 'rgba(119, 224, 181, 0.1)',
icon: (size: number) => <SuccessIcon sx={{ fontSize: size ?? 24 }} />,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Box, Stack, Typography } from '@mui/material'
import { SecurityIcon } from '../icons/SecurityIcon'
import { useI18N } from '../../locales'

export const DefaultPlaceholder = () => {
const t = useI18N()
return (
<Stack alignItems="center" spacing={2.5}>
<Box>
<SecurityIcon sx={{ fontSize: 48 }} />
</Box>
<Box>
<Typography variant="body2">{t.default_placeholder()}</Typography>
</Box>
</Stack>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Box, Link, Stack, Typography } from '@mui/material'
import { useI18N } from '../../locales'
import { GoPlusLabLogo } from '../icons/Logo'
import { PLUGIN_OFFICIAL_WEBSITE } from '../../constants'

export const Footer = () => {
const t = useI18N()
return (
<Stack justifyContent="flex-end" direction="row">
<Stack direction="row" alignItems="center">
<Box>
<Typography variant="body2" mr={1.25}>
{t.powered_by_go_plus()}
</Typography>
</Box>
<Link href={PLUGIN_OFFICIAL_WEBSITE} target="_blank" rel="noopener noreferrer">
<GoPlusLabLogo />
</Link>
</Stack>
</Stack>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { makeStyles } from '@masknet/theme'
import type { SvgIconProps } from '@mui/material'
import { LoadingIcon } from '../icons/Loading'

const useStyles = makeStyles()({
animated: {
'@keyframes loadingAnimation': {
'0%': {
transform: 'rotate(0deg)',
},
'100%': {
transform: 'rotate(360deg)',
},
},
animation: 'loadingAnimation 1s linear infinite',
},
})

export const LoadingAnimation = (props: SvgIconProps) => {
const { classes } = useStyles()
return <LoadingIcon {...props} className={`${classes.animated} ${props.className}`} />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Stack, Typography } from '@mui/material'
import { useI18N } from '../../locales'

export const NotFound = () => {
const t = useI18N()
return (
<Stack justifyContent="flex-start" alignItems="flex-start">
<Typography fontSize={12} color={(t) => t.palette.error.main}>
{t.not_found_tip()}
</Typography>
</Stack>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { memo, ReactNode } from 'react'
import { DefineMapping, TokenSecurity } from './Common'
import { Box, Stack, Typography } from '@mui/material'
import type { SecurityMessage } from '../rules'
import { useI18N } from '../../locales'
import { makeStyles } from '@masknet/theme'

const useStyles = makeStyles()((theme) => ({
detectionCard: {
backgroundColor: theme.palette.background.default,
borderRadius: 8,
},
icon: {
display: 'inline-flex',
lineHeight: '22px',
height: 22,
justifyContent: 'center',
alignItems: 'center',
},
header: {
fontSize: 14,
lineHeight: '22px',
},
description: {
fontSize: 12,
},
}))

interface RiskCardProps {
info: SecurityMessage
tokenSecurity: TokenSecurity
}

export const RiskCard = memo<RiskCardProps>(({ info, tokenSecurity }) => {
const t = useI18N()
return (
<RiskCardUI
icon={DefineMapping[info.level].icon(14)}
title={t[info.titleKey]({ quantity: '', rate: info.i18nParams?.(tokenSecurity).rate ?? '' })}
titleColor={DefineMapping[info.level].titleColor}
description={t[info.messageKey]({ quantity: '', rate: info.i18nParams?.(tokenSecurity).rate ?? '' })}
/>
)
})

interface RiskCardUIProps {
icon: ReactNode
title: string
titleColor: string
description?: string
}

export const RiskCardUI = memo<RiskCardUIProps>(({ icon, title, titleColor, description }) => {
const { classes } = useStyles()
return (
<Stack spacing={1} key={title} p={1.5} direction="row" className={classes.detectionCard}>
<Box className={classes.icon}>{icon}</Box>
<Box>
<Typography className={classes.header} color={titleColor}>
{title}
</Typography>
{description && <Typography className={classes.description}>{description}</Typography>}
</Box>
</Stack>
)
})
Loading