@w3ux/observables-connect 0.9.0-alpha.9 → 0.9.1
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/extensions.js +22 -42
- package/extensions.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
package/extensions.js
CHANGED
|
@@ -3,65 +3,45 @@ import { _extensionsStatus, _gettingExtensions } from './index';
|
|
|
3
3
|
export const getExtensions = async () => {
|
|
4
4
|
_gettingExtensions.next(true);
|
|
5
5
|
let injectedWeb3Interval = null;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
updated = true;
|
|
16
|
-
acc[key] = 'installed';
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
acc[key] = undefined;
|
|
20
|
-
}
|
|
21
|
-
console.log(acc);
|
|
22
|
-
return acc;
|
|
23
|
-
}, { ...current });
|
|
24
|
-
return { installed, updated };
|
|
25
|
-
};
|
|
26
|
-
const processInterval = async () => {
|
|
27
|
-
const { installed, updated } = findInstalled();
|
|
28
|
-
if (updated) {
|
|
29
|
-
_extensionsStatus.next(installed);
|
|
6
|
+
const formatInstalled = () => Object.keys(extensions).reduce((acc, key) => {
|
|
7
|
+
acc[key] =
|
|
8
|
+
window?.injectedWeb3[key] !== undefined ? 'installed' : acc[key];
|
|
9
|
+
return acc;
|
|
10
|
+
}, { ..._extensionsStatus.getValue() });
|
|
11
|
+
const handleCompleted = async (foundExtensions) => {
|
|
12
|
+
clearInterval(injectedWeb3Interval);
|
|
13
|
+
if (foundExtensions) {
|
|
14
|
+
_extensionsStatus.next(formatInstalled());
|
|
30
15
|
}
|
|
16
|
+
_gettingExtensions.next(false);
|
|
31
17
|
};
|
|
32
|
-
let
|
|
18
|
+
let counter = 0;
|
|
33
19
|
const interval = 300;
|
|
34
20
|
const maxChecks = 10;
|
|
35
21
|
injectedWeb3Interval = setInterval(() => {
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
clearInterval(injectedWeb3Interval);
|
|
22
|
+
counter++;
|
|
23
|
+
if (counter === maxChecks) {
|
|
24
|
+
handleCompleted(false);
|
|
40
25
|
}
|
|
41
26
|
else {
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
const injectedWeb3 = window?.injectedWeb3 || null;
|
|
28
|
+
if (injectedWeb3 !== null) {
|
|
29
|
+
handleCompleted(true);
|
|
44
30
|
}
|
|
45
31
|
}
|
|
46
32
|
}, interval);
|
|
47
33
|
};
|
|
48
|
-
export const getStatus = (id) =>
|
|
49
|
-
const value = _extensionsStatus.getValue();
|
|
50
|
-
return value[id] || undefined;
|
|
51
|
-
};
|
|
34
|
+
export const getStatus = (id) => _extensionsStatus.getValue()[id] || undefined;
|
|
52
35
|
export const setStatus = (id, status) => {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
_extensionsStatus.next(
|
|
36
|
+
const newValue = { ..._extensionsStatus.getValue() };
|
|
37
|
+
newValue[id] = status;
|
|
38
|
+
_extensionsStatus.next(newValue);
|
|
56
39
|
};
|
|
57
40
|
export const removeStatus = (id) => {
|
|
58
41
|
const { [id]: _, ...rest } = _extensionsStatus.getValue();
|
|
59
42
|
_extensionsStatus.next(rest);
|
|
60
43
|
};
|
|
61
|
-
export const canConnect = (id) =>
|
|
62
|
-
const value = _extensionsStatus.getValue();
|
|
63
|
-
return ![undefined, 'connected'].includes(value[id]);
|
|
64
|
-
};
|
|
44
|
+
export const canConnect = (id) => ![undefined, 'connected'].includes(_extensionsStatus.getValue()[id]);
|
|
65
45
|
|
|
66
46
|
//# sourceMappingURL=extensions.js.map
|
|
67
47
|
|
package/extensions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/extensions.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,MAAM,wBAAwB,CAAA;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EAAE,CAAC,EAAE,CAAC,CAAC,CAAA","file":"extensions.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport extensions from '@w3ux/extension-assets'\nimport type { ExtensionStatus } from '@w3ux/types'\nimport { _extensionsStatus, _gettingExtensions } from './index'\n\n// Gets extensions from injectedWeb3\nexport const getExtensions = async () => {\n _gettingExtensions.next(true)\n let injectedWeb3Interval: ReturnType<typeof setInterval> = null\n\n // Format installed extensions\n const formatInstalled = () =>\n Object.keys(extensions).reduce(\n (acc, key) => {\n acc[key] =\n window?.injectedWeb3[key] !== undefined ? 'installed' : acc[key]\n return acc\n },\n { ..._extensionsStatus.getValue() }\n )\n\n // Handle completed interval check\n const handleCompleted = async (foundExtensions: boolean) => {\n clearInterval(injectedWeb3Interval)\n if (foundExtensions) {\n _extensionsStatus.next(formatInstalled())\n }\n _gettingExtensions.next(false)\n }\n\n // Getter for the currently installed extensions\n let counter = 0\n const interval = 300\n const maxChecks = 10\n injectedWeb3Interval = setInterval(() => {\n counter++\n if (counter === maxChecks) {\n handleCompleted(false)\n } else {\n // `injectedWeb3` is present\n const injectedWeb3 = window?.injectedWeb3 || null\n if (injectedWeb3 !== null) {\n handleCompleted(true)\n }\n }\n }, interval)\n}\n\n// Gets an extension status\nexport const getStatus = (id: string): ExtensionStatus =>\n _extensionsStatus.getValue()[id] || undefined\n\n// Sets an extension status\nexport const setStatus = (id: string, status: ExtensionStatus) => {\n const newValue = { ..._extensionsStatus.getValue() }\n newValue[id] = status\n _extensionsStatus.next(newValue)\n}\n\n// Removes an extension status\nexport const removeStatus = (id: string) => {\n const { [id]: _, ...rest } = _extensionsStatus.getValue()\n _extensionsStatus.next(rest)\n}\n\n// Whether an extension can be connected\nexport const canConnect = (id: string) =>\n ![undefined, 'connected'].includes(_extensionsStatus.getValue()[id])\n"]}
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BehaviorSubject } from 'rxjs';
|
|
2
|
-
export const _gettingExtensions = new BehaviorSubject(
|
|
2
|
+
export const _gettingExtensions = new BehaviorSubject(true);
|
|
3
3
|
export const gettingExtensions$ = _gettingExtensions.asObservable();
|
|
4
4
|
export const _extensionsStatus = new BehaviorSubject({});
|
|
5
5
|
export const extensionsStatus$ = _extensionsStatus.asObservable();
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAGtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,eAAe,CAAU,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAGtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,eAAe,CAAU,IAAI,CAAC,CAAA;AACpE,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,YAAY,EAAE,CAAA;AAGnE,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,eAAe,CAAmB,EAAE,CAAC,CAAA;AAC1E,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,YAAY,EAAE,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { ExtensionsStatus } from '@w3ux/types'\nimport { BehaviorSubject } from 'rxjs'\n\n// Whether extensions are being checked\nexport const _gettingExtensions = new BehaviorSubject<boolean>(true)\nexport const gettingExtensions$ = _gettingExtensions.asObservable()\n\n// Discovered extensions along with their status\nexport const _extensionsStatus = new BehaviorSubject<ExtensionsStatus>({})\nexport const extensionsStatus$ = _extensionsStatus.asObservable()\n"]}
|