Skip to content

Commit

Permalink
feat: bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Jun 29, 2023
1 parent 9908523 commit 521827c
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 244 deletions.
6 changes: 2 additions & 4 deletions packages/web-lib/components/ModalLogin.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {cloneElement, useCallback} from 'react';
import {useWeb3} from '@yearn-finance/web-lib//contexts/useWeb3';
import {Modal} from '@yearn-finance/web-lib/components/Modal';
import {yToast} from '@yearn-finance/web-lib/components/yToast';
import {useWeb3} from '@yearn-finance/web-lib/contexts/useWeb3';
import {useInjectedWallet} from '@yearn-finance/web-lib/hooks/useInjectedWallet';
import IconWalletWalletConnect from '@yearn-finance/web-lib/icons/IconWalletWalletConnect';

Expand Down Expand Up @@ -53,12 +53,10 @@ function ModalLogin(props: TModalLogin): ReactElement {
(): void => onClose()
);
}}
className={'yearn--modalLogin-card cursor-not-allowed !bg-neutral-100/40 !opacity-25'}>
className={'yearn--modalLogin-card !bg-neutral-100/40'}>
<div><IconWalletWalletConnect className={'h-12 w-12'} /></div>
<b>{'WalletConnect'}</b>
</div>
<p className={'col-span-2 text-center text-xs !text-neutral-500'}>{'WalletConnect is temporarily disabled due to a shutdown of their V1 services. As soon as we will be whitelisted on their V2, this functionality will be reenabled.'}</p>

</div>
</Modal>
);
Expand Down
6 changes: 3 additions & 3 deletions packages/web-lib/contexts/WithYearn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import type {FallbackTransport} from 'viem';
import type {Config, PublicClient, WebSocketPublicClient} from 'wagmi';
import type {TSettingsBase, TSettingsOptions, TUIOptions, TWeb3Options} from '@yearn-finance/web-lib/types/contexts';

function WithYearn({children, configOverwrite, options}: {
function WithYearn({children, config, options}: {
children: ReactElement
configOverwrite?: Config<PublicClient<FallbackTransport>, WebSocketPublicClient<FallbackTransport>>
config: Config<PublicClient<FallbackTransport>, WebSocketPublicClient<FallbackTransport>>
options?: {
ui?: TUIOptions,
web3?: TWeb3Options,
Expand All @@ -24,7 +24,7 @@ function WithYearn({children, configOverwrite, options}: {
networksOptions={options?.networks}
baseOptions={options?.baseSettings}>
<Web3ContextApp
configOverwrite={configOverwrite}
config={config}
options={options?.web3}>
{children}
</Web3ContextApp>
Expand Down
85 changes: 10 additions & 75 deletions packages/web-lib/contexts/useWeb3.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,17 @@
import React, {createContext, useCallback, useContext, useMemo, useState} from 'react';
import {arbitrum, fantom, gnosis, optimism, polygon} from 'viem/chains';
import {configureChains, createConfig, mainnet, useAccount, useConnect, useDisconnect, useEnsName, useNetwork, usePublicClient, useSwitchNetwork, useWalletClient, WagmiConfig} from 'wagmi';
import {CoinbaseWalletConnector} from 'wagmi/connectors/coinbaseWallet';
import {InjectedConnector} from 'wagmi/connectors/injected';
import {LedgerConnector} from 'wagmi/connectors/ledger';
import {MetaMaskConnector} from 'wagmi/connectors/metaMask';
import {SafeConnector} from 'wagmi/connectors/safe';
import {publicProvider} from 'wagmi/providers/public';
import {useAccount, useConnect, useDisconnect, useEnsName, useNetwork, usePublicClient, useSwitchNetwork, useWalletClient, WagmiConfig} from 'wagmi';
import {useIsMounted, useUpdateEffect} from '@react-hookz/web';
import {ModalLogin} from '@yearn-finance/web-lib/components/ModalLogin';
import {deepMerge} from '@yearn-finance/web-lib/contexts/utils';
import {useSupportedChainsID} from '@yearn-finance/web-lib/hooks/useSupportedChainsID';
import {toAddress} from '@yearn-finance/web-lib/utils/address';
import {isIframe} from '@yearn-finance/web-lib/utils/helpers';
import {IFrameEthereumConnector} from '@yearn-finance/web-lib/utils/web3/ledgerConnector';
import {getRPC} from '@yearn-finance/web-lib/utils/web3/providers';

import {useSupportedChainsID} from '../hooks/useSupportedChainsID';

import type {ReactElement} from 'react';
import type {BaseError, FallbackTransport} from 'viem';
import type {Chain, Config, PublicClient, WebSocketPublicClient} from 'wagmi';
import type {Config, PublicClient, WebSocketPublicClient} from 'wagmi';
import type {TWeb3Context, TWeb3Options} from '@yearn-finance/web-lib/types/contexts';

const localhost = {
id: 1_337,
name: 'Localhost',
network: 'localhost',
nativeCurrency: {
decimals: 18,
name: 'Ether',
symbol: 'ETH'
},
rpcUrls: {
default: {http: ['http://0.0.0.0:8545', 'http://127.0.0.1:8545', 'http://localhost:8545']},
public: {http: ['http://0.0.0.0:8545', 'http://127.0.0.1:8545', 'http://localhost:8545']}
},
contracts: {
ensRegistry: {
address: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e'
},
ensUniversalResolver: {
address: '0xE4Acdd618deED4e6d2f03b9bf62dc6118FC9A4da',
blockCreated: 16773775
},
multicall3: {
address: '0xca11bde05977b3631167028862be2a173976ca11',
blockCreated: 14353601
}
}
} as const satisfies Chain;

const defaultState = {
address: undefined,
ens: undefined,
Expand All @@ -73,33 +35,6 @@ const defaultOptions = {
};

const Web3Context = createContext<TWeb3Context>(defaultState);
const {chains, publicClient, webSocketPublicClient} = configureChains(
[mainnet, optimism, polygon, gnosis, fantom, arbitrum, localhost],
[publicProvider()]
);
const config = createConfig({
autoConnect: true,
publicClient,
webSocketPublicClient,
connectors: [
new SafeConnector({chains, options: {allowedDomains: [/gnosis-safe.io/, /app.safe.global/]}}),
new IFrameEthereumConnector({chains, options: {}}),
new InjectedConnector({chains}),
new MetaMaskConnector(),
new LedgerConnector({chains}),
// new WalletConnectConnector({
// chains,
// options: {projectId: process.env.WALLETCONNECT_PROJECT_ID as string}
// }),
new CoinbaseWalletConnector({
options: {
jsonRpcUrl: getRPC(1),
appName: process.env.WEBSITE_TITLE as string
}
})
]
});

export const Web3ContextAppWrapper = ({children, options}: {children: ReactElement, options?: TWeb3Options}): ReactElement => {
const {address, isConnecting, isConnected, isDisconnected, connector} = useAccount();
const {connectAsync, connectors} = useConnect();
Expand Down Expand Up @@ -139,8 +74,8 @@ export const Web3ContextAppWrapper = ({children, options}: {children: ReactEleme
await connectAsync({connector: connectors[2], chainId: currentChainID});
} else if (providerType === 'INJECTED_LEDGER') {
await connectAsync({connector: connectors[4], chainId: currentChainID});
// } else if (providerType === 'WALLET_CONNECT') {
// await connectAsync({connector: connectors[5], chainId: currentChainID});
} else if (providerType === 'WALLET_CONNECT') {
await connectAsync({connector: connectors[5], chainId: currentChainID});
} else if (providerType === 'EMBED_LEDGER') {
await connectAsync({connector: connectors[1], chainId: currentChainID});
} else if (providerType === 'EMBED_GNOSIS_SAFE') {
Expand Down Expand Up @@ -185,9 +120,9 @@ export const Web3ContextAppWrapper = ({children, options}: {children: ReactEleme
case 'ledger':
return ('EMBED_LEDGER');
case 'walletConnectLegacy':
return ('NONE'); // return ('WALLET_CONNECT');
return ('WALLET_CONNECT');
case 'walletConnect':
return ('NONE'); // return ('WALLET_CONNECT');
return ('WALLET_CONNECT');
case 'coinbaseWallet':
return ('EMBED_COINBASE');
default:
Expand Down Expand Up @@ -236,13 +171,13 @@ export const Web3ContextAppWrapper = ({children, options}: {children: ReactEleme
);
};

export const Web3ContextApp = ({children, configOverwrite, options}: {
export const Web3ContextApp = ({children, config, options}: {
children: ReactElement,
configOverwrite?: Config<PublicClient<FallbackTransport>, WebSocketPublicClient<FallbackTransport>>,
config: Config<PublicClient<FallbackTransport>, WebSocketPublicClient<FallbackTransport>>,
options?: TWeb3Options
}): ReactElement => {
return (
<WagmiConfig config={configOverwrite || config}>
<WagmiConfig config={config}>
<Web3ContextAppWrapper options={options}>
{children}
</Web3ContextAppWrapper>
Expand Down
8 changes: 4 additions & 4 deletions packages/web-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yearn-finance/web-lib",
"version": "0.20.83",
"version": "0.20.84",
"files": [
"."
],
Expand All @@ -26,7 +26,7 @@
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/line-clamp": "^0.4.4",
"@tailwindcss/typography": "^0.5.9",
"@wagmi/core": "^1.1.0",
"@wagmi/core": "^1.3.3",
"axios": "^1.4.0",
"dayjs": "^1.11.8",
"graphql": "^16.6.0",
Expand All @@ -36,8 +36,8 @@
"react-dom": "^18.2.0",
"react-hot-toast": "2.4.1",
"tailwindcss": "^3.3.2",
"viem": "^1.0.0",
"wagmi": "^1.1.0",
"viem": "^1.2.5",
"wagmi": "^1.3.3",
"zod": "^3.21.4"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-lib/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function isIframe(): boolean {
if (typeof(window) === 'undefined') {
return false;
}
if (window !== window.top || window.parent.frames.length > 0) {
if (window !== window.top || window.top !== window.self || document.location.ancestorOrigins.length !== 0) {
return true;
}
return false;
Expand Down
Loading

0 comments on commit 521827c

Please sign in to comment.