Skip to content

Commit

Permalink
added startMining
Browse files Browse the repository at this point in the history
  • Loading branch information
CoNETProject committed Apr 20, 2024
1 parent 3764241 commit d94a7a6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/API/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type WorkerCommandType = 'READY'|'testPasscode'|'getCONETBalance'|'getRegiestNod
'isAddress'|'getFaucet'|'syncAsset'|'sendAsset'|'getUSDCPrice'|'registerReferrer'|'showSRP'|'getAllProfiles'|
'buyUSDC'|'mintCoNETCash'|'getSINodes'|'getRecipientCoNETCashAddress'|'setRegion'|'ipaddress'|'startLiveness'|'stopLiveness'|
'isLivenessRunning'|'getRefereesList'|'getAllNodes'|'getContainer'|'importWallet'|'updateProfile'|'resetPasscode'|'recoverAccount'|'addProfile'|
'getAssetsPrice'|'CONETFaucet'|'prePurchase'|'guardianPurchase'|'fx168PrePurchase'
'getAssetsPrice'|'CONETFaucet'|'prePurchase'|'guardianPurchase'|'fx168PrePurchase'|'startMining'

export type WorkerCallStatus = 'SUCCESS' | 'NOT_READY' | 'UNKNOWN_COMMAND' |
'TIME_OUT' | 'SYSTEM_ERROR'
Expand Down
50 changes: 44 additions & 6 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'|'assets'|'purchaseStatus'
type command = 'profileVer'|'assets'|'purchaseStatus'|'miningStatus'
interface channelWroker {
cmd: command,
data: any[]
Expand All @@ -65,9 +65,24 @@ export const listeningGuardianPurchaseHook = (purchaseHook: React.Dispatch<React
profileVerChannel.addEventListener('message', e => profileVerChannelListening(e, null, null, purchaseHook))
}

const profileVerChannelListening = (e: MessageEvent<any>, profileVerHook: React.Dispatch<React.SetStateAction<number>>|null = null,
interface mining {
blockNumber: number
CCNTP_total_balance: string
Updated_balace: string // CCNTP_total_balance - Last_balance
status: 'mining'|'stoped'
profile: profile
}

export const listeningMiningHook = (miningHook: React.Dispatch<React.SetStateAction<mining>>) => {
profileVerChannel.addEventListener('message', e => profileVerChannelListening(e, null, null, null, miningHook))
}

const profileVerChannelListening = (e: MessageEvent<any>,
profileVerHook: React.Dispatch<React.SetStateAction<number>>|null = null,
assetsHook:React.Dispatch<React.SetStateAction<number>>|null = null,
purchaseHook:React.Dispatch<React.SetStateAction<number>>|null = null) => {
purchaseHook:React.Dispatch<React.SetStateAction<number>>|null = null,
miningHook: React.Dispatch<React.SetStateAction<mining>>|null = null
) => {
let cmd: channelWroker
try {
cmd = JSON.parse(e.data)
Expand All @@ -81,22 +96,30 @@ const profileVerChannelListening = (e: MessageEvent<any>, profileVerHook: React.
if (profileVerHook) {
return profileVerHook(cmd.data[0])
}
return console.log('profileVerHook profileVerHook === null', `profileVer data [${cmd.data}]`)
return
}

case 'assets': {
if (assetsHook) {
return assetsHook(cmd.data[0])
}
return console.log('assets assetsHook === null', `assets from backend [${cmd.data}]`)
return
}

case 'purchaseStatus': {
if (purchaseHook) {
return purchaseHook(cmd.data[0])
}
return console.log('purchaseStatus purchaseHook === null', `purchaseStatus =[${cmd.data[0]}]`)
return
}

case 'miningStatus': {
if (miningHook) {
return miningHook(cmd.data[0])
}
return console.log('purchaseStatus miningStatus === null', `miningStatus =[${cmd.data[0]}]`)
}

default : {
return console.log(`profileVerChannelListening unknow command [${ cmd.cmd }] from backend [${ cmd.data }]`)
}
Expand Down Expand Up @@ -391,4 +414,19 @@ export class platform {
return resolve (data[0])
})
})

public startMining: (authorizationKey: string, profile: profile) => Promise<type_platformStatus> = (authorizationKey, profile) => new Promise(async resolve=> {
const cmd: WorkerCommand = {
cmd: 'startMining',
uuid: v4(),
data: [authorizationKey, profile]
}
return postMessage (cmd, false, null, (err: any, data: any) => {
if (err) {
return resolve (err)
}

return resolve (data[0])
})
})
}

0 comments on commit d94a7a6

Please sign in to comment.