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

[DTRA] Henry/wall 2135/wallets account switcher #606

Conversation

henry-deriv
Copy link
Contributor

@henry-deriv henry-deriv commented Feb 6, 2024

Changes:

  • New header for wallets

Type of change

  • Bug fix
  • New feature
  • Update feature
  • Refactor code
  • Translation to code
  • Translation to crowdin
  • Script configuration
  • Improve performance
  • Style only
  • Dependency update
  • Documentation update
  • Release

@henry-deriv henry-deriv requested a review from a team as a code owner February 6, 2024 08:27
@@ -28,7 +28,7 @@ const ClientBase = (() => {

const isValidLoginid = () => {
if (!isLoggedIn()) return true;
const valid_login_ids = new RegExp('^(MX|MF|VRTC|MLT|CR|FOG)[0-9]+$', 'i');
const valid_login_ids = new RegExp('^(MX|MF|VRTC|MLT|CR|FOG|VRW|CRW)[0-9]+$', 'i');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wallet accounts start with VRW and CRW. Without this change, page refreshes during login which causes log out.

@@ -135,6 +135,9 @@ const ClientBase = (() => {
return only_real_loginids.every(loginid => get('currency', loginid) && !isCryptocurrency(get('currency', loginid)));
};

const isWalletsAccount = (loginid) => getAllAccountsObject()[loginid].account_category === 'wallet';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is not TS, it's hard to say if loginid is defined and if it's present among keys of returned object getAllAccountsObject().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. What do u mean to say?

[loginid] accepts anything

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, is there opportunity to get undefined here getAllAccountsObject()[loginid]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point. i handled the edge cases. please check

window.LC_API.on_chat_ended = () => {
setNameEmail();
};
if (window.LC_API && window.LC_API.on_chat_ended) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this condition needed? - window.LC_API.on_chat_ended

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is optional chaining supported here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. Theres a console error complaining because on_chat_ended doesn't exist in LC_API object. i dont believe on_chat_ended exists in the object until live chat is started then closed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we are checking for this function window.LC_API.on_chat_ended before defining it at the below line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah u r right i'll fix.

@@ -92,6 +108,9 @@ const Header = (() => {
applyToAllElements('.url-manage-account', el => {
el.href = Url.urlForDeriv('redirect', `action=manage_account&ext_platform_url=${encodeURIComponent(window.location.href)}`);
});
applyToAllElements('.url-wallets-deposit', el => {
el.href = Url.urlForDeriv('wallets/cashier/transfer', `ext_platform_url=${encodeURIComponent(window.location.href)}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it make sense to move encodeURIComponent(window.location.href) in a constant and reuse it? encodeURIComponent(window.location.href) is used in multiple lines in setHeaderUrls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya this is fine. i'll implement.

el.src = Url.urlForStatic(`${header_icon_base_path}ic-bell.svg`);
});

applyToAllElements('#header__notification-empty', (el) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this selectors match to that from line 111? If yes, then it should be header__notification-empty-img
Not sure, if this comment is relevant, but I noticed that all the rest selectors have a pair from constants above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i was applying to container instead of image tag. i fixed it

@@ -275,7 +318,7 @@ const Header = (() => {
mobile_menu__livechat_logo.src = Url.urlForStatic('images/common/livechat.svg');

// Notification Event
const notification_bell = getElementById('header__notiifcation-icon-container');
const notification_bell = getElementById('header__notifcation-icon-container');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notifcation ---> notification

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch lol.

const account_switcher = Client.hasWalletsAccount() ? getElementById('wallet__switcher') : getElementById('account__switcher');
const account_switcher_dropdown = Client.hasWalletsAccount() ? getElementById('wallet__switcher-dropdown') : getElementById('account__switcher-dropdown');
const account_switcher_active = Client.hasWalletsAccount() ? 'wallet__switcher-dropdown--show' : 'account__switcher-dropdown--show';
const wallet_switcher_close = getElementById('wallet__switcher-close');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it (wallet_switcher_close) always exist or only if Client.hasWalletsAccount() === true?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because after you put an eventListener on it

Copy link
Contributor Author

@henry-deriv henry-deriv Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wallet_switcher_close exist only if Client.hasWalletaccount() is true. I remove the whole < WalletHeader /> from the DOM at the start in switchHeader() at the top.

Theres actually a lot of shared classnames/IDs in both <Header /> and <WalletHeader />. Removing the switcher from the DOM was the way I could attach event handler without rewriting the same thing but with different classnames. JS didn't know where to attach the event handler when classnames/IDs are same but both headers exist in the DOM.

} else {
add_account_text_eu_country.style.display = 'none';
}
if (isEuCountry() && has_real_account) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, it's an old code and you didn't touch this part, but maybe:

if (isEuCountry()) {
   add_account_text_normal.style.display = 'none';
   if (has_real_account) {
     add_account_text_eu_country.parentElement.style.display = 'none';
   }
} else {
    add_account_text_eu_country.style.display = 'none';
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets not touch this lol. Any fart in the wind and the whole account switcher will break. It has like 4 different account types that is juggling lol

const currency = Client.get('currency', loginid);
const currencyName = mapCurrencyName(currency);

const getIcon = (() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't get why do we need extra brackets here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats a typo. thanks for pointing it out

border-top: 1px solid var(--general-hover);
bottom: 0;
position: fixed;
width: stretch;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First time saw this css property for width))))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didnt know until yesterday either

</div>
</div>
<div id='mobile_menu-content' className='mobile__menu-content mobile__menu-content--active'>
<div className='mobile__platform-switcher' >
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any style which can be also deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do u mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean if you delete a component, which have classNames, we need to make sure that this classnames are reused or deleted

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I can see that they are still being used in new files, sorry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i just removed and turned it into a component

</a>
</div>
<div className='wallet__header-menu-item wallet__header-menu-links client_logged_in invisible mobile-hide'>
<a className='url-wallet-apps'>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember exactly, but is href attribute required? I saw a lot of places, where devs were using at least dummy href : href="#"
Please, ignore if relevant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not in this case. hrefs are applied via javascript in header.js. So "#" would be wrong.

@@ -135,6 +135,19 @@ const ClientBase = (() => {
return only_real_loginids.every(loginid => get('currency', loginid) && !isCryptocurrency(get('currency', loginid)));
};

const isWalletsAccount = (loginid) => {
if (typeof loginid === 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined here is a string, is it correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

gap: 8px;
}
&-logo {
width: 148px !important;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which style is overriding it? is it possible to move this style after the place where it gets overriden in order to avoid using !important? or can we use some other approach to increase this CSS selector's specificity (priority) for your element without using !important? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i forget but let me check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is handled! i removed this classname completely and handled the other classname with media query

Copy link

Preview Link: https://pr-606.smarttrader-preview.pages.dev

Name Result
Build status Completed ✅
Preview URL Visit Preview
Action URL Visit Action

@balakrishna-deriv balakrishna-deriv merged commit 7ae045d into deriv-com:master Mar 13, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants