@@ -41,6 +41,15 @@ export async function checkMetaMask(from) {
41
41
// to hang
42
42
const isServer = typeof window === 'undefined'
43
43
44
+ /**
45
+ * Check if the hash is a valid transaction hash
46
+ * @param hash {string} - A suspected transaction hash
47
+ * @returns {boolean } - if hash was a valid transaction hash
48
+ */
49
+ function isValidHash ( hash ) {
50
+ return typeof hash === 'string' && [ 66 , 64 ] . includes ( hash . length )
51
+ }
52
+
44
53
// Should we try to use the relayer
45
54
function useRelayer ( { mutation, value } ) {
46
55
if ( isServer ) return
@@ -311,6 +320,11 @@ async function handleCallbacks({ callbacks, val }) {
311
320
async function handleHash ( { hash, from, mutation } ) {
312
321
debug ( `got hash ${ hash } ` )
313
322
323
+ if ( ! isValidHash ( hash ) ) {
324
+ console . error ( `Received hash: ${ hash } ` )
325
+ throw new Error ( 'handleHash got invalid tx hash!' )
326
+ }
327
+
314
328
contracts . transactions [ from ] = contracts . transactions [ from ] || [ ]
315
329
contracts . transactions [ from ] . unshift ( {
316
330
id : hash ,
@@ -441,7 +455,7 @@ async function sendViaRelayer({
441
455
throw new Error ( 'No transaction hash from relayer!' )
442
456
}
443
457
const txHash = resp . id
444
- if ( typeof txHash !== 'string' || ! [ 66 , 64 ] . includes ( txHash . length ) ) {
458
+ if ( ! isValidHash ( txHash ) ) {
445
459
throw new Error ( 'Invalid transaction hash returned by relayer!' )
446
460
}
447
461
@@ -465,7 +479,12 @@ async function sendViaRelayer({
465
479
let receipt
466
480
const responseBlocks = async ( { newBlock } ) => {
467
481
if ( ! receipt ) {
468
- receipt = await web3 . eth . getTransactionReceipt ( txHash )
482
+ try {
483
+ receipt = await web3 . eth . getTransactionReceipt ( txHash )
484
+ } catch ( err ) {
485
+ console . error ( err )
486
+ return
487
+ }
469
488
}
470
489
/**
471
490
* There some potential races going on here, where we can't use === for
@@ -563,10 +582,7 @@ async function sendViaWeb3({
563
582
} else if ( txHash === null ) {
564
583
console . error ( tx )
565
584
throw new Error ( 'Transaction hash returned null. Invalid tx?' )
566
- } else if (
567
- typeof txHash !== 'string' ||
568
- ! [ 66 , 64 ] . includes ( txHash . length )
569
- ) {
585
+ } else if ( ! isValidHash ( txHash ) ) {
570
586
console . error ( 'Invaild hash: ' , txHash )
571
587
throw new Error ( 'Invalid transaction hash returned by web3!' )
572
588
}
@@ -582,10 +598,20 @@ async function sendViaWeb3({
582
598
} )
583
599
} )
584
600
. on ( 'error' , function ( error ) {
601
+ /**
602
+ * This seems like an internal web3.js error and not caused by our code.
603
+ * it should be temporary, so we're just gonna ignore it.
604
+ */
605
+ if ( error && error . message && error . message . includes ( 'Invalid params' ) ) {
606
+ console . error ( error . message )
607
+ return
608
+ }
609
+
585
610
if ( txHash ) {
611
+ const hashTosend = isValidHash ( txHash ) ? txHash : null
586
612
pubsub . publish ( 'TRANSACTION_UPDATED' , {
587
613
transactionUpdated : {
588
- id : txHash ,
614
+ id : hashTosend ,
589
615
status : 'error' ,
590
616
error,
591
617
mutation
0 commit comments