From d44fb73e912408e6b1472316857aa98dcb7e3565 Mon Sep 17 00:00:00 2001 From: Ryan Wolhuter Date: Wed, 2 Nov 2022 15:23:16 +0200 Subject: [PATCH] chore: housekeeping (#54) * rename constants dir to avoid name clash Signed-off-by: ryanwolhuter * organize constant dir Signed-off-by: ryanwolhuter * update constant imports Signed-off-by: ryanwolhuter * organize helpers dir Signed-off-by: ryanwolhuter * split type defs into separate files Signed-off-by: ryanwolhuter * use default prettier config Signed-off-by: ryanwolhuter * apply prettier default formatting Signed-off-by: ryanwolhuter * fix error caused by lint Signed-off-by: ryanwolhuter Signed-off-by: ryanwolhuter --- .prettierrc | 5 - components/Button/Button.tsx | 19 ++- components/Checkbox/Checkbox.tsx | 12 +- components/DonutChart/DonutChart.tsx | 31 +++- components/DonutChart/helpers.ts | 9 +- components/Dropdown/Dropdown.tsx | 39 ++++- components/GlobalStyle/GlobalStyle.ts | 27 ++-- components/Header/Header.tsx | 6 +- components/HowItWorks/HowItWorks.tsx | 57 +++++-- components/Input/TextInput.tsx | 3 +- .../LoadingSkeleton/LoadingSkeleton.tsx | 17 ++- components/LoadingSpinner/LoadingSpinner.tsx | 17 ++- components/Nav/Nav.tsx | 10 +- components/Notifications/Notification.tsx | 5 +- components/Notifications/Notifications.tsx | 8 +- components/Pagination/Pagination.tsx | 69 ++++++--- components/Panel/ClaimPanel.tsx | 46 ++++-- components/Panel/DelegationPanel.tsx | 46 ++++-- components/Panel/HistoryPanel.tsx | 26 ++-- components/Panel/MenuPanel/MenuPanel.tsx | 81 +++++++--- components/Panel/Panel.tsx | 13 +- components/Panel/PanelTitle.tsx | 8 +- .../Panel/RemindMePanel/RemindMePanel.tsx | 33 ++++- .../Panel/StakeUnstakePanel/CooldownTimer.tsx | 18 ++- components/Panel/StakeUnstakePanel/Stake.tsx | 32 +++- .../StakeUnstakePanel/StakeUnstakePanel.tsx | 16 +- .../Panel/StakeUnstakePanel/Unstake.tsx | 38 +++-- components/Panel/VotePanel/Details.tsx | 19 ++- components/Panel/VotePanel/Result.tsx | 7 +- components/Panel/VotePanel/VotePanel.tsx | 6 +- .../PanelErrorBanner/PanelErrorBanner.tsx | 6 +- components/Toggle/Toggle.tsx | 2 +- components/Tooltip/Tooltip.tsx | 5 +- .../VoteHistoryTable/VoteHistoryTableRow.tsx | 6 +- components/VoteTimeline/CommitPhase.tsx | 9 +- components/VoteTimeline/RevealPhase.tsx | 9 +- components/VoteTimeline/VoteTimeline.tsx | 23 ++- components/Votes/Votes.tsx | 40 ++++- components/VotesTable/VotesTableHeadings.tsx | 6 +- components/VotesTable/VotesTableRow.tsx | 41 ++++- components/Wallet/Wallet.tsx | 38 +++-- components/index.ts | 6 +- components/pages/PastVotes.tsx | 18 ++- components/pages/Vote.tsx | 10 +- .../pages/WalletSettings/AddDelegate.tsx | 11 +- .../pages/WalletSettings/ConnectedWallet.tsx | 5 +- .../pages/WalletSettings/IsDelegate.tsx | 6 +- .../pages/WalletSettings/IsDelegator.tsx | 6 +- .../WalletSettings/NoWalletConnected.tsx | 12 +- .../pages/WalletSettings/OtherWallet.tsx | 13 +- .../pages/WalletSettings/PendingRequests.tsx | 77 ++++++++-- .../pages/WalletSettings/WalletSettings.tsx | 8 +- components/pages/WalletSettings/Wallets.tsx | 8 +- components/pages/WalletSettings/styles.tsx | 36 ++++- constant/index.ts | 71 +++++++++ constant/query/graphEndpoint.ts | 1 + {constants => constant/query}/queryKeys.ts | 0 {constants => constant/styles}/colors.ts | 0 {constants => constant/styles}/containers.ts | 0 {constants => constant/styles}/fonts.ts | 0 {constants => constant/styles}/shadows.ts | 0 {constants => constant/voting}/discordLink.ts | 0 constant/voting/earlyRequestMagicNumber.ts | 2 + {constants => constant/voting}/voteTiming.ts | 0 {constants => constant/web3}/addresses.ts | 0 {constants => constant/web3}/deployBlocks.ts | 0 constant/web3/signingMessage.ts | 1 + constants/earlyRequestMagicNumber.ts | 3 - constants/graphEndpoint.ts | 3 - constants/signingMessage.ts | 3 - contexts/ContractsContext.tsx | 16 +- contexts/DelegationContext.tsx | 114 ++++++++++---- contexts/ErrorContext.tsx | 12 +- contexts/NotificationsContext.tsx | 23 ++- contexts/PaginationContext.tsx | 14 +- contexts/PanelContext.tsx | 13 +- contexts/StakingContext.tsx | 4 +- contexts/UserContext.tsx | 7 +- contexts/VoteTimingContext.tsx | 15 +- contexts/VotesContext.tsx | 16 +- contexts/WalletContext.tsx | 18 ++- contexts/index.ts | 66 +++++++-- data/approvedIdentifiersTable.ts | 3 +- graph/queries/getPastVotes.ts | 43 ++++-- .../queries/getUserVotingAndStakingDetails.ts | 29 +++- ...RequestToBeDelegateAddressesFromStorage.ts | 0 helpers/index.ts | 78 +++++----- helpers/{ => staking}/getCanUnstakeTime.ts | 5 +- helpers/{ => util}/addOpacityToHsl.ts | 0 helpers/{ => util}/formatNumber.ts | 0 helpers/{ => util}/getEntriesForPage.ts | 6 +- helpers/{ => util}/handleNotifications.ts | 2 +- helpers/{misc.ts => util/isExternalLink.ts} | 0 helpers/{ => util}/logTruthy.ts | 0 helpers/{ => util}/unixTimestampToDate.ts | 0 helpers/{ => voting}/checkIfIsPolymarket.ts | 5 +- helpers/{ => voting}/formatVotes.ts | 54 +++++-- helpers/{ => voting}/getVoteMetaData.ts | 42 ++++-- .../{ => voting}/makePriceRequestsByKey.ts | 18 ++- .../makeUniqueKeyForVote.ts} | 6 +- .../{ => voting}/onlyOneRequestPerAddress.ts | 5 +- helpers/{ => voting}/voteTiming.ts | 2 +- helpers/{ => web3}/crypto.ts | 27 +++- helpers/{ => web3}/decodeHexString.ts | 0 helpers/{ => web3}/ethers.ts | 2 +- helpers/{ => web3}/events.ts | 15 +- helpers/{ => web3}/initOnboard.ts | 4 +- helpers/{ => web3}/truncateEthAddress.ts | 0 helpers/{ => web3}/wallet.ts | 0 hooks/helpers/useInitializeVoteTiming.ts | 16 +- hooks/helpers/useIsomorphicLayoutEffect.ts | 3 +- hooks/helpers/useOnChange.ts | 4 +- .../useAcceptReceivedRequestToBeDelegate.ts | 12 +- .../useCancelSentRequestToBeDelegate.ts | 11 +- .../useIgnoreReceivedRequestToBeDelegate.ts | 18 ++- .../delegation/useSendRequestToBeDelegate.ts | 36 +++-- .../useTerminateRelationshipWithDelegate.ts | 12 +- .../useTerminateRelationshipWithDelegator.ts | 7 +- hooks/mutations/staking/useApprove.ts | 15 +- hooks/mutations/staking/useExecuteUnstake.ts | 64 ++++---- hooks/mutations/staking/useRequestUnstake.ts | 41 +++-- hooks/mutations/staking/useStake.ts | 35 +++-- .../staking/useWithdrawAndRestake.ts | 35 +++-- hooks/mutations/staking/useWithdrawRewards.ts | 28 +++- hooks/mutations/votes/useCommitVotes.ts | 34 +++-- hooks/mutations/votes/useRevealVotes.ts | 19 ++- .../useCommittedVotesForDelegator.ts | 10 +- .../queries/delegation/useDelegateToStaker.ts | 9 +- .../useDelegatorSetEventsForDelegate.ts | 2 +- .../useDelegatorSetEventsForDelegator.ts | 2 +- .../useIgnoredRequestToBeDelegateAddresses.ts | 2 +- .../useReceivedRequestsToBeDelegate.ts | 2 +- .../delegation/useSentRequestsToBeDelegate.ts | 2 +- .../delegation/useVoterFromDelegate.ts | 14 +- .../queries/staking/useOutstandingRewards.ts | 18 ++- hooks/queries/staking/useStakerDetails.ts | 40 +++-- hooks/queries/staking/useTokenAllowance.ts | 18 ++- hooks/queries/staking/useUnstakeCoolDown.ts | 18 ++- hooks/queries/staking/useUnstakedBalance.ts | 16 +- .../user/useUserVotingAndStakingDetails.ts | 36 +++-- hooks/queries/votes/useActiveVotes.ts | 22 ++- hooks/queries/votes/useCommittedVotes.ts | 9 +- hooks/queries/votes/useContentfulData.ts | 19 ++- hooks/queries/votes/useDecryptedVotes.ts | 29 +++- hooks/queries/votes/useEncryptedVotes.ts | 9 +- hooks/queries/votes/useHasActiveVotes.ts | 20 ++- hooks/queries/votes/usePastVotes.ts | 2 +- hooks/queries/votes/useRevealedVotes.ts | 25 +++- hooks/queries/votes/useUpcomingVotes.ts | 32 ++-- .../queries/votes/useVoteTransactionHashes.ts | 17 ++- pages/_document.tsx | 34 ++++- pages/api/_common.ts | 19 ++- pages/api/augment-request.ts | 79 +++++++--- pages/api/decode-admin.ts | 60 ++++++-- scripts/approvedIdentifiersTableParser.ts | 20 ++- .../errors/ErrorBanner.stories.tsx | 28 +++- .../errors/PanelErrorBanner.stories.tsx | 30 +++- .../info/CooldownTimer.stories.tsx | 6 +- .../info/DonutChart.stories.tsx | 9 +- .../info/Notifications.stories.tsx | 17 ++- .../BaseComponents/info/Tooltip.stories.tsx | 5 +- .../inputs/AmountInput.stories.tsx | 6 +- .../inputs/Checkbox.stories.tsx | 7 +- .../inputs/Dropdown.stories.tsx | 2 +- .../BaseComponents/inputs/Toggle.stories.tsx | 4 +- .../loaders/LoadingSkeleton.stories.tsx | 16 +- .../loaders/LoadingSpinner.stories.tsx | 4 +- .../navigation/Header.stories.tsx | 6 +- .../navigation/Pagination.stories.tsx | 38 +++-- .../navigation/Panel.stories.tsx | 27 +++- .../navigation/VoteHistoryTable.stories.tsx | 4 +- stories/Pages/PastVotesPage.stories.tsx | 6 +- stories/Pages/VotePage/InfoBar.stories.tsx | 4 +- .../Pages/VotePage/VoteTableRow.stories.tsx | 4 +- .../Pages/VotePage/VoteTimeline.stories.tsx | 7 +- stories/Pages/VotePage/Votes.stories.tsx | 29 +++- stories/Pages/VotePage/VotesTable.stories.tsx | 18 ++- .../VotePage/VotesTableHeadings.stories.tsx | 4 +- .../WalletSettingsPage/Wallets.stories.tsx | 47 ++++-- stories/mocks/delegation.ts | 3 +- stories/mocks/votes.ts | 10 +- types/delegation.ts | 13 ++ types/index.ts | 8 +- types/notifications.ts | 19 +++ types/queries.ts | 31 ++++ types/staking.ts | 9 ++ types/ui.ts | 51 +++++++ types/user.ts | 20 +++ types/{global.ts => voting.ts} | 140 ++---------------- .../contracts/createVotingContractInstance.ts | 7 +- .../createVotingTokenContractInstance.ts | 7 +- web3/mutations/delegation/removeDelegate.ts | 6 +- web3/mutations/delegation/removeDelegator.ts | 6 +- web3/mutations/delegation/setDelegate.ts | 6 +- web3/mutations/delegation/setDelegator.ts | 12 +- web3/mutations/staking/approve.ts | 7 +- web3/mutations/staking/executeUnstake.ts | 12 +- web3/mutations/staking/requestUnstake.ts | 20 ++- web3/mutations/staking/stake.ts | 8 +- web3/mutations/staking/withdrawAndRestake.ts | 12 +- web3/mutations/staking/withdrawRewards.ts | 4 +- web3/mutations/votes/revealVotes.ts | 4 +- .../queries/balances/getOutstandingRewards.ts | 5 +- web3/queries/balances/getStakerDetails.ts | 17 ++- web3/queries/balances/getTokenAllowance.ts | 12 +- web3/queries/balances/getUnstakedBalance.ts | 5 +- .../delegation/getDelegateSetEvents.ts | 10 +- .../queries/delegation/getDelegateToStaker.ts | 5 +- .../getIgnoredRequestToBeDelegateAddresses.ts | 7 +- web3/queries/votes/getCommittedVotes.ts | 23 ++- web3/queries/votes/getEncryptedVotes.ts | 19 ++- web3/queries/votes/getRevealedVotes.ts | 25 +++- web3/queries/votes/getUpcomingVotes.ts | 11 +- .../queries/votes/getVoteTransactionHashes.ts | 11 +- 214 files changed, 2735 insertions(+), 1005 deletions(-) delete mode 100644 .prettierrc create mode 100644 constant/index.ts create mode 100644 constant/query/graphEndpoint.ts rename {constants => constant/query}/queryKeys.ts (100%) rename {constants => constant/styles}/colors.ts (100%) rename {constants => constant/styles}/containers.ts (100%) rename {constants => constant/styles}/fonts.ts (100%) rename {constants => constant/styles}/shadows.ts (100%) rename {constants => constant/voting}/discordLink.ts (100%) create mode 100644 constant/voting/earlyRequestMagicNumber.ts rename {constants => constant/voting}/voteTiming.ts (100%) rename {constants => constant/web3}/addresses.ts (100%) rename {constants => constant/web3}/deployBlocks.ts (100%) create mode 100644 constant/web3/signingMessage.ts delete mode 100644 constants/earlyRequestMagicNumber.ts delete mode 100644 constants/graphEndpoint.ts delete mode 100644 constants/signingMessage.ts rename helpers/{ => delegation}/getIgnoredRequestToBeDelegateAddressesFromStorage.ts (100%) rename helpers/{ => staking}/getCanUnstakeTime.ts (62%) rename helpers/{ => util}/addOpacityToHsl.ts (100%) rename helpers/{ => util}/formatNumber.ts (100%) rename helpers/{ => util}/getEntriesForPage.ts (55%) rename helpers/{ => util}/handleNotifications.ts (97%) rename helpers/{misc.ts => util/isExternalLink.ts} (100%) rename helpers/{ => util}/logTruthy.ts (100%) rename helpers/{ => util}/unixTimestampToDate.ts (100%) rename helpers/{ => voting}/checkIfIsPolymarket.ts (73%) rename helpers/{ => voting}/formatVotes.ts (71%) rename helpers/{ => voting}/getVoteMetaData.ts (84%) rename helpers/{ => voting}/makePriceRequestsByKey.ts (74%) rename helpers/{votes.ts => voting/makeUniqueKeyForVote.ts} (56%) rename helpers/{ => voting}/onlyOneRequestPerAddress.ts (76%) rename helpers/{ => voting}/voteTiming.ts (95%) rename helpers/{ => web3}/crypto.ts (80%) rename helpers/{ => web3}/decodeHexString.ts (100%) rename helpers/{ => web3}/ethers.ts (96%) rename helpers/{ => web3}/events.ts (59%) rename helpers/{ => web3}/initOnboard.ts (92%) rename helpers/{ => web3}/truncateEthAddress.ts (100%) rename helpers/{ => web3}/wallet.ts (100%) create mode 100644 types/delegation.ts create mode 100644 types/notifications.ts create mode 100644 types/queries.ts create mode 100644 types/staking.ts create mode 100644 types/ui.ts create mode 100644 types/user.ts rename types/{global.ts => voting.ts} (50%) diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 6a723b71..00000000 --- a/.prettierrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "printWidth": 120, - "bracketSpacing": true, - "tabWidth": 2 -} \ No newline at end of file diff --git a/components/Button/Button.tsx b/components/Button/Button.tsx index b7cff63a..20bb2959 100644 --- a/components/Button/Button.tsx +++ b/components/Button/Button.tsx @@ -1,8 +1,8 @@ -import { red100, red500, red600, white } from "constants/colors"; +import { red100, red500, red600, white } from "constant"; +import { isExternalLink } from "helpers"; import Link from "next/link"; import { ReactNode } from "react"; import styled, { CSSProperties } from "styled-components"; -import { isExternalLink } from "helpers"; interface Props { /** @@ -54,7 +54,9 @@ export function Button({ type = "button", }: Props) { if (onClick && href) { - throw new Error("Cannot have both onClick and href. Must behave as either a link or a button."); + throw new Error( + "Cannot have both onClick and href. Must behave as either a link or a button." + ); } if (!onClick && !href && type !== "submit") { @@ -64,7 +66,9 @@ export function Button({ } if (href && disabled) { - throw new Error("`disabled` only makes sense on `button` elements. Cannot be used with `href`. "); + throw new Error( + "`disabled` only makes sense on `button` elements. Cannot be used with `href`. " + ); } width = typeof width === "string" ? width : `${width}px`; @@ -111,7 +115,12 @@ export function Button({ ) : null} {onClick || type === "submit" ? ( - <_Button onClick={onClick} style={style} disabled={disabled} type={type}> + <_Button + onClick={onClick} + style={style} + disabled={disabled} + type={type} + > {label} ) : null} diff --git a/components/Checkbox/Checkbox.tsx b/components/Checkbox/Checkbox.tsx index 9f789bca..4f95fd94 100644 --- a/components/Checkbox/Checkbox.tsx +++ b/components/Checkbox/Checkbox.tsx @@ -1,9 +1,9 @@ import { CustomCheckboxContainer, CustomCheckboxInput } from "@reach/checkbox"; import "@reach/checkbox/styles.css"; -import { black, white } from "constants/colors"; +import { black, white } from "constant"; +import Check from "public/assets/icons/check.svg"; import { ChangeEvent, ReactNode } from "react"; import styled, { CSSProperties } from "styled-components"; -import Check from "public/assets/icons/check.svg"; interface Props { label: ReactNode; @@ -12,7 +12,13 @@ interface Props { disabled?: boolean; gap?: number; } -export function Checkbox({ label, checked, onChange, disabled, gap = 15 }: Props) { +export function Checkbox({ + label, + checked, + onChange, + disabled, + gap = 15, +}: Props) { const boxBackgroundColor = checked ? black : white; return (