diff --git a/src/API/index.ts b/src/API/index.ts index 3a3517f..5d45f98 100644 --- a/src/API/index.ts +++ b/src/API/index.ts @@ -103,37 +103,44 @@ type StartWorkerResolveForAPI = [WorkerCallStatus, any []] const channelWrokerListenName = 'toMainWroker' -const postUrl: (url: string, data: string) => Promise = (url, data) => { +export const postUrl: (url: string, data: string, post?: boolean) => Promise = (url, data, post = true) => { return new Promise( async (resolve, reject )=> { const timeout = 1000 const controller = new AbortController() const id = setTimeout(() => controller.abort(), timeout) let status:null|boolean = null - await fetch (url, { - method: "POST", + + const opt: RequestInit = { + method: post ? "POST" : 'GET', headers: { Accept: "text/event-stream", "Content-Type": 'application/json;charset=UTF-8' }, - body: data, cache: 'no-store', referrerPolicy: 'no-referrer', signal: controller.signal - }) + } + if (post) { + opt.body = data + } + await fetch (url, opt) .then ( async res => { if (!res.ok) { - console.log (`postUrl return resolve (false) res.status = [${res.status}]`) return res.status } status = true - const returnData = await res.json() + let returnData = res.text.length ? await res.text(): '' + if (res.headers.get('content-type')?.includes('application/json')) { + returnData = await res.json() - if (!returnData) { - return true + if (!returnData) { + return true + } } + console.log (`postUrl status = [${res.status}] returnData = `, returnData) console.log (`postUrl return JSON data`, returnData) return returnData @@ -142,7 +149,7 @@ const postUrl: (url: string, data: string) => Promise = (url, data .then(_data => { return resolve (_data) }) - .catch (ex => { + .catch ((ex) => { return resolve (status) }) @@ -150,12 +157,23 @@ const postUrl: (url: string, data: string) => Promise = (url, data }) } -export const testLocalServer = () => { - return postUrl(`http://localhost:3001/loginRequest`, '') + +export const postPasscode: (passcode: string) => Promise = async (passcode) => { + return await postUrl(`http://localhost:3001/loginRequest`, JSON.stringify({data:passcode})) } -export const postPasscode: (passcode: string) => Promise = (passcode) => { - return postUrl(`http://localhost:3001/loginRequest`, JSON.stringify({data:passcode})) +export const testLocalServer = async () => { + const ver = '0.0.6' + const result = await postUrl(`http://localhost:3001/ver`, '', false) + if (result) { + if (result.ver === ver) { + return true + } + return false + } + console.log (`[${!result}]`) + console.log (result? 'result true ': 'result false') + return null } const postMessage = (cmd: WorkerCommand, resolve: (value: StartWorkerResolveForAPI | PromiseLike) => void) => { diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index 3d6000b..45757e7 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx @@ -66,7 +66,8 @@ const App = () => { showAppStore, localDaemon, setlocalDaemon, - showMiner + showMiner, + dAPPInitialize } = useAppState() const drawerDragControls = useDragControls() @@ -104,10 +105,14 @@ const App = () => { const testDeamon = async() => { const test = await testLocalServer () - if (test === null) { + if (test === true) { setlocalDaemon(true) + dAPPInitialize().then(() => { + + }) } } + testDeamon().catch((ex) => { console.log(`APP useEffect testDeamon error`, ex) }) @@ -117,8 +122,8 @@ const App = () => { const ShowApp = () => { return ( <> - {localDaemon && } - {!localDaemon && } + {!localDaemon && } + {localDaemon && } ) diff --git a/src/components/App/LaunchAPP.tsx b/src/components/App/LaunchAPP.tsx index 317825d..ef92ac0 100644 --- a/src/components/App/LaunchAPP.tsx +++ b/src/components/App/LaunchAPP.tsx @@ -8,7 +8,6 @@ import {OnboardingPageProvider} from '../Providers/OnboardingPageProvider' import OnboardingScreen from "./OnboardingScreen/OnboardingScreen" import UnlockScreen from "./UnlockScreen/UnlockScreen" import LaunchScreen from "./LaunchScreen/LaunchScreen" -import {US, CN,JP, TW } from 'country-flag-icons/react/3x2' const StyledContainer = styled.div` height: 100vh; @@ -22,76 +21,25 @@ const StyledContainer = styled.div` const App = () => { const { - dAPPInitialize, + isInitializing, - isPlatformLoading, - setNetworkStrength, + setWindowInnerSize, - setClientDevices, - setIsTouchDevice, - showJoinUS, - setShowAppStore, - setIsModalOpen, - setIsShowOverlay, - showOverlay, hasContainer, isUnlocked } = useAppState() - const windowResizeHandler = () => { - setWindowInnerSize(detectWindowInnerSize()) - } - - const [reload, setReload] = useState(false) - useEffect(() => { - - dAPPInitialize().then(() => { - if (!isInitializing) { - setReload (true) - } - }) - - const randomDeviceIds = Array.from({length: 3}, (_, i) => (Date.now() + Math.round(Math.random() * 100)).toString()) - setClientDevices({ - [randomDeviceIds[0]]: { - id: randomDeviceIds[0], - type: 'mobile', - name: 'iPhone-S4GD0S' - }, - [randomDeviceIds[1]]: { - id: randomDeviceIds[1], - type: 'desktop', - name: 'Mac Mini-C0S3M8VN' - }, - [randomDeviceIds[2]]: { - id: randomDeviceIds[2], - type: 'tablet', - name: 'Samsung TAB-LX30SMA' - }, - }) - setIsTouchDevice(detectTouchDevice()) - // Test network connection icon - const rndInt = Math.floor(Math.random() * 4) + 1; - // @ts-ignore - setNetworkStrength(rndInt) - - window.addEventListener('resize', windowResizeHandler) - return () => { - window.removeEventListener('resize', windowResizeHandler) - } - - }, []) const getContent = () => { switch (true) { - case isInitializing: - return ( - - ) + // case isInitializing: + // return ( + // + // ) case hasContainer && isUnlocked: return ( diff --git a/src/components/App/MainScreen/MainScreen.tsx b/src/components/App/MainScreen/MainScreen.tsx index 7142fd7..5be5cc8 100644 --- a/src/components/App/MainScreen/MainScreen.tsx +++ b/src/components/App/MainScreen/MainScreen.tsx @@ -37,15 +37,8 @@ const MainScreen = () => { const { windowInnerSize: {width}, - setIsDrawerOpen, - isDrawerOpen, - isTouchDevice, - isModalOpen, - showGuide, setClientProfiles, showAppStore, - showBlockScan, - showJoinUS, setIsModalOpen, showMiner } = useAppState() @@ -75,9 +68,9 @@ const MainScreen = () => { } } - useEffect(() => { - setInitialProfiles() - }, []) + // useEffect(() => { + // setInitialProfiles() + // }, []) const startDrag = (event: any) => { drawerDragControls.start(event) @@ -114,9 +107,8 @@ const MainScreen = () => { */} - { showGuide && } + { showAppStore && } - { showBlockScan && } { showMiner && } {/* {!showGuide && !showAppStore && } diff --git a/src/components/App/NoDaemon/index.tsx b/src/components/App/NoDaemon/index.tsx index 0f5ceb8..4f75ace 100644 --- a/src/components/App/NoDaemon/index.tsx +++ b/src/components/App/NoDaemon/index.tsx @@ -7,11 +7,16 @@ import Container from '@mui/material/Container' import Stack from '@mui/material/Stack' import Button from '@mui/material/Button' import React, {HTMLAttributes, useState, useEffect} from "react" -import CircularProgress from '@mui/material/CircularProgress' +import BottomNavigationAction from '@mui/material/BottomNavigationAction' import LoadingButton from '@mui/lab/LoadingButton' import {testLocalServer} from '../../../API/index' import useAppState from '../../../store/appState/useAppState' - +import BottomNavigation from '@mui/material/BottomNavigation' +import WindowSharpIcon from '@mui/icons-material/WindowSharp' +import AppleIcon from '@mui/icons-material/Apple' +import Paper from '@mui/material/Paper' +import Link from '@mui/material/Link' +import GitHubIcon from '@mui/icons-material/GitHub' const themeTopArea1 = createTheme ({ typography: { h3: { @@ -39,6 +44,48 @@ const RootContainer = styled(Container)(() => ({ height: '100vh' })) +const downloadConet = ((event: React.SyntheticEvent, newValue: any) =>{ + + switch (newValue) { + default: + case 0: { + return window.open(`https://github.com/CoNET-project/seguro-platform/releases/download/0.0.1/CONET-0.61.0.exe`) + } + case 1: { + return window.open(`https://github.com/CoNET-project/seguro-platform/releases/download/0.0.1/CONET-0.61.0-Apple-M-Series-cpu.dmg`) + } + case 2: { + return window.open(`https://github.com/CoNET-project/seguro-platform/releases/download/0.0.1/CONET-0.61.0-Inter-CPU.dmg`) + } + case 3: { + return window.open(`https://github.com/CoNET-project/seguro-platform/releases/tag/0.0.1`) + } + } +}) +const DownloadArea = () => { + const intl = useIntl() + return ( + + window.open(`https://github.com/CoNET-project/CONET-Proxy`)} > + + { intl.formatMessage({id: 'platform.api.daemon.openSource'})} + + + + + } /> + } /> + } /> + } /> + + + + ) + +} const deamon = () => { const intl = useIntl() @@ -58,6 +105,8 @@ const deamon = () => { } setlocalDaemon(true) } + + return ( @@ -79,10 +128,12 @@ const deamon = () => { color={error ? "error": 'info'} > - { intl.formatMessage({id: 'platform.api.daemon.testButton'})} + { intl.formatMessage({id: 'platform.api.daemon.testButton'})} + + diff --git a/src/components/UI/Common/AlertDialog/AlertDialog.tsx b/src/components/UI/Common/AlertDialog/AlertDialog.tsx index 961f5a7..ab9c41b 100644 --- a/src/components/UI/Common/AlertDialog/AlertDialog.tsx +++ b/src/components/UI/Common/AlertDialog/AlertDialog.tsx @@ -97,13 +97,10 @@ const StyledDialogButton = styled.button` const AlertDialog = ({icon, message, dialogActions}: AlertDialogProps) => { - const appState = useAppState() + const {setIsShowOverlay} = useAppState() useEffect(() => { - appState.setIsShowOverlay(true) - return () => { - appState.setIsShowOverlay(false) - } + }, []) return ( diff --git a/src/index.tsx b/src/index.tsx index 8aa5c5d..8847c27 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,7 +2,7 @@ import React from 'react' import { createRoot } from "react-dom/client" import 'modern-normalize' -import App from './components/App/APP' +import App from './components/App/App' import RootProvider from './components/Providers/RootProvider' import GlobalStyle from './components/UI/Global/Styles' import './index.css' diff --git a/src/localization/messages/en-US.ts b/src/localization/messages/en-US.ts index 0cead42..e6024d1 100644 --- a/src/localization/messages/en-US.ts +++ b/src/localization/messages/en-US.ts @@ -337,6 +337,7 @@ const en_US: Messages = { 'platform.api.daemon.title': 'No CONET Daemon Activity Detected', 'platform.api.daemon.detail': 'Please start CONET Daemon, or download and start it', 'platform.api.daemon.testButton': 'test daemon', + 'platform.api.daemon.openSource': 'CONET is Open Source', 'platform.miner.header.title': 'Welcome to CONET DePIN', 'platform.miner.register.title': 'Node Register', diff --git a/src/localization/messages/ja_JP.ts b/src/localization/messages/ja_JP.ts index 7e709c3..899e6bf 100644 --- a/src/localization/messages/ja_JP.ts +++ b/src/localization/messages/ja_JP.ts @@ -59,9 +59,9 @@ const ja_JP: Messages = { 'unlock.title': 'パスコードを入力してください', 'platform.unlock.button.forgot': 'パスコードをお忘れですか?', - 'platform.dialog.delete.message': '削除はCoNET Platform 内のすべてのデータが失われます。', + 'platform.dialog.delete.message': '削除はCoNET Platform 内のすべてデータが失われます!', 'platform.dialog.delete.button.cancel': 'キャンセル', - 'platform.dialog.delete.button.confirm': 'Delete', + 'platform.dialog.delete.button.confirm': 'パスコードを削除', 'keypad.cancel': 'Cancel', 'keypad.unlock': 'Unlock', @@ -334,6 +334,7 @@ const ja_JP: Messages = { 'platform.api.daemon.title': 'CONETデーモンが検出されませんでした', 'platform.api.daemon.detail': 'CONETを起動、又ダウンロードして起動してください', 'platform.api.daemon.testButton': 'テストデーモン', + 'platform.api.daemon.openSource': 'CONETはオープンソースコードです', 'platform.miner.header.title': 'ようこそCONET DePIN参加者の皆様', 'platform.miner.register.title': 'ノードの登録', diff --git a/src/localization/messages/zh-CN.ts b/src/localization/messages/zh-CN.ts index b7ecf60..3eea6c0 100644 --- a/src/localization/messages/zh-CN.ts +++ b/src/localization/messages/zh-CN.ts @@ -57,9 +57,9 @@ const zh_CN: Messages = { 'unlock.title': '输入您的 CoNET 平台密码', 'platform.unlock.button.forgot': '忘记密码了?', - 'platform.dialog.delete.message': '删除您的容器是不同的操作,需要使用新的邀请码创建新密码', + 'platform.dialog.delete.message': '删除,将失去您在CONET平台内的所有信息!', 'platform.dialog.delete.button.cancel': '取消', - 'platform.dialog.delete.button.confirm': '删除', + 'platform.dialog.delete.button.confirm': '删除密码', 'keypad.cancel': '取消', 'keypad.unlock': '解锁', @@ -323,6 +323,7 @@ const zh_CN: Messages = { 'platform.api.daemon.title': '未检测到CONET守护程序', 'platform.api.daemon.detail': '请启动CONET,或下载启动它', 'platform.api.daemon.testButton': '测试守护进程', + 'platform.api.daemon.openSource': 'CONET是开源代码', 'platform.miner.header.title': '欢迎您CONET DePIN参与者', diff --git a/src/localization/messages/zh-TW.ts b/src/localization/messages/zh-TW.ts index ac52c80..94ccf4c 100644 --- a/src/localization/messages/zh-TW.ts +++ b/src/localization/messages/zh-TW.ts @@ -58,9 +58,9 @@ const zh_CN: Messages = { 'unlock.title': '輸入您的 Platform 平台密碼', 'platform.unlock.button.forgot': '忘記密碼了?', - 'platform.dialog.delete.message': '刪除容器是一項永久性操作,您需要使用新的邀請碼創建新密碼', + 'platform.dialog.delete.message': '刪除密碼,將失去您在CONET内的所有信息!', 'platform.dialog.delete.button.cancel': '取消', - 'platform.dialog.delete.button.confirm': '刪除', + 'platform.dialog.delete.button.confirm': '刪除密碼', 'keypad.cancel': '取消', 'keypad.unlock': '解鎖', @@ -341,6 +341,7 @@ const zh_CN: Messages = { 'platform.api.daemon.title': '未偵測到CONET守護程序', 'platform.api.daemon.detail': '請啟動CONET,或下載啟動它', 'platform.api.daemon.testButton': '測試守護程序', + 'platform.api.daemon.openSource': 'CONET是開源程式碼', 'platform.miner.header.title': '欢迎您CONE DePIN参与者', 'platform.miner.register.title': '節點註冊', diff --git a/src/localization/types.ts b/src/localization/types.ts index 16f7795..5739e43 100644 --- a/src/localization/types.ts +++ b/src/localization/types.ts @@ -334,6 +334,7 @@ export type Messages = { 'platform.api.daemon.title': string 'platform.api.daemon.detail': string 'platform.api.daemon.testButton': string + 'platform.api.daemon.openSource': string 'platform.miner.header.title': string 'platform.miner.register.title': string