@w3ux/observables-connect 0.9.26 → 0.9.27
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/accounts/connect.d.ts +1 -0
- package/accounts/connect.js +35 -0
- package/accounts/connect.js.map +1 -0
- package/accounts/index.d.ts +1 -0
- package/accounts/index.js +1 -0
- package/accounts/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const connectExtension: (dappName: string, ss58: number, id: string) => Promise<boolean>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { canConnect, connectExtensions } from '../extensions/index';
|
|
2
|
+
import { addUnsub } from './state';
|
|
3
|
+
import { processExtensionAccounts } from './util';
|
|
4
|
+
export const connectExtension = async (dappName, ss58, id) => {
|
|
5
|
+
if (canConnect(id)) {
|
|
6
|
+
const { connected } = await connectExtensions(dappName, [id]);
|
|
7
|
+
if (connected.size === 0) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const { extension } = connected.get(id);
|
|
11
|
+
const canSubscribe = typeof extension.accounts.subscribe === 'function';
|
|
12
|
+
const handleAccounts = (accounts) => {
|
|
13
|
+
processExtensionAccounts({
|
|
14
|
+
source: id,
|
|
15
|
+
ss58,
|
|
16
|
+
}, extension.signer, accounts);
|
|
17
|
+
};
|
|
18
|
+
if (!canSubscribe) {
|
|
19
|
+
const accounts = await extension.accounts.get();
|
|
20
|
+
handleAccounts(accounts);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const unsub = extension.accounts.subscribe((accounts) => {
|
|
24
|
+
handleAccounts(accounts);
|
|
25
|
+
});
|
|
26
|
+
addUnsub(id, unsub);
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=connect.js.map
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=connect.js.map
|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CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;QACrB,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","file":"connect.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { ExtensionAccount } from '@w3ux/types'\nimport { canConnect, connectExtensions } from '../extensions/index'\nimport { addUnsub } from './state'\nimport { processExtensionAccounts } from './util'\n\n// Connects to a single extension and processes its accounts\nexport const connectExtension = async (\n dappName: string,\n ss58: number,\n id: string\n): Promise<boolean> => {\n if (canConnect(id)) {\n const { connected } = await connectExtensions(dappName, [id])\n if (connected.size === 0) {\n return\n }\n const { extension } = connected.get(id)\n const canSubscribe = typeof extension.accounts.subscribe === 'function'\n\n const handleAccounts = (accounts: ExtensionAccount[]) => {\n processExtensionAccounts(\n {\n source: id,\n ss58,\n },\n extension.signer,\n accounts\n )\n }\n\n // If account subscriptions are not supported, simply get the account(s) from the extension,\n // otherwise, subscribe to accounts\n if (!canSubscribe) {\n const accounts = await extension.accounts.get()\n handleAccounts(accounts)\n } else {\n const unsub = extension.accounts.subscribe((accounts) => {\n handleAccounts(accounts)\n })\n addUnsub(id, unsub)\n }\n return true\n }\n return false\n}\n"]}
|
package/accounts/index.d.ts
CHANGED
package/accounts/index.js
CHANGED
package/accounts/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/accounts/index.ts"],"names":[],"mappings":"AAGA,cAAc,OAAO,CAAA;AACrB,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from './get'\nexport * from './local'\nexport * from './observables'\nexport * from './reconnect'\nexport * from './state'\nexport * from './util'\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/accounts/index.ts"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA","file":"index.js","sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from './connect'\nexport * from './get'\nexport * from './local'\nexport * from './observables'\nexport * from './reconnect'\nexport * from './state'\nexport * from './util'\n"]}
|