Skip to content

Commit

Permalink
Merge pull request #9 from okx/feat-demo-release
Browse files Browse the repository at this point in the history
chore: optimize widget-configurator build
  • Loading branch information
toringo authored Sep 27, 2024
2 parents f561400 + 7603127 commit b7e4e55
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 54 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ yarn.lock
yalc.lock
.npmrc

.env*
.env*
uploadKey.txt
deploy-static.sh
output.tgz
6 changes: 3 additions & 3 deletions packages/widget-configurator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build --mode production",
"build:aladdin": "vite build --mode aladdin --base /assets/dex-iframe-test/",
"dev": "VITE_APP_ENV=development vite",
"build": "vite build --mode production --base /dex-widget/",
"build:static": "vite build",
"lint": "eslint .",
"preview": "vite preview"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
import React, { Dispatch, SetStateAction } from 'react';
import Select, { SelectChangeEvent } from '@mui/material/Select';
import FormControl from '@mui/material/FormControl';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import TextField from '@mui/material/TextField';

const local_urls = 'local_urls';
const BASE_DEFAULT_URL = import.meta.env.VITE_BASE_DEFAULT_URL;

export const BaseUrlControl = ({ state, widgetHandler, params }: {
state: [string, Dispatch<SetStateAction<string>>],
Expand All @@ -21,33 +20,6 @@ export const BaseUrlControl = ({ state, widgetHandler, params }: {
});
};

const [customUrl, setCustomUrl] = useState('');

const [urlOptions, setUrlOptions] = useState([]);
useEffect(() => {
const localUrls = localStorage.getItem(local_urls);
try {
if (localUrls) {
setUrlOptions(JSON.parse(localUrls));
}
} catch (e) {
console.error(e);
}
}, []);

const addCustomUrl = () => {
if (!customUrl) return;
const preUrls = localStorage.getItem(local_urls);
try {
const urls = preUrls ? JSON.parse(preUrls) : [];
urls.push(customUrl);
localStorage.setItem(local_urls, JSON.stringify(urls));
setUrlOptions(urls);
} catch (e) {
console.error(e);
}
};

return (
<>
<FormControl fullWidth>
Expand All @@ -60,26 +32,15 @@ export const BaseUrlControl = ({ state, widgetHandler, params }: {
onChange={handleBaseUrlChange}
size="small"
>
<MenuItem value="https://www.okx.com">https://www.okx.com</MenuItem>
<MenuItem value="http://127.0.0.1:3000">http://127.0.0.1:3000</MenuItem>
{
urlOptions.map((url: string, index) => {
return <MenuItem key={index} value={url}>{url}</MenuItem>;
})
BASE_DEFAULT_URL && (
<MenuItem value={BASE_DEFAULT_URL}>{BASE_DEFAULT_URL}</MenuItem>
)
}
<MenuItem value="https://www.okx.com">https://www.okx.com</MenuItem>
<MenuItem value="http://127.0.0.1:3000">http://127.0.0.1:3000</MenuItem>
</Select>
</FormControl>
<TextField
size="small"
value={customUrl}
fullWidth
label="Custum Base Url"
onChange={(event) => {
const url = event.target.value;
setCustomUrl(url);
}}
onBlur={addCustomUrl}
/>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { useEffect, useState } from 'react';
let clickNum = 0;

const CACHE_KEY = 'dev_mode_is_open';
const isDev = ['aladdin', 'development'].includes(import.meta.env.VITE_APP_ENV);
export const useDevMode = () => {
const [isDevModeOpen, setIsDevModeOpen] = useState<boolean>(
import.meta.env.VITE_APP_ENV !== 'prod',
isDev
);

useEffect(() => {
Expand All @@ -16,7 +17,7 @@ export const useDevMode = () => {
}, []);

const openDevMode = () => {
if (isDevModeOpen) {
if (isDevModeOpen || !isDev) {
return;
}
clickNum++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function Configurator({ title }: { title: string }) {
const feeConfigState = useState<string>('');
const [feeConfig] = feeConfigState;

const baseUrlState = useState<string>(import.meta.env.VITE_APP_DEFAUL_BASE_URL as string || 'https://www.okx.com');
const baseUrlState = useState<string>(import.meta.env.VITE_BASE_DEFAULT_URL as string || 'https://www.okx.com');
const [baseUrl] = baseUrlState;

const widthState = useState('');
Expand Down
1 change: 0 additions & 1 deletion packages/widget-configurator/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default defineConfig(({ mode }) => {
const isDev = mode === 'development';

return {
base: isDev ? '' : '/dex-widget/',
define: {
'process.env': {
isDev: isDev,
Expand Down

0 comments on commit b7e4e55

Please sign in to comment.