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

Adrienne / Show online offline status in advertiser page #6913

Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1437840
remove p2p_advertiser_info call from buy-sell-store
Oct 28, 2022
d7e1392
remove p2p_advertiser_info call from my-profile-store
Oct 28, 2022
02f3c81
remove p2p_advertiser_info call from my-ads-store
Oct 28, 2022
a27e914
remove available balance hook
Oct 28, 2022
f7f066d
remove p2p_advertiser_info call from order-store
Oct 31, 2022
f6533ef
make p2p_advertiser_info in advertiser_page_store a subscription
Nov 3, 2022
063c0e3
cleanup
Nov 3, 2022
69d5a69
fixed conflicts
Nov 3, 2022
34abed3
Added online status to advertiser page
adrienne-deriv Nov 7, 2022
f9a9d9e
Merge branch 'master' into adrienne-deriv/task-79700/show-online-offl…
adrienne-deriv Nov 7, 2022
916e095
Removed unused css
adrienne-deriv Nov 7, 2022
77b7179
Merge branch 'adrienne-deriv/task-79700/show-online-offline-status-ad…
adrienne-deriv Nov 7, 2022
be053b7
remove unnecessary action.bound
Nov 8, 2022
808f17a
added more padding in rating row
adrienne-deriv Nov 9, 2022
0b36af8
fix: review comments
Nov 9, 2022
f642c6d
Merge branch 'master' of github.com:binary-com/deriv-app into p2p-adv…
Nov 9, 2022
7780355
cleanup advertiser page store
Nov 9, 2022
5f43dbc
cleanup buy-sell- store
Nov 9, 2022
b9ca64e
cleanup my-ads-store
Nov 9, 2022
a3e01b3
cleanup my-profile-store
Nov 9, 2022
db2a074
cleanup order-store
Nov 9, 2022
25276f9
Fixed styling issues
adrienne-deriv Nov 14, 2022
c4616bc
fix subtask
Nov 15, 2022
0b4ee87
fix subtask
Nov 16, 2022
e6af86f
updated changes
adrienne-deriv Nov 16, 2022
78ff79c
Fixed merge conflicts
adrienne-deriv Nov 17, 2022
b78b159
Refactored code with subs
adrienne-deriv Nov 17, 2022
5f186d2
Refactored code with subs
adrienne-deriv Nov 17, 2022
8a812d6
Merge branch 'master' into adrienne-deriv/task-79700/show-online-offl…
adrienne-deriv Nov 17, 2022
0f31d36
Merge branch 'master' into adrienne-deriv/task-79700/show-online-offl…
adrienne-deriv Nov 17, 2022
9f19e52
Reverted icons.js
adrienne-deriv Nov 17, 2022
363c02b
Refactored icons.js
adrienne-deriv Nov 17, 2022
4a08344
Refactored code based on reviews
adrienne-deriv Nov 17, 2022
70551fc
Refactored code based on reviews
adrienne-deriv Nov 17, 2022
55dbbbd
Refactored online status label
adrienne-deriv Nov 17, 2022
272ea17
Refactored code
adrienne-deriv Nov 17, 2022
98d4025
Refactored code
adrienne-deriv Nov 17, 2022
a7ccac4
Fixed CircleCI issue
adrienne-deriv Nov 17, 2022
2f07229
Refactored code
adrienne-deriv Nov 17, 2022
6f3596e
Used advertiser details id to check if its my advert
adrienne-deriv Nov 17, 2022
6ff5a05
used moment shared functions
adrienne-deriv Nov 17, 2022
3f886ca
Refactored label
adrienne-deriv Nov 17, 2022
3de41d4
Update online-status-label.jsx
adrienne-deriv Nov 17, 2022
57a210d
Update online-status-label.jsx
adrienne-deriv Nov 17, 2022
19b070d
Merge branch 'master' into adrienne-deriv/task-79700/show-online-offl…
carolsachdeva Nov 22, 2022
9a052bf
docs: add comment
Nov 22, 2022
0053e10
Merge pull request #1 from carol-binary/add-comment
adrienne-deriv Nov 22, 2022
c1bf364
Added checks for years and months greater than 6
adrienne-deriv Nov 23, 2022
c1be825
Merge branch 'master' into adrienne-deriv/task-79700/show-online-offl…
adrienne-deriv Nov 23, 2022
e4052a8
Fixed typo
adrienne-deriv Nov 23, 2022
d234256
Merge branch 'master' into adrienne-deriv/task-79700/show-online-offl…
carolsachdeva Nov 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import './advertiser-page.scss';
const AdvertiserPageStats = () => {
const { advertiser_page_store, general_store } = useStores();

const is_my_advert = advertiser_page_store.advertiser_details_id === general_store.advertiser_id;
const info = is_my_advert ? general_store.advertiser_info : advertiser_page_store.counterparty_advertiser_info;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I found the cause of this issue: this.advertiser_details_id in the advertiser page store is correctly pointing to the clicked advertiser ID, but when we navigate to our own adverts, we make a call to p2p_advertiser_info with subscribe: 1 and the id as our advertiser ID, but this returns an error from the websocket.
Screenshot 2022-11-17 at 7 13 55 PM

This is because we are already subscribed to listen to our own advertiser details within general store, and thus the reason why the websocket is returning AlreadySubscribed error (by omitting the id field, we are essentially calling advertiser info on our own profile as per the API documentation):
Screenshot 2022-11-17 at 7 55 33 PM
So, one of the ways I tried to use a single request was modifying this.counterparty_advertiser_info into using general_store.advertiser_info if we are looking at our own adverts, but this defeats the purpose of having a counterparty advertiser info as an observable, since it could then contain your own advertiser info or the counterparty advertiser info. Since we are already subscribed to our own p2p_advertiser_info endpoint, I feel that we can just reuse our details within general_store.advertiser_info without making unnecessary re-request to again get our personal advertiser info, since its already cached within general store. If there are any updates to our own advertiser info, the subscribed endpoint in general store should automatically already re-set our advertiser info through general_store.updateAdvertiserInfo:
Screenshot 2022-11-17 at 8 05 50 PM

Thus the approach I can find at the moment without breaking other pages using counterparty_advertiser_info is to just check within advertiser page, that is:

  1. If we are looking at our own advert, use general_store.advertiser_info, any subsequent updates to our advertiser info will be updated automatically since we are already subscribed to it in general store (and it would not be unsubscribed even if we leave our advertiser page and check on other user's advertiser info)
  2. If we are looking at counterparty adverts, use advertiser_page_store.counterparty_advertiser_info
  3. Make checks if we are looking at our own advert by advertiser_page_store.advertiser_details_id === general_store.advertiser_id

If this approach is not a good one, I could try to create a new computed value to return either general_store.advertiser_info or advertiser_page_store.counterparty_advertiser_info, but that is essentially the same approach as I am doing within advertiser page

const {
buy_completion_rate,
buy_orders_amount,
Expand All @@ -19,7 +21,7 @@ const AdvertiserPageStats = () => {
sell_completion_rate,
sell_orders_amount,
sell_orders_count,
} = advertiser_page_store.counterparty_advertiser_info;
} = info;

const avg_buy_time_in_minutes = buy_time_avg > 60 ? Math.round(buy_time_avg / 60) : '< 1';
const avg_release_time_in_minutes = release_time_avg > 60 ? Math.round(release_time_avg / 60) : '< 1';
Expand Down
99 changes: 63 additions & 36 deletions packages/p2p/src/components/advertiser-page/advertiser-page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,34 @@ import BlockUserOverlay from './block-user/block-user-overlay';
import BlockUserModal from 'Components/block-user/block-user-modal';
import ErrorModal from 'Components/error-modal/error-modal';
import classNames from 'classnames';
import { OnlineStatusIcon, OnlineStatusLabel } from 'Components/online-status';
adrienne-deriv marked this conversation as resolved.
Show resolved Hide resolved
import './advertiser-page.scss';

const AdvertiserPage = () => {
const { general_store, advertiser_page_store, buy_sell_store } = useStores();

const is_my_advert = advertiser_page_store.advertiser_details_id === general_store.advertiser_id;
const info = is_my_advert ? general_store.advertiser_info : advertiser_page_store.counterparty_advertiser_info;
const {
basic_verification,
buy_orders_count,
created_time,
first_name,
full_verification,
id,
is_online,
last_online_time,
last_name,
name,
rating_average,
rating_count,
recommended_average,
recommended_count,
sell_orders_count,
} = advertiser_page_store.counterparty_advertiser_info;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you are viewing your own ads, this will return the previously viewed counterparty advertiser's info instead of your own info

} = info;

// rating_average_decimal converts rating_average to 1 d.p number
const rating_average_decimal = rating_average ? Number(rating_average).toFixed(1) : null;
const joined_since = daysSince(created_time);
const is_my_advert = id === general_store.advertiser_id;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is_my_advert is invalid here, id refers to the counterparty advertiser's id when the user is vieweing their own ads

const [is_error_modal_open, setIsErrorModalOpen] = React.useState(false);

React.useEffect(() => {
Expand Down Expand Up @@ -78,7 +81,8 @@ const AdvertiserPage = () => {
return (
<div
className={classNames('advertiser-page', {
'advertiser-page--no-scroll': !!advertiser_page_store.is_counterparty_advertiser_blocked,
'advertiser-page--no-scroll':
!!advertiser_page_store.is_counterparty_advertiser_blocked && !is_my_advert,
})}
>
<RateChangeModal onMount={advertiser_page_store.setShowAdPopup} />
Expand All @@ -96,7 +100,7 @@ const AdvertiserPage = () => {
/>
<BlockUserModal
advertiser_name={name}
is_advertiser_blocked={!!advertiser_page_store.is_counterparty_advertiser_blocked}
is_advertiser_blocked={!!advertiser_page_store.is_counterparty_advertiser_blocked && !is_my_advert}
is_block_user_modal_open={
general_store.is_block_user_modal_open && !general_store.block_unblock_user_error
}
Expand All @@ -122,7 +126,7 @@ const AdvertiserPage = () => {
)}
</div>
<BlockUserOverlay
is_visible={!!advertiser_page_store.is_counterparty_advertiser_blocked}
is_visible={!!advertiser_page_store.is_counterparty_advertiser_blocked && !is_my_advert}
onClickUnblock={() => general_store.setIsBlockUserModalOpen(true)}
>
<div className='advertiser-page-details-container'>
Expand All @@ -145,7 +149,60 @@ const AdvertiserPage = () => {
</div>
)}
</div>

<MobileWrapper>
<div className='advertiser-page__row'>
<div className='advertiser-page__rating--row'>
<OnlineStatusIcon is_online={is_online} />
<OnlineStatusLabel is_online={is_online} last_online_time={last_online_time} />
</div>
<div className='advertiser-page__rating--row'>
<Text
className='advertiser-page__joined-since'
color='less-prominent'
size='xxxs'
>
{joined_since ? (
<Localize
i18n_default_text='Joined {{days_since_joined}}d'
values={{ days_since_joined: joined_since }}
/>
) : (
<Localize i18n_default_text='Joined today' />
)}
</Text>
</div>
</div>
</MobileWrapper>

<div className='advertiser-page__rating'>
<DesktopWrapper>
<React.Fragment>
<div className='advertiser-page__rating--row'>
<OnlineStatusIcon is_online={is_online} />
<OnlineStatusLabel
is_online={is_online}
last_online_time={last_online_time}
/>
</div>
<div className='advertiser-page__rating--row'>
<Text
className='advertiser-page__joined-since'
color='less-prominent'
size='xs'
>
{joined_since ? (
<Localize
i18n_default_text='Joined {{days_since_joined}}d'
values={{ days_since_joined: joined_since }}
/>
) : (
<Localize i18n_default_text='Joined today' />
)}
</Text>
</div>
</React.Fragment>
</DesktopWrapper>
{rating_average ? (
<React.Fragment>
<div className='advertiser-page__rating--row'>
Expand Down Expand Up @@ -193,37 +250,7 @@ const AdvertiserPage = () => {
</Text>
</div>
)}
{!isMobile() && (
<div className='advertiser-page__rating--row'>
<Text color='less-prominent' size={isMobile() ? 'xxxs' : 'xs'}>
{joined_since > 0 ? (
<Localize
i18n_default_text='Joined {{days_since_joined}}d'
values={{ days_since_joined: joined_since }}
/>
) : (
<Localize i18n_default_text='Joined today' />
)}
</Text>
</div>
)}
</div>
{isMobile() && (
<Text
className='advertiser-page__joined-since'
color='less-prominent'
size={isMobile() ? 'xxxs' : 'xs'}
>
{joined_since > 0 ? (
<Localize
i18n_default_text='Joined {{days_since_joined}}d'
values={{ days_since_joined: joined_since }}
/>
) : (
<Localize i18n_default_text='Joined today' />
)}
</Text>
)}
<div className='advertiser-page__row'>
<TradeBadge
is_poa_verified={!!full_verification}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
}

&-real-name {
margin-top: 0.4rem;
margin: 0.4rem 0;
max-width: 500px;
}
&-verification {
Expand Down Expand Up @@ -205,7 +205,8 @@
}

&__joined-since {
margin-bottom: 0.7rem;
margin-bottom: 0.35rem;
margin-top: 0.35rem;
}

&__stats {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,41 @@ const MyProfileName = () => {
<Text color='prominent' weight='bold' size='s' line_height='m'>
{general_store.nickname}
</Text>
<MobileWrapper>
<div className='my-profile-name__row'>
<Text
className='my-profile-name--rating__row'
color='less-prominent'
size={isMobile() ? 'xxxs' : 'xs'}
>
{joined_since ? (
<Localize
i18n_default_text='Joined {{days_since_joined}}d'
values={{ days_since_joined: joined_since }}
/>
) : (
<Localize i18n_default_text='Joined today' />
)}
</Text>
</div>
</MobileWrapper>
<div className='my-profile-name--rating'>
<DesktopWrapper>
<Text
className='my-profile-name--rating__row'
color='less-prominent'
size={isMobile() ? 'xxxs' : 'xs'}
>
{joined_since ? (
<Localize
i18n_default_text='Joined {{days_since_joined}}d'
values={{ days_since_joined: joined_since }}
/>
) : (
<Localize i18n_default_text='Joined today' />
)}
</Text>
</DesktopWrapper>
{rating_average ? (
<React.Fragment>
<div className='my-profile-name--rating__row'>
Expand Down Expand Up @@ -94,41 +128,14 @@ const MyProfileName = () => {
<div className='my-profile-name--rating__row'>
<BlockUserCount />
</div>
<Text
className='my-profile-name--rating__row'
color='less-prominent'
size={isMobile() ? 'xxxs' : 'xs'}
>
{joined_since > 0 ? (
<Localize
i18n_default_text='Joined {{days_since_joined}}d'
values={{ days_since_joined: joined_since }}
/>
) : (
<Localize i18n_default_text='Joined today' />
)}
</Text>
</DesktopWrapper>
</div>

<MobileWrapper>
<div className='my-profile-name__row'>
<div className='my-profile-name--rating__row'>
<BlockUserCount />
</div>
<Text
className='my-profile-name--rating__row'
color='less-prominent'
size={isMobile() ? 'xxxs' : 'xs'}
>
{joined_since > 0 ? (
<Localize
i18n_default_text='Joined {{days_since_joined}}d'
values={{ days_since_joined: joined_since }}
/>
) : (
<Localize i18n_default_text='Joined today' />
)}
</Text>
</div>
</MobileWrapper>
<div className='my-profile-name__row'>
Expand Down
5 changes: 5 additions & 0 deletions packages/p2p/src/components/online-status/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import OnlineStatusIcon from './online-status-icon';
import OnlineStatusLabel from './online-status-label';
import './online-status.scss';

export { OnlineStatusIcon, OnlineStatusLabel };
26 changes: 26 additions & 0 deletions packages/p2p/src/components/online-status/online-status-icon.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react-lite';

const OnlineStatusIcon = ({ is_online, size = '1em' }) => {
return (
<div
className={classNames('online-status__icon', {
'online-status__icon--offline': !is_online,
'online-status__icon--online': !!is_online,
})}
style={{
width: size,
height: size,
}}
/>
);
};

OnlineStatusIcon.propTypes = {
is_online: PropTypes.oneOfType([PropTypes.number, PropTypes.bool]).isRequired,
size: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
};

export default observer(OnlineStatusIcon);
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import { Text } from '@deriv/components';
import { getDiffDuration, isMobile, toMoment, epochToMoment } from '@deriv/shared';
import { localize } from 'Components/i18next';
import { observer } from 'mobx-react-lite';
import PropTypes from 'prop-types';

const OnlineStatusLabel = ({ is_online, last_online_time, size = isMobile() ? 'xxxs' : 'xs' }) => {
const last_online_label = () => {
if (!is_online) {
if (last_online_time) {
const start_time = epochToMoment(last_online_time).unix();
const end_time = toMoment().unix();

const diff = getDiffDuration(start_time, end_time);
const addPrural = duration => (duration !== 1 ? 's' : '');
nijil-deriv marked this conversation as resolved.
Show resolved Hide resolved

if (diff.months())
return localize('Seen {{ duration }} month{{ prural }} ago', {
duration: diff.months(),
prural: addPrural(diff.months()),
});
if (diff.days())
return localize('Seen {{ duration }} day{{ prural }} ago', {
duration: diff.days(),
prural: addPrural(diff.days()),
});
if (diff.hours())
return localize('Seen {{ duration }} hour{{ prural }} ago', {
duration: diff.hours(),
prural: addPrural(diff.hours()),
});
if (diff.minutes())
return localize('Seen {{ duration }} minute{{ prural }} ago', {
duration: diff.minutes(),
prural: addPrural(diff.minutes()),
});
} else {
return localize('Seen more than 6 months ago');
}
}
return localize('Online');
};

return (
<Text color='less-prominent' size={size}>
{last_online_label()}
</Text>
);
};

OnlineStatusLabel.propTypes = {
is_online: PropTypes.number.isRequired,
last_online_time: PropTypes.number,
size: PropTypes.string,
};

export default observer(OnlineStatusLabel);
20 changes: 20 additions & 0 deletions packages/p2p/src/components/online-status/online-status.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.online-status {
&__icon {
width: 1rem;
height: 1rem;
margin: auto 0.5rem auto 0rem;
border-radius: 50%;

@include mobile {
width: 0.8rem;
height: 0.8rem;
}

&--online {
background: var(--text-profit-success);
}
&--offline {
background: var(--checkbox-disabled-grey);
}
}
}