From 6513b96d40ab2b5559a490336dc968ecda8f3b23 Mon Sep 17 00:00:00 2001 From: nada-deriv Date: Thu, 2 Mar 2023 09:15:40 +0400 Subject: [PATCH 1/8] fix: get chat url from p2p_order_create instead of p2p_chat_create --- packages/p2p/src/components/order-details/order-details.jsx | 1 + packages/p2p/src/stores/buy-sell-store.js | 3 +++ packages/p2p/src/stores/sendbird-store.js | 1 + 3 files changed, 5 insertions(+) diff --git a/packages/p2p/src/components/order-details/order-details.jsx b/packages/p2p/src/components/order-details/order-details.jsx index 2da26a6aa716..9e2ef721b8eb 100644 --- a/packages/p2p/src/components/order-details/order-details.jsx +++ b/packages/p2p/src/components/order-details/order-details.jsx @@ -85,6 +85,7 @@ const OrderDetails = observer(() => { order_store.setIsRecommended(undefined); my_profile_store.getPaymentMethodsList(); + // TODO: remove condition check once access chat_channel_url from p2p_order_create is activated in BO if (order_channel_url) { sendbird_store.setChatChannelUrl(order_channel_url); } else { diff --git a/packages/p2p/src/stores/buy-sell-store.js b/packages/p2p/src/stores/buy-sell-store.js index 71bf4a279293..d86959a4f539 100644 --- a/packages/p2p/src/stores/buy-sell-store.js +++ b/packages/p2p/src/stores/buy-sell-store.js @@ -261,6 +261,7 @@ export default class BuySellStore extends BaseStore { } handleSubmit = async (isMountedFn, values, { setSubmitting }) => { + const { sendbird_store } = this.root_store; if (isMountedFn()) { setSubmitting(true); } @@ -272,6 +273,7 @@ export default class BuySellStore extends BaseStore { advert_id: this.advert.id, amount: values.amount, payment_method_ids: this.payment_method_ids, + subscribe: 1, ...(values.payment_info && this.is_sell_advert ? { payment_info: values.payment_info } : {}), // Validate extra information for sell adverts. ...(this.is_sell_advert @@ -293,6 +295,7 @@ export default class BuySellStore extends BaseStore { this.form_props.setErrorMessage(null); this.root_store.general_store.hideModal(); this.root_store.floating_rate_store.setIsMarketRateChanged(false); + sendbird_store.setChatChannelUrl(order?.p2p_order_create?.chat_channel_url ?? ''); const response = await requestWS({ p2p_order_info: 1, id: order.p2p_order_create.id }); this.form_props.handleConfirm(response.p2p_order_info); this.form_props.handleClose(); diff --git a/packages/p2p/src/stores/sendbird-store.js b/packages/p2p/src/stores/sendbird-store.js index d5e7f80a25b7..450c720f88cd 100644 --- a/packages/p2p/src/stores/sendbird-store.js +++ b/packages/p2p/src/stores/sendbird-store.js @@ -71,6 +71,7 @@ export default class SendbirdStore extends BaseStore { this.chat_messages.push(chat_message); } + // TODO: remove when access chat_channel_url from p2p_order_create is activated in BO createChatForNewOrder(id) { if (!this.chat_channel_url) { // If order_information doesn't have chat_channel_url this is a new order From 2c93f30762628146c2693ba09a4eb53e9b7a1353 Mon Sep 17 00:00:00 2001 From: nada-deriv Date: Mon, 6 Mar 2023 09:03:29 +0400 Subject: [PATCH 2/8] fix: fixed issue with order details page --- .../order-details/order-details.jsx | 3 +- packages/p2p/src/stores/buy-sell-store.js | 48 ++++++++++++------- packages/p2p/src/stores/order-store.js | 4 ++ 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/packages/p2p/src/components/order-details/order-details.jsx b/packages/p2p/src/components/order-details/order-details.jsx index 9e2ef721b8eb..900831cb9920 100644 --- a/packages/p2p/src/components/order-details/order-details.jsx +++ b/packages/p2p/src/components/order-details/order-details.jsx @@ -23,7 +23,7 @@ import { useModalManagerContext } from 'Components/modal-manager/modal-manager-c import 'Components/order-details/order-details.scss'; const OrderDetails = observer(() => { - const { general_store, my_profile_store, order_store, sendbird_store } = useStores(); + const { general_store, my_profile_store, order_store, sendbird_store, buy_sell_store } = useStores(); const { hideModal, showModal, useRegisterModalProps } = useModalManagerContext(); const { @@ -103,6 +103,7 @@ const OrderDetails = observer(() => { redirectToOrderDetails: general_store.redirectToOrderDetails, setIsRatingModalOpen: is_open => (is_open ? showRatingModal : hideModal), }); + buy_sell_store.unsubscribeCreateOrder(); }; }, []); // eslint-disable-line react-hooks/exhaustive-deps diff --git a/packages/p2p/src/stores/buy-sell-store.js b/packages/p2p/src/stores/buy-sell-store.js index d86959a4f539..669a83d4ea5b 100644 --- a/packages/p2p/src/stores/buy-sell-store.js +++ b/packages/p2p/src/stores/buy-sell-store.js @@ -4,7 +4,7 @@ import { formatMoney, getDecimalPlaces, isMobile } from '@deriv/shared'; import { Text } from '@deriv/components'; import { localize } from 'Components/i18next'; import { buy_sell } from 'Constants/buy-sell'; -import { requestWS } from 'Utils/websocket'; +import { requestWS , subscribeWS } from 'Utils/websocket'; import { textValidator, lengthValidator } from 'Utils/validations'; import { countDecimalPlaces } from 'Utils/string'; import { removeTrailingZeros } from 'Utils/format-value'; @@ -141,9 +141,12 @@ export default class BuySellStore extends BaseStore { validatePopup: action.bound, sort_list: computed, fetchAdvertiserAdverts: action.bound, + handleResponse: action.bound, }); } + create_order_subscription = {}; + get account_currency() { return this.advert?.account_currency; } @@ -260,8 +263,26 @@ export default class BuySellStore extends BaseStore { this.setIsSortDropdownOpen(false); } - handleSubmit = async (isMountedFn, values, { setSubmitting }) => { + handleResponse = async order => { const { sendbird_store } = this.root_store; + if (order.error) { + this.form_props.setErrorMessage(order.error.message); + this.setFormErrorCode(order.error.code); + } else { + this.form_props.setErrorMessage(null); + this.root_store.general_store.hideModal(); + this.root_store.floating_rate_store.setIsMarketRateChanged(false); + sendbird_store.setChatChannelUrl(order?.p2p_order_create?.chat_channel_url ?? ''); + if (order?.p2p_order_create?.id) { + const response = await requestWS({ p2p_order_info: 1, id: order?.p2p_order_create?.id }); + this.form_props.handleConfirm(response?.p2p_order_info); + } + this.form_props.handleClose(); + this.payment_method_ids = []; + } + }; + + handleSubmit = async (isMountedFn, values, { setSubmitting }) => { if (isMountedFn()) { setSubmitting(true); } @@ -273,7 +294,6 @@ export default class BuySellStore extends BaseStore { advert_id: this.advert.id, amount: values.amount, payment_method_ids: this.payment_method_ids, - subscribe: 1, ...(values.payment_info && this.is_sell_advert ? { payment_info: values.payment_info } : {}), // Validate extra information for sell adverts. ...(this.is_sell_advert @@ -286,21 +306,7 @@ export default class BuySellStore extends BaseStore { payload.rate = values.rate; } - const order = await requestWS({ ...payload }); - - if (order.error) { - this.form_props.setErrorMessage(order.error.message); - this.setFormErrorCode(order.error.code); - } else { - this.form_props.setErrorMessage(null); - this.root_store.general_store.hideModal(); - this.root_store.floating_rate_store.setIsMarketRateChanged(false); - sendbird_store.setChatChannelUrl(order?.p2p_order_create?.chat_channel_url ?? ''); - const response = await requestWS({ p2p_order_info: 1, id: order.p2p_order_create.id }); - this.form_props.handleConfirm(response.p2p_order_info); - this.form_props.handleClose(); - this.payment_method_ids = []; - } + this.create_order_subscription = subscribeWS({ ...payload }, [this.handleResponse]); if (isMountedFn()) { setSubmitting(false); @@ -723,4 +729,10 @@ export default class BuySellStore extends BaseStore { return () => disposeAdvertIntervalReaction(); } + + unsubscribeCreateOrder = () => { + if (this.create_order_subscription.unsubscribe) { + this.create_order_subscription.unsubscribe(); + } + }; } diff --git a/packages/p2p/src/stores/order-store.js b/packages/p2p/src/stores/order-store.js index 71b9a8ae6792..629dd590740b 100644 --- a/packages/p2p/src/stores/order-store.js +++ b/packages/p2p/src/stores/order-store.js @@ -277,8 +277,12 @@ export default class OrderStore { } onOrderIdUpdate() { + const { buy_sell_store } = this.root_store; this.unsubscribeFromCurrentOrder(); + if (buy_sell_store.create_order_subscription.unsubscribe) { + buy_sell_store.create_order_subscription.unsubscribe(); + } if (this.order_id) { this.subscribeToCurrentOrder(); } From a8ef7aeed8fe6150bfe34d3d4407d48aedd04dc2 Mon Sep 17 00:00:00 2001 From: nada-deriv Date: Tue, 7 Mar 2023 09:13:54 +0400 Subject: [PATCH 3/8] fix: chat channel url empty issue fixed for p2p_order_create response --- .../components/order-details/order-details.jsx | 1 + packages/p2p/src/stores/buy-sell-store.js | 18 ++++++++++++++++-- packages/p2p/src/stores/order-store.js | 7 +++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/p2p/src/components/order-details/order-details.jsx b/packages/p2p/src/components/order-details/order-details.jsx index 900831cb9920..4acf2d13cb85 100644 --- a/packages/p2p/src/components/order-details/order-details.jsx +++ b/packages/p2p/src/components/order-details/order-details.jsx @@ -103,6 +103,7 @@ const OrderDetails = observer(() => { redirectToOrderDetails: general_store.redirectToOrderDetails, setIsRatingModalOpen: is_open => (is_open ? showRatingModal : hideModal), }); + buy_sell_store.setIsCreateOrderSubscribed(false); buy_sell_store.unsubscribeCreateOrder(); }; }, []); // eslint-disable-line react-hooks/exhaustive-deps diff --git a/packages/p2p/src/stores/buy-sell-store.js b/packages/p2p/src/stores/buy-sell-store.js index 669a83d4ea5b..9092b9d5496c 100644 --- a/packages/p2p/src/stores/buy-sell-store.js +++ b/packages/p2p/src/stores/buy-sell-store.js @@ -4,7 +4,7 @@ import { formatMoney, getDecimalPlaces, isMobile } from '@deriv/shared'; import { Text } from '@deriv/components'; import { localize } from 'Components/i18next'; import { buy_sell } from 'Constants/buy-sell'; -import { requestWS , subscribeWS } from 'Utils/websocket'; +import { requestWS, subscribeWS } from 'Utils/websocket'; import { textValidator, lengthValidator } from 'Utils/validations'; import { countDecimalPlaces } from 'Utils/string'; import { removeTrailingZeros } from 'Utils/format-value'; @@ -41,6 +41,7 @@ export default class BuySellStore extends BaseStore { submitForm = () => {}; table_type = buy_sell.BUY; form_props = {}; + is_create_order_subscribed = false; initial_values = { amount: this.advert?.min_order_amount_limit, @@ -84,6 +85,7 @@ export default class BuySellStore extends BaseStore { submitForm: observable, table_type: observable, form_props: observable, + is_create_order_subscribed: observable, account_currency: computed, advert: computed, has_payment_info: computed, @@ -264,11 +266,14 @@ export default class BuySellStore extends BaseStore { } handleResponse = async order => { - const { sendbird_store } = this.root_store; + const { sendbird_store, order_store } = this.root_store; if (order.error) { this.form_props.setErrorMessage(order.error.message); this.setFormErrorCode(order.error.code); } else { + if (order?.subscription?.id && !this.is_create_order_subscribed) { + this.setIsCreateOrderSubscribed(true); + } this.form_props.setErrorMessage(null); this.root_store.general_store.hideModal(); this.root_store.floating_rate_store.setIsMarketRateChanged(false); @@ -280,6 +285,11 @@ export default class BuySellStore extends BaseStore { this.form_props.handleClose(); this.payment_method_ids = []; } + if (order?.p2p_order_info?.id && order?.p2p_order_info?.chat_channel_url) { + sendbird_store.setChatChannelUrl(order?.p2p_order_info?.chat_channel_url ?? ''); + order_store.setOrderDetails(order); + this.create_order_subscription.unsubscribe(); + } }; handleSubmit = async (isMountedFn, values, { setSubmitting }) => { @@ -611,6 +621,10 @@ export default class BuySellStore extends BaseStore { this.submitForm = submitFormFn; } + setIsCreateOrderSubscribed(is_create_order_subscribed) { + this.is_create_order_subscribed = is_create_order_subscribed; + } + showAdvertiserPage(selected_advert) { this.setSelectedAdState(selected_advert); this.setShowAdvertiserPage(true); diff --git a/packages/p2p/src/stores/order-store.js b/packages/p2p/src/stores/order-store.js index 629dd590740b..064e5c28185d 100644 --- a/packages/p2p/src/stores/order-store.js +++ b/packages/p2p/src/stores/order-store.js @@ -280,11 +280,10 @@ export default class OrderStore { const { buy_sell_store } = this.root_store; this.unsubscribeFromCurrentOrder(); - if (buy_sell_store.create_order_subscription.unsubscribe) { - buy_sell_store.create_order_subscription.unsubscribe(); - } if (this.order_id) { - this.subscribeToCurrentOrder(); + if (!buy_sell_store.is_create_order_subscribed) { + this.subscribeToCurrentOrder(); + } } } From 6e6e640de6288cd94e597865695327761a269e3f Mon Sep 17 00:00:00 2001 From: nada-deriv Date: Tue, 7 Mar 2023 09:16:28 +0400 Subject: [PATCH 4/8] fix: function added to store --- packages/p2p/src/stores/buy-sell-store.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/p2p/src/stores/buy-sell-store.js b/packages/p2p/src/stores/buy-sell-store.js index 9092b9d5496c..b7024d9e8e22 100644 --- a/packages/p2p/src/stores/buy-sell-store.js +++ b/packages/p2p/src/stores/buy-sell-store.js @@ -144,6 +144,7 @@ export default class BuySellStore extends BaseStore { sort_list: computed, fetchAdvertiserAdverts: action.bound, handleResponse: action.bound, + setIsCreateOrderSubscribed: action.bound, }); } From 8246dbc869af962208e435f0c930522811761388 Mon Sep 17 00:00:00 2001 From: nada-deriv Date: Tue, 7 Mar 2023 10:23:15 +0400 Subject: [PATCH 5/8] fix: added timeout for setting chat_channel in order details --- .../src/components/order-details/order-details.jsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/p2p/src/components/order-details/order-details.jsx b/packages/p2p/src/components/order-details/order-details.jsx index 4acf2d13cb85..d399f77cf0be 100644 --- a/packages/p2p/src/components/order-details/order-details.jsx +++ b/packages/p2p/src/components/order-details/order-details.jsx @@ -85,12 +85,14 @@ const OrderDetails = observer(() => { order_store.setIsRecommended(undefined); my_profile_store.getPaymentMethodsList(); - // TODO: remove condition check once access chat_channel_url from p2p_order_create is activated in BO - if (order_channel_url) { - sendbird_store.setChatChannelUrl(order_channel_url); - } else { - sendbird_store.createChatForNewOrder(order_store.order_id); - } + // TODO: remove condition check and settimeout once access chat_channel_url from p2p_order_create is activated in BO, since chat channel url response is always delayed + setTimeout(() => { + if (order_channel_url) { + sendbird_store.setChatChannelUrl(order_channel_url); + } else { + sendbird_store.createChatForNewOrder(order_store.order_id); + } + }, 1000); return () => { disposeListeners(); From cfcac46636f812dcd7f42c5c88808b2bf7cd62cf Mon Sep 17 00:00:00 2001 From: nada-deriv Date: Tue, 7 Mar 2023 12:42:56 +0400 Subject: [PATCH 6/8] fix: pr comments fixed --- packages/p2p/src/stores/buy-sell-store.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/p2p/src/stores/buy-sell-store.js b/packages/p2p/src/stores/buy-sell-store.js index b7024d9e8e22..a4e15bfb145a 100644 --- a/packages/p2p/src/stores/buy-sell-store.js +++ b/packages/p2p/src/stores/buy-sell-store.js @@ -267,23 +267,24 @@ export default class BuySellStore extends BaseStore { } handleResponse = async order => { - const { sendbird_store, order_store } = this.root_store; + const { sendbird_store, order_store, general_store, floating_rate_store } = this.root_store; + const { setErrorMessage, handleConfirm, handleClose } = this.form_props; if (order.error) { - this.form_props.setErrorMessage(order.error.message); + setErrorMessage(order.error.message); this.setFormErrorCode(order.error.code); } else { if (order?.subscription?.id && !this.is_create_order_subscribed) { this.setIsCreateOrderSubscribed(true); } - this.form_props.setErrorMessage(null); - this.root_store.general_store.hideModal(); - this.root_store.floating_rate_store.setIsMarketRateChanged(false); + setErrorMessage(null); + general_store.hideModal(); + floating_rate_store.setIsMarketRateChanged(false); sendbird_store.setChatChannelUrl(order?.p2p_order_create?.chat_channel_url ?? ''); if (order?.p2p_order_create?.id) { const response = await requestWS({ p2p_order_info: 1, id: order?.p2p_order_create?.id }); - this.form_props.handleConfirm(response?.p2p_order_info); + handleConfirm(response?.p2p_order_info); } - this.form_props.handleClose(); + handleClose(); this.payment_method_ids = []; } if (order?.p2p_order_info?.id && order?.p2p_order_info?.chat_channel_url) { From 021036a7e6e901a0e6a94331de217abcefef6f1b Mon Sep 17 00:00:00 2001 From: nada-deriv Date: Thu, 9 Mar 2023 18:27:25 +0400 Subject: [PATCH 7/8] fix: increased time out --- packages/p2p/src/components/order-details/order-details.jsx | 2 +- packages/p2p/src/stores/buy-sell-store.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/p2p/src/components/order-details/order-details.jsx b/packages/p2p/src/components/order-details/order-details.jsx index d399f77cf0be..145a04be90f4 100644 --- a/packages/p2p/src/components/order-details/order-details.jsx +++ b/packages/p2p/src/components/order-details/order-details.jsx @@ -92,7 +92,7 @@ const OrderDetails = observer(() => { } else { sendbird_store.createChatForNewOrder(order_store.order_id); } - }, 1000); + }, 1250); return () => { disposeListeners(); diff --git a/packages/p2p/src/stores/buy-sell-store.js b/packages/p2p/src/stores/buy-sell-store.js index a4e15bfb145a..0c34727d1872 100644 --- a/packages/p2p/src/stores/buy-sell-store.js +++ b/packages/p2p/src/stores/buy-sell-store.js @@ -290,7 +290,6 @@ export default class BuySellStore extends BaseStore { if (order?.p2p_order_info?.id && order?.p2p_order_info?.chat_channel_url) { sendbird_store.setChatChannelUrl(order?.p2p_order_info?.chat_channel_url ?? ''); order_store.setOrderDetails(order); - this.create_order_subscription.unsubscribe(); } }; From 991bd134fba32ff0543e2b7d6461273397e1220f Mon Sep 17 00:00:00 2001 From: nada-deriv Date: Tue, 14 Mar 2023 17:13:19 +0400 Subject: [PATCH 8/8] fix: removed delay for going to details page from list --- .../components/order-details/order-details.jsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/p2p/src/components/order-details/order-details.jsx b/packages/p2p/src/components/order-details/order-details.jsx index 145a04be90f4..5174003142f3 100644 --- a/packages/p2p/src/components/order-details/order-details.jsx +++ b/packages/p2p/src/components/order-details/order-details.jsx @@ -85,14 +85,23 @@ const OrderDetails = observer(() => { order_store.setIsRecommended(undefined); my_profile_store.getPaymentMethodsList(); - // TODO: remove condition check and settimeout once access chat_channel_url from p2p_order_create is activated in BO, since chat channel url response is always delayed - setTimeout(() => { + const handleChatChannelCreation = () => { if (order_channel_url) { sendbird_store.setChatChannelUrl(order_channel_url); } else { sendbird_store.createChatForNewOrder(order_store.order_id); } - }, 1250); + }; + + // TODO: remove condition check and settimeout once access chat_channel_url from p2p_order_create is activated in BO, since chat channel url response is always delayed + // Added delay only for first time order creation, since response is delayed. To be removed after feature release. + if (buy_sell_store.is_create_order_subscribed) { + setTimeout(() => { + handleChatChannelCreation(); + }, 1250); + } else { + handleChatChannelCreation(); + } return () => { disposeListeners();