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 / Made block user count to be subscribed to updates #6561

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import { isDesktop } from '@deriv/shared';
import './block-user-count.scss';

const BlockUserCount = () => {
const { my_profile_store } = useStores();
const { blocked_by_count } = my_profile_store.advertiser_info;
const { general_store } = useStores();
const { user_blocked_count } = general_store;

const [is_block_user_count_modal_open, setIsBlockUserCountModalOpen] = React.useState(false);

const getMessage = () => {
if (blocked_by_count === 0) {
return localize('Nobody has blocked you. Yay!');
} else if (blocked_by_count === 1) {
return localize('{{blocked_by_count}} person has blocked you', { blocked_by_count });
switch (user_blocked_count) {
case 0:
return localize('Nobody has blocked you. Yay!');
case 1:
return localize('{{user_blocked_count}} person has blocked you', {
user_blocked_count,
});
default:
return localize('{{user_blocked_count}} people have blocked you', {
user_blocked_count,
});
}
return localize('{{blocked_by_count}} people have blocked you', { blocked_by_count });
};

React.useEffect(() => {
my_profile_store.getAdvertiserInfo();

// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<>
<React.Fragment>
<MobileWrapper>
<Modal has_close_icon={false} is_open={is_block_user_count_modal_open} width='440px'>
<Modal.Body>
Expand Down Expand Up @@ -58,11 +58,11 @@ const BlockUserCount = () => {
>
<Icon className='block-user-count__container--icon' icon='IcUserBlockedOutline' size={16} />
<Text color='less-prominent' line_height='m' size={isDesktop() ? 'xs' : 14}>
{blocked_by_count}
{user_blocked_count}
</Text>
</Popover>
</div>
</>
</React.Fragment>
);
};

Expand Down
23 changes: 16 additions & 7 deletions packages/p2p/src/stores/general-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class GeneralStore extends BaseStore {
@observable review_period;
@observable should_show_real_name = false;
@observable should_show_popup = false;
@observable user_blocked_count = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the block user count from my profile to general store since it already contains the subscription to p2p_advertiser_info, thus any updates to block user count is set to here

@observable user_blocked_until = null;
@observable is_high_risk_fully_authed_without_fa = false;
@observable is_modal_open = false;
Expand Down Expand Up @@ -592,6 +593,11 @@ export default class GeneralStore extends BaseStore {
this.should_show_popup = should_show_popup;
}

@action.bound
setUserBlockedCount(user_blocked_count) {
this.user_blocked_count = user_blocked_count;
}

@action.bound
setUserBlockedUntil(user_blocked_until) {
this.user_blocked_until = user_blocked_until;
Expand All @@ -610,14 +616,17 @@ export default class GeneralStore extends BaseStore {

@action.bound
updateAdvertiserInfo(response) {
const { p2p_advertiser_info } = response;
const { blocked_until, blocked_by_count, id, is_approved, is_blocked, is_listed, name } =
response?.p2p_advertiser_info || {};

if (!response.error) {
this.setAdvertiserId(p2p_advertiser_info.id);
this.setIsAdvertiser(!!p2p_advertiser_info.is_approved);
this.setIsAdvertiserBlocked(!!p2p_advertiser_info.is_blocked);
this.setIsListed(!!p2p_advertiser_info.is_listed);
this.setNickname(p2p_advertiser_info.name);
this.setUserBlockedUntil(p2p_advertiser_info.blocked_until);
this.setAdvertiserId(id);
this.setIsAdvertiser(!!is_approved);
this.setIsAdvertiserBlocked(!!is_blocked);
this.setIsListed(!!is_listed);
this.setNickname(name);
this.setUserBlockedUntil(blocked_until);
this.setUserBlockedCount(blocked_by_count);
} else {
this.ws_subscriptions.advertiser_subscription.unsubscribe();
if (response.error.code === 'RestrictedCountry') {
Expand Down