diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/OpenSea/ActionBar.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/OpenSea/ActionBar.tsx index 7b6cda385941..f1edde7ac3e4 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/OpenSea/ActionBar.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/OpenSea/ActionBar.tsx @@ -54,7 +54,7 @@ export function ActionBar(props: ActionBarProps) { const isOwner = isSameAddress(asset.value.owner?.address, account) return ( - + {!isOwner && asset.value.auction ? ( { onConfirm: () => void onClose?: () => void wallet?: Wallet | null + account?: string } export function ConfirmDialogUI(props: ConfirmDialogUIProps) { const { t } = useI18N() - const { open, trade, wallet, inputToken, outputToken, onConfirm, onClose, gas, gasPrice } = props + const { open, trade, wallet, inputToken, outputToken, onConfirm, onClose, gas, gasPrice, account } = props const [cacheTrade, setCacheTrade] = useState() const [priceUpdated, setPriceUpdated] = useState(false) @@ -220,7 +221,11 @@ export function ConfirmDialogUI(props: ConfirmDialogUIProps) { {t('plugin_red_packet_nft_account_name')} - ({wallet?.name}) + {wallet?.name ? ( + `(${wallet.name})` + ) : ( + + )} ()((them }) export interface AllTradeFormProps { - wallet?: Wallet | null + account?: string | null inputAmount: string inputToken?: FungibleToken outputToken?: FungibleToken @@ -199,7 +192,7 @@ export interface AllTradeFormProps { export const TradeForm = memo( ({ - wallet, + account, trades, inputAmount, inputToken, @@ -456,7 +449,7 @@ export const TradeForm = memo( - {wallet ? ( + {account ? ( ( withChildren ActionButtonProps={{ color: 'primary', + style: { borderRadius: isDashboard ? 8 : 24 }, }} infiniteUnlockContent={ diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx index 574feb7e7a32..96569b9ceb34 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx @@ -28,7 +28,7 @@ import { ConfirmDialog } from './ConfirmDialog' import { useGasConfig } from './hooks/useGasConfig' import { useSortedTrades } from './hooks/useSortedTrades' import { useUpdateBalance } from './hooks/useUpdateBalance' -import { useChainId, useChainIdValid, useFungibleTokenBalance, useWallet } from '@masknet/plugin-infra/web3' +import { useChainId, useChainIdValid, useFungibleTokenBalance, useWallet, useAccount } from '@masknet/plugin-infra/web3' import { SettingsDialog } from './SettingsDialog' import { TradeForm } from './TradeForm' @@ -52,6 +52,7 @@ export function Trader(props: TraderProps) { const { defaultOutputCoin, coin, chainId: targetChainId, defaultInputCoin } = props const [focusedTrade, setFocusTrade] = useState() const wallet = useWallet(NetworkPluginID.PLUGIN_EVM) + const account = useAccount(NetworkPluginID.PLUGIN_EVM) const currentChainId = useChainId(NetworkPluginID.PLUGIN_EVM) const chainId = targetChainId ?? currentChainId const chainIdValid = useChainIdValid(NetworkPluginID.PLUGIN_EVM) @@ -356,7 +357,7 @@ export function Trader(props: TraderProps) { return (
{focusedTrade?.value && !isNativeTokenWrapper(focusedTrade.value) && inputToken && outputToken ? ( (props: ChainBoundaryPro <> {!props.hiddenConnectButton ? ( } variant="contained" size={props.ActionButtonPromiseProps?.size} diff --git a/packages/mask/src/web3/UI/EthereumERC20TokenApprovedBoundary.tsx b/packages/mask/src/web3/UI/EthereumERC20TokenApprovedBoundary.tsx index ce788fcd7dac..86e68ea3c09f 100644 --- a/packages/mask/src/web3/UI/EthereumERC20TokenApprovedBoundary.tsx +++ b/packages/mask/src/web3/UI/EthereumERC20TokenApprovedBoundary.tsx @@ -80,6 +80,27 @@ export function EthereumERC20TokenApprovedBoundary(props: EthereumERC20TokenAppr // not a valid erc20 token, please given token as undefined if (!token) return {render ? (render(false) as any) : children} + if (transactionState.loading || approveStateType === ApproveStateType.UPDATING) + return ( + + + {transactionState.loading + ? t('plugin_ito_unlocking_symbol', { symbol: token.symbol }) + : `Updating ${token.symbol}`} + … + + {withChildren ? ( + {render ? (render(true) as any) : children} + ) : null} + + ) + if (approveStateType === ApproveStateType.UNKNOWN) return ( @@ -151,23 +172,6 @@ export function EthereumERC20TokenApprovedBoundary(props: EthereumERC20TokenAppr ) : null} ) - if (transactionState.loading || approveStateType === ApproveStateType.UPDATING) - return ( - - - {transactionState.loading - ? t('plugin_ito_unlocking_symbol', { symbol: token.symbol }) - : `Updating ${token.symbol}`} - … - - - ) if (approveStateType === ApproveStateType.APPROVED) return ( diff --git a/packages/plugin-infra/src/web3/EVM/useERC20TokenApproveCallback.ts b/packages/plugin-infra/src/web3/EVM/useERC20TokenApproveCallback.ts index 8302173b3fad..41bf0e70d8cb 100644 --- a/packages/plugin-infra/src/web3/EVM/useERC20TokenApproveCallback.ts +++ b/packages/plugin-infra/src/web3/EVM/useERC20TokenApproveCallback.ts @@ -1,6 +1,5 @@ import type { NonPayableTx } from '@masknet/web3-contracts/types/types' import { isLessThan, NetworkPluginID, toFixed } from '@masknet/web3-shared-base' -import { once } from 'lodash-unified' import { useCallback, useMemo } from 'react' import { useAsyncFn } from 'react-use' import { useERC20TokenContract } from './useERC20TokenContract' @@ -80,10 +79,10 @@ export function useERC20TokenApproveCallback(address?: string, amount?: string, // send transaction and wait for hash return new Promise(async (resolve, reject) => { - const revalidate = once(() => { + const revalidate = () => { revalidateBalance() revalidateAllowance() - }) + } erc20Contract.methods .approve(spender, useExact ? amount : MaxUint256) .send(config as NonPayableTx) @@ -116,7 +115,7 @@ export function useERC20TokenApproveCallback(address?: string, amount?: string, spender, balance, }, - state, + { ...state, loading: loadingAllowance || loadingBalance || state.loading }, approveCallback, resetCallback, ] as const diff --git a/packages/plugin-infra/src/web3/index.ts b/packages/plugin-infra/src/web3/index.ts index c51a3a0820cc..5bced7295e19 100644 --- a/packages/plugin-infra/src/web3/index.ts +++ b/packages/plugin-infra/src/web3/index.ts @@ -1,6 +1,7 @@ export * from './Context' export * from './useAccount' +export * from './useAccountName' export * from './useAddressBook' export * from './useSocialAddressList' export * from './useSocialAddressListAll' diff --git a/packages/plugin-infra/src/web3/useAccountName.ts b/packages/plugin-infra/src/web3/useAccountName.ts new file mode 100644 index 000000000000..95f26cb8700f --- /dev/null +++ b/packages/plugin-infra/src/web3/useAccountName.ts @@ -0,0 +1,25 @@ +import { useMemo } from 'react' +import { isSameAddress, NetworkPluginID } from '@masknet/web3-shared-base' +import { useWeb3State } from './useWeb3State' +import { useAccount } from './useAccount' +import { useWallets } from './useWallets' +import { useProviderType } from './useProviderType' +import type { Web3Helper } from '../web3-helpers' + +export function useAccountName(pluginID?: T, expectedAccount?: string) { + type ProviderName = (providerType: Web3Helper.Definition[T]['ProviderType']) => string + + const { Others } = useWeb3State(pluginID) + const account = useAccount(pluginID, expectedAccount) + const providerType = useProviderType(pluginID) + const wallets = useWallets(pluginID) + + return useMemo(() => { + // if the currently selected account is a mask wallet, then use the wallet name as the account name + const wallet = wallets.find((x) => isSameAddress(account, x.address)) + if (wallet?.name) return wallet.name + + // else use the provider name as the account name + return (Others?.providerResolver.providerName as ProviderName | undefined)?.(providerType) + }, [account, providerType, wallets.map((x) => x.address.toLowerCase()), Others]) +} diff --git a/packages/plugins/EVM/src/state/Connection/translators/Base.ts b/packages/plugins/EVM/src/state/Connection/translators/Base.ts index f633830797da..dd40597559a8 100644 --- a/packages/plugins/EVM/src/state/Connection/translators/Base.ts +++ b/packages/plugins/EVM/src/state/Connection/translators/Base.ts @@ -13,9 +13,15 @@ export class Base implements Translator { // #region polyfill transaction config { - // add gas margin - if (config.gas) - config.gas = BigNumber.max(toHex(addGasMargin(config.gas as string).toFixed()), 21000).toFixed() + try { + // add gas margin + if (config.gas) + config.gas = toHex( + BigNumber.max(toHex(addGasMargin(config.gas as string).toFixed()), 21000).toFixed(), + ) + } catch (error) { + console.log(error) + } // add gas price const hub = await Web3StateSettings.value.Hub?.getHub?.({ @@ -31,7 +37,7 @@ export class Base implements Translator { slowOption?.suggestedMaxFeePerGas && normalOption && isLessThan( - config.maxFeePerGas ? formatWeiToGwei(config.maxFeePerGas as string) : 0, + config.maxPriorityFeePerGas ? formatWeiToGwei(config.maxPriorityFeePerGas as string) : 0, slowOption.suggestedMaxPriorityFeePerGas, ) ) { @@ -52,7 +58,6 @@ export class Base implements Translator { config.gasPrice = toHex(normalOption.suggestedMaxFeePerGas) } } - context.config = config } // #endregion diff --git a/packages/plugins/EVM/src/state/TransactionFormatter/descriptors/ERC20.ts b/packages/plugins/EVM/src/state/TransactionFormatter/descriptors/ERC20.ts index ac9d67f0a813..716834484be1 100644 --- a/packages/plugins/EVM/src/state/TransactionFormatter/descriptors/ERC20.ts +++ b/packages/plugins/EVM/src/state/TransactionFormatter/descriptors/ERC20.ts @@ -19,7 +19,7 @@ export class ERC20Descriptor implements TransactionDescriptor { title: 'Approve', description: `Approve spend ${getTokenAmountDescription( context.parameters?.value, - await connection?.getFungibleToken(context.parameters?.to ?? '', { + await connection?.getFungibleToken(context.to ?? '', { chainId: context.chainId, }), )}`,