Skip to content

Commit a05ed0b

Browse files
prepares base network and remove trm types
1 parent 41d65da commit a05ed0b

File tree

15 files changed

+131
-138
lines changed

15 files changed

+131
-138
lines changed

src/components/Navbar/NetworkButton.tsx

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { Arbitrum } from "../../static/icons/Arbitrum"
1818
import { Base } from "../../static/icons/Base"
1919
import { chainIdToChainParameterName, networks } from "../../networks/utils"
2020
import { useIsActive } from "../../hooks/useIsActive"
21-
import { SupportedChainIds } from "../../networks/enums/networks"
21+
import { NetworkType, SupportedChainIds } from "../../networks/enums/networks"
22+
import { getDefaultProviderChainId } from "../../utils/getEnvVariable"
2223

2324
interface NetworkIconMap {
2425
icon: ReactElement
@@ -70,30 +71,44 @@ const getNetworkIcon = (chainId: number, colorMode: string): NetworkIconMap => {
7071
const NetworkButton: FC = () => {
7172
const { colorMode } = useColorMode()
7273
const { chainId, switchNetwork } = useIsActive()
74+
const defaultChainId = getDefaultProviderChainId()
7375

7476
const networkIcon = useMemo(
7577
() => getNetworkIcon(chainId || 0, colorMode),
7678
[chainId, colorMode]
7779
)
7880

7981
const renderMenuItems = () =>
80-
networks
81-
.filter((network) => network.chainParameters.chainName !== "Localhost")
82-
.map((network) => {
83-
const { icon } = getNetworkIcon(network.chainId, colorMode)
84-
return (
85-
<MenuItem
86-
key={network.chainId}
87-
onClick={() => switchNetwork(network.chainId)}
88-
iconSpacing="4"
89-
display="flex"
90-
gap="3"
91-
>
92-
{icon}
93-
{network.chainParameters?.chainName}
94-
</MenuItem>
95-
)
96-
})
82+
defaultChainId === SupportedChainIds.Ethereum ? (
83+
networks
84+
.filter((network) => network.networkType === NetworkType.Mainnet)
85+
.map((network) => {
86+
const { icon } = getNetworkIcon(network.chainId, colorMode)
87+
return (
88+
<MenuItem
89+
key={network.chainId}
90+
onClick={() => switchNetwork(network.chainId)}
91+
iconSpacing="4"
92+
display="flex"
93+
gap="3"
94+
>
95+
{icon}
96+
{network.chainParameters?.chainName}
97+
</MenuItem>
98+
)
99+
})
100+
) : (
101+
<MenuItem
102+
key={SupportedChainIds.Sepolia}
103+
onClick={() => switchNetwork(SupportedChainIds.Sepolia)}
104+
iconSpacing="4"
105+
display="flex"
106+
gap="3"
107+
>
108+
{getNetworkIcon(SupportedChainIds.Sepolia, colorMode)}
109+
Sepolia Testnet
110+
</MenuItem>
111+
)
97112

98113
return (
99114
<>

src/hooks/useIsActive.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export const useIsActive = (): UseIsActiveResult => {
5353
if (errorCode === 4902 || errorCode === 4901) {
5454
if (!provider) throw new Error("No provider available")
5555

56-
const network = networks.find((net) => net.chainId === chainId)
56+
const network = networks.find(
57+
(network) => network.chainId === chainId
58+
)
5759
if (!network || !network.chainParameters) {
5860
throw new Error("Network parameters not found")
5961
}

src/networks/types/networks.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,4 @@ export interface Network {
3737
alchemyName?: AlchemyName
3838
}
3939

40-
export type TrmNetworksMap = {
41-
[chainId: number]: string
42-
}
43-
4440
export type NetworkMapping = Record<number, NetworkName>

src/networks/utils/chainIdToTrmNetworkName.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
import { getChainIdToNetworkName } from "./getChainIdToNetworkName"
22
import {
3-
l1MainnetNetworksMap,
4-
l1TestNetworksMap,
5-
l2MainnetNetworksMap,
6-
l2TestNetworksMap,
7-
testNetworksMap,
3+
l1MainnetNetworks,
4+
l1TestNetworks,
5+
l2MainnetNetworks,
6+
l2TestNetworks,
7+
testNetworks,
88
} from "./mappings"
99

1010
export const isSupportedNetwork = (chainId?: string | number): boolean => {
1111
return getChainIdToNetworkName(chainId) !== "Unsupported"
1212
}
1313

1414
export const isTestnetNetwork = (networkChainId: string | number): boolean => {
15-
return !!testNetworksMap[Number(networkChainId)]
15+
return !!testNetworks[Number(networkChainId)]
1616
}
1717

1818
export const isL2Network = (networkChainId?: string | number): boolean => {
1919
const chainId = Number(networkChainId)
20-
return !!l2MainnetNetworksMap[chainId] || !!l2TestNetworksMap[chainId]
20+
return !!l2MainnetNetworks[chainId] || !!l2TestNetworks[chainId]
2121
}
2222

2323
export const isL1Network = (networkChainId?: string | number): boolean => {
2424
const chainId = Number(networkChainId)
25-
return !!l1MainnetNetworksMap[chainId] || !!l1TestNetworksMap[chainId]
25+
return !!l1MainnetNetworks[chainId] || !!l1TestNetworks[chainId]
2626
}
2727

2828
export const isL1Mainnet = (networkChainId?: string | number): boolean => {
2929
const chainId = Number(networkChainId)
30-
return !!l1MainnetNetworksMap[chainId]
30+
return !!l1MainnetNetworks[chainId]
3131
}

src/networks/utils/getRpcUrl.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { EnvVariable } from "../../enums"
2-
import { getEnvVariable } from "../../utils/getEnvVariable"
3-
import { SupportedChainIds } from "../enums/networks"
2+
import {
3+
getDefaultProviderChainId,
4+
getEnvVariable,
5+
} from "../../utils/getEnvVariable"
46
import { networksAlchemyConfig } from "./networksAlchemyConfig"
57

68
const MAIN_ALCHEMY_URL = "g.alchemy.com/v2/"
79

810
export const getRpcUrl = (chainId?: number | string) => {
911
const alchemyApi = getEnvVariable(EnvVariable.ALCHEMY_API)
10-
const defaultChainId = SupportedChainIds.Ethereum
12+
const defaultChainId = getDefaultProviderChainId()
1113
const chainIdNum = Number(chainId) || defaultChainId
1214
const alchemyConfig = networksAlchemyConfig[chainIdNum]
1315

src/networks/utils/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from "./chainId"
22
export * from "./getChainIdToNetworkName"
3-
export * from "./chainIdToTrmNetworkName"
43
export * from "./connectedNetwork"
54
export * from "./createExplorerLink"
65
export * from "./getRpcUrl"

src/networks/utils/mappings.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@ import { Layer, NetworkType } from "../enums/networks"
22
import { NetworkMapping } from "../types/networks"
33
import { networks } from "./networks"
44

5-
export const supportedNetworksMap: NetworkMapping = {}
6-
export const l1TestNetworksMap: NetworkMapping = {}
7-
export const l1MainnetNetworksMap: NetworkMapping = {}
8-
export const l2TestNetworksMap: NetworkMapping = {}
9-
export const l2MainnetNetworksMap: NetworkMapping = {}
10-
export const testNetworksMap: NetworkMapping = {}
5+
export const supportedNetworks: NetworkMapping = {}
6+
export const l1TestNetworks: NetworkMapping = {}
7+
export const l1MainnetNetworks: NetworkMapping = {}
8+
export const l2TestNetworks: NetworkMapping = {}
9+
export const l2MainnetNetworks: NetworkMapping = {}
10+
export const testNetworks: NetworkMapping = {}
1111

1212
networks.forEach((network) => {
1313
const { chainId, name, layer, networkType } = network
14-
supportedNetworksMap[chainId] = name
14+
supportedNetworks[chainId] = name
1515

1616
if (layer === Layer.L1 && networkType === NetworkType.Testnet) {
17-
l1TestNetworksMap[chainId] = name
17+
l1TestNetworks[chainId] = name
1818
}
1919

2020
if (layer === Layer.L1 && networkType === NetworkType.Mainnet) {
21-
l1MainnetNetworksMap[chainId] = name
21+
l1MainnetNetworks[chainId] = name
2222
}
2323

2424
if (layer === Layer.L2 && networkType === NetworkType.Testnet) {
25-
l2TestNetworksMap[chainId] = name
25+
l2TestNetworks[chainId] = name
2626
}
2727

2828
if (layer === Layer.L2 && networkType === NetworkType.Mainnet) {
29-
l2MainnetNetworksMap[chainId] = name
29+
l2MainnetNetworks[chainId] = name
3030
}
3131

3232
if (networkType === NetworkType.Testnet) {
33-
testNetworksMap[chainId] = name
33+
testNetworks[chainId] = name
3434
}
3535
})

src/networks/utils/networks.ts

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -65,78 +65,78 @@ export const networks: Network[] = [
6565
blockExplorerUrls: ["http://localhost:8545"],
6666
},
6767
},
68-
// {
69-
// chainId: SupportedChainIds.Base,
70-
// name: "Base",
71-
// layer: Layer.L2,
72-
// networkType: NetworkType.Mainnet,
73-
// alchemyName: AlchemyName.Base,
74-
// chainParameters: {
75-
// chainId: toHex(SupportedChainIds.Base),
76-
// chainName: "Base Mainnet",
77-
// nativeCurrency: {
78-
// name: NativeCurrency.Ether,
79-
// symbol: ETH_SYMBOL,
80-
// decimals: DECIMALS,
81-
// },
82-
// rpcUrls: [PublicRpcUrls.Base],
83-
// blockExplorerUrls: [createExplorerPrefix(SupportedChainIds.Base)],
84-
// },
85-
// },
86-
{
87-
chainId: SupportedChainIds.Sepolia,
88-
name: "Ethereum",
89-
layer: Layer.L1,
90-
networkType: NetworkType.Testnet,
91-
alchemyName: AlchemyName.Ethereum,
92-
chainParameters: {
93-
chainId: toHex(SupportedChainIds.Sepolia),
94-
chainName: "Sepolia Testnet",
95-
nativeCurrency: {
96-
name: NativeCurrency.SepoliaEther,
97-
symbol: ETH_SYMBOL,
98-
decimals: DECIMALS,
99-
},
100-
rpcUrls: [PublicRpcUrls.Sepolia],
101-
blockExplorerUrls: [createExplorerPrefix(SupportedChainIds.Sepolia)],
102-
},
103-
},
10468
{
105-
chainId: SupportedChainIds.ArbitrumSepolia,
106-
name: "Arbitrum",
69+
chainId: SupportedChainIds.Base,
70+
name: "Base",
10771
layer: Layer.L2,
108-
networkType: NetworkType.Testnet,
109-
alchemyName: AlchemyName.Arbitrum,
72+
networkType: NetworkType.Mainnet,
73+
alchemyName: AlchemyName.Base,
11074
chainParameters: {
111-
chainId: toHex(SupportedChainIds.ArbitrumSepolia),
112-
chainName: "Arbitrum Sepolia",
75+
chainId: toHex(SupportedChainIds.Base),
76+
chainName: "Base Mainnet",
11377
nativeCurrency: {
114-
name: NativeCurrency.SepoliaEther,
78+
name: NativeCurrency.Ether,
11579
symbol: ETH_SYMBOL,
11680
decimals: DECIMALS,
11781
},
118-
rpcUrls: [PublicRpcUrls.ArbitrumSepolia],
119-
blockExplorerUrls: [
120-
createExplorerPrefix(SupportedChainIds.ArbitrumSepolia),
121-
],
82+
rpcUrls: [PublicRpcUrls.Base],
83+
blockExplorerUrls: [createExplorerPrefix(SupportedChainIds.Base)],
12284
},
12385
},
12486
{
125-
chainId: SupportedChainIds.BaseSepolia,
126-
name: "Base",
127-
layer: Layer.L2,
87+
chainId: SupportedChainIds.Sepolia,
88+
name: "Ethereum",
89+
layer: Layer.L1,
12890
networkType: NetworkType.Testnet,
129-
alchemyName: AlchemyName.Base,
91+
alchemyName: AlchemyName.Ethereum,
13092
chainParameters: {
131-
chainId: toHex(SupportedChainIds.BaseSepolia),
132-
chainName: "Base Sepolia",
93+
chainId: toHex(SupportedChainIds.Sepolia),
94+
chainName: "Sepolia Testnet",
13395
nativeCurrency: {
13496
name: NativeCurrency.SepoliaEther,
13597
symbol: ETH_SYMBOL,
13698
decimals: DECIMALS,
13799
},
138-
rpcUrls: [PublicRpcUrls.BaseSepolia],
139-
blockExplorerUrls: [createExplorerPrefix(SupportedChainIds.BaseSepolia)],
100+
rpcUrls: [PublicRpcUrls.Sepolia],
101+
blockExplorerUrls: [createExplorerPrefix(SupportedChainIds.Sepolia)],
140102
},
141103
},
104+
// {
105+
// chainId: SupportedChainIds.ArbitrumSepolia,
106+
// name: "Arbitrum",
107+
// layer: Layer.L2,
108+
// networkType: NetworkType.Testnet,
109+
// alchemyName: AlchemyName.Arbitrum,
110+
// chainParameters: {
111+
// chainId: toHex(SupportedChainIds.ArbitrumSepolia),
112+
// chainName: "Arbitrum Sepolia",
113+
// nativeCurrency: {
114+
// name: NativeCurrency.SepoliaEther,
115+
// symbol: ETH_SYMBOL,
116+
// decimals: DECIMALS,
117+
// },
118+
// rpcUrls: [PublicRpcUrls.ArbitrumSepolia],
119+
// blockExplorerUrls: [
120+
// createExplorerPrefix(SupportedChainIds.ArbitrumSepolia),
121+
// ],
122+
// },
123+
// },
124+
// {
125+
// chainId: SupportedChainIds.BaseSepolia,
126+
// name: "Base",
127+
// layer: Layer.L2,
128+
// networkType: NetworkType.Testnet,
129+
// alchemyName: AlchemyName.Base,
130+
// chainParameters: {
131+
// chainId: toHex(SupportedChainIds.BaseSepolia),
132+
// chainName: "Base Sepolia",
133+
// nativeCurrency: {
134+
// name: NativeCurrency.SepoliaEther,
135+
// symbol: ETH_SYMBOL,
136+
// decimals: DECIMALS,
137+
// },
138+
// rpcUrls: [PublicRpcUrls.BaseSepolia],
139+
// blockExplorerUrls: [createExplorerPrefix(SupportedChainIds.BaseSepolia)],
140+
// },
141+
// },
142142
]

src/store/account/effects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StakeData, TrmEntity, TrmRiskIndicator } from "../../types"
1+
import { StakeData } from "../../types"
22
import { isAddressZero, isSameETHAddress } from "../../web3/utils"
33
import { AppListenerEffectAPI } from "../listener"
44
import { setStakes } from "../staking"

src/store/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ const store = configureStore({
7878
ignoredActions: [
7979
"modal/openModal",
8080
"staking/unstaked",
81-
"staking/toppepUp",
81+
"staking/toppedUp",
82+
"account/setOperatorMappingError",
83+
"account/setTrmError",
8284
],
8385
// Ignore these field paths in all actions
8486
ignoredPaths: [
@@ -89,6 +91,8 @@ const store = configureStore({
8991
"modal.props.onSubmit",
9092
"modal.props.setAmountToStake",
9193
"payload.props.setAmountToStake",
94+
"account.trm",
95+
"account.operatorMapping",
9296
],
9397
},
9498
}).prepend(listenerMiddleware.middleware),

0 commit comments

Comments
 (0)