Skip to content

Commit

Permalink
fix: smart pay and Base chain (#10430)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleBill committed Aug 16, 2023
1 parent 9b85cca commit d4c7dc6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { SelectNetworkSidebar } from '@masknet/shared'
import { EMPTY_LIST, NetworkPluginID } from '@masknet/shared-base'
import { makeStyles } from '@masknet/theme'
import type { Web3Helper } from '@masknet/web3-helpers'
import { useFungibleAssets, useNetworks } from '@masknet/web3-hooks-base'
import { useFungibleAssets, useNetworks, useWallet } from '@masknet/web3-hooks-base'
import { isSameAddress } from '@masknet/web3-shared-base'
import { type ChainId } from '@masknet/web3-shared-evm'
import { ChainId } from '@masknet/web3-shared-evm'
import { Box, List, type BoxProps } from '@mui/material'
import { memo, useMemo, useState } from 'react'
import { TokenItem, type TokenItemProps } from './TokenItem.js'
Expand Down Expand Up @@ -51,21 +51,26 @@ export const TokenPicker = memo(function TokenPicker({
return assets.filter((x) => x.chainId === sidebarChainId)
}, [assets, sidebarChainId])

const isSmartPay = !!useWallet(NetworkPluginID.PLUGIN_EVM)?.owner
const networks = useNetworks(NetworkPluginID.PLUGIN_EVM, true)
const filteredNetworks = useMemo(() => {
if (isSmartPay) return networks.filter((x) => x.chainId === ChainId.Matic && !x.isCustomized)
return networks
}, [networks, isSmartPay])

return (
<Box className={cx(classes.picker, className)} {...rest}>
<SelectNetworkSidebar
className={classes.sidebar}
networks={networks}
networks={filteredNetworks}
pluginID={NetworkPluginID.PLUGIN_EVM}
chainId={sidebarChainId}
hideAllButton
onChainChange={setSidebarChainId}
/>
<List className={classes.list} data-hide-scrollbar>
{availableAssets.map((asset) => {
const network = networks.find((x) => x.chainId === asset.chainId)!
const network = filteredNetworks.find((x) => x.chainId === asset.chainId)!
const selected = asset.chainId === chainId && isSameAddress(asset.address, address)
return (
<TokenItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export const FungibleTokenSection = memo(function FungibleTokenSection() {
const {
balance,
isLoading: isLoadingAvailableBalance,
isAvailableBalance,
isGasSufficient,
gasFee,
} = useAvailableBalance(NetworkPluginID.PLUGIN_EVM, address, patchedGasConfig as GasConfig, {
Expand Down Expand Up @@ -225,7 +226,7 @@ export const FungibleTokenSection = memo(function FungibleTokenSection() {
{token?.symbol}
</ProgressiveText>
<ProgressiveText loading={isLoadingBalance} skeletonWidth={60}>
{isNativeToken
{isAvailableBalance
? t('available_amount', {
amount: formatTokenBalance(tokenBalance, token?.decimals),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { FormattedCurrency, NetworkIcon, ProgressiveText, TokenIcon } from '@mas
import { NetworkPluginID, PopupRoutes } from '@masknet/shared-base'
import { useEverSeen } from '@masknet/shared-base-ui'
import { TextOverflowTooltip, makeStyles } from '@masknet/theme'
import { useFungibleTokenBalance, useNetworks } from '@masknet/web3-hooks-base'
import { useFungibleTokenBalance, useNetworks, useWallet } from '@masknet/web3-hooks-base'
import { formatCurrency, isGte, isLessThan, isZero, type FungibleAsset } from '@masknet/web3-shared-base'
import { isNativeTokenAddress, type ChainId, type SchemaType } from '@masknet/web3-shared-evm'
import { isNativeTokenAddress, ChainId, type SchemaType } from '@masknet/web3-shared-evm'
import { Box, List, ListItem, ListItemText, Skeleton, Typography, type ListItemProps } from '@mui/material'
import { range } from 'lodash-es'
import { memo, useCallback, useMemo } from 'react'
Expand Down Expand Up @@ -162,14 +162,19 @@ export const AssetsList = memo(function AssetsList() {
navigate(urlcat(PopupRoutes.TokenDetail, { chainId: asset.chainId, address: asset.address }))
}, [])
const onSwitch = useCallback(() => setAssetsIsExpand((x) => !x), [])
const isSmartPay = !!useWallet(NetworkPluginID.PLUGIN_EVM)?.owner
const filteredAssets = useMemo(() => {
if (isSmartPay) return assets.filter((x) => x.chainId === ChainId.Matic)
return assets
}, [assets, isSmartPay])

const hasLowValueToken = useMemo(() => {
return !!assets.find((x) => {
return !!filteredAssets.find((x) => {
if (isNativeTokenAddress(x.address)) return false
return x.value?.usd ? isLessThan(x.value.usd, 1) : false
})
}, [assets])
const list = assets.filter(
}, [filteredAssets])
const list = filteredAssets.filter(
(asset) => assetsIsExpand || isNativeTokenAddress(asset.address) || isGte(asset.value?.usd ?? 0, 1),
)
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-constants/evm/coingecko.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"Gorli": "",
"BSC": "binancecoin",
"BSCT": "",
"Base": "base",
"Base": "ethereum",
"Base_Goerli": "",
"Matic": "matic-network",
"Mumbai": "",
Expand Down
2 changes: 2 additions & 0 deletions packages/web3-providers/src/DeBank/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const DEBANK_CHAIN_TO_CHAIN_ID_MAP: Record<DebankChains, ChainId | number
tlos: ChainId.Telos,
wan: ChainId.Wanchain,
xdai: ChainId.xDai,
base: ChainId.Base,
}

/**
Expand Down Expand Up @@ -89,6 +90,7 @@ export const CHIAN_ID_TO_DEBANK_CHAIN_MAP: Record<number, DebankChains> = {
4689: 'iotx',
7700: 'canto',
8217: 'klay',
8453: 'base',
9001: 'evmos',
10000: 'sbch',
32520: 'brise',
Expand Down
1 change: 1 addition & 0 deletions packages/web3-providers/src/DeBank/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum DebankTransactionDirection {
* Collect from https://docs.cloud.debank.com/en/readme/api-pro-reference/chain#returns-1
*/
export type DebankChains =
| 'base'
| 'eth'
| 'arb'
| 'astar'
Expand Down

0 comments on commit d4c7dc6

Please sign in to comment.