Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
[AUD-73] Add flags for node operators (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Jan 21, 2022
1 parent 9c96752 commit 01b648e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 10 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"numeral": "2.0.6",
"react": "16.13.1",
"react-chartjs-2": "2.10.0",
"react-country-flag": "3.0.2",
"react-custom-scrollbars": "4.2.1",
"react-dom": "16.13.1",
"react-helmet": "6.1.0",
Expand Down
6 changes: 5 additions & 1 deletion src/components/ServiceTable/ServiceTable.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@

.error > * {
padding: 0;
}
}

.countryFlag {
margin: var(--unit-2);
}
5 changes: 5 additions & 0 deletions src/components/ServiceTable/ServiceTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import clsx from 'clsx'
import ReactCountryFlag from 'react-country-flag'
import { NodeService, ContentNode, DiscoveryProvider } from 'types'
import styles from './ServiceTable.module.css'
import Table from 'components/Table'
Expand Down Expand Up @@ -46,6 +47,10 @@ const ServiceTable: React.FC<ServiceTableProps> = ({
return (
<div className={styles.rowContainer}>
<div className={clsx(styles.rowCol, styles.colEndpoint)}>
<ReactCountryFlag
className={styles.countryFlag}
countryCode={data.country}
/>
{data.endpoint}
</div>
<div className={clsx(styles.rowCol, styles.colVersion)}>
Expand Down
4 changes: 2 additions & 2 deletions src/services/Audius/AudiusClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
displayShortAud,
getAud,
getWei,
getNodeVersion,
getNodeMetadata,
getEthWallet,
getBlock,
getBlockNearTimestamp,
Expand Down Expand Up @@ -86,7 +86,7 @@ export class AudiusClient {
static displayShortAud = displayShortAud
static getAud = getAud
static getWei = getWei
static getNodeVersion = getNodeVersion
static getNodeMetadata = getNodeMetadata
}

window.AudiusClient = AudiusClient
Expand Down
16 changes: 11 additions & 5 deletions src/services/Audius/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,21 @@ export function getWei(amount: BigNumber) {
return amount.mul(Utils.toBN('1000000000000000000'))
}

export async function getNodeVersion(endpoint: string): Promise<string> {
type NodeMetadata = {
version: string
country: string
}

export async function getNodeMetadata(endpoint: string): Promise<NodeMetadata> {
try {
const version = await fetchWithTimeout(`${endpoint}/health_check`).then(
r => r.data.version
const { data } = await fetchWithTimeout(
`${endpoint}/health_check?verbose=true`
)
return version
const { version, country } = data
return { version, country }
} catch (e) {
console.error(e)
// Return no version if we couldn't find one, so we don't hold everything up
return ''
return { version: '', country: '' }
}
}
4 changes: 3 additions & 1 deletion src/store/cache/contentNode/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const getFilteredNodes = ({
// -------------------------------- Helpers --------------------------------

const processNode = async (node: Node, aud: Audius): Promise<ContentNode> => {
const version = await Audius.getNodeVersion(node.endpoint)
const { country, version } = await Audius.getNodeMetadata(node.endpoint)
const isDeregistered = node.endpoint === ''
let previousInfo = {}
if (isDeregistered) {
Expand All @@ -76,11 +76,13 @@ const processNode = async (node: Node, aud: Audius): Promise<ContentNode> => {
node.spID
)
}

return {
...node,
...previousInfo,
type: ServiceType.ContentNode,
version,
country,
isDeregistered
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/store/cache/discoveryProvider/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const processDP = async (
node: Node,
aud: Audius
): Promise<DiscoveryProvider> => {
const version = await Audius.getNodeVersion(node.endpoint)
const { version, country } = await Audius.getNodeMetadata(node.endpoint)
const isDeregistered = node.endpoint === ''
let previousInfo = {}
if (isDeregistered) {
Expand All @@ -85,6 +85,7 @@ const processDP = async (
...previousInfo,
type: ServiceType.DiscoveryProvider,
version,
country,
isDeregistered
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type Node = {
type: ServiceType
blockNumber: BlockNumber
delegateOwnerWallet: Wallet
country: string
}

export type DiscoveryProvider = {
Expand Down

0 comments on commit 01b648e

Please sign in to comment.