Skip to content

Commit

Permalink
Updates on files
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Rogalskiy committed Oct 27, 2021
1 parent 126e836 commit 95b6d27
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/constant/getParametres.ts
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;
44 changes: 44 additions & 0 deletions src/constant/store.ts
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();
53 changes: 53 additions & 0 deletions src/constant/ws.ts
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)
};

0 comments on commit 95b6d27

Please sign in to comment.