@novasamatech/product-sdk 0.5.0-15 → 0.5.0-17
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.
|
@@ -7,5 +7,5 @@ type Params = {
|
|
|
7
7
|
type InternalParams = {
|
|
8
8
|
transport?: Transport;
|
|
9
9
|
};
|
|
10
|
-
export declare function createSpektrPapiProvider({ chainId, fallback }: Params, internal?: InternalParams): JsonRpcProvider;
|
|
10
|
+
export declare function createSpektrPapiProvider({ chainId: genesisHash, fallback }: Params, internal?: InternalParams): JsonRpcProvider;
|
|
11
11
|
export {};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { unwrapResultOrThrow } from '@novasamatech/host-api';
|
|
2
2
|
import { getSyncProvider } from '@polkadot-api/json-rpc-provider-proxy';
|
|
3
3
|
import { defaultTransport } from './defaultTransport.js';
|
|
4
|
-
export function createSpektrPapiProvider({ chainId, fallback }, internal) {
|
|
4
|
+
export function createSpektrPapiProvider({ chainId: genesisHash, fallback }, internal) {
|
|
5
5
|
const transport = internal?.transport ?? defaultTransport;
|
|
6
6
|
if (!transport.isCorrectEnvironment())
|
|
7
7
|
return fallback;
|
|
8
8
|
const spektrProvider = onMessage => {
|
|
9
9
|
const unsubscribe = transport.subscribe('papiProviderReceiveMessageV1', (_, payload) => {
|
|
10
|
-
const unwrapped = unwrapResultOrThrow(payload);
|
|
11
|
-
if (unwrapped.
|
|
10
|
+
const unwrapped = unwrapResultOrThrow(payload, e => new Error(e));
|
|
11
|
+
if (unwrapped.genesisHash === genesisHash) {
|
|
12
12
|
onMessage(unwrapped.message);
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
15
|
return {
|
|
16
16
|
send(message) {
|
|
17
|
-
transport.postMessage('_', { tag: 'papiProviderSendMessageV1', value: {
|
|
17
|
+
transport.postMessage('_', { tag: 'papiProviderSendMessageV1', value: { genesisHash, message } });
|
|
18
18
|
},
|
|
19
19
|
disconnect() {
|
|
20
20
|
unsubscribe();
|
|
@@ -26,10 +26,10 @@ export function createSpektrPapiProvider({ chainId, fallback }, internal) {
|
|
|
26
26
|
if (!ready)
|
|
27
27
|
return false;
|
|
28
28
|
return transport
|
|
29
|
-
.request({ tag: 'supportFeatureRequestV1', value: { tag: 'chain', value: {
|
|
29
|
+
.request({ tag: 'supportFeatureRequestV1', value: { tag: 'chain', value: { genesisHash } } }, 'supportFeatureResponseV1')
|
|
30
30
|
.then(payload => {
|
|
31
|
-
const result = unwrapResultOrThrow(payload);
|
|
32
|
-
if (result.tag === 'chain' && result.value.
|
|
31
|
+
const result = unwrapResultOrThrow(payload, e => new Error(e));
|
|
32
|
+
if (result.tag === 'chain' && result.value.genesisHash === genesisHash) {
|
|
33
33
|
return result.value.result;
|
|
34
34
|
}
|
|
35
35
|
})
|
|
@@ -12,12 +12,12 @@ export async function createExtensionEnableFactory(transport) {
|
|
|
12
12
|
get() {
|
|
13
13
|
return transport
|
|
14
14
|
.request({ tag: 'getAccountsRequestV1', value: undefined }, 'getAccountsResponseV1')
|
|
15
|
-
.then(unwrapResultOrThrow);
|
|
15
|
+
.then(v => unwrapResultOrThrow(v, e => new Error(e)));
|
|
16
16
|
},
|
|
17
17
|
subscribe(callback) {
|
|
18
18
|
const unsubscribe = transport.subscribe('getAccountsResponseV1', (_, payload) => {
|
|
19
19
|
try {
|
|
20
|
-
const accounts = unwrapResultOrThrow(payload);
|
|
20
|
+
const accounts = unwrapResultOrThrow(payload, e => new Error(e));
|
|
21
21
|
callback(accounts);
|
|
22
22
|
}
|
|
23
23
|
catch {
|
|
@@ -33,17 +33,27 @@ export async function createExtensionEnableFactory(transport) {
|
|
|
33
33
|
},
|
|
34
34
|
signer: {
|
|
35
35
|
signRaw(raw) {
|
|
36
|
-
return transport
|
|
36
|
+
return transport
|
|
37
|
+
.request({ tag: 'signRawRequestV1', value: raw }, 'signResponseV1')
|
|
38
|
+
.then(v => unwrapResultOrThrow(v, e => new Error(e)));
|
|
37
39
|
},
|
|
38
40
|
signPayload(payload) {
|
|
41
|
+
const codecPayload = {
|
|
42
|
+
...payload,
|
|
43
|
+
method: payload.method,
|
|
44
|
+
assetId: payload.assetId,
|
|
45
|
+
mode: payload.mode,
|
|
46
|
+
withSignedTransaction: payload.withSignedTransaction,
|
|
47
|
+
metadataHash: payload.metadataHash,
|
|
48
|
+
};
|
|
39
49
|
return transport
|
|
40
|
-
.request({ tag: 'signPayloadRequestV1', value:
|
|
41
|
-
.then(unwrapResultOrThrow);
|
|
50
|
+
.request({ tag: 'signPayloadRequestV1', value: codecPayload }, 'signResponseV1')
|
|
51
|
+
.then(v => unwrapResultOrThrow(v, e => new Error(e)));
|
|
42
52
|
},
|
|
43
53
|
createTransaction(payload) {
|
|
44
54
|
return transport
|
|
45
55
|
.request({ tag: 'createTransactionRequestV1', value: payload }, 'createTransactionResponseV1')
|
|
46
|
-
.then(unwrapResultOrThrow);
|
|
56
|
+
.then(v => unwrapResultOrThrow(v, e => new Error(e)));
|
|
47
57
|
},
|
|
48
58
|
},
|
|
49
59
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/product-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.0-
|
|
4
|
+
"version": "0.5.0-17",
|
|
5
5
|
"description": "Polkadot product SDK: integrate and run your product inside Polkadot browser.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@polkadot/extension-inject": "^0.62.6",
|
|
30
30
|
"@polkadot-api/json-rpc-provider": "^0.0.4",
|
|
31
31
|
"@polkadot-api/json-rpc-provider-proxy": "^0.2.7",
|
|
32
|
-
"@novasamatech/host-api": "0.5.0-
|
|
32
|
+
"@novasamatech/host-api": "0.5.0-17"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|