Skip to content

Commit

Permalink
Remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
thesan committed Jun 24, 2024
1 parent 1aa49cb commit 3f3ed8d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/ui/src/app/config/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ const NODE_RPC_ENDPOINT: PredefinedEndpoint = {

const NODE_HTTP_RPC_ENDPOINT: PredefinedEndpoint = {
mainnet: MAINNET_NODE_HTTP_RPC,
local: 'http://127.0.0.1:9933', // TODO: check
local: 'http://127.0.0.1:9933',
testnet: TESTNET_NODE_HTTP_RPC,
'local-mocks': 'http://127.0.0.1:9933', // TODO: check
'local-mocks': 'http://127.0.0.1:9933',
}

const BACKEND_ENDPOINT: PredefinedEndpoint = {
Expand Down
20 changes: 2 additions & 18 deletions packages/ui/src/common/providers/network-endpoints/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { ReactNode, Reducer, useCallback, useEffect, useReducer, useState } from 'react'
import React, { ReactNode, useCallback, useEffect, useState } from 'react'
import * as Yup from 'yup'

import { DEFAULT_NETWORK, NetworkEndpoints, pickEndpoints } from '@/app/config'
import { Loading } from '@/common/components/Loading'
import { useLocalStorage } from '@/common/hooks/useLocalStorage'
import { useNetwork } from '@/common/hooks/useNetwork'
import { Optional } from '@/common/types'
import { objectEquals } from '@/common/utils'

import { NetworkEndpointsContext } from './context'
Expand All @@ -22,24 +21,9 @@ const EndpointsSchema = Yup.object().shape({
backendEndpoint: Yup.string(),
})

// HACK will approximately guess the http endpoint
const endpointReducer: Reducer<NetworkEndpoints | undefined, Optional<NetworkEndpoints, 'nodeHttpRpcEndpoint'>> = (
_,
newEndpoints
): NetworkEndpoints => ({
...newEndpoints,
nodeHttpRpcEndpoint:
newEndpoints.nodeHttpRpcEndpoint ??
newEndpoints.nodeRpcEndpoint
.replace('ws:', 'http:')
.replace('wss:', 'https:')
.replace('ws-rpc', 'http-rpc')
.replace(':9944', ''),
})

export const NetworkEndpointsProvider = ({ children }: Props) => {
const { network, setNetwork } = useNetwork()
const [endpoints, setEndpoints] = useReducer(endpointReducer, undefined)
const [endpoints, setEndpoints] = useState<NetworkEndpoints>()
const [autoConfEndpoints, storeAutoConfEndpoints] = useLocalStorage<NetworkEndpoints>('auto_network_config')
const [isLoading, setIsLoading] = useState(false)
const [customEndpoints] = useLocalStorage<NetworkEndpoints>('custom_endpoint')
Expand Down

0 comments on commit 3f3ed8d

Please sign in to comment.