Skip to content

Commit 0464448

Browse files
author
Alex Kwiatkowski
authored
Merge pull request #1276 from smartcontractkit/bugs/runtime-etherscan-host
Use etherscan host from job run metadata
2 parents b818347 + 7c549be commit 0464448

File tree

12 files changed

+109
-17
lines changed

12 files changed

+109
-17
lines changed

explorer/client/@types/link-stats/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface IJobRun {
1515
createdAt: string
1616
finishedAt?: string
1717
chainlinkNode: IChainlinkNode
18+
etherscanHost: string
1819
taskRuns: ITaskRun[]
1920
}
2021

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import reducer, { IState } from '../../reducers'
2+
import { Action } from '../../reducers/config'
3+
4+
describe('reducers/config', () => {
5+
it('returns an initial state', () => {
6+
const action = {} as Action
7+
const state = reducer({}, action) as IState
8+
9+
expect(state.search).toEqual({
10+
etherscanHost: undefined
11+
})
12+
})
13+
14+
it('can update the search query', () => {
15+
const action = {
16+
type: 'UPSERT_JOB_RUN',
17+
data: {
18+
meta: {
19+
jobRun: {
20+
meta: {
21+
etherscanHost: 'ropsten.etherscan.io'
22+
}
23+
}
24+
}
25+
}
26+
} as Action
27+
const state = reducer({}, action) as IState
28+
29+
expect(state.config).toEqual({
30+
etherscanHost: 'ropsten.etherscan.io'
31+
})
32+
})
33+
})

explorer/client/src/__tests__/reducers/jobRuns.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ describe('reducers/jobRuns', () => {
7070
id: '9b7d791a-9a1f-4c55-a6be-b4231cf9fd4e'
7171
}
7272
}
73-
const data = { jobRuns: normalizedJobRuns }
73+
const data = {
74+
jobRuns: normalizedJobRuns,
75+
meta: {
76+
jobRun: { meta: {} }
77+
}
78+
}
7479
const action = { type: 'UPSERT_JOB_RUN', data: data } as JobRunsAction
7580
const state = reducer(STATE, action) as IState
7681

explorer/client/src/__tests__/reducers/jobRunsIndex.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ describe('reducers/jobRunsIndex', () => {
5353

5454
describe('UPSERT_JOB_RUN', () => {
5555
it('clears items', () => {
56-
const data = { jobRuns: {} }
56+
const data = {
57+
jobRuns: {},
58+
meta: {
59+
jobRun: { meta: {} }
60+
}
61+
}
5762
const action = { type: 'UPSERT_JOB_RUN', data: data } as JobRunsAction
5863
const state = reducer(STATE, action) as IState
5964

explorer/client/src/actions/jobRuns.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const getJobRuns = (query: Query, page: number, size: number) => {
2121
const getJobRun = (jobRunId?: string) => {
2222
return (dispatch: Dispatch<any>) => {
2323
api.getJobRun(jobRunId).then((r: IJobRun) => {
24-
const normalizedData = normalize(r)
24+
const normalizedData = normalize(r, { endpoint: 'jobRun' })
2525
const action: JobRunsAction = {
2626
type: 'UPSERT_JOB_RUN',
2727
data: normalizedData

explorer/client/src/components/JobRuns/Details.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ const styles = ({ spacing, palette }: Theme) =>
119119

120120
interface IProps extends WithStyles<typeof styles> {
121121
jobRun: IJobRun
122+
etherscanHost: string
122123
}
123124

124-
const Details = ({ classes, jobRun }: IProps) => {
125+
const Details = ({ classes, jobRun, etherscanHost }: IProps) => {
125126
return (
126127
<div>
127128
<Row>
@@ -169,7 +170,7 @@ const Details = ({ classes, jobRun }: IProps) => {
169170
<Row className={classes.bottomRow}>
170171
<Key>Tasks</Key>
171172
<BaseItem sm={12} md={8} className={classes.task}>
172-
<TaskRuns taskRuns={jobRun.taskRuns} />
173+
<TaskRuns taskRuns={jobRun.taskRuns} etherscanHost={etherscanHost} />
173174
</BaseItem>
174175
</Row>
175176
</div>

explorer/client/src/components/JobRuns/EtherscanLink.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ const styles = ({ palette, spacing }: Theme) =>
2828

2929
interface IProps extends WithStyles<typeof styles> {
3030
txHash: string
31+
host: string
3132
}
3233

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

36-
const Details = ({ classes, txHash }: IProps) => {
36+
const Details = ({ classes, host, txHash }: IProps) => {
3737
return (
3838
<a
39-
href={url(txHash)}
39+
href={url(host, txHash)}
4040
target="_blank"
4141
rel="noopener noreferrer"
4242
className={classes.link}>

explorer/client/src/components/JobRuns/TaskRuns.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ const styles = ({ spacing, palette }: Theme) =>
3939
})
4040

4141
interface IProps extends WithStyles<typeof styles> {
42+
etherscanHost: string
4243
taskRuns?: ITaskRun[]
4344
}
4445

45-
const TaskRuns = ({ taskRuns, classes }: IProps) => {
46+
const TaskRuns = ({ etherscanHost, taskRuns, classes }: IProps) => {
4647
return (
4748
<ul className={classes.container}>
4849
{taskRuns &&
@@ -60,7 +61,10 @@ const TaskRuns = ({ taskRuns, classes }: IProps) => {
6061
</Grid>
6162
<Grid item xs={9}>
6263
{run.transactionHash && (
63-
<EtherscanLink txHash={run.transactionHash} />
64+
<EtherscanLink
65+
txHash={run.transactionHash}
66+
host={etherscanHost}
67+
/>
6468
)}
6569
</Grid>
6670
</Grid>

explorer/client/src/containers/JobRuns/Show.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ const styles = ({ spacing, breakpoints }: Theme) =>
5555
interface IProps extends WithStyles<typeof styles> {
5656
jobRunId?: string
5757
jobRun?: IJobRun
58+
etherscanHost?: string
5859
getJobRun: Function
5960
path: string
6061
}
6162

6263
const Show = withStyles(styles)(
63-
({ jobRunId, jobRun, getJobRun, classes }: IProps) => {
64+
({ jobRunId, jobRun, getJobRun, classes, etherscanHost }: IProps) => {
6465
useEffect(() => {
6566
getJobRun(jobRunId)
6667
}, [])
@@ -79,7 +80,14 @@ const Show = withStyles(styles)(
7980

8081
<div className={classes.container}>
8182
<Card className={classes.card}>
82-
{jobRun ? <Details jobRun={jobRun} /> : <Loading />}
83+
{jobRun && etherscanHost ? (
84+
<Details
85+
jobRun={jobRun}
86+
etherscanHost={etherscanHost.toString()}
87+
/>
88+
) : (
89+
<Loading />
90+
)}
8391
</Card>
8492
</div>
8593
</Grid>
@@ -103,13 +111,19 @@ const jobRunSelector = (
103111
}
104112
}
105113

114+
const etherscanHostSelector = ({ config }: IState) => {
115+
return config.etherscanHost
116+
}
117+
106118
interface IOwnProps {
107119
jobRunId?: string
108120
}
109121

110122
const mapStateToProps = (state: IState, { jobRunId }: IOwnProps) => {
111123
const jobRun = jobRunSelector(state, jobRunId)
112-
return { jobRun }
124+
const etherscanHost = etherscanHostSelector(state)
125+
126+
return { jobRun, etherscanHost }
113127
}
114128

115129
const mapDispatchToProps = (dispatch: Dispatch<any>) =>

explorer/client/src/reducers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { combineReducers } from 'redux'
2+
import config, { IState as IConfigState } from './reducers/config'
23
import search, { IState as ISearchState } from './reducers/search'
34
import jobRuns, { IState as IJobRunsState } from './reducers/jobRuns'
45
import taskRuns, { IState as ITaskRunsState } from './reducers/taskRuns'
@@ -10,6 +11,7 @@ import jobRunsIndex, {
1011
} from './reducers/jobRunsIndex'
1112

1213
export interface IState {
14+
config: IConfigState
1315
chainlinkNodes: IChainlinkNodesState
1416
jobRuns: IJobRunsState
1517
taskRuns: ITaskRunsState
@@ -18,6 +20,7 @@ export interface IState {
1820
}
1921

2022
const reducer = combineReducers({
23+
config,
2124
chainlinkNodes,
2225
jobRuns,
2326
taskRuns,

0 commit comments

Comments
 (0)