Skip to content

Commit

Permalink
fix: bugfix for logout password field (#10434)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuanyang233 committed Aug 17, 2023
1 parent c856421 commit 19a97bb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 36 deletions.
3 changes: 2 additions & 1 deletion packages/mask/shared-ui/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,8 @@
"popups_wallet_reset_wallet_description_3": "Note: If you using the mnemonic phrase from your last import, you can recover the wallet derived from that mnemonic phrase.",
"popups_wallet_backup_json_file_confirm_password_tip": "This file has been encrypted and stored with your current password. Your current password is needed to decrypt this file when using it to import wallet.",
"popups_wallet_backup_private_key_tip": "Please don’t show anyone your private key. The private key can be used in any wallet that supports EVM-compatible chains without decryption.",
"popups_wallet_backup_input_password": "Input your password",
"popups_wallet_backup_input_password": "Please enter your backup password.",
"popups_wallet_logout_input_payment_password": "Please enter your payment password.",
"popups_wallet_backup_json_file_drag_tip": "Drag your file into here…",
"popups_wallet_backup_json_file_click_tip": "Click or drag your file here",
"popups_wallet_enter_your_wallet_name": "Enter your wallet name",
Expand Down
97 changes: 64 additions & 33 deletions packages/mask/src/extension/popups/pages/Personas/Logout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,69 @@ export const LogoutUI = memo<LogoutUIProps>(
password,
])

const passwordField = useMemo(() => {
if (manageWallets.length) {
if (hasPassword) {
return (
<PasswordField
placeholder={t('popups_wallet_logout_input_payment_password')}
value={paymentPassword}
error={!!paymentPasswordError}
helperText={paymentPasswordError}
onChange={(e) => {
if (paymentPasswordError) setPaymentPasswordError('')
setPaymentPassword(e.target.value)
}}
onClear={() => {
setPaymentPassword('')
setPaymentPasswordError('')
}}
/>
)
} else if (backupPassword) {
return (
<PasswordField
placeholder={t('popups_wallet_backup_input_password')}
value={password}
onChange={(e) => {
if (error) setError(false)
setPassword(e.target.value)
}}
error={error}
onClear={() => {
setPassword('')
setError(false)
}}
helperText={error ? t('popups_password_do_not_match') : ''}
/>
)
}

return
}

if (backupPassword) {
return (
<PasswordField
placeholder={t('popups_wallet_backup_input_password')}
value={password}
onChange={(e) => {
if (error) setError(false)
setPassword(e.target.value)
}}
error={error}
onClear={() => {
setPassword('')
setError(false)
}}
helperText={error ? t('popups_password_do_not_match') : ''}
/>
)
}

return
}, [manageWallets, hasPassword, paymentPassword, paymentPasswordError, backupPassword, password, error, t])

return (
<Box flex={1} maxHeight="544px" overflow="auto" data-hide-scrollbar>
<Box p={2} pb={11}>
Expand Down Expand Up @@ -248,39 +311,7 @@ export const LogoutUI = memo<LogoutUIProps>(
</Typography>
) : null}
</Typography>
{backupPassword ? (
manageWallets.length && hasPassword ? (
<PasswordField
placeholder={t('popups_wallet_backup_input_password')}
value={paymentPassword}
error={!!paymentPasswordError}
helperText={paymentPasswordError}
onChange={(e) => {
if (paymentPasswordError) setPaymentPasswordError('')
setPaymentPassword(e.target.value)
}}
onClear={() => {
setPaymentPassword('')
setPaymentPasswordError('')
}}
/>
) : (
<PasswordField
placeholder={t('popups_backup_password')}
value={password}
onChange={(e) => {
if (error) setError(false)
setPassword(e.target.value)
}}
error={error}
onClear={() => {
setPassword('')
setError(false)
}}
helperText={error ? t('popups_password_do_not_match') : ''}
/>
)
) : null}
{passwordField}
</Box>
<BottomController>
<Button variant="outlined" fullWidth onClick={onCancel}>
Expand Down
3 changes: 1 addition & 2 deletions packages/web3-providers/src/Web3/EVM/interceptors/Popups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export class Popups implements Middleware<ConnectionContext> {
private async getPaymentToken(context: ConnectionContext) {
const maskAddress = getMaskTokenAddress(context.chainId)
try {
if (!context.paymentToken) return DEFAULT_PAYMENT_TOKEN_STATE
const smartPayChainId = await this.Bundler.getSupportedChainId()
if (context.chainId !== smartPayChainId || !context.owner) return DEFAULT_PAYMENT_TOKEN_STATE

Expand Down Expand Up @@ -89,7 +88,7 @@ export class Popups implements Middleware<ConnectionContext> {
const availableBalanceTooLow =
isGreaterThan(maskGasFee, maskAllowance) || isGreaterThan(maskGasFee, maskBalance)

const isNative = isNativeTokenAddress(context.paymentToken)
const isNative = !context.paymentToken || isNativeTokenAddress(context.paymentToken)

return {
allowMaskAsGas: !availableBalanceTooLow,
Expand Down

0 comments on commit 19a97bb

Please sign in to comment.