Skip to content

Commit

Permalink
Merge pull request #145 from lidofinance/feature/si-1058-fix-reef-kno…
Browse files Browse the repository at this point in the history
…t-deps-on-lido-ethereum-sdk-playground

Update reef  knot on playground
  • Loading branch information
Jeday authored Aug 15, 2024
2 parents eae39bb + 0c406c5 commit 0a6a2b6
Show file tree
Hide file tree
Showing 30 changed files with 1,555 additions and 1,102 deletions.
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
"prism-react-renderer": "^2.3.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "3.4.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"husky": "^8.0.3",
"prettier": "^3.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
"typescript": "^5.4.5"
},
"resolutions": {
"postcss": "8.4.31",
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@
"scripts": {
"build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types",
"types": "tsc --noEmit",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'",
"build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --moduleResolution node10 --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --module nodenext --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'",
"build:types": "tsc --project tsconfig.build.json --module nodenext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
"test": "jest",
"prepublishOnly": "node scripts/updateVersion.cjs",
"lint": "eslint . --ext .ts --max-warnings 0",
Expand All @@ -157,6 +157,6 @@
"jest": "^29.7.0",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.2",
"typescript": "5.1.6"
"typescript": "^5.4.5"
}
}
2 changes: 1 addition & 1 deletion playground/components/action/action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ResultCode,
SuccessMessage,
} from './styles';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';

type ActionProps<TResult> = PropsWithChildren<{
action: () => Promise<TResult> | TResult;
Expand Down
17 changes: 11 additions & 6 deletions playground/components/connection-error/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CHAINS } from '@lido-sdk/constants';
import { Block } from '@lidofinance/lido-ui';
import { useConnectorError, useSupportedChains } from '@reef-knot/web3-react';
import { useSupportedChains, useWeb3 } from 'reef-knot/web3-react';
import { useMemo } from 'react';
import styled from 'styled-components';
import { useAccount } from 'wagmi';

const ErrorBlock = styled(Block)`
text-align: center;
Expand All @@ -12,7 +13,8 @@ const ErrorBlock = styled(Block)`
`;

export const ConnectionError = () => {
let errorMessage = useConnectorError()?.message;
const { error } = useWeb3();
const { isConnected } = useAccount();
const { isUnsupported, supportedChains } = useSupportedChains();

const chains = useMemo(() => {
Expand All @@ -24,10 +26,13 @@ export const ConnectionError = () => {
return [chains.join(', '), lastChain].filter((chain) => chain).join(' or ');
}, [supportedChains]);

if (isUnsupported) {
errorMessage = `Unsupported chain. Please switch to ${chains} in your wallet and restart the page.`;
if (isConnected && isUnsupported) {
return `Unsupported chain. Please switch to ${chains} in your wallet and restart the page.`;
}

if (!errorMessage) return null;
return <ErrorBlock color="accent">{errorMessage}</ErrorBlock>;
if (!error) {
return;
}

return <ErrorBlock color="accent">{error.message}</ErrorBlock>;
};
5 changes: 3 additions & 2 deletions playground/components/custom-rpc-input/custom-rpc-input.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useSDK } from '@lido-sdk/react';
import { useWeb3 } from 'reef-knot/web3-react';
import { Accordion, Button, DataTableRow, Input } from '@lidofinance/lido-ui';
import { useCustomRpc } from 'providers/web3';
import { useEffect, useState } from 'react';
import { Controls, StyledBlock } from './styles';
import { dynamics } from 'config';

export const CustomRpcInput = () => {
const { chainId } = useSDK();
const { chainId = dynamics.defaultChain } = useWeb3();
const { activeRpc, setCustomRpcUrl, customRpc } = useCustomRpc();
const [url, setUrl] = useState('');

Expand Down
2 changes: 1 addition & 1 deletion playground/components/layout/header/headerWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC } from 'react';
import { CHAINS, getChainColor } from '@lido-sdk/constants';

import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { ThemeToggler } from '@lidofinance/lido-ui';

import WalletButton from 'components/layout/header/walletButton';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
WalledButtonStyle,
WalledButtonWrapperStyle,
} from './walletButtonStyles';
import { useAccount } from 'wagmi';
import { useModal } from 'hooks/useModal';
import { MODAL } from 'providers';
import { useWeb3 } from '@reef-knot/web3-react';

const WalletButton: FC<ButtonProps> = (props) => {
const { onClick, ...rest } = props;
const { address } = useAccount();
const { openModal } = useModal(MODAL.wallet);
const { account } = useWeb3();

return (
<WalledButtonStyle
Expand All @@ -23,7 +23,7 @@ const WalletButton: FC<ButtonProps> = (props) => {
{...rest}
>
<WalledButtonWrapperStyle>
<AddressBadge address={account} />
<AddressBadge address={address} />
</WalledButtonWrapperStyle>
</WalledButtonStyle>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { FC } from 'react';
import { Button, ButtonProps } from '@lidofinance/lido-ui';
import { useModal } from 'hooks/useModal';
import { MODAL } from 'providers';
import { useConnect } from 'reef-knot/core-react';

const WalletConnect: FC<ButtonProps> = (props) => {
const { onClick, ...rest } = props;
const { openModal } = useModal(MODAL.connect);
const { connect } = useConnect();

return (
<Button onClick={openModal} {...rest}>
<Button onClick={connect} {...rest}>
Connect wallet
</Button>
);
Expand Down
1 change: 1 addition & 0 deletions playground/components/no-ssr-wrapper/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as default } from './no-ssr-wrapper';
10 changes: 10 additions & 0 deletions playground/components/no-ssr-wrapper/no-ssr-wrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import dynamic from 'next/dynamic';

const NoSSRWrapper = (props: { children: React.ReactNode }) => (
<>{props.children}</>
);

export default dynamic(() => Promise.resolve(NoSSRWrapper), {
ssr: false,
});
15 changes: 8 additions & 7 deletions playground/components/walletModal/walletModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
External,
Copy,
} from '@lidofinance/lido-ui';
import { useEtherscanOpen } from '@lido-sdk/react';
import { useConnectorInfo, useDisconnect, useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { useConnectorInfo, useDisconnect } from 'reef-knot/core-react';
import { useCopyToClipboard } from 'hooks/useCopyToClipboard';
import { useEtherscanOpen } from 'hooks/useEtherscanOpen';
import { FC, useCallback } from 'react';
import {
WalletModalContentStyle,
Expand All @@ -21,11 +22,11 @@ import {
WalletModalActionsStyle,
} from './walletModalStyles';

const WalletModal: FC<ModalProps> = (props) => {
const { onClose } = props;
const WalletModal: FC<ModalProps> = ({ onClose, ...props }) => {
const { account } = useWeb3();
const { providerName } = useConnectorInfo();
const { connectorName } = useConnectorInfo();
const { disconnect } = useDisconnect();

const handleDisconnect = useCallback(() => {
disconnect?.();
onClose?.();
Expand All @@ -38,9 +39,9 @@ const WalletModal: FC<ModalProps> = (props) => {
<Modal title="Account" {...props}>
<WalletModalContentStyle>
<WalletModalConnectedStyle>
{providerName && (
{connectorName && (
<WalletModalConnectorStyle>
Connected with {providerName}
Connected with {connectorName}
</WalletModalConnectorStyle>
)}

Expand Down
1 change: 0 additions & 1 deletion playground/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export const { serverRuntimeConfig } = getConfig();
export { default as dynamics } from './dynamics';
export * from './api';
export * from './locale';
export * from './rpc';
export * from './storage';
6 changes: 0 additions & 6 deletions playground/config/rpc.ts

This file was deleted.

15 changes: 9 additions & 6 deletions playground/demo/core/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useCallback, useEffect, useState } from 'react';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { Input, Accordion } from '@lidofinance/lido-ui';
import { Action, renderTokenResult } from 'components/action';
import { useLidoSDK } from 'providers/sdk';
import { renderBlockResult } from 'components/action/render-block-result';
import NoSsrWrapper from '../../components/no-ssr-wrapper/no-ssr-wrapper';

const locale = new Intl.Locale('en', { hourCycle: 'h24' });

Expand Down Expand Up @@ -65,11 +66,13 @@ export const CoreDemo = () => {
core.getLatestBlockToTimestamp(BigInt(timestampSeconds))
}
>
<Input
label={`timestamp at ${dateAtTimestamp}`}
value={timestampSeconds}
onChange={(e) => setTimestampSeconds(e.currentTarget.value)}
/>
<NoSsrWrapper>
<Input
label={`timestamp at ${dateAtTimestamp}`}
value={timestampSeconds}
onChange={(e) => setTimestampSeconds(e.currentTarget.value)}
/>
</NoSsrWrapper>
</Action>
</Accordion>
);
Expand Down
2 changes: 1 addition & 1 deletion playground/demo/shares/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Input, Accordion } from '@lidofinance/lido-ui';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { Action, renderTokenResult } from 'components/action';
import { DEFAULT_VALUE, ValueType } from 'components/tokenInput';
import TokenInput from 'components/tokenInput/tokenInput';
Expand Down
2 changes: 1 addition & 1 deletion playground/demo/stake/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Input, Accordion } from '@lidofinance/lido-ui';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { Action } from 'components/action';
import { DEFAULT_VALUE, ValueType } from 'components/tokenInput';
import TokenInput from 'components/tokenInput/tokenInput';
Expand Down
2 changes: 1 addition & 1 deletion playground/demo/tokens/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractLidoSDKErc20 } from '@lidofinance/lido-ethereum-sdk/dist/types/erc20';
import { Input, Accordion } from '@lidofinance/lido-ui';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { Action, renderTokenResult } from 'components/action';
import { DEFAULT_VALUE, ValueType } from 'components/tokenInput';
import TokenInput from 'components/tokenInput/tokenInput';
Expand Down
2 changes: 1 addition & 1 deletion playground/demo/unsteth/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Input, Accordion } from '@lidofinance/lido-ui';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { Action } from 'components/action';
import { ToggleButton } from 'components/toggle-button';

Expand Down
2 changes: 1 addition & 1 deletion playground/demo/withdrawals/claim.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Checkbox, Accordion } from '@lidofinance/lido-ui';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { RequestStatusWithId } from '@lidofinance/lido-ethereum-sdk';
import { Action } from 'components/action';
import { RequestsWrapper } from 'components/requestsWrapper';
Expand Down
2 changes: 1 addition & 1 deletion playground/demo/withdrawals/request.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Accordion, Select, Option } from '@lidofinance/lido-ui';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { Action, renderTokenResult } from 'components/action';
import TokenInput from 'components/tokenInput/tokenInput';
import { useLidoSDK } from 'providers/sdk';
Expand Down
2 changes: 1 addition & 1 deletion playground/demo/withdrawals/views.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Accordion } from '@lidofinance/lido-ui';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { Action, renderTokenResult } from 'components/action';
import { useLidoSDK } from 'providers/sdk';

Expand Down
2 changes: 1 addition & 1 deletion playground/demo/wrap/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Accordion } from '@lidofinance/lido-ui';
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { Action, renderTokenResult } from 'components/action';
import { DEFAULT_VALUE, ValueType } from 'components/tokenInput';
import TokenInput from 'components/tokenInput/tokenInput';
Expand Down
2 changes: 1 addition & 1 deletion playground/hooks/useAddressState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useWeb3 } from '@reef-knot/web3-react';
import { useWeb3 } from 'reef-knot/web3-react';
import { useEffect, useState } from 'react';
import { Address } from 'viem';

Expand Down
20 changes: 20 additions & 0 deletions playground/hooks/useEtherscanOpen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
getEtherscanLink,
openWindow,
EtherscanEntities,
} from '@lido-sdk/helpers';
import { useCallback } from 'react';
import { useAccount } from 'wagmi';

export const useEtherscanOpen = (
hash: string,
entity: EtherscanEntities,
): (() => void) => {
const { chainId } = useAccount();

return useCallback(() => {
if (chainId === undefined) return;
const link = getEtherscanLink(chainId, hash, entity);
openWindow(link);
}, [chainId, entity, hash]);
};
23 changes: 7 additions & 16 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,33 @@
"@ethersproject/constants": "^5.5.0",
"@ethersproject/units": "^5.6.1",
"@lido-sdk/constants": "^3.3.0",
"@lido-sdk/providers": "^1.4.14",
"@lido-sdk/react": "^2.0.6",
"@lido-sdk/helpers": "^1.6.0",
"@lidofinance/lido-ethereum-sdk": "workspace:*",
"@lidofinance/lido-ui": "^3.10.1",
"@lidofinance/next-cache-files-middleware": "^0.35.0",
"@reef-knot/connect-wallet-modal": "1.6.2",
"@reef-knot/core-react": "1.6.0",
"@reef-knot/ledger-connector": "1.0.1",
"@reef-knot/types": "1.3.0",
"@reef-knot/ui-react": "1.0.7",
"@reef-knot/wallets-helpers": "1.1.5",
"@reef-knot/wallets-icons": "1.0.0",
"@reef-knot/wallets-list": "1.4.5",
"@reef-knot/web3-react": "1.5.0",
"@tanstack/react-query": "^5.51.1",
"copy-to-clipboard": "^3.3.1",
"fs-extra": "^10.1.0",
"next": "^13.5.1",
"next-logger": "^3.0.0",
"prom-client": "^14.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-is": "^18.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-json-view": "^1.21.3",
"reef-knot": "^5.3.1",
"styled-components": "^5.3.5",
"swr": "^1.3.0",
"tiny-invariant": "^1.3.1",
"viem": "^2.0.6",
"wagmi": "^0.12.19"
"wagmi": "2.11.2"
},
"devDependencies": {
"@next/bundle-analyzer": "^13.4.19",
"@svgr/webpack": "^6.5.1",
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/styled-components": "^5.1.23",
"typescript": "5.1.6",
"typescript": "^5.4.5",
"url-loader": "^4.1.1"
},
"lint-staged": {
Expand Down
Loading

0 comments on commit 0a6a2b6

Please sign in to comment.