From 165e41a862dc200262144aed88bc52550e8a424b Mon Sep 17 00:00:00 2001 From: cyrbuzz Date: Tue, 26 Mar 2024 10:35:16 +0800 Subject: [PATCH 1/5] fix: improve login --- src/components/CreateFlexPlan/index.tsx | 19 +++++++++++++++++-- src/components/GetEndpoint/index.tsx | 10 ++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/components/CreateFlexPlan/index.tsx b/src/components/CreateFlexPlan/index.tsx index db29b1bdc..d79220eea 100644 --- a/src/components/CreateFlexPlan/index.tsx +++ b/src/components/CreateFlexPlan/index.tsx @@ -454,7 +454,13 @@ const CreateFlexPlan: FC = ({ deploymentId, project, prevHostingPlan, pr <> You must deposit SQT to open this billing account - You must deposit SQT to create this flex plan + You must deposit SQT to create this flex plan, we suggest{' '} + {BigNumberJs(form.getFieldValue('price') || '0') + .multipliedBy(20) + .multipliedBy(form.getFieldValue('maximum') || 2) + .toNumber() + .toLocaleString()}{' '} + {TOKEN} ) : ( @@ -483,7 +489,16 @@ const CreateFlexPlan: FC = ({ deploymentId, project, prevHostingPlan, pr Deposit amount} name="amount" - rules={[{ type: 'number', required: true, min: 500 }]} + rules={[ + { type: 'number', required: true, min: 500, message: 'The minimum deposit can not be less than 500 SQT' }, + { + validator: (_, value) => { + return BigNumberJs(value).gt(formatSQT(balance.result.data?.toString() || '0')) + ? Promise.reject('Insufficient amount') + : Promise.resolve(); + }, + }, + ]} > = ({ deploymentId, project }) => { data: [], }, }; + } else { + return { + hostingPlan: { + data: [], + }, + apiKeys: { + data: [], + }, + }; } + const apiKeys = await getUserApiKeysApi(); if (!isConsumerHostError(apiKeys.data)) { setUserApiKeys(apiKeys.data); From f88aa0ac7de3387ec777c7bff88d32346a7d32fa Mon Sep 17 00:00:00 2001 From: cyrbuzz Date: Tue, 26 Mar 2024 10:59:22 +0800 Subject: [PATCH 2/5] fix: use env variable --- .env | 2 ++ src/config/rainbowConf.tsx | 8 ++++---- src/hooks/useEthersProvider.ts | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.env b/.env index e3d32b08a..8e4c6dd69 100644 --- a/.env +++ b/.env @@ -8,3 +8,5 @@ VITE_GQL_PROXY=https://gql-proxy.subquery.network VITE_AUTH_URL=https://auth.subquery.network VITE_NETWORK_DEPLOYMENT_ID=QmdfKqUt4rNDoV71MprAwTheQNfL7uUk1unyt5oCAnZFdK VITE_PROXYGATEWAY=https://gateway.subquery.network +VITE_SUBQUERY_OFFICIAL_BASE_RPC=https://gateway.subquery.network/rpc/base +VITE_SUBQUERY_OFFICIAL_ETH_RPC=https://gateway.subquery.network/rpc/eth diff --git a/src/config/rainbowConf.tsx b/src/config/rainbowConf.tsx index 008531fd2..03c91e17b 100644 --- a/src/config/rainbowConf.tsx +++ b/src/config/rainbowConf.tsx @@ -25,10 +25,10 @@ const supportedChains = ...base, rpcUrls: { default: { - http: ['https://gateway.subquery.network/rpc/base'], + http: [import.meta.env.VITE_SUBQUERY_OFFICIAL_BASE_RPC], }, public: { - http: ['https://gateway.subquery.network/rpc/base'], + http: [import.meta.env.VITE_SUBQUERY_OFFICIAL_BASE_RPC], }, fallback: { http: base.rpcUrls.default.http, @@ -39,10 +39,10 @@ const supportedChains = ...mainnet, rpcUrls: { default: { - http: ['https://gateway.subquery.network/rpc/eth'], + http: [import.meta.env.VITE_SUBQUERY_OFFICIAL_ETH_RPC], }, public: { - http: ['https://gateway.subquery.network/rpc/eth'], + http: [import.meta.env.VITE_SUBQUERY_OFFICIAL_ETH_RPC], }, fallback: { http: mainnet.rpcUrls.default.http, diff --git a/src/hooks/useEthersProvider.ts b/src/hooks/useEthersProvider.ts index f5be81055..2b631b603 100644 --- a/src/hooks/useEthersProvider.ts +++ b/src/hooks/useEthersProvider.ts @@ -48,8 +48,8 @@ export function walletClientToSignerAndProvider(walletClient: WalletClient) { async request(request, ...rest) { try { const fetchUrl = { - [base.id]: 'https://gateway.subquery.network/rpc/base', - [mainnet.id]: 'https://gateway.subquery.network/rpc/eth', + [base.id]: import.meta.env.VITE_SUBQUERY_OFFICIAL_BASE_RPC, + [mainnet.id]: import.meta.env.VITE_SUBQUERY_OFFICIAL_ETH_RPC, }[chain.id]; if (fetchUrl) { requestId += 1; From 716dce16486e12da6be2cd5e3ce224223bdd68a2 Mon Sep 17 00:00:00 2001 From: cyrbuzz Date: Tue, 26 Mar 2024 11:04:34 +0800 Subject: [PATCH 3/5] fix: hide token tooltip --- src/components/TokenTooltip/TokenTooltip.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/TokenTooltip/TokenTooltip.tsx b/src/components/TokenTooltip/TokenTooltip.tsx index c20ff48b9..17b5ac40f 100644 --- a/src/components/TokenTooltip/TokenTooltip.tsx +++ b/src/components/TokenTooltip/TokenTooltip.tsx @@ -20,6 +20,9 @@ interface IProps { const TokenTooltip: FC = (props) => { const { ethSqtBalance } = useSQToken(); + if (ethSqtBalance.result.loading) return null; + if (ethSqtBalance.result.error) return null; + if (ethSqtBalance.result.data?.isZero()) return null; return ( Date: Tue, 26 Mar 2024 12:05:31 +0800 Subject: [PATCH 4/5] fix: improve delegate form --- .../delegator/DoDelegate/DelegateFrom.tsx | 60 ++++++++++++------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/src/pages/delegator/DoDelegate/DelegateFrom.tsx b/src/pages/delegator/DoDelegate/DelegateFrom.tsx index 17f2548e1..702013d76 100644 --- a/src/pages/delegator/DoDelegate/DelegateFrom.tsx +++ b/src/pages/delegator/DoDelegate/DelegateFrom.tsx @@ -18,6 +18,7 @@ import { import { limitQueue } from '@utils/limitation'; import { Alert, Button, Divider, Select, Tooltip } from 'antd'; import BignumberJs from 'bignumber.js'; +import BigNumberJs from 'bignumber.js'; import clsx from 'clsx'; import { BigNumber, BigNumberish } from 'ethers'; import { Form, Formik } from 'formik'; @@ -124,6 +125,14 @@ export const DelegateForm: React.FC = ({ const isYourself = React.useMemo(() => delegateFrom === account, [account, delegateFrom]); + const capacityMemo = React.useMemo( + () => + styleMode === 'normal' + ? indexerCapacity + : allIndexers.find((i) => i.id === selectedOption?.value)?.capacity?.valueAfter?.value.toString() || '0', + [indexerCapacity, allIndexers, selectedOption], + ); + const sortedMaxAmount = React.useMemo(() => { let maxAmount: BigNumberish | undefined; @@ -135,11 +144,13 @@ export const DelegateForm: React.FC = ({ } if (styleMode === 'reDelegate') { - return delegatedAmount ?? '0'; + return BigNumberJs(formatSQT(capacityMemo)).gt(delegatedAmount || '0') + ? delegatedAmount + : formatSQT(capacityMemo) ?? '0'; } - return formatEther(maxAmount?.gt(indexerCapacity) ? indexerCapacity : maxAmount) ?? '0'; - }, [isYourself, balance, getIndexerDelegation, delegatedAmount, styleMode]); + return formatEther(maxAmount?.gt(capacityMemo) ? capacityMemo : maxAmount) ?? '0'; + }, [isYourself, balance, getIndexerDelegation, delegatedAmount, styleMode, capacityMemo]); const maxAmountText = React.useMemo(() => { if (isYourself && styleMode !== 'reDelegate') { @@ -159,12 +170,28 @@ export const DelegateForm: React.FC = ({ }); }, [isYourself, sortedMaxAmount, TOKEN, balance, styleMode]); - const summaryList = React.useMemo(() => { - const capacity = - styleMode === 'normal' - ? indexerCapacity - : allIndexers.find((i) => i.id === selectedOption?.value)?.capacity?.valueAfter?.value.toString() || '0'; + const alertInfoText = React.useMemo(() => { + if (isYourself) + return t('delegate.delegateFromYourselfInfo', { + indexerName: indexerMetadata.name, + }); + if (styleMode === 'normal') { + return t('delegate.redelegateInfo', { + reIndexerName: selectedOption?.name, + indexerName: indexerMetadata.name, + }); + } + return t('delegate.redelegateInfo', { + reIndexerName: indexerMetadata.name, + indexerName: selectedOption?.name, + }); + }, [isYourself, styleMode, indexerMetadata.name, selectedOption?.name]); + + const zeroCapacity = React.useMemo(() => { + return BigNumberJs(capacityMemo.toString()).isZero(); + }, [capacityMemo]); + const summaryList = React.useMemo(() => { const delegated = styleMode === 'normal' ? delegatedAmount : formatSQT(getIndexerDelegation()?.after?.toString() || '0'); @@ -184,7 +211,7 @@ export const DelegateForm: React.FC = ({ }, { label: t('delegate.remainingCapacity'), - value: ` ${formatEther(capacity, 4)} ${TOKEN}`, + value: ` ${formatEther(capacityMemo, 4)} ${TOKEN}`, tooltip: t('delegate.remainingTooltip'), }, { @@ -197,7 +224,7 @@ export const DelegateForm: React.FC = ({ if (styleMode === 'reDelegate' && i.key === 'indexerInfo') return false; return true; }); - }, [indexerCapacity, delegatedAmount, styleMode, indexerAddress, selectedOption, getIndexerDelegation]); + }, [capacityMemo, delegatedAmount, styleMode, indexerAddress, getIndexerDelegation]); const initDelegations = async () => { if (!account) return; @@ -410,16 +437,7 @@ export const DelegateForm: React.FC = ({ = ({