From d94a7a62406eaa73ca9d15b4238829d886390f79 Mon Sep 17 00:00:00 2001 From: CoNET Project Date: Sat, 20 Apr 2024 12:50:27 -0700 Subject: [PATCH] added startMining --- src/API/index.ts | 2 +- src/API/platform.ts | 50 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/API/index.ts b/src/API/index.ts index 32e2764..20f8ed4 100644 --- a/src/API/index.ts +++ b/src/API/index.ts @@ -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' diff --git a/src/API/platform.ts b/src/API/platform.ts index 3497094..cf137cf 100644 --- a/src/API/platform.ts +++ b/src/API/platform.ts @@ -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[] @@ -65,9 +65,24 @@ export const listeningGuardianPurchaseHook = (purchaseHook: React.Dispatch profileVerChannelListening(e, null, null, purchaseHook)) } -const profileVerChannelListening = (e: MessageEvent, profileVerHook: React.Dispatch>|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>) => { + profileVerChannel.addEventListener('message', e => profileVerChannelListening(e, null, null, null, miningHook)) +} + +const profileVerChannelListening = (e: MessageEvent, + profileVerHook: React.Dispatch>|null = null, assetsHook:React.Dispatch>|null = null, - purchaseHook:React.Dispatch>|null = null) => { + purchaseHook:React.Dispatch>|null = null, + miningHook: React.Dispatch>|null = null +) => { let cmd: channelWroker try { cmd = JSON.parse(e.data) @@ -81,22 +96,30 @@ const profileVerChannelListening = (e: MessageEvent, 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 }]`) } @@ -391,4 +414,19 @@ export class platform { return resolve (data[0]) }) }) + + public startMining: (authorizationKey: string, profile: profile) => Promise = (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]) + }) + }) } \ No newline at end of file