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

Fix reload when switching networks on the browser #3133

Merged
merged 4 commits into from
Sep 23, 2021
Merged
Changes from 2 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
19 changes: 13 additions & 6 deletions app/components/Views/BrowserTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export const BrowserTab = (props) => {
const [blockedUrl, setBlockedUrl] = useState(undefined);
const [watchAsset, setWatchAsset] = useState(false);
const [suggestedAssetMeta, setSuggestedAssetMeta] = useState(undefined);
const currentNetwork = useRef(props.network);

const [customNetworkToAdd, setCustomNetworkToAdd] = useState(null);
const [showAddCustomNetworkDialog, setShowAddCustomNetworkDialog] = useState(false);
Expand Down Expand Up @@ -1044,10 +1045,19 @@ export const BrowserTab = (props) => {
* Reload current page
*/
const reload = useCallback(() => {
toggleOptionsIfNeeded();
const { current } = webviewRef;
current && current.reload();
}, [toggleOptionsIfNeeded]);
}, []);

/**
* Reload page if network changes
*/
useEffect(() => {
if (props.network === 'loading') return;
if (currentNetwork.current === props.network) return;
currentNetwork.current = props.network;
reload();
}, [currentNetwork, props.network, reload]);

/**
* Handle when the drawer (app menu) is opened
Expand Down Expand Up @@ -1077,16 +1087,12 @@ export const BrowserTab = (props) => {
setWatchAsset(true);
});

// Listen to network changes
Engine.context.TransactionController.hub.on('networkChange', reload);

// Specify how to clean up after this effect:
return function cleanup() {
backgroundBridges.current.forEach((bridge) => bridge.onDisconnect());

// Remove all Engine listeners
Engine.context.TokensController.hub.removeAllListeners();
Engine.context.TransactionController.hub.removeListener('networkChange', reload);
};

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down Expand Up @@ -1601,6 +1607,7 @@ export const BrowserTab = (props) => {
* Handles reload button press
*/
const onReloadPress = () => {
toggleOptionsIfNeeded();
reload();
trackReloadEvent();
};
Expand Down