Skip to content

Commit

Permalink
fix(#1137): fix typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
d1mon1k committed Sep 10, 2022
1 parent 338d861 commit 3251733
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
10 changes: 4 additions & 6 deletions src/components/photo-editor/crop-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,17 @@ export default async function getCroppedImg(
canvas.height = pixelCrop.height;

// paste generated rotate image with correct offsets for x,y crop values.
ctx.putImageData(
data,
0 - safeArea / 2 + image.width * 0.5 - pixelCrop.x,
0 - safeArea / 2 + image.height * 0.5 - pixelCrop.y,
);
ctx.putImageData(data, 0 - safeArea / 2 + image.width * 0.5 - pixelCrop.x, 0 - safeArea / 2 + image.height * 0.5 - pixelCrop.y);

// As Base64 string
// return canvas.toDataURL('image/jpeg');

// As a blob
return new Promise((resolve) => {
canvas.toBlob((file) => {
resolve(URL.createObjectURL(file));
if (file) {
resolve(URL.createObjectURL(file));
}
}, 'image/jpeg');
});
}
17 changes: 10 additions & 7 deletions src/store/common/decorators/retry-on-network-connection-error.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosError } from 'axios';
import { SagaIterator } from 'redux-saga';
import { call, race, take } from 'redux-saga/effects';

Expand All @@ -11,13 +12,15 @@ export function* retryOnNetworkConnectionError(handler: () => SagaIterator): Sag
try {
return yield call(handler);
} catch (e) {
if (isNetworkError(e)) {
yield race({
websocketsConnected: take(WebsocketsConnected.action),
internetConnected: take(InternetConnected.action),
});
} else {
throw e;
if (e instanceof AxiosError) {
if (isNetworkError(e)) {
yield race({
websocketsConnected: take(WebsocketsConnected.action),
internetConnected: take(InternetConnected.action),
});
} else {
throw e;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosError } from 'axios';
import { SagaIterator } from 'redux-saga';
import { call, race, take } from 'redux-saga/effects';

Expand All @@ -10,13 +11,15 @@ export function* retryOnNetworkConnectionError(handler: () => SagaIterator): Sag
try {
return yield call(handler);
} catch (e) {
if (isNetworkError(e)) {
yield race({
websocketsConnected: take(WebsocketsConnected.action),
internetConnected: take(InternetConnected.action),
});
} else {
throw e;
if (e instanceof AxiosError) {
if (isNetworkError(e)) {
yield race({
websocketsConnected: take(WebsocketsConnected.action),
internetConnected: take(InternetConnected.action),
});
} else {
throw e;
}
}
}
}
Expand Down
25 changes: 10 additions & 15 deletions src/store/login/features/send-sms-code/send-sms-code.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { AxiosResponse} from 'axios';
import { ISendSmsCodeRequest} from 'kimbu-models';
import { AxiosError, AxiosResponse } from 'axios';
import { ISendSmsCodeRequest } from 'kimbu-models';
import { SagaIterator } from 'redux-saga';
import { call, put } from 'redux-saga/effects';

import { MAIN_API } from '@common/paths';
import { createDeferredAction } from '@store/common/actions';
import { authRequestFactory } from '@store/common/http/auth-request-factory';
import { HttpRequestMethod } from '@store/common/http/http-request-method';
import {mapAxiosErrorToApplicationError} from "@utils/error-utils";
import { mapAxiosErrorToApplicationError } from '@utils/error-utils';

import { ISendSmsCodeActionPayload } from './action-payloads/send-sms-code-action-payload';
import { SendSmsCodeFailure } from './send-sms-code-failure';
Expand All @@ -30,10 +30,7 @@ export class SendSmsCode {
}

static get saga() {
return function* sendSmsPhoneConfirmationCodeSaga(
action: ReturnType<typeof SendSmsCode.action>,
): SagaIterator {

return function* sendSmsPhoneConfirmationCodeSaga(action: ReturnType<typeof SendSmsCode.action>): SagaIterator {
try {
SendSmsCode.httpRequest.call(
yield call(() =>
Expand All @@ -46,19 +43,17 @@ export class SendSmsCode {
yield put(SendSmsCodeSuccess.action());

yield call(() => action.meta?.deferred?.resolve());
}
catch (e){
} catch (e) {
yield put(SendSmsCodeFailure.action());
const applicationError = mapAxiosErrorToApplicationError(e)
yield call(() => action.meta?.deferred?.reject(applicationError));
if (e instanceof AxiosError) {
const applicationError = mapAxiosErrorToApplicationError(e);
yield call(() => action.meta?.deferred?.reject(applicationError));
}
}
};
}

static get httpRequest() {
return authRequestFactory<AxiosResponse<string>, ISendSmsCodeRequest>(
MAIN_API.SEND_SMS_CODE,
HttpRequestMethod.Post,
);
return authRequestFactory<AxiosResponse<string>, ISendSmsCodeRequest>(MAIN_API.SEND_SMS_CODE, HttpRequestMethod.Post);
}
}

0 comments on commit 3251733

Please sign in to comment.