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

fix: replaced throttle with debounce #17520

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
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
17 changes: 9 additions & 8 deletions packages/trader/src/Stores/Modules/Trading/trade-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {
import { STATE_TYPES, TPayload, getChartAnalyticsData } from './Helpers/chart';
import { safeParse } from '@deriv/utils';
import { sendDtraderPurchaseToAnalytics } from '../../../Analytics';
import throttle from 'lodash.throttle';

type TBarriers = Array<
ChartBarrierStore & {
Expand Down Expand Up @@ -346,7 +347,7 @@ export default class TradeStore extends BaseStore {
this.is_chart_loading = status;
});
}); // no time is needed here, the only goal is to put the call into macrotasks queue
debouncedProposal = debounce(this.requestProposal, 500);
throttleProposal = throttle(this.requestProposal, 500);
proposal_requests: Record<string, Partial<PriceProposalRequest>> = {};
is_purchasing_contract = false;

Expand Down Expand Up @@ -1070,7 +1071,7 @@ export default class TradeStore extends BaseStore {
if (info) this.onPurchase(info.id, info.stake, trade_type, isMobile, callback, true);
}

onPurchase = debounce(this.processPurchase, 300);
onPurchase = throttle(this.processPurchase, 300);

processPurchase(
proposal_id: string,
Expand Down Expand Up @@ -1183,7 +1184,7 @@ export default class TradeStore extends BaseStore {
this.forgetAllProposal();
this.purchase_info = response;
this.proposal_requests = {};
this.debouncedProposal();
this.throttleProposal();
this.clearLimitOrderBarriers();
this.pushPurchaseDataToGtm(contract_data);
if (this.root_store.ui.is_mobile) {
Expand Down Expand Up @@ -1374,7 +1375,7 @@ export default class TradeStore extends BaseStore {
const is_crypto = isCryptocurrency(this.currency ?? '');
const default_crypto_value = getMinPayout(this.currency ?? '') ?? '';
this.setV2ParamsInitialValues({
value: is_crypto ? default_crypto_value : this.default_stake ?? '',
value: is_crypto ? default_crypto_value : (this.default_stake ?? ''),
name: 'stake',
});
obj_new_values.amount = is_crypto ? default_crypto_value : this.default_stake;
Expand Down Expand Up @@ -1423,7 +1424,7 @@ export default class TradeStore extends BaseStore {
if (/\b(contract_type|currency)\b/.test(Object.keys(new_state) as unknown as string)) {
this.validateAllProperties();
}
this.debouncedProposal();
this.throttleProposal();
}
}

Expand Down Expand Up @@ -1647,7 +1648,7 @@ export default class TradeStore extends BaseStore {
this.refresh();

if (this.is_trade_component_mounted) {
this.debouncedProposal();
this.throttleProposal();
}
return;
}
Expand Down Expand Up @@ -1802,7 +1803,7 @@ export default class TradeStore extends BaseStore {
await this.setContractTypes();
this.is_trade_enabled = true;
this.is_trade_enabled_v2 = true;
this.debouncedProposal();
this.throttleProposal();
}

clientInitListener() {
Expand Down Expand Up @@ -1885,7 +1886,7 @@ export default class TradeStore extends BaseStore {

await this.processNewValuesAsync({ currency: new_currency }, true, { currency: this.currency }, false);
this.refresh();
this.debouncedProposal();
this.throttleProposal();
}

onUnmount() {
Expand Down
Loading