Skip to content

Commit

Permalink
Merge pull request #110 from lidofinance/develop
Browse files Browse the repository at this point in the history
Develop to main
  • Loading branch information
itaven authored Jun 28, 2023
2 parents 7fc8ba5 + b58e730 commit d87f6f2
Show file tree
Hide file tree
Showing 38 changed files with 1,746 additions and 2,136 deletions.
4 changes: 2 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ ALCHEMY_API_KEY=
ETHERSCAN_API_KEY=

# supported networks for connecting wallet
SUPPORTED_CHAINS=1,4,5
SUPPORTED_CHAINS=1,5

# this chain uses when a wallet is not connected
DEFAULT_CHAIN=4
DEFAULT_CHAIN=1

# comma-separated trusted hosts for Content Security Policy
CSP_TRUSTED_HOSTS=
Expand Down
136 changes: 0 additions & 136 deletions .eslintrc.js

This file was deleted.

83 changes: 83 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": ["next", "plugin:import/typescript", "prettier"],
"plugins": ["prettier", "@typescript-eslint", "react", "react-hooks"],
"settings": {
"react": { "version": "detect" },
"import/resolver": {
"node": {
"paths": ["."]
}
}
},
"rules": {
"no-var": "error",
"no-unused-expressions": "error",
"no-param-reassign": "error",
"no-else-return": "error",
"no-useless-escape": "error",
"no-return-await": "error",
"default-case": "error",
"no-fallthrough": "error",
"prettier/prettier": ["error", { "usePrettierrc": true }],
"no-undef": "off",
"no-shadow": "off",
"no-unused-vars": "off",
"react/jsx-no-undef": "off",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-redeclare": ["error"],
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/consistent-type-assertions": [
"error",
{ "assertionStyle": "as" }
],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-unnecessary-condition": "error",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-arguments": "error",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/require-await": "error",
"react/no-children-prop": "off",
"react/self-closing-comp": "error",
"react/no-unused-prop-types": "error",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": ["error"],
"import/no-unresolved": "off",
"import/no-dynamic-require": "error",
"import/no-self-import": "error",
"import/no-useless-path-segments": ["error", { "noUselessIndex": true }],
"import/no-duplicates": "error",
"import/extensions": [
"error",
"never",
{
"ignorePackages": true,
"svg": "always"
}
],
"import/export": "error",
"import/newline-after-import": "error",
"import/first": "error",
"import/no-mutable-exports": "error",
"import/no-cycle": "error",
"import/order": "off"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": { "jsx": true },
"ecmaVersion": 2021,
"sourceType": "module",
"project": "./tsconfig.json"
}
}
2 changes: 1 addition & 1 deletion .github/workflows/ci-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
TARGET_REPO: "lidofinance/infra-mainnet"
TAG: "${{ github.event.release.tag_name }}"
TARGET_WORKFLOW: "build_mainnet_dao_voting_ui.yaml"
TARGET_WORKFLOW: "build_critical_dao_voting_ui.yaml"
2 changes: 1 addition & 1 deletion .github/workflows/ci-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ jobs:
APP_ID: ${{ secrets.APP_ID }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
TARGET_REPO: "lidofinance/infra-mainnet"
TARGET_WORKFLOW: "deploy_staging_mainnet_dao_voting_ui.yaml"
TARGET_WORKFLOW: "deploy_staging_critical_dao_voting_ui.yaml"
TARGET: "main"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ yarn-error.log*

# vercel
.vercel

#ide
.vscode
.idea
File renamed without changes.
2 changes: 1 addition & 1 deletion modules/blockChain/hooks/useErrorMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react'
import { useConfig } from 'modules/config/hooks/useConfig'
import { useSupportedChains, useConnectorError } from '@reef-knot/web3-react'
import { useSupportedChains, useConnectorError } from 'reef-knot/web3-react'

import { getChainName } from 'modules/blockChain/chains'

Expand Down
28 changes: 28 additions & 0 deletions modules/blockChain/hooks/useIsContract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useEthereumSWR } from '@lido-sdk/react'

export const useIsContract = (
account?: string | null,
): { loading: boolean; isContract: boolean } => {
// eth_getCode returns hex string of bytecode at address
// for accounts it's "0x"
// for contract it's potentially very long hex (can't be safely&quickly parsed)
const result = useEthereumSWR({
shouldFetch: !!account,
method: 'getCode',
params: [account, 'latest'],
config: {
// this is very stable request
refreshWhenHidden: false,
revalidateOnFocus: false,
revalidateIfStale: false,
revalidateOnMount: true,
revalidateOnReconnect: false,
refreshInterval: 0,
},
})

return {
loading: result.loading,
isContract: result.data ? result.data !== '0x' : false,
}
}
8 changes: 8 additions & 0 deletions modules/blockChain/hooks/useIsMultisig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useWeb3 } from 'reef-knot/web3-react'
import { useIsContract } from './useIsContract'

export const useIsMultisig = () => {
const { account } = useWeb3()
const { isContract, loading } = useIsContract(account ?? undefined)
return [isContract, loading]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { useCallback } from 'react'
import { useWeb3 } from 'modules/blockChain/hooks/useWeb3'
import { PopulatedTransaction } from '@ethersproject/contracts'
import { sendTransactionGnosisWorkaround } from '../utils/sendTransactionGnosisWorkaround'
import { useIsMultisig } from './useIsMultisig'

export function useSendTransactionGnosisWorkaround() {
const { library } = useWeb3()
// TODO: track loading state of this swr in the ui on yes/no/enact button
const [isMultisig] = useIsMultisig()

return useCallback(
(tx: PopulatedTransaction) =>
sendTransactionGnosisWorkaround(library.getSigner(), tx),
[library],
sendTransactionGnosisWorkaround(library?.getSigner(), tx, isMultisig),
[library, isMultisig],
)
}
2 changes: 1 addition & 1 deletion modules/blockChain/hooks/useTransactionSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function useTransactionSender<A extends unknown[]>(
if (!resultTx) return
const link =
resultTx.type === 'safe'
? getGnosisSafeLink(chainId, `${walletAddress}/transaction`)
? getGnosisSafeLink(chainId, `${walletAddress}`)
: getEtherscanLink(chainId, resultTx.tx.hash, 'tx')
openWindow(link)
}, [chainId, resultTx, walletAddress])
Expand Down
7 changes: 5 additions & 2 deletions modules/blockChain/hooks/useWeb3.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useMemo } from 'react'
import { useWeb3React } from '@web3-react/core'
import { useWeb3 as useWeb3ReefKnot } from 'reef-knot/web3-react'
import { useConfig } from 'modules/config/hooks/useConfig'
import { parseChainId } from '../chains'
import { useSDK } from '@lido-sdk/react'

export function useWeb3() {
const web3 = useWeb3React()
const web3 = useWeb3ReefKnot()
const { providerWeb3 } = useSDK()
const { defaultChain } = useConfig()
const { chainId } = web3

Expand All @@ -18,5 +20,6 @@ export function useWeb3() {
isWalletConnected: web3.active,
walletAddress: web3.account,
chainId: currentChain,
library: providerWeb3,
}
}
6 changes: 0 additions & 6 deletions modules/blockChain/utils/checkConnectedToSafe.ts

This file was deleted.

7 changes: 5 additions & 2 deletions modules/blockChain/utils/createContractHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useContractSwr } from '../hooks/useContractSwr'
import { useConfig } from 'modules/config/hooks/useConfig'

import type { Signer, providers } from 'ethers'
import type { JsonRpcSigner } from '@ethersproject/providers'
import { getStaticRpcBatchProvider } from '@lido-sdk/providers'
import { getChainName } from 'modules/blockChain/chains'
import type { FilterAsyncMethods } from '@lido-sdk/react/dist/esm/hooks/types'
Expand All @@ -15,7 +16,7 @@ import {
AsyncMethodParameters,
} from 'modules/types/filter-async-methods'

type Library = Signer | providers.Provider
type Library = JsonRpcSigner | Signer | providers.Provider

interface Factory {
name: string
Expand Down Expand Up @@ -81,11 +82,13 @@ export function createContractHelpers<F extends Factory>({
() =>
connect({
chainId,
library: library?.getSigner(),
// TODO: find a way to remove ! here
library: library?.getSigner()!,
}),
[
'contract-web3-',
active ? 'active' : 'inactive',
library ? 'with-signer' : 'no-signer',
chainId,
address[chainId],
account,
Expand Down
Loading

0 comments on commit d87f6f2

Please sign in to comment.