Skip to content

Commit

Permalink
fix: disable register button if balance is less than bond amount
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed Jun 11, 2024
1 parent 843e7af commit ec14fb4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/api/subsquid-network-squid/settings-graphql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fromSqd, toSqd } from '@lib/network';
import { toSqd } from '@lib/network';

import { useSquidDataSource } from './datasource';
import { useSettingsQuery } from './graphql';
Expand All @@ -9,13 +9,11 @@ export function useNetworkSettings() {

const settings = data?.settingsConnection.edges?.[0]?.node;
const bondAmount = settings?.bondAmount ? settings?.bondAmount : toSqd(100_000);
const delegationLimitInBp = settings?.delegationLimitCoefficient || 0.2;
const minimalWorkerVersion = settings?.minimalWorkerVersion || '>=0.0.0';
const recommendedWorkerVersion = settings?.recommendedWorkerVersion || '>=0.0.0';

return {
bondAmount,
delegationLimit: toSqd(fromSqd(bondAmount).times(delegationLimitInBp)),
minimalWorkerVersion,
recommendedWorkerVersion,
isPending,
Expand Down
10 changes: 7 additions & 3 deletions src/pages/WorkersPage/AddNewWorker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ function AddWorkerForm() {
return (
(formik.values.source
? sources.find(c => c.id === formik.values.source)
: sources.find(c => fromSqd(c.balance).gte(0))) || sources?.[0]
: sources.find(c => fromSqd(c.balance).gte(fromSqd(bondAmount)))) || sources?.[0]
);
}, [formik.values.source, isContractsLoading, isSettingsLoading, sources]);
}, [bondAmount, formik.values.source, isContractsLoading, isSettingsLoading, sources]);

useEffect(() => {
if (!source) return;
Expand Down Expand Up @@ -189,7 +189,11 @@ function AddWorkerForm() {
<BlockchainContractError error={error} />
</Card>
<Box mt={2.5} justifyContent="flex-end" display="flex">
<LoadingButton disabled={isLoading} variant="contained" type="submit">
<LoadingButton
disabled={isLoading || fromSqd(source?.balance || 0).lt(fromSqd(bondAmount))}
variant="contained"
type="submit"
>
Register
</LoadingButton>
</Box>
Expand Down

0 comments on commit ec14fb4

Please sign in to comment.