Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Farzin/73307/TS migration of deposit related stores #6262

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
f8e1bca
update MobX libraries
Jun 30, 2022
e4e17d1
bot migration
Jun 30, 2022
fa986f2
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Jul 3, 2022
329a079
trader migration
Jul 3, 2022
f4efa8a
core migration
Jul 3, 2022
aaa62c6
cfd migration
Jul 3, 2022
3d05428
p2p migration
Jul 3, 2022
082d006
cashier migration
Jul 3, 2022
6522824
regenerate package-lock.json
Jul 3, 2022
cf53a09
fix verification store issue on cashier
Jul 4, 2022
361e57c
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Jul 4, 2022
78056c0
temperately commented failed tests to find a solution
Jul 5, 2022
9ca013c
resolve conflicts
Jul 14, 2022
fe930cf
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Jul 17, 2022
f66f8c2
fix console errors related to mobx
Jul 17, 2022
fc462dc
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Jul 19, 2022
38a359c
regenerate package-lock.json
Jul 19, 2022
e471dd9
resolve conflicts
Jul 21, 2022
bf821e9
fix general store issue on p2p
Jul 21, 2022
757a20b
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Jul 26, 2022
5efe2a2
bug: fix p2p stores bugs
Jul 26, 2022
b3d75bc
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Jul 26, 2022
3545dc0
resolve conflicts
Jul 28, 2022
05dbb76
resolve conflicts
Aug 9, 2022
373aa5e
fix console errors
Aug 9, 2022
c4a3bb0
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Aug 9, 2022
5548a78
fix: Open position blinking while there is active contract going on
Aug 14, 2022
201072b
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Aug 14, 2022
e59fbca
perf(cashier): add types for client, common, ui stores; refactor Type…
heorhi-deriv Aug 15, 2022
fefda84
perf(cashier): add types in client, ui stores
heorhi-deriv Aug 15, 2022
128909c
refactor(cashier): refactor root-store declaration into type
heorhi-deriv Aug 16, 2022
490c3b1
refactor(cashier): refactor naming
heorhi-deriv Aug 16, 2022
3d9672a
resolve conflicts
Aug 16, 2022
6baec59
fix: blinking issue
Aug 16, 2022
0780030
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Aug 17, 2022
62dd8ca
fix: nitpik
Aug 17, 2022
8501aaa
Merge branch 'master' into client-store-types
heorhi-deriv Aug 17, 2022
4f30947
Merge branch 'master' into client-store-types
heorhi-deriv Aug 18, 2022
a5ff374
Merge branch 'master' into client-store-types
heorhi-deriv Aug 18, 2022
9909baa
resolve conflicts
Aug 21, 2022
32f1309
fix: conflicts
Aug 22, 2022
8ef7100
feat(cashier): :construction: migrate `ErrorStore` to TypeScript
Aug 23, 2022
7ddf468
Merge remote-tracking branch 'george-usynin-binary/client-store-types…
Aug 23, 2022
e90e2bd
fix bot issue
Aug 23, 2022
e9bd4f7
feat(cashier): :construction: migrate `IframeStore` to TypeScript
Aug 23, 2022
d62e662
feat(cashier): :construction: migrate `DepositStore` to TypeScript
Aug 23, 2022
542a42f
chores: change @deriv/deriv-charts versions
Aug 25, 2022
29d52aa
fix: conflicts
Aug 25, 2022
69f5dd6
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Aug 25, 2022
0337a29
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Aug 25, 2022
82dbd46
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Aug 25, 2022
0fcbb68
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Aug 25, 2022
13d186c
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Aug 25, 2022
9d976e1
Merge branch 'master' of github.com:binary-com/deriv-app into mobx-mi…
Aug 25, 2022
984ee7c
Merge remote-tracking branch 'niloo-fs/mobx-migration-to-version-6' i…
Aug 29, 2022
38b1ee5
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Aug 29, 2022
884609b
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Aug 29, 2022
49408a9
fix(cashier): :bug: fix `tsconfig`
Aug 29, 2022
bb42f9b
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Aug 29, 2022
8cb9282
fix(cashier): :memo: resolve PR comments
Aug 29, 2022
8af03a7
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Aug 30, 2022
34e8a1c
fix(cashier): :memo: resolve PR comments
Aug 31, 2022
527434e
fix(cashier): :memo: resolve PR comments
Aug 31, 2022
12944dc
fix(cashier): :memo: resolve PR comments
Aug 31, 2022
26da89a
refactor(cashier): :coffin: remove `container` as a prop in `setIfram…
Aug 31, 2022
31d1714
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 6, 2022
ce12d71
fix(cashier): :memo: resolve merge conflicts
Sep 6, 2022
53f63a3
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 6, 2022
84882f8
fix(cashier): :memo: resolve merge conflicts
Sep 6, 2022
1edbb41
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 6, 2022
6d7208c
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 6, 2022
4f93e2a
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 8, 2022
bd2f8e0
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 11, 2022
83056c3
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 14, 2022
b88e4d1
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 14, 2022
66040e7
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 15, 2022
a0a6886
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 15, 2022
90e75fd
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 16, 2022
dc13e8c
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 18, 2022
0075e02
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 20, 2022
1984fe0
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 21, 2022
6e375d9
Merge remote-tracking branch 'upstream/ts-cashier' into farzin/73307/…
Sep 23, 2022
2b3eeed
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 23, 2022
6adea0e
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
Sep 26, 2022
03f2ae0
Merge branch 'master' into farzin/73307/ts_migration_of_deposit_relat…
carolsachdeva Sep 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/cashier/globals.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('DepositStore', () => {
send: jest.fn(() => Promise.resolve({})),
};

deposit_store = new DepositStore({ root_store, WS });
deposit_store = new DepositStore(WS, root_store);
});

it('should mount deposit properly', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/cashier/src/stores/__tests__/iframe-store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ beforeEach(() => {
is_mobile: false,
},
};
iframe_store = new IframeStore({ WS, root_store });
iframe_store = new IframeStore(root_store);
});

describe('IframeStore', () => {
Expand All @@ -39,7 +39,7 @@ describe('IframeStore', () => {
iframe_store.removeOnIframeLoaded();

expect(removeEventListener).toHaveBeenCalledWith('message', expect.any(Function), false);
expect(iframe_store.onIframeLoaded).toBe('');
expect(iframe_store.onIframeLoaded).toBe(null);
});

it('should clear timeout cashier url', () => {
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('IframeStore', () => {
it('should set proper iframe_height for desktop and mobile view', async () => {
const spyRemoveOnIframeLoaded = jest.spyOn(iframe_store, 'removeOnIframeLoaded');

expect(iframe_store.onIframeLoaded).toBe('');
expect(iframe_store.onIframeLoaded).toBe(null);

await iframe_store.checkIframeLoaded();

Expand Down
4 changes: 2 additions & 2 deletions packages/cashier/src/stores/cashier-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export default class CashierStore {
this.account_prompt_dialog = new AccountPromptDialogStore(root_store);
this.account_transfer = new AccountTransferStore({ root_store, WS });
this.crypto_fiat_converter = new CryptoFiatConverterStore({ root_store, WS });
this.deposit = new DepositStore({ root_store, WS });
this.deposit = new DepositStore(WS, root_store);
this.error_dialog = new ErrorDialogStore();
this.error = new ErrorStore();
this.general_store = new GeneralStore({ root_store, WS });
this.iframe = new IframeStore({ root_store, WS });
this.iframe = new IframeStore(root_store);
this.onramp = new OnRampStore({ root_store, WS });
this.payment_agent = new PaymentAgentStore({ root_store, WS });
this.payment_agent_transfer = new PaymentAgentTransferStore({ root_store, WS });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { action, computed, observable } from 'mobx';
import Constants from 'Constants/constants';
import ErrorStore from './error-store';
import { TRootStore, TWebSocket } from 'Types';

export default class DepositStore {
constructor({ WS, root_store }) {
constructor(public WS: TWebSocket, public root_store: TRootStore) {
this.root_store = root_store;
this.WS = WS;
}
Expand All @@ -12,7 +13,7 @@ export default class DepositStore {
@observable error = new ErrorStore();

@action.bound
async onMountDeposit() {
async onMountDeposit(): Promise<void> {
const { client, modules } = this.root_store;
const { active_container, is_crypto, onMountCommon, setLoading, setOnRemount } = modules.cashier.general_store;
const {
Expand All @@ -30,7 +31,7 @@ export default class DepositStore {
setOnRemount(this.onMountDeposit);
await onMountCommon();

this.error.setErrorMessage('');
this.error.setErrorMessage({ code: '', message: '' }, null, false);
setContainerHeight(0);
setLoading(true);

Expand Down Expand Up @@ -78,7 +79,7 @@ export default class DepositStore {
}

@computed
get is_deposit_locked() {
get is_deposit_locked(): boolean {
const {
is_authentication_needed,
is_tnc_needed,
Expand Down Expand Up @@ -113,7 +114,7 @@ export default class DepositStore {
}

@action.bound
submitFundsProtection() {
submitFundsProtection(): void {
this.WS.send({ ukgc_funds_protection: 1, tnc_approval: 1 }).then(response => {
if (response.error) {
this.error.setMessage(response.error.message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { action, observable } from 'mobx';
import { getPropertyValue } from '@deriv/shared';
import { TServerError } from 'Types';

export default class ErrorStore {
@observable message = '';
@observable code = '';
@observable fields = '';
@observable is_show_full_page = false;
@observable onClickButton = null;
@observable onClickButton: VoidFunction | null = null;
@observable is_ask_uk_funds_protection = false;
@observable is_self_exclusion_max_turnover_set = false;
@observable is_ask_authentication = false;
@observable is_ask_financial_risk_approval = false;

@action.bound
setErrorMessage(error, onClickButton, is_show_full_page) {
setErrorMessage(error: TServerError, onClickButton?: VoidFunction | null, is_show_full_page?: boolean): void {
// for errors that need to show a button, reset the form
const error_object = {
onClickButton,
code: error.code,
message: error.message,
is_show_full_page: is_show_full_page || /InvalidToken|WrongResponse/.test(error.code),
...(getPropertyValue(error, ['details', 'fields']) && {
fields: error.details.fields,
fields: error.details?.fields,
}),
};

Expand All @@ -37,7 +38,7 @@ export default class ErrorStore {
}

@action.bound
handleCashierError(error) {
handleCashierError(error: TServerError): void {
switch (error.code) {
case 'ASK_TNC_APPROVAL':
this.setErrorMessage(error, null, true);
Expand Down Expand Up @@ -68,27 +69,27 @@ export default class ErrorStore {
}

@action.bound
setMessage(value) {
setMessage(value: string): void {
this.message = value;
}

@action.bound
setIsAskUkFundsProtection(value) {
setIsAskUkFundsProtection(value: boolean): void {
this.is_ask_uk_funds_protection = value;
}

@action.bound
setIsSelfExclusionMaxTurnoverSet(value) {
setIsSelfExclusionMaxTurnoverSet(value: boolean): void {
this.is_self_exclusion_max_turnover_set = value;
}

@action.bound
setIsAskAuthentication(value) {
setIsAskAuthentication(value: boolean): void {
this.is_ask_authentication = value;
}

@action.bound
setIsAskFinancialRiskApproval(value) {
setIsAskFinancialRiskApproval(value: boolean): void {
this.is_ask_financial_risk_approval = value;
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import { action, observable } from 'mobx';
import Constants from 'Constants/constants';
import { TRootStore } from 'Types';

type TOnIframeLoadedCallback = (ev: MessageEvent) => void;

export default class IframeStore {
constructor({ WS, root_store }) {
constructor(public root_store: TRootStore) {
farzin-deriv marked this conversation as resolved.
Show resolved Hide resolved
this.root_store = root_store;
this.WS = WS;
}

@observable iframe_height = 0;
@observable iframe_url = '';
@observable is_session_timeout = true;

onIframeLoaded = '';
@observable timeout_session = '';
onIframeLoaded: TOnIframeLoadedCallback | null = null;
@observable timeout_session: NodeJS.Timeout | null = null;

@action.bound
setSessionTimeout(is_session_time_out) {
setSessionTimeout(is_session_time_out: boolean): void {
this.is_session_timeout = is_session_time_out;
if (is_session_time_out) {
this.removeOnIframeLoaded();
}
}

@action.bound
async checkIframeLoaded() {
async checkIframeLoaded(): Promise<void> {
const { modules, ui } = this.root_store;

this.removeOnIframeLoaded();
this.onIframeLoaded = function (e) {
this.onIframeLoaded = (e: MessageEvent) => {
if (/cashier|doughflow/.test(e.origin)) {
modules.cashier.general_store.setLoading(false);
// set the height of the container after content loads so that the
Expand All @@ -40,52 +41,59 @@ export default class IframeStore {
// do not remove the listener
// on every iframe screen change we need to update the height to more/less to match the new content
}
}.bind(this);
};
window.addEventListener('message', this.onIframeLoaded, false);
}

removeOnIframeLoaded() {
removeOnIframeLoaded(): void {
if (this.onIframeLoaded) {
window.removeEventListener('message', this.onIframeLoaded, false);
this.onIframeLoaded = '';
this.onIframeLoaded = null;
}
}

@action.bound
clearTimeoutCashierUrl() {
clearTimeoutCashierUrl(): void {
if (this.timeout_session) {
clearTimeout(this.timeout_session);
}
}

@action.bound
setTimeoutCashierUrl() {
setTimeoutCashierUrl(): void {
this.clearTimeoutCashierUrl();
this.timeout_session = setTimeout(() => {
this.setSessionTimeout(true);
}, 60000);
}

@action.bound
setIframeUrl(url, container = this.root_store.modules.cashier.general_store.active_container) {
setIframeUrl(url: string): void {
const { client, ui } = this.root_store;

if (url) {
this.iframe_url = `${url}&theme=${ui.is_dark_mode_on ? 'dark' : 'light'}`;
// after we set iframe url we can clear verification code
client.setVerificationCode('', Constants.map_action[container]);

const container = this.root_store.modules.cashier.general_store.active_container;

if (container in Constants.map_action) {
const container_key = container as keyof typeof Constants.map_action;

// after we set iframe url we can clear verification code
client.setVerificationCode('', Constants.map_action[container_key]);
}
} else {
this.iframe_url = url;
}
}

@action.bound
setContainerHeight(height) {
setContainerHeight(height: number): void {
this.iframe_height = height;
}

@action.bound
clearIframe() {
clearIframe(): void {
this.setContainerHeight(0);
this.setIframeUrl('');
this.clearTimeoutCashierUrl();
Expand Down
9 changes: 9 additions & 0 deletions packages/cashier/src/types/shared/websocket.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ export type TServerError = {
message: string;
details?: { [key: string]: string };
};

type TWebSocketCall = {
cashier: (action: any, parameters: any) => Promise<any>;
};

export type TWebSocket = {
send: (obj: any) => Promise<any>;
authorized: TWebSocketCall;
};
9 changes: 9 additions & 0 deletions packages/cashier/src/types/stores/client-store.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ export type TClientStore = {
trading_platform_dxtrade_password_reset: string;
trading_platform_mt5_password_reset: string;
};
setVerificationCode: (code: string, action: string) => void;
updateAccountStatus: () => Promise<void>;
mt5_login_list: DetailsOfEachMT5Loginid[];
is_authentication_needed: boolean;
is_tnc_needed: boolean;
is_financial_account: boolean;
is_financial_information_incomplete: boolean;
is_trading_experience_incomplete: boolean;
is_eu: boolean;
};
5 changes: 4 additions & 1 deletion packages/cashier/src/types/stores/root-store.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { TClientStore } from './client-store.types';
import { TCommonStore } from './common-store.types';
import { TUiStore } from './ui-store.types';
import CashierStore from '../../stores/cashier-store';

export type TRootStore = {
client: TClientStore;
common: TCommonStore;
modules: any;
modules: {
cashier: CashierStore;
};
ui: TUiStore;
};
2 changes: 1 addition & 1 deletion packages/cashier/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"outDir": "./dist",
"baseUrl": "./"
},
"include": ["src", "globals.d.ts"]
"include": ["src"]
}