Skip to content

Commit

Permalink
chore: merge conflicts with master
Browse files Browse the repository at this point in the history
  • Loading branch information
nada-deriv committed Apr 26, 2024
2 parents 1f0961b + 02772b7 commit 6684c63
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Button } from '@deriv-com/ui';
import { LocalStorageConstants, LocalStorageUtils, URLUtils } from '@deriv-com/utils';
import './Header.scss';

// TODO: handle local storage values not updating after changing local storage values
const Header = () => {
const { activeLoginid, logout } = useAuthData();
const appId = LocalStorageUtils.getValue(LocalStorageConstants.configAppId);
Expand Down
8 changes: 2 additions & 6 deletions src/hooks/api/advertiser/p2p-advertiser/useAdvertiserInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect } from 'react';
import { useEffect } from 'react';
import { DeepPartial } from 'react-hook-form';
import { useLocalStorage } from 'usehooks-ts';
import { useP2PAdvertiserInfo } from '@deriv-com/api-hooks';
Expand All @@ -18,14 +18,10 @@ type TP2PAdvertiserInfo = ReturnType<typeof useP2PAdvertiserInfo>['data'] & {
const useAdvertiserInfo = (id?: string) => {
const { data, subscribe, error, ...rest } = useP2PAdvertiserInfo() ?? {};

const callback = useCallback(() => {
useEffect(() => {
subscribe({});
}, [subscribe]);

useEffect(() => {
callback();
}, [callback]);

/**
* Use different local storage key for each advertiser, one to keep the current user's info, the other to keep the advertiser's info
* This is to prevent the current user's info from being overwritten by the advertiser's info when the current user views the advertiser's profile.
Expand Down
1 change: 1 addition & 0 deletions src/pages/endpoint/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './screens';
15 changes: 15 additions & 0 deletions src/pages/endpoint/screens/Endpoint/Endpoint.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.endpoint {
position: absolute;
top: 8rem;
background: #fff;
width: 100%;
height: 60%;
display: flex;
align-items: center;
justify-content: center;

@include mobile {
height: unset;
padding-top: 2rem;
}
}
81 changes: 81 additions & 0 deletions src/pages/endpoint/screens/Endpoint/Endpoint.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Controller, useForm } from 'react-hook-form';
import { Button, Input, Text } from '@deriv-com/ui';
import { LocalStorageConstants, LocalStorageUtils } from '@deriv-com/utils';
import './Endpoint.scss';

const Endpoint = () => {
const {
control,
formState: { isDirty, isValid },
getValues,
handleSubmit,
reset,
} = useForm({
defaultValues: {
serverUrl: localStorage.getItem(LocalStorageConstants.configServerURL.toString()) || '',
appId: LocalStorageUtils.getValue(LocalStorageConstants.configAppId) || '',
},
mode: 'onChange',
});

return (
<div className='endpoint flex flex-col gap-8'>
<Text weight='bold'>Change API endpoint</Text>
<form className='flex flex-col' action=''>
<Controller
control={control}
name='serverUrl'
render={({ field: { onBlur, onChange, value }, fieldState: { error } }) => (
<Input
label='Server'
message={error?.message}
onBlur={onBlur}
onChange={onChange}
value={value}
/>
)}
rules={{
required: 'This field is required',
}}
/>
<Controller
control={control}
name='appId'
render={({ field: { onBlur, onChange, value }, fieldState: { error } }) => (
<Input
label='OAuth App ID'
message={error?.message}
onBlur={onBlur}
onChange={onChange}
value={value}
/>
)}
rules={{
required: 'This field is required',
pattern: {
message: 'Please enter a valid app ID',
value: /^(0|[1-9]\d*)(\.\d+)?$/,
},
}}
/>
<Button
className='w-40'
disabled={!isDirty || !isValid}
onClick={handleSubmit(() => {
// Can't use LocalStorageUtils.setValue because it will place "" around the value
localStorage.setItem(LocalStorageConstants.configServerURL, getValues('serverUrl'));
localStorage.setItem(LocalStorageConstants.configAppId, getValues('appId'));
reset({
serverUrl: getValues('serverUrl'),
appId: getValues('appId'),
});
})}
>
Submit
</Button>
</form>
</div>
);
};

export default Endpoint;
1 change: 1 addition & 0 deletions src/pages/endpoint/screens/Endpoint/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Endpoint } from './Endpoint';
1 change: 1 addition & 0 deletions src/pages/endpoint/screens/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Endpoint';
11 changes: 8 additions & 3 deletions src/routes/AppContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { useHistory, useLocation } from 'react-router-dom';
import { BUY_SELL_URL } from '@/constants';
import { api } from '@/hooks';
import { AdvertiserInfoStateProvider } from '@/providers/AdvertiserInfoStateProvider';
import { getCurrentRoute } from '@/utils';
import { useAuthorize } from '@deriv-com/api-hooks';
import { Loader, Tab, Tabs } from '@deriv-com/ui';
import Router from '../Router';
import { routes } from '../routes-config';
import './index.scss';

const tabRoutesConfiguration = routes.filter(route => route.name !== 'Advertiser');
const tabRoutesConfiguration = routes.filter(route => route.name !== 'Advertiser' && route.name !== 'Endpoint');

const AppContent = () => {
const history = useHistory();
Expand All @@ -32,6 +33,7 @@ const AppContent = () => {
isActive: isSubscribed,
subscribe: subscribeAdvertiserInfo,
} = api.advertiser.useGetInfo();
const isEndpointRoute = getCurrentRoute() === 'endpoint';

useEffect(() => {
if (activeAccountData) {
Expand All @@ -57,10 +59,13 @@ const AppContent = () => {
setActiveTab(getActiveTab(location.pathname));
}, [location]);

if (isLoadingActiveAccount || !activeAccountData) return <Loader />;
if ((isLoadingActiveAccount || !activeAccountData) && !isEndpointRoute) {
return <Loader />;
}

// NOTE: Replace this with P2PBlocked component later and a custom hook useIsP2PEnabled, P2P is only available for USD accounts
if (activeAccountData?.currency !== 'USD') return <h1>P2P is only available for USD accounts.</h1>;
if (activeAccountData?.currency !== 'USD' && !isEndpointRoute)
return <h1>P2P is only available for USD accounts.</h1>;

return (
<AdvertiserInfoStateProvider
Expand Down
6 changes: 6 additions & 0 deletions src/routes/routes-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const CreateEditAd = lazy(() =>
);
const MyProfile = lazy(() => import('@/pages/my-profile').then(module => ({ default: module.MyProfile })));
const Advertiser = lazy(() => import('@/pages/advertiser').then(module => ({ default: module.Advertiser })));
const Endpoint = lazy(() => import('@/pages/endpoint').then(module => ({ default: module.Endpoint })));

export const routes = [
{
Expand Down Expand Up @@ -51,4 +52,9 @@ export const routes = [
name: 'Advertiser',
path: `${ADVERTISER_URL}/:advertiserId`,
},
{
component: Endpoint,
name: 'Endpoint',
path: '/endpoint',
},
];

0 comments on commit 6684c63

Please sign in to comment.