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

Update libraries, rework WC URI connection, update ZenGo logo #64

Merged
merged 9 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/cold-eagles-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reef-knot/wallet-adapter-zengo': patch
---

Update ZenGo logo, wagmi 0.12.18
9 changes: 6 additions & 3 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.2.0/schema.json",
"$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": [],
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"onlyUpdatePeerDependentsWhenOutOfRange": true
}
}
10 changes: 10 additions & 0 deletions .changeset/nice-waves-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@reef-knot/connect-wallet-modal': patch
'@reef-knot/wallets-helpers': patch
'@reef-knot/core-react': patch
'@reef-knot/web3-react': patch
'@reef-knot/ui-react': patch
'@reef-knot/types': patch
---

wagmi 0.12.18
5 changes: 5 additions & 0 deletions .changeset/rotten-drinks-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reef-knot/web3-react': patch
---

Update lido-sdk packages
11 changes: 11 additions & 0 deletions .changeset/shy-bugs-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@reef-knot/wallet-adapter-blockchaincom': patch
'@reef-knot/wallet-adapter-walletconnect': patch
'@reef-knot/wallet-adapter-ambire': patch
'@reef-knot/wallet-adapter-exodus': patch
'@reef-knot/wallet-adapter-zerion': patch
'@reef-knot/wallet-adapter-taho': patch
'@reef-knot/wallet-adapter-okx': patch
---

wagmi 0.12.18
6 changes: 6 additions & 0 deletions .changeset/smart-tomatoes-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@reef-knot/connect-wallet-modal': patch
'@reef-knot/wallets-helpers': patch
---

Rework and fix WalletConnect connection via pairing URI
5 changes: 5 additions & 0 deletions .changeset/warm-hounds-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reef-knot/wallet-adapter-phantom': patch
---

wagmi 0.12.18
2 changes: 1 addition & 1 deletion apps/demo-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react-dom": "17.0.2",
"reef-knot": "*",
"styled-components": "^5.3.6",
"wagmi": "^0.12.17"
"wagmi": "^0.12.18"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"release": "changeset publish"
},
"devDependencies": {
"@changesets/cli": "^2.25.0",
"@changesets/cli": "^2.26.2",
"@lidofinance/eslint-config": "0.0.2",
"@next/eslint-plugin-next": "12.1.6",
"@rollup/plugin-babel": "5.3.1",
Expand Down Expand Up @@ -54,14 +54,12 @@
"rollup-plugin-svg-import": "1.6.0",
"rollup-plugin-typescript2": "0.34.1",
"tslib": "2.5.0",
"turbo": "^1.9.6",
"turbo": "^1.10.7",
"typescript": "^4.9.5"
},
"dependencies": {},
"resolutions": {
"@types/react": "17.0.53",
"@walletconnect/core": "^2.8.3",
"@walletconnect/ethereum-provider": "^2.8.3"
"@types/react": "17.0.53"
},
"engines": {
"node": ">=16.0.0"
Expand Down
6 changes: 4 additions & 2 deletions packages/connect-wallet-modal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,23 @@
"@reef-knot/types": "^1.2.1",
"@reef-knot/ui-react": "^1.0.4",
"@reef-knot/wallets-icons": "^1.0.0",
"@reef-knot/wallets-helpers": "^1.1.2",
"@reef-knot/web3-react": "^1.3.0",
"@types/ua-parser-js": "^0.7.36",
"react": "17.0.2",
"react-dom": "17.0.2",
"ua-parser-js": "1.0.33",
"wagmi": "^0.12.17"
"wagmi": "^0.12.18"
},
"peerDependencies": {
"@reef-knot/core-react": "^1.4.2",
"@reef-knot/types": "^1.2.1",
"@reef-knot/ui-react": "^1.0.4",
"@reef-knot/wallets-icons": "^1.0.0",
"@reef-knot/wallets-helpers": "^1.1.2",
"@reef-knot/web3-react": "^1.3.0",
"react": ">=17",
"ua-parser-js": "^1.0.33",
"wagmi": "^0.12.17"
"wagmi": "^0.12.18"
}
}
67 changes: 33 additions & 34 deletions packages/connect-wallet-modal/src/connectButtons/ConnectWC.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { FC, useCallback, useEffect, useState } from 'react';
import React, { FC, useCallback, useState } from 'react';
import { useConnect } from 'wagmi';
import { useDisconnect } from '@reef-knot/web3-react';
import { WCWarnBannerRequest } from '@reef-knot/ui-react';
import { getWalletConnectUri } from '@reef-knot/wallets-helpers';
import { ConnectButton } from '../components/ConnectButton';
import { capitalize } from '../helpers';
import { ConnectWCProps } from './types';
Expand Down Expand Up @@ -42,30 +43,6 @@ export const ConnectWC: FC<ConnectWCProps> = (props: ConnectWCProps) => {
const metricsOnClick =
metrics?.events?.click?.handlers[`onClick${walletIdCapitalized}`];

const WCURIConnector = walletconnectExtras?.connectionViaURI?.connector;
const WCURICondition = walletconnectExtras?.connectionViaURI?.condition;
const WCURIRedirectLink = walletconnectExtras?.connectionViaURI?.redirectLink;
const WCURICloseRedirectionWindow =
walletconnectExtras?.connectionViaURI?.closeRedirectionWindow ?? true;

useEffect(() => {
// BEGIN Handle WalletConnect v2 redirection (connection without QR modal)
const redirect = (uri: string) => {
if (WCURIRedirectLink)
setRedirectionWindowLocation(WCURIRedirectLink, uri);
};
let provider: any;
(async () => {
provider = await WCURIConnector?.getProvider();
provider?.on('display_uri', redirect);
})();
// END Handle WalletConnect v2 redirection (connection without QR modal)

return () => {
provider?.off('display_uri', redirect);
};
}, [WCURICondition, WCURIConnector, WCURIRedirectLink]);

const { connectAsync } = useConnect({
onSuccess() {
onConnect?.();
Expand All @@ -77,36 +54,58 @@ export const ConnectWC: FC<ConnectWCProps> = (props: ConnectWCProps) => {
const [isConnecting, setIsConnecting] = useState(false);

const handleConnect = useCallback(async () => {
// WCURI – WalletConnect Pairing URI: https://docs.walletconnect.com/2.0/specs/clients/core/pairing/pairing-uri
// Used for connection without WalletConnect QR modal via redirect
const WCURIConnector = walletconnectExtras?.connectionViaURI?.connector;
const WCURICondition = walletconnectExtras?.connectionViaURI?.condition;
const WCURIRedirectLink =
walletconnectExtras?.connectionViaURI?.redirectLink;
const WCURICloseRedirectionWindow =
walletconnectExtras?.connectionViaURI?.closeRedirectionWindow ?? true;

setIsConnecting(true);

try {
onBeforeConnect?.();
metricsOnClick?.();

disconnect?.();

if (WCURICondition) {
// because of popup blockers, window.open must be called directly from onclick handler
if (WCURICondition && WCURIConnector && WCURIRedirectLink) {
// BEGIN Handle connection via redirect using WC Pairing URI (without WalletConnect QR modal)
// Because of popup blockers, window.open must be called directly from onclick handler
redirectionWindow = window.open('', '_blank');
redirectionWindow?.document.write(getRedirectionLoadingHTML());
await connectAsync({ connector: WCURIConnector });
if (WCURICloseRedirectionWindow) {
redirectionWindow?.close();
}

// Initiate a connection, but do not block the further execution
connectAsync({ connector: WCURIConnector }).then(() => {
// We got a connection result
if (WCURICloseRedirectionWindow) {
// Close the previously opened window if necessary
redirectionWindow?.close();
}
});

// Wait for WalletConnect Pairing URI to arrive
const wcUri = await getWalletConnectUri(WCURIConnector);
setRedirectionWindowLocation(WCURIRedirectLink, wcUri);
// END Handle connection via redirect using WC Pairing URI (without WalletConnect QR modal)
} else {
await connectAsync({ connector });
}
} finally {
setIsConnecting(false);
}
}, [
WCURICloseRedirectionWindow,
WCURICondition,
WCURIConnector,
connectAsync,
connector,
disconnect,
metricsOnClick,
onBeforeConnect,
walletconnectExtras?.connectionViaURI?.closeRedirectionWindow,
walletconnectExtras?.connectionViaURI?.condition,
walletconnectExtras?.connectionViaURI?.connector,
walletconnectExtras?.connectionViaURI?.redirectLink,
]);

const WalletIcon = icon || icons;
Expand Down
4 changes: 2 additions & 2 deletions packages/core-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
},
"devDependencies": {
"react": "17.0.2",
"wagmi": "^0.12.17",
"wagmi": "^0.12.18",
"@reef-knot/wallets-list": "^1.4.1",
"@reef-knot/types": "^1.2.1",
"@reef-knot/ui-react": "^1.0.4"
},
"peerDependencies": {
"react": ">=17",
"wagmi": "^0.12.17",
"wagmi": "^0.12.18",
"@reef-knot/wallets-list": "^1.4.1",
"@reef-knot/types": "^1.2.1",
"@reef-knot/ui-react": "^1.0.4"
Expand Down
4 changes: 2 additions & 2 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
},
"devDependencies": {
"react": "17.0.2",
"wagmi": "^0.12.17"
"wagmi": "^0.12.18"
},
"peerDependencies": {
"react": ">=17",
"wagmi": "^0.12.17"
"wagmi": "^0.12.18"
}
}
4 changes: 2 additions & 2 deletions packages/ui-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
"react-dom": ">=17",
"react-is": ">=17",
"styled-components": "5",
"wagmi": "^0.12.17"
"wagmi": "^0.12.18"
},
"devDependencies": {
"react": "17.0.2",
"react-dom": "17.0.2",
"react-is": "17.0.2",
"styled-components": "^5.3.6",
"@types/react-transition-group": "4.4.2",
"wagmi": "^0.12.17"
"wagmi": "^0.12.18"
}
}
4 changes: 2 additions & 2 deletions packages/wallets-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
"lint": "eslint"
},
"devDependencies": {
"wagmi": "^0.12.17",
"wagmi": "^0.12.18",
"ua-parser-js": "1.0.33"
},
"peerDependencies": {
"react": ">=17",
"wagmi": "^0.12.17",
"wagmi": "^0.12.18",
"ua-parser-js": "1.0.33"
}
}
1 change: 0 additions & 1 deletion packages/wallets-helpers/src/factories/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/wallets-helpers/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './factories';
export * from './walletconnect';
export * from './utils';
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export const getWalletConnectConnector = ({
qrcode?: boolean;
chains: Chain[];
}) => {
if (!projectId) {
throw new Error(
'No WalletConnect Project ID found, it is required by WalletConnect v2: https://docs.walletconnect.com/2.0/cloud/relay#project-id',
);
}

const params = {
chains,
options: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Connector } from 'wagmi/connectors';

export const getWalletConnectUri = async (connector: Connector) => {
const provider = await connector.getProvider();
return new Promise<string>((resolve) => {
provider.once('display_uri', resolve);
});
};
2 changes: 2 additions & 0 deletions packages/wallets-helpers/src/walletconnect/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './getWalletConnectConnector';
export * from './getWalletConnectUri';
2 changes: 1 addition & 1 deletion packages/wallets/ambire/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@svgr/rollup": "^6.5.1"
},
"peerDependencies": {
"wagmi": "^0.12.17",
"wagmi": "^0.12.18",
"@reef-knot/wallets-helpers": "^1.1.2",
"@reef-knot/types": "^1.2.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/blockchaincom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@svgr/rollup": "^6.5.1"
},
"peerDependencies": {
"wagmi": "^0.12.17",
"wagmi": "^0.12.18",
"@reef-knot/wallets-helpers": "^1.1.2",
"@reef-knot/types": "^1.2.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/exodus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@svgr/rollup": "^6.5.1"
},
"peerDependencies": {
"wagmi": "^0.12.17",
"wagmi": "^0.12.18",
"@reef-knot/types": "^1.2.1"
}
}
2 changes: 1 addition & 1 deletion packages/wallets/okx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@svgr/rollup": "^6.5.1"
},
"peerDependencies": {
"wagmi": "^0.12.17",
"wagmi": "^0.12.18",
"@reef-knot/types": "^1.2.1"
}
}
2 changes: 1 addition & 1 deletion packages/wallets/phantom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@svgr/rollup": "^6.5.1"
},
"peerDependencies": {
"wagmi": "^0.12.17",
"wagmi": "^0.12.18",
"@reef-knot/types": "^1.2.1"
}
}
2 changes: 1 addition & 1 deletion packages/wallets/taho/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@svgr/rollup": "^6.5.1"
},
"peerDependencies": {
"wagmi": "^0.12.17",
"wagmi": "^0.12.18",
"@reef-knot/types": "^1.2.1"
}
}
2 changes: 1 addition & 1 deletion packages/wallets/walletconnect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@svgr/rollup": "^6.5.1"
},
"peerDependencies": {
"wagmi": "^0.12.17",
"wagmi": "^0.12.18",
"@reef-knot/wallets-helpers": "^1.1.2",
"@reef-knot/types": "^1.2.1"
}
Expand Down
Loading