Skip to content

Commit

Permalink
Merge branch 'master' of github.com:binary-com/deriv-app into iphone-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-deriv committed Jun 10, 2024
2 parents cdc7826 + f6f87e2 commit bf7297e
Show file tree
Hide file tree
Showing 88 changed files with 733 additions and 674 deletions.
6 changes: 3 additions & 3 deletions .github/actions/analyze/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ runs:
script: |
core.setFailed('Size changes exceed the defined threshold. Check above logs for details.');
- name: Zip all report.json files
- name: Zip all treemaps and reports
shell: bash
run: |
zip -r analyse.zip packages/*/report.json
zip -r analyse.zip packages/*/{report.json,treemap.html}
- name: Upload analyse.zip for Master Branch
if: github.ref == 'refs/heads/master'
Expand All @@ -196,4 +196,4 @@ runs:
with:
name: analyse-${{ env.SANITIZED_REF_NAME }}
path: analyse.zip
retention-days: 5
retention-days: 5
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ playwright/.cache/
packages/*/stats.json
packages/*/report.json
packages/*/analyzed.html
packages/*/treemap.html
150 changes: 0 additions & 150 deletions analyze.html

This file was deleted.

2 changes: 1 addition & 1 deletion packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"scripts": {
"analyze:stats": "f () { NODE_OPTIONS='-r ts-node/register' webpack --progress --config \"./build/webpack.config.js\" --env base=$1 --profile --json=stats.json;}; f",
"analyze:build": "webpack-bundle-analyzer --no-open -m static -r analyzed.html stats.json ./dist && webpack-bundle-analyzer -m json stats.json ./dist",
"analyze:build": "webpack-bundle-analyzer --no-open -m static -r treemap.html stats.json ./dist && webpack-bundle-analyzer -m json stats.json ./dist",
"start": "npm run test && npm run serve",
"serve": "echo \"Serving...\" && NODE_OPTIONS='-r ts-node/register' webpack --progress --watch --config \"./build/webpack.config.js\"",
"build": "f () { NODE_OPTIONS='-r ts-node/register' webpack --config \"./build/webpack.config.js\" --env base=$1;}; f",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ const ResetTradingPassword = ({
/>
</Text>
<Text as='p' size='xs' className='reset-trading-password__details'>
{localize('You can use this password for all your Deriv MT5 accounts.')}
<Localize
i18n_default_text='You can use this password for all your {{platform}} accounts.'
values={{
platform: getCFDPlatformLabel(platform),
}}
/>
</Text>
<fieldset className='reset-trading-password__input-field'>
<PasswordMeter
Expand Down
12 changes: 3 additions & 9 deletions packages/account/src/Containers/reset-trading-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ import { TPlatforms } from '../Types';

const ResetTradingPassword = observer(() => {
const { ui, client } = useStore();
const {
enableApp,
disableApp,
is_reset_trading_password_modal_visible,
is_loading,
setResetTradingPasswordModalOpen,
} = ui;
const { enableApp, disableApp, is_loading, setCFDPasswordResetModal, is_cfd_reset_password_modal_enabled } = ui;
const location = useLocation();
const platform = React.useRef('');
const query_params = new URLSearchParams(location.search);
Expand All @@ -35,8 +29,8 @@ const ResetTradingPassword = observer(() => {
platform={platform.current as TPlatforms}
enableApp={enableApp}
disableApp={disableApp}
toggleResetTradingPasswordModal={setResetTradingPasswordModalOpen}
is_visible={is_reset_trading_password_modal_visible}
toggleResetTradingPasswordModal={setCFDPasswordResetModal}
is_visible={is_cfd_reset_password_modal_enabled}
is_loading={is_loading}
verification_code={verification_code}
/>
Expand Down
58 changes: 53 additions & 5 deletions packages/api-v2/src/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useAPIContext } from './APIProvider';

import { getAccountsFromLocalStorage, getActiveLoginIDFromLocalStorage, getToken } from '@deriv/utils';
import useMutation from './useMutation';
import { TSocketResponseData } from '../types';
import { TSocketSubscribableEndpointNames, TSocketResponseData, TSocketRequestPayload } from '../types';
import useAPI from './useAPI';

// Define the type for the context state
type AuthContextType = {
Expand All @@ -19,6 +20,17 @@ type AuthContextType = {
error: unknown;
isSwitching: boolean;
isInitializing: boolean;
subscribe: <T extends TSocketSubscribableEndpointNames>(
name: T,
payload?: TSocketRequestPayload<T>
) =>
| {
subscribe: (
onData: (response: any) => void,
onError: (response: any) => void
) => { unsubscribe?: VoidFunction };
}
| undefined;
};

type LoginToken = {
Expand Down Expand Up @@ -97,17 +109,43 @@ const AuthProvider = ({ loginIDKey, children, cookieTimeout, selectDefaultAccoun

const { mutateAsync } = useMutation('authorize');

const { queryClient, setOnReconnected, setOnConnected } = useAPIContext();
const { queryClient, setOnReconnected, setOnConnected, derivAPI } = useAPIContext();

const [isLoading, setIsLoading] = useState(true);
const [isSwitching, setIsSwitching] = useState(false);
const [isInitializing, setIsInitializing] = useState(true);
const [isSuccess, setIsSuccess] = useState(false);
const [isError, setIsError] = useState(false);
const [isFetching, setIsFetching] = useState(false);
const [isAuthorized, setIsAuthorized] = useState(false);

const [data, setData] = useState<TSocketResponseData<'authorize'> | null>();

const { subscribe: _subscribe } = useAPI();

const subscribe = useCallback(
<T extends TSocketSubscribableEndpointNames>(
name: T,
payload?: TSocketRequestPayload<T>
):
| {
subscribe: (
// The type will be handled by the `useSubscription` hook.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onData: (response: any) => void,
// The type will be handled by the `useSubscription` hook.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onError: (response: any) => void
) => { unsubscribe?: VoidFunction };
}
| undefined => {
if (isAuthorized && derivAPI.connection.readyState == 1) {
return derivAPI?.subscribe({ [name]: 1, subscribe: 1, ...(payload || {}) });
}
},
[derivAPI, isAuthorized]
);

const processAuthorizeResponse = useCallback(
(authorizeResponse: TSocketResponseData<'authorize'>) => {
setData(authorizeResponse);
Expand Down Expand Up @@ -135,8 +173,10 @@ const AuthProvider = ({ loginIDKey, children, cookieTimeout, selectDefaultAccoun
}, []);

useEffect(() => {
setOnReconnected(() => {
mutateAsync({ payload: { authorize: getToken(loginid || '') ?? '' } });
setOnReconnected(async () => {
setIsAuthorized(false);
await mutateAsync({ payload: { authorize: getToken(loginid || '') ?? '' } });
setIsAuthorized(true);
});
}, [loginid]);

Expand All @@ -154,15 +194,18 @@ const AuthProvider = ({ loginIDKey, children, cookieTimeout, selectDefaultAccoun
setIsLoading(true);
setIsInitializing(true);
setIsFetching(true);
setIsAuthorized(false);
await mutateAsync({ payload: { authorize: token || '' } })
.then(res => {
setIsAuthorized(true);
processAuthorizeResponse(res);
setIsLoading(false);
setIsInitializing(false);
setIsSuccess(true);
setLoginid(res?.authorize?.loginid ?? '');
})
.catch(() => {
setIsAuthorized(false);
setIsLoading(false);
setIsInitializing(false);
setIsError(true);
Expand All @@ -175,6 +218,7 @@ const AuthProvider = ({ loginIDKey, children, cookieTimeout, selectDefaultAccoun
})
.catch(() => {
if (isMounted) {
setIsAuthorized(false);
setIsLoading(false);
setIsInitializing(false);
setIsError(true);
Expand All @@ -197,7 +241,9 @@ const AuthProvider = ({ loginIDKey, children, cookieTimeout, selectDefaultAccoun
setIsLoading(true);
setIsSwitching(true);

setIsAuthorized(false);
const authorizeResponse = await mutateAsync({ payload: { authorize: getToken(newLoginId) ?? '' } });
setIsAuthorized(true);
setLoginid(newLoginId);
processAuthorizeResponse(authorizeResponse);

Expand All @@ -224,8 +270,9 @@ const AuthProvider = ({ loginIDKey, children, cookieTimeout, selectDefaultAccoun
loginid,
isSwitching,
isInitializing,
subscribe,
};
}, [data, switchAccount, refetch, isLoading, isError, isFetching, isSuccess, loginid]);
}, [data, switchAccount, refetch, isLoading, isError, isFetching, isSuccess, loginid, subscribe]);

return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
};
Expand All @@ -234,6 +281,7 @@ export default AuthProvider;

export const useAuthContext = () => {
const context = useContext(AuthContext);

if (!context) {
throw new Error('useAuthContext must be used within APIProvider');
}
Expand Down
6 changes: 4 additions & 2 deletions packages/api-v2/src/__tests__/useSubscription.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import APIProvider from '../APIProvider';
import AuthProvider from '../AuthProvider';
import useSubscription from '../useSubscription';

jest.mock('./../useAPI', () => ({
jest.mock('../AuthProvider', () => ({
__esModule: true,
default() {
...jest.requireActual('../AuthProvider'),

useAuthContext: () => {
return {
subscribe() {
return {
Expand Down
Loading

0 comments on commit bf7297e

Please sign in to comment.