Skip to content

Commit a15aa23

Browse files
committed
refactor: add social icons component
2 parents e7a470f + fdc729c commit a15aa23

File tree

9 files changed

+203
-63
lines changed

9 files changed

+203
-63
lines changed

src/components/layout/app-bar.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Link } from 'react-router-dom'
55
import { Col, Row, Button, Badge, Switch } from 'antd'
66
import { WalletContext } from 'contexts/wallet-context'
77
import { TourContext } from 'contexts/tour-context'
8-
import { NETWORK_NAME, NETWORK_COLOR, NETWORK } from 'utils/network-utils'
8+
import { NETWORKS, NETWORKS_INFO } from '../../config/networks'
99
import Identicon from 'components/identicon'
1010
import Notifications from 'components/notifications'
1111
import { ReactComponent as Logo } from 'assets/images/logo.svg'
@@ -107,17 +107,17 @@ const AppBar = () => {
107107
const [requestedChain, setRequestedChain] = useState()
108108
const nextNetworkTCR = getNetworkEnv(
109109
'REACT_APP_DEFAULT_TCR_ADDRESSES',
110-
networkId === NETWORK.XDAI ? NETWORK.MAINNET : NETWORK.XDAI
110+
networkId === NETWORKS.xDai ? NETWORKS.ethereum : NETWORKS.xDai
111111
)
112112
const currentChainId = useMemo(() => requestedChain ?? networkId, [
113113
networkId,
114114
requestedChain
115115
])
116116

117117
const switchChain = useCallback(() => {
118-
let nextNetwork = NETWORK.XDAI
119-
if (networkId === NETWORK.XDAI) nextNetwork = NETWORK.MAINNET
120-
else nextNetwork = NETWORK.XDAI
118+
let nextNetwork = NETWORKS.xDai
119+
if (networkId === NETWORKS.xDai) nextNetwork = NETWORKS.ethereum
120+
else nextNetwork = NETWORKS.xDai
121121

122122
setRequestedChain(nextNetwork)
123123
localStorage.setItem(SAVED_NETWORK_KEY, nextNetwork)
@@ -143,14 +143,16 @@ const AppBar = () => {
143143
web3Context.networkId &&
144144
(account ? (
145145
<StyledNetworkStatus>
146-
<Badge color={NETWORK_COLOR[web3Context.networkId]} />
147-
{capitalizeFirstLetter(NETWORK_NAME[web3Context.networkId])}
146+
<Badge color={NETWORKS_INFO[web3Context.networkId].color} />
147+
{capitalizeFirstLetter(
148+
NETWORKS_INFO[web3Context.networkId].name
149+
)}
148150
</StyledNetworkStatus>
149151
) : (
150152
<Switch
151153
checkedChildren="xDai"
152154
unCheckedChildren="Mainnet"
153-
checked={currentChainId === NETWORK.XDAI}
155+
checked={currentChainId === NETWORKS.xDai}
154156
onClick={switchChain}
155157
/>
156158
))}

src/components/social-icons.js

Lines changed: 164 additions & 0 deletions
Large diffs are not rendered by default.

src/config/connectors.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Connectors } from 'web3-react'
22
import WalletConnectApi from '@walletconnect/web3-subprovider'
33
import FortmaticApi from 'fortmatic'
4-
import { NETWORK_NAME, NETWORK } from '../utils/network-utils'
4+
import { NETWORKS_INFO, NETWORKS } from 'config/networks'
55
import { SAVED_NETWORK_KEY } from '../utils/string'
66
import getNetworkEnv from '../utils/network-env'
77

@@ -26,7 +26,7 @@ if (process.env.REACT_APP_RPC_URLS) {
2626
providerURL: supportedNetworkURLs[defaultNetwork]
2727
})
2828
connectors.xDai = new NetworkOnlyConnector({
29-
providerURL: supportedNetworkURLs[NETWORK.XDAI]
29+
providerURL: supportedNetworkURLs[NETWORKS.xDai]
3030
})
3131

3232
connectors.Ledger = new LedgerConnector({
@@ -50,17 +50,19 @@ if (fortmaticApiKey)
5050
apiKey: fortmaticApiKey,
5151
logoutOnDeactivation: false,
5252
testNetwork:
53-
defaultNetwork === NETWORK.MAINNET ? null : NETWORK_NAME[defaultNetwork]
53+
defaultNetwork === NETWORKS.ethereum
54+
? null
55+
: NETWORKS_INFO[defaultNetwork].name
5456
})
5557

5658
if (window.ethereum)
5759
connectors.Injected = new InjectedConnector({
5860
supportedNetworks: [
59-
NETWORK.MAINNET,
60-
NETWORK.KOVAN,
61-
NETWORK.XDAI,
62-
NETWORK.GOERLI,
63-
NETWORK['ARBITRUM-RINKEBY']
61+
NETWORKS.ethereum,
62+
NETWORKS.kovan,
63+
NETWORKS.xDai,
64+
NETWORKS.goerli,
65+
NETWORKS['arbitrum-rinkeby']
6466
]
6567
})
6668

src/config/networks.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const NETWORKS_INFO = Object.freeze({
6969
chainId: 100,
7070
shortName: 'xdai',
7171
chain: 'XDAI',
72-
network: 'mainnet',
72+
network: 'xdai',
7373
networkId: 100,
7474
nativeCurrency: { name: 'xDAI', symbol: 'xDAI', decimals: 18 },
7575
rpc: [
@@ -105,7 +105,14 @@ export const NETWORKS_INFO = Object.freeze({
105105
// },
106106
[NETWORKS.kovan]: {
107107
name: 'Kovan',
108-
color: '#690496'
108+
color: '#690496',
109+
explorers: [
110+
{
111+
name: 'etherscan',
112+
url: 'https://kovan.etherscan.io',
113+
standard: 'EIP3091'
114+
}
115+
]
109116
},
110117
[NETWORKS['arbitrum-rinkeby']]: {
111118
name: 'Arbitrum Rinkeby',

src/hooks/native-currency.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useWeb3Context } from 'web3-react'
2-
import { NETWORK } from '../utils/network-utils'
2+
import { NETWORKS } from '../config/networks'
33

44
/**
55
* Get the ticker for the chain's native currency.
@@ -8,7 +8,7 @@ import { NETWORK } from '../utils/network-utils'
88
export default function useNativeCurrency() {
99
const { networkId } = useWeb3Context()
1010
if (!networkId) return 'ETH'
11-
if (networkId === NETWORK.XDAI) return 'DAI'
11+
if (networkId === NETWORKS.xDai) return 'DAI'
1212

1313
return 'ETH'
1414
}

src/hooks/tcr-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ const useTcrView = tcrAddress => {
274274
!library ||
275275
gtcr.address !== tcrAddress ||
276276
!metadataByTime ||
277-
metadataByTime.address !== tcrAddress ||
277+
metadataByTime.address.toLowerCase() !== tcrAddress.toLowerCase() ||
278278
!getLogs
279279
)
280280
return

src/hooks/tcr2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { useWeb3Context } from 'web3-react'
2-
import { NETWORK } from '../utils/network-utils'
2+
import { NETWORKS } from '../config/networks'
33

44
// TODO: Replace users with getNetworkEnv.
55
const useMainTCR2 = () => {
66
const DEFAULT_NETWORK =
7-
process.env.REACT_APP_DEFAULT_NETWORK || NETWORK.MAINNET
7+
process.env.REACT_APP_DEFAULT_NETWORK || NETWORKS.ethereum
88

99
const web3Context = useWeb3Context()
1010
let tcr2Data = ''

src/utils/network-env.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NETWORK } from './network-utils'
1+
import { NETWORKS } from '../config/networks'
22

33
/**
44
* Fetch an environment variable for a given networkId.
@@ -8,7 +8,7 @@ import { NETWORK } from './network-utils'
88
*/
99
function getNetworkEnv(envVariableKey, networkId) {
1010
const defaultNetwork =
11-
process.env.REACT_APP_DEFAULT_NETWORK || NETWORK.MAINNET
11+
process.env.REACT_APP_DEFAULT_NETWORK || NETWORKS.ethereum
1212
let data = ''
1313
try {
1414
data = process.env[envVariableKey]

src/utils/network-utils.js

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,13 @@
1-
export const NETWORK = {
2-
MAINNET: 1,
3-
ROPSTEN: 3,
4-
RINKEBY: 4,
5-
GOERLI: 5,
6-
KOVAN: 42,
7-
XDAI: 100,
8-
'ARBITRUM-RINKEBY': 421611
9-
}
10-
11-
export const NETWORK_NAME = {
12-
[NETWORK.MAINNET]: 'mainnet',
13-
[NETWORK.ROPSTEN]: 'ropsten',
14-
[NETWORK.RINKEBY]: 'rinkeby',
15-
[NETWORK.GOERLI]: 'goerli',
16-
[NETWORK.KOVAN]: 'kovan',
17-
[NETWORK.XDAI]: 'xDai'
18-
}
19-
20-
export const NETWORK_COLOR = {
21-
[NETWORK.MAINNET]: '#29b6af',
22-
[NETWORK.ROPSTEN]: '#ff4a8d',
23-
[NETWORK.RINKEBY]: '#f6c343',
24-
[NETWORK.GOERLI]: '#3099f2',
25-
[NETWORK.KOVAN]: '#690496',
26-
[NETWORK.XDAI]: '#48A9A6'
27-
}
28-
29-
const getFreePage = ({ networkId }) => {
30-
const corePage =
31-
networkId === 100 ? 'blockscout.com/xdai/mainnet' : 'etherscan.io'
32-
const hasSubdomain = ![1, 100].includes(networkId)
33-
const uri = `${hasSubdomain ? `${NETWORK_NAME[networkId]}.` : ''}${corePage}`
34-
const fullPage = `https://${uri}`
35-
return fullPage
36-
}
1+
import { NETWORKS_INFO } from 'config/networks'
372

383
export const getAddressPage = ({ networkId, address }) => {
39-
const page = getFreePage({ networkId })
4+
const page = NETWORKS_INFO[networkId].explorers[0].url
405
const pageWithAddress = `${page}/address/${address}`
416
return pageWithAddress
427
}
438

449
export const getTxPage = ({ networkId, txHash }) => {
45-
const page = getFreePage({ networkId })
10+
const page = NETWORKS_INFO[networkId].explorers[0].url
4611
const pageWithTx = `${page}/tx/${txHash}`
4712
return pageWithTx
4813
}

0 commit comments

Comments
 (0)