From edbbe71644581b01c5973d1b907e4a0f280cd32e Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 14 Dec 2021 14:41:02 +0800 Subject: [PATCH 01/10] fix: collectible insufficient balance --- .../src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx index 6151bb1fde52..9ba3f0f47ab6 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx @@ -114,7 +114,8 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { }, [open]) const validationMessage = useMemo(() => { - const amount_ = new BigNumber(amount || '0') + const amountWithDecimal = Number(amount) * 10 ** Number(token.value?.decimals ?? 0) + const amount_ = new BigNumber(amountWithDecimal || '0') const balance_ = new BigNumber(balance.value ?? '0') if (amount_.isZero()) return t('plugin_collectible_enter_a_price') if (balance_.isZero() || amount_.isGreaterThan(balance_)) return t('plugin_collectible_insufficient_balance') From bba11494fffde482a9d112de0de238d201a05eef Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 14 Dec 2021 16:43:29 +0800 Subject: [PATCH 02/10] feat: when not meet the minimum price requirement --- packages/mask/shared-ui/locales/en-US.json | 1 + packages/mask/shared-ui/locales/zh-CN.json | 1 + .../SNSAdaptor/MakeOfferDialog.tsx | 115 ++++++++++-------- .../src/plugins/Collectible/types/opensea.ts | 1 + 4 files changed, 67 insertions(+), 51 deletions(-) diff --git a/packages/mask/shared-ui/locales/en-US.json b/packages/mask/shared-ui/locales/en-US.json index 4cbe53f66cb5..f316d159352c 100644 --- a/packages/mask/shared-ui/locales/en-US.json +++ b/packages/mask/shared-ui/locales/en-US.json @@ -633,6 +633,7 @@ "plugin_collectible_no_history": "No History", "plugin_collectible_ensure_unreviewed_item": "Please ensure unreviewed item", "plugin_collectible_check_tos_document": "Please check ToS document", + "plugin_collectible_insufficient_offer": "Insufficient Offer", "plugin_collectible_not_been_reviewed_by_opensea": "This item has not been reviewed by OpenSea.", "plugin_collectible_reviewed_tips": "You should proceed with extra caution. Anyone can create a digital item on a blockchain with any\n name, including fake versions of existing items. Please take extra caution and do your research\n when interacting with this item to ensure it's what it chains to be.", "plugin_collectible_total": "Total", diff --git a/packages/mask/shared-ui/locales/zh-CN.json b/packages/mask/shared-ui/locales/zh-CN.json index 08be779b787b..ff4d6628644e 100644 --- a/packages/mask/shared-ui/locales/zh-CN.json +++ b/packages/mask/shared-ui/locales/zh-CN.json @@ -620,6 +620,7 @@ "plugin_collectible_no_history": "无历史记录", "plugin_collectible_ensure_unreviewed_item": "请确保未经审核的收藏品", "plugin_collectible_check_tos_document": "请查阅 ToS 文档", + "plugin_collectible_insufficient_offer": "报价不足", "plugin_collectible_not_been_reviewed_by_opensea": "此收藏品尚未经 OpenSea 审查。", "plugin_collectible_reviewed_tips": "你需要格外谨慎。 任何人都可以在区块链上创建一个带有任何名称的收藏品。 包括现有收藏品的假版本。 请在与这个收藏品交互时格外小心并进行研究,以确保它是您想要的收藏品。", "plugin_collectible_total": "总共", diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx index 9ba3f0f47ab6..22669bf2d071 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx @@ -61,6 +61,10 @@ const useStyles = makeStyles()((theme) => { flex: 1, margin: `${theme.spacing(1.5)} ${theme.spacing(0.5)} 0`, }, + insufficientError: { + paddingTop: theme.spacing(1), + color: 'red', + }, } }) @@ -74,6 +78,11 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { const { asset, open, onClose } = props const isAuction = asset?.value?.is_auction ?? false const isVerified = asset?.value?.is_verified ?? false + const leastPrice = + asset?.value && asset.value.orders?.length + ? new BigNumber(asset.value.orders[0].base_price ?? '0') + : new BigNumber('0') + const paymentTokens = (isAuction ? asset?.value?.offer_payment_tokens : asset?.value?.order_payment_tokens) ?? [] const selectedPaymentToken = first(paymentTokens) @@ -117,12 +126,16 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { const amountWithDecimal = Number(amount) * 10 ** Number(token.value?.decimals ?? 0) const amount_ = new BigNumber(amountWithDecimal || '0') const balance_ = new BigNumber(balance.value ?? '0') + if (amount_.isZero()) return t('plugin_collectible_enter_a_price') if (balance_.isZero() || amount_.isGreaterThan(balance_)) return t('plugin_collectible_insufficient_balance') if (!isAuction && expirationDateTime.getTime() - Date.now() <= 0) return t('plugin_collectible_invalid_expiration_date') if (!isVerified && !unreviewedChecked) return t('plugin_collectible_ensure_unreviewed_item') if (!isVerified && !ToS_Checked) return t('plugin_collectible_check_tos_document') + if (leastPrice.isGreaterThan(amount_)) { + return t('plugin_collectible_insufficient_offer') + } return '' }, [amount, balance.value, expirationDateTime, isVerified, isAuction, unreviewedChecked, ToS_Checked]) @@ -156,6 +169,7 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { whitelist: paymentTokens.map((x) => x.address), }} /> + {!isAuction ? ( ) : null} - - {isVerified ? null : ( - <> - ) => - setUnreviewedChecked(ev.target.checked) - } - /> - } - label={ - - {t('plugin_collectible_approved_by_open_sea')} - - } - /> - ) => - setToS_Checked(ev.target.checked) - } + + {isVerified ? null : ( + + ) => + setUnreviewedChecked(ev.target.checked) + } + /> + } + label={ + + {t('plugin_collectible_approved_by_open_sea')} + + } + /> + ) => + setToS_Checked(ev.target.checked) + } + /> + } + label={ + + + ), + }} /> - } - label={ - - - ), - }} - /> - - } - /> - - )} - + + } + /> + + )} diff --git a/packages/mask/src/plugins/Collectible/types/opensea.ts b/packages/mask/src/plugins/Collectible/types/opensea.ts index c9036f6984bf..a0af4e48e4de 100644 --- a/packages/mask/src/plugins/Collectible/types/opensea.ts +++ b/packages/mask/src/plugins/Collectible/types/opensea.ts @@ -188,6 +188,7 @@ export interface AssetOrder { quantity: string expiration_time: number order_hash: string + base_price?: string } export interface OpenSeaResponse extends Asset { From 42f6f741ca0c25f19e1e9c0376b5f32a79f9ace4 Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 14 Dec 2021 16:46:43 +0800 Subject: [PATCH 03/10] style: kill unused code --- .../src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx index 22669bf2d071..a69919d66159 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx @@ -61,10 +61,6 @@ const useStyles = makeStyles()((theme) => { flex: 1, margin: `${theme.spacing(1.5)} ${theme.spacing(0.5)} 0`, }, - insufficientError: { - paddingTop: theme.spacing(1), - color: 'red', - }, } }) From ce548b4b4ea9330fdf8fa46db0351e9f67a4fbbd Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 14 Dec 2021 18:55:55 +0800 Subject: [PATCH 04/10] fix: change tos check as a common check --- .../SNSAdaptor/MakeOfferDialog.tsx | 67 +++++++++---------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx index a69919d66159..a6bdb4aabfa7 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx @@ -128,7 +128,7 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { if (!isAuction && expirationDateTime.getTime() - Date.now() <= 0) return t('plugin_collectible_invalid_expiration_date') if (!isVerified && !unreviewedChecked) return t('plugin_collectible_ensure_unreviewed_item') - if (!isVerified && !ToS_Checked) return t('plugin_collectible_check_tos_document') + if (!ToS_Checked) return t('plugin_collectible_check_tos_document') if (leastPrice.isGreaterThan(amount_)) { return t('plugin_collectible_insufficient_offer') } @@ -176,9 +176,35 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { fullWidth /> ) : null} - - {isVerified ? null : ( - + ) => setToS_Checked(ev.target.checked)} + /> + } + label={ + + + ), + }} + /> + + } + /> + + {isVerified ? null : ( } /> - ) => - setToS_Checked(ev.target.checked) - } - /> - } - label={ - - - ), - }} - /> - - } - /> - - )} + )} + From 1e7a6252b54c1f8f6565bcba315ff08c39dec9bb Mon Sep 17 00:00:00 2001 From: BillyS <52899576+BillySh1@users.noreply.github.com> Date: Tue, 14 Dec 2021 18:57:24 +0800 Subject: [PATCH 05/10] Update packages/mask/shared-ui/locales/en-US.json Co-authored-by: Hancheng Zhou --- packages/mask/shared-ui/locales/en-US.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mask/shared-ui/locales/en-US.json b/packages/mask/shared-ui/locales/en-US.json index 3c3c2ee04fc4..85332c1395e8 100644 --- a/packages/mask/shared-ui/locales/en-US.json +++ b/packages/mask/shared-ui/locales/en-US.json @@ -633,7 +633,7 @@ "plugin_collectible_no_history": "No History", "plugin_collectible_ensure_unreviewed_item": "Please ensure unreviewed item", "plugin_collectible_check_tos_document": "Please check ToS document", - "plugin_collectible_insufficient_offer": "Insufficient Offer", + "plugin_collectible_insufficient_offer": "Insufficient Offer", "plugin_collectible_not_been_reviewed_by_opensea": "This item has not been reviewed by OpenSea.", "plugin_collectible_reviewed_tips": "You should proceed with extra caution. Anyone can create a digital item on a blockchain with any\n name, including fake versions of existing items. Please take extra caution and do your research\n when interacting with this item to ensure it's what it chains to be.", "plugin_collectible_total": "Total", From 22997dcf7eddefae74c0cbab013015779eecc3b9 Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 14 Dec 2021 19:14:55 +0800 Subject: [PATCH 06/10] fix: use pow10 --- .../src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx index a6bdb4aabfa7..6dc4f71567f9 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx @@ -35,6 +35,7 @@ import { toAsset } from '../helpers' import { PluginTraderMessages } from '../../Trader/messages' import { Trans } from 'react-i18next' import getUnixTime from 'date-fns/getUnixTime' +import { pow10 } from '@masknet/web3-shared-base' const useStyles = makeStyles()((theme) => { return { @@ -119,10 +120,8 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { }, [open]) const validationMessage = useMemo(() => { - const amountWithDecimal = Number(amount) * 10 ** Number(token.value?.decimals ?? 0) - const amount_ = new BigNumber(amountWithDecimal || '0') + const amount_ = new BigNumber(pow10(token.value?.decimals ?? 0).multipliedBy(amount) || '0') const balance_ = new BigNumber(balance.value ?? '0') - if (amount_.isZero()) return t('plugin_collectible_enter_a_price') if (balance_.isZero() || amount_.isGreaterThan(balance_)) return t('plugin_collectible_insufficient_balance') if (!isAuction && expirationDateTime.getTime() - Date.now() <= 0) From b049f60d8b8848015907eeb7634ab4a7140bc55c Mon Sep 17 00:00:00 2001 From: billy Date: Wed, 15 Dec 2021 15:26:27 +0800 Subject: [PATCH 07/10] fix: check price is NaN --- .../src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx index 6dc4f71567f9..67cc0d29f0bc 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx @@ -120,9 +120,9 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { }, [open]) const validationMessage = useMemo(() => { - const amount_ = new BigNumber(pow10(token.value?.decimals ?? 0).multipliedBy(amount) || '0') + const amount_ = new BigNumber(pow10(token.value?.decimals ?? 0).multipliedBy(amount) ?? '0') const balance_ = new BigNumber(balance.value ?? '0') - if (amount_.isZero()) return t('plugin_collectible_enter_a_price') + if (amount_.isNaN() || amount_.isZero()) return t('plugin_collectible_enter_a_price') if (balance_.isZero() || amount_.isGreaterThan(balance_)) return t('plugin_collectible_insufficient_balance') if (!isAuction && expirationDateTime.getTime() - Date.now() <= 0) return t('plugin_collectible_invalid_expiration_date') From 93c366facbe0acfc6abaaba1457040ffb3587b78 Mon Sep 17 00:00:00 2001 From: billy Date: Wed, 15 Dec 2021 15:50:33 +0800 Subject: [PATCH 08/10] fix: kill padding --- .../SNSAdaptor/MakeOfferDialog.tsx | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx index 67cc0d29f0bc..778e387c34a1 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx @@ -202,27 +202,25 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { } /> - - {isVerified ? null : ( - ) => - setUnreviewedChecked(ev.target.checked) - } - /> - } - label={ - - {t('plugin_collectible_approved_by_open_sea')} - - } - /> - )} - + {isVerified ? null : ( + ) => + setUnreviewedChecked(ev.target.checked) + } + /> + } + label={ + + {t('plugin_collectible_approved_by_open_sea')} + + } + /> + )} From e79e0531a4ebe722c7bf38359a908610ac988eaf Mon Sep 17 00:00:00 2001 From: billy Date: Wed, 15 Dec 2021 16:19:15 +0800 Subject: [PATCH 09/10] refactor: use number utils --- .../plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx index 778e387c34a1..7e0749783b25 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx @@ -35,7 +35,7 @@ import { toAsset } from '../helpers' import { PluginTraderMessages } from '../../Trader/messages' import { Trans } from 'react-i18next' import getUnixTime from 'date-fns/getUnixTime' -import { pow10 } from '@masknet/web3-shared-base' +import { rightShift, ZERO } from '@masknet/web3-shared-base/utils/number' const useStyles = makeStyles()((theme) => { return { @@ -76,9 +76,7 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { const isAuction = asset?.value?.is_auction ?? false const isVerified = asset?.value?.is_verified ?? false const leastPrice = - asset?.value && asset.value.orders?.length - ? new BigNumber(asset.value.orders[0].base_price ?? '0') - : new BigNumber('0') + asset?.value && asset.value.orders?.length ? new BigNumber(asset.value.orders[0].base_price ?? '0') : ZERO const paymentTokens = (isAuction ? asset?.value?.offer_payment_tokens : asset?.value?.order_payment_tokens) ?? [] const selectedPaymentToken = first(paymentTokens) @@ -120,7 +118,7 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { }, [open]) const validationMessage = useMemo(() => { - const amount_ = new BigNumber(pow10(token.value?.decimals ?? 0).multipliedBy(amount) ?? '0') + const amount_ = new BigNumber(rightShift(amount, token.value?.decimals) ?? '0') const balance_ = new BigNumber(balance.value ?? '0') if (amount_.isNaN() || amount_.isZero()) return t('plugin_collectible_enter_a_price') if (balance_.isZero() || amount_.isGreaterThan(balance_)) return t('plugin_collectible_insufficient_balance') From 1eaa9cdeac4448774ceb8a16dc31405be0d77c85 Mon Sep 17 00:00:00 2001 From: BillyS <52899576+BillySh1@users.noreply.github.com> Date: Wed, 15 Dec 2021 16:44:41 +0800 Subject: [PATCH 10/10] Update packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com> --- .../mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx index 7e0749783b25..18ea02667f03 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/MakeOfferDialog.tsx @@ -118,7 +118,7 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { }, [open]) const validationMessage = useMemo(() => { - const amount_ = new BigNumber(rightShift(amount, token.value?.decimals) ?? '0') + const amount_ = rightShift(amount, token.value?.decimals) const balance_ = new BigNumber(balance.value ?? '0') if (amount_.isNaN() || amount_.isZero()) return t('plugin_collectible_enter_a_price') if (balance_.isZero() || amount_.isGreaterThan(balance_)) return t('plugin_collectible_insufficient_balance')