diff --git a/package.json b/package.json index d3181b5..81aa813 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,9 @@ ], "homepage": "https://conet.network", "main": "./src/electron/electron.js", - "resolutions": { - "@types/react": "^18.2.38" - }, + "resolutions": { + "@types/react": "^18.2.38" + }, "scripts": { "start": "concurrently --kill-others --success=first 'yarn start:gateway' 'yarn _start:web' 'wait-on tcp:3000 && NODE_ENV=development yarn _start:desktop'", "start:storybook": "start-storybook -p 6006 -s public", @@ -29,80 +29,85 @@ "build-storybook": "build-storybook -s public" }, "dependencies": { - "@conet.project/seguro-worker-lib": "0.13.9", - "@emotion/react": "^11.11.1", + "@conet.project/seguro-worker-lib": "0.13.10", + "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", - "@mui/icons-material": "^5.15.0", - "@mui/material": "^5.15.0", - "@mui/base": "^5.0.0-beta.27", - "@mui/material-next": "^6.0.0-alpha.113", - "@mui/lab": "^5.0.0-alpha.156", - "primereact": "^10.2.1", + "@material/material-color-utilities": "^0.2.7", + "@mui/base": "^5.0.0-beta.29", + "@mui/icons-material": "^5.15.2", + "@mui/lab": "^5.0.0-alpha.158", + "@mui/material": "^5.15.2", + "@mui/material-next": "^6.0.0-alpha.115", "@react-icons/all-files": "^4.1.0", "@tippyjs/react": "^4.2.6", + "@webcontainer/api": "^1.1.8", + "async": "^3.2.5", + "country-flag-icons": "^1.5.9", "dayjs": "^1.11.10", "framer-motion": "^10.16.16", - "get-port": "^7.0.0", + "primereact": "^10.2.1", "react-draggable": "^4.4.6", "react-hot-toast": "^2.4.1", - "react-loader-spinner": "^6.1.0", + "react-loader-spinner": "^6.1.6", "react-lottie-player": "^1.5.5", - "react-router-dom": "^6.21.0", + "react-router-dom": "^6.21.1", "uuid": "^9.0.1", - "web-vitals": "^3.5.0", - "country-flag-icons": "^1.5.9", - "@webcontainer/api": "^1.1.8", - "@material/material-color-utilities": "^0.2.7" - + "web-vitals": "^3.5.1", + "web3": "^4.3.0", + "react-chartjs-2": "^5.2.0", + "chart.js": "4.4.1", + "fg-loadcss": "^3.1.0", + "@types/fg-loadcss": "^3.1.3" + }, "devDependencies": { "@fortawesome/fontawesome-svg-core": "^6.5.1", "@fortawesome/free-brands-svg-icons": "^6.5.1", "@fortawesome/react-fontawesome": "^0.2.0", "@reduxjs/toolkit": "^2.0.1", - "@storybook/addon-actions": "^7.6.5", - "@storybook/addon-essentials": "^7.6.5", - "@storybook/addon-links": "^7.6.5", - "@storybook/node-logger": "^7.6.5", - "@storybook/preset-create-react-app": "^7.6.5", - "@storybook/react": "^7.6.5", - "@testing-library/jest-dom": "^6.1.5", + "@storybook/addon-actions": "^7.6.6", + "@storybook/addon-essentials": "^7.6.6", + "@storybook/addon-links": "^7.6.6", + "@storybook/node-logger": "^7.6.6", + "@storybook/preset-create-react-app": "^7.6.6", + "@storybook/react": "^7.6.6", + "@testing-library/jest-dom": "^6.1.6", "@testing-library/react": "^14.1.2", "@testing-library/user-event": "^14.5.1", + "@types/async": "^3.2.24", "@types/jest": "^29.5.11", - "@types/node": "^20.10.4", - "@types/react": "^18.2.45", + "@types/node": "^20.10.5", + "@types/react": "^18.2.46", "@types/react-document-meta": "^3.0.5", "@types/react-dom": "^18.2.18", + "@types/react-gauge-chart": "^0.4.3", "@types/react-router-dom": "^5.3.3", + "@types/react-swipeable-views": "^0.13.5", "@types/styled-components": "^5.1.34", "@types/uuid": "^9.0.7", - "@types/react-swipeable-views": "^0.13.5", "babel-loader": "^9.1.3", - "concurrently": "^8.2.2", "buffer": "^6.0.3", + "caniuse-lite": "^1.0.30001572", + "concurrently": "^8.2.2", "cors": "^2.8.5", - "electron":"^28.0.0", + "electron": "^28.1.0", "eslint-plugin-react-hooks": "^4.6.0", "express": "^4.18.2", "modern-normalize": "^2.0.0", "react": "^18.2.0", + "react-d3-speedometer": "^1.1.0", "react-document-meta": "^3.0.0-beta.2", "react-dom": "^18.2.0", + "react-gauge-chart": "^0.4.1", "react-icons": "^4.12.0", "react-intl": "^6.5.5", - "react-redux": "^9.0.4", "react-scripts": "^5.0.1", - "styled-components": "^6.1.1", + "react-swipeable-views": "^0.14.0", + "styled-components": "^6.1.6", "typescript": "^5.3.3", - "wait-on": "^7.2.0", - "caniuse-lite": "^1.0.30001570", - "react-swipeable-views": "^0.14.0", - "react-d3-speedometer": "^1.1.0", - "react-gauge-chart": "^0.4.1", - "@types/react-gauge-chart": "^0.4.3" + "wait-on": "^7.2.0" }, "browserslist": { "production": [ @@ -128,5 +133,4 @@ } ] } - } diff --git a/src/API/index.ts b/src/API/index.ts index ce3d3d0..2f64ce1 100644 --- a/src/API/index.ts +++ b/src/API/index.ts @@ -1,9 +1,11 @@ - +import React, {SetStateAction, Dispatch} from "react" import {v4} from 'uuid' import {logger} from '../components/App/logger' -import useAppState from "../store/appState/useAppState" - +import Async from 'async' +import web3 from 'web3' import store from '../store/store' +import { setIslivenessRunning } from '../store/appState/appStateActions' +import {getWorkerService} from '../services/workerService/workerService' type WorkerCommandErrorType = 'NOT_READY'|'INVALID_DATA'| 'NO_UUID'|'INVALID_COMMAND'|'OPENPGP_RUNNING_ERROR'| @@ -12,10 +14,10 @@ type WorkerCommandErrorType = 'NOT_READY'|'INVALID_DATA'| type WorkerCommandType = 'READY'|'encrypt_TestPasscode'|'getCONETBalance'|'getRegiestNodes'| 'encrypt_createPasscode'|'encrypt_lock'|'encrypt_deletePasscode'|'storePreferences'| 'newProfile'|'storeProfile'|'invitation'|'WORKER_MESSAGE'|'startProxy'| -'isAddress'|'getFaucet'|'syncAsset'|'sendAsset'|'getUSDCPrice'| +'isAddress'|'getFaucet'|'syncAsset'|'sendAsset'|'getUSDCPrice'|'registerReferrer'| 'buyUSDC'|'mintCoNETCash'|'getSINodes'|'getRecipientCoNETCashAddress'| 'getUserProfile'|'sendMessage'|'setRegion'|'ipaddress'|'startLiveness'|'stopLiveness'| -'isLivenessRunning' +'isLivenessRunning'|'referrerList'|'getAllNodes' export type WorkerCallStatus = 'SUCCESS' | 'NOT_READY' | 'UNKNOWN_COMMAND' | 'TIME_OUT' | 'SYSTEM_ERROR' @@ -30,13 +32,9 @@ export type SeguroNetworkStatus = WorkerCallStatus | 'LOCAL_SERVER_ERROR'|'INVITATION_CODE_ERROR'| 'SEGURO_ERROR'|'UNKNOW_ERROR'|'SEGURO_DATA_FORMAT_ERROR' - - const ver = '0.0.13' - - /*eslint-disable */ export interface profile { bio: string @@ -57,7 +55,7 @@ export type SINodesSortby = 'CUSTOMER_REVIEW'|'TOTAL_ONLINE_TIME'| export type SINodesRegion = 'USA'|'UK'|'ES'|'DE' export interface ContainerData { - method: { + method?: { testPasscode?: ( passcode: string, progressCallback: ( progressInteger: string, progressFractional: string ) => void @@ -111,7 +109,7 @@ export type StartWorkerResolve = [WorkerCallStatus, ContainerData?] type StartWorkerResolveForAPI = [WorkerCallStatus, any []] const channelWrokerListenName = 'toMainWroker' - +let workerService: ContainerData export const postUrl: (url: string, data: string, post?: boolean) => Promise = (url, data, post = true) => { return new Promise( async (resolve, reject )=> { @@ -167,7 +165,6 @@ export const postUrl: (url: string, data: string, post?: boolean) => Promise Promise = async (passcode) => { return await postUrl(`http://localhost:3001/loginRequest`, JSON.stringify({data:passcode})) } @@ -185,16 +182,17 @@ export const testLocalServer = async () => { return null } - const postMessage = (cmd: WorkerCommand, close: boolean, resolve: any, Callback?:(err: string, data: string[]) => void) => { const channel = new BroadcastChannel(channelWrokerListenName) - const listenChannel = new BroadcastChannel(cmd.uuid) + const kk = (e: any) => { listeningChannel(e.data, cmd.uuid) } + const listenChannel = cmd.uuid ? new BroadcastChannel(cmd.uuid): null + const listeningChannel = (data: any, uuid: string) => { let cmd: WorkerCommand @@ -205,14 +203,14 @@ const postMessage = (cmd: WorkerCommand, close: boolean, resolve: any, Callback return logger ('class CONET_Platfrom_API', `listeningChannel JSON.parse(data) Error`) } - if (close) { + if (close && listenChannel) { listenChannel.close() } if (cmd.err) { if (resolve) { - return resolve(['SYSTEM_ERROR', cmd.data]) + return resolve([cmd.err, cmd.data]) } if (Callback) { return Callback('SYSTEM_ERROR', []) @@ -223,12 +221,22 @@ const postMessage = (cmd: WorkerCommand, close: boolean, resolve: any, Callback return resolve(['SUCCESS', cmd.data]) } if (Callback) { + if (!cmd.data.length) { + if (listenChannel) { + listenChannel.close() + } + + return Callback('',[]) + } return Callback('', cmd.data) } return console.log (`postMessage Callback && resolve all null`, cmd.data) } - - listenChannel.addEventListener('message', kk) + + if (listenChannel){ + + listenChannel.addEventListener('message', kk) + } channel.postMessage(JSON.stringify(cmd)) channel.close() } @@ -292,11 +300,12 @@ export const getRegiestNodes : () => Promise < StartWorkerResolveForAPI > = () = export const createPasscode : (passcord: string, local: string) => Promise < StartWorkerResolveForAPI > = (passcord: string, local: string) => { return new Promise( resolve => { - + const search = window.location.search + const referrals = search ? search.split('=')[1]: '' const cmd: WorkerCommand = { cmd: 'encrypt_createPasscode', uuid: v4(), - data: [passcord, local] + data: [passcord, local, referrals] } return postMessage (cmd, true, resolve) @@ -330,7 +339,6 @@ export const encrypt_deletePasscode : () => Promise < StartWorkerResolveForAPI > } export const startLiveness: (callback: (err: string, data: string[]) => void) => void = (callback) => { - const cmd: WorkerCommand = { cmd: 'startLiveness', uuid: v4(), @@ -340,7 +348,7 @@ export const startLiveness: (callback: (err: string, data: string[]) => void) => if (err) { return callback (err, []) } - + return callback ('', data) }) } @@ -357,16 +365,99 @@ export const stopLiveness: () => Promise < StartWorkerResolveForAPI > = () => { }) } -export const isLivenessRunning: () => Promise < StartWorkerResolveForAPI > = () => { +export const encrypt_TestPasscode:(passcode: string) => Promise < StartWorkerResolveForAPI > = (passcode) => new Promise(resolve=> { + const search = window.location.search + const referrals = search ? search.split('=')[1]: '' + const cmd: WorkerCommand = { + cmd: 'encrypt_TestPasscode', + uuid: v4(), + data: [passcode, referrals] + } + + return postMessage (cmd, true, resolve) + +}) +export const isLivenessRunning: (callback: (err: string, data: string[]) => void) => Promise < StartWorkerResolveForAPI > = (callback) => { + return new Promise(resolve => { const cmd: WorkerCommand = { cmd: 'isLivenessRunning', uuid: v4(), data: [] } - return postMessage (cmd, true, resolve) + return postMessage (cmd, false, null,(err, data) => { + if (err) { + return callback (err, []) + } + + return callback ('', data) + }) + }) +} + +type listenState = 'referrer'|'system'|'conet'|'cntp'|'cntp-balance' + +export const initOneTimeListenState = (listenState: listenState, dispatch: Dispatch>) => { + const channel = new BroadcastChannel(listenState) + channel.addEventListener('message', (e: any) => { + dispatch(JSON.parse(e.data)) }) } +export const initListenState = (listenState: listenState, dispatch: Dispatch>) => { + const channel = new BroadcastChannel(listenState) + const listen = (e: any) => { + dispatch(JSON.parse(e.data)) + } + channel.addEventListener('message', listen) +} + +export const registerReferrer:(referrerAddr: string) => Promise < StartWorkerResolveForAPI > = (referrerAddr) => new Promise(resolve=>{ + const cmd: WorkerCommand = { + cmd: 'registerReferrer', + uuid: v4(), + data: [referrerAddr] + } + return postMessage (cmd, true, resolve) +}) + +export const scanAssets = () => { + const cmd: WorkerCommand = { + cmd: 'syncAsset', + uuid: '', + data: [] + } + return postMessage (cmd, true, null) +} + +export const referrerList : () => Promise < StartWorkerResolveForAPI > = () => { + return new Promise( resolve => { + const cmd: WorkerCommand = { + cmd: 'referrerList', + uuid: v4(), + data: [] + } + return postMessage (cmd, true, resolve) + }) +} + +export interface nodeType { + ip_addr: string + minerAddr: string + running: boolean + wallet_addr: string + balance: string + country: string +} + +export const getAllNodes:() => Promise < StartWorkerResolveForAPI > = () => new Promise(resolve => { + const cmd: WorkerCommand = { + cmd: 'getAllNodes', + uuid: v4(), + data: [] + } + return postMessage (cmd, true, resolve) +}) + diff --git a/src/assets/logo/CNTP.png b/src/assets/logo/CNTP.png new file mode 100644 index 0000000..ff5bf1c Binary files /dev/null and b/src/assets/logo/CNTP.png differ diff --git a/src/assets/logo/cntp-log.svg b/src/assets/logo/cntp-log.svg new file mode 100644 index 0000000..35cc38c --- /dev/null +++ b/src/assets/logo/cntp-log.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/components/App/Apps/Browser/searchPage.tsx b/src/components/App/Apps/Browser/searchPage.tsx index 1807a2a..73bcf66 100644 --- a/src/components/App/Apps/Browser/searchPage.tsx +++ b/src/components/App/Apps/Browser/searchPage.tsx @@ -1,6 +1,6 @@ import ToDoContext, {Todo} from './TodoContext' import { useContext, useRef, useEffect, useState, useCallback } from 'react' -import { Box} from '@mui/system' +import { Box} from '@mui/material' import Typography from '@mui/material/Typography' import Grid from '@mui/material/Grid' import SearchInput from './SearchInput' diff --git a/src/components/App/Apps/CONET-Proxy/index.tsx b/src/components/App/Apps/CONET-Proxy/index.tsx index 7e3e743..d1d9cda 100644 --- a/src/components/App/Apps/CONET-Proxy/index.tsx +++ b/src/components/App/Apps/CONET-Proxy/index.tsx @@ -259,12 +259,6 @@ const IOS = () => { ) } -const ItemStyle2 = styled(Paper)(() => ({ - textAlign: 'center', - borderRadius: '1rem', - padding: '1rem', - color: colors.grey[500] -})) const FeatureArea8ItemNew = () => { const { diff --git a/src/components/App/Apps/blockscan/index.tsx b/src/components/App/Apps/blockscan/index.tsx index 8d8e790..dbbf162 100644 --- a/src/components/App/Apps/blockscan/index.tsx +++ b/src/components/App/Apps/blockscan/index.tsx @@ -103,7 +103,6 @@ const headerArea = (setShowBlockScan: (showBlockScan: boolean) => void, setShowG ) } - const ooo = { blockHash: "0xb570cdc8549c176bdc41a87499ac7dc02ef5536051b42ec007b08179b33f8153", blockNumber: "58", @@ -261,7 +260,6 @@ export const BlockScanBody = (receipt: CryptoAssetHistory|undefined) => { ) } - const BlockScan = () => { const { setShowGuide, @@ -278,6 +276,4 @@ const BlockScan = () => { ) } - - export default BlockScan \ No newline at end of file diff --git a/src/components/App/Apps/dashboard/UnLockWallet.tsx b/src/components/App/Apps/dashboard/UnLockWallet.tsx index 01dfc21..b9439f5 100644 --- a/src/components/App/Apps/dashboard/UnLockWallet.tsx +++ b/src/components/App/Apps/dashboard/UnLockWallet.tsx @@ -98,9 +98,9 @@ const UnLockWallet = () => { return ( - + - + { intl.formatMessage({id:'platform.overlay.unlocking'})} @@ -108,7 +108,7 @@ const UnLockWallet = () => { - + { - + { (password.length === 0 || passwordError ) && @@ -168,7 +168,7 @@ const UnLockWallet = () => { variant='elevated' color='primary' size="large" - sx={{ fontSize: '1.2rem', borderRadius: '2rem', padding: '0.9rem 2rem 0.9rem 2rem', fontFamily: "inherit"}} + sx={{ fontSize: '1.2rem', borderRadius: '2rem', width: '100%', padding: '0.9rem 2rem 0.9rem 2rem', fontFamily: "inherit"}} onClick={handleAddFruit} > {intl.formatMessage({id:'platform.unlock.button.forgot'})} diff --git a/src/components/App/Apps/dashboard/index-next.tsx b/src/components/App/Apps/dashboard/index-next.tsx index 76c83e7..594d387 100644 --- a/src/components/App/Apps/dashboard/index-next.tsx +++ b/src/components/App/Apps/dashboard/index-next.tsx @@ -13,6 +13,7 @@ import Box from '@mui/material/Box' import MenuItem from '@mui/material/MenuItem' import ListItemIcon from '@mui/material/ListItemIcon' import useAppState from "../../../../store/appState/useAppState" +import {setDAPPOpen, setIsUnlocked} from "../../../../store/appState/appStateActions" import UnLockWallet from './UnLockWallet' import CreateWallet from './CreateWallet' import Dialog from '@mui/material/Dialog' @@ -27,9 +28,11 @@ import NoDaemon from '../../NoDaemon/index' import Proxy from '../CONET-Proxy/index' import Miner from '../miner/index' import ManageProfiles from '../../PlatformModal/ManageProfiles/ManageProfiles' //"..//ManageProfiles/ManageProfiles" - +import HubIcon from '@mui/icons-material/Hub' +import NodeExplorer from '../nodeExplorer/nodeExplorer' import ProfileDropdown from '../../../UI/Dropdowns/ProfileDropdown/ProfileDropdown' import Container from '@mui/material/Container' +import store from '../../../../store/store' interface StyledTabsProps { children?: React.ReactNode value?: number @@ -135,48 +138,56 @@ const DashBoard = () => { isInitializing, setShowAppStore, locale, - + isNodeExplorerOpen, isModalOpen, setLocale, - + setIsNodeExplorerOpen, + dAPPOpen + } = useAppState() - const [menuValue, setMenuValue] = useState(1) + const [menuValue, setMenuValue] = useState(0) const [anchorEl, setAnchorEl] = useState() const openMenu = Boolean(anchorEl) const { mode, setMode } = useColorScheme() const [showProfileDropdown, setShowProfileDropdown] = useState(false) const ShowApp = () => { - - switch (true) { - case !hasContainer: { - return ( - - ) - } - case !isUnlocked : { - return ( - - ) - } + if (!hasContainer) { + return ( + + ) + } + if (!isUnlocked) { + return ( + + ) + } + - case !showAppStore: { - + switch (dAPPOpen) { + + case 'miner': { return ( ) } - case !localDaemon: { - return ( - - ) - } + case 'proxy': { + if (!localDaemon) { + return ( + + ) + } + return ( + + ) + + } default: { - return ( - + return ( + ) } } @@ -188,41 +199,40 @@ const DashBoard = () => { const animeCONET = () => { return ( - + ) } - - useEffect(() => { - if (isUnlocked) { - if (showAppStore) { - setMenuValue(1) - } else { - setMenuValue(0) - } - } - - },[]) - const handleChange = (event: SyntheticEvent|null, newValue: number) => { if (event !== null ) { - if (newValue ===0 ) { - if (showMiner) { - return - } - setMenuValue(newValue) - setShowAppStore(false) - return setShowMiner (true) - } - if (newValue ===1) { - if (showAppStore) { - return - } - setMenuValue(newValue) - setShowAppStore(true) - return setShowMiner (false) - } - + switch (newValue) { + case 0: { + setMenuValue(newValue) + if (dAPPOpen==='miner') { + return + } + + return store.dispatch(setDAPPOpen('miner')) + + } + case 1: { + setMenuValue(newValue) + if (dAPPOpen==='proxy') { + return + } + + return store.dispatch(setDAPPOpen('proxy')) + + } + default: { + setMenuValue(newValue) + if (dAPPOpen==='nodes') { + return + } + return store.dispatch(setDAPPOpen('nodes')) + } + } + } } @@ -248,17 +258,21 @@ const DashBoard = () => { isUnlocked && <> { - setShowMiner(true) - setShowAppStore(false) + store.dispatch(setDAPPOpen('miner')) }} sx={{ opacity: showMiner ? '1': '0.5'}} > { - setShowAppStore(true) - setShowMiner(false) + store.dispatch(setDAPPOpen('proxy')) }} sx={{ opacity: showAppStore ? '1': '0.5'}}> + + + { + store.dispatch(setDAPPOpen('nodes')) + }} sx={{ opacity: showAppStore ? '1': '0.5'}}> + } @@ -348,7 +362,7 @@ const DashBoard = () => { onChange={handleChange} sx={{ backgroundColor: mode === 'light' ? '#f0eddd': '#2d2d1e', - minWidth: '5.5rem', + width: '5.7rem', display:{xs: 'none', sm: 'flex', md: 'flex', xm: 'flex', lg: 'flex', xl: 'flex'}, paddingTop: '2rem' }} @@ -357,9 +371,9 @@ const DashBoard = () => { { isUnlocked && <> - } sx={{paddingBottom: '2rem'}} /> - } sx={{paddingBottom: '2rem'}}/> - + } sx={{paddingBottom: '2rem'}} /> + } sx={{paddingBottom: '2rem'}}/> + } sx={{paddingBottom: '2rem'}}/> } @@ -369,6 +383,7 @@ const DashBoard = () => { */} + { @@ -389,16 +404,16 @@ const DashBoard = () => { } }> - } sx={{ position: 'fixed', bottom: '0px', width: '1rem', fontSize: '30px'}}/> + + } sx={{ position: 'fixed', bottom: '0px'}}/> - - setShowProfileDropdown(false)} + maxWidth='xs' > { diff --git a/src/components/App/Apps/miner/assets/ADbig.png b/src/components/App/Apps/miner/assets/ADbig.png index 07fee1e..1571351 100644 Binary files a/src/components/App/Apps/miner/assets/ADbig.png and b/src/components/App/Apps/miner/assets/ADbig.png differ diff --git a/src/components/App/Apps/miner/index.tsx b/src/components/App/Apps/miner/index.tsx index 27e4299..0b4d97e 100644 --- a/src/components/App/Apps/miner/index.tsx +++ b/src/components/App/Apps/miner/index.tsx @@ -2,40 +2,82 @@ import { styled } from '@mui/material/styles' import { useIntl } from "react-intl" -import {Grid, CircularProgress, styled as materialStyled, TableContainer, Table, TableHead, TableRow, TableCell, TableBody} from '@mui/material' - - +import {Grid, CircularProgress, TextField, styled as materialStyled, TableContainer, Table, TableHead, TableRow, TableCell, TableBody, IconButton} from '@mui/material' import styledCom from "styled-components" import Paper from '@mui/material/Paper' import Box from '@mui/material/Box' import CloudQueueIcon from '@mui/icons-material/CloudQueue' +import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDown' +import KeyboardArrowRight from '@mui/icons-material/KeyboardArrowRight' import Slide from '@mui/material/Slide' import Typography from '@mui/material/Typography' import useAppState from "../../../../store/appState/useAppState" import miner2 from '../../../../assets/miner/FancyNyan.webp' import minerPause from '../../../../assets/miner/FancyNyanPause.png' -import {Stack, Link, IconButton, SvgIcon} from '@mui/material' +import {Stack, Link, SvgIcon} from '@mui/material' import Fab from '@mui/material/Fab' import CallMissedOutgoingIcon from '@mui/icons-material/CallMissedOutgoing' import DriveFolderUploadIcon from '@mui/icons-material/DriveFolderUpload' import DnsIcon from '@mui/icons-material/Dns' - +import {CopyToClipboard} from "../../../../utilities/utilities" import React, {useState, useEffect} from "react" -import {getCONETBalance, startLiveness, stopLiveness} from '../../../../API/index' +import {getCONETBalance, startLiveness, stopLiveness, isLivenessRunning, initOneTimeListenState, registerReferrer, referrerList} from '../../../../API/index' import {logger} from '../../logger' import {grey, lightGreen, blueGrey, green, red} from '@mui/material/colors' import boostImg from './assets/boost.gif' import { useTheme } from '@mui/material/styles' import {Tabs, Tab, Button, Divider} from '@mui/material-next' import {getWorkerService} from '../../../../services/workerService/workerService' - +import ContentCopyIcon from '@mui/icons-material/ContentCopy' +import MuiAccordion, { AccordionProps } from '@mui/material/Accordion' +import MuiAccordionDetails from '@mui/material/AccordionDetails' +import MuiAccordionSummary, { + AccordionSummaryProps, +} from '@mui/material/AccordionSummary' +import ArrowForwardIosSharpIcon from '@mui/icons-material/ArrowForwardIosSharp' import AD from './AD-1' const StyleDiv = styledCom.div` - ` +const Accordion = styled((props: AccordionProps) => ( + + ))(({ theme }) => ({ + border: `0px solid ${theme.palette.divider}`, + '&:not(:last-child)': { + borderBottom: 0, + }, + '&::before': { + display: 'none', + }, +})) + +const AccordionSummary = styled((props: AccordionSummaryProps) => ( + } + {...props} + /> + ))(({ theme }) => ({ + backgroundColor: + theme.palette.mode === 'dark' + ? 'rgba(255, 255, 255, .05)' + : 'rgba(0, 0, 0, .03)', + flexDirection: 'row-reverse', + '& .MuiAccordionSummary-expandIconWrapper.Mui-expanded': { + transform: 'rotate(90deg)', + }, + '& .MuiAccordionSummary-content': { + + marginLeft: theme.spacing(1), + }, +})) +const AccordionDetails = styled(MuiAccordionDetails)(({ theme }) => ({ + padding: theme.spacing(1), + borderTop: '1px solid rgba(0, 0, 0, .125)', +})) + const cntp_address = '0x0f43685B2cB08b9FB8Ca1D981fF078C22Fec84c5' @@ -69,7 +111,11 @@ const ItemStyle2 = styled(Paper)(() => ({ const CloudNode = ( check: boolean, setcheck: React.Dispatch>) => { const intl = useIntl() - + const { + locale + } = useAppState() + + return ( @@ -167,6 +213,34 @@ const CloudNode = ( check: boolean, setcheck: React.Dispatch + + + + { intl.formatMessage({id: 'platform.joinUS.miner.cloud.table.item7'})} + + + + + - + + + { intl.formatMessage({id: 'platform.joinUS.miner.cloud.table.item7-2'})} + + + + + { intl.formatMessage({id: 'platform.joinUS.miner.cloud.table.item8'})} + + + - + + + { intl.formatMessage({id: 'platform.joinUS.miner.cloud.table.item8-2'})} + + @@ -287,9 +361,10 @@ const Storage = (check: boolean,setcheck: React.Dispatch + sx={{ fontFamily:'inherit' }} + > - { intl.formatMessage({id: 'platform.joinUS.forDeveloper.button'})} + { intl.formatMessage({id: 'platform.joinUS.forDeveloper.button'})} @@ -366,7 +441,6 @@ const CustomTabPanel = (props: TabPanelProps) => { ) } - const currentProfile = () => { const workerService = getWorkerService() if (workerService.data.passcode.status === 'LOCKED') { @@ -379,10 +453,10 @@ const currentProfile = () => { return workerService.data.profiles[index] } - const Community_liveness = (CNTP: string, setCNTP: (v:string) => void, setTodayCNTP: (v:string) => void) => { const intl = useIntl() const [showLoader, setShowLoader] = useState(false) + const [firstLoader, setFirstLoader] = useState(0) const [showSameIPError, setShowSameIPError] = useState(false) const [showInstanceError, setShowInstanceError] = useState(false) const [minting, setMinting] = useState(false) @@ -397,21 +471,26 @@ const Community_liveness = (CNTP: string, setCNTP: (v:string) => void, setTodayC if (minting) { await stopLiveness() setShowLoader (false) + // setIslivenessRunning(false) return setMinting(false) } startLiveness((err, data ) => { - setShowLoader (false) - if (err) { + if (showLoader) { + setShowLoader (false) + } + + if (data[0] === 'FAILURE'||err) { clearError() - setMinting(false) return setShowInstanceError(true) } + if (!minting) { + setMinting(true) + } - setMinting(true) setCNTP(data[0]) setTodayCNTP(data[1]) - console.log (data) - + console.log ('showLoader0',data) + }) } @@ -422,6 +501,33 @@ const Community_liveness = (CNTP: string, setCNTP: (v:string) => void, setTodayC return () => { active = false } },[showLoader]) + useEffect(() => { + const fetchData = async () => { + if (!active) { + return + } + if (minting) { + return logger(`minting is true return!`) + } + + isLivenessRunning ((err, data ) => { + if (!data.length||err) { + return + } + + if (!minting) { + setMinting(true) + setCNTP(data[0]) + setTodayCNTP(data[1]) + } + }) + } + + let active = true + fetchData() + return () => { active = false } + },[minting]) + const clearError = () => { setTimeout(() => { setShowSameIPError(false) @@ -437,9 +543,14 @@ const Community_liveness = (CNTP: string, setCNTP: (v:string) => void, setTodayC { !showInstanceError && !showSameIPError && - - {intl.formatMessage({id: 'platform.miner.community.liveness.detail'})} - + + + {intl.formatMessage({id: 'platform.miner.community.liveness.detail'})} + + + + + } { @@ -485,24 +596,249 @@ const Community_liveness = (CNTP: string, setCNTP: (v:string) => void, setTodayC const Referrals_Miner = () => { const intl = useIntl() + const workservice = getWorkerService() + const currentProfile = () => { + if (workservice.data.passcode.status === 'LOCKED') { + return null + } + const index = workservice.data.profiles.findIndex((n:any) => { + return n.isPrimary + }) + return workservice.data.profiles[index] + } + const { + activeProfile + } = useAppState() + + const [showReferrer, setShowReferrer] = useState(currentProfile().referrer) + const [input, setInput] = useState('') + const [inputShowError, setInputShowError] = useState(false) + const [loading, setLoading] = useState(false) + const referralsLink = activeProfile ? window.location.origin+'/?referral=' + activeProfile.keyID.toLowerCase(): '' + const keyUpHandler = (event: React.KeyboardEvent) => { + const key = event.key + setInputShowError(false) + if (key == 'Enter') { + return _registerReferrer() + } + } + const _registerReferrer = async () => { + setLoading(true) + const [success, kkkk ] =await registerReferrer(input) + + setLoading(false) + if (success!= 'SUCCESS') { + setTimeout(() => { + setInputShowError (false) + }, 3000) + return setInputShowError (true) + } + + + } + initOneTimeListenState('referrer', setShowReferrer) return ( - + + {intl.formatMessage({id: 'platform.miner.community.referral.detail'})} - + + {intl.formatMessage({id: 'platform.miner.community.referral.detail1'})} + + + {intl.formatMessage({id: 'platform.miner.community.referral.detail1-1'})} + + + {intl.formatMessage({id: 'platform.miner.community.referral.detail2'})} + + + {intl.formatMessage({id: 'platform.miner.community.referral.detail2-1'})} + + + { + (!showReferrer || !showReferrer?.length ) && + + { + setInput(e.target.value) + }} + error ={inputShowError} + onKeyUp={keyUpHandler} + /> + { + !loading && !inputShowError && + + } + { + loading && + + + + } + + + + } + { + showReferrer && + <> + + {intl.formatMessage({id: 'platform.miner.community.liveness.yourReferrer'})} + + + {showReferrer} + + + + } + + + { + activeProfile && + + + {intl.formatMessage({id: 'platform.miner.community.referral.link'})} + + + + {referralsLink} + + + CopyToClipboard(referralsLink) + } + > + + + + + } + ) } + +const Referrals_Table = () => { + const [listValve, setListValve] = React.useState([]) + const [expanded, setExpanded] = React.useState('') + + const intl = useIntl() + useEffect(() => { + + const fetchData = async () => { + if (!active) { + return + } + const [success, data] = await referrerList() + if (success === 'SUCCESS') { + setListValve (data[0]) + } + } + let active = true + fetchData() + return () => { active = false } + }, []) + + const handleChange = + (panel: string) => (event: React.SyntheticEvent, newExpanded: boolean) => { + setExpanded(newExpanded ? panel : false); + } + + const Row = (props: { row: string}) => { + const { row } = props + const [open, setOpen] = React.useState(false) + return ( + + *': { borderBottom: 'unset' } }}> + + setOpen(n => !n)} + > + {open ? : } + + + + + {row} + + + + ) + } + + return ( + + { + + listValve.length === 0 && + + + {intl.formatMessage({id: 'platform.miner.register.referralsEmpty'})} + + + + } + { + // listValve.length >0 && + // + // + // + // { + // listValve.map(n => ( + // + // )) + // } + // + //
+ //
+ } + { + listValve.length >0 && + + listValve.map(n => ( + + + + {n} + + + + + + + )) + + + + } + +
+ + ) +} + const Community = (CNTP: string, setCNTP:(v: string) => void, setTodayCNTP:(v: string) => void) => { const intl = useIntl() const [value, setValue] = React.useState(0) @@ -518,6 +854,7 @@ const Community = (CNTP: string, setCNTP:(v: string) => void, setTodayCNTP:(v: s return ( + {intl.formatMessage({id: 'platform.miner.community.title'})} @@ -531,6 +868,7 @@ const Community = (CNTP: string, setCNTP:(v: string) => void, setTodayCNTP:(v: s allowScrollButtonsMobile> +
@@ -546,6 +884,13 @@ const Community = (CNTP: string, setCNTP:(v: string) => void, setTodayCNTP:(v: s
+ + + + + + + @@ -696,6 +1041,7 @@ const DashBoardpanel = (cntp: string, todayCNTP: string) => { }, []) + const intl = useIntl() const addMateMask = async() => { try { @@ -704,8 +1050,8 @@ const DashBoardpanel = (cntp: string, todayCNTP: string) => { .request({ method: "wallet_addEthereumChain", params: [{ - chainId: "0x36CA6", - rpcUrls: ["https://rpc1.conet.network/"], + chainId: "0x36CB1", + rpcUrls: ["https://holeskyrpc1.conet.network"], chainName: "CONET Sebolia", nativeCurrency: { name: "CONET", @@ -794,15 +1140,14 @@ const DashBoardpanel = (cntp: string, todayCNTP: string) => { const Miner = () => { const { - locale, - + locale } = useAppState() const [minerReward, setMinerReward] = useState(0) const [minting, setMinting] = useState(false) const intl = useIntl() const [CONET_balance, setCONET_balance] = useState(0) - const [showNodeMiner, setShowNodeMiner] = useState(false) + const [showNodeMiner, setShowNodeMiner] = useState(true) const [showBosste, setShowBosste] = useState(false) const [walletAddress, setWalletAddress] = useState('') const [totalRewards, setTotalRewards]= useState('0') @@ -810,6 +1155,7 @@ const Miner = () => { const [referrals, setReferrals]= useState('0') const [cntp, setCntp] = useState('0') const [todayCntp, setTodayCntp] = useState('0') + useEffect(() => { const fetchData = () => { if (!active) { diff --git a/src/components/App/Apps/nodeExplorer/miner.gif b/src/components/App/Apps/nodeExplorer/miner.gif new file mode 100644 index 0000000..ecdaa2e Binary files /dev/null and b/src/components/App/Apps/nodeExplorer/miner.gif differ diff --git a/src/components/App/Apps/nodeExplorer/nodeExplorer.tsx b/src/components/App/Apps/nodeExplorer/nodeExplorer.tsx new file mode 100644 index 0000000..7f5de1a --- /dev/null +++ b/src/components/App/Apps/nodeExplorer/nodeExplorer.tsx @@ -0,0 +1,329 @@ +import {Grid, CircularProgress, styled as materialStyled, TableContainer,SvgIcon, Table, Link, Paper, TableHead, TableRow, TableCell, TableBody, Typography, Stack, Box, Icon, Fade} from '@mui/material' +import { useIntl } from "react-intl" +import React, {useState, useEffect} from "react" +import { initListenState, getAllNodes} from '../../../../API/index' +import WalletIcon from '@mui/icons-material/Wallet' +import { LogoIcon, LogoText} from "../../../../components/UI/Logo/Logo" +import { red, blueGrey, blue, green, grey } from '@mui/material/colors' +import PublicIcon from '@mui/icons-material/Public' +import {US,JP, SG, AU, CA, KR, IN, IE, SE} from 'country-flag-icons/react/3x2' +import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js' +import { loadCSS } from 'fg-loadcss' +import { Pie } from 'react-chartjs-2' +import {FontAwesomeIcon} from '@fortawesome/react-fontawesome' +import { faContao } from '@fortawesome/free-brands-svg-icons' +import { Container, createStyles, makeStyles } from "@mui/material" +import BrightnessLowIcon from '@mui/icons-material/BrightnessLow' + +ChartJS.register(ArcElement, Tooltip, Legend) +const ItemStyle = materialStyled(Paper)(() => ({ + textAlign: 'center', + borderRadius: '1rem', + + padding: '0.5rem', + height: '4rem' +})) + +const ItemStylePie = materialStyled(Paper)(() => ({ + textAlign: 'center', + borderRadius: '1rem', + padding: '0.5rem', + height: '23rem' +})) + +interface nodeType { + ip_addr: string + minerAddr: string + running: boolean + wallet_addr: string + balance: string + country: string +} +interface pieDatasets { + label: string + data: number[] + backgroundColor: string[] + borderColor: string[] + borderWidth: number +} +interface pieData { + labels: string[] + datasets: pieDatasets[] +} + +const countryGetIcon = (country: string) => { + switch (country) { + case 'US': { + return + } + case 'AU': { + return + } + case 'CA': { + return + } + case 'KR': { + return + } + case 'IN': { + return + } + case 'IE': { + return + } + case 'SE': { + return + } + case 'SG': { + return + } + case 'JP': { + return + } + } + + +} + +const PieChart = (minted: number) => { + const totalCNTP = 100000000 + const balance = totalCNTP - minted + const intl = useIntl() + const data: pieData = { + labels: [ + intl.formatMessage({id: 'platform.conet.explorer.CNTP.balance'}), + intl.formatMessage({id: 'platform.conet.explorer.CNTP.mint'}), + ], + datasets: [{ + label: '', + data: [balance, minted], + backgroundColor: [ + '#6e7b63', + '#a1b095', + ], + //@ts-ignore + hoverOffset: 0, + borderWidth: 0.5, + }] + } + + return ( + + { + minted > 0 && + + } + + + ) +} + +const Overview = () => { + const intl = useIntl() + const [lastBlock, setLastBlock] = useState(0) + const [nodes, setNodes] = useState(0) + const [runningNodes, setRunningNodes] = useState(0) + const [walletCounting, setWalletCounting] = useState(0) + const [CNTPBalance, setCNTPBalance] = useState('') + const [CNTPMint, setCNTPMint] = useState(0) + const [nodesDetail, setNodesDetail] = useState([]) + + + const setDates = (data: any) => { + setCNTPMint(n => data.balance.toFixed(0)) + const bala = (((100000000-data.balance)/100000000)*100).toFixed(2) + setCNTPBalance(n => bala.toString()+'%') + const nodes: nodeType[] = data.nodes + + if (nodes?.length > 1) { + setNodesDetail(n => data.nodes) + + nodes.sort((a,b) =>parseFloat(b.balance) - parseFloat(a.balance)) + setNodes(nodes.length) + const running = nodes.filter(n => n.running) + setRunningNodes(n => running.length) + } + + + } + + useEffect(() => { + + const fetchData = async () => { + if (!active) { + return + } + fetch('https://scan.conet.network/api/v2/stats', { + method: 'GET', + headers: { + 'Content-Type': 'application/json;charset=UTF-8', + 'Connection': 'close', + }, + cache: 'no-store', + referrerPolicy: 'no-referrer' + }) + .then ( async res => res.json()) + .then( async data => { + console.log (data) + setLastBlock(data.total_blocks) + setWalletCounting(data.total_addresses) + const [succes, nodes] = await getAllNodes() + setDates(nodes[0]) + initListenState('cntp-balance', data => { + return setDates(data) + }) + }) + const node = loadCSS( + 'https://use.fontawesome.com/releases/v6.5.1/css/all.css', + // Inject before JSS + //@ts-ignore + document.querySelector('#font-awesome-css') || document.head.firstChild) + + return () => { + node.parentNode!.removeChild(node) + }; + } + + let active = true + fetchData() + return () => { active = false } + + }, []) + + return ( + <> + + + + + {intl.formatMessage({id: 'platform.conet.explorer.lastBlock'})} + + + + {lastBlock} / {walletCounting} + + + + + + + + + + + {intl.formatMessage({id: 'platform.conet.explorer.nodes'})} + + + + {nodes} / {runningNodes} + + + + + + + + + + {intl.formatMessage({id: 'platform.conet.explorer.CNTP'})} 100,000,000 + + + {PieChart(CNTPMint)} + + + + + + + + + {intl.formatMessage({id: 'platform.conet.explorer.CNTP.relayNodes'})} + + + + + + + + { + !nodesDetail.length && + + + + } + { + nodesDetail.map(n => ( + + + + {n.wallet_addr.substring(0,5)+'....'+ n.wallet_addr.substring(37)} + + + + + {n.ip_addr} + + + {countryGetIcon(n.country)} + + + + + + + 0}> + + {n.balance} + + + + + + + + + + + + )) + } + +
+
+ +
+ + ) +} + +const NodeExplorer = () => { + const intl = useIntl() + return ( + + + + {intl.formatMessage({id: 'platform.conet.explorer.title'})} + + + + < Overview/> + + + ) +} + +export default NodeExplorer \ No newline at end of file diff --git a/src/components/UI/Dropdowns/ProfileDropdown/CurrentProfileItem/CurrentProfileItem.tsx b/src/components/UI/Dropdowns/ProfileDropdown/CurrentProfileItem/CurrentProfileItem.tsx index d234aeb..ca5cc55 100644 --- a/src/components/UI/Dropdowns/ProfileDropdown/CurrentProfileItem/CurrentProfileItem.tsx +++ b/src/components/UI/Dropdowns/ProfileDropdown/CurrentProfileItem/CurrentProfileItem.tsx @@ -76,19 +76,6 @@ const StyledProfileKeyIdCopy = styled.button` margin-left: 0.1rem; ` - -const RightToolIcon = styled.div` - cursor: pointer; - margin-left: 1rem; -` -const Item = styled(Box)(({ theme }) => ({ - backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff', - ...theme.typography.body2, - padding: theme.spacing(1), - textAlign: 'center', - color: theme.palette.text.secondary, -})) - const CurrentProfileItem = ({closeDropdown, syncAsset}: ProfileDropdownProps ) => { const [showMetaMask, setShowMetaMask] = useState(false) const [showPrivateKey, setShowPrivateKey] = useState(false) @@ -128,11 +115,11 @@ const CurrentProfileItem = ({closeDropdown, syncAsset}: ProfileDropdownProps ) = .request({ method: "wallet_addEthereumChain", params: [{ - chainId: "0x36CA6", - rpcUrls: ["https://rpc1.conet.network/"], - chainName: "CONET Sebolia", + chainId: "0x36CB1", + rpcUrls: ["https://HoleskyRpc1.conet.network"], + chainName: "CONET Holesky", nativeCurrency: { - name: "CONET", + name: "CONET Holesky", symbol: "CONET", decimals: 18 }, @@ -150,12 +137,10 @@ const CurrentProfileItem = ({closeDropdown, syncAsset}: ProfileDropdownProps ) = const [loading, setLoading] = useState(false) - const theme = useTheme() - const {setIsModalOpen, clientProfiles, setActiveProfile, activeProfile} = useAppState() return ( - - + + {/* { setIsModalOpen('profilesList') @@ -164,8 +149,8 @@ const CurrentProfileItem = ({closeDropdown, syncAsset}: ProfileDropdownProps ) = */} - - + + { currentProfile.nickName || intl.formatMessage({id: 'platform.ProfileDropdown.CurrentProfileItem.AnonymousUser'})} @@ -225,9 +210,6 @@ const CurrentProfileItem = ({closeDropdown, syncAsset}: ProfileDropdownProps ) = - - - } diff --git a/src/components/UI/Dropdowns/ProfileDropdown/ProfileDropdown.tsx b/src/components/UI/Dropdowns/ProfileDropdown/ProfileDropdown.tsx index 95e5fc8..eae624e 100644 --- a/src/components/UI/Dropdowns/ProfileDropdown/ProfileDropdown.tsx +++ b/src/components/UI/Dropdowns/ProfileDropdown/ProfileDropdown.tsx @@ -35,10 +35,10 @@ import CloseIcon from '@mui/icons-material/Close' import CallReceivedIcon from '@mui/icons-material/CallReceived' import ContentCopyIcon from '@mui/icons-material/ContentCopy' import {CopyToClipboard} from "../../../../utilities/utilities" - import CoNETSINodeSetup from './conet-si/CoNET_SI_SETUP' - import ListItemText from '@mui/material/ListItemText' +import {faucet, initOneTimeListenState, scanAssets} from '../../../../API/index' + export type Profiles = Array @@ -100,7 +100,7 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { const GasToEth = 0.00000001 const {setIsModalOpen, clientProfiles, setActiveProfile, activeProfile} = useAppState() - const workerService = getWorkerService() + let workerService = getWorkerService() const currentProfile = () => { if (workerService.data.passcode.status === 'LOCKED') { @@ -139,18 +139,25 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { const [showAssetBalance_balance, setshowAssetBalance_balanc] = useState('') const [showCoNET_SI_setup_Badge, setShowCoNET_SI_setup_Badge] = useState(0) const [showPage, setShowPage] = useState(false) + const [showLowCONETBalance, setShowLowCONETBalance] = useState(false) + const [oldBalance, setOldBalance] = useState(0) + const [getFaucetWaiting, setGetFaucetWaiting] = useState('') - const init = () => { + const init = async () => { const current = currentProfile() if (!current) { return } setShowPage(true) + await syncAsset() if (!current?.network) { setShowCoNET_SI_setup_Badge (1) } conetToken = current.tokens.conet setshowAssetBalance_balanc(conetToken.balance) + if (conetToken.balance < 0.001) { + setShowLowCONETBalance(true) + } } const shortToAddr = (addr: string|undefined) => { if (!addr) { @@ -164,29 +171,28 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { const currentProfile1 = currentProfile() const currentAsset = reflashAssetList()[currectAsset] switch (currentAsset.primary) { - case 'CoNET': { + case 'CONET': { return setCurrentAssetHistorys (currentProfile1.tokens.conet.history) } - case 'USDC': { - return setCurrentAssetHistorys (currentProfile1.tokens.usdc.history) - } + default: { - const _history: any = [] - workerService.data.CoNETCash.assets.forEach((n: any) => { - if ( n.history && n.history.length ) { - n.history.forEach ((nn:any) => { - _history.push (nn) - }) - } + return setCurrentAssetHistorys (currentProfile1.tokens.cntp.history) + // const _history: any = [] + // workerService.data.CoNETCash.assets.forEach((n: any) => { + // if ( n.history && n.history.length ) { + // n.history.forEach ((nn:any) => { + // _history.push (nn) + // }) + // } - }) - _history.sort ((a: any, b: any) => { - const aa = new Date(a.time) - const bb = new Date(b.time) - return aa > bb - - }) - return setCurrentAssetHistorys (_history) + // }) + // _history.sort ((a: any, b: any) => { + // const aa = new Date(a.time) + // const bb = new Date(b.time) + // return aa > bb + + // }) + // return setCurrentAssetHistorys (_history) } } @@ -223,20 +229,15 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { const ret = [ { - primary: 'CoNET', + primary: 'CONET', balance: currentProfile().tokens.conet.balance, icon: }, - // { - // primary: 'CoNETCash', - // balance: workerService.data?.CoNETCash ? workerService.data.CoNETCash.Total : 0, - // icon: , - // }, - // { - // primary: 'USDC', - // balance: currentProfile().tokens.usdc.balance, - // icon: , - // } + { + primary: 'CNPT', + balance: currentProfile().tokens.cntp.balance, + icon: + } ] return ret } @@ -246,32 +247,45 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { return amountVal + fees } - const getFaucet = () => { - if ( !workerService.method?.getFaucet) { - return - } + const getFaucet = async () => { setLoading (true) - return workerService.method.getFaucet (currentProfile().keyID) - .then (async n => { - const [status, check] = n - setLoading(false) - - if (status === 'SUCCESS') { - await syncAsset () - setResultSuccess (true) - return setSendStep (1) - } - return setResultError(true) - }) + const profile = currentProfile() + const oldBalance = parseFloat(profile.tokens.conet.balance) + + initOneTimeListenState('conet', () => { + workerService = getWorkerService() + const profileNew = currentProfile() + const conetBalance = parseFloat(profileNew.tokens.conet.balance) + if (conetBalance - oldBalance > 0.001) { + setshowAssetBalance_balanc(profileNew.tokens.conet.balance) + setResultSuccess (true) + setSendStep (1) + return setLoading (false) + } + setTimeout (() => scanAssets(), 1000) + + }) + + + const [success] = await faucet() + if (success !== 'SUCCESS') { + setLoading(false) + return setResultError(true) + } + scanAssets() + } const syncAsset = () => { + setLoading(true) return new Promise ( async (resolve)=> { if ( !workerService.method?.syncAsset) { + setLoading(false) return resolve (null) } - const [ status, data ] = await workerService.method?.syncAsset () + const [ status, data ] = await workerService.method.syncAsset () + setLoading(false) const assetList = reflashAssetList() setshowAssetBalance_balanc(assetList[currectAsset].balance) return resolve (null) @@ -372,15 +386,11 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { let asset = '' switch (currectAsset) { case 0: { - asset = 'CoNET' - break - } - case 1: { - asset = 'CoNETCash' + asset = 'CONET' break } default : { - asset = 'USDC' + asset = 'COPT' } } return workerService.method?.sendAsset(currentProfile().keyID, amountVal, toAddr, asset) @@ -412,7 +422,7 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { }} > {icon} - + @@ -486,6 +496,8 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { const BottomNavigationChanged = (event: any, newValue: number) => { setButtonNavigationCurrent(newValue) const current = reflashAssetList()[currectAsset] + const conetBalance = parseFloat( reflashAssetList()[0].balance) + switch (current.primary) { case 'USDC' : { if ( newValue === 2) { // buy USDC @@ -518,9 +530,13 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { return setShowCoNETCashsendFrom (true) } - + // CNPT default: { - break + if (conetBalance > 0.001) { + setShowLowCONETBalance(false) + break + } + setShowLowCONETBalance(true) } } } @@ -609,46 +625,16 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { } return ( + + - - - + - - {/* - - - - - - - - - {intl.formatMessage({id: 'platform.ProfileDropdown.SI.network.title'})} - - - - - - */} - - - { - - } - + { showAssetBalance && // Asset balance @@ -660,8 +646,8 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { { buttonNavigationCurrent === 0 && sendStep < 1 && // Faucet Information before send - - + + {intl.formatMessage({id: 'platform.ProfileDropdown.faucet.limited'})} @@ -670,12 +656,12 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { { resultSuccess && // success <> - + {intl.formatMessage({id: 'platform.ProfileDropdown.faucet.success'})} - + - - - - USDC}} - sx={{ width: '100%'}} - /> - - + } - { - showCoNETCashBuyFrom && !resultError && !resultSuccess && - <> - { - /error/.test(amountTextFieldID) && - - - {intl.formatMessage({id:'platform.ProfileDropdown.CoNETCash.amountError'})} - - - } - - - - { - let val = parseFloat(e.target.value) - setAmountTextFieldID('standard-basic') - if ( isNaN(val) || val < 0 ) { - return setAmountVal(0) - } - - setAmountVal(val) - if ( val + fees > reflashAssetList()[2].balance|| val > 100|| val < 10) { - return setAmountTextFieldID('standard-error') - } - - - }} - /> - - - - - } { - showHistoryDetail && + showHistoryDetail && // HistoryDetail @@ -1072,7 +947,6 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { - } @@ -1089,9 +963,9 @@ const ProfileDropdown = ({closeDropdown}: ProfileDropdownProps) => { } { - buttonNavigationCurrent > -1 && !loading && !resultError && !resultSuccess && // Process button bar + buttonNavigationCurrent > -1 && !loading && !resultError && !resultSuccess && // Process button bar - +