@w3ux/observables-connect 0.9.0-alpha.10
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.d.ts +6 -0
- package/extensions.js +70 -0
- package/extensions.js.map +1 -0
- package/index.d.ts +6 -0
- package/index.js +9 -0
- package/index.js.map +1 -0
- package/package.json +12 -0
- package/types.d.ts +6 -0
- package/types.js +5 -0
- package/types.js.map +1 -0
package/extensions.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExtensionStatus } from '@w3ux/types';
|
|
2
|
+
export declare const getExtensions: () => Promise<void>;
|
|
3
|
+
export declare const getStatus: (id: string) => ExtensionStatus;
|
|
4
|
+
export declare const setStatus: (id: string, status: ExtensionStatus) => void;
|
|
5
|
+
export declare const removeStatus: (id: string) => void;
|
|
6
|
+
export declare const canConnect: (id: string) => boolean;
|
package/extensions.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import extensions from '@w3ux/extension-assets';
|
|
2
|
+
import { _extensionsStatus, _gettingExtensions } from './index';
|
|
3
|
+
export const getExtensions = async () => {
|
|
4
|
+
_gettingExtensions.next(true);
|
|
5
|
+
let injectedWeb3Interval = null;
|
|
6
|
+
const findInstalled = () => {
|
|
7
|
+
let updated = false;
|
|
8
|
+
const current = _extensionsStatus.getValue();
|
|
9
|
+
console.log('current: ', current);
|
|
10
|
+
const installed = Object.keys(extensions).reduce((acc, key) => {
|
|
11
|
+
if (acc[key] !== undefined) {
|
|
12
|
+
return acc;
|
|
13
|
+
}
|
|
14
|
+
const maybeExtension = window?.injectedWeb3?.[key];
|
|
15
|
+
if (maybeExtension !== undefined) {
|
|
16
|
+
updated = true;
|
|
17
|
+
acc[key] = 'installed';
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
acc[key] = undefined;
|
|
21
|
+
}
|
|
22
|
+
return acc;
|
|
23
|
+
}, { ...current });
|
|
24
|
+
console.log('end of iteration: ');
|
|
25
|
+
console.log(installed);
|
|
26
|
+
return { installed, updated };
|
|
27
|
+
};
|
|
28
|
+
const processInterval = async () => {
|
|
29
|
+
const { installed, updated } = findInstalled();
|
|
30
|
+
if (updated) {
|
|
31
|
+
_extensionsStatus.next(installed);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
let i = 0;
|
|
35
|
+
const interval = 300;
|
|
36
|
+
const maxChecks = 10;
|
|
37
|
+
injectedWeb3Interval = setInterval(() => {
|
|
38
|
+
i++;
|
|
39
|
+
if (i === maxChecks) {
|
|
40
|
+
_gettingExtensions.next(false);
|
|
41
|
+
clearInterval(injectedWeb3Interval);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
if (window?.injectedWeb3 !== undefined) {
|
|
45
|
+
processInterval();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, interval);
|
|
49
|
+
};
|
|
50
|
+
export const getStatus = (id) => {
|
|
51
|
+
const value = _extensionsStatus.getValue();
|
|
52
|
+
return value[id] || undefined;
|
|
53
|
+
};
|
|
54
|
+
export const setStatus = (id, status) => {
|
|
55
|
+
const value = _extensionsStatus.getValue();
|
|
56
|
+
value[id] = status;
|
|
57
|
+
_extensionsStatus.next(value);
|
|
58
|
+
};
|
|
59
|
+
export const removeStatus = (id) => {
|
|
60
|
+
const { [id]: _, ...rest } = _extensionsStatus.getValue();
|
|
61
|
+
_extensionsStatus.next(rest);
|
|
62
|
+
};
|
|
63
|
+
export const canConnect = (id) => {
|
|
64
|
+
const value = _extensionsStatus.getValue();
|
|
65
|
+
return ![undefined, 'connected'].includes(value[id]);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=extensions.js.map
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/extensions.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,MAAM,wBAAwB,CAAA;AAE/C,OAAO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AAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC9B,CAAC,CAAA;AAGD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAU,EAAE,EAAE;IACvC,MAAM,KAAK,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAA;IAC1C,OAAO,CAAC,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;AACtD,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 // Find new installed extensions and update state\n const findInstalled = () => {\n let updated = false\n const current = _extensionsStatus.getValue()\n console.log('current: ', current)\n\n const installed = Object.keys(extensions).reduce(\n (acc, key) => {\n if (acc[key] !== undefined) {\n return acc\n }\n const maybeExtension = window?.injectedWeb3?.[key]\n if (maybeExtension !== undefined) {\n updated = true\n acc[key] = 'installed'\n } else {\n acc[key] = undefined\n }\n return acc\n },\n { ...current }\n )\n\n console.log('end of iteration: ')\n console.log(installed)\n\n return { installed, updated }\n }\n\n // Handle interval iteration\n const processInterval = async () => {\n const { installed, updated } = findInstalled()\n if (updated) {\n _extensionsStatus.next(installed)\n }\n }\n\n // Getter for the currently installed extensions\n let i = 0\n const interval = 300\n const maxChecks = 10\n injectedWeb3Interval = setInterval(() => {\n i++\n if (i === maxChecks) {\n _gettingExtensions.next(false)\n clearInterval(injectedWeb3Interval)\n } else {\n if (window?.injectedWeb3 !== undefined) {\n processInterval()\n }\n }\n }, interval)\n}\n\n// Gets an extension status\nexport const getStatus = (id: string): ExtensionStatus => {\n const value = _extensionsStatus.getValue()\n return value[id] || undefined\n}\n\n// Sets an extension status\nexport const setStatus = (id: string, status: ExtensionStatus) => {\n const value = _extensionsStatus.getValue()\n value[id] = status\n _extensionsStatus.next(value)\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 const value = _extensionsStatus.getValue()\n return ![undefined, 'connected'].includes(value[id])\n}\n"]}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExtensionsStatus } from '@w3ux/types';
|
|
2
|
+
import { BehaviorSubject } from 'rxjs';
|
|
3
|
+
export declare const _gettingExtensions: BehaviorSubject<boolean>;
|
|
4
|
+
export declare const gettingExtensions$: import("rxjs").Observable<boolean>;
|
|
5
|
+
export declare const _extensionsStatus: BehaviorSubject<ExtensionsStatus>;
|
|
6
|
+
export declare const extensionsStatus$: import("rxjs").Observable<ExtensionsStatus>;
|
package/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BehaviorSubject } from 'rxjs';
|
|
2
|
+
export const _gettingExtensions = new BehaviorSubject(false);
|
|
3
|
+
export const gettingExtensions$ = _gettingExtensions.asObservable();
|
|
4
|
+
export const _extensionsStatus = new BehaviorSubject({});
|
|
5
|
+
export const extensionsStatus$ = _extensionsStatus.asObservable();
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +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,KAAK,CAAC,CAAA;AACrE,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>(false)\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"]}
|
package/package.json
ADDED
package/types.d.ts
ADDED
package/types.js
ADDED
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { ExtensionInjected } from '@w3ux/types'\n\ndeclare global {\n interface Window {\n injectedWeb3?: Record<string, ExtensionInjected>\n }\n}\n"]}
|