From c93b48920e4861b4fe35c60be19344abbb19a184 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Thu, 18 Apr 2019 13:49:37 +0200 Subject: [PATCH] Increment JSON-RPC ID for JsonRpcProviders for environments that unsafely manage callbacks (#489). --- src.ts/providers/json-rpc-provider.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src.ts/providers/json-rpc-provider.ts b/src.ts/providers/json-rpc-provider.ts index 65dc7485ff..5248b93931 100644 --- a/src.ts/providers/json-rpc-provider.ts +++ b/src.ts/providers/json-rpc-provider.ts @@ -50,6 +50,11 @@ function getLowerCase(value: string): string { const _constructorGuard = {}; +// Some environments (Trust Wallet and company) use a global map +// to track JSON-RPC ID, so we try to keep IDs unique across all +// connections. See #489. +let _nextId = 42; + export class JsonRpcSigner extends Signer { readonly provider: JsonRpcProvider; private _index: number; @@ -250,7 +255,7 @@ export class JsonRpcProvider extends BaseProvider { let request = { method: method, params: params, - id: 42, + id: (_nextId++), jsonrpc: "2.0" };