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

likhith/OrderConfirmCompleted error status displayed on slow n/w #4832

Merged
merged 16 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from 14 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
5 changes: 0 additions & 5 deletions packages/p2p/src/components/app-content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import MyProfile from './my-profile';
import NicknameForm from './nickname-form';
import Orders from './orders/orders.jsx';
import TemporarilyBarredHint from './temporarily-barred-hint';
import UnsupportedAccount from './unsupported-account';
import Verification from './verification/verification.jsx';

const AppContent = () => {
Expand All @@ -21,10 +20,6 @@ const AppContent = () => {
return <Loading is_fullscreen={false} />;
}

if (general_store.is_unsupported_account) {
return <UnsupportedAccount />;
}

if (general_store.should_show_dp2p_blocked) {
return <Dp2pBlocked />;
}
Expand Down
1 change: 0 additions & 1 deletion packages/p2p/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const App = props => {

waitWS('authorize').then(() => {
general_store.onMount();

if (localStorage.getItem('is_verifying_p2p')) {
localStorage.removeItem('is_verifying_p2p');
general_store.setActiveIndex(general_store.path.my_ads);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Button, Checkbox, Modal, Text } from '@deriv/components';
import { Button, Checkbox, Loading, Modal, Text } from '@deriv/components';
import { useIsMounted } from '@deriv/shared';
import { Localize } from 'Components/i18next';
import { requestWS } from 'Utils/websocket';
Expand All @@ -27,18 +27,39 @@ const OrderDetailsConfirmModal = ({
const isMounted = useIsMounted();
const [error_message, setErrorMessage] = React.useState('');
const [is_checkbox_checked, setIsCheckboxChecked] = React.useState(false);
const [is_process_request, setIsProcessRequest] = React.useState(false); // This state disables the Release amount button during a request

const confirmOrderRequest = () => {
setIsProcessRequest(true);
requestWS({
p2p_order_confirm: 1,
id,
}).then(response => {
if (isMounted()) {
if (response.error) {
setErrorMessage(response.error.message);
})
.then(response => {
Comment on lines +37 to +38
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the code formatted?
Please use prettier to format the code.

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 am using prettier. For some reason, thats how the code is refactored

Copy link
Contributor

Choose a reason for hiding this comment

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

@likhith-deriv have you run npm run prettify?😊

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 I have. But in this file, line 38, still seems to be kept in that way. If I remove the spaces and move it up, on save it reverts back :(

Copy link
Contributor

Choose a reason for hiding this comment

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

@likhith-deriv as long as you run npm run prettify, it should be fine ) it's alright then

if (isMounted()) {
if (response.error) {
setErrorMessage(response.error.message);
}
}
}
});
})
.finally(() => setIsProcessRequest(false));
};

const getConfirmButtonText = () => {
if (is_buy_order_for_user) {
return <Localize i18n_default_text="I've paid" />;
} else if (is_process_request) {
return <Loading is_fullscreen={false} />;
}
return (
<Localize
i18n_default_text='Release {{amount}} {{currency}}'
values={{
amount: amount_display,
currency: account_currency,
}}
/>
);
};

return (
Expand Down Expand Up @@ -109,18 +130,13 @@ const OrderDetailsConfirmModal = ({
<Localize i18n_default_text='Cancel' />
)}
</Button>
<Button is_disabled={!is_checkbox_checked} primary large onClick={confirmOrderRequest}>
{is_buy_order_for_user ? (
<Localize i18n_default_text="I've paid" />
) : (
<Localize
i18n_default_text='Release {{amount}} {{currency}}'
values={{
amount: amount_display,
currency: account_currency,
}}
/>
)}
<Button
is_disabled={!is_checkbox_checked || is_process_request}
primary
large
onClick={confirmOrderRequest}
>
{getConfirmButtonText()}
</Button>
</Button.Group>
</Modal.Footer>
Expand Down
4 changes: 0 additions & 4 deletions packages/p2p/src/components/unsupported-account/index.js

This file was deleted.

This file was deleted.

This file was deleted.

14 changes: 8 additions & 6 deletions packages/p2p/src/stores/buy-sell-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export default class BuySellStore extends BaseStore {
requestWS({
p2p_advertiser_info: 1,
}).then(response => {
if (!response.error) {
// Added a check to prevent console errors
if (response && !response.error) {
const { p2p_advertiser_info } = response;
this.setContactInfo(p2p_advertiser_info.contact_info);
this.setPaymentInfo(p2p_advertiser_info.payment_info);
Expand Down Expand Up @@ -194,7 +195,6 @@ export default class BuySellStore extends BaseStore {
const { general_store } = this.root_store;
const counterparty_type = this.is_buy ? buy_sell.BUY : buy_sell.SELL;
this.setApiErrorMessage('');

return new Promise(resolve => {
requestWS({
p2p_advert_list: 1,
Expand All @@ -205,7 +205,7 @@ export default class BuySellStore extends BaseStore {
use_client_limits: this.should_use_client_limits ? 1 : 0,
...(this.filter_payment_methods.length > 0 ? { payment_method: this.filter_payment_methods } : {}),
}).then(response => {
if (!response.error) {
if (response && !response.error) {
// Ignore any responses that don't match our request. This can happen
// due to quickly switching between Buy/Sell tabs.
if (response.echo_req.counterparty_type === counterparty_type) {
Expand Down Expand Up @@ -248,10 +248,11 @@ export default class BuySellStore extends BaseStore {
this.setSearchResults([]);
}
}
} else if (response.error.code === 'PermissionDenied') {
// Added a check to prevent console errors
} else if (response && response.error.code === 'PermissionDenied') {
this.root_store.general_store.setIsBlocked(true);
} else {
this.setApiErrorMessage(response.error.message);
this.setApiErrorMessage(response?.error.message);
}

this.setIsLoading(false);
Expand Down Expand Up @@ -552,7 +553,8 @@ export default class BuySellStore extends BaseStore {
const updateAdvert = () => {
requestWS({ p2p_advert_info: 1, id: this.selected_ad_state.id, use_client_limits: 1 }).then(
response => {
if (response.error) return;
// Added a check to prevent console errors
if (response && response.error) return;
const { p2p_advert_info } = response;

if (this.selected_ad_state?.id === p2p_advert_info.id) {
Expand Down
6 changes: 0 additions & 6 deletions packages/p2p/src/stores/general-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ export default class GeneralStore extends BaseStore {
return this.is_advertiser && !this.root_store.my_profile_store.should_hide_my_profile_tab;
}

@computed
get is_unsupported_account() {
const allowed_currency = 'USD';
return this.client?.is_virtual || this.client?.currency !== allowed_currency;
}

@computed
get should_show_dp2p_blocked() {
return this.is_blocked || this.is_high_risk_fully_authed_without_fa;
Expand Down
4 changes: 4 additions & 0 deletions packages/p2p/src/utils/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const populateInitialResponses = async () => {
};

export const requestWS = async request => {
// Added a check to proceed only if ws is available
if (ws === undefined) {
return null;
}
await populateInitialResponses();
return ws.send(request);
};
Expand Down