Skip to content

Commit

Permalink
Merge pull request #106 from lidofinance/fix/autoconnect-terms
Browse files Browse the repository at this point in the history
Fix: Terms modal not closing during autoconnect
  • Loading branch information
alx-khramov authored Nov 27, 2023
2 parents 8d40c7d + f1a379c commit 1ce20c7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
7 changes: 7 additions & 0 deletions packages/reef-knot/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# reef-knot

## 1.11.1

### Patch Changes

- Updated dependencies
- @reef-knot/web3-react@1.9.1

## 1.10.7

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/reef-knot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reef-knot",
"version": "1.11.0",
"version": "1.11.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
Expand Down Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@reef-knot/connect-wallet-modal": "1.11.0",
"@reef-knot/core-react": "1.7.0",
"@reef-knot/web3-react": "1.9.0",
"@reef-knot/web3-react": "1.9.1",
"@reef-knot/ui-react": "1.0.7",
"@reef-knot/wallets-icons": "1.3.0",
"@reef-knot/wallets-list": "1.7.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/web3-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @reef-knot/web3-react

## 1.9.1

### Patch Changes

- Fix an issue with the terms modal not closing until page restart.

## 1.9.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reef-knot/web3-react",
"version": "1.9.0",
"version": "1.9.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
Expand Down
17 changes: 9 additions & 8 deletions packages/web3-react/src/hooks/useAutoConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { useDisconnect } from './useDisconnect';
import { ConnectorsContextValue } from '../context';
import { isDappBrowserProvider } from '../helpers';

const isTermsAccepted = () => {
if (typeof window !== 'undefined') {
return window.localStorage?.getItem(LS_KEY_TERMS_ACCEPTANCE) === 'true';
}
return false;
};

export const useAutoConnect = (connectors: ConnectorsContextValue) => {
useEagerConnector(connectors);
useSaveConnectorToLS();
Expand Down Expand Up @@ -59,7 +66,7 @@ export const useEagerConnector = (connectors: ConnectorsContextValue) => {
error = e as Error;
}
if (shouldAutoConnectApp) {
if (!termsAccepted || error) {
if (!isTermsAccepted() || error) {
acceptTermsModal.setError?.(error);
acceptTermsModal.setVisible?.(true);
} else {
Expand All @@ -69,13 +76,7 @@ export const useEagerConnector = (connectors: ConnectorsContextValue) => {
}
};

let termsAccepted = false;
if (typeof window !== 'undefined') {
termsAccepted =
window.localStorage?.getItem(LS_KEY_TERMS_ACCEPTANCE) === 'true';
}

if (shouldAutoConnectApp && !termsAccepted) {
if (shouldAutoConnectApp && !isTermsAccepted()) {
acceptTermsModal.setOnContinue?.(() => connectWallet);
acceptTermsModal.setVisible?.(true);
return;
Expand Down

0 comments on commit 1ce20c7

Please sign in to comment.