Skip to content

Commit

Permalink
added hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
CoNETProject committed Apr 8, 2024
1 parent 5ab65d4 commit 19b2c6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/API/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ export const postMessage = (cmd: WorkerCommand, close: boolean, resolve: any, C
channel.close()
}

export const faucet: () => Promise < StartWorkerResolveForAPI > = () => {
export const faucet: (walletAddr: string) => Promise < StartWorkerResolveForAPI > = (walletAddr) => {
return new Promise( resolve => {
const cmd: WorkerCommand = {
cmd: 'getFaucet',
data: [],
data: [walletAddr],
uuid: v4()
}
return postMessage (cmd, true, resolve)
Expand Down Expand Up @@ -353,7 +353,6 @@ export const stopLiveness: () => Promise < StartWorkerResolveForAPI > = () => {
})
}


export const isLivenessRunning: (callback: (err: string, data: string[]) => void) => Promise < StartWorkerResolveForAPI > = (callback) => {

return new Promise(resolve => {
Expand Down
20 changes: 16 additions & 4 deletions src/API/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const beforeunload = (event: BeforeUnloadEvent) => {
return true

}
type command = 'profileVer'
type command = 'profileVer'|'assets'
interface channelWroker {
cmd: command,
data: any[]
Expand All @@ -58,7 +58,12 @@ export const listeningVersionHook = (profileVerHook: React.Dispatch<React.SetSta
profileVerChannel.addEventListener('message', e => profileVerChannelListening(e, profileVerHook))
}

const profileVerChannelListening = (e: MessageEvent<any>, profileVerHook: React.Dispatch<React.SetStateAction<number>>) => {
export const listeningAssetsHook = (assetsHook: React.Dispatch<React.SetStateAction<number>>) => {
const profileVerChannel = new BroadcastChannel(channelWrokerListenName)
profileVerChannel.addEventListener('message', e => profileVerChannelListening(e, null, assetsHook))
}

const profileVerChannelListening = (e: MessageEvent<any>, profileVerHook: React.Dispatch<React.SetStateAction<number>>|null = null, assetsHook:React.Dispatch<React.SetStateAction<number>>|null = null) => {
let cmd: channelWroker
try {
cmd = JSON.parse(e.data)
Expand All @@ -72,10 +77,17 @@ const profileVerChannelListening = (e: MessageEvent<any>, profileVerHook: React.
if (profileVerHook) {
return profileVerHook(cmd.data[0])
}
return console.log('profileVerChannelListening Error! profileVerHook === null', `profileVer from backend [${cmd.data}]`)
return console.log('profileVerChannelListening profileVerHook === null', `profileVer from backend [${cmd.data}]`)
}

case 'assets': {
if (assetsHook) {
return assetsHook(cmd.data[0])
}
return console.log('profileVerChannelListening assetsHook === null', `profileVer from backend [${cmd.data}]`)
}
default : {
return console.log(`profileVerChannelListening unknow comd [${ cmd.cmd }] from backend [${ cmd.data }]`)
return console.log(`profileVerChannelListening unknow command [${ cmd.cmd }] from backend [${ cmd.data }]`)
}
}
}
Expand Down

0 comments on commit 19b2c6d

Please sign in to comment.