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
6 changes: 6 additions & 0 deletions packages/mask/shared-ui/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -926,11 +926,17 @@
"popups_wallet_dialog_legacy_wallet_tip": "Detected legacy wallets, please click confirm to restore them all.",
"popups_wallet_set_payment_password": "Set the payment password",
"popups_wallet_payment_password": "Payment Password",
"popups_wallet_re_payment_password": "Re-enter the payment password",
"popups_wallet_set_up_payment_password": "Set up payment password",
"popups_wallet_payment_password_tip": "The Payment password must be a combination of 2 categories out of numbers, letters, and special characters with a length of 8-20 characters.",
"popups_wallet_go_back": "Go back",
"popups_wallet_start_up_tip": "Connect to your wallet, create a new wallet or recover an existing wallet using a seed phrase.",
"popups_wallet_name_placeholder": "Enter 1-12 characters",
"popups_wallet_name_mnemonic": "Mnemonic",
"popups_wallet_name_json_file": "Json File",
"popups_wallet_name_private_key": "Private Key",
"popups_wallet_name_mnemonic_placeholder": "Please enter 12 mnemonic words separated by spaces",
"popups_wallet_name_origin_password": "Original Password",
"popups_wallet_tab_assets": "Assets",
"popups_wallet_tab_activity": "Activity",
"popups_wallet_derivation_path": "Derivation path ({{ path }})",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ProviderType } from '@masknet/web3-shared-evm'
import { EthereumAddress } from 'wallet.ts'
import { getTransactionCount } from './network'
import { currentMaskWalletChainIdSettings } from '../../../plugins/Wallet/settings'

class NonceManager {
constructor(private address: string) {}
Expand Down Expand Up @@ -28,7 +30,14 @@ class NonceManager {
const run = async () => {
try {
this.lock()
callback(null, await getTransactionCount(this.address))
callback(
null,
// Only mask wallets need to use Nonce
await getTransactionCount(this.address, {
providerType: ProviderType.MaskWallet,
chainId: currentMaskWalletChainIdSettings.value,
}),
)
} catch (error: any) {
callback(error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,23 @@ export async function replaceRequest(hash: string, payload: JsonRpcPayload, over
if (!pid || payload.method !== EthereumMethodType.ETH_SEND_TRANSACTION) return

const [config] = payload.params as [TransactionConfig]
return request<string>({
method: EthereumMethodType.MASK_REPLACE_TRANSACTION,
params: [
hash,
{
...config,
...overrides,
},
],
})
return request<string>(
{
method: EthereumMethodType.MASK_REPLACE_TRANSACTION,
params: [
hash,
{
...config,
...overrides,
},
],
},
{
account: currentMaskWalletAccountSettings.value,
chainId: currentMaskWalletChainIdSettings.value,
providerType: ProviderType.MaskWallet,
},
)
}

export async function cancelRequest(hash: string, payload: JsonRpcPayload, overrides?: TransactionConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { memo, useCallback } from 'react'
import { Box, MenuItem, Typography } from '@mui/material'
import { makeStyles } from '@masknet/theme'
import { Flags } from '../../../../../shared'
import { ChainId, ProviderType, useAccount, useChainId, useProviderType } from '@masknet/web3-shared-evm'
import { ChainId, ProviderType, useAccount, useChainId } from '@masknet/web3-shared-evm'
import { getRegisteredWeb3Networks, NetworkPluginID, Web3Plugin } from '@masknet/plugin-infra'
import { currentMaskWalletAccountSettings } from '../../../../plugins/Wallet/settings'
import { ChainIcon, useMenu, WalletIcon } from '@masknet/shared'
import { currentMaskWalletAccountSettings, currentProviderSettings } from '../../../../plugins/Wallet/settings'
import { ChainIcon, useMenu, useValueRef, WalletIcon } from '@masknet/shared'
import { ArrowDownRound } from '@masknet/icons'
import { WalletRPC } from '../../../../plugins/Wallet/messages'

Expand Down Expand Up @@ -46,7 +46,7 @@ export const NetworkSelector = memo(() => {
const networks = getRegisteredWeb3Networks()
const account = useAccount()
const chainId = useChainId()
const providerType = useProviderType()
const providerType = useValueRef(currentProviderSettings)
Comment thread
nuanyang233 marked this conversation as resolved.
const onChainChange = useCallback(
async (chainId: ChainId) => {
if (providerType === ProviderType.MaskWallet) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { memo, useMemo, useState } from 'react'
import { Tab, Tabs, TextField, Typography } from '@mui/material'
import { makeStyles } from '@masknet/theme'
import { makeStyles, useTabs } from '@masknet/theme'
import { Controller, useForm } from 'react-hook-form'
import { z as zod } from 'zod'
import { zodResolver } from '@hookform/resolvers/zod'
import { getEnumAsArray } from '@dimensiondev/kit'
import { LoadingButton, TabContext, TabPanel } from '@mui/lab'
import { useHistory } from 'react-router-dom'
import { PopupRoutes } from '@masknet/shared-base'
Expand Down Expand Up @@ -101,18 +100,12 @@ const useStyles = makeStyles()({
},
})

enum ImportWalletTab {
Mnemonic = 'Mnemonic',
JsonFile = 'Json File',
PrivateKey = 'Private Key',
}

const ImportWallet = memo(() => {
const { t } = useI18N()
const history = useHistory()
const chainId = useChainId()
const { classes } = useStyles()
const [currentTab, setCurrentTab] = useState(ImportWalletTab.Mnemonic)
const [currentTab, onChange, tabs] = useTabs('mnemonic', 'json', 'privateKey')
const [mnemonic, setMnemonic] = useState('')
const [keyStoreContent, setKeyStoreContent] = useState('')
const [keyStorePassword, setKeyStorePassword] = useState('')
Expand All @@ -139,23 +132,23 @@ const ImportWallet = memo(() => {
const disabled = useMemo(() => {
if (!isValid) return true
switch (currentTab) {
case ImportWalletTab.Mnemonic:
case tabs.mnemonic:
return !mnemonic
case ImportWalletTab.JsonFile:
case tabs.json:
return !keyStoreContent
case ImportWalletTab.PrivateKey:
case tabs.privateKey:
return !privateKey
default:
return true
}
}, [currentTab, mnemonic, keyStorePassword, keyStoreContent, privateKey, isValid])
}, [currentTab, mnemonic, keyStorePassword, keyStoreContent, privateKey, isValid, tabs])

const [{ loading }, onDerivedWallet] = useAsyncFn(
async (data: zod.infer<typeof schema>) => {
if (!disabled) {
try {
switch (currentTab) {
case ImportWalletTab.Mnemonic:
case tabs.mnemonic:
// valid the mnemonic
await getDerivableAccounts(mnemonic, 0, 1)
const params = query({ name: data.name })
Expand All @@ -165,7 +158,7 @@ const ImportWallet = memo(() => {
state: { mnemonic },
})
break
case ImportWalletTab.JsonFile:
case tabs.json:
const wallet = await WalletRPC.recoverWalletFromKeyStoreJSON(
data.name,
keyStoreContent,
Expand All @@ -186,7 +179,7 @@ const ImportWallet = memo(() => {
history.replace(PopupRoutes.Wallet)
await Services.Helper.removePopupWindow()
break
case ImportWalletTab.PrivateKey:
case tabs.privateKey:
const privateKeyWallet = await WalletRPC.recoverWalletFromPrivateKey(data.name, privateKey)
if (!currentMaskWalletAccountSettings.value) {
await WalletRPC.updateMaskAccount({
Expand Down Expand Up @@ -215,7 +208,7 @@ const ImportWallet = memo(() => {
}
}
},
[mnemonic, currentTab, keyStoreContent, keyStorePassword, privateKey, disabled, chainId, history],
[mnemonic, currentTab, keyStoreContent, keyStorePassword, privateKey, disabled, chainId, history, tabs],
)

const onSubmit = handleSubmit(onDerivedWallet)
Expand Down Expand Up @@ -251,18 +244,25 @@ const ImportWallet = memo(() => {
classes={{ indicator: classes.indicator }}
onChange={(event, tab) => {
if (errorMessage) setErrorMessage('')
setCurrentTab(tab)
onChange(event, tab)
}}>
{getEnumAsArray(ImportWalletTab).map(({ key, value }) => (
<Tab
key={key}
label={key}
value={value}
classes={{ root: classes.tab, selected: classes.selected }}
/>
))}
<Tab
label={t('popups_wallet_name_mnemonic')}
value={tabs.mnemonic}
classes={{ root: classes.tab, selected: classes.selected }}
/>
<Tab
label={t('popups_wallet_name_json_file')}
value={tabs.json}
classes={{ root: classes.tab, selected: classes.selected }}
/>
<Tab
label={t('popups_wallet_name_private_key')}
value={tabs.privateKey}
classes={{ root: classes.tab, selected: classes.selected }}
/>
</Tabs>
<TabPanel value={ImportWalletTab.Mnemonic} className={classes.tabPanel}>
<TabPanel value={tabs.mnemonic} className={classes.tabPanel}>
<TextField
variant="filled"
multiline
Expand All @@ -273,25 +273,25 @@ const ImportWallet = memo(() => {
}}
minRows={4}
maxRows={10}
placeholder="Please enter 12 mnemonic words separated by spaces"
placeholder={t('popups_wallet_name_mnemonic_placeholder')}
InputProps={{ disableUnderline: true, classes: { root: classes.multilineInput } }}
className={classes.multiline}
inputProps={{ className: classes.textArea }}
/>
</TabPanel>
<TabPanel value={ImportWalletTab.JsonFile} className={classes.tabPanel}>
<TabPanel value={tabs.json} className={classes.tabPanel}>
<JsonFileBox onChange={(content: string) => setKeyStoreContent(content)} />
<PasswordField
classes={{ root: classes.textField }}
placeholder="Original Password"
placeholder={t('popups_wallet_name_origin_password')}
onChange={(e) => {
if (errorMessage) setErrorMessage('')
setKeyStorePassword(e.target.value)
}}
value={keyStorePassword}
/>
</TabPanel>
<TabPanel value={ImportWalletTab.PrivateKey} className={classes.tabPanel}>
<TabPanel value={tabs.privateKey} className={classes.tabPanel}>
<TextField
variant="filled"
multiline
Expand All @@ -301,7 +301,7 @@ const ImportWallet = memo(() => {
setPrivateKey(e.target.value)
}}
rows={4}
placeholder="Private Key"
placeholder={t('popups_wallet_name_private_key')}
InputProps={{ disableUnderline: true, classes: { root: classes.multilineInput } }}
className={classes.multiline}
inputProps={{ className: classes.textArea }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const WalletRecovery = memo(() => {
helperText={!isValid ? errors.confirm?.message : ''}
type="password"
variant="filled"
placeholder="Re-enter the payment password"
placeholder={t('popups_wallet_re_payment_password')}
/>
)}
name="confirm"
Expand Down
9 changes: 5 additions & 4 deletions packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import {
useChainId,
useChainIdValid,
useFungibleTokenBalance,
useProviderType,
useTokenConstants,
useWallet,
} from '@masknet/web3-shared-evm'
import { isGreaterThan, isLessThan, multipliedBy } from '@masknet/web3-shared-base'
import { useRemoteControlledDialog, useValueRef } from '@masknet/shared'
import { useRemoteControlledDialog } from '@masknet/shared'
import { delay } from '@masknet/shared-base'
import type { Coin } from '../../types'
import { TokenPanelType, TradeInfo } from '../../types'
Expand All @@ -36,15 +37,15 @@ import { useTradeCallback } from '../../trader/useTradeCallback'
import { isNativeTokenWrapper } from '../../helpers'
import { ConfirmDialog } from './ConfirmDialog'
import Services from '../../../../extension/service'
import { currentBalancesSettings, currentProviderSettings } from '../../../Wallet/settings'
import { currentBalancesSettings } from '../../../Wallet/settings'
import { TargetChainIdContext } from '../../trader/useTargetChainIdContext'
import { WalletRPC } from '../../../Wallet/messages'
import { PluginTraderMessages } from '../../messages'
import { NetworkType } from '@masknet/public-api'
import BigNumber from 'bignumber.js'
import { useNativeTokenPrice, useTokenPrice } from '../../../Wallet/hooks/useTokenPrice'
import { SettingsDialog } from './SettingsDialog'
import { useAccount } from '@masknet/plugin-infra'
import { useAccount } from '@masknet/web3-shared-evm'

const useStyles = makeStyles()(() => {
return {
Expand All @@ -71,7 +72,7 @@ export function Trader(props: TraderProps) {
const chainIdValid = useChainIdValid()
const { NATIVE_TOKEN_ADDRESS } = useTokenConstants()
const currentAccount = useAccount()
const currentProvider = useValueRef(currentProviderSettings)
const currentProvider = useProviderType()
const classes = useStylesExtends(useStyles(), props)
const { t } = useI18N()
const { setTargetChainId } = TargetChainIdContext.useContainer()
Expand Down