Skip to content

Commit

Permalink
fixup! feat: mf-6358 migrate finance feed source to debank
Browse files Browse the repository at this point in the history
  • Loading branch information
swkatmask committed Oct 25, 2024
1 parent 52a5703 commit 26a24ce
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 32 deletions.
52 changes: 37 additions & 15 deletions packages/plugins/RSS3/src/SiteAdaptor/FinanceFeeds/FeedSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Select, Trans } from '@lingui/macro'
import { type Transaction } from '@masknet/web3-shared-base'
import { isSameAddress, type Transaction } from '@masknet/web3-shared-base'
import { Typography, type TypographyProps } from '@mui/material'
import { memo } from 'react'
import { makeStyles } from '@masknet/theme'
import type { ChainId, SchemaType } from '@masknet/web3-shared-evm'
import { AccountLabel } from '../components/common.js'
import { formatAmount, type ChainId, type SchemaType } from '@masknet/web3-shared-evm'
import { AccountLabel, Label } from '../components/common.js'
import { useFeedOwner } from '../contexts/FeedOwnerContext.js'

const useStyles = makeStyles<{ size: number }>()((theme) => ({
summary: {
display: 'flex',
flexWrap: 'wrap',
gap: theme.spacing(0.5),
alignItems: 'center',
},
Expand All @@ -19,19 +21,39 @@ interface Props extends TypographyProps {
}
export const FeedSummary = memo<Props>(function FeedSummary({ transaction, ...rest }) {
const { classes, cx } = useStyles({ size: 20 })
const owner = useFeedOwner()

const otherAddress = isSameAddress(owner.address, transaction.from) ? transaction.to : transaction.from

return (
<Typography {...rest} className={cx(classes.summary, rest.className)}>
<Select
value={transaction.type}
other={
<Trans>
<AccountLabel address={transaction.from} />
transferred to
<AccountLabel address={transaction.to} />
</Trans>
}
/>
</Typography>
<>
{transaction.assets.map((asset, index) => {
return (
<Typography key={index} component="div" {...rest} className={cx(classes.summary, rest.className)}>
<Select
value={asset.direction}
_send={
<Trans>
<AccountLabel address={owner.address} />
{transaction.cateName}
<AccountLabel address={otherAddress} />
</Trans>
}
other={
<Trans>
<AccountLabel address={owner.address} />
{transaction.cateName}{' '}
<Label>
{formatAmount(asset.amount)} {asset.name}
</Label>{' '}
from
<AccountLabel address={otherAddress} />
</Trans>
}
/>
</Typography>
)
})}
</>
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const useStyles = makeStyles()((theme) => ({
fontWeight: 400,
color: theme.palette.maskColor.third,
},
body: {},
}))

export interface FinanceFeedProps extends HTMLProps<HTMLDivElement> {
Expand All @@ -55,10 +54,6 @@ export const FinanceFeed = memo<FinanceFeedProps>(function FinanceFeed({ transac
: null}
</div>
<FeedSummary transaction={transaction} mt={0.5} />
<div className={classes.body}>
{transaction.type}
{transaction.cateName}
</div>
</article>
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function useFinanceFeeds({ address }: Options) {
: skipToken,
getNextPageParam: (lp) => lp.nextIndicator,
select(data) {
return data.pages.flatMap((page) => page.data)
return data.pages.flatMap((page) => page.data).filter((x) => !x.isScam)
},
})
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Select, Trans } from '@lingui/macro'
import { Image } from '@masknet/shared'
import { makeStyles } from '@masknet/theme'
import type { Social } from '@masknet/web3-providers/types'
import { Typography, type TypographyProps } from '@mui/material'
import { memo } from 'react'
import { Label } from '../components/common.js'
import { Image } from '@masknet/shared'
import { makeStyles } from '@masknet/theme'

const useStyles = makeStyles<{ size: number }>()((theme, { size }) => ({
summary: {
Expand Down Expand Up @@ -52,7 +52,7 @@ export const FeedSummary = memo<Props>(function FeedSummary({ post, ...rest }) {
const pfp = post.author.pfp

return (
<Typography {...rest} className={cx(classes.summary, rest.className)}>
<Typography component="div" {...rest} className={cx(classes.summary, rest.className)}>
<Select
value={post.type}
_Post={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function AccountLabel({
: <Label className={className} {...rest} />
return (
<>
<UserAvatar identity={reversed || address} style={{ marginRight: 6 }} />
<UserAvatar identity={reversed || address} />
{label}
</>
)
Expand Down
8 changes: 8 additions & 0 deletions packages/plugins/RSS3/src/SiteAdaptor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const FinanceTabConfig: Plugin.SiteAdaptor.ProfileTab = {
return <FinanceFeeds address={socialAccount?.address} />
},
},
Utils: {
shouldDisplay,
},
}

const LegacyFinanceTabConfig = createProfileTabConfig({
Expand Down Expand Up @@ -197,6 +200,11 @@ const SocialTabConfigInSearchResult: Plugin.SiteAdaptor.SearchResultTab = {
)
},
},
Utils: {
shouldDisplay(result) {
return [SearchResultType.Domain, SearchResultType.EOA].includes(result.type)
},
},
}

const site: Plugin.SiteAdaptor.Definition = {
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-providers/src/DeBank/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function toTxAsset(
schema,
name: token.name || token.collection?.name || fallbackName,
symbol: token.optimized_symbol || token.collection?.name || fallbackName,
address: token.decimals ? token_id : token.contract_id,
address: token.decimals ? token.contract_id : ZERO_ADDRESS,
decimals: token.decimals || 1,
direction,
amount: amount?.toString(),
Expand Down
1 change: 1 addition & 0 deletions packages/web3-providers/src/DeBank/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface ProjectItem {
export interface TokenItem {
decimals: number
display_symbol?: string
/** could be native token id, for example arb */
id: string
is_core: boolean
is_swap_common?: boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-shared/base/src/specs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ type TransactionAsset<ChainId, SchemaType> = Token<ChainId, SchemaType> & {
name: string
symbol: string
amount: string
direction: string
direction: LiteralUnion<'send' | 'receive'>
}

export interface Transaction<ChainId, SchemaType> {
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-shared/evm/src/helpers/isValidDomain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import punycode from 'punycode'

const NAME_SERVICE_RE = /\.(eth|bnb|arb|lens)$/
const NAME_SERVICE_RE = /\.(eth|bnb|arb|lens|zeta|mode|taiko|mint)$/
const DOMAIN_RE = /^(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+[a-z0-9][-a-z0-9]*[a-z0-9]$/u
const ENS_SUBDOMAIN_RE = /\[.{64}?\]\.(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+[a-z0-9][-a-z0-9]*[a-z0-9]$/u

Expand Down
10 changes: 6 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 26a24ce

Please sign in to comment.