Skip to content

Commit

Permalink
fix: bugfix for transfer token (#10406)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuanyang233 committed Aug 15, 2023
1 parent 723e767 commit 86be60e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { NetworkPluginID } from '@masknet/shared-base'
import { unreachable } from '@masknet/kit'
import { isString } from 'lodash-es'
import { FormattedBalance, FormattedCurrency, ImageIcon, TokenIcon } from '@masknet/shared'
import { FormattedCurrency, ImageIcon, TokenIcon } from '@masknet/shared'
import { GasSettingMenu } from '../GasSettingMenu/index.js'
import type { TransactionDetail } from '../../pages/Wallet/type.js'

Expand Down Expand Up @@ -203,12 +203,16 @@ export const TransactionPreview = memo<TransactionPreviewProps>(function Transac
name={token?.name}
className={classes.tokenIcon}
/>
<FormattedBalance
value={amount}
decimals={token?.decimals}
significant={4}
formatter={formatBalance}
/>
{amount
? formatBalance(
amount,
token?.decimals,
4,
false,
true,
leftShift(amount, token?.decimals).isGreaterThan(1) ? 6 : 12,
)
: null}
</>
) : null}
</Typography>
Expand Down
26 changes: 16 additions & 10 deletions packages/mask/src/extension/popups/pages/Personas/Home/UI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export interface PersonaHomeUIProps {
onConnect: (networkIdentifier: EnhanceableSite) => void
onAccountClick: (account: ProfileAccount) => void
bindingWallets?: ConnectedWalletInfo[]
hasPaymentPassword?: boolean
}

export const PersonaHomeUI = memo<PersonaHomeUIProps>(
Expand All @@ -194,6 +195,7 @@ export const PersonaHomeUI = memo<PersonaHomeUIProps>(
onAccountClick,
bindingWallets,
hasProofs,
hasPaymentPassword,
}) => {
const theme = useTheme()
const { t } = useI18N()
Expand All @@ -203,16 +205,20 @@ export const PersonaHomeUI = memo<PersonaHomeUIProps>(

const [currentTab, onChange] = useParamTab<PopupHomeTabType>(PopupHomeTabType.SocialAccounts)

const onChangeTab = useCallback((event: object, value: PopupHomeTabType) => {
if (
currentMaskWalletLockStatusSettings.value === LockStatus.LOCKED &&
value === PopupHomeTabType.ConnectedWallets
) {
navigate(urlcat(PopupRoutes.Unlock, { from: PopupRoutes.Personas, goBack: true, popup: true }))
return
}
onChange(event, value)
}, [])
const onChangeTab = useCallback(
(event: object, value: PopupHomeTabType) => {
if (
currentMaskWalletLockStatusSettings.value === LockStatus.LOCKED &&
value === PopupHomeTabType.ConnectedWallets &&
hasPaymentPassword
) {
navigate(urlcat(PopupRoutes.Unlock, { from: PopupRoutes.Personas, goBack: true, popup: true }))
return
}
onChange(event, value)
},
[hasPaymentPassword],
)
return (
<div className={classes.container}>
{!isEmpty ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Services from '../../../../service.js'
import { HydrateFinished } from '../../../../../utils/createNormalReactRoot.js'
import { useSupportSocialNetworks } from '../../../hook/useSupportSocialNetworks.js'
import { useVerifiedWallets } from '../../../hook/useVerifiedWallets.js'
import { useHasPassword } from '../../../hook/useHasPassword.js'

const PersonaHome = memo(() => {
const navigate = useNavigate()
Expand All @@ -24,6 +25,8 @@ const PersonaHome = memo(() => {

const { data: bindingWallets } = useVerifiedWallets(proofs)

const { hasPassword } = useHasPassword()

const onCreatePersona = useCallback(() => {
browser.tabs.create({
active: true,
Expand Down Expand Up @@ -81,6 +84,7 @@ const PersonaHome = memo(() => {
onRestore={onRestore}
onConnect={handleConnect}
onAccountClick={handleAccountClick}
hasPaymentPassword={hasPassword}
/>
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const FungibleTokenSection = memo(function FungibleTokenSection() {
providerURL: network?.rpcUrl,
})
} catch (err) {
showSnackbar(t('failed_to_transfer_token', { message: (err as Error).message, variant: 'error' }))
showSnackbar(t('failed_to_transfer_token', { message: (err as Error).message }), { variant: 'error' })
}
}, [address, chainId, recipient, totalAmount, token?.decimals, gasConfig, paymentAddress, network?.rpcUrl])

Expand Down Expand Up @@ -250,7 +250,7 @@ export const FungibleTokenSection = memo(function FungibleTokenSection() {
}}
/>
</Box>
<Box display="flex" justifyContent="space-between" mt={2} mx={2}>
<Box display="flex" justifyContent="space-between" alignItems="center" mt={2} mx={2}>
<Typography className={classes.label}>{t('gas_fee')}</Typography>
<ChainContextProvider value={chainContextValue}>
<GasSettingMenu
Expand Down
18 changes: 11 additions & 7 deletions packages/web3-providers/src/Web3/EVM/translators/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ export class Base implements Translator<ConnectionContext> {
// #region polyfill transaction config
try {
// add gas margin
if (config.gas && context.providerType !== ProviderType.MaskWallet) {
config.gas = toHex(
BigNumber.max(
toHex(addGasMargin(config.gas).toFixed()),
context.chainId === ChainId.Optimism ? 25000 : 21000,
).toFixed(),
)
if (config.gas) {
if (context.providerType !== ProviderType.MaskWallet) {
config.gas = toHex(
BigNumber.max(
toHex(addGasMargin(config.gas).toFixed()),
context.chainId === ChainId.Optimism ? 25000 : 21000,
).toFixed(),
)
} else {
config.gas = toHex(config.gas)
}
}

// add gas price
Expand Down

0 comments on commit 86be60e

Please sign in to comment.