@polkadot/extension-dapp 0.41.2 → 0.41.3-3

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.
@@ -3,8 +3,6 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
3
3
 
4
4
  const global = window;
5
5
 
6
- // Copyright 2019-2021 @polkadot/extension-dapp authors & contributors
7
- // SPDX-License-Identifier: Apache-2.0
8
6
  function documentReadyPromise(creator) {
9
7
  return new Promise(resolve => {
10
8
  if (document.readyState === 'complete') {
@@ -15,26 +13,17 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
15
13
  });
16
14
  }
17
15
 
18
- // Copyright 2019-2021 @polkadot/extension authors & contributors
19
16
  const unwrapBytes = util.u8aUnwrapBytes;
20
17
  const wrapBytes = util.u8aWrapBytes;
21
18
 
22
- // Copyright 2019-2021 @polkadot/extension-dapp authors & contributors
23
-
24
- const win = window; // don't clobber the existing object, but ensure non-undefined
25
-
26
- win.injectedWeb3 = win.injectedWeb3 || {}; // true when anything has been injected and is available
27
-
19
+ const win = window;
20
+ win.injectedWeb3 = win.injectedWeb3 || {};
28
21
  function web3IsInjected() {
29
22
  return Object.keys(win.injectedWeb3).length !== 0;
30
- } // helper to throw a consistent error when not enabled
31
-
32
-
23
+ }
33
24
  function throwError(method) {
34
25
  throw new Error(`${method}: web3Enable(originName) needs to be called before ${method}`);
35
- } // internal helper to map from Array<InjectedAccount> -> Array<InjectedAccountWithMeta>
36
-
37
-
26
+ }
38
27
  function mapAccounts(source, list, ss58Format) {
39
28
  return list.map(({
40
29
  address,
@@ -53,13 +42,9 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
53
42
  type
54
43
  };
55
44
  });
56
- } // have we found a properly constructed window.injectedWeb3
57
-
58
-
59
- exports.isWeb3Injected = web3IsInjected(); // we keep the last promise created around (for queries)
60
-
45
+ }
46
+ exports.isWeb3Injected = web3IsInjected();
61
47
  exports.web3EnablePromise = null;
62
-
63
48
  function getWindowExtensions(originName) {
64
49
  return Promise.all(Object.entries(win.injectedWeb3).map(([name, {
65
50
  enable,
@@ -70,25 +55,20 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
70
55
  }), enable(originName).catch(error => {
71
56
  console.error(`Error initializing ${name}: ${error.message}`);
72
57
  })])));
73
- } // enables all the providers found on the injected window interface
74
-
75
-
58
+ }
76
59
  function web3Enable(originName, compatInits = []) {
77
60
  if (!originName) {
78
61
  throw new Error('You must pass a name for your app to the web3Enable function');
79
62
  }
80
-
81
63
  const initCompat = compatInits.length ? Promise.all(compatInits.map(c => c().catch(() => false))) : Promise.resolve([true]);
82
64
  exports.web3EnablePromise = documentReadyPromise(() => initCompat.then(() => getWindowExtensions(originName).then(values => values.filter(value => !!value[1]).map(([info, ext]) => {
83
- // if we don't have an accounts subscriber, add a single-shot version
84
65
  if (!ext.accounts.subscribe) {
85
66
  ext.accounts.subscribe = cb => {
86
67
  ext.accounts.get().then(cb).catch(console.error);
87
- return () => {// no ubsubscribe needed, this is a single-shot
68
+ return () => {
88
69
  };
89
70
  };
90
71
  }
91
-
92
72
  return { ...info,
93
73
  ...ext
94
74
  };
@@ -102,8 +82,7 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
102
82
  return values;
103
83
  })));
104
84
  return exports.web3EnablePromise;
105
- } // retrieve all the accounts across all providers
106
-
85
+ }
107
86
  async function web3Accounts({
108
87
  accountType,
109
88
  ss58Format
@@ -111,7 +90,6 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
111
90
  if (!exports.web3EnablePromise) {
112
91
  return throwError('web3Accounts');
113
92
  }
114
-
115
93
  const accounts = [];
116
94
  const injected = await exports.web3EnablePromise;
117
95
  const retrieved = await Promise.all(injected.map(async ({
@@ -124,7 +102,6 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
124
102
  type
125
103
  }) => type && accountType ? accountType.includes(type) : true), ss58Format);
126
104
  } catch (error) {
127
- // cannot handle this one
128
105
  return [];
129
106
  }
130
107
  }));
@@ -143,22 +120,18 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
143
120
  if (!exports.web3EnablePromise) {
144
121
  return throwError('web3AccountsSubscribe');
145
122
  }
146
-
147
123
  const accounts = {};
148
-
149
124
  const triggerUpdate = () => cb(Object.entries(accounts).reduce((result, [source, list]) => {
150
125
  result.push(...mapAccounts(source, list, ss58Format));
151
126
  return result;
152
127
  }, []));
153
-
154
128
  const unsubs = (await exports.web3EnablePromise).map(({
155
129
  accounts: {
156
130
  subscribe
157
131
  },
158
132
  name: source
159
133
  }) => subscribe(result => {
160
- accounts[source] = result; // eslint-disable-next-line @typescript-eslint/no-floating-promises
161
-
134
+ accounts[source] = result;
162
135
  triggerUpdate();
163
136
  }));
164
137
  return () => {
@@ -166,67 +139,52 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
166
139
  unsub();
167
140
  });
168
141
  };
169
- } // find a specific provider based on the name
170
-
142
+ }
171
143
  async function web3FromSource(source) {
172
144
  if (!exports.web3EnablePromise) {
173
145
  return throwError('web3FromSource');
174
146
  }
175
-
176
147
  const sources = await exports.web3EnablePromise;
177
148
  const found = source && sources.find(({
178
149
  name
179
150
  }) => name === source);
180
-
181
151
  if (!found) {
182
152
  throw new Error(`web3FromSource: Unable to find an injected ${source}`);
183
153
  }
184
-
185
154
  return found;
186
- } // find a specific provider based on an address
187
-
155
+ }
188
156
  async function web3FromAddress(address) {
189
157
  if (!exports.web3EnablePromise) {
190
158
  return throwError('web3FromAddress');
191
159
  }
192
-
193
160
  const accounts = await web3Accounts();
194
161
  let found;
195
-
196
162
  if (address) {
197
163
  const accountU8a = utilCrypto.decodeAddress(address);
198
164
  found = accounts.find(account => util.u8aEq(utilCrypto.decodeAddress(account.address), accountU8a));
199
165
  }
200
-
201
166
  if (!found) {
202
167
  throw new Error(`web3FromAddress: Unable to find injected ${address}`);
203
168
  }
204
-
205
169
  return web3FromSource(found.meta.source);
206
- } // retrieve all providers exposed by one source
207
-
170
+ }
208
171
  async function web3ListRpcProviders(source) {
209
172
  const {
210
173
  provider
211
174
  } = await web3FromSource(source);
212
-
213
175
  if (!provider) {
214
176
  console.warn(`Extension ${source} does not expose any provider`);
215
177
  return null;
216
178
  }
217
-
218
179
  return provider.listProviders();
219
- } // retrieve all providers exposed by one source
220
-
180
+ }
221
181
  async function web3UseRpcProvider(source, key) {
222
182
  const {
223
183
  provider
224
184
  } = await web3FromSource(source);
225
-
226
185
  if (!provider) {
227
186
  throw new Error(`Extension ${source} does not expose any provider`);
228
187
  }
229
-
230
188
  const meta = await provider.startProvider(key);
231
189
  return {
232
190
  meta,
package/package.json CHANGED
@@ -14,13 +14,13 @@
14
14
  },
15
15
  "sideEffects": false,
16
16
  "type": "module",
17
- "version": "0.41.2",
17
+ "version": "0.41.3-3",
18
18
  "main": "index.js",
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.16.3",
21
- "@polkadot/extension-inject": "^0.41.2",
22
- "@polkadot/util": "^8.0.4",
23
- "@polkadot/util-crypto": "^8.0.4"
21
+ "@polkadot/extension-inject": "^0.41.3-3",
22
+ "@polkadot/util": "^8.1.2",
23
+ "@polkadot/util-crypto": "^8.1.2"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@polkadot/api": "*",
package/packageInfo.cjs CHANGED
@@ -9,6 +9,6 @@ exports.packageInfo = void 0;
9
9
  // Auto-generated by @polkadot/dev, do not edit
10
10
  const packageInfo = {
11
11
  name: '@polkadot/extension-dapp',
12
- version: '0.41.2'
12
+ version: '0.41.3-3'
13
13
  };
14
14
  exports.packageInfo = packageInfo;
package/packageInfo.js CHANGED
@@ -3,5 +3,5 @@
3
3
  // Auto-generated by @polkadot/dev, do not edit
4
4
  export const packageInfo = {
5
5
  name: '@polkadot/extension-dapp',
6
- version: '0.41.2'
6
+ version: '0.41.3-3'
7
7
  };