Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
CoNETProject committed Nov 18, 2023
1 parent db6c029 commit 0066ddf
Show file tree
Hide file tree
Showing 65 changed files with 2,928 additions and 1,993 deletions.
56 changes: 30 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,64 +26,68 @@
"build-storybook": "build-storybook -s public"
},
"dependencies": {
"@conet.project/seguro-worker-lib": "0.13.8",
"@conet.project/seguro-worker-lib": "0.13.9",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.14.15",
"@mui/material": "^5.14.15",
"@mui/icons-material": "^5.14.16",
"@mui/material": "^5.14.17",
"@mui/lab": "^5.0.0-alpha.153",
"primereact": "^10.0.9",
"@react-icons/all-files": "^4.1.0",
"@tippyjs/react": "^4.2.6",
"buffer": "^6.0.3",
"dayjs": "^1.11.10",
"framer-motion": "^10.16.4",
"get-port": "^7.0.0",
"react-draggable": "^4.4.6",
"react-hot-toast": "^2.4.1",
"react-loader-spinner": "^5.4.5",
"react-lottie-player": "^1.5.5",
"react-router-dom": "^6.17.0",
"react-router-dom": "^6.18.0",
"uuid": "^9.0.1",
"web-vitals": "^3.5.0",
"country-flag-icons": "^1.5.7"
"country-flag-icons": "^1.5.7",
"@webcontainer/api": "^1.1.8"


},
"devDependencies": {
"@reduxjs/toolkit": "^1.9.7",
"@storybook/addon-actions": "^7.5.1",
"@storybook/addon-essentials": "^7.5.1",
"@storybook/addon-links": "^7.5.1",
"@storybook/node-logger": "^7.5.1",
"@storybook/preset-create-react-app": "^7.5.1",
"@storybook/react": "^7.5.1",
"@storybook/addon-actions": "^7.5.3",
"@storybook/addon-essentials": "^7.5.3",
"@storybook/addon-links": "^7.5.3",
"@storybook/node-logger": "^7.5.3",
"@storybook/preset-create-react-app": "^7.5.3",
"@storybook/react": "^7.5.3",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.0.0",
"@testing-library/react": "^14.1.0",
"@testing-library/user-event": "^14.5.1",
"@types/jest": "^29.5.6",
"@types/node": "^20.8.8",
"@types/react": "^18.2.31",
"@types/react-document-meta": "^3.0.4",
"@types/react-dom": "^18.2.10",
"@types/jest": "^29.5.8",
"@types/node": "^20.9.0",
"@types/react": "^18.2.37",
"@types/react-document-meta": "^3.0.5",
"@types/react-dom": "^18.2.15",
"@types/react-router-dom": "^5.3.3",
"@types/styled-components": "^5.1.28",
"@types/uuid": "^9.0.4",
"@types/styled-components": "^5.1.30",
"@types/uuid": "^9.0.7",
"babel-loader": "^9.1.3",
"concurrently": "^8.2.1",
"concurrently": "^8.2.2",
"buffer": "^6.0.3",
"cors": "^2.8.5",
"electron":"^26.2.4",
"electron":"^27.0.4",
"eslint-plugin-react-hooks": "^4.6.0",
"express": "^4.18.2",
"modern-normalize": "^2.0.0",
"react": "^18.2.0",
"react-document-meta": "^3.0.0-beta.2",
"react-dom": "^18.2.0",
"react-icons": "^4.11.0",
"react-intl": "^6.5.1",
"react-intl": "^6.5.2",
"react-redux": "^8.1.3",
"react-scripts": "^5.0.1",
"styled-components": "^6.0.8",
"styled-components": "^6.1.1",
"typescript": "^5.2.2",
"wait-on": "^7.0.1",
"caniuse-lite": "^1.0.30001543"
"wait-on": "^7.1.0",
"caniuse-lite": "^1.0.30001561"
},
"browserslist": {
"production": [
Expand Down
4 changes: 3 additions & 1 deletion public/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module.exports = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization",
"Access-Control-Allow-Credentials": "true"
"Access-Control-Allow-Credentials": "true",
"Cross-Origin-Embedder-Policy": "require-corp",
"Cross-Origin-Opener-Policy": "same-origin"
},
}
};
257 changes: 257 additions & 0 deletions src/API/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@

import {v4} from 'uuid'
import {logger} from '../components/App/logger'
import useAppState from "../store/appState/useAppState"

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'


const postUrl: (url: string, data: string) => Promise<null|boolean> = (url, data) => {
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",
headers: {
Accept: "text/event-stream",
"Content-Type": 'application/json;charset=UTF-8'
},
body: data,
cache: 'no-store',
referrerPolicy: 'no-referrer',
signal: controller.signal
})
.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()

if (!returnData) {
return true
}
console.log (`postUrl status = [${res.status}] returnData = `, returnData)
console.log (`postUrl return JSON data`, returnData)
return returnData

})
.then(_data => {
return resolve (_data)
})
.catch (ex => {
return resolve (status)
})

clearTimeout(id)
})
}

export const testLocalServer = () => {
return postUrl(`http://localhost:3001/loginRequest`, '')
}

export const postPasscode: (passcode: string) => Promise<null|boolean|WorkerCommand> = (passcode) => {
return postUrl(`http://localhost:3001/loginRequest`, JSON.stringify({data:passcode}))
}

const 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()
}

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

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

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

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

export const createPasscode : (passcord: string, local: string) => Promise < StartWorkerResolveForAPI > = (passcord: string, local: string) => {
return new Promise( resolve => {

const cmd: WorkerCommand = {
cmd: 'encrypt_createPasscode',
uuid: v4(),
data: [passcord, local]
}
return postMessage (cmd, resolve)
})
}


export const checkLocaldemond: () => Promise < StartWorkerResolveForAPI > = () => {
return new Promise(resolve => {

})
}



Loading

0 comments on commit 0066ddf

Please sign in to comment.