@novasamatech/statement-store 0.7.4 → 0.7.5-0
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/dist/adapter/lazyClient.js +14 -45
- package/package.json +2 -2
|
@@ -1,68 +1,37 @@
|
|
|
1
|
-
import { createClient as createSubstrateClient } from '@polkadot-api/substrate-client';
|
|
2
1
|
import { createClient as createPolkadotClient } from 'polkadot-api';
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
4
|
-
const noop = () => { };
|
|
5
2
|
export const createLazyClient = (provider) => {
|
|
6
3
|
let polkadotClient = null;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
substrateClient = createSubstrateClient(provider);
|
|
4
|
+
function getPolkadotClient() {
|
|
5
|
+
if (!polkadotClient) {
|
|
6
|
+
polkadotClient = createPolkadotClient(provider);
|
|
11
7
|
}
|
|
12
|
-
return
|
|
8
|
+
return polkadotClient;
|
|
13
9
|
}
|
|
14
10
|
return {
|
|
15
11
|
getClient() {
|
|
16
|
-
|
|
17
|
-
polkadotClient = createPolkadotClient(provider);
|
|
18
|
-
}
|
|
19
|
-
return polkadotClient;
|
|
12
|
+
return getPolkadotClient();
|
|
20
13
|
},
|
|
21
14
|
getRequestFn() {
|
|
22
|
-
const c =
|
|
23
|
-
return (method, params) =>
|
|
24
|
-
c._request(method, params, {
|
|
25
|
-
onSuccess: result => resolve(result),
|
|
26
|
-
onError: e => reject(e),
|
|
27
|
-
});
|
|
28
|
-
});
|
|
15
|
+
const c = getPolkadotClient();
|
|
16
|
+
return (method, params) => c._request(method, params);
|
|
29
17
|
},
|
|
30
18
|
getSubscribeFn() {
|
|
31
|
-
const c =
|
|
19
|
+
const c = getPolkadotClient();
|
|
32
20
|
return (method, params, onMessage, onError) => {
|
|
33
|
-
let subscriptionId = null;
|
|
34
|
-
let unsubscribeLocal = null;
|
|
35
|
-
const cancelRequest = c._request(method, params, {
|
|
36
|
-
onSuccess: (subId, followSubscription) => {
|
|
37
|
-
subscriptionId = subId;
|
|
38
|
-
unsubscribeLocal = followSubscription(subId, { next: onMessage, error: onError });
|
|
39
|
-
},
|
|
40
|
-
onError,
|
|
41
|
-
});
|
|
42
21
|
// Derive the unsubscribe RPC method from the subscribe method name
|
|
43
22
|
// e.g. statement_subscribeStatement -> statement_unsubscribeStatement
|
|
44
23
|
const unsubscribeMethod = method.replace('subscribe', 'unsubscribe');
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
onSuccess: noop,
|
|
51
|
-
onError: noop,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
cancelRequest();
|
|
56
|
-
}
|
|
57
|
-
};
|
|
24
|
+
const subscription = c._subscribe(method, unsubscribeMethod, params).subscribe({
|
|
25
|
+
next: onMessage,
|
|
26
|
+
error: onError,
|
|
27
|
+
});
|
|
28
|
+
return () => subscription.unsubscribe();
|
|
58
29
|
};
|
|
59
30
|
},
|
|
60
31
|
disconnect() {
|
|
61
32
|
if (polkadotClient) {
|
|
62
33
|
polkadotClient.destroy();
|
|
63
|
-
|
|
64
|
-
if (substrateClient) {
|
|
65
|
-
substrateClient.destroy();
|
|
34
|
+
polkadotClient = null;
|
|
66
35
|
}
|
|
67
36
|
},
|
|
68
37
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/statement-store",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.5-0",
|
|
5
5
|
"description": "Statement store integration",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@novasamatech/scale": "0.7.
|
|
28
|
+
"@novasamatech/scale": "0.7.5-0",
|
|
29
29
|
"@novasamatech/sdk-statement": "^0.6.0",
|
|
30
30
|
"@polkadot-api/substrate-bindings": "^0.20.1",
|
|
31
31
|
"@polkadot-api/substrate-client": "^0.7.0",
|