From 7615bac922610e651683d7299128fe9dee76143d Mon Sep 17 00:00:00 2001 From: binmax <501711499@qq.com> Date: Fri, 10 May 2024 16:28:05 +0800 Subject: [PATCH 1/3] fix: nig-773 --- src/components/NumberInput.tsx | 5 ++++- src/service/contract/shares.ts | 6 ++++++ src/welcome/Wallet/BuyModal.tsx | 25 +++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/components/NumberInput.tsx b/src/components/NumberInput.tsx index 2a3016a..1999dec 100644 --- a/src/components/NumberInput.tsx +++ b/src/components/NumberInput.tsx @@ -3,6 +3,7 @@ import { TextField } from '@mui/material'; import { debounce } from 'lodash'; const pattern = /^(0|[1-9][0-9]*)(\.[0-9]{0,1})?$/; +const integerPattern = /^[1-9][0-9]*$/; export type NumberInputRef = { reset(): void; @@ -15,6 +16,7 @@ type NumberInputProps = { label?: string; max?: number; min?: number; + integerOnly?: boolean; size?: 'small' | 'medium'; onChange(value: number | null): void; }; @@ -23,6 +25,7 @@ export default forwardRef(function NumberInput max = Number.MAX_SAFE_INTEGER, min = Number.MIN_SAFE_INTEGER, onChange, + integerOnly = false, ...restProps }: NumberInputProps, ref @@ -38,7 +41,7 @@ export default forwardRef(function NumberInput } return; } - if (pattern.test(nextValue)) { + if (integerOnly ? integerPattern.test(nextValue) : pattern.test(nextValue)) { const n = +nextValue; if (n <= max && n >= min) { setValue(nextValue); diff --git a/src/service/contract/shares.ts b/src/service/contract/shares.ts index 770598d..471187a 100644 --- a/src/service/contract/shares.ts +++ b/src/service/contract/shares.ts @@ -93,3 +93,9 @@ export async function transfer(address: string, amount: string) { address, }); } + +export async function getSupply(address: string) { + return await http.get('/xfans/api/shares/supply', { + address, + }); +} diff --git a/src/welcome/Wallet/BuyModal.tsx b/src/welcome/Wallet/BuyModal.tsx index 46d4658..a6ff40f 100644 --- a/src/welcome/Wallet/BuyModal.tsx +++ b/src/welcome/Wallet/BuyModal.tsx @@ -15,6 +15,7 @@ import { getBuyPrice, getBuyPriceAfterFee, getFloorPrice, + getSupply, } from '../../service/contract/shares'; import { getBalance } from '../../service/contract/user'; import useProfileModal from '../../store/useProfileModal'; @@ -70,15 +71,27 @@ const BuyModal = ({ onClose }: BuyModalProps) => { const [balance, setBalance] = useState('0'); const [isBuying, setIsBuying] = useState(false); const [floorPrice, setFloorPrice] = useState('0'); + const [supply, setSupply] = useState(0); const numberInputRef = useRef(null); const [loadingFloorPrice, setLoadingFloorPrice] = useState(true); const [loadingPrice, setLoadingPrice] = useState(false); const [loadingPirceAfterFee, setLoadingPirceAfterFee] = useState(false); const [loadingBalance, setLoadingBalance] = useState(true); + const [loadingSupply, setLoadingSupply] = useState(true); const ethPrice = useETHPrice(); + useEffect(() => { + setLoadingSupply(true); + if (currentInfo?.walletAddress != null) { + getSupply(currentInfo?.walletAddress).then((data) => { + setLoadingSupply(false); + setSupply(+data); + }); + } + }, [currentInfo]); + useEffect(() => { if (amount === 0) { setGasFee('0'); @@ -181,6 +194,11 @@ const BuyModal = ({ onClose }: BuyModalProps) => { }); } + const unit = useMemo(() => { + if (supply <= 5) return 1; + return 0.1; + }, [supply]); + return (
@@ -200,7 +218,8 @@ const BuyModal = ({ onClose }: BuyModalProps) => { className="!mt-6" fullWidth label="Amount" - disabled={isBuying} + integerOnly={unit === 1} + disabled={isBuying || loadingSupply} onChange={(v) => { setAmount(v ?? 0); }} @@ -208,7 +227,9 @@ const BuyModal = ({ onClose }: BuyModalProps) => {
Minimum unit: - 0.1 + + {loadingSupply ? : unit} +
Date: Fri, 10 May 2024 16:34:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E5=BF=98=E4=BA=86=20/=2010?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/contract/shares.ts | 4 +++- src/welcome/Wallet/BuyModal.tsx | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/service/contract/shares.ts b/src/service/contract/shares.ts index 471187a..7ff5c92 100644 --- a/src/service/contract/shares.ts +++ b/src/service/contract/shares.ts @@ -95,7 +95,9 @@ export async function transfer(address: string, amount: string) { } export async function getSupply(address: string) { - return await http.get('/xfans/api/shares/supply', { + const supply = await http.get('/xfans/api/shares/supply', { address, }); + + return +supply / SHARE_UNIT_MODIFIER; } diff --git a/src/welcome/Wallet/BuyModal.tsx b/src/welcome/Wallet/BuyModal.tsx index a6ff40f..34150cb 100644 --- a/src/welcome/Wallet/BuyModal.tsx +++ b/src/welcome/Wallet/BuyModal.tsx @@ -87,7 +87,7 @@ const BuyModal = ({ onClose }: BuyModalProps) => { if (currentInfo?.walletAddress != null) { getSupply(currentInfo?.walletAddress).then((data) => { setLoadingSupply(false); - setSupply(+data); + setSupply(data); }); } }, [currentInfo]); From 6a6d197da7d3550e3f1036209193a9d20e3e5967 Mon Sep 17 00:00:00 2001 From: binmax <501711499@qq.com> Date: Fri, 10 May 2024 16:39:57 +0800 Subject: [PATCH 3/3] fix: review --- src/welcome/Wallet/BuyModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/welcome/Wallet/BuyModal.tsx b/src/welcome/Wallet/BuyModal.tsx index 34150cb..727a398 100644 --- a/src/welcome/Wallet/BuyModal.tsx +++ b/src/welcome/Wallet/BuyModal.tsx @@ -83,8 +83,8 @@ const BuyModal = ({ onClose }: BuyModalProps) => { const ethPrice = useETHPrice(); useEffect(() => { - setLoadingSupply(true); if (currentInfo?.walletAddress != null) { + setLoadingSupply(true); getSupply(currentInfo?.walletAddress).then((data) => { setLoadingSupply(false); setSupply(data);