Skip to content

Commit

Permalink
(govern) chore: review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Atatakai authored and Atatakai committed Aug 27, 2024
1 parent 0bf812e commit fde79af
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 61 deletions.
27 changes: 13 additions & 14 deletions apps/govern/common-util/functions/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ import { Abi, AbiFunction, TransactionReceipt, parseUnits } from 'viem';
import { Address } from 'viem';
import { mainnet } from 'viem/chains';



import { sendTransaction } from '@autonolas/frontend-library';



import { SERVICE_REGISTRY, STAKING_FACTORY, VE_OLAS } from 'libs/util-contracts/src/lib/abiAndAddresses';
import {
SERVICE_REGISTRY,
STAKING_FACTORY,
VE_OLAS,
} from 'libs/util-contracts/src/lib/abiAndAddresses';
import { getEstimatedGasLimit } from 'libs/util-functions/src';



import { SUPPORTED_CHAINS, wagmiConfig } from 'common-util/config/wagmi';
import { RPC_URLS } from 'common-util/constants/rpcs';



import { getAddressFromBytes32 } from './addresses';
import { getUnixNextWeekStartTimestamp } from './time';
import { getOlasContract, getTokenomicsContract, getTreasuryContract, getVeOlasContract, getVoteWeightingContract } from './web3';

import {
getOlasContract,
getTokenomicsContract,
getTreasuryContract,
getVeOlasContract,
getVoteWeightingContract,
} from './web3';

type VoteForNomineeWeightsParams = {
account: Address | undefined;
Expand Down Expand Up @@ -323,7 +324,6 @@ export const checkpointRequest = async ({ account }: { account: Address }) => {
/**
* Check services are eligible for donating
*/

export const checkServicesTerminatedOrNotDeployed = async (ids: string[]) => {
const invalidServiceIds: string[] = [];

Expand Down Expand Up @@ -355,7 +355,6 @@ export const checkServicesTerminatedOrNotDeployed = async (ids: string[]) => {
/**
* Donate to services
*/

export const depositServiceDonationRequest = async ({
account,
serviceIds,
Expand Down Expand Up @@ -384,4 +383,4 @@ export const depositServiceDonationRequest = async ({
window.console.log('Error occurred on depositing service donation');
throw error;
}
};
};
15 changes: 8 additions & 7 deletions apps/govern/common-util/functions/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { mainnet } from 'viem/chains';
import Web3 from 'web3';
import { AbiItem } from 'web3-utils';



import { OLAS, TOKENOMICS, TREASURY, VE_OLAS, VOTE_WEIGHTING } from 'libs/util-contracts/src/lib/abiAndAddresses';


import {
OLAS,
TOKENOMICS,
TREASURY,
VE_OLAS,
VOTE_WEIGHTING,
} from 'libs/util-contracts/src/lib/abiAndAddresses';

import { getChainId, getProvider } from 'common-util/functions/frontend-library';


/**
* returns the web3 details
*/
Expand Down Expand Up @@ -64,4 +65,4 @@ export const getTreasuryContract = () => {
const address = TREASURY.addresses[mainnet.id];
const contract = getContract(abi, address);
return contract;
};
};
22 changes: 10 additions & 12 deletions apps/govern/components/Donate/DonateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ export const DonateForm = ({ isLoading, onSubmit }: DonateFormProps) => {
const inputStyle = screens.xs ? { width: '140px' } : { width: 'auto' };

const onFinish = async (values: { units: { unitId: number; amount: number }[] }) => {
if (onSubmit) {
try {
await onSubmit({
unitIds: values.units.map((unit) => unit.unitId),
amounts: values.units.map((unit) => unit.amount),
});
try {
await onSubmit({
unitIds: values.units.map((unit) => unit.unitId),
amounts: values.units.map((unit) => unit.amount),
});

form.resetFields();
} catch (error) {
window.console.error(error);
}
form.resetFields();
} catch (error) {
window.console.error(error);
}
};

Expand Down Expand Up @@ -103,15 +101,15 @@ export const DonateForm = ({ isLoading, onSubmit }: DonateFormProps) => {
<Form.ErrorList errors={errors} />

<Form.Item wrapperCol={{ span: 6 }}>
<Button size="large" onClick={() => add()} block icon={<PlusOutlined />}>
<Button size="large" onClick={add} block icon={<PlusOutlined />}>
Add row
</Button>
</Form.Item>
</>
)}
</Form.List>

<Form.Item>
<Form.Item className="mb-0">
<Button
size="large"
type="primary"
Expand Down
43 changes: 30 additions & 13 deletions apps/govern/components/Donate/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import { useCallback, useMemo } from 'react';
import { mainnet } from 'viem/chains';
import { useReadContract } from 'wagmi';



import { TOKENOMICS, TREASURY } from 'libs/util-contracts/src/lib/abiAndAddresses';


const useVeOLASThreshold = () =>
useReadContract({
address: TOKENOMICS.addresses[mainnet.id],
Expand Down Expand Up @@ -56,12 +53,26 @@ const useEpochLength = () =>
});

export const useThresholdData = () => {
const { data: veOLASThreshold, isFetching: isVeOLASThresholdFetching, refetch: refetchVeOLASThreshold } = useVeOLASThreshold();
const { data: minAcceptedETH, isFetching: isMinAcceptedETHFetching, refetch: refetchMinAcceptedETH } = useMinAcceptedETH();
const { data: epochCounter, isFetching: isEpochCounterFetching, refetch: refetchEpochCounter } = useEpochCounter();
const { data: prevEpochPoint, isFetching: isPrevEpochPointFetching, refetch: refetchPrevEpochPoint } = useEpochTokenomics(
epochCounter !== undefined ? Number(epochCounter) - 1 : undefined,
);
const {
data: veOLASThreshold,
isFetching: isVeOLASThresholdFetching,
refetch: refetchVeOLASThreshold,
} = useVeOLASThreshold();
const {
data: minAcceptedETH,
isFetching: isMinAcceptedETHFetching,
refetch: refetchMinAcceptedETH,
} = useMinAcceptedETH();
const {
data: epochCounter,
isFetching: isEpochCounterFetching,
refetch: refetchEpochCounter,
} = useEpochCounter();
const {
data: prevEpochPoint,
isFetching: isPrevEpochPointFetching,
refetch: refetchPrevEpochPoint,
} = useEpochTokenomics(epochCounter !== undefined ? Number(epochCounter) - 1 : undefined);
const {
data: epochLength,
isFetching: isEpochLengthFetching,
Expand All @@ -83,8 +94,14 @@ export const useThresholdData = () => {
refetchEpochLength(),
];

return Promise.all(promises);
}, []);
return Promise.all(promises);
}, [
refetchVeOLASThreshold,
refetchMinAcceptedETH,
refetchEpochCounter,
refetchPrevEpochPoint,
refetchEpochLength,
]);

return {
veOLASThreshold,
Expand All @@ -99,6 +116,6 @@ export const useThresholdData = () => {
isEpochCounterFetching ||
isPrevEpochPointFetching ||
isEpochLengthFetching,
refetchData
refetchData,
};
};
};
15 changes: 6 additions & 9 deletions apps/govern/components/Donate/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Alert, Button, Skeleton, Typography } from 'antd';
import { Alert, Button, Card, Skeleton, Typography } from 'antd';
import { ethers } from 'ethers';
import isNumber from 'lodash/isNumber';
import Link from 'next/link';
Expand Down Expand Up @@ -54,9 +54,7 @@ export const DonatePage = () => {
setIsDonationLoading(true);

const [sortedUnitIds, sortedAmounts] = sortUnitIdsAndAmounts(values.unitIds, values.amounts);

const serviceIds = sortedUnitIds.map((e) => `${e}`);

const invalidServices = await checkServicesTerminatedOrNotDeployed(serviceIds);

// deposit only if all services are deployed or not terminated
Expand Down Expand Up @@ -110,8 +108,7 @@ export const DonatePage = () => {
notifySuccess('Started new epoch');
} catch (error) {
console.error(error);
const errorMessage = (error as Error).message || 'Error occurred on starting new epoch';
notifyError(errorMessage);
notifyError('Error occurred on starting new epoch');
} finally {
setIsCheckpointLoading(false);
}
Expand Down Expand Up @@ -141,7 +138,7 @@ export const DonatePage = () => {

return (
<DonateContainer>
<div className="donate-section">
<Card className="donate-section">
<Title level={2} className="mt-0">
Donate
</Title>
Expand Down Expand Up @@ -170,9 +167,9 @@ export const DonatePage = () => {
/>

<DonateForm isLoading={isDonationLoading} onSubmit={onDepositServiceDonationSubmit} />
</div>
</Card>

<div className="last-epoch-section">
<Card className="last-epoch-section">
<Title level={2} className="mt-0">
Epoch Status
</Title>
Expand Down Expand Up @@ -200,7 +197,7 @@ export const DonatePage = () => {
</Button>
<Text type="secondary">New epochs must be manually triggered by community members</Text>
</EpochCheckpointRow>
</div>
</Card>
</DonateContainer>
);
};
10 changes: 4 additions & 6 deletions apps/govern/components/Donate/styles.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import styled from 'styled-components';

import { COLOR, MEDIA_QUERY } from 'libs/ui-theme/src';
import { MEDIA_QUERY } from 'libs/ui-theme/src';

export const DonateContainer = styled.div`
display: flex;
padding: 0 16px;
gap: 16px;
.donate-section {
width: 720px;
}
.last-epoch-section {
padding-left: 1rem;
margin-left: 1rem;
border-left: 1px solid ${COLOR.BORDER_GREY_2};
flex: auto;
}
${MEDIA_QUERY.mobileL} {
${MEDIA_QUERY.tabletL} {
flex-direction: column;
.donate-section {
width: 100%;
Expand Down

0 comments on commit fde79af

Please sign in to comment.