Skip to content

Commit

Permalink
Merge pull request binary-com#42 from farhan-nurzi-deriv/P2PS-1309/bl…
Browse files Browse the repository at this point in the history
…ock-banned-user-bug

FarhanNurzi/P2PS-1309/ block banned user bug
  • Loading branch information
farrah-deriv committed Jul 27, 2023
2 parents 2cd544d + ebc1394 commit ab9555d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
32 changes: 19 additions & 13 deletions packages/p2p/src/pages/advertiser-page/advertiser-page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import { useModalManagerContext } from 'Components/modal-manager/modal-manager-c
const AdvertiserPage = () => {
const { advertiser_page_store, buy_sell_store, general_store, my_profile_store } = useStores();
const { hideModal, showModal, useRegisterModalProps } = useModalManagerContext();
const { advertiser_details_name, advertiser_details_id, counterparty_advertiser_info } = advertiser_page_store;

const is_my_advert = advertiser_page_store.advertiser_details_id === general_store.advertiser_id;
const is_my_advert = advertiser_details_id === general_store.advertiser_id;
// Use general_store.advertiser_info since resubscribing to the same id from advertiser page returns error
const info = is_my_advert ? general_store.advertiser_info : advertiser_page_store.counterparty_advertiser_info;
const info = is_my_advert ? general_store.advertiser_info : counterparty_advertiser_info;

const history = useHistory();

Expand All @@ -48,11 +49,11 @@ const AdvertiserPage = () => {
sell_orders_count,
} = info;

const nickname = advertiser_page_store.advertiser_details_name ?? name;

const joined_since = daysSince(created_time);
const nickname = advertiser_details_name ?? name;
// 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 error_message = () => {
return !!advertiser_page_store.is_counterparty_advertiser_blocked && !is_my_advert
? localize("Unblocking wasn't possible as {{name}} is not using Deriv P2P anymore.", {
Expand All @@ -76,11 +77,20 @@ const AdvertiserPage = () => {
{ fireImmediately: true }
);

reaction(
return () => {
disposeCounterpartyAdvertiserIdReaction();
advertiser_page_store.onUnmount();
};

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

React.useEffect(() => {
const disposeBlockUnblockUserErrorReaction = reaction(
() => [advertiser_page_store.active_index, general_store.block_unblock_user_error],
() => {
advertiser_page_store.onTabChange();
if (general_store.block_unblock_user_error && buy_sell_store.show_advertiser_page) {
if (general_store.block_unblock_user_error) {
showModal({
key: 'ErrorModal',
props: {
Expand Down Expand Up @@ -108,19 +118,15 @@ const AdvertiserPage = () => {
width: isMobile() ? '90rem' : '40rem',
},
});
general_store.setBlockUnblockUserError(null);
}
},
{ fireImmediately: true }
);

return () => {
disposeCounterpartyAdvertiserIdReaction();
advertiser_page_store.onUnmount();
disposeBlockUnblockUserErrorReaction();
};

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

useRegisterModalProps({
key: 'BlockUserModal',
Expand Down
6 changes: 2 additions & 4 deletions packages/p2p/src/stores/advertiser-page-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,8 @@ export default class AdvertiserPageStore extends BaseStore {
}

onSubmit() {
this.root_store.general_store.blockUnblockUser(
!this.is_counterparty_advertiser_blocked,
this.advertiser_details_id
);
const current_advertiser_id = this.advertiser_details_id ?? this.counterparty_advertiser_info?.id;
this.root_store.general_store.blockUnblockUser(!this.is_counterparty_advertiser_blocked, current_advertiser_id);
if (this.is_counterparty_advertiser_blocked) this.getCounterpartyAdvertiserList(this.advertiser_details_id);
this.setIsDropdownMenuVisible(false);
}
Expand Down
1 change: 1 addition & 0 deletions packages/p2p/src/stores/general-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export default class GeneralStore extends BaseStore {
);
}
} else {
this.hideModal();
const { code, message } = response.error;
this.setErrorCode(code);
this.setBlockUnblockUserError(message);
Expand Down

0 comments on commit ab9555d

Please sign in to comment.