Skip to content

Commit f0e8afe

Browse files
defispartangrothemMareskoY
committed
chore: screening optimisations (#1348)
* chore: export state to exclude mock wallet from screening * chore: disable screening if watch mode enabled * fix: stub address screening api call * fix: tests wallet connect * fix: revet intercept Co-authored-by: Mark Grothe <[email protected]> Co-authored-by: NikitaY <[email protected]>
1 parent 503e55a commit f0e8afe

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

cypress/e2e/2-settings/wallet-connect.cy.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ export const closeModal = (selector: string) => {
1111
cy.get(selector).click();
1212
};
1313

14+
const walletButtonlocator = '#wallet-button';
15+
1416
describe('Manipulation on the wallet connect', () => {
1517
describe('CASE1: Disconnect and connect wallet using Wallet connect option', () => {
1618
configEnvWithTenderlyMainnetFork({});
17-
const walletButton = '#wallet-button';
1819

1920
it('step1:Disconnect wallet', () => {
2021
cy.wait(1000);
21-
cy.get(walletButton).click();
22-
cy.wait(6000);
22+
cy.get(walletButtonlocator).click();
23+
cy.wait(3000);
2324
cy.contains('Disconnect').click();
2425
cy.contains('Please, connect your wallet').should('be.visible');
2526
});
2627

2728
it('step2:Connect wallet using wallet connect', () => {
28-
cy.get(walletButton).click();
29+
cy.get(walletButtonlocator).click();
2930
optionOnConnectionModal('WalletConnect');
3031
checkElementsOnModal(
3132
'#walletconnect-qrcode-text',
@@ -39,6 +40,9 @@ describe('Manipulation on the wallet connect', () => {
3940

4041
describe('CASE2:Connect and disconnect wallet over Coinbase', () => {
4142
it('step1:Connect wallet over Coinbase', () => {
43+
cy.wait(1000);
44+
cy.get(walletButtonlocator).click();
45+
cy.wait(3000);
4246
optionOnConnectionModal('Coinbase');
4347
checkElementsOnModal('.-cbwsdk-extension-dialog-box', 'Try the Coinbase Wallet extension');
4448
closeModal('.-cbwsdk-extension-dialog-box-cancel');

src/components/AddressBlocked.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
66
import { AddressBlockedModal } from './AddressBlockedModal';
77

88
export const AddressBlocked = ({ children }: { children: ReactNode }) => {
9-
const { currentAccount, disconnectWallet } = useWeb3Context();
10-
const { isAllowed } = useAddressAllowed(currentAccount);
9+
const { currentAccount, disconnectWallet, watchModeOnly } = useWeb3Context();
10+
const screenAddress = watchModeOnly ? '' : currentAccount;
11+
const { isAllowed } = useAddressAllowed(screenAddress);
1112

1213
if (!isAllowed) {
1314
return (

src/libs/web3-data-provider/Web3Provider.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export type Web3Data = {
4747
switchNetworkError: Error | undefined;
4848
setSwitchNetworkError: (err: Error | undefined) => void;
4949
watchModeOnlyAddress: string | undefined;
50+
watchModeOnly: boolean;
5051
};
5152

5253
export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ children }) => {
@@ -68,6 +69,7 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil
6869
const [deactivated, setDeactivated] = useState(false);
6970
const [triedGnosisSafe, setTriedGnosisSafe] = useState(false);
7071
const [triedCoinbase, setTriedCoinbase] = useState(false);
72+
const [watchModeOnly, setWatchModeOnly] = useState(false);
7173
const [triedLedger, setTriedLedger] = useState(false);
7274
const [switchNetworkError, setSwitchNetworkError] = useState<Error>();
7375
const setAccount = useRootStore((store) => store.setAccount);
@@ -128,6 +130,13 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil
128130
try {
129131
const connector: AbstractConnector = getWallet(wallet, chainId);
130132

133+
if (connector instanceof WatchModeOnlyConnector) {
134+
setWatchModeOnly(true);
135+
} else {
136+
setAccount('');
137+
setWatchModeOnly(false);
138+
}
139+
131140
if (connector instanceof WalletConnectConnector) {
132141
connector.walletConnectProvider = undefined;
133142
}
@@ -432,8 +441,8 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil
432441
error,
433442
switchNetworkError,
434443
setSwitchNetworkError,
435-
watchModeOnlyAddress:
436-
connector instanceof WatchModeOnlyConnector ? account?.toLowerCase() : undefined,
444+
watchModeOnlyAddress: watchModeOnly ? account?.toLowerCase() : undefined,
445+
watchModeOnly,
437446
},
438447
}}
439448
>

0 commit comments

Comments
 (0)