Skip to content

Commit

Permalink
Merge pull request #1276 from smartcontractkit/bugs/runtime-etherscan…
Browse files Browse the repository at this point in the history
…-host

Use etherscan host from job run metadata
  • Loading branch information
rupurt authored May 28, 2019
2 parents b818347 + 7c549be commit 0464448
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 17 deletions.
1 change: 1 addition & 0 deletions explorer/client/@types/link-stats/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface IJobRun {
createdAt: string
finishedAt?: string
chainlinkNode: IChainlinkNode
etherscanHost: string
taskRuns: ITaskRun[]
}

Expand Down
33 changes: 33 additions & 0 deletions explorer/client/src/__tests__/reducers/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import reducer, { IState } from '../../reducers'
import { Action } from '../../reducers/config'

describe('reducers/config', () => {
it('returns an initial state', () => {
const action = {} as Action
const state = reducer({}, action) as IState

expect(state.search).toEqual({
etherscanHost: undefined
})
})

it('can update the search query', () => {
const action = {
type: 'UPSERT_JOB_RUN',
data: {
meta: {
jobRun: {
meta: {
etherscanHost: 'ropsten.etherscan.io'
}
}
}
}
} as Action
const state = reducer({}, action) as IState

expect(state.config).toEqual({
etherscanHost: 'ropsten.etherscan.io'
})
})
})
7 changes: 6 additions & 1 deletion explorer/client/src/__tests__/reducers/jobRuns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ describe('reducers/jobRuns', () => {
id: '9b7d791a-9a1f-4c55-a6be-b4231cf9fd4e'
}
}
const data = { jobRuns: normalizedJobRuns }
const data = {
jobRuns: normalizedJobRuns,
meta: {
jobRun: { meta: {} }
}
}
const action = { type: 'UPSERT_JOB_RUN', data: data } as JobRunsAction
const state = reducer(STATE, action) as IState

Expand Down
7 changes: 6 additions & 1 deletion explorer/client/src/__tests__/reducers/jobRunsIndex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ describe('reducers/jobRunsIndex', () => {

describe('UPSERT_JOB_RUN', () => {
it('clears items', () => {
const data = { jobRuns: {} }
const data = {
jobRuns: {},
meta: {
jobRun: { meta: {} }
}
}
const action = { type: 'UPSERT_JOB_RUN', data: data } as JobRunsAction
const state = reducer(STATE, action) as IState

Expand Down
2 changes: 1 addition & 1 deletion explorer/client/src/actions/jobRuns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getJobRuns = (query: Query, page: number, size: number) => {
const getJobRun = (jobRunId?: string) => {
return (dispatch: Dispatch<any>) => {
api.getJobRun(jobRunId).then((r: IJobRun) => {
const normalizedData = normalize(r)
const normalizedData = normalize(r, { endpoint: 'jobRun' })
const action: JobRunsAction = {
type: 'UPSERT_JOB_RUN',
data: normalizedData
Expand Down
5 changes: 3 additions & 2 deletions explorer/client/src/components/JobRuns/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ const styles = ({ spacing, palette }: Theme) =>

interface IProps extends WithStyles<typeof styles> {
jobRun: IJobRun
etherscanHost: string
}

const Details = ({ classes, jobRun }: IProps) => {
const Details = ({ classes, jobRun, etherscanHost }: IProps) => {
return (
<div>
<Row>
Expand Down Expand Up @@ -169,7 +170,7 @@ const Details = ({ classes, jobRun }: IProps) => {
<Row className={classes.bottomRow}>
<Key>Tasks</Key>
<BaseItem sm={12} md={8} className={classes.task}>
<TaskRuns taskRuns={jobRun.taskRuns} />
<TaskRuns taskRuns={jobRun.taskRuns} etherscanHost={etherscanHost} />
</BaseItem>
</Row>
</div>
Expand Down
8 changes: 4 additions & 4 deletions explorer/client/src/components/JobRuns/EtherscanLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ const styles = ({ palette, spacing }: Theme) =>

interface IProps extends WithStyles<typeof styles> {
txHash: string
host: string
}

const host = process.env.ETHERSCAN_HOST || 'ropsten.etherscan.io'
const url = (txHash: string) => `https://${host}/tx/${txHash}`
const url = (host: string, txHash: string) => `https://${host}/tx/${txHash}`

const Details = ({ classes, txHash }: IProps) => {
const Details = ({ classes, host, txHash }: IProps) => {
return (
<a
href={url(txHash)}
href={url(host, txHash)}
target="_blank"
rel="noopener noreferrer"
className={classes.link}>
Expand Down
8 changes: 6 additions & 2 deletions explorer/client/src/components/JobRuns/TaskRuns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ const styles = ({ spacing, palette }: Theme) =>
})

interface IProps extends WithStyles<typeof styles> {
etherscanHost: string
taskRuns?: ITaskRun[]
}

const TaskRuns = ({ taskRuns, classes }: IProps) => {
const TaskRuns = ({ etherscanHost, taskRuns, classes }: IProps) => {
return (
<ul className={classes.container}>
{taskRuns &&
Expand All @@ -60,7 +61,10 @@ const TaskRuns = ({ taskRuns, classes }: IProps) => {
</Grid>
<Grid item xs={9}>
{run.transactionHash && (
<EtherscanLink txHash={run.transactionHash} />
<EtherscanLink
txHash={run.transactionHash}
host={etherscanHost}
/>
)}
</Grid>
</Grid>
Expand Down
20 changes: 17 additions & 3 deletions explorer/client/src/containers/JobRuns/Show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ const styles = ({ spacing, breakpoints }: Theme) =>
interface IProps extends WithStyles<typeof styles> {
jobRunId?: string
jobRun?: IJobRun
etherscanHost?: string
getJobRun: Function
path: string
}

const Show = withStyles(styles)(
({ jobRunId, jobRun, getJobRun, classes }: IProps) => {
({ jobRunId, jobRun, getJobRun, classes, etherscanHost }: IProps) => {
useEffect(() => {
getJobRun(jobRunId)
}, [])
Expand All @@ -79,7 +80,14 @@ const Show = withStyles(styles)(

<div className={classes.container}>
<Card className={classes.card}>
{jobRun ? <Details jobRun={jobRun} /> : <Loading />}
{jobRun && etherscanHost ? (
<Details
jobRun={jobRun}
etherscanHost={etherscanHost.toString()}
/>
) : (
<Loading />
)}
</Card>
</div>
</Grid>
Expand All @@ -103,13 +111,19 @@ const jobRunSelector = (
}
}

const etherscanHostSelector = ({ config }: IState) => {
return config.etherscanHost
}

interface IOwnProps {
jobRunId?: string
}

const mapStateToProps = (state: IState, { jobRunId }: IOwnProps) => {
const jobRun = jobRunSelector(state, jobRunId)
return { jobRun }
const etherscanHost = etherscanHostSelector(state)

return { jobRun, etherscanHost }
}

const mapDispatchToProps = (dispatch: Dispatch<any>) =>
Expand Down
3 changes: 3 additions & 0 deletions explorer/client/src/reducers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { combineReducers } from 'redux'
import config, { IState as IConfigState } from './reducers/config'
import search, { IState as ISearchState } from './reducers/search'
import jobRuns, { IState as IJobRunsState } from './reducers/jobRuns'
import taskRuns, { IState as ITaskRunsState } from './reducers/taskRuns'
Expand All @@ -10,6 +11,7 @@ import jobRunsIndex, {
} from './reducers/jobRunsIndex'

export interface IState {
config: IConfigState
chainlinkNodes: IChainlinkNodesState
jobRuns: IJobRunsState
taskRuns: ITaskRunsState
Expand All @@ -18,6 +20,7 @@ export interface IState {
}

const reducer = combineReducers({
config,
chainlinkNodes,
jobRuns,
taskRuns,
Expand Down
21 changes: 21 additions & 0 deletions explorer/client/src/reducers/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface IState {
etherscanHost?: string
}

export type Action =
| { type: 'UPSERT_JOB_RUN'; data: any }
| { type: '@@redux/INIT' }
| { type: '@@INIT' }

const initialState = { etherscanHost: undefined }

export default (state: IState = initialState, action: Action) => {
switch (action.type) {
case 'UPSERT_JOB_RUN':
return Object.assign({}, state, {
etherscanHost: action.data.meta.jobRun.meta.etherscanHost
})
default:
return state
}
}
11 changes: 8 additions & 3 deletions explorer/src/serializers/jobRunSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ export const taskRuns = {
]
}

const jobRunsSerializer = (run: JobRun) => {
const ETHERSCAN_HOST = process.env.ETHERSCAN_HOST || 'ropsten.etherscan.io'

const jobRunSerializer = (run: JobRun) => {
const opts = {
attributes: BASE_ATTRIBUTES.concat(['taskRuns']),
keyForAttribute: 'camelCase',
chainlinkNode: chainlinkNode,
taskRuns: taskRuns
taskRuns: taskRuns,
meta: {
etherscanHost: ETHERSCAN_HOST
}
} as SerializerOptions

return new JSONAPISerializer('job_runs', opts).serialize(run)
}

export default jobRunsSerializer
export default jobRunSerializer

0 comments on commit 0464448

Please sign in to comment.