Skip to content

Commit

Permalink
[DTRA-V2]/Ahmad/Default Stake Currency fix (#17422)
Browse files Browse the repository at this point in the history
* chore: fix

* fix: fix

* chore: trigger

* chore: remove trade_store

* chore: removing types too

* chore: testcase
  • Loading branch information
ahmadtaimoor-deriv authored Nov 13, 2024
1 parent b0d9f3f commit 7dfa0a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,6 @@ export default class ClientStore extends BaseStore {
if (this.accounts && this.accounts[this.loginid]) {
return this.accounts[this.loginid].email;
}

return '';
}

Expand Down Expand Up @@ -2068,6 +2067,7 @@ export default class ClientStore extends BaseStore {
async logout() {
// makes sure to clear the cached traders-hub data when logging out
localStorage.removeItem('traders_hub_store');
localStorage.removeItem('trade_store');

// TODO: [add-client-action] - Move logout functionality to client store
const response = await requestLogout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ describe('Stake', () => {
userEvent.click(screen.getByText(stake_param_label));
userEvent.type(screen.getByPlaceholderText(input_placeholder), '0');

expect(default_mock_store.modules.trade.setV2ParamsInitialValues).toHaveBeenCalledTimes(1);
expect(default_mock_store.modules.trade.setV2ParamsInitialValues).toHaveBeenCalledTimes(2);

userEvent.click(screen.getByRole('button', { name: save_button_label }));
expect(default_mock_store.modules.trade.setV2ParamsInitialValues).toHaveBeenCalledTimes(2);
expect(default_mock_store.modules.trade.setV2ParamsInitialValues).toHaveBeenCalledTimes(3);
});

it('calls onChange on component mount if v2_params_initial_values.stake is not equal to amount', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import clsx from 'clsx';
import { observer } from 'mobx-react';
import { useStore } from '@deriv/stores';
Expand Down Expand Up @@ -38,7 +38,7 @@ const Stake = observer(({ is_minimized }: TTradeParametersProps) => {
validation_params,
} = useTraderStore();
const {
client: { is_logged_in },
client: { is_logged_in, currency: client_currency },
} = useStore();
const { addSnackbar } = useSnackbar();
const [is_open, setIsOpen] = React.useState(false);
Expand All @@ -53,6 +53,16 @@ const Stake = observer(({ is_minimized }: TTradeParametersProps) => {
? Number(v2_params_initial_values.stake)
: available_contract_types?.[contract_type]?.config?.default_stake;

useEffect(() => {
if (client_currency !== currency) {
onChange({ target: { name: 'currency', value: client_currency } });
if (!isCryptocurrency(client_currency ?? '')) {
onChange({ target: { name: 'amount', value: default_stake } });
setV2ParamsInitialValues({ value: default_stake as number, name: 'stake' });
}
}
}, [client_currency]);

const displayed_error = React.useRef(false);
const contract_types = getDisplayedContractTypes(trade_types, contract_type, trade_type_tab);
// first contract type data:
Expand Down

0 comments on commit 7dfa0a9

Please sign in to comment.