fix: incorrect checks

main
mrmld 2022-06-13 18:23:12 +03:00
parent bf3690d1cc
commit 554aeefd8c
3 changed files with 8 additions and 19 deletions

View File

@ -313,7 +313,7 @@ export class TonhubConnector {
});
if (!session.data.ok) {
if (!session.ok) {
throw Error('Unable to create state');
}
});
@ -375,7 +375,7 @@ export class TonhubConnector {
getSessionState = async (sessionId: string): Promise<TonhubSessionState> => {
return await backoff(async () => {
let session = this.transport.call('session_get', {
let session = await this.transport.call('session_get', {
id: sessionId
});
return this.ensureSessionStateCorrect(sessionId, session);
@ -384,7 +384,7 @@ export class TonhubConnector {
waitForSessionState = async (sessionId: string, lastUpdated?: number): Promise<TonhubSessionState> => {
return await backoff(async () => {
let session = this.transport.call('session_wait', {
let session = await this.transport.call('session_wait', {
id: sessionId,
lastUpdated
});

View File

@ -10,7 +10,7 @@ export class TonhubEmbeddedTransport implements Transport {
}
private static get() {
if (!window || !(window as any).tonX) {
if (typeof window === 'undefined' || !(window as any)?.tonX) {
return null;
}

View File

@ -1,4 +1,5 @@
import axios from 'axios';
import { string } from 'fp-ts';
export class TonhubHttpTransport implements Transport {
private readonly _endpoint: string;
@ -38,9 +39,6 @@ export class TonhubHttpTransport implements Transport {
args,
this.getAxiosConfig(),
);
if (!session.data.ok) {
throw Error('Unable to create session: ' + JSON.stringify(session.data));
}
return session.data;
}
@ -53,9 +51,6 @@ export class TonhubHttpTransport implements Transport {
`${this._endpoint}/connect/` + args.id,
this.getAxiosConfig()
);
if (!session.data.ok) {
throw Error('Unable to create session: ' + JSON.stringify(session.data));
}
return session.data;
}
@ -66,22 +61,16 @@ export class TonhubHttpTransport implements Transport {
let session = await axios.get(
`${this._endpoint}/connect/` + args.id + '/wait?lastUpdated='+(args.lastUpdated || 0),
this.getAxiosConfig()
{ ...this.getAxiosConfig(), timeout: 30000 }
);
if (!session.data.ok) {
throw Error('Unable to create session: ' + JSON.stringify(session.data));
}
return session.data;
}
async createCommand(args: any) {
let result = await axios.post(`${this._endpoint}/connect/command`, args, this.getAxiosConfig());
if (!result.data.ok) {
throw new Error('Cannot create command: ' + JSON.stringify(result.data));
}
return result.data;
}
async getCommand(appk: string) {
return (await axios.get(`${this._endpoint}/connect/command/` + appk, this.getAxiosConfig())).data;
async getCommand(args: { appk: string }) {
return (await axios.get(`${this._endpoint}/connect/command/` + args.appk, this.getAxiosConfig())).data;
}
}