Skip to content

Commit

Permalink
conet-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
CoNETProject committed Oct 19, 2023
1 parent de7ee17 commit 79cb4fc
Show file tree
Hide file tree
Showing 22 changed files with 1,430 additions and 217 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"@conet.project/seguro-worker-lib": "0.13.8",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.14.12",
"@mui/material": "^5.14.12",
"@mui/icons-material": "^5.14.13",
"@mui/material": "^5.14.13",
"@react-icons/all-files": "^4.1.0",
"@tippyjs/react": "^4.2.6",
"buffer": "^6.0.3",
Expand All @@ -43,7 +43,10 @@
"react-lottie-player": "^1.5.5",
"react-router-dom": "^6.16.0",
"uuid": "^9.0.1",
"web-vitals": "^3.5.0"
"web-vitals": "^3.5.0",
"country-flag-icons": "^1.5.7",
"react-terminal-ui": "^1.0.5"

},
"devDependencies": {
"@reduxjs/toolkit": "^1.9.7",
Expand Down
34 changes: 34 additions & 0 deletions src/assets/logo/CoNET_logo_white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 2 additions & 33 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {Overlay, OverlayWithLoaderText} from '../UI/Common/Overlay/Overlay'

const StyledContainer = styled.div`
height: 100vh;
Expand All @@ -19,7 +18,6 @@ const StyledContainer = styled.div`
color: black;
`


const App = () => {
const {
dAPPInitialize,
Expand Down Expand Up @@ -114,38 +112,9 @@ const App = () => {
<MainScreen/>
)
}
// let content = <MainScreen/>
// // launch screen
// if (appState.isInitializing) {
// content = (
// <LaunchScreen/>
// )
// } else if (appState.isInitialized && appState.noContainer) {
// content = (
// <OnboardingPageProvider
// existingPages={['language', 'setPasscode', 'confirmPasscode', 'verification', 'verificationProcess']}>
// <OnboardingScreen/>
// </OnboardingPageProvider>
// )
// } else if (appState.isInitialized && appState.hasContainer && appState.isLocked) {
// content = (
// <UnlockScreen/>
// )
// }

}

// // unlock screen
// else if (appState.isInitialized && appState.isLocked) {
// content = (
// <UnlockScreen />
// )
// }
// // main screen
// else if (appState.isInitialized && appState.isUnlocked) {
// content = (
// <MainScreen />
// )
// }

return (
<>
Expand All @@ -165,4 +134,4 @@ const App = () => {
)
}

export default App
export default App
187 changes: 187 additions & 0 deletions src/components/App/Apps/API/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@

import {v4} from 'uuid'
import {logger} from '../../../../components/App/logger'

type WorkerCommandErrorType = 'NOT_READY'|'INVALID_DATA'|
'NO_UUID'|'INVALID_COMMAND'|'OPENPGP_RUNNING_ERROR'|
'PouchDB_ERROR'|'GENERATE_PASSCODE_ERROR'|'FAILURE'|'COUNTDOWN'

type WorkerCommandType = 'READY'|'encrypt_TestPasscode'|'getCONETBalance'|'getRegiestNodes'|
'encrypt_createPasscode'|'encrypt_lock'|'encrypt_deletePasscode'|'storePreferences'|
'newProfile'|'storeProfile'|'invitation'|'WORKER_MESSAGE'|
'isAddress'|'getFaucet'|'syncAsset'|'sendAsset'|'getUSDCPrice'|
'buyUSDC'|'mintCoNETCash'|'getSINodes'|'getRecipientCoNETCashAddress'|
'getUserProfile'|'sendMessage'|'setRegion'

export type WorkerCallStatus = 'SUCCESS' | 'NOT_READY' | 'UNKNOWN_COMMAND' |
'TIME_OUT' | 'SYSTEM_ERROR'
export type PasscodeStatus = 'LOCKED' | 'UNLOCKED' | 'NOT_SET'
export type ColorTheme = 'LIGHT' | 'DARK'
export type Language = 'en-CA' | 'fr-CA' | 'ja-JP' | 'zh-CN' | 'zh-TW'
export type secondVerificationValume = '1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
export type SeguroNetworkStatus = WorkerCallStatus |
'TIMEOUT_EMAIL_SERVER' | 'TIMEOUT_SEGURO_NETWORK' |
'NO_INTERNET' | 'CONNECTING_ACCESS_POINT' |
'CONNECTING_SEGURO_NETWORK'|'INIT'|'NOT_STRIPE'|
'LOCAL_SERVER_ERROR'|'INVITATION_CODE_ERROR'|
'SEGURO_ERROR'|'UNKNOW_ERROR'|'SEGURO_DATA_FORMAT_ERROR'

/*eslint-disable */
export interface profile {
bio: string
nickname: string
keyID?: string
tags: string[]
alias: string
isPrimary: boolean
profileImg: string
}

export type passcodeUnlockStatus =
[status: 'FAILURE' | 'COUNTDOWN' | WorkerCallStatus, payload?: ContainerData]

export type SINodesSortby = 'CUSTOMER_REVIEW'|'TOTAL_ONLINE_TIME'|
'STORAGE_PRICE_LOW'|'STORAGE_PRICE_HIGH'|'OUTBOUND_PRICE_HIGH'|'OUTBOUND_PRICE_LOW'

export type SINodesRegion = 'USA'|'UK'|'ES'|'DE'

export interface ContainerData {
method: {
testPasscode?: (
passcode: string,
progressCallback: ( progressInteger: string, progressFractional: string ) => void
) => Promise <passcodeUnlockStatus>
createPasscode?: (
passcode: string,
progressCallback: ( progressInteger: string, progressFractional: string ) => void
) => Promise <[WorkerCallStatus, ContainerData?]>
deletePasscode?: () => Promise <[WorkerCallStatus, ContainerData?]>
lock?: () => Promise <[WorkerCallStatus, ContainerData?]>
storePreferences?: () => Promise <[WorkerCallStatus, ContainerData?]>
newProfile?: (profile: profile) => Promise<StartWorkerResolve>
storeProfile?: () => Promise<StartWorkerResolve>
isAddress?: (address: string) => Promise <StartWorkerResolve>
getFaucet?: (address: string) => Promise <StartWorkerResolve>
syncAsset?: () => Promise<StartWorkerResolve>
sendAsset?: (sendAddr: string, total: number, toAddr: string, asset: string ) => Promise<StartWorkerResolve>
getUSDCPrice?: () => Promise<StartWorkerResolve>
buyUSDC?: (conetVal: number, keyID: string) => Promise<StartWorkerResolve>
mintCoNETCash?: (usdcVal: number, keyID: string ) => Promise<StartWorkerResolve>
getSINodes?: (sortby: SINodesSortby, region: SINodesRegion) => Promise < StartWorkerResolve >
getRecipientCoNETCashAddress?: (amount: number, callback: any) => Promise<StartWorkerResolve>
getUserProfile?: (keyID: string) => Promise<StartWorkerResolve>
sendMessage?: (keyAddress: string, message: string ) => Promise<StartWorkerResolve>
listening?: (data: any) => void
}
status: PasscodeStatus
data: any
preferences: any
}

export interface WorkerCommand {
cmd: WorkerCommandType
data?: any
uuid: string
err?: WorkerCommandErrorType
}

export type regionType = {
us: boolean,
uk: boolean,
ge: boolean,
sp: boolean,
fr: boolean
}

export type CreatePasscodeResolve =
[status: WorkerCallStatus, updateProgress?: ( percentage: number ) => void ]

export type StartWorkerResolve = [WorkerCallStatus, ContainerData?]
type StartWorkerResolveForAPI = [WorkerCallStatus, any []]

const channelWrokerListenName = 'toMainWroker'



export class CONET_Platfrom_API {

private postMessage = (cmd: WorkerCommand, resolve: (value: StartWorkerResolveForAPI | PromiseLike<StartWorkerResolveForAPI>) => void) => {

const channel = new BroadcastChannel(channelWrokerListenName)
const listenChannel = new BroadcastChannel(cmd.uuid)

const kk = (e: any) => {
listeningChannel(e.data, cmd.uuid, resolve)
}

const listeningChannel = (data: any, uuid: string, resolve: (value: StartWorkerResolveForAPI | PromiseLike<StartWorkerResolveForAPI>) => void) => {
let cmd: WorkerCommand

try{
cmd = JSON.parse(data)
} catch (ex) {
// 'searchPage.tsx', 'checkLinkedUrl ifram is NULL'
return logger ('class CONET_Platfrom_API', `listeningChannel JSON.parse(data) Error`)
}

listenChannel.close()

if (cmd.err) {
return resolve(['SYSTEM_ERROR', cmd.data])
}

return resolve(['SUCCESS', cmd.data])
}

listenChannel.addEventListener('message', kk)
channel.postMessage(JSON.stringify(cmd))
channel.close()
}

constructor () {
}

public faucet (): Promise < StartWorkerResolveForAPI > {
return new Promise( resolve => {
const cmd: WorkerCommand = {
cmd: 'getFaucet',
data: [],
uuid: v4()
}
return this.postMessage (cmd, resolve)
})
}

public getCONETBalance (): Promise < StartWorkerResolveForAPI > {
return new Promise( resolve => {
const cmd: WorkerCommand = {
cmd: 'getCONETBalance',
uuid: v4()
}
return this.postMessage (cmd, resolve)
})
}

public setRegion(region: regionType): Promise < StartWorkerResolveForAPI > {
return new Promise( resolve => {
const cmd: WorkerCommand = {
cmd: 'setRegion',
uuid: v4(),
data: [region]
}
return this.postMessage (cmd, resolve)
})
}

public getRegiestNodes () : Promise < StartWorkerResolveForAPI >{
return new Promise( resolve => {
const cmd: WorkerCommand = {
cmd: 'getRegiestNodes',
uuid: v4(),
data: []
}
return this.postMessage (cmd, resolve)
})
}

}
3 changes: 1 addition & 2 deletions src/components/App/Apps/Browser/TodoContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ const TodoContext = createContext<TodosContextProps> ({

})

export default TodoContext

export default TodoContext
Loading

0 comments on commit 79cb4fc

Please sign in to comment.