Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: if new user didn't login to consumer-host then skip the login. Change to more friendly error tips, fix re-delegate capacity & tips. #698

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 17 additions & 2 deletions src/components/CreateFlexPlan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,13 @@ const CreateFlexPlan: FC<IProps> = ({ deploymentId, project, prevHostingPlan, pr
<>
<Typography>You must deposit SQT to open this billing account</Typography>
<Typography variant="medium" type="secondary">
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}
</Typography>
</>
) : (
Expand Down Expand Up @@ -483,7 +489,16 @@ const CreateFlexPlan: FC<IProps> = ({ deploymentId, project, prevHostingPlan, pr
<Form.Item
label={<Typography>Deposit amount</Typography>}
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();
},
},
]}
>
<InputNumber
placeholder="Enter amount"
Expand Down
10 changes: 10 additions & 0 deletions src/components/GetEndpoint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,17 @@ const GetEndpoint: FC<IProps> = ({ deploymentId, project }) => {
data: [],
},
};
} else {
return {
hostingPlan: {
data: [],
},
apiKeys: {
data: [],
},
};
}

const apiKeys = await getUserApiKeysApi();
if (!isConsumerHostError(apiKeys.data)) {
setUserApiKeys(apiKeys.data);
Expand Down
3 changes: 3 additions & 0 deletions src/components/TokenTooltip/TokenTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ interface IProps {

const TokenTooltip: FC<IProps> = (props) => {
const { ethSqtBalance } = useSQToken();
if (ethSqtBalance.result.loading) return null;
if (ethSqtBalance.result.error) return null;
if (ethSqtBalance.result.data?.isZero()) return null;
return (
<Tooltip
overlayClassName={styles.tokenTooltip}
Expand Down
8 changes: 4 additions & 4 deletions src/config/rainbowConf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useEthersProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
69 changes: 44 additions & 25 deletions src/pages/delegator/DoDelegate/DelegateFrom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -124,6 +125,14 @@ export const DelegateForm: React.FC<FormProps> = ({

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;

Expand All @@ -135,11 +144,13 @@ export const DelegateForm: React.FC<FormProps> = ({
}

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') {
Expand All @@ -159,15 +170,32 @@ export const DelegateForm: React.FC<FormProps> = ({
});
}, [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 delegated =
styleMode === 'normal' ? delegatedAmount : formatSQT(getIndexerDelegation()?.after?.toString() || '0');
const zeroCapacity = React.useMemo(() => {
return BigNumberJs(capacityMemo.toString()).isZero();
}, [capacityMemo]);

const delegatedAmountMemo = React.useMemo(() => {
return styleMode === 'normal' ? delegatedAmount : formatSQT(getIndexerDelegation()?.after?.toString() || '0');
}, [delegatedAmount, getIndexerDelegation]);

const summaryList = React.useMemo(() => {
return [
{
label: t('delegate.to'),
Expand All @@ -184,20 +212,20 @@ export const DelegateForm: React.FC<FormProps> = ({
},
{
label: t('delegate.remainingCapacity'),
value: ` ${formatEther(capacity, 4)} ${TOKEN}`,
value: ` ${formatEther(capacityMemo, 4)} ${TOKEN}`,
tooltip: t('delegate.remainingTooltip'),
},
{
label: t('delegate.existingDelegation'),
value: ` ${delegated} ${TOKEN}`,
value: ` ${delegatedAmountMemo} ${TOKEN}`,
tooltip: t('delegate.existingDelegationTooltip'),
},
].filter((i) => {
if (styleMode === 'normal') return true;
if (styleMode === 'reDelegate' && i.key === 'indexerInfo') return false;
return true;
});
}, [indexerCapacity, delegatedAmount, styleMode, indexerAddress, selectedOption, getIndexerDelegation]);
}, [capacityMemo, delegatedAmountMemo, indexerAddress]);

const initDelegations = async () => {
if (!account) return;
Expand Down Expand Up @@ -410,23 +438,14 @@ export const DelegateForm: React.FC<FormProps> = ({
<Alert
className={styles.alertInfo}
type="info"
message={
isYourself
? t('delegate.delegateFromYourselfInfo', {
indexerName: indexerMetadata.name,
})
: t('delegate.redelegateInfo', {
reIndexerName: selectedOption?.name,
indexerName: indexerMetadata.name,
})
}
message={alertInfoText}
showIcon
style={{
marginBottom: 32,
}}
></Alert>

{styleMode === 'normal' && (
{styleMode === 'normal' && !BigNumberJs(delegatedAmountMemo).isZero() && (
<div className="flex" style={{ justifyContent: 'space-between', marginBottom: 24 }}>
<Typography type="secondary" variant="medium">
Total Delegation to {indexerMetadata.name} after change
Expand All @@ -445,7 +464,7 @@ export const DelegateForm: React.FC<FormProps> = ({
<Button
onClick={submitForm}
loading={isSubmitting}
disabled={!isValid || isSubmitting}
disabled={zeroCapacity || !isValid || isSubmitting}
className={clsx(styles.button, !isValid || isSubmitting ? styles.disabledButton : '')}
type="primary"
shape="round"
Expand Down
Loading