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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { OrderRow } from './OrderRow'
import { TableListPagination } from './Pagination'
import { LoadingTable } from './LoadingTable'
import { NonFungibleAssetProvider, useAccount } from '@masknet/web3-shared-evm'
import { isZero } from '@masknet/web3-shared-base'
import { isOne, isZero } from '@masknet/web3-shared-base'

const useStyles = makeStyles()((theme) => {
return {
Expand Down Expand Up @@ -50,7 +50,7 @@ export function ListingTab() {
(item) =>
(item.payment_token_contract?.symbol !== 'WETH' &&
item.payment_token_contract?.symbol !== 'ETH') ||
(item.quantity && new BigNumber(item.quantity).toString() !== '1'),
(item.quantity && !isOne(item.quantity)),
) && orders.value?.data.filter((item) => isZero(item.expiration_time ?? 0)).length === 0
)
} else {
Expand Down
5 changes: 2 additions & 3 deletions packages/mask/src/plugins/Collectible/SNSAdaptor/OfferTab.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useMemo } from 'react'
import BigNumber from 'bignumber.js'
import { Button, Table, TableBody, TableCell, TableHead, TableRow, Typography } from '@mui/material'
import { makeStyles } from '@masknet/theme'
import { useI18N } from '../../../utils'
Expand All @@ -8,7 +7,7 @@ import { CollectibleTab } from './CollectibleTab'
import { OrderRow } from './OrderRow'
import { TableListPagination } from './Pagination'
import { LoadingTable } from './LoadingTable'
import { isZero } from '@masknet/web3-shared-base'
import { isOne, isZero } from '@masknet/web3-shared-base'
import { NonFungibleAssetProvider } from '@masknet/web3-shared-evm'

const useStyles = makeStyles()((theme) => {
Expand Down Expand Up @@ -49,7 +48,7 @@ export function OfferTab() {
(item) =>
(item.payment_token_contract?.symbol !== 'WETH' &&
item.payment_token_contract?.symbol !== 'ETH') ||
(item.quantity && new BigNumber(item.quantity).toString() !== '1'),
(item.quantity && !isOne(item.quantity)),
) && offers.value.data.filter((item) => isZero(item.expiration_time ?? 0)).length === 0
)
} else {
Expand Down
5 changes: 2 additions & 3 deletions packages/mask/src/plugins/Collectible/SNSAdaptor/OrderRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useMemo } from 'react'
import BigNumber from 'bignumber.js'
import { Avatar, Link, TableCell, TableRow, Typography } from '@mui/material'
import { makeStyles } from '@masknet/theme'

Expand All @@ -9,7 +8,7 @@ import {
NonFungibleAssetProvider,
resolveAddressLinkOnExplorer,
} from '@masknet/web3-shared-evm'
import { isZero } from '@masknet/web3-shared-base'
import { isOne, isZero } from '@masknet/web3-shared-base'
import { CollectibleState } from '../hooks/useCollectibleState'
import { Account } from './Account'
import { FormattedBalance } from '@masknet/shared'
Expand Down Expand Up @@ -116,7 +115,7 @@ export function OrderRow({ order, isDifferenceToken }: IRowProps) {
<Typography className={classes.content}>
<FormattedBalance
value={order.quantity ?? 0}
decimals={new BigNumber(order.quantity ?? 0).toString() !== '1' ? 8 : 0}
decimals={!isOne(order.quantity ?? 0) ? 8 : 0}
formatter={formatBalance}
/>
</Typography>
Expand Down
5 changes: 5 additions & 0 deletions packages/web3-shared/base/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export function isZero(n: BigNumber.Value) {
return n === 0 || n === '0' || new BigNumber(n).isZero()
}

/** n === 1 */
export function isOne(n: BigNumber.Value) {
return n === 1 || n === '1' || new BigNumber(n).isEqualTo(ONE)
}

/** a > b */
export function isGreaterThan(a: BigNumber.Value, b: BigNumber.Value) {
return new BigNumber(a).isGreaterThan(b)
Expand Down