-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/components/Views/Settings/NetworksSettings/NetworkSettings/withIsOriginalNativeToken.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { selectChainId } from '../../../../../selectors/networkController'; | ||
import axios from 'axios'; | ||
|
||
const CHAIN_ID_NETWORK_URL = 'https://chainid.network/chains.json'; | ||
|
||
const withIsOriginalNativeToken = (WrappedComponent) => { | ||
// This is the functional component wrapper that can use hooks | ||
const WithIsOriginalNativeTokenWrapper = (props) => { | ||
// Use the useSelector hook to access Redux state | ||
const chainId = useSelector(selectChainId); | ||
|
||
const [matchedChainNetwork, setMatchedChainNetwork] = useState(null); | ||
|
||
useEffect(() => { | ||
axios.get(CHAIN_ID_NETWORK_URL).then(({ data: safeChainsList }) => { | ||
const matchedChainNetwork = safeChainsList.find( | ||
(network) => network.networkId === parseInt(chainId), | ||
); | ||
setMatchedChainNetwork({ | ||
matchedChainNetwork, | ||
}); | ||
}); | ||
}, [chainId]); | ||
|
||
// Pass the value from useSelector as a prop to the WrappedComponent | ||
return ( | ||
<WrappedComponent {...props} matchedChainNetwork={matchedChainNetwork} /> | ||
); | ||
}; | ||
|
||
return WithIsOriginalNativeTokenWrapper; | ||
}; | ||
|
||
export default withIsOriginalNativeToken; |