Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reef Knot v2: rework autoconnect and remove legacy #119

Merged
merged 21 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6c08cb3
feat(types): add autoConnectOnly field to WalletAdapterData
alx-khramov Jan 25, 2024
0348815
feat(demo-react): disable default wagmi autoconnect
alx-khramov Jan 26, 2024
713793e
feat(ledger-connector): rework ledger live connector for wagmi
alx-khramov Jan 26, 2024
fc399a8
feat(connect-wallet-modal): do not display autoConnectOnly wallet ada…
alx-khramov Jan 26, 2024
91d2c9a
feat: add wallet-adapter-ledger-live
alx-khramov Jan 26, 2024
0ba6e4a
feat(reef-knot): re-export @reef-knot/types package
alx-khramov Feb 2, 2024
79176d4
feat: add dappBrowserInjected wallet adapter
alx-khramov Feb 2, 2024
c2ea572
feat: add Safe wallet adapter
alx-khramov Feb 2, 2024
7d4182a
feat(wallets-list): add new adapters
alx-khramov Feb 2, 2024
05c3923
refactor(ledger-connector): detector function
alx-khramov Feb 2, 2024
ebb7d0a
fix(connect-wallet-modal): minor fixes
alx-khramov Feb 2, 2024
fd8f76e
feat(core-react): autoconnect based on wagmi
alx-khramov Feb 2, 2024
1719218
feat(web3-react): rm lido-sdk and web3-react related code
alx-khramov Feb 2, 2024
1f47f61
feat(demo-react): add favicon and manifest for Safe
alx-khramov Feb 2, 2024
e836c25
feat(demo-react): rework context providers
alx-khramov Feb 2, 2024
d477a00
chore: update yarn.lock
alx-khramov Feb 2, 2024
1046886
chore: add changesets
alx-khramov Feb 2, 2024
f4a968e
chore: set new package versions
alx-khramov Feb 2, 2024
88699e1
fix: rm console.log
alx-khramov Feb 8, 2024
745d134
fix(core-react): getUnsupportedChainError text
alx-khramov Feb 8, 2024
7a6b67e
feat(core-react): rework useAutoConnect
alx-khramov Feb 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React from 'react';
import { WagmiConfig, createClient, configureChains, Chain } from 'wagmi';
import { goerli, mainnet } from 'wagmi/chains';
import { ProviderWeb3 } from 'reef-knot/web3-react';
import { getConnectors, holesky } from 'reef-knot/core-react';
import { ReefKnot, getConnectors, holesky } from 'reef-knot/core-react';
import { getStaticRpcBatchProvider } from '@lido-sdk/providers';
import { ProviderSDKWithProps } from './ProviderSDKWithProps';
import { getRPCPath } from '../util/contractTestingUtils';
import { rpcUrlsString } from '../util/rpc';
import { WC_PROJECT_ID } from '../util/walletconnectProjectId';

const supportedChains = [holesky, mainnet, goerli];
const supportedChainsIds = supportedChains.map((chain) => chain.id);
const defaultChainId = holesky.id;

const jsonRpcBatchProvider = (chain: Chain) => ({
Expand All @@ -34,23 +33,38 @@ const connectors = getConnectors({

const client = createClient({
connectors,
autoConnect: true,
autoConnect: false, // default wagmi autoConnect should be false
provider,
webSocketProvider,
});

const ProviderWeb3WithProps = ({ children }: { children: React.ReactNode }) => {
const ConfigContextProviders = ({
children,
}: {
children: React.ReactNode;
}) => {
const defaultChain =
supportedChains.find((chain) => chain.id === defaultChainId) ||
supportedChains[0];

return (
<WagmiConfig client={client}>
<ProviderWeb3
defaultChainId={defaultChainId}
supportedChainIds={supportedChainsIds}
<ReefKnot
rpc={rpcUrlsString}
chains={supportedChains}
defaultChain={defaultChain}
walletconnectProjectId={WC_PROJECT_ID}
autoConnect
>
{children}
</ProviderWeb3>
<ProviderSDKWithProps
DiRaiks marked this conversation as resolved.
Show resolved Hide resolved
defaultChainId={defaultChain.id}
supportedChains={supportedChains}
rpc={rpcUrlsString}
>
{children}
</ProviderSDKWithProps>
</ReefKnot>
</WagmiConfig>
);
};
export default ProviderWeb3WithProps;
export default ConfigContextProviders;
1 change: 1 addition & 0 deletions apps/demo-react/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Header = () => (
<Head>
<title>Reef Knot demo app</title>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<link rel="icon" type="image/png" href="/reef-knot-logo-32x32.png" />
<style>{`
body {
font-family: sans-serif;
Expand Down
70 changes: 70 additions & 0 deletions apps/demo-react/components/ProviderSDKWithProps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { useEffect, useState } from 'react';
import { ProviderSDK } from '@lido-sdk/react';
import { getStaticRpcBatchProvider } from '@lido-sdk/providers';
import { Web3Provider } from '@ethersproject/providers';
import { Chain, useAccount } from 'wagmi';
import { mainnet } from 'wagmi/chains';
import { useWeb3 } from 'reef-knot/web3-react';

const POLLING_INTERVAL = 12_000;

export const ProviderSDKWithProps = (props: {
children?: React.ReactNode;
defaultChainId: number;
supportedChains: Chain[];
rpc: Record<number, string>;
}) => {
const { children, defaultChainId, rpc, supportedChains } = props;
const { chainId = defaultChainId, account } = useWeb3();
const { connector, isConnected } = useAccount();

const [providerWeb3, setProviderWeb3] = useState<Web3Provider>();

// Reset web3 provider if the provider was set previously,
// and currently no wallet is connected.
// Gets triggered on a wallet disconnection, for example.
if (!isConnected && providerWeb3) {
setProviderWeb3(undefined);
}

useEffect(() => {
void (async () => {
if (!providerWeb3 && connector && isConnected) {
const provider = await connector.getProvider();
const wrappedProvider = new Web3Provider(provider);
wrappedProvider.pollingInterval = POLLING_INTERVAL;
setProviderWeb3(wrappedProvider);
}
});
}, [connector, isConnected, providerWeb3]);

const supportedChainIds = supportedChains.map((chain) => chain.id);

const providerRpc = getStaticRpcBatchProvider(
chainId,
rpc[chainId],
0,
POLLING_INTERVAL,
);

const providerMainnetRpc = getStaticRpcBatchProvider(
mainnet.id,
rpc[mainnet.id],
0,
POLLING_INTERVAL,
);

return (
// @ts-expect-error Property children does not exist on type
<ProviderSDK
chainId={chainId}
supportedChainIds={supportedChainIds}
providerWeb3={providerWeb3}
providerRpc={providerRpc}
providerMainnetRpc={providerMainnetRpc}
account={account ?? undefined}
>
{children}
</ProviderSDK>
);
};
2 changes: 1 addition & 1 deletion apps/demo-react/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { default as ConnectDisconnect } from './ConnectDisconnect';
export { default as Header } from './Header';
export { default as MainContainer } from './MainContainer';
export { default as ProviderWeb3WithProps } from './ProviderWeb3WithProps';
export { default as ProviderWeb3WithProps } from './ConfigContextProviders';
export { default as ThemeSelect } from './ThemeSelect';
export { default as WalletsModal } from './WalletsModal';
export { default as ContractTesting } from './contractTesting/index';
Expand Down
22 changes: 22 additions & 0 deletions apps/demo-react/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,26 @@ export default withBundleAnalyzer({
publicRuntimeConfig: {
alchemyApiKey,
},
async headers() {
return [
{
// required for Gnosis Safe apps
source: '/manifest.json',
headers: [
{
key: "Access-Control-Allow-Origin",
value: '*',
},
{
key: "Access-Control-Allow-Methods",
value: 'GET',
},
{
key: "Access-Control-Allow-Headers",
value: 'X-Requested-With, content-type, Authorization',
},
],
},
]
}
})
18 changes: 18 additions & 0 deletions apps/demo-react/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "ReefKnot Demo App",
"short_name": "ReefKnot",
"description": "Application for demonstrating how ReefKnot works and for development purposes.",
"iconPath": "reef-knot-logo.svg",
"icons": [
{
"src": "/reef-knot-logo-32x32.png",
"sizes": "32x32",
"type": "image/png"
},
{
"src": "/reef-knot-logo.svg",
"sizes": "64x64",
"type": "image/svg+xml"
}
]
}
Binary file added apps/demo-react/public/reef-knot-logo-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions apps/demo-react/public/reef-knot-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions packages/connect-wallet-modal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @reef-knot/connect-wallet-modal

## 2.0.0

### Minor Changes

- 1046886: Support autoConnectOnly wallet adapters

### Patch Changes

- Updated dependencies [1046886]
- @reef-knot/[email protected]
- @reef-knot/[email protected]
- @reef-knot/[email protected]

## 1.17.1

### Patch Changes
Expand Down
16 changes: 8 additions & 8 deletions packages/connect-wallet-modal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reef-knot/connect-wallet-modal",
"version": "1.17.1",
"version": "2.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
Expand Down Expand Up @@ -45,12 +45,12 @@
"@types/react-dom": "18.2.17"
},
"devDependencies": {
"@reef-knot/core-react": "^1.8.1",
"@reef-knot/types": "^1.4.0",
"@reef-knot/core-react": "^2.0.0",
"@reef-knot/types": "^1.5.0",
"@reef-knot/ui-react": "^1.0.8",
"@reef-knot/wallets-helpers": "^1.1.5",
"@reef-knot/web3-react": "^1.13.0",
"@reef-knot/ledger-connector": "^2.0.1",
"@reef-knot/web3-react": "^2.0.0",
"@reef-knot/ledger-connector": "^3.0.0",
"@types/ua-parser-js": "^0.7.36",
"eslint-config-custom": "*",
"react": "18.2.0",
Expand All @@ -59,12 +59,12 @@
"wagmi": "^0.12.19"
},
"peerDependencies": {
"@reef-knot/core-react": "^1.4.2",
"@reef-knot/core-react": "^2.0.0",
"@reef-knot/types": "^1.2.1",
"@reef-knot/ui-react": "^1.0.4",
"@reef-knot/wallets-helpers": "^1.1.2",
"@reef-knot/web3-react": "^1.12.0",
"@reef-knot/ledger-connector": "^2.0.0",
"@reef-knot/web3-react": "^2.0.0",
"@reef-knot/ledger-connector": "^3.0.0",
"react": ">=18",
"@lidofinance/lido-ui": "^3.18.0",
"ua-parser-js": "^1.0.33",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useLedgerAccounts, useLedgerContext } from './hooks';
import { getFirstIndexOnPage, saveLedgerDerivationPath } from './helpers';
import { Metrics } from '../WalletsModal';
import { LedgerDerivationPathSelect } from './LedgerDerivationPathSelect';
import { AccountsStorage } from './types';
import { AccountRecord, AccountsStorage } from './types';
import { DERIVATION_PATHS } from './constants';

const BoxWrapper = styled.div`
Expand Down Expand Up @@ -70,7 +70,7 @@ export const LedgerAccountScreen: FC<Props> = ({ metrics, closeScreen }) => {
);

const handleAccountButtonClick = useCallback(
async (account) => {
async (account: AccountRecord) => {
saveLedgerDerivationPath(account.path);
await disconnectTransport(true);
try {
Expand All @@ -83,7 +83,7 @@ export const LedgerAccountScreen: FC<Props> = ({ metrics, closeScreen }) => {
[closeScreen, connect, disconnectTransport, ledgerConnector, setError],
);

const handleDerivationPathSelect = useCallback((value) => {
const handleDerivationPathSelect = useCallback((value: string) => {
setCurrentPage(1);
setDerivationPathTemplate(value);
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export function getWalletsButtons({
let wallets: string[] = [];

walletDataList.forEach((walletData) => {
const { walletId, detector } = walletData;
addWalletTo(wallets, walletId, !!detector?.());
const { walletId, detector, autoConnectOnly } = walletData;
if (!autoConnectOnly) {
addWalletTo(wallets, walletId, !!detector?.());
}
});

wallets = [...wallets].filter(
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-wallet-modal/src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './user-agents';
export * from './userAgents';
export * from './noop';
export * from './capitalize';
export * from './useLocalStorage';
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-wallet-modal/src/helpers/suggestApp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { openWindow } from './openWindow';
import { isAndroid, isIOS } from './user-agents';
import { isAndroid, isIOS } from './userAgents';

export const suggestApp = (urls: {
default: string;
Expand Down
6 changes: 6 additions & 0 deletions packages/connectors/ledger-connector/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @reef-knot/ledger-connector

## 3.0.0

### Major Changes

- 1046886: Rework: use wagmi for Ledger Live connector instead of web3-react

## 2.0.1

### Patch Changes
Expand Down
19 changes: 10 additions & 9 deletions packages/connectors/ledger-connector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reef-knot/ledger-connector",
"version": "2.0.1",
"version": "3.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
Expand Down Expand Up @@ -37,14 +37,15 @@
"eslint-config-custom": "*"
},
"dependencies": {
"@ethersproject/abstract-signer": "^5.5.0",
"@ethersproject/bignumber": "^5.5.0",
"@ethersproject/bytes": "^5.5.0",
"@ethersproject/properties": "^5.5.0",
"@ethersproject/providers": "^5.5.2",
"@ethersproject/strings": "^5.5.0",
"@ethersproject/transactions": "^5.5.0",
"@ethersproject/hash": "^5.5.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/properties": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@ethersproject/strings": "^5.7.0",
"@ethersproject/transactions": "^5.7.0",
"@ethersproject/hash": "^5.7.0",
"@ethersproject/address": "^5.7.0",
"@ledgerhq/hw-app-eth": "^6.35.2",
"@ledgerhq/hw-transport": "^6.30.1",
"@ledgerhq/hw-transport-webhid": "^6.28.1",
Expand Down
Loading