-
-
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
Alexander Rogalskiy
committed
Oct 27, 2021
1 parent
126e836
commit 95b6d27
Showing
3 changed files
with
148 additions
and
0 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,51 @@ | ||
interface IParametres { | ||
radius: number, | ||
width: number, | ||
height: number, | ||
fontSize: number, | ||
strokeWidth: number, | ||
arrowRadius: number, | ||
arrowStroke: number, | ||
capText: boolean, | ||
x: number, | ||
y: number, | ||
offsetY: number, | ||
} | ||
|
||
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini/i.test( | ||
navigator.userAgent | ||
); | ||
const getParametres = (): IParametres => { | ||
|
||
if (isMobile) { | ||
return { | ||
radius: 150, | ||
width: 320, | ||
height: 312, | ||
fontSize: 11, | ||
strokeWidth: 1, | ||
arrowRadius: 18, | ||
arrowStroke: 1, | ||
capText: false, | ||
x: 300, | ||
y: 156, | ||
offsetY: 5, | ||
}; | ||
} else { | ||
return { | ||
radius: 250, | ||
width: 820, | ||
height: 520, | ||
fontSize: 17, | ||
strokeWidth: 1, | ||
arrowRadius: 30, | ||
arrowStroke: 1, | ||
capText: true, | ||
x: 655, | ||
y: 260, | ||
offsetY: 10, | ||
}; | ||
} | ||
}; | ||
|
||
export default getParametres; |
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,44 @@ | ||
import { observable, action } from 'mobx'; | ||
|
||
type ListItem = {}; | ||
|
||
export interface IListStore { | ||
items: ListItem[], | ||
spinning: boolean, | ||
add(value: string): void, | ||
delete(index: number): void, | ||
start(): void, | ||
finish(): void, | ||
} | ||
|
||
class ListStore implements IListStore { | ||
|
||
@observable | ||
items = []; | ||
|
||
@observable | ||
spinning = false; | ||
|
||
@action.bound | ||
add(value: string): void { | ||
const newItem = { text: value, color: 'white' }; | ||
this.items.push(newItem); | ||
} | ||
|
||
@action.bound | ||
delete(index: number): void { | ||
this.items.splice(index, 1); | ||
} | ||
|
||
@action.bound | ||
start(): void { | ||
this.spinning = true; | ||
} | ||
|
||
@action.bound | ||
finish(): void { | ||
this.spinning = false; | ||
} | ||
} | ||
|
||
export default new ListStore(); |
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,53 @@ | ||
import { quote, keys } from 'stores'; | ||
|
||
const client = new WebSocket('wss://api.exchange.bitcoin.com/api/2/ws'); | ||
|
||
export const initWs = () => { | ||
client.onopen = () => { | ||
getSymbols(); | ||
console.log('socket connected'); | ||
}; | ||
client.onmessage = (msg): void => { | ||
const message = JSON.parse(msg.data); | ||
if (!message.error) { | ||
if (message.method === 'ticker') { | ||
quote.updateStore(message.params); | ||
} | ||
else if (typeof message.result !== 'boolean') { | ||
const symbols = message.result; | ||
keys.init(symbols); | ||
|
||
}; | ||
} | ||
}; | ||
}; | ||
|
||
export const subscribe = (id: string) => { | ||
const message = { | ||
method: "subscribeTicker", params: { | ||
symbol: id | ||
} | ||
} | ||
const json = JSON.stringify(message); | ||
client.send(json) | ||
} | ||
export const unsubscribe = (id: string) => { | ||
quote.unsubscribeQuote(id); | ||
|
||
const message = { | ||
method: "unsubscribeTicker", params: { | ||
symbol: id | ||
} | ||
} | ||
const json = JSON.stringify(message); | ||
client.send(json); | ||
} | ||
|
||
export const close = (): void => { | ||
client.close(1000, 'click lol') | ||
}; | ||
|
||
export const getSymbols = (): void => { | ||
const message = JSON.stringify({ method: 'getSymbols' }); | ||
client.send(message) | ||
}; |