Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"unicorn/no-new-buffer": "error",
"unicorn/no-thenable": "error",
"unicorn/no-useless-promise-resolve-reject": "error",
"unicorn/no-array-reduce": ["error", { "allowSimpleOperations": false }],
"unicorn/prefer-add-event-listener": "error",
"unicorn/prefer-date-now": "error",
"unicorn/prefer-dom-node-dataset": "error",
Expand Down
3 changes: 2 additions & 1 deletion packages/backup-format/src/utils/backupPreview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { NormalizedBackup } from '@masknet/backup-format'
import { sumBy } from 'lodash-unified'

export interface BackupPreview {
personas: number
Expand All @@ -20,7 +21,7 @@ export function getBackupPreviewInfo(json: NormalizedBackup.Data): BackupPreview

return {
personas: json.personas.size,
accounts: [...json.personas.values()].reduce((a, b) => a + b.linkedProfiles.size, 0),
accounts: sumBy([...json.personas.values()], (persona) => persona.linkedProfiles.size),
posts: json.posts.size,
contacts: json.profiles.size,
relations: json.relations.length,
Expand Down
4 changes: 3 additions & 1 deletion packages/backup-format/src/utils/hex2buffer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { sum } from 'lodash-unified'

/** @internal */
export function hex2buffer(hexString: string, padded?: boolean) {
if (hexString.length % 2) {
Expand All @@ -21,7 +23,7 @@ export function hex2buffer(hexString: string, padded?: boolean) {

/** @internal */
function concat(...buf: (Uint8Array | number[])[]) {
const res = new Uint8Array(buf.map((item) => item.length).reduce((prev, cur) => prev + cur))
const res = new Uint8Array(sum(buf.map((item) => item.length)))
let offset = 0
buf.forEach((item) => {
for (let i = 0; i < item.length; i += 1) {
Expand Down
1 change: 1 addition & 0 deletions packages/gun-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EventIterator } from 'event-iterator'
import { getGunInstance, OnCloseEvent } from './instance'

function getGunNodeFromPath(path: string[]) {
// eslint-disable-next-line unicorn/no-array-reduce
const resultNode = path.reduce((gun, path) => gun.get(path as never), getGunInstance())
return resultNode
}
Expand Down
6 changes: 3 additions & 3 deletions packages/mask/background/services/identity/profile/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export async function resolveUnknownLegacyIdentity(identifier: ProfileIdentifier
const unknown = ProfileIdentifier.of(identifier.network, '$unknown').unwrap()
const self = ProfileIdentifier.of(identifier.network, '$self').unwrap()

const r = await queryProfilesDB({ identifiers: [unknown, self] })
if (!r.length) return
const records = await queryProfilesDB({ identifiers: [unknown, self] })
if (!records.length) return
const final = {
...r.reduce((p, c) => ({ ...p, ...c })),
...Object.assign({}, ...records),
identifier,
}
try {
Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/UIRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { MaskThemeProvider } from '@masknet/theme'

const identity = (jsx: React.ReactNode) => jsx as JSX.Element
function compose(init: React.ReactNode, ...f: ((children: React.ReactNode) => JSX.Element)[]) {
// eslint-disable-next-line unicorn/no-array-reduce
return f.reduceRight((prev, curr) => curr(prev), <>{init}</>)
}

Expand Down
44 changes: 18 additions & 26 deletions packages/mask/src/components/shared/ApplicationBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Typography } from '@mui/material'
import { useChainId } from '@masknet/web3-shared-evm'
import { useActivatedPluginsSNSAdaptor } from '@masknet/plugin-infra/content-script'
import { useCurrentWeb3NetworkPluginID, useAccount, NetworkPluginID } from '@masknet/plugin-infra/web3'
import { EMPTY_LIST, CrossIsolationMessages, formatPersonaPublicKey } from '@masknet/shared-base'
import { CrossIsolationMessages, formatPersonaPublicKey } from '@masknet/shared-base'
import { getCurrentSNSNetwork } from '../../social-network-adaptor/utils'
import { activatedSocialNetworkUI } from '../../social-network'
import { useI18N } from '../../utils'
Expand Down Expand Up @@ -122,33 +122,25 @@ function ApplicationBoardContent(props: Props) {
const applicationList = useMemo(
() =>
snsAdaptorPlugins
.reduce<Application[]>((acc, cur) => {
if (!cur.ApplicationEntries) return acc
const currentWeb3NetworkSupportedChainIds = cur.enableRequirement.web3?.[currentWeb3Network]
.flatMap(({ ID, ApplicationEntries, enableRequirement }) => {
if (!ApplicationEntries) return []
const currentWeb3NetworkSupportedChainIds = enableRequirement.web3?.[currentWeb3Network]
const isWalletConnectedRequired = currentWeb3NetworkSupportedChainIds !== undefined
const currentSNSIsSupportedNetwork = cur.enableRequirement.networks.networks[currentSNSNetwork]
const currentSNSIsSupportedNetwork = enableRequirement.networks.networks[currentSNSNetwork]
const isSNSEnabled = currentSNSIsSupportedNetwork === undefined || currentSNSIsSupportedNetwork

return acc.concat(
cur.ApplicationEntries.map((x) => {
return {
entry: x,
enabled: isSNSEnabled,
pluginId: cur.ID,
isWalletConnectedRequired: !account && isWalletConnectedRequired,
isWalletConnectedEVMRequired: Boolean(
account &&
currentWeb3Network !== NetworkPluginID.PLUGIN_EVM &&
isWalletConnectedRequired,
),
}
}) ?? EMPTY_LIST,
)
}, EMPTY_LIST)
.sort(
(a, b) =>
(a.entry.appBoardSortingDefaultPriority ?? 0) - (b.entry.appBoardSortingDefaultPriority ?? 0),
)
return ApplicationEntries.map((entry) => ({
entry,
enabled: isSNSEnabled,
pluginId: ID,
isWalletConnectedRequired: !account && isWalletConnectedRequired,
isWalletConnectedEVMRequired: Boolean(
account && currentWeb3Network !== NetworkPluginID.PLUGIN_EVM && isWalletConnectedRequired,
),
}))
})
.sort((a, b) => {
return (a.entry.appBoardSortingDefaultPriority ?? 0) - (b.entry.appBoardSortingDefaultPriority ?? 0)
})
.filter((x) => Boolean(x.entry.RenderEntryComponent)),
[snsAdaptorPlugins, currentWeb3Network, chainId, account],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useActivatedPluginsSNSAdaptor, Plugin } from '@masknet/plugin-infra/con
import { useMemo, useState, useCallback } from 'react'
import { List, ListItem, Typography } from '@mui/material'
import { makeStyles, getMaskColor } from '@masknet/theme'
import { EMPTY_LIST } from '@masknet/shared-base'
import { useI18N } from '../../utils'
import { PersistentStorages } from '../../../shared'

Expand Down Expand Up @@ -81,28 +80,17 @@ export function ApplicationSettingPluginList() {
const { classes } = useStyles()
const { t } = useI18N()
const snsAdaptorPlugins = useActivatedPluginsSNSAdaptor('any')
const applicationList = useMemo(
() =>
snsAdaptorPlugins
.reduce<Application[]>((acc, cur) => {
if (!cur.ApplicationEntries) return acc
return acc.concat(
cur.ApplicationEntries.filter(
(x) => x.appBoardSortingDefaultPriority && !x.recommendFeature,
).map((x) => {
return {
entry: x,
pluginId: cur.ID,
}
}) ?? EMPTY_LIST,
)
}, EMPTY_LIST)
.sort(
(a, b) =>
(a.entry.appBoardSortingDefaultPriority ?? 0) - (b.entry.appBoardSortingDefaultPriority ?? 0),
),
[snsAdaptorPlugins],
)
const applicationList = useMemo(() => {
return snsAdaptorPlugins
.flatMap(({ ID, ApplicationEntries: entries }) =>
(entries ?? [])
.filter((entry) => entry.appBoardSortingDefaultPriority && !entry.recommendFeature)
.map((entry) => ({ entry, pluginId: ID })),
)
.sort((a, b) => {
return (a.entry.appBoardSortingDefaultPriority ?? 0) - (b.entry.appBoardSortingDefaultPriority ?? 0)
})
}, [snsAdaptorPlugins])
const [listedAppList, setListedAppList] = useState(applicationList.filter((x) => !getUnlistedApp(x)))
const [unlistedAppList, setUnListedAppList] = useState(applicationList.filter((x) => getUnlistedApp(x)))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { List, ListItem, ListItemAvatar, Avatar, Typography, Box } from '@mui/material'
import { openWindow } from '@masknet/shared-base-ui'
import { TutorialIcon } from '@masknet/icons'
import { useActivatedPluginsSNSAdaptor, Plugin, PluginI18NFieldRender } from '@masknet/plugin-infra/content-script'
import { useActivatedPluginsSNSAdaptor, PluginI18NFieldRender } from '@masknet/plugin-infra/content-script'
import { SettingSwitch } from '@masknet/shared'
import { makeStyles, MaskColorVar } from '@masknet/theme'
import { Services } from '../../extension/service'
Expand Down Expand Up @@ -72,17 +72,9 @@ export function ApplicationSettingPluginSwitch(props: Props) {
return (
<List>
{snsAdaptorPlugins
.reduce<{ entry: Plugin.SNSAdaptor.ApplicationEntry; pluginId: string }[]>((acc, cur) => {
if (!cur.ApplicationEntries) return acc
return acc.concat(
cur.ApplicationEntries.map((x) => {
return {
entry: x,
pluginId: cur.ID,
}
}) ?? [],
)
}, [])
.flatMap(({ ID, ApplicationEntries: entries }) =>
(entries ?? []).map((entry) => ({ entry, pluginId: ID })),
)
.filter((x) => x.entry.category === 'dapp')
.sort((a, b) => (a.entry.marketListSortingPriority ?? 0) - (b.entry.marketListSortingPriority ?? 0))
.map((x) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import NoNftCard from './NoNftCard'
import { FindTrumanContext } from '../context'
import { BorderLinearProgress } from './ResultCard'
import { ActionButtonPromise } from '../../../extension/options-page/DashboardComponents/ActionButton'
import { sumBy } from 'lodash-unified'

const useOptionsStyles = makeStyles()((theme) => {
return {
Expand Down Expand Up @@ -92,11 +93,7 @@ export default function OptionsCard(props: OptionsViewProps) {

const renderOptions = (userStatus: UserPollStatus) => {
const showCount = !!userStatus.count
const total = userStatus.count
? userStatus.count.reduce((total, e) => {
return { choice: -1, value: total.value + e.value }
}).value
: 0
const total = sumBy(userStatus.count ?? [], (status) => status.value)
return userStatus.options.map((option, index) => {
const count = userStatus.count ? userStatus.count.find((e) => e.choice === index)?.value || 0 : 0
const percent = (total > 0 ? (count * 100) / total : 0).toFixed(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { PostType } from '../types'
import { useContext, useState } from 'react'
import { FindTrumanContext } from '../context'
import { makeStyles } from '@masknet/theme'
import { sumBy } from 'lodash-unified'

export const BorderLinearProgress: any = styled(LinearProgress)(({ theme }) => ({
height: 10,
Expand Down Expand Up @@ -49,12 +50,7 @@ export default function ResultCard(props: ResultViewProps) {

const { t } = useContext(FindTrumanContext)

const total =
result?.count && result.count.length > 0
? result.count.reduce((total, e) => {
return { choice: -1, value: total.value + e.value }
}).value
: 1
const total = result?.count ? sumBy(result.count, (status) => status.value) : 1

const answer = result
? type === PostType.PuzzleResult
Expand Down
7 changes: 1 addition & 6 deletions packages/mask/src/plugins/ITO/SNSAdaptor/NftAirdropCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,7 @@ export function NftAirdropCard(props: NftAirdropCardProps) {
const currentChainId = useChainId()
const { classes } = useStyles()

const claimableCount = campaignInfos
? campaignInfos.reduce((acc, cur) => {
if (cur.claimableInfo.claimable) return acc + 1
return acc
}, 0)
: 0
const claimableCount = campaignInfos?.filter((info) => info.claimableInfo.claimable).length ?? 0

useEffect(() => {
setCheckAddress('')
Expand Down
Loading