diff --git a/packages/game-bridge/package.json b/packages/game-bridge/package.json index cf31c2a160..cc97d93e7f 100644 --- a/packages/game-bridge/package.json +++ b/packages/game-bridge/package.json @@ -14,8 +14,8 @@ "parcel": "^2.8.3" }, "scripts": { - "build": "parcel build --no-cache --no-scope-hoist", - "build:local": "parcel build --no-cache --no-scope-hoist && yarn updateSdkVersion", + "build": "parcel build --no-cache --no-scope-hoist --no-optimize", + "build:local": "parcel build --no-cache --no-scope-hoist --no-optimize && yarn updateSdkVersion", "d": "swc src -d dist --strip-leading-paths --ignore '**/*.test.*'", "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0", "start": "parcel", diff --git a/packages/game-bridge/src/index.ts b/packages/game-bridge/src/index.ts index 338fe1ebee..26eca7c226 100644 --- a/packages/game-bridge/src/index.ts +++ b/packages/game-bridge/src/index.ts @@ -122,7 +122,6 @@ type VersionInfo = { const callbackToGame = (data: CallbackData) => { const message = JSON.stringify(data); console.log(`callbackToGame: ${message}`); - console.log(message); if (typeof window.ue !== 'undefined') { if (typeof window.ue.jsconnector === 'undefined') { const unrealError = 'Unreal JSConnector not defined'; @@ -562,7 +561,11 @@ window.callFunction = async (jsonData: string) => { case PASSPORT_FUNCTIONS.imx.transfer: { const unsignedTransferRequest = JSON.parse(data); const response = await getProvider().transfer(unsignedTransferRequest); - trackDuration(moduleName, 'performedImxTransfer', mt(markStart)); + trackDuration(moduleName, 'performedImxTransfer', mt(markStart), { + requestId, + transferRequest: JSON.stringify(unsignedTransferRequest), + transferResponse: JSON.stringify(response), + }); callbackToGame({ ...{ responseFor: fxName, @@ -579,7 +582,11 @@ window.callFunction = async (jsonData: string) => { const response = await getProvider().batchNftTransfer( nftTransferDetails, ); - trackDuration(moduleName, 'performedImxBatchNftTransfer', mt(markStart)); + trackDuration(moduleName, 'performedImxBatchNftTransfer', mt(markStart), { + requestId, + transferRequest: JSON.stringify(nftTransferDetails), + transferResponse: JSON.stringify(response), + }); callbackToGame({ ...{ responseFor: fxName, @@ -622,7 +629,11 @@ window.callFunction = async (jsonData: string) => { throw new Error('Failed to send transaction'); } - trackDuration(moduleName, 'performedZkevmSendTransaction', mt(markStart)); + trackDuration(moduleName, 'performedZkevmSendTransaction', mt(markStart), { + requestId, + transactionRequest: JSON.stringify(transaction), + transactionResponse: transactionHash, + }); callbackToGame({ responseFor: fxName, requestId, @@ -640,7 +651,11 @@ window.callFunction = async (jsonData: string) => { const tx = await signer.sendTransaction(transaction); const response = await tx.wait(); - trackDuration(moduleName, 'performedZkevmSendTransactionWithConfirmation', mt(markStart)); + trackDuration(moduleName, 'performedZkevmSendTransactionWithConfirmation', mt(markStart), { + requestId, + transactionRequest: JSON.stringify(transaction), + transactionResponse: JSON.stringify(response), + }); callbackToGame({ ...{ responseFor: fxName, @@ -734,6 +749,8 @@ window.callFunction = async (jsonData: string) => { break; } } catch (error: any) { + console.log(`Error in callFunction: ${error}`); + let wrappedError; if (!(error instanceof Error)) { @@ -758,7 +775,8 @@ window.callFunction = async (jsonData: string) => { error: wrappedError.message, }); - console.log('callFunction error', error); + console.log('callFunction error', wrappedError); + console.log('callFunction errorType', errorType); callbackToGame({ responseFor: fxName, requestId, @@ -769,6 +787,14 @@ window.callFunction = async (jsonData: string) => { } }; +window.addEventListener('offline', () => { + console.log('gameBridge offline'); +}); + +window.addEventListener('online', () => { + console.log('gameBridge online'); +}); + function onLoadHandler() { // File loaded // This is to prevent callFunction not defined error in Unity