Skip to content

Commit

Permalink
Merge pull request #18 from lidofinance/develop
Browse files Browse the repository at this point in the history
Develop to main
  • Loading branch information
itaven authored Aug 15, 2023
2 parents 9991563 + 7c0054b commit 58c3be5
Show file tree
Hide file tree
Showing 77 changed files with 1,005 additions and 506 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@

# production
/build

/public
36 changes: 21 additions & 15 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:jsx-a11y/recommended",
"plugin:prettier/recommended"
],
"extends": ["plugin:jsx-a11y/recommended", "@lidofinance", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
Expand All @@ -22,21 +15,34 @@
},
"plugins": ["@typescript-eslint", "react"],
"rules": {
"prettier/prettier": ["error", {}, { "usePrettierrc": true }],
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
"@typescript-eslint/require-await": "off",
"react/display-name": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-shadow": "off",
"jsx-a11y/no-autofocus": "off",
"jsx-a11y/anchor-is-valid": "off",
"@next/next/no-img-element": "off",
"no-console": ["warn", { "allow": ["warn", "error", "info", "debug"] }],
"@typescript-eslint/no-unused-vars": [
"warn",
{
"ignoreRestSiblings": true,
"argsIgnorePattern": "^_"
}
],
"jsx-a11y/no-autofocus": "off",
"jsx-a11y/anchor-is-valid": "off",
"func-style": ["error", "expression"]
"promise/param-names": [
"warn",
{
"resolvePattern": "^_?(resolve)$|^_$",
"rejectPattern": "^_?(reject)$|^_$"
}
],
"func-style": ["error", "expression"],
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": false
}
]
},
"settings": {
"react": {
Expand Down
18 changes: 4 additions & 14 deletions features/home/stake-form/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { AddressZero } from '@ethersproject/constants';
import { useLidoSWR, useSTETHContractRPC } from '@lido-sdk/react';
import {
ESTIMATE_ACCOUNT,
getBackendRPCPath,
STETH_SUBMIT_GAS_LIMIT_DEFAULT,
} from 'config';
import { ESTIMATE_ACCOUNT, STETH_SUBMIT_GAS_LIMIT_DEFAULT } from 'config';
import { parseEther } from '@ethersproject/units';
import { useWeb3 } from 'reef-knot/web3-react';
import { getStaticRpcBatchProvider } from 'utils/rpcProviders';
import { BigNumber } from 'ethers';
import { CHAINS } from 'utils/chains';
import { getFeeData } from 'utils/getFeeData';
import { CHAINS } from '@lido-sdk/constants';

type UseStethSubmitGasLimit = () => number | undefined;

Expand All @@ -24,13 +20,7 @@ export const useStethSubmitGasLimit: UseStethSubmitGasLimit = () => {
return;
}

const provider = getStaticRpcBatchProvider(
chainId as string,
// TODO: add a way to type useWeb3 hook
getBackendRPCPath(chainId as CHAINS),
);

const feeData = await provider.getFeeData();
const feeData = await getFeeData(chainId as CHAINS);
const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? undefined;
const maxFeePerGas = feeData.maxFeePerGas ?? undefined;

Expand Down
4 changes: 1 addition & 3 deletions features/home/stake-form/stake-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const StakeForm: FC = memo(() => {
typeof router.query.amount === 'string'
) {
const { amount, ...rest } = router.query;
router.replace({ pathname: router.pathname, query: rest });
void router.replace({ pathname: router.pathname, query: rest });
setInputValue(amount);
}
}, [router]);
Expand Down Expand Up @@ -97,7 +97,6 @@ export const StakeForm: FC = memo(() => {
providerWeb3,
stethContractWeb3,
openTxModal,
closeTxModal,
setTxStage,
setTxHash,
setTxModalFailedText,
Expand All @@ -113,7 +112,6 @@ export const StakeForm: FC = memo(() => {
providerWeb3,
stethContractWeb3,
openTxModal,
closeTxModal,
stethBalance.update,
chainId,
router?.query?.ref,
Expand Down
32 changes: 12 additions & 20 deletions features/home/stake-form/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getBackendRPCPath } from 'config';
import { TX_STAGE } from 'shared/components';
import { BigNumber } from 'ethers';
import invariant from 'tiny-invariant';
import { getFeeData } from 'utils/getFeeData';
import type { Web3Provider } from '@ethersproject/providers';

const SUBMIT_EXTRA_GAS_TRANSACTION_RATIO = 1.05;
Expand All @@ -22,7 +23,6 @@ type StakeProcessingProps = (
providerWeb3: Web3Provider | undefined,
stethContractWeb3: StethAbi | null,
openTxModal: () => void,
closeTxModal: () => void,
setTxStage: (value: TX_STAGE) => void,
setTxHash: (value: string | undefined) => void,
setTxModalFailedText: (value: string) => void,
Expand Down Expand Up @@ -68,7 +68,6 @@ export const stakeProcessing: StakeProcessingProps = async (
providerWeb3,
stethContractWeb3,
openTxModal,
closeTxModal,
setTxStage,
setTxHash,
setTxModalFailedText,
Expand All @@ -79,15 +78,12 @@ export const stakeProcessing: StakeProcessingProps = async (
refFromQuery,
isMultisig,
) => {
if (!stethContractWeb3 || !chainId) {
return;
}

invariant(providerWeb3, 'must have providerWeb3');

try {
const referralAddress = await getAddress(refFromQuery, chainId);
invariant(stethContractWeb3);
invariant(chainId);
invariant(providerWeb3);

const referralAddress = await getAddress(refFromQuery, chainId);
const callback = async () => {
if (isMultisig) {
const tx = await stethContractWeb3.populateTransaction.submit(
Expand All @@ -98,17 +94,13 @@ export const stakeProcessing: StakeProcessingProps = async (
);
return providerWeb3.getSigner().sendUncheckedTransaction(tx);
} else {
const provider = getStaticRpcBatchProvider(
chainId,
getBackendRPCPath(chainId),
);

const feeData = await provider.getFeeData();

const feeData = await getFeeData(chainId);
const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? undefined;
const maxFeePerGas = feeData.maxFeePerGas ?? undefined;
const overrides = {
value: parseEther(inputValue),
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? undefined,
maxFeePerGas: feeData.maxFeePerGas ?? undefined,
maxPriorityFeePerGas,
maxFeePerGas,
};

const originalGasLimit = await stethContractWeb3.estimateGas.submit(
Expand Down Expand Up @@ -148,12 +140,13 @@ export const stakeProcessing: StakeProcessingProps = async (
);

const handleEnding = () => {
openTxModal();
resetForm();
stethBalanceUpdate();
};

if (isMultisig) {
closeTxModal();
setTxStage(TX_STAGE.SUCCESS_MULTISIG);
handleEnding();
return;
}
Expand All @@ -168,7 +161,6 @@ export const stakeProcessing: StakeProcessingProps = async (
}

setTxStage(TX_STAGE.SUCCESS);
openTxModal();
handleEnding();
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
} catch (error: any) {
Expand Down
2 changes: 1 addition & 1 deletion features/rewards/components/addressInput/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const AddressInput: FC<AddressInputProps> = (props) => {
}
rightDecorator={address ? <CopyAddressUrl address={inputValue} /> : null}
spellCheck="false"
error={!!inputValue.length && !isValidAnyAddress(inputValue)}
error={inputValue.length > 0 && !isValidAnyAddress(inputValue)}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const RewardsListContent: FC = () => {
);
}
if (error) return <RewardsListErrorMessage error={error} />;
if (data && !data.events.length) return <ErrorBlockNoSteth />;
if (data && data.events.length === 0) return <ErrorBlockNoSteth />;

return (
<TableWrapperStyle>
Expand Down
2 changes: 1 addition & 1 deletion features/rewards/components/stats/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const Stats: FC<StatsProps> = (props) => {
}, []);

useEffect(() => {
getStEthEth();
void getStEthEth();
}, [getStEthEth]);

const stEthBalanceParsed = steth.data && new Big(steth.data.toString());
Expand Down
2 changes: 1 addition & 1 deletion features/rewards/hooks/useGetCurrentAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const useGetCurrentAddress: UseGetCurrentAddress = () => {
);

useEffect(() => {
resolveInputValue(inputValue);
void resolveInputValue(inputValue);
}, [resolveInputValue, inputValue]);

// Pick up an address
Expand Down
2 changes: 1 addition & 1 deletion features/rewards/utils/saveAsCSV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const objToCSV = (objArray: SomeObj[]) => {
};

export const saveAsCSV = (data: SomeObj[], fileName = 'Lido Rewards') => {
if (!data.length) {
if (data.length === 0) {
return;
}

Expand Down
7 changes: 3 additions & 4 deletions features/withdrawals/claim/form/claim-form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useRef, useState } from 'react';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { BigNumber } from 'ethers';

import { FormatToken } from 'shared/formatters';
Expand Down Expand Up @@ -36,16 +36,15 @@ export const ClaimForm = () => {
const startTx = async () => {
setIsSubmitting(true);
try {
claimMutation(claimSelection.sortedSelectedRequests);
await claimMutation(claimSelection.sortedSelectedRequests);
} finally {
setIsSubmitting(false);
}
};
// send it to state
dispatchModalState({ type: 'set_starTx_callback', callback: startTx });
// start flow
startTx();
return;
return startTx();
}, [
dispatchModalState,
claimMutation,
Expand Down
4 changes: 3 additions & 1 deletion features/withdrawals/claim/requests-list/requests-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
REQUESTS_LIST_LOADERS_COUNT,
} from './styles';

const LOADERS_SIZE_ARRAY = Array.from(Array(REQUESTS_LIST_LOADERS_COUNT));
const LOADERS_SIZE_ARRAY = Array.from({
length: REQUESTS_LIST_LOADERS_COUNT,
}).fill(null);

export const RequestsLoader = () => {
return (
Expand Down
3 changes: 3 additions & 0 deletions features/withdrawals/claim/tx-modal/tx-claim-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TxStageModal,
TxStagePending,
TxStageSuccess,
TxStageSuccessMultisig,
TxStageSign,
TxStageFail,
TX_STAGE,
Expand Down Expand Up @@ -65,6 +66,8 @@ export const TxClaimModal = () => {
}
/>
);
case TX_STAGE.SUCCESS_MULTISIG:
return <TxStageSuccessMultisig />;
case TX_STAGE.FAIL:
return (
<TxStageFail
Expand Down
2 changes: 1 addition & 1 deletion features/withdrawals/claim/wallet/wallet.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { memo } from 'react';
import { Divider } from '@lidofinance/lido-ui';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { useSDK } from '@lido-sdk/react';

import { CardAccount, CardRow, Fallback } from 'shared/wallet';
Expand Down
9 changes: 9 additions & 0 deletions features/withdrawals/contexts/transaction-modal-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type TransactionModalAction =
}
| {
type: 'success';
}
| {
type: 'success_multisig';
};

const TransactionModalContext =
Expand Down Expand Up @@ -149,6 +152,12 @@ const TransactionModalReducer = (
isModalOpen: true,
txStage: TX_STAGE.SUCCESS,
};
case 'success_multisig':
return {
...state,
isModalOpen: true,
txStage: TX_STAGE.SUCCESS_MULTISIG,
};
case 'error':
return {
...state,
Expand Down
13 changes: 6 additions & 7 deletions features/withdrawals/contexts/withdrawals-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ export const WithdrawalsProvider: FC<WithdrawalsProviderProps> = ({
useWithdrawalsBaseData();
const { isBunker, isPaused, isTurbo, maxAmount, minAmount } = data ?? {};

const withdrawalsStatus: StatusProps['variant'] = isPaused
? 'error'
: isBunker
? 'warning'
: isTurbo
? 'success'
: 'error';
const withdrawalsStatus: StatusProps['variant'] = (() => {
if (isPaused) return 'error';
if (isBunker) return 'warning';
if (isTurbo) return 'success';
return 'error';
})();

const value = useMemo(
() => ({
Expand Down
4 changes: 3 additions & 1 deletion features/withdrawals/hooks/contract/useClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export const useClaim = () => {
);
}
await update();
dispatchModalState({ type: isMultisig ? 'reset' : 'success' });
dispatchModalState({
type: isMultisig ? 'success_multisig' : 'success',
});
} catch (error) {
const errorMessage = getErrorMessage(error);
dispatchModalState({ type: 'error', errorText: errorMessage });
Expand Down
Loading

0 comments on commit 58c3be5

Please sign in to comment.