forked from skybet/js-tech-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5724869
commit a5b3522
Showing
5 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import styled from 'styled-components' | ||
|
||
export const Container = styled.div` | ||
padding: 1rem; | ||
margin: 1rem; | ||
border: 1ps solid black; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { Component } from 'react' | ||
import { IMarket } from '../../models/Market' | ||
import { wsEndpoint } from '../../utils/config' | ||
import { Container } from './Markets.css' | ||
|
||
interface IProps { | ||
markets: number[] | ||
} | ||
|
||
interface IState { | ||
markets: IMarket[] | null | ||
} | ||
|
||
class Markets extends Component<IProps, IState> { | ||
w: WebSocket | ||
constructor(props: IProps) { | ||
super(props) | ||
this.w = new WebSocket(wsEndpoint) | ||
this.state = { | ||
markets: null | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
this.w.onmessage = (e:MessageEvent) => { | ||
this.setState({ | ||
markets: JSON.parse(e.data) | ||
})} | ||
this.w.onopen = () => | ||
this.w.send(JSON.stringify({ type: "getMarket", id: this.props.markets[0] })); // try the first | ||
} | ||
|
||
componentWillUnmount() { | ||
this.w.close() | ||
} | ||
|
||
render() { | ||
const { markets } = this.state | ||
|
||
return( | ||
<Container> | ||
{JSON.stringify(markets)} | ||
</Container> | ||
) | ||
} | ||
} | ||
|
||
export default Markets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export interface IMarket { | ||
marketId: number | ||
eventId: number | ||
name: string | ||
displayOrder: number | ||
type: string | ||
status: { | ||
active: boolean | ||
resulted: boolean | ||
cashoutable: boolean | ||
displayable: boolean | ||
suspended: boolean | ||
noExtraTime: boolean | ||
live: boolean | ||
} | ||
liabilities: { | ||
livePriceLimit: number | ||
} | ||
spAvail: false | ||
outcomes: number[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters