@snapshot-labs/snapshot.js 0.11.13 → 0.11.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapshot-labs/snapshot.js",
3
- "version": "0.11.13",
3
+ "version": "0.11.15",
4
4
  "repository": "snapshot-labs/snapshot.js",
5
5
  "license": "MIT",
6
6
  "main": "dist/snapshot.cjs.js",
package/src/sign/index.ts CHANGED
@@ -43,7 +43,11 @@ import constants from '../constants.json';
43
43
  const NAME = 'snapshot';
44
44
  const VERSION = '0.1.4';
45
45
 
46
- export const domain = {
46
+ export const domain: {
47
+ name: string;
48
+ version: string;
49
+ chainId?: number;
50
+ } = {
47
51
  name: NAME,
48
52
  version: VERSION
49
53
  // chainId: 1
@@ -74,8 +78,16 @@ export default class Client {
74
78
  message.from = message.from ? getAddress(message.from) : checksumAddress;
75
79
  if (!message.timestamp)
76
80
  message.timestamp = parseInt((Date.now() / 1e3).toFixed());
77
- const data: any = { domain, types, message };
78
- const sig = await signer._signTypedData(domain, data.types, message);
81
+
82
+ const domainData = {
83
+ ...domain
84
+ };
85
+ // @ts-ignore
86
+ if (window?.ethereum?.isTrust) {
87
+ domainData.chainId = (await signer.provider.getNetwork()).chainId;
88
+ }
89
+ const data: any = { domain: domainData, types, message };
90
+ const sig = await signer._signTypedData(domainData, data.types, message);
79
91
  return await this.send({ address: checksumAddress, sig, data });
80
92
  }
81
93
 
@@ -95,9 +107,11 @@ export default class Client {
95
107
  fetch(address, init)
96
108
  .then((res) => {
97
109
  if (res.ok) return resolve(res.json());
110
+ if (res.headers.get('content-type')?.includes('application/json'))
111
+ return res.json().then(reject).catch(reject);
98
112
  throw res;
99
113
  })
100
- .catch((e) => reject(e));
114
+ .catch(reject);
101
115
  });
102
116
  }
103
117