Skip to content

Commit

Permalink
feat: fw-6316 okx bridge (#11790)
Browse files Browse the repository at this point in the history
  • Loading branch information
swkatmask authored and guanbinrui committed Sep 24, 2024
1 parent f737adb commit 0826e97
Show file tree
Hide file tree
Showing 73 changed files with 3,457 additions and 759 deletions.
3 changes: 3 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"blurhash",
"boba",
"bonfida",
"bridgable",
"bridgers",
"brise",
"cacheable",
"caip",
Expand Down Expand Up @@ -377,6 +379,7 @@
"bsct",
"btcb",
"canft",
"cctp",
"celo",
"ceur",
"chainid",
Expand Down
2 changes: 1 addition & 1 deletion packages/icons/general/Checkbox.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/icons/general/EmptySimple.dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/icons/general/EmptySimple.light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/icons/general/RadioButtonChecked.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 66 additions & 12 deletions packages/icons/icon-generated-as-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1263,10 +1263,13 @@ export const Checkbox = /*#__PURE__*/ __createIcon('Checkbox', [
d: 'M0 4a4 4 0 0 1 4-4h10a4 4 0 0 1 4 4v10a4 4 0 0 1-4 4H4a4 4 0 0 1-4-4z',
}),
/*#__PURE__*/ _jsx('path', {
fill: '#fff',
fillRule: 'evenodd',
d: 'M14.03 5.47a.75.75 0 0 1 0 1.06l-6 6a.75.75 0 0 1-1.06 0l-3-3a.75.75 0 0 1 1.06-1.06l2.47 2.47 5.47-5.47a.75.75 0 0 1 1.06 0',
clipRule: 'evenodd',
style: {
'--default-stroke-color': '#fff',
fill: 'var(--stroke-color, var(--default-stroke-color, currentColor))',
},
}),
],
}),
Expand Down Expand Up @@ -1982,16 +1985,64 @@ export const Empty = /*#__PURE__*/ __createIcon('Empty', [
u: () => new URL('./general/Empty.png', import.meta.url).href,
},
])
export const EmptySimple = /*#__PURE__*/ __createIcon('EmptySimple', [
{
c: ['dark'],
u: () => new URL('./general/EmptySimple.dark.svg', import.meta.url).href,
},
{
c: ['light'],
u: () => new URL('./general/EmptySimple.light.svg', import.meta.url).href,
},
])
export const EmptySimple = /*#__PURE__*/ __createIcon(
'EmptySimple',
[
{
c: ['dark'],
u: () => new URL('./general/EmptySimple.dark.svg', import.meta.url).href,
j: () =>
/*#__PURE__*/ _jsx('svg', {
xmlns: 'http://www.w3.org/2000/svg',
viewBox: '0 0 36 37',
children: /*#__PURE__*/ _jsxs('g', {
fillRule: 'evenodd',
clipRule: 'evenodd',
style: {
'--default-color': '#666c75',
fill: 'var(--icon-color, var(--default-color, currentColor))',
},
children: [
/*#__PURE__*/ _jsx('path', {
d: 'M4.59 5.223C6.611 3.2 9.631 2.434 13.5 2.434h9c3.869 0 6.889.766 8.911 2.789 2.023 2.023 2.79 5.043 2.79 8.911v9c0 3.868-.767 6.889-2.79 8.911-2.022 2.023-5.042 2.79-8.91 2.79h-9c-3.87 0-6.89-.767-8.912-2.79S1.8 27.002 1.8 23.135v-9c0-3.87.767-6.89 2.79-8.912M6.285 6.92C4.934 8.272 4.2 10.502 4.2 14.134v9c0 3.632.734 5.862 2.086 7.214C7.64 31.7 9.87 32.434 13.5 32.434h9c3.632 0 5.862-.734 7.214-2.086s2.086-3.582 2.086-7.214v-9c0-3.632-.733-5.862-2.086-7.214S26.132 4.834 22.5 4.834h-9c-3.631 0-5.861.734-7.214 2.086z',
}),
/*#__PURE__*/ _jsx('path', {
d: 'm25.749 22.321-1.335 2.685a4.2 4.2 0 0 1-3.759 2.328H15.36c-.436 0-2.597-.003-3.77-2.305l-.004-.01-1.334-2.683a1.8 1.8 0 0 0-1.612-1.002H3a1.2 1.2 0 1 1 0-2.4h5.64a4.2 4.2 0 0 1 3.759 2.329v.002l1.333 2.68c.507.99 1.34.99 1.626.99h5.297a1.8 1.8 0 0 0 1.611-1.001l1.336-2.686a4.2 4.2 0 0 1 3.758-2.329h5.61a1.2 1.2 0 0 1 0 2.4h-5.61c-.68 0-1.303.386-1.611 1.002',
}),
],
}),
}),
s: true,
},
{
c: ['light'],
u: () => new URL('./general/EmptySimple.light.svg', import.meta.url).href,
j: () =>
/*#__PURE__*/ _jsx('svg', {
xmlns: 'http://www.w3.org/2000/svg',
viewBox: '0 0 36 37',
children: /*#__PURE__*/ _jsxs('g', {
fillRule: 'evenodd',
clipRule: 'evenodd',
style: {
'--default-color': '#acb4c1',
fill: 'var(--icon-color, var(--default-color, currentColor))',
},
children: [
/*#__PURE__*/ _jsx('path', {
d: 'M4.59 5.223C6.611 3.2 9.631 2.434 13.5 2.434h9c3.869 0 6.889.766 8.911 2.789 2.023 2.023 2.79 5.043 2.79 8.911v9c0 3.868-.767 6.889-2.79 8.911-2.022 2.023-5.042 2.79-8.91 2.79h-9c-3.87 0-6.89-.767-8.912-2.79S1.8 27.002 1.8 23.135v-9c0-3.87.767-6.89 2.79-8.912M6.285 6.92C4.934 8.272 4.2 10.502 4.2 14.134v9c0 3.632.734 5.862 2.086 7.214C7.64 31.7 9.87 32.434 13.5 32.434h9c3.632 0 5.862-.734 7.214-2.086s2.086-3.582 2.086-7.214v-9c0-3.632-.733-5.862-2.086-7.214S26.132 4.834 22.5 4.834h-9c-3.631 0-5.861.734-7.214 2.086z',
}),
/*#__PURE__*/ _jsx('path', {
d: 'm25.749 22.321-1.335 2.685a4.2 4.2 0 0 1-3.759 2.328H15.36c-.436 0-2.597-.003-3.77-2.305l-.004-.01-1.334-2.683a1.8 1.8 0 0 0-1.612-1.002H3a1.2 1.2 0 1 1 0-2.4h5.64a4.2 4.2 0 0 1 3.759 2.329v.002l1.333 2.68c.507.99 1.34.99 1.626.99h5.297a1.8 1.8 0 0 0 1.611-1.001l1.336-2.686a4.2 4.2 0 0 1 3.758-2.329h5.61a1.2 1.2 0 0 1 0 2.4h-5.61c-.68 0-1.303.386-1.611 1.002',
}),
],
}),
}),
s: true,
},
],
[36, 37],
)
export const EncryptedFiles = /*#__PURE__*/ __createIcon('EncryptedFiles', [
{
u: () => new URL('./general/EncryptedFiles.svg', import.meta.url).href,
Expand Down Expand Up @@ -3038,11 +3089,14 @@ export const RadioButtonChecked = /*#__PURE__*/ __createIcon('RadioButtonChecked
},
}),
/*#__PURE__*/ _jsx('path', {
stroke: '#fff',
strokeLinecap: 'round',
strokeLinejoin: 'round',
strokeWidth: '1.5',
d: 'm5.166 10.63 3.333 3.5 6.667-7',
style: {
'--default-stroke-color': '#fff',
stroke: 'var(--stroke-color, var(--default-stroke-color, currentColor))',
},
}),
],
}),
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/Trader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"bignumber.js": "9.1.2",
"date-fns": "^2.30.0",
"fuse.js": "^7.0.0",
"immer": "^10.1.1",
"react-router-dom": "^6.24.0",
"react-use": "^17.4.0",
"urlcat": "^3.1.0",
Expand Down
95 changes: 95 additions & 0 deletions packages/plugins/Trader/src/SiteAdaptor/components/BridgeNode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { makeStyles } from '@masknet/theme'
import { Typography } from '@mui/material'
import { memo, type HTMLProps } from 'react'
import { CoinIcon, type CoinIconProps } from './CoinIcon.js'

const useStyles = makeStyles<void, 'active'>()((theme, _, refs) => ({
active: {},
node: {
position: 'relative',
padding: theme.spacing(1.5),
display: 'flex',
flexDirection: 'column',
gap: 10,
borderRadius: theme.spacing(1.5),
border: `1px solid ${theme.palette.maskColor.line}`,
backgroundColor: theme.palette.maskColor.bg,
[`&.${refs.active}`]: {
backgroundColor: theme.palette.maskColor.bottom,
'&::after': {
content: '""',
display: 'block',
borderRadius: 4,
border: '1px solid transparent',
borderRightColor: theme.palette.maskColor.line,
borderBottomColor: theme.palette.maskColor.line,
transform: 'scaleX(.6) rotate(45deg) translate(-50%, 100%)',
backgroundColor: theme.palette.maskColor.bottom,
position: 'absolute',
width: 12,
height: 12,
left: '50%',
bottom: -2,
zIndex: 1,
},
},
},
coin: {
display: 'flex',
gap: theme.spacing(0.5),
alignItems: 'flex-start',
},
chainName: {
fontSize: 16,
lineHeight: '20px',
color: theme.palette.maskColor.second,
},
symbol: {
fontSize: 16,
lineHeight: '20px',
fontWeight: 700,
color: theme.palette.maskColor.main,
},
step: {
position: 'absolute',
userSelect: 'none',
right: 0,
top: 0,
minWidth: theme.spacing(4),
textAlign: 'center',
lineHeight: '76px',
fontSize: 64,
fontWeight: 700,
fontFamily: 'Helvetica',
color: theme.palette.maskColor.secondaryMain,
},
}))

interface Props extends HTMLProps<HTMLDivElement>, Pick<CoinIconProps, 'chainId' | 'address' | 'disableBadge'> {
symbol?: string
step: number
active?: boolean
}

export const BridgeNode = memo<Props>(function BridgeNode({
symbol,
chainId,
address,
label,
step,
active,
disableBadge,
...rest
}) {
const { classes, cx } = useStyles()
return (
<div {...rest} className={cx(classes.node, rest.className, active ? classes.active : null)}>
<Typography className={classes.chainName}>{label}</Typography>
<div className={classes.coin}>
<CoinIcon chainId={chainId} address={address} disableBadge={disableBadge} />
<Typography className={classes.symbol}>{symbol ?? '--'}</Typography>
</div>
<Typography className={classes.step}>{step}</Typography>
</div>
)
})
74 changes: 74 additions & 0 deletions packages/plugins/Trader/src/SiteAdaptor/components/CoinIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { NetworkIcon, TokenIcon } from '@masknet/shared'
import { NetworkPluginID } from '@masknet/shared-base'
import { makeStyles } from '@masknet/theme'
import type { Web3Helper } from '@masknet/web3-helpers'
import { OKX } from '@masknet/web3-providers'
import { isSameAddress } from '@masknet/web3-shared-base'
import type { ChainId } from '@masknet/web3-shared-evm'
import { Box, type BoxProps } from '@mui/material'
import { skipToken, useQuery } from '@tanstack/react-query'
import { memo } from 'react'

const useStyles = makeStyles()(() => ({
icon: {
position: 'relative',
width: 30,
height: 30,
},
tokenIcon: {
height: 30,
width: 30,
},
badgeIcon: {
position: 'absolute',
right: -3,
bottom: -2,
},
}))

export interface CoinIconProps extends BoxProps {
chainId?: ChainId
address?: string
token?: Web3Helper.FungibleTokenAll
tokenIconSize?: number
chainIconSize?: number
disableBadge?: boolean
}

export const CoinIcon = memo<CoinIconProps>(function CoinIcon({
chainId,
address,
tokenIconSize = 30,
chainIconSize = 12,
disableBadge,
...rest
}) {
const { classes, cx } = useStyles()

const { data: logoURL } = useQuery({
queryKey: ['okx-tokens', chainId],
queryFn: chainId ? () => OKX.getTokens(chainId) : skipToken,
select(tokens) {
return tokens?.find((x) => isSameAddress(x.address, address))?.logoURL
},
})
return (
<Box className={cx(classes.icon, rest.className)}>
<TokenIcon
className={classes.tokenIcon}
chainId={chainId}
address={address || ''}
size={tokenIconSize}
logoURL={logoURL}
/>
{chainId && !disableBadge ?
<NetworkIcon
pluginID={NetworkPluginID.PLUGIN_EVM}
className={classes.badgeIcon}
chainId={chainId}
size={chainIconSize}
/>
: null}
</Box>
)
})
Loading

0 comments on commit 0826e97

Please sign in to comment.