walletconnect-monorepo icon indicating copy to clipboard operation
walletconnect-monorepo copied to clipboard

Error: Missing or invalid topic field

Open joshstevens19 opened this issue 5 years ago • 31 comments

We are seeing a lot of errors coming from the wallet connect socket transport all the below: Error: Missing or invalid topic field

Logs:

message: "Uncaught (in promise): Error: Missing or invalid topic field↵Error: Missing or invalid topic field↵    at SocketTransport.send (https://localhost:4251/default~modules-approval-approval-module~modules-change-password-change-password-module~modules-chan~60cd62e9.js:1560:19)↵    at WalletConnect.<anonymous> (https://localhost:4251/default~modules-approval-approval-module~modules-change-password-change-password-module~modules-chan~60cd62e9.js:698:29)↵    at Generator.next (<anonymous>)↵    at fulfilled (https://localhost:4251/vendor.js:212225:58)↵    at ZoneDelegate.invoke (https://localhost:4251/polyfills.js:440:30)↵    at Object.onInvoke (https://localhost:4251/vendor.js:56946:33)↵    at ZoneDelegate.invoke (https://localhost:4251/polyfills.js:439:36)↵    at Zone.run (https://localhost:4251/polyfills.js:197:47)↵    at https://localhost:4251/polyfills.js:938:38↵    at ZoneDelegate.invokeTask (https://localhost:4251/polyfills.js:475:35)"
stackTrace: "send (webpack:///node_modules/@walletconnect/socket-transport/dist/cjs/index.js:57:)↵tslib_1.__awaiter (webpack:///node_modules/@walletconnect/core/dist/cjs/index.js:577:)↵fulfilled (webpack:///node_modules/tslib/tslib.es6.js:70:41)↵invoke (webpack:///node_modules/zone.js/dist/zone.js:396:)↵onInvoke (webpack:///node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js:27815:)↵invoke (webpack:///node_modules/zone.js/dist/zone.js:395:)↵run (webpack:///node_modules/zone.js/dist/zone.js:153:)↵zone.scheduleMicroTask (webpack:///node_modules/zone.js/dist/zone.js:894:)↵invokeTask (webpack:///node_modules/zone.js/dist/zone.js:431:)↵scheduleResolveOrReject (webpack:///node_modules/zone.js/dist/zone.js:836:)↵function (webpack:///node_modules/zone.js/dist/zone.js:750:)↵rejected (webpack:///node_modules/tslib/tslib.es6.js:71:87)↵invoke (webpack:///node_modules/zone.js/dist/zone.js:396:)↵onInvoke (webpack:///node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js:27815:)↵invoke (webpack:///node_modules/zone.js/dist/zone.js:395:)↵run (webpack:///node_modules/zone.js/dist/zone.js:153:)↵zone.scheduleMicroTask (webpack:///node_modules/zone.js/dist/zone.js:894:)↵invokeTask (webpack:///node_modules/zone.js/dist/zone.js:431:)↵onInvokeTask (webpack:///node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js:27803:)"

Our setup looks fine so not sure why it keeps erroring. It actually keeps working and does not break but would rather not have that error emitting in the console.

joshstevens19 avatar Jul 17 '20 11:07 joshstevens19

Hmm this is new.. Any steps to reproduce?

pedrouid avatar Jul 20 '20 11:07 pedrouid

So we have an angular app and i just connect on trust wallet (it happens on other wallets and sometimes just randomly) then i disconnect and it hits your .send with info:

parameter 1:

"{"data":"74eb97d6a74529a290a01b84daad84543c12009443c6999cea9e0235140f5248d5070802c0bedff68163f1df48b50cf8c84470b9ede4b6bd48591ef4b67aed28c8b6ac7524bf52b7307454abc29d81e9a82b3ae1db74090f7033cd7aea2249d8afa39332190ca9eb7369a242f1cf940f44031d56e093b4a0994d134fde4f75cd9ffb82fd89032b9fccab54e4cc2cd0558fa7951a4e466d09f34dd54bdffa5aab","hmac":"93c4907a457dc560c5bef27ce753aa7c4a45e961a70c260d2ccb5f1c13b4afbc","iv":"3fd47537bd9c19ad7c0e3a4ee86be124"}"

parameter 2: ""

parameter 3: true

now your statement (from the compiled code) is:

 if (!t || "string" != typeof t)
       throw new Error("Missing or invalid topic field");

so you throw because the topic is an empty string.

if i look at the call stack i see it went from _sendRequest(e, t)

e = "{"id":1595249132172380,"jsonrpc":"2.0","method":"wc_sessionUpdate","params":[{"approved":false,"chainId":null,"networkId":null,"accounts":null}]}"

t = undefined

it seems that it is falling back to this.peerId which is an empty string which then calls the above send

That's as much info as I can get which is useful.

joshstevens19 avatar Jul 20 '20 12:07 joshstevens19

any news on this @pedrouid

joshstevens19 avatar Oct 23 '20 11:10 joshstevens19

Is this still an issue?

pedrouid avatar Jan 18 '21 18:01 pedrouid

I will upgrade to latest package and recheck for you tomorrow. 👍

joshstevens19 avatar Jan 18 '21 19:01 joshstevens19

no this is still a issue image

joshstevens19 avatar Jan 19 '21 12:01 joshstevens19

Anything particular about the network or browser environment that I should know for reproducing it?

pedrouid avatar Jan 19 '21 14:01 pedrouid

I am using a windows computer on the latest version of windows 10, google chrome again latest version. This happens on local as well as when deployed to aws for us. I also above explained every step I could to how it reproduces https://github.com/WalletConnect/walletconnect-monorepo/issues/315#issuecomment-661019926

joshstevens19 avatar Jan 19 '21 14:01 joshstevens19

so from you comment above it seems that you disconnect the session before calling send() is that correct?

at this point if your peer is disconnected then peerId would be an empty string which is invalid

unless there is another reason peerId would not be present but the only reason would be that the session is not connected so you should create a new connector and connect again

pedrouid avatar Jan 20 '21 11:01 pedrouid

I'm getting this error too.

connector.createSession() does not update the _peerId value.

Hephyrius avatar Apr 30 '21 03:04 Hephyrius

I'm getting the same error probably for the exact reason pedrouid indicated: I'm calling disconnect before sending anything. The reason I'm doing so it because I want to discard the old (cached) connection and scan a new QR code.

Maybe there is a more elegant way ensure that "startSession" actually starts a brand new connection and does not just reuse an old cashed connection?

PS: here is the workaround for my use case. If you want to make sure that walletconnect starts in a clean state, just delete its local storage before initializing it: window.localStorage.removeItem('walletconnect');

luziusmeisser avatar May 01 '21 21:05 luziusmeisser

any update on this issue?

FrozenIce0617 avatar May 21 '21 20:05 FrozenIce0617

There should be some way to completely disconnect the session, currently it remembers last session, for one time even after calling disconnect so need to remove it from localstorage as mentioned in above workaround after disconnect.

imaksp avatar Jun 30 '21 09:06 imaksp

Issue is existing since 2020 any update ?

ZentaChainAdmin avatar Jul 01 '21 18:07 ZentaChainAdmin

Hi guys! Any update here? Also facing this issue on my side. Handling the error manually for now.

cmalfesi avatar Sep 24 '21 19:09 cmalfesi

Also getting this myself

theAlexPatin avatar Nov 09 '21 23:11 theAlexPatin

Same problem :/ But my app work anyway

Xeway avatar Feb 17 '22 11:02 Xeway

@luziusmeisser 's window.localStorage.removeItem('walletconnect'); solution works except I sometimes get 2 QR codes when provider.enable() is triggered after window.localStorage.removeItem('walletconnect'); . Anybody knows the solution to this ?.

hammersharkfish avatar Mar 16 '22 19:03 hammersharkfish

Same problem here :/ also subscribing

mzaatar avatar Mar 23 '22 04:03 mzaatar

Same problem here when connecting to metamask via walletconnect on mobile

nbeuchat avatar Mar 27 '22 16:03 nbeuchat

+1 Bumping this!

Adamj1232 avatar Apr 20 '22 15:04 Adamj1232

This issue was opened almost 2 years ago. C'mon dev team

0x9090 avatar Apr 23 '22 17:04 0x9090

Possible Unhandled Promise Rejection (id: 2):
Error: Missing or invalid topic field
Error: Missing or invalid topic field
    at send (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:245697:26)
    at _sendResponse$ (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:237871:37)
    at call (native)
    at tryCatch (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28362:23)
    at invoke (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28532:32)
    at anonymous (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28404:30)
    at call (native)
    at tryCatch (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28362:23)
    at invoke (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28434:30)
    at anonymous (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28444:21)
    at tryCallOne (/Users/distiller/hermes/build_iphoneos/lib/InternalBytecode/InternalBytecode.js:53:16)
    at anonymous (/Users/distiller/hermes/build_iphoneos/lib/InternalBytecode/InternalBytecode.js:139:27)
    at apply (native)
    at anonymous (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:33854:26)
    at _callTimer (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:33750:17)
    at _callReactNativeMicrotasksPass (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:33789:17)
    at callReactNativeMicrotasks (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:33998:44)
    at __callReactNativeMicrotasks (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:27201:46)
    at anonymous (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:26980:45)
    at __guard (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:27184:15)
    at flushedQueue (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:26979:21)
    at callFunctionReturnFlushedQueue (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:26961:33)

Facing this error when trying to approveSession. This is happening 1/5 times on an average.

justinjoyn avatar Apr 29 '22 09:04 justinjoyn

is this still an issue?

ArshiaDhiman avatar Jun 22 '22 13:06 ArshiaDhiman

I am still getting this issue

mmartin4972 avatar Jun 29 '22 13:06 mmartin4972

Putting the connection in a singleton and then nullifying the singleton allowed me to uncache the state without having to use the window.remove workaround.

class ConnectionWrapper {
  private static _instance: ConnectionWrapper;
  private _connector:any;

  private constructor() {
    this._connector = new client({bridge: "https://bridge.walletconnect.org",  qrcodeModal: QRCodeModal});
  }

  public static getConnection():any {
    if (!this._instance) {
      this._instance = new ConnectionWrapper();
    }
    return this._instance;
  }

  public disconnect() {
    this._connector.killSession();
    this._connector = null;
    ConnectionWrapper._instance = null;
  }

  get connector() {
    return this._connector;
  }
} 

wrapper = ConnectionWrapper.getConnection(); wrapper.connector.createSession() // Shows new QR Code wrapper.disconnect() // Throws topic error but removes cached data

mmartin4972 avatar Jun 29 '22 13:06 mmartin4972

same, I am still getting this issue

trieu-hphuc96 avatar Jul 20 '22 06:07 trieu-hphuc96

quick solution: Clean application browser cache and try again, that works for me but that can happen again

ceerlepy avatar Aug 03 '22 22:08 ceerlepy

I encountered this issue, and was able to get past it. It seems like this happens when the params are not available. I checked my code, and there were some bugs which were not setting the required params correctly. Once I ensured everything was correct in code, this error was gone.

r4881t avatar Aug 16 '22 15:08 r4881t

I solved this error by:

  1. Instead of using wcProvider.disconnect(), i used wcProvider.wc.killSession().
  2. Instead of reading connection status from wcProvider.connected, I used wcProvider.wc.session.connected.

RaphaelNdonga avatar Aug 26 '22 08:08 RaphaelNdonga