@polkadot/extension-dapp 0.40.4 → 0.40.5-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.
- package/bundle-polkadot-extension-dapp.js +4 -19
- package/index.cjs +87 -60
- package/index.js +3 -7
- package/package.json +4 -6
- package/packageInfo.cjs +1 -1
- package/packageInfo.js +1 -1
|
@@ -3,21 +3,6 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
|
|
|
3
3
|
|
|
4
4
|
const global = window;
|
|
5
5
|
|
|
6
|
-
function _defineProperty(obj, key, value) {
|
|
7
|
-
if (key in obj) {
|
|
8
|
-
Object.defineProperty(obj, key, {
|
|
9
|
-
value: value,
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true
|
|
13
|
-
});
|
|
14
|
-
} else {
|
|
15
|
-
obj[key] = value;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return obj;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
6
|
// Copyright 2019-2021 @polkadot/extension-dapp authors & contributors
|
|
22
7
|
// SPDX-License-Identifier: Apache-2.0
|
|
23
8
|
function documentReadyPromise(creator) {
|
|
@@ -34,9 +19,7 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
|
|
|
34
19
|
const unwrapBytes = util.u8aUnwrapBytes;
|
|
35
20
|
const wrapBytes = util.u8aWrapBytes;
|
|
36
21
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
22
|
+
// Copyright 2019-2021 @polkadot/extension-dapp authors & contributors
|
|
40
23
|
|
|
41
24
|
const win = window; // don't clobber the existing object, but ensure non-undefined
|
|
42
25
|
|
|
@@ -106,7 +89,9 @@ const polkadotExtensionDapp = (function (exports, util, utilCrypto) {
|
|
|
106
89
|
};
|
|
107
90
|
}
|
|
108
91
|
|
|
109
|
-
return
|
|
92
|
+
return { ...info,
|
|
93
|
+
...ext
|
|
94
|
+
};
|
|
110
95
|
})).catch(() => []).then(values => {
|
|
111
96
|
const names = values.map(({
|
|
112
97
|
name,
|
package/index.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -27,8 +25,6 @@ Object.defineProperty(exports, "wrapBytes", {
|
|
|
27
25
|
}
|
|
28
26
|
});
|
|
29
27
|
|
|
30
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
31
|
-
|
|
32
28
|
var _util = require("@polkadot/util");
|
|
33
29
|
|
|
34
30
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
@@ -37,10 +33,9 @@ var _util2 = require("./util.cjs");
|
|
|
37
33
|
|
|
38
34
|
var _wrapBytes = require("./wrapBytes.cjs");
|
|
39
35
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
// Copyright 2019-2021 @polkadot/extension-dapp authors & contributors
|
|
37
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
38
|
+
// expose utility functions
|
|
44
39
|
// just a helper (otherwise we cast all-over, so shorter and more readable)
|
|
45
40
|
const win = window; // don't clobber the existing object, but ensure non-undefined
|
|
46
41
|
|
|
@@ -57,12 +52,13 @@ function throwError(method) {
|
|
|
57
52
|
|
|
58
53
|
|
|
59
54
|
function mapAccounts(source, list, ss58Format) {
|
|
60
|
-
return list.map(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
return list.map(_ref => {
|
|
56
|
+
let {
|
|
57
|
+
address,
|
|
58
|
+
genesisHash,
|
|
59
|
+
name,
|
|
60
|
+
type
|
|
61
|
+
} = _ref;
|
|
66
62
|
const encodedAddress = address.length === 42 ? address : (0, _utilCrypto.encodeAddress)((0, _utilCrypto.decodeAddress)(address), ss58Format);
|
|
67
63
|
return {
|
|
68
64
|
address: encodedAddress,
|
|
@@ -84,25 +80,32 @@ let web3EnablePromise = null;
|
|
|
84
80
|
exports.web3EnablePromise = web3EnablePromise;
|
|
85
81
|
|
|
86
82
|
function getWindowExtensions(originName) {
|
|
87
|
-
return Promise.all(Object.entries(win.injectedWeb3).map(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
83
|
+
return Promise.all(Object.entries(win.injectedWeb3).map(_ref2 => {
|
|
84
|
+
let [name, {
|
|
85
|
+
enable,
|
|
86
|
+
version
|
|
87
|
+
}] = _ref2;
|
|
88
|
+
return Promise.all([Promise.resolve({
|
|
89
|
+
name,
|
|
90
|
+
version
|
|
91
|
+
}), enable(originName).catch(error => {
|
|
92
|
+
console.error(`Error initializing ${name}: ${error.message}`);
|
|
93
|
+
})]);
|
|
94
|
+
}));
|
|
96
95
|
} // enables all the providers found on the injected window interface
|
|
97
96
|
|
|
98
97
|
|
|
99
|
-
function web3Enable(originName
|
|
98
|
+
function web3Enable(originName) {
|
|
99
|
+
let compatInits = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
100
|
+
|
|
100
101
|
if (!originName) {
|
|
101
102
|
throw new Error('You must pass a name for your app to the web3Enable function');
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
const initCompat = compatInits.length ? Promise.all(compatInits.map(c => c().catch(() => false))) : Promise.resolve([true]);
|
|
105
|
-
exports.web3EnablePromise = web3EnablePromise = (0, _util2.documentReadyPromise)(() => initCompat.then(() => getWindowExtensions(originName).then(values => values.filter(value => !!value[1]).map(
|
|
106
|
+
exports.web3EnablePromise = web3EnablePromise = (0, _util2.documentReadyPromise)(() => initCompat.then(() => getWindowExtensions(originName).then(values => values.filter(value => !!value[1]).map(_ref3 => {
|
|
107
|
+
let [info, ext] = _ref3;
|
|
108
|
+
|
|
106
109
|
// if we don't have an accounts subscriber, add a single-shot version
|
|
107
110
|
if (!ext.accounts.subscribe) {
|
|
108
111
|
ext.accounts.subscribe = cb => {
|
|
@@ -112,12 +115,17 @@ function web3Enable(originName, compatInits = []) {
|
|
|
112
115
|
};
|
|
113
116
|
}
|
|
114
117
|
|
|
115
|
-
return
|
|
118
|
+
return { ...info,
|
|
119
|
+
...ext
|
|
120
|
+
};
|
|
116
121
|
})).catch(() => []).then(values => {
|
|
117
|
-
const names = values.map(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
122
|
+
const names = values.map(_ref4 => {
|
|
123
|
+
let {
|
|
124
|
+
name,
|
|
125
|
+
version
|
|
126
|
+
} = _ref4;
|
|
127
|
+
return `${name}/${version}`;
|
|
128
|
+
});
|
|
121
129
|
exports.isWeb3Injected = isWeb3Injected = web3IsInjected();
|
|
122
130
|
console.log(`web3Enable: Enabled ${values.length} extension${values.length !== 1 ? 's' : ''}: ${names.join(', ')}`);
|
|
123
131
|
return values;
|
|
@@ -126,25 +134,32 @@ function web3Enable(originName, compatInits = []) {
|
|
|
126
134
|
} // retrieve all the accounts across all providers
|
|
127
135
|
|
|
128
136
|
|
|
129
|
-
async function web3Accounts({
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
137
|
+
async function web3Accounts() {
|
|
138
|
+
let {
|
|
139
|
+
accountType,
|
|
140
|
+
ss58Format
|
|
141
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
142
|
+
|
|
133
143
|
if (!web3EnablePromise) {
|
|
134
144
|
return throwError('web3Accounts');
|
|
135
145
|
}
|
|
136
146
|
|
|
137
147
|
const accounts = [];
|
|
138
148
|
const injected = await web3EnablePromise;
|
|
139
|
-
const retrieved = await Promise.all(injected.map(async
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
149
|
+
const retrieved = await Promise.all(injected.map(async _ref5 => {
|
|
150
|
+
let {
|
|
151
|
+
accounts,
|
|
152
|
+
name: source
|
|
153
|
+
} = _ref5;
|
|
154
|
+
|
|
143
155
|
try {
|
|
144
156
|
const list = await accounts.get();
|
|
145
|
-
return mapAccounts(source, list.filter(
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
return mapAccounts(source, list.filter(_ref6 => {
|
|
158
|
+
let {
|
|
159
|
+
type
|
|
160
|
+
} = _ref6;
|
|
161
|
+
return type && accountType ? accountType.includes(type) : true;
|
|
162
|
+
}), ss58Format);
|
|
148
163
|
} catch (error) {
|
|
149
164
|
// cannot handle this one
|
|
150
165
|
return [];
|
|
@@ -153,37 +168,46 @@ async function web3Accounts({
|
|
|
153
168
|
retrieved.forEach(result => {
|
|
154
169
|
accounts.push(...result);
|
|
155
170
|
});
|
|
156
|
-
const addresses = accounts.map(
|
|
157
|
-
|
|
158
|
-
|
|
171
|
+
const addresses = accounts.map(_ref7 => {
|
|
172
|
+
let {
|
|
173
|
+
address
|
|
174
|
+
} = _ref7;
|
|
175
|
+
return address;
|
|
176
|
+
});
|
|
159
177
|
console.log(`web3Accounts: Found ${accounts.length} address${accounts.length !== 1 ? 'es' : ''}: ${addresses.join(', ')}`);
|
|
160
178
|
return accounts;
|
|
161
179
|
}
|
|
162
180
|
|
|
163
|
-
async function web3AccountsSubscribe(cb
|
|
164
|
-
|
|
165
|
-
|
|
181
|
+
async function web3AccountsSubscribe(cb) {
|
|
182
|
+
let {
|
|
183
|
+
ss58Format
|
|
184
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
185
|
+
|
|
166
186
|
if (!web3EnablePromise) {
|
|
167
187
|
return throwError('web3AccountsSubscribe');
|
|
168
188
|
}
|
|
169
189
|
|
|
170
190
|
const accounts = {};
|
|
171
191
|
|
|
172
|
-
const triggerUpdate = () => cb(Object.entries(accounts).reduce((result,
|
|
192
|
+
const triggerUpdate = () => cb(Object.entries(accounts).reduce((result, _ref8) => {
|
|
193
|
+
let [source, list] = _ref8;
|
|
173
194
|
result.push(...mapAccounts(source, list, ss58Format));
|
|
174
195
|
return result;
|
|
175
196
|
}, []));
|
|
176
197
|
|
|
177
|
-
const unsubs = (await web3EnablePromise).map(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
198
|
+
const unsubs = (await web3EnablePromise).map(_ref9 => {
|
|
199
|
+
let {
|
|
200
|
+
accounts: {
|
|
201
|
+
subscribe
|
|
202
|
+
},
|
|
203
|
+
name: source
|
|
204
|
+
} = _ref9;
|
|
205
|
+
return subscribe(result => {
|
|
206
|
+
accounts[source] = result; // eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
184
207
|
|
|
185
|
-
|
|
186
|
-
|
|
208
|
+
triggerUpdate();
|
|
209
|
+
});
|
|
210
|
+
});
|
|
187
211
|
return () => {
|
|
188
212
|
unsubs.forEach(unsub => {
|
|
189
213
|
unsub();
|
|
@@ -198,9 +222,12 @@ async function web3FromSource(source) {
|
|
|
198
222
|
}
|
|
199
223
|
|
|
200
224
|
const sources = await web3EnablePromise;
|
|
201
|
-
const found = source && sources.find(
|
|
202
|
-
|
|
203
|
-
|
|
225
|
+
const found = source && sources.find(_ref10 => {
|
|
226
|
+
let {
|
|
227
|
+
name
|
|
228
|
+
} = _ref10;
|
|
229
|
+
return name === source;
|
|
230
|
+
});
|
|
204
231
|
|
|
205
232
|
if (!found) {
|
|
206
233
|
throw new Error(`web3FromSource: Unable to find an injected ${source}`);
|
package/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
-
|
|
7
1
|
// Copyright 2019-2021 @polkadot/extension-dapp authors & contributors
|
|
8
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
3
|
import { u8aEq } from '@polkadot/util';
|
|
@@ -81,7 +75,9 @@ export function web3Enable(originName, compatInits = []) {
|
|
|
81
75
|
};
|
|
82
76
|
}
|
|
83
77
|
|
|
84
|
-
return
|
|
78
|
+
return { ...info,
|
|
79
|
+
...ext
|
|
80
|
+
};
|
|
85
81
|
})).catch(() => []).then(values => {
|
|
86
82
|
const names = values.map(({
|
|
87
83
|
name,
|
package/package.json
CHANGED
|
@@ -3,12 +3,10 @@
|
|
|
3
3
|
"bugs": "https://github.com/polkadot-js/extension/issues",
|
|
4
4
|
"contributors": [],
|
|
5
5
|
"description": "Provides an interfaces around the injected globals for ease of access by dapp developers.",
|
|
6
|
-
"engines": {},
|
|
7
6
|
"homepage": "https://github.com/polkadot-js/extension/tree/master/packages/extension-dapp#readme",
|
|
8
7
|
"license": "Apache-2",
|
|
9
8
|
"maintainers": [],
|
|
10
9
|
"name": "@polkadot/extension-dapp",
|
|
11
|
-
"private": false,
|
|
12
10
|
"repository": {
|
|
13
11
|
"directory": "packages/extension-dapp",
|
|
14
12
|
"type": "git",
|
|
@@ -16,13 +14,13 @@
|
|
|
16
14
|
},
|
|
17
15
|
"sideEffects": false,
|
|
18
16
|
"type": "module",
|
|
19
|
-
"version": "0.40.
|
|
17
|
+
"version": "0.40.5-3",
|
|
20
18
|
"main": "index.js",
|
|
21
19
|
"dependencies": {
|
|
22
20
|
"@babel/runtime": "^7.15.4",
|
|
23
|
-
"@polkadot/extension-inject": "^0.40.
|
|
24
|
-
"@polkadot/util": "^7.6
|
|
25
|
-
"@polkadot/util-crypto": "^7.6
|
|
21
|
+
"@polkadot/extension-inject": "^0.40.5-3",
|
|
22
|
+
"@polkadot/util": "^7.7.2-6",
|
|
23
|
+
"@polkadot/util-crypto": "^7.7.2-6"
|
|
26
24
|
},
|
|
27
25
|
"peerDependencies": {
|
|
28
26
|
"@polkadot/api": "*",
|
package/packageInfo.cjs
CHANGED
package/packageInfo.js
CHANGED