Skip to content

Commit 93e018b

Browse files
authored
Merge pull request #112 from nspcc-dev/fix/111-endless_reloading
Endless reloading after connect wallet
2 parents cdd8f2c + 8e0091a commit 93e018b

File tree

3 files changed

+22
-39
lines changed

3 files changed

+22
-39
lines changed

src/App.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,8 @@ export const App = () => {
148148
};
149149

150150
useEffect(() => {
151-
if (localStorage['wc@2:client//session:settled'] === '[]') {
152-
onDisconnectWallet();
153-
}
154-
}, [wcSdk]); // eslint-disable-line react-hooks/exhaustive-deps
155-
156-
useEffect(() => {
157-
if (wcSdk.isConnected()) {
158-
onPopup('success', 'Wallet connected');
159-
if (localStorage.walletData && JSON.parse(localStorage.walletData).expiry > new Date().getTime()) {
160-
const walletDataTemp = JSON.parse(localStorage.walletData);
161-
setWalletData(walletDataTemp);
162-
} else {
163-
if (localStorage.walletData) {
164-
localStorage.removeItem('walletData');
165-
}
151+
if (process.env.REACT_APP_WC_PROJECT_ID && process.env.REACT_APP_WC_PROJECT_ID !== '') {
152+
if (wcSdk.isConnected()) {
166153
setWalletData({
167154
type: wcSdk.session.namespaces.neo3.accounts[0].split(':')[0],
168155
net: wcSdk.session.namespaces.neo3.accounts[0].split(':')[1],
@@ -173,12 +160,22 @@ export const App = () => {
173160
object: {}
174161
}
175162
});
163+
onPopup('success', 'Wallet connected');
164+
onModal();
165+
166+
if (location.pathname.indexOf('/profile') === -1) {
167+
document.location.href = "/profile";
168+
}
169+
} else if (walletData) {
170+
onDisconnectWallet();
171+
if (location.pathname !== '/') {
172+
document.location.href = "/";
173+
}
176174
}
177-
onModal();
178-
} else if (walletData) {
179-
onDisconnectWallet();
175+
} else {
176+
onModal('failed', 'Error: Global variable REACT_APP_WC_PROJECT_ID is not set.');
180177
}
181-
}, [wcSdk.isConnected()]); // eslint-disable-line react-hooks/exhaustive-deps
178+
}, [wcSdk]); // eslint-disable-line react-hooks/exhaustive-deps
182179

183180
const onResetContainerForm = () => {
184181
setContainerForm({
@@ -212,7 +209,6 @@ export const App = () => {
212209
if (!walletDataTemp.expiry || walletDataTemp.expiry < new Date().getTime()) {
213210
walletDataTemp.expiry = new Date().getTime() + 7200000;
214211
}
215-
localStorage.setItem('walletData', JSON.stringify(walletDataTemp));
216212
setWalletData(walletDataTemp);
217213
}
218214

@@ -490,7 +486,6 @@ export const App = () => {
490486
const onDisconnectWallet = async () => {
491487
await wcSdk.disconnect();
492488
onPopup('success', 'Wallet disconnected');
493-
localStorage.removeItem('walletData');
494489
setWalletData(null);
495490
};
496491

@@ -1395,7 +1390,10 @@ export const App = () => {
13951390
<Navbar>
13961391
<Navbar.Brand>
13971392
<Navbar.Item renderAs="div">
1398-
<Link to="/" style={{ lineHeight: 0 }}>
1393+
<Link
1394+
to={walletData ? "/profile" : "/"}
1395+
style={{ lineHeight: 0 }}
1396+
>
13991397
<img
14001398
src="/img/logo.svg"
14011399
alt="logo"
@@ -1409,8 +1407,6 @@ export const App = () => {
14091407
path="/"
14101408
element={<Home
14111409
onConnectWallet={onConnectWallet}
1412-
walletData={walletData}
1413-
location={location}
14141410
/>}
14151411
/>
14161412
<Route
@@ -1445,7 +1441,7 @@ export const App = () => {
14451441
alt="neo logo"
14461442
/>
14471443
</a>
1448-
<span class="social_pipe">
1444+
<span className="social_pipe">
14491445
<a className="neospcc" href="https://nspcc.io/" target="_blank" rel="noopener noreferrer">
14501446
<img
14511447
src="/img/socials/neo_spcc.svg"

src/Home.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react';
1+
import React from 'react';
22
import {
33
Container,
44
Section,
@@ -11,18 +11,8 @@ import {
1111

1212
const Home = ({
1313
onConnectWallet,
14-
walletData,
15-
location,
1614
}) => {
1715

18-
useEffect(() => {
19-
if (walletData && !walletData.balance && walletData.account) {
20-
if (location.pathname.indexOf('/profile') === -1 && process.env.REACT_APP_WC_PROJECT_ID && process.env.REACT_APP_WC_PROJECT_ID !== '') {
21-
document.location.href = "/profile";
22-
}
23-
}
24-
}, [walletData]); // eslint-disable-line react-hooks/exhaustive-deps
25-
2616
return (
2717
<Container
2818
id="login"

src/Profile.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ const Profile = ({
6666
}, [isLoadContainers]); // eslint-disable-line react-hooks/exhaustive-deps
6767

6868
useEffect(() => {
69-
if (!localStorage['wc@2:client:0.3//session'] || localStorage['wc@2:client:0.3//session'] === '[]' || !process.env.REACT_APP_WC_PROJECT_ID) {
70-
document.location.href = "/";
71-
}
7269
if (walletData && walletData.account && !isLoading) {
7370
onNeoBalance();
7471
onNeoFSBalance();

0 commit comments

Comments
 (0)