From a7dc370b4a6ef6187f48d3a76c15c53e36d1cfd2 Mon Sep 17 00:00:00 2001 From: Dendi Date: Wed, 15 May 2024 13:13:39 +0800 Subject: [PATCH 01/11] update: set default chain Bera --- src/content/loginPage/signInWithXPage.tsx | 2 -- src/store/useGlobalStore.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/content/loginPage/signInWithXPage.tsx b/src/content/loginPage/signInWithXPage.tsx index 427b472..a71f1aa 100644 --- a/src/content/loginPage/signInWithXPage.tsx +++ b/src/content/loginPage/signInWithXPage.tsx @@ -1,7 +1,6 @@ import React, { FC } from 'react'; import { NextButton } from '../../components/buttons/loginButton'; -import TSelect from '../../components/Select/index'; import '../../tailwind.css'; @@ -54,7 +53,6 @@ const SignInWithXPage: FC = ({ handleButtonClick, showLoad 'Login With X' )} - ); }; diff --git a/src/store/useGlobalStore.ts b/src/store/useGlobalStore.ts index a823f3d..76e8fe2 100644 --- a/src/store/useGlobalStore.ts +++ b/src/store/useGlobalStore.ts @@ -52,7 +52,7 @@ const useGlobalStore = create()( }); }, userVote: null, - chain: Chain.Arb, + chain: Chain.Bera, }), { name: 'xfans-user-config', From f174611e9f13525ec9cfd18eeffe1d139ad89ad7 Mon Sep 17 00:00:00 2001 From: Dendi Date: Wed, 15 May 2024 16:15:26 +0800 Subject: [PATCH 02/11] feat: add weth balance --- src/welcome/Wallet/index.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/welcome/Wallet/index.tsx b/src/welcome/Wallet/index.tsx index b70fc2e..ea4ac6e 100644 --- a/src/welcome/Wallet/index.tsx +++ b/src/welcome/Wallet/index.tsx @@ -114,6 +114,10 @@ const Wallet = (props: { back?: () => void; logout?: () => void }) => { +
+ + +
@@ -368,6 +372,14 @@ const Icon = () => ( ); +const BeraIcon = () => ( + Logo +); + const GoBack = () => ( Date: Wed, 15 May 2024 16:54:49 +0800 Subject: [PATCH 03/11] =?UTF-8?q?feat=EF=BC=9Aupdate=20deposit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Select/index.tsx | 39 +++++++++++++++++++++------------ src/welcome/Wallet/Deposit.tsx | 11 +++++++--- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/components/Select/index.tsx b/src/components/Select/index.tsx index 9f0b5f6..7311b66 100644 --- a/src/components/Select/index.tsx +++ b/src/components/Select/index.tsx @@ -1,25 +1,36 @@ -import React from 'react'; +import React, { useState } from 'react'; import { MenuItem, Select, SelectChangeEvent } from '@mui/material'; +interface TSelectProps { + defaultValue: string; + options: string[]; + onChange: (value: string) => void; +} -import { Chain } from '../../config/chainConfig'; -import useGlobalStore from '../../store/useGlobalStore'; +const TSelect: React.FC = ({ defaultValue, options, onChange }) => { + const [currentValue, setCurrentValue] = useState(defaultValue); -const TSelect = () => { - const { chain } = useGlobalStore(); - - const handleInternalChange = (event: SelectChangeEvent) => { - const value = event.target.value as Chain; - useGlobalStore.setState({ chain: value }); + const handleInternalChange = (event: SelectChangeEvent) => { + const value = (event.target.value as string) ?? ''; + setCurrentValue(value); + onChange(value); }; return ( - - value={chain} + + value={currentValue} onChange={handleInternalChange} - style={{ minWidth: '120px', height: '60px' }} + style={{ + height: '60px', + borderRadius: 8, + borderWidth: 0, + borderColor: 'transparent', + fontSize: '15px', + }} + className="bg-[#F7F9FA] py-[18px] pl-[10px] text-base font-medium text-[#1A1D1F]" > - {Chain.Arb} - {Chain.Bera} + {options.map((option: string) => ( + {option} + ))} ); }; diff --git a/src/welcome/Wallet/Deposit.tsx b/src/welcome/Wallet/Deposit.tsx index b16f128..7e2ff5b 100644 --- a/src/welcome/Wallet/Deposit.tsx +++ b/src/welcome/Wallet/Deposit.tsx @@ -5,6 +5,7 @@ import { useToggle } from 'ahooks'; import { BackButton, BasicButton, PrimaryButton } from '../../components/Button'; import Modal from '../../components/Modal'; import * as toaster from '../../components/Toaster'; +import TSelect from '../../components/Select'; import { chainNameMap } from '../../config/chainConfig'; import useGlobalStore from '../../store/useGlobalStore'; import useGlobalUserStore from '../../store/useGlobalUserStore'; @@ -52,9 +53,13 @@ const Deposit = () => {
Asset -
- ETH -
+ { + console.log('Tselect', x); + }} + />
From 07343b05223ebeabf55a178bbb38c1c3c9ea61fb Mon Sep 17 00:00:00 2001 From: Dendi Date: Wed, 15 May 2024 17:24:49 +0800 Subject: [PATCH 04/11] fix: fix weth_balance --- src/content/addToTwitterHome.tsx | 2 +- src/hooks/useAccount.ts | 1 + src/service/contract/user.ts | 2 +- src/service/wallet/index.ts | 1 + src/store/useGlobalUserStore.ts | 2 ++ src/welcome/Wallet/Deposit.tsx | 2 +- src/welcome/Wallet/WithDraw.tsx | 8 ++++++++ src/welcome/Wallet/index.tsx | 7 +++++-- 8 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/content/addToTwitterHome.tsx b/src/content/addToTwitterHome.tsx index 95bff5b..f6b3fe1 100644 --- a/src/content/addToTwitterHome.tsx +++ b/src/content/addToTwitterHome.tsx @@ -122,7 +122,7 @@ export const addUserPagePriceComponent = () => { const elementId = `xfans-userPagePrice-${username}`; const existingElement = document.getElementById(elementId); - console.log(username); + // console.log(username); // 由于个人中心页面有复用,因此在插入之前要删除掉其他price tag const elements = document.querySelectorAll('[id^="xfans-userPagePrice-"]'); elements.forEach((x) => { diff --git a/src/hooks/useAccount.ts b/src/hooks/useAccount.ts index 7ea68ab..ba68785 100644 --- a/src/hooks/useAccount.ts +++ b/src/hooks/useAccount.ts @@ -19,6 +19,7 @@ export default function useAccount() { useGlobalUserStore.setState({ accounts: response.accounts, balance: response.balance, + wETHBalance: response.weth_balance, }); }, }); diff --git a/src/service/contract/user.ts b/src/service/contract/user.ts index 308f492..8be6f9c 100644 --- a/src/service/contract/user.ts +++ b/src/service/contract/user.ts @@ -1,7 +1,7 @@ import { contractRequestHttp as http } from '../request'; export async function getAccounts() { - const accounts = await http.get<{ accounts: string[]; balance: string }>( + const accounts = await http.get<{ accounts: string[]; balance: string; weth_balance: string }>( '/xfans/api/user/accounts' ); return accounts; diff --git a/src/service/wallet/index.ts b/src/service/wallet/index.ts index 8976999..cfc07a2 100644 --- a/src/service/wallet/index.ts +++ b/src/service/wallet/index.ts @@ -10,6 +10,7 @@ const useWalletAccounts = () => { useGlobalUserStore.setState({ accounts: response.accounts, balance: response.balance, + wETHBalance: response.weth_balance, }); }, }); diff --git a/src/store/useGlobalUserStore.ts b/src/store/useGlobalUserStore.ts index ab1820f..0a16ae1 100644 --- a/src/store/useGlobalUserStore.ts +++ b/src/store/useGlobalUserStore.ts @@ -3,11 +3,13 @@ import { create } from 'zustand'; interface GlobalUserStoreProps { accounts: string[]; balance: string; + wETHBalance: string; } const useGlobalUserStore = create((set, get) => ({ accounts: [], balance: '', + wETHBalance: '', })); export default useGlobalUserStore; diff --git a/src/welcome/Wallet/Deposit.tsx b/src/welcome/Wallet/Deposit.tsx index 7e2ff5b..5ebe938 100644 --- a/src/welcome/Wallet/Deposit.tsx +++ b/src/welcome/Wallet/Deposit.tsx @@ -55,7 +55,7 @@ const Deposit = () => { Asset { console.log('Tselect', x); }} diff --git a/src/welcome/Wallet/WithDraw.tsx b/src/welcome/Wallet/WithDraw.tsx index c1a74c9..ce6a41a 100644 --- a/src/welcome/Wallet/WithDraw.tsx +++ b/src/welcome/Wallet/WithDraw.tsx @@ -14,6 +14,7 @@ import { ContractError } from '../../constants'; import useAccount from '../../hooks/useAccount'; import { transfer as transferApi } from '../../service/contract/shares'; import useGlobalStore from '../../store/useGlobalStore'; +import TSelect from '../../components/Select'; const TextField = styled(MTextField)({ width: '493px', @@ -102,6 +103,13 @@ const WithDraw = ({ onClose }: Props) => {

+ { + console.log('Tselect', x); + }} + /> void; logout?: () => void }) => { getUserInfo(); }, []); - const { balance, accounts } = useGlobalUserStore((state) => ({ + const { balance, accounts, wETHBalance } = useGlobalUserStore((state) => ({ ...state, })); @@ -112,7 +112,10 @@ const Wallet = (props: { back?: () => void; logout?: () => void }) => {
- +
From 8abb54dcfbbccf89223ddb399279dff8fcc13d1c Mon Sep 17 00:00:00 2001 From: Dendi Date: Thu, 16 May 2024 12:58:21 +0800 Subject: [PATCH 05/11] feat: add deposit --- src/components/Select/index.tsx | 1 + src/components/icons/ETHIcon.tsx | 10 ++++++++++ src/constants.ts | 5 +++++ src/hooks/useAccount.ts | 3 ++- src/service/contract/shares.ts | 3 ++- src/welcome/Wallet/Deposit.tsx | 9 ++++----- src/welcome/Wallet/WithDraw.tsx | 23 +++++++++++++++-------- src/welcome/Wallet/index.tsx | 9 +-------- 8 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/components/Select/index.tsx b/src/components/Select/index.tsx index 7311b66..3a90d6e 100644 --- a/src/components/Select/index.tsx +++ b/src/components/Select/index.tsx @@ -20,6 +20,7 @@ const TSelect: React.FC = ({ defaultValue, options, onChange }) => value={currentValue} onChange={handleInternalChange} style={{ + width: '100%', height: '60px', borderRadius: 8, borderWidth: 0, diff --git a/src/components/icons/ETHIcon.tsx b/src/components/icons/ETHIcon.tsx index 13d683e..dfa9fe0 100644 --- a/src/components/icons/ETHIcon.tsx +++ b/src/components/icons/ETHIcon.tsx @@ -18,3 +18,13 @@ export default function Icon() { ); } + +export function BeraIcon() { + return ( + Logo + ); +} diff --git a/src/constants.ts b/src/constants.ts index 02843ec..eb7c468 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -16,6 +16,11 @@ export enum ContractError { InsufficientBalance = 'Insufficient Balance', } +export enum Token { + Bera = 'Bera', + WETH = 'WETH', +} + export const XFANS_CONTENT_WIDTH = 433; export const XFANS_MIN_WIDTH = 458; diff --git a/src/hooks/useAccount.ts b/src/hooks/useAccount.ts index ba68785..e042f63 100644 --- a/src/hooks/useAccount.ts +++ b/src/hooks/useAccount.ts @@ -8,7 +8,7 @@ import useUserStore from '../store/useUserStore'; // 账户相关的全局状态 export default function useAccount() { - const { accounts, balance } = useGlobalUserStore(); + const { accounts, balance, wETHBalance } = useGlobalUserStore(); const { userInfo, inviteInfo } = useUserStore((state) => ({ ...state })); const { run: getUserInfo } = useUserInfo(); const { run: getUserInviteInfo } = useUserInvite(); @@ -40,5 +40,6 @@ export default function useAccount() { userInfo, inviteInfo, refresh, + wETHBalance, }; } diff --git a/src/service/contract/shares.ts b/src/service/contract/shares.ts index 7ff5c92..7205b55 100644 --- a/src/service/contract/shares.ts +++ b/src/service/contract/shares.ts @@ -87,10 +87,11 @@ export async function unstake(address: string, amount: number) { amount: BigNumber(amount).times(SHARE_UNIT_MODIFIER).toFixed(), }); } -export async function transfer(address: string, amount: string) { +export async function transfer(address: string, amount: string, token?: string) { await http.post('/xfans/api/shares/transfer', { amount, address, + token, }); } diff --git a/src/welcome/Wallet/Deposit.tsx b/src/welcome/Wallet/Deposit.tsx index 5ebe938..6fa7252 100644 --- a/src/welcome/Wallet/Deposit.tsx +++ b/src/welcome/Wallet/Deposit.tsx @@ -9,6 +9,7 @@ import TSelect from '../../components/Select'; import { chainNameMap } from '../../config/chainConfig'; import useGlobalStore from '../../store/useGlobalStore'; import useGlobalUserStore from '../../store/useGlobalUserStore'; +import { Token } from '../../constants'; const Deposit = () => { const [isOpen, { setLeft: close, setRight: open }] = useToggle(false); @@ -54,11 +55,9 @@ const Deposit = () => {
Asset { - console.log('Tselect', x); - }} + defaultValue={Token.WETH} + options={[Token.WETH, Token.Bera]} + onChange={(x) => {}} />
diff --git a/src/welcome/Wallet/WithDraw.tsx b/src/welcome/Wallet/WithDraw.tsx index ce6a41a..352f544 100644 --- a/src/welcome/Wallet/WithDraw.tsx +++ b/src/welcome/Wallet/WithDraw.tsx @@ -15,6 +15,8 @@ import useAccount from '../../hooks/useAccount'; import { transfer as transferApi } from '../../service/contract/shares'; import useGlobalStore from '../../store/useGlobalStore'; import TSelect from '../../components/Select'; +import { BeraIcon } from '../../components/icons/ETHIcon'; +import { Token } from '../../constants'; const TextField = styled(MTextField)({ width: '493px', @@ -44,11 +46,12 @@ type Props = { }; const WithDraw = ({ onClose }: Props) => { - const { balance, refresh } = useAccount(); + const { balance, refresh, wETHBalance } = useAccount(); const [address, setAddress] = useState(''); const [amount, setAmount] = useState(''); + const [token, setToken] = useState('Bera'); const { chain } = useGlobalStore(); - const { run: transfer, loading } = useRequest(() => transferApi(address, amount), { + const { run: transfer, loading } = useRequest(() => transferApi(address, amount, token), { manual: true, onSuccess() { success('Submitted successfully'); @@ -61,6 +64,10 @@ const WithDraw = ({ onClose }: Props) => { } }, [address]); + const realBalance = useMemo(() => { + return token === Token.Bera ? balance : wETHBalance; + }, [wETHBalance, balance, token]); + function handleAmountChange(nextAmount: string) { if (nextAmount === '') { setAmount(''); @@ -72,7 +79,7 @@ const WithDraw = ({ onClose }: Props) => { } function handleTransferClick() { - if (new BigNumber(balance).isLessThan(amount)) { + if (new BigNumber(realBalance).isLessThan(amount)) { error('Insufficient Balance'); return; } @@ -104,10 +111,10 @@ const WithDraw = ({ onClose }: Props) => {
{ - console.log('Tselect', x); + setToken(x); }} /> {
Wallet Balance:
- + {token === 'Bera' ? : }
diff --git a/src/welcome/Wallet/index.tsx b/src/welcome/Wallet/index.tsx index a1d604b..9b5b060 100644 --- a/src/welcome/Wallet/index.tsx +++ b/src/welcome/Wallet/index.tsx @@ -20,6 +20,7 @@ import useProfileModal from '../../store/useProfileModal'; import Deposit from './Deposit'; import InviteFriends from './InviteFriends'; import WithDraw from './WithDraw'; +import { BeraIcon } from '../../components/icons/ETHIcon'; const Wallet = (props: { back?: () => void; logout?: () => void }) => { const { openProfile } = useProfileModal((state) => ({ ...state })); @@ -375,14 +376,6 @@ const Icon = () => ( ); -const BeraIcon = () => ( - Logo -); - const GoBack = () => ( Date: Thu, 16 May 2024 13:15:40 +0800 Subject: [PATCH 06/11] fix: fix token type --- src/welcome/Wallet/WithDraw.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/welcome/Wallet/WithDraw.tsx b/src/welcome/Wallet/WithDraw.tsx index 352f544..8470131 100644 --- a/src/welcome/Wallet/WithDraw.tsx +++ b/src/welcome/Wallet/WithDraw.tsx @@ -49,7 +49,7 @@ const WithDraw = ({ onClose }: Props) => { const { balance, refresh, wETHBalance } = useAccount(); const [address, setAddress] = useState(''); const [amount, setAmount] = useState(''); - const [token, setToken] = useState('Bera'); + const [token, setToken] = useState(Token.Bera); const { chain } = useGlobalStore(); const { run: transfer, loading } = useRequest(() => transferApi(address, amount, token), { manual: true, @@ -113,7 +113,7 @@ const WithDraw = ({ onClose }: Props) => { { + onChange={(x: any) => { setToken(x); }} /> @@ -136,7 +136,7 @@ const WithDraw = ({ onClose }: Props) => {
Wallet Balance:
- {token === 'Bera' ? : } + {token === Token.Bera ? : } Date: Thu, 16 May 2024 13:24:38 +0800 Subject: [PATCH 07/11] feat: change gas icon --- src/welcome/Wallet/BuyModal.tsx | 5 +++-- src/welcome/Wallet/SellModal.tsx | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/welcome/Wallet/BuyModal.tsx b/src/welcome/Wallet/BuyModal.tsx index 727a398..65aaed4 100644 --- a/src/welcome/Wallet/BuyModal.tsx +++ b/src/welcome/Wallet/BuyModal.tsx @@ -10,6 +10,7 @@ import * as toaster from '../../components/Toaster'; import { ContractError } from '../../constants'; import useAccount from '../../hooks/useAccount'; import { useETHPrice } from '../../hooks/useETHPrice'; +import { BeraIcon } from '../../components/icons/ETHIcon'; import { buyShares, getBuyPrice, @@ -270,7 +271,7 @@ const BuyModal = ({ onClose }: BuyModalProps) => { Transaction Fee
- + { Est. Gas Fee
- + diff --git a/src/welcome/Wallet/SellModal.tsx b/src/welcome/Wallet/SellModal.tsx index 7d63026..9edcc79 100644 --- a/src/welcome/Wallet/SellModal.tsx +++ b/src/welcome/Wallet/SellModal.tsx @@ -10,6 +10,7 @@ import * as toaster from '../../components/Toaster'; import { ContractError, SHARE_UNIT_MODIFIER } from '../../constants'; import useAccount from '../../hooks/useAccount'; import { useETHPrice } from '../../hooks/useETHPrice'; +import { BeraIcon } from '../../components/icons/ETHIcon'; import { getFloorPrice, getSellPrice, @@ -276,7 +277,7 @@ const SellModal = ({ onClose }: SellModalProps) => { Transaction Fee
- + { Est. Gas Fee
- + From c5902a864bd23f8e2d432a7e8ca50af620e3c7ac Mon Sep 17 00:00:00 2001 From: Dendi Date: Thu, 16 May 2024 19:49:59 +0800 Subject: [PATCH 08/11] feat: add buy & sell --- src/service/contract/user.ts | 2 +- src/welcome/Wallet/BuyModal.tsx | 14 ++++++++++++-- src/welcome/Wallet/SellModal.tsx | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/service/contract/user.ts b/src/service/contract/user.ts index 8be6f9c..3207072 100644 --- a/src/service/contract/user.ts +++ b/src/service/contract/user.ts @@ -6,7 +6,7 @@ export async function getAccounts() { ); return accounts; } - +// todo: 建议删除 export async function getBalance() { const balance = await http.get('/xfans/api/user/getBalance'); return balance; diff --git a/src/welcome/Wallet/BuyModal.tsx b/src/welcome/Wallet/BuyModal.tsx index 65aaed4..e97f47e 100644 --- a/src/welcome/Wallet/BuyModal.tsx +++ b/src/welcome/Wallet/BuyModal.tsx @@ -271,7 +271,7 @@ const BuyModal = ({ onClose }: BuyModalProps) => { Transaction Fee
- + {
- + + + + +
diff --git a/src/welcome/Wallet/SellModal.tsx b/src/welcome/Wallet/SellModal.tsx index 9edcc79..eb8fcd1 100644 --- a/src/welcome/Wallet/SellModal.tsx +++ b/src/welcome/Wallet/SellModal.tsx @@ -277,7 +277,7 @@ const SellModal = ({ onClose }: SellModalProps) => { Transaction Fee
- + Date: Fri, 17 May 2024 11:58:11 +0800 Subject: [PATCH 09/11] feat: buy sell modal update --- src/service/contract/user.ts | 10 +++++----- src/welcome/Wallet/BuyModal.tsx | 15 +++++++++------ src/welcome/Wallet/SellModal.tsx | 15 +++++++++------ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/service/contract/user.ts b/src/service/contract/user.ts index 3207072..a2afc65 100644 --- a/src/service/contract/user.ts +++ b/src/service/contract/user.ts @@ -6,8 +6,8 @@ export async function getAccounts() { ); return accounts; } -// todo: 建议删除 -export async function getBalance() { - const balance = await http.get('/xfans/api/user/getBalance'); - return balance; -} +// todo: 建议删除,后端暂时没删除 +// export async function getBalance() { +// const balance = await http.get('/xfans/api/user/getBalance'); +// return balance; +// } diff --git a/src/welcome/Wallet/BuyModal.tsx b/src/welcome/Wallet/BuyModal.tsx index e97f47e..ec36cbb 100644 --- a/src/welcome/Wallet/BuyModal.tsx +++ b/src/welcome/Wallet/BuyModal.tsx @@ -18,7 +18,7 @@ import { getFloorPrice, getSupply, } from '../../service/contract/shares'; -import { getBalance } from '../../service/contract/user'; +import { getAccounts } from '../../service/contract/user'; import useProfileModal from '../../store/useProfileModal'; import { formatDollar } from '../../utils'; @@ -70,6 +70,7 @@ const BuyModal = ({ onClose }: BuyModalProps) => { const [amount, setAmount] = useState(0); const [priceAfterFee, setPriceAfterFee] = useState('0'); const [balance, setBalance] = useState('0'); + const [WETHbalance, setWETHBalance] = useState('0'); const [isBuying, setIsBuying] = useState(false); const [floorPrice, setFloorPrice] = useState('0'); const [supply, setSupply] = useState(0); @@ -134,9 +135,10 @@ const BuyModal = ({ onClose }: BuyModalProps) => { useEffect(() => { if (wallet) { setLoadingBalance(true); - getBalance().then((balance) => { + getAccounts().then((result) => { setLoadingBalance(false); - setBalance(balance); + setBalance(result.balance); + setWETHBalance(result.weth_balance); }); } }, [wallet]); @@ -166,9 +168,10 @@ const BuyModal = ({ onClose }: BuyModalProps) => { numberInputRef.current?.reset(); refreshAccount(); setLoadingBalance(true); - getBalance().then((balance) => { + getAccounts().then((result) => { setLoadingBalance(false); - setBalance(balance); + setBalance(result.balance); + setWETHBalance(result.weth_balance); }); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion setLoadingFloorPrice(true); @@ -330,7 +333,7 @@ const BuyModal = ({ onClose }: BuyModalProps) => {
- +
diff --git a/src/welcome/Wallet/SellModal.tsx b/src/welcome/Wallet/SellModal.tsx index eb8fcd1..acc1760 100644 --- a/src/welcome/Wallet/SellModal.tsx +++ b/src/welcome/Wallet/SellModal.tsx @@ -18,7 +18,7 @@ import { getSharesBalance, sellShares, } from '../../service/contract/shares'; -import { getBalance } from '../../service/contract/user'; +import { getAccounts } from '../../service/contract/user'; import useProfileModal from '../../store/useProfileModal'; import { formatDollar } from '../../utils'; @@ -70,6 +70,7 @@ const SellModal = ({ onClose }: SellModalProps) => { const [amount, setAmount] = useState(0); const [priceAfterFee, setPriceAfterFee] = useState('0'); const [balance, setBalance] = useState('0'); + const [WETHbalance, setWETHBalance] = useState('0'); const [shareBalance, setShareBalance] = useState('0'); const [isSelling, setIsSelling] = useState(false); const [floorPrice, setFloorPrice] = useState('0'); @@ -135,9 +136,10 @@ const SellModal = ({ onClose }: SellModalProps) => { useEffect(() => { if (wallet) { setLoadingBalance(true); - getBalance().then((balance) => { + getAccounts().then((result) => { setLoadingBalance(false); - setBalance(balance); + setBalance(result.balance); + setWETHBalance(result.weth_balance); }); } }, [wallet]); @@ -164,9 +166,10 @@ const SellModal = ({ onClose }: SellModalProps) => { }); setLoadingBalance(true); - getBalance().then((balance) => { + getAccounts().then((result) => { setLoadingBalance(false); - setBalance(balance); + setBalance(result.balance); + setWETHBalance(result.weth_balance); }); setLoadingFloorPrice(true); @@ -329,7 +332,7 @@ const SellModal = ({ onClose }: SellModalProps) => {
- +
From b89e1653ac9da5cba10201e92de6a0360175bd37 Mon Sep 17 00:00:00 2001 From: Dendi Date: Fri, 17 May 2024 15:57:02 +0800 Subject: [PATCH 10/11] feat: apply bera price --- src/hooks/useETHPrice.ts | 14 ++++++++++++++ src/service/share/index.ts | 28 +++++++++++++++++----------- src/store/useShareStore.ts | 2 ++ src/welcome/Wallet/BuyModal.tsx | 6 +++--- src/welcome/Wallet/SellModal.tsx | 5 +++-- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/hooks/useETHPrice.ts b/src/hooks/useETHPrice.ts index 7e3c3ca..1816f70 100644 --- a/src/hooks/useETHPrice.ts +++ b/src/hooks/useETHPrice.ts @@ -16,3 +16,17 @@ export function useETHPrice() { return ethPrice?.price ?? 0; } + +/** + * 获取最新 eth 价格 + */ +export function useBeraPrice() { + const { run: getPrice } = useEthPriceService(); + const { beraPrice } = useShareStore((state) => ({ ...state })); + + useEffect(() => { + getPrice(); + }, [getPrice]); + + return beraPrice?.price ?? 0; +} diff --git a/src/service/share/index.ts b/src/service/share/index.ts index 948e685..f84dcd7 100644 --- a/src/service/share/index.ts +++ b/src/service/share/index.ts @@ -94,17 +94,23 @@ const useHolderList = () => { }; const useEthPrice = () => { - const result = useRequest, unknown[]>( - () => http.get('/api/share/eth-price'), - { - manual: true, - onSuccess(response) { - useShareStore.setState({ - ethPrice: response.data, - }); - }, - } - ); + const result = useRequest< + ResultData<{ items: { id: number; symbol: string; price: number }[] }>, + unknown[] + >(() => http.get('/api/share/prices'), { + manual: true, + onSuccess(response) { + const ethPrice = response.data.items.find((x) => x.symbol === 'eth'); + const beraPrice = response.data.items.find((x) => x.symbol === 'bera'); + + console.log('eth-prices', response, ethPrice, beraPrice); + + useShareStore.setState({ + ethPrice: ethPrice, + beraPrice: beraPrice, + }); + }, + }); return result; }; diff --git a/src/store/useShareStore.ts b/src/store/useShareStore.ts index 82e2840..6b25813 100644 --- a/src/store/useShareStore.ts +++ b/src/store/useShareStore.ts @@ -10,6 +10,7 @@ interface ShareStoreProps { holderingList: HolderProps[] | null; holderingListTotal: number; ethPrice: { id: number; symbol: string; price: number } | null; + beraPrice: { id: number; symbol: string; price: number } | null; } const useShareStore = create((set) => ({ @@ -22,6 +23,7 @@ const useShareStore = create((set) => ({ holderingList: null, holderingListTotal: 0, ethPrice: null, + beraPrice: null, })); export default useShareStore; diff --git a/src/welcome/Wallet/BuyModal.tsx b/src/welcome/Wallet/BuyModal.tsx index ec36cbb..fbb96de 100644 --- a/src/welcome/Wallet/BuyModal.tsx +++ b/src/welcome/Wallet/BuyModal.tsx @@ -9,7 +9,7 @@ import NumberInput, { NumberInputRef } from '../../components/NumberInput'; import * as toaster from '../../components/Toaster'; import { ContractError } from '../../constants'; import useAccount from '../../hooks/useAccount'; -import { useETHPrice } from '../../hooks/useETHPrice'; +import { useBeraPrice, useETHPrice } from '../../hooks/useETHPrice'; import { BeraIcon } from '../../components/icons/ETHIcon'; import { buyShares, @@ -83,7 +83,7 @@ const BuyModal = ({ onClose }: BuyModalProps) => { const [loadingSupply, setLoadingSupply] = useState(true); const ethPrice = useETHPrice(); - + const beraPrice = useBeraPrice(); useEffect(() => { if (currentInfo?.walletAddress != null) { setLoadingSupply(true); @@ -294,7 +294,7 @@ const BuyModal = ({ onClose }: BuyModalProps) => {
- {formatDollar(gasFee, ethPrice)} + {formatDollar(gasFee, beraPrice)}
diff --git a/src/welcome/Wallet/SellModal.tsx b/src/welcome/Wallet/SellModal.tsx index acc1760..46dbc94 100644 --- a/src/welcome/Wallet/SellModal.tsx +++ b/src/welcome/Wallet/SellModal.tsx @@ -9,7 +9,7 @@ import NumberInput, { NumberInputRef } from '../../components/NumberInput'; import * as toaster from '../../components/Toaster'; import { ContractError, SHARE_UNIT_MODIFIER } from '../../constants'; import useAccount from '../../hooks/useAccount'; -import { useETHPrice } from '../../hooks/useETHPrice'; +import { useETHPrice, useBeraPrice } from '../../hooks/useETHPrice'; import { BeraIcon } from '../../components/icons/ETHIcon'; import { getFloorPrice, @@ -83,6 +83,7 @@ const SellModal = ({ onClose }: SellModalProps) => { const [loadingSharesBalance, setLoadingSharesBalance] = useState(true); const ethPrice = useETHPrice(); + const beraPrice = useBeraPrice(); useEffect(() => { if (amount === 0) { @@ -300,7 +301,7 @@ const SellModal = ({ onClose }: SellModalProps) => {
- {formatDollar(gasFee, ethPrice)} + {formatDollar(gasFee, beraPrice)}
From 2c4b4488c547eedd8d8a657518e1dc13b2aa8df1 Mon Sep 17 00:00:00 2001 From: Dendi Date: Mon, 20 May 2024 16:15:44 +0800 Subject: [PATCH 11/11] fix:clear select border ui update --- src/components/Select/index.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/Select/index.tsx b/src/components/Select/index.tsx index 3a90d6e..a1a36f4 100644 --- a/src/components/Select/index.tsx +++ b/src/components/Select/index.tsx @@ -21,12 +21,16 @@ const TSelect: React.FC = ({ defaultValue, options, onChange }) => onChange={handleInternalChange} style={{ width: '100%', - height: '60px', + height: '58.5px', borderRadius: 8, - borderWidth: 0, - borderColor: 'transparent', fontSize: '15px', }} + sx={{ + border: 'none', + '& .MuiOutlinedInput-notchedOutline': { + border: 'none', + }, + }} className="bg-[#F7F9FA] py-[18px] pl-[10px] text-base font-medium text-[#1A1D1F]" > {options.map((option: string) => (