1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
import { colors, Styles } from '@0xproject/react-shared';
import * as _ from 'lodash';
import { GridList } from 'material-ui/GridList';
import * as React from 'react';
import { RelayerGridTile } from 'ts/components/relayer_index/relayer_grid_tile';
import { WebsiteBackendRelayerInfo } from 'ts/types';
import { backendClient } from 'ts/utils/backend_client';
export interface RelayerIndexProps {
networkId: number;
}
interface RelayerIndexState {
relayerInfos?: WebsiteBackendRelayerInfo[];
error?: Error;
}
const styles: Styles = {
root: {
width: '100%',
},
item: {
backgroundColor: colors.white,
borderBottomRightRadius: 10,
borderBottomLeftRadius: 10,
borderTopRightRadius: 10,
borderTopLeftRadius: 10,
boxShadow: `0px 4px 6px ${colors.walletBoxShadow}`,
overflow: 'hidden',
padding: 4,
},
};
const CELL_HEIGHT = 290;
const NUMBER_OF_COLUMNS = 4;
const GRID_PADDING = 20;
export class RelayerIndex extends React.Component<RelayerIndexProps, RelayerIndexState> {
private _isUnmounted: boolean;
constructor(props: RelayerIndexProps) {
super(props);
this._isUnmounted = false;
this.state = {
relayerInfos: undefined,
error: undefined,
};
}
public componentWillMount() {
// tslint:disable-next-line:no-floating-promises
this._fetchRelayerInfosAsync();
}
public componentWillUnmount() {
this._isUnmounted = true;
}
public render() {
const readyToRender = _.isUndefined(this.state.error) && !_.isUndefined(this.state.relayerInfos);
if (readyToRender) {
return (
<div style={styles.root}>
<GridList
cellHeight={CELL_HEIGHT}
cols={NUMBER_OF_COLUMNS}
padding={GRID_PADDING}
style={styles.gridList}
>
{this.state.relayerInfos.map((relayerInfo: WebsiteBackendRelayerInfo) => (
<RelayerGridTile
key={relayerInfo.id}
relayerInfo={relayerInfo}
networkId={this.props.networkId}
/>
))}
</GridList>
</div>
);
} else {
// TODO: loading and error states with a scrolling container
return null;
}
}
private async _fetchRelayerInfosAsync(): Promise<void> {
try {
const relayerInfos = await backendClient.getRelayerInfosAsync();
if (!this._isUnmounted) {
this.setState({
relayerInfos,
});
}
} catch (error) {
if (!this._isUnmounted) {
this.setState({
error,
});
}
}
}
}
|