Skip to content

Commit 809a4de

Browse files
committed
chore: fix crash when no PRIVY_APP_ID is set
1 parent 3b99bd6 commit 809a4de

File tree

11 files changed

+556
-519
lines changed

11 files changed

+556
-519
lines changed

packages/mask/.webpack/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ export async function createConfiguration(
236236
NEXT_PUBLIC_FIREFLY_API_URL: process.env.NEXT_PUBLIC_FIREFLY_API_URL || '',
237237
SOLANA_DEFAULT_RPC_URL: process.env.SOLANA_DEFAULT_RPC_URL || '',
238238
MASK_ENABLE_EXCHANGE: process.env.MASK_ENABLE_EXCHANGE || '',
239-
GOOGLE_CLIENT_ID: JSON.stringify(process.env.GOOGLE_CLIENT_ID) || '',
240-
LOAD_KEY: process.env.LOAD_KEY || '',
241239
FIREFLY_X_CLIENT_ID: process.env.FIREFLY_X_CLIENT_ID || '',
242240
FIREFLY_X_CLIENT_SECRET: process.env.FIREFLY_X_CLIENT_SECRET || '',
243241
PRIVY_APP_ID: process.env.PRIVY_APP_ID || '',

packages/mask/popups/components/WalletItem/index.tsx

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Trans } from '@lingui/react/macro'
22
import { FormattedAddress } from '@masknet/shared'
3-
import { ImportSource, NetworkPluginID, PersistentStorages, type Wallet } from '@masknet/shared-base'
3+
import { ImportSource, NetworkPluginID, PersistentStorages, PrivyEnvGuard, type Wallet } from '@masknet/shared-base'
44
import { makeStyles } from '@masknet/theme'
55
import { useReverseAddress } from '@masknet/web3-hooks-base'
66
import { isSameAddress } from '@masknet/web3-shared-base'
@@ -93,57 +93,56 @@ interface WalletItemProps extends Omit<ListItemProps, 'onSelect'> {
9393
hiddenTag?: boolean
9494
}
9595

96-
export const WalletItem = memo<WalletItemProps>(function WalletItem({
97-
wallet,
98-
onSelect,
99-
isSelected,
100-
className,
101-
hiddenTag,
102-
...rest
103-
}) {
104-
const { classes, cx } = useStyles()
105-
const { data: domain } = useReverseAddress(NetworkPluginID.PLUGIN_EVM, wallet.address)
96+
export const WalletItem = memo<WalletItemProps>(
97+
PrivyEnvGuard(function WalletItem({ wallet, onSelect, isSelected, className, hiddenTag, ...rest }) {
98+
const { classes, cx } = useStyles()
99+
const { data: domain } = useReverseAddress(NetworkPluginID.PLUGIN_EVM, wallet.address)
106100

107-
const handleSelect = useCallback(() => {
108-
onSelect(wallet)
109-
}, [wallet])
101+
const handleSelect = useCallback(() => {
102+
onSelect(wallet)
103+
}, [wallet])
110104

111-
const extraName = domain && domain !== wallet.name ? ` (${formatDomainName(domain)})` : ''
112-
const { wallets: fireflyWallets } = useWallets()
113-
const isFireflyWallet = useMemo(
114-
() => fireflyWallets.some((w) => isSameAddress(w.address, wallet.address)),
115-
[fireflyWallets, wallet.address],
116-
)
117-
const fireflyAccount = useSubscription(PersistentStorages.Settings.storage.firefly_account.subscription)
105+
const extraName = domain && domain !== wallet.name ? ` (${formatDomainName(domain)})` : ''
106+
const { wallets: fireflyWallets } = useWallets()
107+
const isFireflyWallet = useMemo(
108+
() => fireflyWallets.some((w) => isSameAddress(w.address, wallet.address)),
109+
[fireflyWallets, wallet.address],
110+
)
111+
const fireflyAccount = useSubscription(PersistentStorages.Settings.storage.firefly_account.subscription)
118112

119-
const walletName = wallet.name || (isFireflyWallet ? fireflyAccount.displayName : `${wallet.name}${extraName}`)
120-
return (
121-
<ListItem
122-
className={cx(classes.item, className)}
123-
onClick={handleSelect}
124-
secondaryAction={<Radio sx={{ marginLeft: 0.75 }} checked={isSelected} />}
125-
{...rest}>
126-
<WalletAvatar address={wallet.address} size={24} />
127-
<Box className={classes.text}>
128-
<Box width={180} overflow="auto">
129-
<Typography className={classes.mainLine} component="div">
130-
<Typography className={classes.name}>{walletName}</Typography>
131-
{wallet.source === ImportSource.LocalGenerated || hiddenTag ? null : (
132-
<Typography component="span" className={classes.badge}>
133-
<Trans>Imported</Trans>
134-
</Typography>
135-
)}
136-
</Typography>
137-
<Typography className={classes.address}>
138-
<Tooltip title={wallet.address} placement="right" classes={{ tooltip: classes.tooltip }}>
139-
<span>
140-
<FormattedAddress address={wallet.address} size={4} formatter={formatEthereumAddress} />
141-
</span>
142-
</Tooltip>
143-
</Typography>
113+
const walletName = wallet.name || (isFireflyWallet ? fireflyAccount.displayName : `${wallet.name}${extraName}`)
114+
return (
115+
<ListItem
116+
className={cx(classes.item, className)}
117+
onClick={handleSelect}
118+
secondaryAction={<Radio sx={{ marginLeft: 0.75 }} checked={isSelected} />}
119+
{...rest}>
120+
<WalletAvatar address={wallet.address} size={24} />
121+
<Box className={classes.text}>
122+
<Box width={180} overflow="auto">
123+
<Typography className={classes.mainLine} component="div">
124+
<Typography className={classes.name}>{walletName}</Typography>
125+
{wallet.source === ImportSource.LocalGenerated || hiddenTag ? null : (
126+
<Typography component="span" className={classes.badge}>
127+
<Trans>Imported</Trans>
128+
</Typography>
129+
)}
130+
</Typography>
131+
<Typography className={classes.address}>
132+
<Tooltip title={wallet.address} placement="right" classes={{ tooltip: classes.tooltip }}>
133+
<span>
134+
<FormattedAddress
135+
address={wallet.address}
136+
size={4}
137+
formatter={formatEthereumAddress}
138+
/>
139+
</span>
140+
</Tooltip>
141+
</Typography>
142+
</Box>
143+
<WalletBalance className={classes.balance} skeletonWidth={60} account={wallet.address} />
144144
</Box>
145-
<WalletBalance className={classes.balance} skeletonWidth={60} account={wallet.address} />
146-
</Box>
147-
</ListItem>
148-
)
149-
})
145+
</ListItem>
146+
)
147+
}),
148+
)
Lines changed: 115 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import Services from '#services'
22
import { Trans } from '@lingui/react/macro'
33
import { Icons } from '@masknet/icons'
4-
import { DashboardRoutes, ECKeyIdentifier, NetworkPluginID, PopupRoutes, type Wallet } from '@masknet/shared-base'
4+
import {
5+
DashboardRoutes,
6+
ECKeyIdentifier,
7+
NetworkPluginID,
8+
PopupRoutes,
9+
PrivyEnvGuard,
10+
type Wallet,
11+
} from '@masknet/shared-base'
512
import { ActionButton, makeStyles } from '@masknet/theme'
613
import { useChainContext, useNetworks, useWallet, useWallets, useWeb3State } from '@masknet/web3-hooks-base'
714
import { EVMWeb3, PRIVY_SUPPORTED_CHAINS } from '@masknet/web3-providers'
@@ -41,117 +48,119 @@ const useStyles = makeStyles()((theme) => ({
4148
},
4249
}))
4350

44-
const SwitchWallet = memo(function SwitchWallet() {
45-
const { classes, theme } = useStyles()
46-
const navigate = useNavigate()
47-
const { closeModal } = useActionModal()
48-
const wallet = useWallet()
49-
const wallets = useWallets()
50-
const { wallets: privyWallets } = usePrivyWallets()
51-
const { chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>()
51+
const SwitchWallet = memo(
52+
PrivyEnvGuard(function SwitchWallet() {
53+
const { classes, theme } = useStyles()
54+
const navigate = useNavigate()
55+
const { closeModal } = useActionModal()
56+
const wallet = useWallet()
57+
const wallets = useWallets()
58+
const { wallets: privyWallets } = usePrivyWallets()
59+
const { chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>()
5260

53-
const handleImport = useCallback(async () => {
54-
await browser.tabs.create({
55-
active: true,
56-
url: browser.runtime.getURL('/dashboard.html#' + DashboardRoutes.RecoveryMaskWallet),
57-
})
58-
}, [])
61+
const handleImport = useCallback(async () => {
62+
await browser.tabs.create({
63+
active: true,
64+
url: browser.runtime.getURL('/dashboard.html#' + DashboardRoutes.RecoveryMaskWallet),
65+
})
66+
}, [])
5967

60-
const { Network } = useWeb3State(NetworkPluginID.PLUGIN_EVM)
61-
const networks = useNetworks(NetworkPluginID.PLUGIN_EVM)
62-
const handleSelect = useCallback(
63-
async (wallet: Wallet) => {
64-
const address = wallet.address
65-
const isPrivyWallet = privyWallets.some((x) => isSameAddress(x.address, address))
66-
await EVMWeb3.connect({
67-
account: address,
68-
chainId: isPrivyWallet && !PRIVY_SUPPORTED_CHAINS.includes(chainId) ? ChainId.Mainnet : chainId,
69-
providerType: ProviderType.MaskWallet,
68+
const { Network } = useWeb3State(NetworkPluginID.PLUGIN_EVM)
69+
const networks = useNetworks(NetworkPluginID.PLUGIN_EVM)
70+
const handleSelect = useCallback(
71+
async (wallet: Wallet) => {
72+
const address = wallet.address
73+
const isPrivyWallet = privyWallets.some((x) => isSameAddress(x.address, address))
74+
await EVMWeb3.connect({
75+
account: address,
76+
chainId: isPrivyWallet && !PRIVY_SUPPORTED_CHAINS.includes(chainId) ? ChainId.Mainnet : chainId,
77+
providerType: ProviderType.MaskWallet,
7078

71-
identifier: ECKeyIdentifier.from(wallet.identifier).unwrapOr(undefined),
72-
})
73-
closeModal()
74-
},
75-
[chainId, closeModal, Network, networks],
76-
)
79+
identifier: ECKeyIdentifier.from(wallet.identifier).unwrapOr(undefined),
80+
})
81+
closeModal()
82+
},
83+
[chainId, closeModal, Network, networks],
84+
)
7785

78-
const handleClickSettings = useCallback(async () => {
79-
navigate(PopupRoutes.WalletSettings)
80-
}, [])
86+
const handleClickSettings = useCallback(async () => {
87+
navigate(PopupRoutes.WalletSettings)
88+
}, [])
8189

82-
const handleLock = useCallback(async () => {
83-
await Services.Wallet.lockWallet()
84-
navigate(PopupRoutes.Wallet)
85-
}, [])
90+
const handleLock = useCallback(async () => {
91+
await Services.Wallet.lockWallet()
92+
navigate(PopupRoutes.Wallet)
93+
}, [])
8694

87-
const action = (
88-
<Box className={classes.modalAction}>
89-
<ActionButton
90-
className={classes.actionButton}
91-
fullWidth
92-
size="small"
93-
variant="outlined"
94-
onClick={() => {
95-
navigate(PopupRoutes.CreateWallet)
96-
}}>
97-
<Icons.Wallet size={20} color={theme.palette.maskColor.second} />
98-
<Typography className={classes.actionLabel} component="span">
99-
<Trans>Add Wallet</Trans>
100-
</Typography>
101-
</ActionButton>
102-
<ActionButton
103-
className={classes.actionButton}
104-
fullWidth
105-
size="small"
106-
variant="outlined"
107-
onClick={handleImport}>
108-
<Icons.Download2 size={20} color={theme.palette.maskColor.second} />
109-
<Typography className={classes.actionLabel} component="span">
110-
<Trans>Import Wallet</Trans>
111-
</Typography>
112-
</ActionButton>
113-
<ActionButton
114-
className={classes.actionButton}
115-
fullWidth
116-
size="small"
117-
variant="outlined"
118-
onClick={handleLock}>
119-
<Icons.Lock size={20} color={theme.palette.maskColor.second} />
120-
<Typography className={classes.actionLabel} component="span">
121-
<Trans>Lock Wallet</Trans>
122-
</Typography>
123-
</ActionButton>
124-
<ActionButton
125-
className={classes.actionButton}
126-
fullWidth
127-
size="small"
128-
variant="outlined"
129-
onClick={handleClickSettings}>
130-
<Icons.WalletSetting size={20} color={theme.palette.maskColor.second} />
131-
<Typography className={classes.actionLabel} component="span">
132-
<Trans>Wallet Settings</Trans>
133-
</Typography>
134-
</ActionButton>
135-
</Box>
136-
)
95+
const action = (
96+
<Box className={classes.modalAction}>
97+
<ActionButton
98+
className={classes.actionButton}
99+
fullWidth
100+
size="small"
101+
variant="outlined"
102+
onClick={() => {
103+
navigate(PopupRoutes.CreateWallet)
104+
}}>
105+
<Icons.Wallet size={20} color={theme.palette.maskColor.second} />
106+
<Typography className={classes.actionLabel} component="span">
107+
<Trans>Add Wallet</Trans>
108+
</Typography>
109+
</ActionButton>
110+
<ActionButton
111+
className={classes.actionButton}
112+
fullWidth
113+
size="small"
114+
variant="outlined"
115+
onClick={handleImport}>
116+
<Icons.Download2 size={20} color={theme.palette.maskColor.second} />
117+
<Typography className={classes.actionLabel} component="span">
118+
<Trans>Import Wallet</Trans>
119+
</Typography>
120+
</ActionButton>
121+
<ActionButton
122+
className={classes.actionButton}
123+
fullWidth
124+
size="small"
125+
variant="outlined"
126+
onClick={handleLock}>
127+
<Icons.Lock size={20} color={theme.palette.maskColor.second} />
128+
<Typography className={classes.actionLabel} component="span">
129+
<Trans>Lock Wallet</Trans>
130+
</Typography>
131+
</ActionButton>
132+
<ActionButton
133+
className={classes.actionButton}
134+
fullWidth
135+
size="small"
136+
variant="outlined"
137+
onClick={handleClickSettings}>
138+
<Icons.WalletSetting size={20} color={theme.palette.maskColor.second} />
139+
<Typography className={classes.actionLabel} component="span">
140+
<Trans>Wallet Settings</Trans>
141+
</Typography>
142+
</ActionButton>
143+
</Box>
144+
)
137145

138-
return (
139-
<ActionModal header={<Trans>Wallet Account</Trans>} action={action}>
140-
<div className={classes.content}>
141-
<List dense className={classes.list}>
142-
{wallets.map((item) => (
143-
<WalletItem
144-
key={item.address}
145-
wallet={item}
146-
onSelect={handleSelect}
147-
isSelected={isSameAddress(item.address, wallet?.address)}
148-
className={classes.walletItem}
149-
/>
150-
))}
151-
</List>
152-
</div>
153-
</ActionModal>
154-
)
155-
})
146+
return (
147+
<ActionModal header={<Trans>Wallet Account</Trans>} action={action}>
148+
<div className={classes.content}>
149+
<List dense className={classes.list}>
150+
{wallets.map((item) => (
151+
<WalletItem
152+
key={item.address}
153+
wallet={item}
154+
onSelect={handleSelect}
155+
isSelected={isSameAddress(item.address, wallet?.address)}
156+
className={classes.walletItem}
157+
/>
158+
))}
159+
</List>
160+
</div>
161+
</ActionModal>
162+
)
163+
}),
164+
)
156165

157166
export default SwitchWallet

packages/mask/popups/pages/Wallet/WalletSettings/Rename.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Trans } from '@lingui/react/macro'
22
import { Icons } from '@masknet/icons'
3-
import { PersistentStorages } from '@masknet/shared-base'
3+
import { PersistentStorages, PrivyEnvGuard } from '@masknet/shared-base'
44
import { useWallet } from '@masknet/web3-hooks-base'
55
import { isSameAddress } from '@masknet/web3-shared-base'
66
import { Box, ListItem, Typography } from '@mui/material'
@@ -10,7 +10,7 @@ import { useSubscription } from 'use-subscription'
1010
import { WalletRenameModal } from '../../../modals/modal-controls.js'
1111
import { useStyles } from './useStyles.js'
1212

13-
export function Rename() {
13+
export const Rename = PrivyEnvGuard(function Rename() {
1414
const wallet = useWallet()
1515
const { classes, theme } = useStyles()
1616
const { wallets: fireflyWallets } = useWallets()
@@ -45,4 +45,4 @@ export function Rename() {
4545
</Box>
4646
</ListItem>
4747
)
48-
}
48+
})

0 commit comments

Comments
 (0)