Skip to content

Commit

Permalink
Account fix selected to (binary-com#27)
Browse files Browse the repository at this point in the history
* fix: default selected to account

* fix: account transfer switch to default client acc
  • Loading branch information
GeorgeUsynin committed Jan 24, 2023
1 parent 71a7958 commit 7b6a68b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/cashier/src/stores/account-transfer-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getPropertyValue,
validNumber,
CFD_PLATFORMS,
routes,
} from '@deriv/shared';
import { localize, Localize } from '@deriv/translations';
import Constants from '../constants/constants';
Expand Down Expand Up @@ -388,6 +389,9 @@ export default class AccountTransferStore {
const arr_accounts = [];
this.setSelectedTo({}); // set selected to empty each time so we can redetermine its value on reload

const is_from_pre_appstore =
this.root_store.client.is_pre_appstore && !location.pathname.startsWith(routes.cashier);

accounts.forEach(account => {
const cfd_platforms = {
mt5: { name: 'Deriv MT5', icon: 'IcMt5' },
Expand Down Expand Up @@ -482,8 +486,16 @@ export default class AccountTransferStore {
// check if selected to is not allowed account
obj_values.error = getSelectedError(obj_values.value);
}
// set the first available account as the default transfer to account
this.setSelectedTo(obj_values);

const { account_id, login } = this.root_store.traders_hub?.selected_account;

//if from appstore -> set selected account as the default transfer to account
//if not from appstore -> set the first available account as the default transfer to account
if (!is_from_pre_appstore) {
this.setSelectedTo(obj_values);
} else if ([account_id, login].includes(account.loginid)) {
this.setSelectedTo(obj_values);
}
}
arr_accounts.push(obj_values);
});
Expand Down Expand Up @@ -546,10 +558,9 @@ export default class AccountTransferStore {
// not allowed to transfer from MT to MT
// not allowed to transfer from Dxtrade to Dxtrade
// not allowed to transfer between MT and Dxtrade
const first_non_cfd = this.accounts_list.find(
account => !account.is_mt && !account.is_dxtrade && !account.is_derivez
);
this.onChangeTransferTo({ target: { value: first_non_cfd.value } });
// if new value of selected_from is different from selected_to
// switch the value of selected_to to current client loginid
this.onChangeTransferTo({ target: { value: this.root_store.client.loginid } });
}

if (hasTransferNotAllowedLoginid(selected_from.value)) {
Expand Down

0 comments on commit 7b6a68b

Please sign in to comment.