Skip to content

Commit

Permalink
Merge pull request #80 from lidofinance/fix/call-terms-modal-less-fre…
Browse files Browse the repository at this point in the history
…quently

Fix: open Terms modal only if terms were not accepted earlier
  • Loading branch information
alx-khramov authored Jul 25, 2023
2 parents e00db59 + ff82576 commit 9b6bad4
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 47 deletions.
6 changes: 6 additions & 0 deletions packages/connect-wallet-modal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @reef-knot/connect-wallet-modal

## 1.6.1

### Patch Changes

- Move TERMS_ACCEPTANCE_LS_K const into core-react package

## 1.6.0

### Minor Changes
Expand Down
6 changes: 3 additions & 3 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.6.0",
"version": "1.6.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
Expand Down Expand Up @@ -41,12 +41,12 @@
"@types/react-dom": "17"
},
"devDependencies": {
"@reef-knot/core-react": "^1.5.0",
"@reef-knot/core-react": "^1.5.1",
"@reef-knot/types": "^1.3.0",
"@reef-knot/ui-react": "^1.0.7",
"@reef-knot/wallets-icons": "^1.0.0",
"@reef-knot/wallets-helpers": "^1.1.5",
"@reef-knot/web3-react": "^1.4.0",
"@reef-knot/web3-react": "^1.4.1",
"@types/ua-parser-js": "^0.7.36",
"react": "17.0.2",
"react-dom": "17.0.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useContext, useState } from 'react';
import { Button, Modal } from '@reef-knot/ui-react';
import { AcceptTermsModalContext } from '@reef-knot/core-react';
import { AcceptTermsModalContext, LS_KEY_TERMS_ACCEPTANCE } from '@reef-knot/core-react';
import {
WalletsModalProps,
ButtonsCommonProps,
Expand All @@ -20,12 +20,8 @@ export function WalletsModal(props: WalletsModalProps): JSX.Element {
privacyNoticeLink,
} = props;

// This key can be changed to enforce all users to accept the Terms again,
// for example if the Terms were significantly updated
const TERMS_ACCEPTANCE_LS_KEY = 'reef-knot_accept-terms_n2';

const [termsChecked, setTermsChecked] = useLocalStorage(
TERMS_ACCEPTANCE_LS_KEY,
LS_KEY_TERMS_ACCEPTANCE,
false,
);

Expand Down
6 changes: 6 additions & 0 deletions packages/core-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @reef-knot/core-react

## 1.5.1

### Patch Changes

- Move TERMS_ACCEPTANCE_LS_K const into core-react package

## 1.5.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reef-knot/core-react",
"version": "1.5.0",
"version": "1.5.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
Expand Down
1 change: 1 addition & 0 deletions packages/core-react/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './localStorage';
3 changes: 3 additions & 0 deletions packages/core-react/src/constants/localStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This key can be changed to enforce all users to accept the Terms again,
// for example if the Terms were significantly updated
export const LS_KEY_TERMS_ACCEPTANCE = 'reef-knot_accept-terms_n2';
2 changes: 2 additions & 0 deletions packages/core-react/src/context/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './reefKnot'
export * from './acceptTermsModal'
14 changes: 2 additions & 12 deletions packages/core-react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
export * from './walletData';
export * from './hooks';

export type { AcceptTermsModalContextValue } from './context/acceptTermsModal.js';
export {
AcceptTermsModalContext,
AcceptTermsModalContextProvider,
} from './context/acceptTermsModal.js';

export type {
ReefKnotContextValue,
ReefKnotContextProps,
} from './context/reefKnot';
export { ReefKnotContext, ReefKnot } from './context/reefKnot';
export * from './context';
export * from './constants';
10 changes: 9 additions & 1 deletion packages/eslint-config-custom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@ module.exports = {
"sourceType": "module",
"project": ["tsconfig.json"]
},
"ignorePatterns": ["*.js", "dist", "node_modules"]
"ignorePatterns": ["*.js", "dist", "node_modules"],
"settings": {
"react": {
"version": "detect"
},
"import/resolver": {
"typescript": {}
}
}
}
10 changes: 10 additions & 0 deletions packages/reef-knot/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# reef-knot

## 1.7.1

### Patch Changes

- Updated dependencies
- Updated dependencies
- @reef-knot/web3-react@1.4.1
- @reef-knot/connect-wallet-modal@1.6.1
- @reef-knot/core-react@1.5.1

## 1.6.2

### Patch Changes
Expand Down
8 changes: 4 additions & 4 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.7.0",
"version": "1.7.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
Expand Down Expand Up @@ -41,9 +41,9 @@
"lint": "eslint"
},
"dependencies": {
"@reef-knot/connect-wallet-modal": "1.6.0",
"@reef-knot/core-react": "1.5.0",
"@reef-knot/web3-react": "1.4.0",
"@reef-knot/connect-wallet-modal": "1.6.1",
"@reef-knot/core-react": "1.5.1",
"@reef-knot/web3-react": "1.4.1",
"@reef-knot/ui-react": "1.0.7",
"@reef-knot/wallets-icons": "1.0.0",
"@reef-knot/wallets-list": "1.4.4",
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.4.1

### Patch Changes

- Open Terms modal only if terms were not accepted earlier

## 1.4.0

### Minor Changes
Expand Down
4 changes: 2 additions & 2 deletions 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.4.0",
"version": "1.4.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
Expand Down Expand Up @@ -46,7 +46,7 @@
"@babel/preset-react": "7.18.6",
"@babel/preset-typescript": "7.18.6",
"@ethersproject/providers": "^5.7.2",
"@reef-knot/core-react": "^1.5.0",
"@reef-knot/core-react": "^1.5.1",
"@reef-knot/ledger-connector": "^1.0.0",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^7.0.2",
Expand Down
18 changes: 11 additions & 7 deletions packages/web3-react/src/hooks/useAutoConnect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef, useContext } from 'react';
import { AcceptTermsModalContext } from '@reef-knot/core-react';
import { AcceptTermsModalContext, LS_KEY_TERMS_ACCEPTANCE } from '@reef-knot/core-react';
import { useWeb3 } from './useWeb3';
import { useConnectorStorage } from './useConnectorStorage';
import { useConnectorInfo } from './useConnectorInfo';
Expand Down Expand Up @@ -48,16 +48,20 @@ export const useEagerConnector = (connectors: ConnectorsContextValue) => {
})();
if (!connector) return;

if (shouldAutoConnectApp) {
const onContinue = () => {
activate(connector, undefined, true);
};
acceptTermsModal.setOnContinue?.(() => onContinue);
const connectWallet = () => activate(connector, undefined, true);

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

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

await activate(connector, undefined, true);
await connectWallet();
})();
}, [
activate,
Expand Down
Loading

0 comments on commit 9b6bad4

Please sign in to comment.