From 5f54778ff52daea9e957b28efb07e048bb95fc39 Mon Sep 17 00:00:00 2001 From: steveschult Date: Wed, 21 Aug 2024 22:42:48 +0800 Subject: [PATCH] feat: rm nouse & adjust token code --- app/~/space/[id]/(home)/layout.tsx | 4 ++-- app/~/space/[id]/Transaction.tsx | 8 ++----- .../[id]/channel/[channelId]/MessagePanel.tsx | 15 ------------- .../channel/[channelId]/SendMessagePanel.tsx | 1 - components/spaceToken/BuyPanel.tsx | 4 ++-- components/spaceToken/SellBtn.tsx | 4 +--- components/spaceToken/SellPanel.tsx | 21 +++++++------------ lib/socket/socketConnector.ts | 1 - 8 files changed, 14 insertions(+), 44 deletions(-) diff --git a/app/~/space/[id]/(home)/layout.tsx b/app/~/space/[id]/(home)/layout.tsx index 673db0ec..fcac03d6 100644 --- a/app/~/space/[id]/(home)/layout.tsx +++ b/app/~/space/[id]/(home)/layout.tsx @@ -2,7 +2,7 @@ import { ReactNode } from 'react' import { NavbarWrapper } from '@/components/Navbar/NavbarWrapper' -import { useChainSpace, useQueryChainSpace } from '@/hooks/useChainSpace' +import { useChainSpace } from '@/hooks/useChainSpace' import { SpaceInfo } from '../Space/SpaceInfo' import { TradeList } from '../Space/TradeList' import { Transaction } from '../Transaction' @@ -13,7 +13,7 @@ export default function Layout({ children }: { children: ReactNode }) { if (!space) return null return ( -
+
diff --git a/app/~/space/[id]/Transaction.tsx b/app/~/space/[id]/Transaction.tsx index 35bd392b..8bdab102 100644 --- a/app/~/space/[id]/Transaction.tsx +++ b/app/~/space/[id]/Transaction.tsx @@ -1,13 +1,10 @@ 'use client' -import { useEffect, useMemo, useState } from 'react' +import { useState } from 'react' import { BuyPanel } from '@/components/spaceToken/BuyPanel' import { SellPanel } from '@/components/spaceToken/SellPanel' -import { useAddress } from '@/hooks/useAddress' import { useSpace } from '@/hooks/useSpace' -import { precision } from '@/lib/math' -import { Address } from 'viem' -import { useAccount, useBalance } from 'wagmi' +import { useAccount } from 'wagmi' enum Direction { buy = 1, @@ -16,7 +13,6 @@ enum Direction { export function Transaction() { const { space } = useSpace() - const address = useAddress() const { isConnected } = useAccount() const [direction, setDirection] = useState(Direction.buy) diff --git a/app/~/space/[id]/channel/[channelId]/MessagePanel.tsx b/app/~/space/[id]/channel/[channelId]/MessagePanel.tsx index de7a70d2..c81fcc1f 100644 --- a/app/~/space/[id]/channel/[channelId]/MessagePanel.tsx +++ b/app/~/space/[id]/channel/[channelId]/MessagePanel.tsx @@ -1,23 +1,10 @@ import { useEffect, useRef, useState } from 'react' -import { UserAvatar } from '@/components/UserAvatar' -import { useMembers } from '@/hooks/useMembers' import { IMessage, useMessages } from '@/hooks/useMessages' import { trpc } from '@/lib/trpc' -import { shortenAddress } from '@/lib/utils' -import { Member, User } from '@prisma/client' import { toast } from 'sonner' import { useThrottledCallback } from 'use-debounce' import { MessageItem } from './MessageItem' -type MemberWithUser = Member & { - user: { - name: string | null - ensName: string | null - email: string | null - address: string - } -} - interface Props { channelId: string } @@ -90,8 +77,6 @@ export const MessagePanel = ({ channelId }: Props) => { } }, [messages]) - // console.log('%c=render:', 'color:red', getMessagesState(channelId)) - return (
{messages.length ? ( diff --git a/app/~/space/[id]/channel/[channelId]/SendMessagePanel.tsx b/app/~/space/[id]/channel/[channelId]/SendMessagePanel.tsx index dbf54e24..dd515b1f 100644 --- a/app/~/space/[id]/channel/[channelId]/SendMessagePanel.tsx +++ b/app/~/space/[id]/channel/[channelId]/SendMessagePanel.tsx @@ -32,7 +32,6 @@ export const SendMessagePanel = ({ userId, channelId }: Props) => { }) setMsgContent('') - // console.log('%c=isOK ?????', 'color:red', isOk) } else { console.error('SocketConnector not init') toast.error('Connector not init') diff --git a/components/spaceToken/BuyPanel.tsx b/components/spaceToken/BuyPanel.tsx index a163413d..7e4e7f85 100644 --- a/components/spaceToken/BuyPanel.tsx +++ b/components/spaceToken/BuyPanel.tsx @@ -55,7 +55,7 @@ export const BuyPanel = ({ space, isConnected }: Props) => {
Sell
} + icon={ETH} value={ethAmount} onChange={(value) => handleEthChange(value)} /> @@ -80,7 +80,7 @@ export const BuyPanel = ({ space, isConnected }: Props) => { {space.symbolName} } value={tokenAmount} diff --git a/components/spaceToken/SellBtn.tsx b/components/spaceToken/SellBtn.tsx index 74232e41..fb49efa3 100644 --- a/components/spaceToken/SellBtn.tsx +++ b/components/spaceToken/SellBtn.tsx @@ -79,9 +79,7 @@ export const SellBtn = ({ handleSwap() toast.success(`${space?.name} sell successfully!`) } catch (error) { - const msg = extractErrorMessage(error) - console.log('%c=error', 'color:red', error, 'msg', msg) - toast.error(msg) + toast.error(extractErrorMessage(error) || 'sell error') } setLoading(false) } diff --git a/components/spaceToken/SellPanel.tsx b/components/spaceToken/SellPanel.tsx index 388c95b6..528ccba9 100644 --- a/components/spaceToken/SellPanel.tsx +++ b/components/spaceToken/SellPanel.tsx @@ -1,15 +1,12 @@ -import { ChangeEvent, useMemo, useState } from 'react' +import { useState } from 'react' import { useChainSpace, useQueryChainSpace } from '@/hooks/useChainSpace' -import { useEthBalance, useQueryEthBalance } from '@/hooks/useEthBalance' import { precision } from '@/lib/math' import { toFloorFixed } from '@/lib/utils' import { Space } from '@prisma/client' -import { Address } from 'viem' import { Button } from '../ui/button' import { AmountInput } from './AmountInput' import { EthBalance } from './EthBalance' import { - formatAmount, useSpaceTokenBalance, } from './hooks/useSpaceTokenBalance' import { SellBtn } from './SellBtn' @@ -25,15 +22,14 @@ export const SellPanel = ({ space, isConnected }: Props) => { const [tokenAmount, setTokenAmount] = useState('') const { space: chainSpace } = useChainSpace() const { refetch: refetchChainSpace } = useQueryChainSpace() + const { data: tokenBalance } = useSpaceTokenBalance() const isAmountValid = parseFloat(tokenAmount) > 0 - const { data: tokenBalance } = useSpaceTokenBalance() + const isInsufficientBalance = + precision.toDecimal(tokenBalance! || '0') < parseFloat(tokenAmount) - const handleEthAmount = (value: string) => { - // Validate and format input - // if (/^\d*\.?\d*$/.test(value) && !value.startsWith('.')) { } - } + const handleEthAmount = (value: string) => {} const handleTokenChange = (value: string) => { setTokenAmount(value) @@ -61,9 +57,6 @@ export const SellPanel = ({ space, isConnected }: Props) => { setEthAmount(toFloorFixed(ethAmountDecimal, 4).toString()) } - const isInsufficientBalance = - precision.toDecimal(tokenBalance! || '0') < parseFloat(tokenAmount) - return ( <>
@@ -75,7 +68,7 @@ export const SellPanel = ({ space, isConnected }: Props) => { {space.symbolName} } value={tokenAmount} @@ -103,7 +96,7 @@ export const SellPanel = ({ space, isConnected }: Props) => { } + icon={ETH} value={ethAmount} onChange={(value) => handleEthAmount(value)} /> diff --git a/lib/socket/socketConnector.ts b/lib/socket/socketConnector.ts index 130b7ef5..13361f96 100644 --- a/lib/socket/socketConnector.ts +++ b/lib/socket/socketConnector.ts @@ -191,7 +191,6 @@ export class SocketConnector { public disconnect(): void { if (this.socket) { - // console.log('%c=Manually disconnecting WebSocket', 'color:cyan'); this.socket.disconnect() this.connectStatus = { type: ConnectStatusType.disconnect,