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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { memo, useCallback, useMemo } from 'react'
import { useNavigate } from 'react-router-dom'
import { makeStyles } from '@masknet/theme'
import { useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { openWindow, useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { useAccount } from '@masknet/web3-shared-evm'
import { PluginMessages, Services } from '../../../API'
import { PersonaContext } from '../../../pages/Personas/hooks/usePersonaContext'
Expand Down Expand Up @@ -64,7 +64,7 @@ export const FeaturePromotions = memo(() => {
connectPersona(currentPersona.identifier, EnhanceableSite.Twitter)
}

const openMaskNetwork = () => window.open('https://twitter.com/realMaskNetwork')
const openMaskNetwork = () => openWindow('https://twitter.com/realMaskNetwork')

return (
<div className={classes.container}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useDashboardI18N } from '../../../../locales'
import { Button } from '@mui/material'
import { MaskNotSquareIcon } from '@masknet/icons'
import urlcat from 'urlcat'
import { openWindow } from '@masknet/shared-base-ui'

const Content = styled('div')`
width: 100%;
Expand Down Expand Up @@ -98,9 +99,7 @@ const Welcome = memo(() => {
link?.addEventListener('click', handleLinkClick)
}

const handleLinkClick = () => {
window.open(MASK_PRIVACY_POLICY)
}
const handleLinkClick = () => openWindow(MASK_PRIVACY_POLICY)

useEffect(
() => () => {
Expand Down
7 changes: 2 additions & 5 deletions packages/dashboard/src/pages/Labs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useDashboardI18N } from '../../locales'
import MarketTrendSettingDialog from './components/MarketTrendSettingDialog'
import { useAccount } from '@masknet/web3-shared-evm'
import { Messages, Services, PluginMessages } from '../../API'
import { useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { openWindow, useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { TUTORIAL_URLS_EN } from './constants'
import { ContentContainer } from '../../components/ContentContainer'
import { WalletStateBar } from '../Wallets/components/WalletStateBar'
Expand Down Expand Up @@ -230,10 +230,7 @@ export default function Plugins() {
}

function onTutorial(id: string) {
const url = TUTORIAL_URLS_EN[id]
if (url) {
window.open(url, '_blank', 'noopener noreferrer')
}
openWindow(TUTORIAL_URLS_EN[id])
}

function onTutorialDialogClose(checked: boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EmptyIcon } from '@masknet/icons'
import { useDashboardI18N } from '../../../../locales'
import urlcat from 'urlcat'
import { MaskColorVar } from '@masknet/theme'
import { openWindow } from '@masknet/shared-base-ui'

interface PlaceholderProps {
network: string
Expand All @@ -13,7 +14,7 @@ export const Placeholder = memo<PlaceholderProps>(({ network }) => {
const t = useDashboardI18N()
const url = urlcat('https://www.:network', { network: network })

const handleClick = () => window.open(url)
const handleClick = () => openWindow(url)

return (
<Stack height="100%" alignItems="center" justifyContent="center" mt={-3.5}>
Expand Down
5 changes: 2 additions & 3 deletions packages/dashboard/src/pages/Welcome/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { styled } from '@mui/material/styles'
import { memo, MutableRefObject, useEffect, useMemo, useRef } from 'react'
import { useDashboardI18N } from '../../locales'
import links from '../../components/FooterLine/links.json'
import { openWindow } from '@masknet/shared-base-ui'

const Content = styled('div')(({ theme }) => ({
padding: `${theme.spacing(1)} ${theme.spacing(4)}`,
Expand Down Expand Up @@ -71,9 +72,7 @@ export default function Welcome() {
link?.addEventListener('click', handleLinkClick)
}

const handleLinkClick = () => {
window.open(links.MASK_PRIVACY_POLICY)
}
const handleLinkClick = () => openWindow(links.MASK_PRIVACY_POLICY)

return (
<WelcomeUI
Expand Down
8 changes: 4 additions & 4 deletions packages/mask/src/components/shared/ApplicationBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames'
import { Typography } from '@mui/material'
import { makeStyles } from '@masknet/theme'
import { ChainId, useChainId, useAccount, useWallet } from '@masknet/web3-shared-evm'
import { useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { openWindow, useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { CrossIsolationMessages } from '@masknet/shared-base'
import { useControlledDialog } from '../../utils/hooks/useControlledDialog'
import { RedPacketPluginID } from '../../plugins/RedPacket/constants'
Expand Down Expand Up @@ -269,15 +269,15 @@ export function ApplicationBoard({ secondEntries, secondEntryChainTabs }: MaskAp
createEntry(
'Mask Bridge',
new URL('./assets/bridge.png', import.meta.url).toString(),
() => window.open('https://bridge.mask.io/#/', '_blank', 'noopener noreferrer'),
() => openWindow('https://bridge.mask.io'),
undefined,
isNotEvm,
false,
),
createEntry(
'MaskBox',
new URL('./assets/mask_box.png', import.meta.url).toString(),
() => window.open('https://box.mask.io/#/', '_blank', 'noopener noreferrer'),
() => openWindow('https://box.mask.io'),
undefined,
isNotEvm,
false,
Expand Down Expand Up @@ -314,7 +314,7 @@ export function ApplicationBoard({ secondEntries, secondEntryChainTabs }: MaskAp
createEntry(
'MaskBox',
new URL('./assets/mask_box.png', import.meta.url).toString(),
() => window.open('https://box.mask.io/#/', '_blank', 'noopener noreferrer'),
() => openWindow('https://box.mask.io'),
undefined,
false,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Services from '../../../../service'
import { compact, intersectionWith } from 'lodash-unified'
import urlcat from 'urlcat'
import { ActivityList } from '../components/ActivityList'
import { openWindow } from '@masknet/shared-base-ui'

const useStyles = makeStyles()({
content: {
Expand Down Expand Up @@ -93,30 +94,25 @@ const TokenDetail = memo(() => {
open: 'Transak',
code: currentToken?.token.symbol ?? currentToken?.token.name,
})
window.open(browser.runtime.getURL(url), 'BUY_DIALOG', 'noopener noreferrer')
openWindow(browser.runtime.getURL(url), 'BUY_DIALOG')
}
}, [wallet?.address, isActiveSocialNetwork, currentToken])

const openSwapDialog = useCallback(async () => {
window.open(
browser.runtime.getURL(
urlcat(
'popups.html#/',
PopupRoutes.Swap,
!isSameAddress(nativeToken?.address, currentToken?.token.address)
? {
id: currentToken?.token.address,
name: currentToken?.token.name,
symbol: currentToken?.token.symbol,
contract_address: currentToken?.token.address,
decimals: currentToken?.token.decimals,
}
: {},
),
),
'SWAP_DIALOG',
'noopener noreferrer',
const url = urlcat(
'popups.html#/',
PopupRoutes.Swap,
!isSameAddress(nativeToken?.address, currentToken?.token.address)
? {
id: currentToken?.token.address,
name: currentToken?.token.name,
symbol: currentToken?.token.symbol,
contract_address: currentToken?.token.address,
decimals: currentToken?.token.decimals,
}
: {},
)
openWindow(browser.runtime.getURL(url), 'SWAP_DIALOG')
}, [currentToken, nativeToken])

if (!currentToken) return null
Expand Down
3 changes: 2 additions & 1 deletion packages/mask/src/plugins/Avatar/SNSAdaptor/NFTBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { openWindow } from '@masknet/shared-base-ui'
import { makeStyles, useStylesExtends } from '@masknet/theme'
import { resolveOpenSeaLink } from '@masknet/web3-shared-evm'
import Link from '@mui/material/Link'
Expand Down Expand Up @@ -42,7 +43,7 @@ export function NFTBadge(props: NFTBadgeProps) {
className={classes.root}
onClick={(e) => {
e.preventDefault()
window.open(resolveOpenSeaLink(avatar.address, avatar.tokenId), '_blank')
openWindow(resolveOpenSeaLink(avatar.address, avatar.tokenId))
}}>
<Link href={resolveOpenSeaLink(avatar.address, avatar.tokenId)} target="_blank" rel="noopener noreferrer">
<NFTAvatarRing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, cloneElement, isValidElement } from 'react'
import { unreachable } from '@dimensiondev/kit'
import type { Web3Plugin } from '@masknet/plugin-infra'
import { useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { openWindow, useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { isDashboardPage } from '@masknet/shared-base'
import {
getChainIdFromNetworkType,
Expand Down Expand Up @@ -47,7 +47,7 @@ export function ProviderIconClickBait({

if (!isProviderAvailable) {
const downloadLink = resolveProviderDownloadLink(providerType)
if (downloadLink) window.open(downloadLink, '_blank', 'noopener noreferrer')
openWindow(downloadLink)
return
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/mask/src/plugins/ITO/SNSAdaptor/ClaimAllDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { flatten, uniq } from 'lodash-unified'
import formatDateTime from 'date-fns/format'
import { SnackbarProvider, makeStyles } from '@masknet/theme'
import { FormattedBalance } from '@masknet/shared'
import { useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { openWindow, useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { DialogContent, CircularProgress, Typography, List, ListItem, useTheme } from '@mui/material'
import {
formatBalance,
Expand Down Expand Up @@ -301,7 +301,7 @@ export function ClaimAllDialog(props: ClaimAllDialogProps) {
if (claimState.type === TransactionStateType.HASH) {
const { hash } = claimState
setTimeout(() => {
window.open(resolveTransactionLinkOnExplorer(chainId, hash), '_blank', 'noopener noreferrer')
openWindow(resolveTransactionLinkOnExplorer(chainId, hash))
}, 2000)
return
}
Expand Down
4 changes: 2 additions & 2 deletions packages/mask/src/plugins/ITO/SNSAdaptor/SwapDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { v4 as uuid } from 'uuid'
import { CircularProgress, Slider, Typography } from '@mui/material'
import { makeStyles, useStylesExtends } from '@masknet/theme'
import { useI18N } from '../../../utils'
import { useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { openWindow, useRemoteControlledDialog } from '@masknet/shared-base-ui'
import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton'
import {
ChainId,
Expand Down Expand Up @@ -239,7 +239,7 @@ export function SwapDialog(props: SwapDialogProps) {
if (swapState.type === TransactionStateType.HASH) {
const { hash } = swapState
setTimeout(() => {
window.open(resolveTransactionLinkOnExplorer(chainId, hash), '_blank', 'noopener noreferrer')
openWindow(resolveTransactionLinkOnExplorer(chainId, hash))
}, 2000)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SuccessIcon } from '@masknet/icons'
import { PluginId, useActivatedPlugin, usePluginIDContext } from '@masknet/plugin-infra'
import { NFTCardStyledAssetPlayer } from '@masknet/shared'
import { EMPTY_LIST } from '@masknet/shared-base'
import { openWindow } from '@masknet/shared-base-ui'
import { makeStyles } from '@masknet/theme'
import { TransactionStateType, useChainId, useERC721TokenDetailed } from '@masknet/web3-shared-evm'
import { DialogContent, Typography } from '@mui/material'
Expand Down Expand Up @@ -140,7 +141,7 @@ export function TipDialog({ open = false, onClose }: TipDialogProps) {
}, [sendState.type])

const handleConfirm = useCallback(() => {
window.open(shareLink)
openWindow(shareLink)
openConfirmModal(false)
onClose?.()
}, [shareLink, onClose])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { activatedSocialNetworkUI } from '../../../social-network'
import { isTwitter } from '../../../social-network-adaptor/twitter.com/base'
import { isFacebook } from '../../../social-network-adaptor/facebook.com/base'
import { NFTCardStyledAssetPlayer } from '@masknet/shared'
import { openWindow } from '@masknet/shared-base-ui'

const useStyles = makeStyles()((theme) => ({
root: {
Expand Down Expand Up @@ -261,11 +262,7 @@ export function RedPacketNft({ payload }: RedPacketNftProps) {
const isClaiming = claimState.type === TransactionStateType.WAIT_FOR_CONFIRMING

const openAddressLinkOnExplorer = useCallback(() => {
window.open(
resolveAddressLinkOnExplorer(payload.chainId, payload.contractAddress),
'_blank',
'noopener noreferrer',
)
openWindow(resolveAddressLinkOnExplorer(payload.chainId, payload.contractAddress))
}, [payload])

const [sourceType, setSourceType] = useState('')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useI18N } from '../../../../utils'
import type { Coin, Currency, Stat } from '../../types'
import { useDimension, Dimension } from '../../../hooks/useDimension'
import { usePriceLineChart } from '../../../hooks/usePriceLineChart'
import { openWindow } from '@masknet/shared-base-ui'

const DEFAULT_DIMENSION: Dimension = {
top: 32,
Expand Down Expand Up @@ -110,9 +111,7 @@ export function PriceChart(props: PriceChartProps) {
viewBox={`0 0 ${dimension.width} ${dimension.height}`}
preserveAspectRatio="xMidYMid meet"
onClick={() => {
props.stats.length &&
props.coin?.platform_url &&
window.open(props.coin.platform_url, '_blank', 'noopener noreferrer')
props.stats.length && openWindow(props.coin?.platform_url)
}}
/>
</>
Expand Down
14 changes: 8 additions & 6 deletions packages/mask/src/social-network-adaptor/facebook.com/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { getPostUrlAtFacebook, isValidFacebookUsername } from './utils/parse-use
import { PostIdentifier, ProfileIdentifier } from '@masknet/shared-base'
import { deconstructPayload } from '../../utils'
import { createSNSAdaptorSpecializedPostContext } from '../../social-network/utils/create-post-context'
import { openWindow } from '@masknet/shared-base-ui'
import urlcat from 'urlcat'

const getPostURL = (post: PostIdentifier): URL | null => {
if (post.identifier instanceof ProfileIdentifier)
Expand All @@ -19,14 +21,14 @@ export const facebookShared: SocialNetwork.Shared & SocialNetwork.Base = {
textPayloadPostProcessor: undefined,
getPostURL,
share(message) {
const url = this.getShareLinkURL!(message)
window.open(url, '_blank', 'noopener noreferrer')
openWindow(this.getShareLinkURL?.(message))
},
getShareLinkURL(message) {
const url = new URL('https://www.facebook.com/sharer/sharer.php')
url.searchParams.set('quote', message)
url.searchParams.set('u', 'mask.io')
return url
const url = urlcat('https://www.facebook.com/sharer/sharer.php', {
quote: message,
u: 'mask.io',
})
return new URL(url)
},
createPostContext: createSNSAdaptorSpecializedPostContext({
payloadParser: deconstructPayload,
Expand Down
10 changes: 7 additions & 3 deletions packages/mask/src/social-network-adaptor/minds.com/shared.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { PostIdentifier } from '@masknet/shared-base'
import { openWindow } from '@masknet/shared-base-ui'
import urlcat from 'urlcat'
import type { SocialNetwork } from '../../social-network/types'
import { createSNSAdaptorSpecializedPostContext } from '../../social-network/utils/create-post-context'
import { deconstructPayload } from '../../utils'
Expand All @@ -17,11 +19,13 @@ export const mindsShared: SocialNetwork.Shared & SocialNetwork.Base = {
textPayloadPostProcessor: undefined,
getPostURL,
share(message) {
const url = this.getShareLinkURL!(message)
window.open(url, '_blank', 'noopener noreferrer')
openWindow(this.getShareLinkURL?.(message))
},
getShareLinkURL(message) {
return new URL(`https://www.minds.com/newsfeed/subscriptions?intentUrl=${encodeURIComponent(message)}`)
const url = urlcat('https://www.minds.com/newsfeed/subscriptions', {
intentUrl: message,
})
return new URL(url)
},
createPostContext: createSNSAdaptorSpecializedPostContext({
payloadParser: deconstructPayload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useAsync, useLocation, useUpdateEffect, useWindowSize } from 'react-use
import { rainbowBorderKeyFrames } from '../../../../plugins/Avatar/SNSAdaptor/RainbowBox'
import { trim } from 'lodash-unified'
import { RSS3_KEY_SNS } from '../../../../plugins/Avatar/constants'
import { openWindow } from '@masknet/shared-base-ui'

export function injectNFTAvatarInTwitter(signal: AbortSignal) {
const watcher = new MutationObserverWatcher(searchTwitterAvatarSelector())
Expand Down Expand Up @@ -194,7 +195,7 @@ function NFTAvatarInTwitter() {
if (!avatar || !linkParentDom || !showAvatar) return

const handler = () => {
window.open(resolveOpenSeaLink(avatar.address, avatar.tokenId), '_blank')
openWindow(resolveOpenSeaLink(avatar.address, avatar.tokenId))
}

linkParentDom.addEventListener('click', handler)
Expand Down
Loading