-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from lidofinance/develop
Develop to main
- Loading branch information
Showing
35 changed files
with
1,427 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
# generated | ||
/generated | ||
tsconfig.tsbuildinfo | ||
|
||
# next.js | ||
/.next/ | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { backendRPC } from 'modules/blockChain/utils/getBackendRpcUrl' | ||
import { useConfig } from 'modules/config/hooks/useConfig' | ||
import getConfig from 'next/config' | ||
import { ProviderWeb3 } from 'reef-knot/web3-react' | ||
|
||
const { publicRuntimeConfig } = getConfig() | ||
|
||
export function AppProviderWeb3({ children }: { children: React.ReactNode }) { | ||
const { supportedChainIds, defaultChain } = useConfig() | ||
|
||
return ( | ||
<ProviderWeb3 | ||
defaultChainId={defaultChain} | ||
supportedChainIds={supportedChainIds} | ||
rpc={backendRPC} | ||
walletconnectProjectId={publicRuntimeConfig.walletconnectProjectId} | ||
> | ||
{children} | ||
</ProviderWeb3> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './appProviderWeb3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { FC } from 'react' | ||
import { WagmiConfig, configureChains, createClient } from 'wagmi' | ||
import * as wagmiChains from 'wagmi/chains' | ||
import { jsonRpcProvider } from 'wagmi/providers/jsonRpc' | ||
import { getConnectors } from 'reef-knot/core-react' | ||
import getConfig from 'next/config' | ||
import { CHAINS } from '@lido-sdk/constants' | ||
import { getBackendRpcUrl } from 'modules/blockChain/utils/getBackendRpcUrl' | ||
|
||
const { publicRuntimeConfig } = getConfig() | ||
|
||
let supportedChainIds: number[] = [] | ||
if (publicRuntimeConfig.supportedChains != null) { | ||
supportedChainIds = publicRuntimeConfig.supportedChains | ||
.split(',') | ||
.map((chainId: string) => parseInt(chainId)) | ||
.filter((chainId: number) => !Number.isNaN(chainId)) | ||
} else if (publicRuntimeConfig.defaultChain != null) { | ||
supportedChainIds = [parseInt(publicRuntimeConfig.defaultChain)] | ||
} | ||
|
||
const wagmiChainsArray = Object.values(wagmiChains) | ||
const supportedChains = wagmiChainsArray.filter( | ||
chain => | ||
// Temporary wagmi fix, need to hardcode it to not affect non-wagmi wallets | ||
supportedChainIds.includes(chain.id) || chain.id === 80001, | ||
) | ||
const defaultChain = wagmiChainsArray.find( | ||
chain => chain.id === parseInt(publicRuntimeConfig.defaultChain), | ||
) | ||
|
||
const backendRPC = supportedChainIds.reduce<Record<number, string>>( | ||
(res, curr) => ({ ...res, [curr]: getBackendRpcUrl(curr) }), | ||
{ | ||
// Required by reef-knot | ||
[CHAINS.Mainnet]: getBackendRpcUrl(CHAINS.Mainnet), | ||
}, | ||
) | ||
|
||
const { chains, provider, webSocketProvider } = configureChains( | ||
supportedChains, | ||
[ | ||
jsonRpcProvider({ | ||
rpc: chain => ({ | ||
http: backendRPC[chain.id], | ||
}), | ||
}), | ||
], | ||
) | ||
|
||
const connectors = getConnectors({ | ||
chains, | ||
defaultChain, | ||
rpc: backendRPC, | ||
walletconnectProjectId: publicRuntimeConfig.walletconnectProjectId, | ||
}) | ||
|
||
const client = createClient({ | ||
connectors, | ||
autoConnect: true, | ||
provider, | ||
webSocketProvider, | ||
}) | ||
|
||
export const AppWagmiConfig: FC = ({ children }) => { | ||
return <WagmiConfig client={client}>{children}</WagmiConfig> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './appWagmiConfig' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { type Provider } from '@ethersproject/abstract-provider' | ||
|
||
export const isContract = async ( | ||
address: string, | ||
provider: Provider, | ||
): Promise<boolean> => { | ||
const code = await provider.getCode(address) | ||
if (code != '0x') return true | ||
return false | ||
} |
12 changes: 7 additions & 5 deletions
12
modules/blockChain/utils/sendTransactionGnosisWorkaround.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.