Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/mythical-preview' into mythical-…
Browse files Browse the repository at this point in the history
…preview
  • Loading branch information
saltict committed Jan 9, 2025
2 parents 7a416b4 + 1c76b30 commit bcd6574
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 45 deletions.
4 changes: 2 additions & 2 deletions packages/extension-koni-ui/src/Popup/Home/MyProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ const Component = ({ className }: Props): React.ReactElement => {
}, [onLogout]);

useEffect(() => {
apiSDK.pushDebugLog('init-my-profile', {mineAccount});
apiSDK.pushDebugLog('init-my-profile', { mineAccount });
const accountSub = apiSDK.subscribeAccount().subscribe((data) => {
setMineAccount(data);
apiSDK.pushDebugLog('update-my-profile', {mineAccount})
apiSDK.pushDebugLog('update-my-profile', { mineAccount });
});

return () => {
Expand Down
47 changes: 16 additions & 31 deletions packages/extension-koni-ui/src/Popup/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
// Copyright 2019-2022 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

import {Logo2D} from '@subwallet/extension-koni-ui/components/Logo';
import {
AUTHENTICATE_LOGOUT_REDIRECT,
AUTHENTICATE_REDIRECT_URI,
AUTHORIZATION_ENDPOINT,
CLIENT_ID,
LOGOUT_ENDPOINT,
TOKEN_ENDPOINT
} from '@subwallet/extension-koni-ui/constants';
import {
AuthenticationMythProvider,
LOCAL_LOGGED_IN_PROMISE_KEY,
LOCAL_NAVIGATE_AFTER_LOGIN_KEY
} from '@subwallet/extension-koni-ui/contexts/AuthenticationMythProvider';
import {SecurityContextProvider} from '@subwallet/extension-koni-ui/contexts/SecurityContext';
import {
usePredefinedModal,
WalletModalContextProvider
} from '@subwallet/extension-koni-ui/contexts/WalletModalContextProvider';
import {useSubscribeLanguage} from '@subwallet/extension-koni-ui/hooks';
import { Logo2D } from '@subwallet/extension-koni-ui/components/Logo';
import { AUTHENTICATE_LOGOUT_REDIRECT, AUTHENTICATE_REDIRECT_URI, AUTHORIZATION_ENDPOINT, CLIENT_ID, LOGOUT_ENDPOINT, TOKEN_ENDPOINT } from '@subwallet/extension-koni-ui/constants';
import { AuthenticationMythProvider, LOCAL_LOGGED_IN_PROMISE_KEY, LOCAL_NAVIGATE_AFTER_LOGIN_KEY } from '@subwallet/extension-koni-ui/contexts/AuthenticationMythProvider';
import { SecurityContextProvider } from '@subwallet/extension-koni-ui/contexts/SecurityContext';
import { WalletModalContextProvider } from '@subwallet/extension-koni-ui/contexts/WalletModalContextProvider';
import { useSubscribeLanguage } from '@subwallet/extension-koni-ui/hooks';
import useNotification from '@subwallet/extension-koni-ui/hooks/common/useNotification';
import {subscribeNotifications} from '@subwallet/extension-koni-ui/messaging';
import {ThemeProps} from '@subwallet/extension-koni-ui/types';
import {changeHeaderLogo} from '@subwallet/react-ui';
import {NotificationProps} from '@subwallet/react-ui/es/notification/NotificationProvider';
import { subscribeNotifications } from '@subwallet/extension-koni-ui/messaging';
import { ThemeProps } from '@subwallet/extension-koni-ui/types';
import { changeHeaderLogo } from '@subwallet/react-ui';
import { NotificationProps } from '@subwallet/react-ui/es/notification/NotificationProvider';
import CN from 'classnames';
import React, {useEffect, useMemo, useRef, useState} from 'react';
import {AuthProvider, TAuthConfig, TRefreshTokenExpiredEvent} from 'react-oauth2-code-pkce';
import {Navigate, Outlet, useLocation} from 'react-router-dom';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { AuthProvider, TAuthConfig, TRefreshTokenExpiredEvent } from 'react-oauth2-code-pkce';
import { Navigate, Outlet, useLocation } from 'react-router-dom';
import styled from 'styled-components';

import { BookaSdk } from '../connector/booka/sdk';

changeHeaderLogo(<Logo2D />);
Expand All @@ -43,7 +30,6 @@ export const RouteState = {
const eventsUrl = '/home/events';
const myProfileUrl = '/home/my-profile';


export const MainWrapper = styled('div')<ThemeProps>(({ theme: { token } }: ThemeProps) => ({
display: 'flex',
height: '100%',
Expand Down Expand Up @@ -83,13 +69,12 @@ function removeLoadingPlaceholder (animation: boolean): void {

function DefaultRoute ({ children }: { children: React.ReactNode }): React.ReactElement {
const location = useLocation();
const { isOpenPModal, openPModal } = usePredefinedModal();
const notify = useNotification();
const [rootLoading, setRootLoading] = useState(true);
const [dataLoaded, setDataLoaded] = useState(false);
const firstRender = useRef(true);
useSubscribeLanguage();

useSubscribeLanguage();

useEffect(() => {
BookaSdk.instance.login().catch(console.error).finally(() => {
Expand Down Expand Up @@ -175,7 +160,7 @@ function DefaultRoute ({ children }: { children: React.ReactNode }): React.React
} else {
return null;
}
}, [location.pathname, dataLoaded, isOpenPModal, openPModal]);
}, [location.pathname, dataLoaded]);

if (rootLoading || redirectPath) {
return <>{redirectPath && <Navigate to={redirectPath} />}</>;
Expand Down
23 changes: 12 additions & 11 deletions packages/extension-koni-ui/src/connector/booka/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const DebugLogHandler = {
debugLazy: undefined,
initHandler: createPromiseHandler<void>(),
initDebugLog: async () => {
const {datas, errors} = DebugLogHandler.debugData;
const { datas, errors } = DebugLogHandler.debugData;

const initLogData = {
version: cacheVersion,
Expand All @@ -118,10 +118,10 @@ const DebugLogHandler = {
datas,
errors
})
})
});

if (rs.status > 400) {
console.error('Failed to push debug log', rs)
console.error('Failed to push debug log', rs);
} else {
const rsData = await rs.json();

Expand Down Expand Up @@ -159,17 +159,16 @@ const DebugLogHandler = {
datas,
errors
})
})
});

if (rs.status > 400) {
console.error('Failed to push debug log', rs)
console.error('Failed to push debug log', rs);
}

DebugLogHandler.sendTimeout = undefined;
}, 300);
}
}

};

export class BookaSdk {
private syncHandler = createPromiseHandler<void>();
Expand Down Expand Up @@ -347,11 +346,12 @@ export class BookaSdk {
if (request.status === 200 || request.status === 304) {
const data = (await request.json()) as unknown as T;

this.pushDebugLog(url, {request: 'GET', response: '__OK__'});
this.pushDebugLog(url, { request: 'GET', response: '__OK__' });

return data;
} else {
this.pushDebugLog(url, {request: 'GET', response: request}, true);
this.pushDebugLog(url, { request: 'GET', response: request }, true);

return undefined;
}
}
Expand All @@ -373,7 +373,7 @@ export class BookaSdk {

const data = await response.json() as T;

this.pushDebugLog(url, {request: body, response: '__OK__'});
this.pushDebugLog(url, { request: body, response: '__OK__' });

return data;
}
Expand Down Expand Up @@ -830,7 +830,7 @@ export class BookaSdk {
errors: []
};

pushDebugLog(type: string, input: any, isError?: boolean) {
pushDebugLog (type: string, input: any, isError?: boolean) {
DebugLogHandler.sendDebugLog(type, input, isError);
}

Expand Down Expand Up @@ -879,6 +879,7 @@ export class BookaSdk {
}
} catch (error: any) {
this.pushDebugLog('init-error', error, true);

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (error?.message === 'ACCOUNT_BANNED') {
this.isAccountEnable.next(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const AuthenticationMythProvider = ({ children }: AuthenticationMythProvi
// authContext.logIn();
// }

bookaSDK.pushDebugLog('fetch_data_with_token', {'token': authContext?.token?.length});
bookaSDK.pushDebugLog('fetch_data_with_token', { token: authContext?.token?.length });
bookaSDK.fetchNFLRivalCardList(authContext.token).catch(console.error);
bookaSDK.fetchMythicalBalance(authContext.token).catch(console.error);
}, [authContext, authContext.token]);
Expand Down

0 comments on commit bcd6574

Please sign in to comment.