Skip to content

Commit

Permalink
fix: webembed build
Browse files Browse the repository at this point in the history
  • Loading branch information
sidmorizon committed Jan 14, 2025
1 parent 5d0eb1d commit 09d5e7c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 12 deletions.
6 changes: 3 additions & 3 deletions apps/web-embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { lazy, Suspense } from 'react';
import { createRoot } from 'react-dom/client';
import { HashRouter, Route, Routes } from 'react-router-dom';
import { EWebEmbedRoutePath } from '@onekeyhq/shared/src/consts/webEmbedConsts';
import AppProvider from './pages/AppProvider';
import WebEmbedAppProvider from './pages/WebEmbedAppProvider';

const PageIndex = lazy(() => import('./pages/PageIndex'));
const PageWebEmbedApi = lazy(() => import('./pages/PageWebEmbedApi'));
Expand All @@ -16,7 +16,7 @@ const root = createRoot(container);

root.render(
<React.StrictMode>
<AppProvider>
<WebEmbedAppProvider>
<Suspense fallback={<div />}>
<HashRouter>
<Routes>
Expand All @@ -32,6 +32,6 @@ root.render(
</Routes>
</HashRouter>
</Suspense>
</AppProvider>
</WebEmbedAppProvider>
</React.StrictMode>,
);
18 changes: 17 additions & 1 deletion apps/web-embed/pages/PageIndex.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
import { Link } from 'react-router-dom';

import { EWebEmbedRoutePath } from '@onekeyhq/shared/src/consts/webEmbedConsts';

export default function PageIndex() {
return <div>PageIndex</div>;
return (
<div style={{ padding: '20px' }}>
<h1>PageIndex</h1>
<ul>
<li>
<Link to={EWebEmbedRoutePath.webEmbedApi}>WebEmbedApi</Link>
</li>
<li>
<Link to={EWebEmbedRoutePath.primePurchase}>PrimePurchase</Link>
</li>
</ul>
</div>
);
}
8 changes: 8 additions & 0 deletions apps/web-embed/pages/PageWebEmbedApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import webembedApi from '@onekeyhq/kit-bg/src/webembeds/instance/webembedApi';

import type { IJsBridgeMessagePayload } from '@onekeyfe/cross-inpage-provider-types';

// create button which can refresh, append to body
const refreshButton = document.createElement('button');
refreshButton.textContent = 'Refresh';
refreshButton.addEventListener('click', () => {
globalThis.location.reload();
});
document.body.appendChild(refreshButton);

function printMessageToBody(message: string) {
const p = document.createElement('p');
p.textContent = `${new Date().toTimeString().slice(0, 8)} ${message}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ConfigProvider } from '@onekeyhq/components';

import webEmbedAppSettings from '../utils/webEmbedAppSettings';

export default function AppProvider({
export default function WebEmbedAppProvider({
children,
}: {
children: React.ReactNode;
Expand All @@ -12,8 +12,8 @@ export default function AppProvider({
// TODO Toast support
return (
<ConfigProvider
theme={settings.themeVariant as any}
locale={settings.localeVariant as any}
theme={(settings?.themeVariant as any) || 'light'}
locale={(settings?.localeVariant as any) || 'en-US'}
>
{children}
</ConfigProvider>
Expand Down
6 changes: 4 additions & 2 deletions apps/web-embed/utils/webEmbedAppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ export type IWebEmbedOnekeyAppSettings = {
localeVariant: string;
};

function getSettings(): IWebEmbedOnekeyAppSettings {
function getSettings(): IWebEmbedOnekeyAppSettings | undefined {
const settings =
// @ts-ignore
globalThis.WEB_EMBED_ONEKEY_APP_SETTINGS as IWebEmbedOnekeyAppSettings;
globalThis.WEB_EMBED_ONEKEY_APP_SETTINGS as
| IWebEmbedOnekeyAppSettings
| undefined;
return settings;
}

Expand Down
4 changes: 2 additions & 2 deletions development/webpack/webpack.web-embed.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = ({
splitChunks: false,
},
output: {
publicPath: PUBLIC_URL || '/',
publicPath: PUBLIC_URL || './',
path: path.join(basePath, 'web-build'),
assetModuleFilename:
'static/media/web-embed.[name].[contenthash][ext]',
Expand All @@ -38,7 +38,7 @@ module.exports = ({
developmentConfig({ platform, basePath }),
{
output: {
publicPath: `http://localhost:${WEB_PORT}/`,
publicPath: '',
},
},
);
Expand Down
1 change: 1 addition & 0 deletions packages/kit-bg/src/apis/backgroundApiPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const WEB_EMBED_API_WHITE_LIST_ORIGIN = [
'http://localhost:8081',

// real iOS Device web-embed origin allowed in DEV (LAN ip)
'http://192.168.6.37:3008',
'http://192.168.31.215:3008',
'http://192.168.31.204:3008',
'http://192.168.31.205:3008',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback } from 'react';

import { StackActions } from '@react-navigation/native';
import { useIntl } from 'react-intl';
import { I18nManager } from 'react-native';

Expand Down Expand Up @@ -31,7 +32,12 @@ import {
setBadgeCountAsync,
} from '@onekeyhq/shared/src/modules3rdParty/expo-notifications';
import platformEnv from '@onekeyhq/shared/src/platformEnv';
import { EModalSettingRoutes } from '@onekeyhq/shared/src/routes';
import {
EModalSettingRoutes,
ERootRoutes,
ETabDeveloperRoutes,
ETabRoutes,
} from '@onekeyhq/shared/src/routes';
import appStorage from '@onekeyhq/shared/src/storage/appStorage';
import { EAppSyncStorageKeys } from '@onekeyhq/shared/src/storage/syncStorage';
import {
Expand Down Expand Up @@ -629,6 +635,20 @@ export const DevSettingsSection = () => {
<AddressBookDevSetting />
<SentryCrashSettings />
<CrashDevSettings />

<SectionPressItem
title="Open Dev Gallery"
onPress={() => {
navigation.dispatch(
StackActions.replace(ERootRoutes.Main, {
screen: ETabRoutes.Developer,
params: {
screen: ETabDeveloperRoutes.TabDeveloper,
},
}),
);
}}
/>
</Section>
);
};

0 comments on commit 09d5e7c

Please sign in to comment.