Skip to content

Commit

Permalink
Merge pull request #654 from CityOfZion/backend-v2
Browse files Browse the repository at this point in the history
Backend v2
  • Loading branch information
lllwvlvwlll authored Oct 11, 2023
2 parents 66e2cdb + 345d05c commit b8493f2
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 103 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/actions/addressActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { ThunkDispatch } from 'redux-thunk'

import { State } from '../reducers/addressReducer'
import { State as NetworkState } from '../reducers/networkReducer'
import { NeoRest } from '@cityofzion/dora-ts/dist/api'
import { NeoRESTApi } from '@cityofzion/dora-ts/dist/api'

const NeoRest = new NeoRESTApi({
doraUrl: 'https://dora.coz.io',
endpoint: '/api/v2/neo3',
})

export const REQUEST_ADDRESS = 'REQUEST_ADDRESS'
export const requestAddress =
Expand Down
7 changes: 6 additions & 1 deletion src/actions/blockActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import { ThunkDispatch } from 'redux-thunk'
import { SUPPORTED_PLATFORMS } from '../constants'
import { Block, DetailedBlock, State } from '../reducers/blockReducer'
import { sortSingleListByDate } from '../utils/time'
import { NeoRest } from '@cityofzion/dora-ts/dist/api'
import { NeoRESTApi } from '@cityofzion/dora-ts/dist/api'
import { BlockTransaction } from '../reducers/transactionReducer'
import { State as NetworkState } from '../reducers/networkReducer'

const NeoRest = new NeoRESTApi({
doraUrl: 'https://dora.coz.io',
endpoint: '/api/v2/neo3',
})

export const REQUEST_BLOCK = 'REQUEST_BLOCK'
// We can dispatch this action if requesting
// block by height (index)
Expand Down
7 changes: 6 additions & 1 deletion src/actions/contractActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import { ThunkDispatch } from 'redux-thunk'
import { SUPPORTED_PLATFORMS } from '../constants'
import { Contract, InvocationStat, State } from '../reducers/contractReducer'
import { sortSingleListByDate } from '../utils/time'
import { NeoRest } from '@cityofzion/dora-ts/dist/api'
import { NeoRESTApi } from '@cityofzion/dora-ts/dist/api'
import { ContractResponse } from '@cityofzion/dora-ts/dist/interfaces/api/neo'
import { State as NetworkState } from '../reducers/networkReducer'

const NeoRest = new NeoRESTApi({
doraUrl: 'https://dora.coz.io',
endpoint: '/api/v2/neo3',
})

export const REQUEST_CONTRACT = 'REQUEST_CONTRACT'
export const requestContract =
(hash: string) =>
Expand Down
7 changes: 6 additions & 1 deletion src/actions/searchActions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ThunkDispatch } from 'redux-thunk'
import { Dispatch, Action } from 'redux'
import { State } from '../reducers/searchReducer'
import { NeoRest } from '@cityofzion/dora-ts/dist/api'
import { NeoRESTApi } from '@cityofzion/dora-ts/dist/api'

const NeoRest = new NeoRESTApi({
doraUrl: 'https://dora.coz.io',
endpoint: '/api/v2/neo3',
})

export const SEARCH_INPUT_ENTERED = 'SEARCH_INPUT_ENTERED'
export const searchInputEntered =
Expand Down
7 changes: 6 additions & 1 deletion src/actions/transactionActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { SUPPORTED_PLATFORMS } from '../constants'
import { State as NetworkState } from '../reducers/networkReducer'
import { State, Transaction } from '../reducers/transactionReducer'
import { sortSingleListByDate } from '../utils/time'
import { NeoRest } from '@cityofzion/dora-ts/dist/api'
import { NeoRESTApi } from '@cityofzion/dora-ts/dist/api'

const NeoRest = new NeoRESTApi({
doraUrl: 'https://dora.coz.io',
endpoint: '/api/v2/neo3',
})

export const REQUEST_TRANSACTION = 'REQUEST_TRANSACTION'
export const requestTransaction =
Expand Down
7 changes: 6 additions & 1 deletion src/components/transaction/notification/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
import { uuid } from '../../../utils/formatter'
import { u } from '@cityofzion/neon-js'
import { StackPanel } from '../StackPanel'
import { NeoRest } from '@cityofzion/dora-ts/dist/api'
import { NeoRESTApi } from '@cityofzion/dora-ts/dist/api'
import { ContractResponse } from '@cityofzion/dora-ts/dist/interfaces/api/neo'

const NeoRest = new NeoRESTApi({
doraUrl: 'https://dora.coz.io',
endpoint: '/api/v2/neo3',
})

export const Notification: React.FC<{
notifications: TransactionNotification[]
chain: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { NeoRest } from '@cityofzion/dora-ts/dist/api'
import { NeoRESTApi } from '@cityofzion/dora-ts/dist/api'
import { store } from '../../../../store'
import { AddressTransactionsResponse } from '@cityofzion/dora-ts/dist/interfaces/api/neo'

const NeoRest = new NeoRESTApi({
doraUrl: 'https://dora.coz.io',
endpoint: '/api/v2/neo3',
})

export const fetchTransaction = async (hash: string, page = 1) => {
try {
const network = store.getState().network.network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
import { convertToArbitraryDecimals } from '../../../../utils/formatter'
import AddressTransactionsCard from './fragments/AddressTransactionCard'
import useUpdateNetworkState from '../../../../hooks/useUpdateNetworkState'
import { NeoRest } from '@cityofzion/dora-ts/dist/api'
import { NeoRESTApi } from '@cityofzion/dora-ts/dist/api'
import {
Notification,
TransactionEnhanced,
Transfer as TransferDoraTS,
} from '@cityofzion/dora-ts/dist/interfaces/api/neo/interface'

const NeoRest = new NeoRESTApi({
doraUrl: 'https://dora.coz.io',
endpoint: '/api/v2/neo3',
})

interface MatchParams {
hash: string
chain: string
Expand Down
16 changes: 1 addition & 15 deletions src/pages/endpoint/Endpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ const Endpoint: React.FC<Props> = (props: Props) => {
<Copy text={endpointSelected ? endpointSelected.url : ''} />
</span>
</div>
<div className="detail-tile endpoint-detail-tile">
<label className="title-tile endpoint-title-tile">TYPE</label>
<span className="content-tile endpoint-content-tile">
{endpointSelected && endpointSelected.type}
</span>
</div>
<div className="detail-tile endpoint-detail-tile">
<label className="title-tile endpoint-title-tile">
IS IT UP?
Expand All @@ -105,14 +99,6 @@ const Endpoint: React.FC<Props> = (props: Props) => {
{endpointSelected && endpointSelected.availability} %
</span>
</div>
<div className="detail-tile endpoint-detail-tile">
<label className="title-tile endpoint-title-tile">
STATE HEIGHT
</label>
<span className="content-tile endpoint-content-tile">
#{endpointSelected && endpointSelected.stateheight}
</span>
</div>
<div className="detail-tile endpoint-detail-tile">
<label className="title-tile endpoint-title-tile">
BLOCK HEIGHT
Expand All @@ -126,7 +112,7 @@ const Endpoint: React.FC<Props> = (props: Props) => {
VERSION
</label>
<span className="content-tile endpoint-content-tile">
{endpointSelected && endpointSelected.version}
{endpointSelected && endpointSelected.user_agent}
</span>
</div>
<div className="detail-tile endpoint-detail-tile">
Expand Down
64 changes: 26 additions & 38 deletions src/pages/monitor/Monitor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ import { uniqueId } from 'lodash'

type ParsedNodes = {
endpoint: React.FC<{}>
type: React.FC<{}>
isItUp: React.FC<{}>
availability: string | React.FC<{}>
stateHeight: string | React.FC<{}>
blockHeight: string | React.FC<{}>
version: string | React.FC<{}>
peers: number | React.FC<{}>
Expand All @@ -59,7 +57,7 @@ interface AllNodes {

interface Endpoint extends AllNodes {
url: string
locale: string
endpointLocation: string
}

const STATUS_ICONS = [
Expand All @@ -69,7 +67,7 @@ const STATUS_ICONS = [
{ status: 'stalled', Icon: DisapprovedSVG, color: '#de4c85' },
]

const Endpoint: React.FC<Endpoint> = ({ url, locale, disable }) => {
const Endpoint: React.FC<Endpoint> = ({ url, endpointLocation, disable }) => {
const { setMessage, setShowMessage } = useContext(MonitorContext)
const handleClickEndpoint = (
e: React.MouseEvent<HTMLDivElement, MouseEvent>,
Expand All @@ -80,6 +78,18 @@ const Endpoint: React.FC<Endpoint> = ({ url, locale, disable }) => {
setShowMessage(true)
}

const LOCATIONS_FLAGS = [
{ location: 'United States', countryCode: 'US' },
{ location: 'USA', countryCode: 'US' },
{ location: 'Hong Kong', countryCode: 'HK' },
{ location: 'Canada', countryCode: 'CA' },
{ location: 'China', countryCode: 'CN' },
{ location: 'US', countryCode: 'US' },
{ location: 'Singapore', countryCode: 'SG' },
{ location: 'France', countryCode: 'FR' },
{ location: 'Russia', countryCode: 'RU' },
]

return (
<div className={disable ? 'endpoint disable' : 'endpoint'}>
<div className="endpoint-flag-container">
Expand All @@ -89,7 +99,11 @@ const Endpoint: React.FC<Endpoint> = ({ url, locale, disable }) => {
fontSize: '1.5em',
lineHeight: '1.5em',
}}
countryCode={locale}
countryCode={
LOCATIONS_FLAGS.find(
({ location }) => location === endpointLocation,
)?.countryCode
}
/>
</div>
<div className="endpoint-url">{url}</div>
Expand Down Expand Up @@ -346,14 +360,11 @@ const mapNodesData = (data: WSDoraData): ParsedNodes => {
endpoint: (): ReactElement => (
<Endpoint
url={data.url}
locale={data.locale}
endpointLocation={data.location}
disable={!isPositive()}
key={data.url}
/>
),
type: (): ReactElement => (
<TypeNode textType={data.type} disable={!isPositive()} />
),
blockHeight: isPositive()
? (): ReactElement => (
<NavigateColumn text={`#${data.height}`} url={url} />
Expand All @@ -366,7 +377,7 @@ const mapNodesData = (data: WSDoraData): ParsedNodes => {
/>
),
version: isPositive()
? (): ReactElement => <NavigateColumn text={data.version} url={url} />
? (): ReactElement => <NavigateColumn text={data.user_agent} url={url} />
: (): ReactElement => (
<NegativeComponent disable={!isPositive()} url={url} />
),
Expand All @@ -381,7 +392,7 @@ const mapNodesData = (data: WSDoraData): ParsedNodes => {
),
availability: isPositive()
? (): ReactElement => (
<Availability text={`${data.reliability}%`} url={url} />
<Availability text={`${data.availability.toFixed(2)}%`} url={url} />
)
: (): ReactElement => (
<NegativeComponent
Expand All @@ -390,17 +401,6 @@ const mapNodesData = (data: WSDoraData): ParsedNodes => {
url={url}
/>
),
stateHeight: isPositive()
? (): ReactElement => (
<NavigateColumn text={`#${data.stateheight}`} url={url} />
)
: (): ReactElement => (
<NegativeComponent
useHashTag={true}
disable={!isPositive()}
url={url}
/>
),
isItUp: (): ReactElement => (
<IsItUp
statusIsItUp={data.status}
Expand Down Expand Up @@ -431,10 +431,8 @@ const columns: ColumnType[] = [
sortOpt: 'endpoint',
style: { minWidth: '250px' },
},
{ name: 'Type', accessor: 'type', sortOpt: 'type' },
{ name: 'Is it up?', accessor: 'isItUp', sortOpt: 'isItUp' },
{ name: 'Availability', accessor: 'availability', sortOpt: 'availability' },
{ name: 'State Height', accessor: 'stateHeight', sortOpt: 'stateHeight' },
{ name: 'Block Height', accessor: 'blockHeight', sortOpt: 'blockHeight' },
{ name: 'Version', accessor: 'version', sortOpt: 'version' },
{ name: 'Peers', accessor: 'peers', sortOpt: 'peers' },
Expand Down Expand Up @@ -573,30 +571,24 @@ const ListMonitor: React.FC<ListMonitor> = ({ network, protocol }) => {
}>({ desc: false, sort: 'isItUp' })

const selectedData = (): WSDoraData[] => {
let sortedNodes = OrderNodes(
const sortedNodes = OrderNodes(
sortDataList.sort,
nodes.nodesArray,
sortDataList.desc,
)

sortedNodes = sortedNodes.filter(node => node.protocol !== 'neo2')

if (protocol === 'all' && network === 'all') {
return sortedNodes
} else if (protocol === 'all' && network !== 'all') {
} else if (network !== 'all') {
return sortedNodes.filter(node => node.network === network)
} else if (protocol !== 'all' && network === 'all') {
return sortedNodes.filter(node => node.protocol === protocol)
} else {
//temporary state, remove when api cuts over
let mutableNetwork = network
if (mutableNetwork === 'testnet_rc4') {
mutableNetwork = 'testnet'
}

return sortedNodes.filter(
node => node.protocol === protocol && node.network === mutableNetwork,
)
return sortedNodes.filter(node => node.network === mutableNetwork)
}
}

Expand All @@ -620,7 +612,7 @@ const ListMonitor: React.FC<ListMonitor> = ({ network, protocol }) => {
useEffect(() => {
let socket: Socket
if (window.location.pathname.includes(ROUTES.MONITOR.url)) {
socket = new Socket('wss://dora.coz.io/ws/v1/unified/network_status')
socket = new Socket('wss://dora.coz.io/ws/v2/unified/network_status')
socket.listening<WSDoraData>(data => {
dispatch(setNode(data))
})
Expand Down Expand Up @@ -835,10 +827,6 @@ const Monitor: React.FC<{}> = () => {
sortDataList.desc,
)

if (protocol !== 'all') {
sortedNodes = sortedNodes.filter(node => node.protocol === protocol)
}

if (network !== 'all') {
sortedNodes = sortedNodes.filter(node => node.network === network)
}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/transaction/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ import BackButton from '../../components/navigation/BackButton'
import { ReactComponent as TransactionIcon } from '../../assets/icons/invocation.svg'
import { Box, Flex, Text } from '@chakra-ui/react'
import { u } from '@cityofzion/neon-js'
import { NeoRest } from '@cityofzion/dora-ts/dist/api'
import { NeoRESTApi } from '@cityofzion/dora-ts/dist/api'
import { store } from '../../store'

const NeoRest = new NeoRESTApi({
doraUrl: 'https://dora.coz.io',
endpoint: '/api/v2/neo3',
})

export type ParsedTransfer = {
name: string
amount: string | number
Expand Down
Loading

0 comments on commit b8493f2

Please sign in to comment.