@novasamatech/product-sdk 0.6.16 → 0.6.18

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.
@@ -0,0 +1,36 @@
1
+ import type { Subscription, Transport } from '@novasamatech/host-api';
2
+ export type PaymentBalance = {
3
+ available: bigint;
4
+ };
5
+ export type PaymentStatus = {
6
+ type: 'processing';
7
+ } | {
8
+ type: 'completed';
9
+ } | {
10
+ type: 'failed';
11
+ reason: string;
12
+ };
13
+ export type TopUpSource = {
14
+ type: 'productAccount';
15
+ dotNsIdentifier: string;
16
+ derivationIndex: number;
17
+ } | {
18
+ type: 'privateKey';
19
+ key: Uint8Array;
20
+ };
21
+ export declare const createPaymentManager: (transport?: Transport) => {
22
+ subscribeBalance(callback: (balance: PaymentBalance) => void): Subscription;
23
+ topUp(amount: bigint, source: TopUpSource): Promise<void>;
24
+ requestPayment(amount: bigint, destination: Uint8Array): Promise<{
25
+ id: string;
26
+ }>;
27
+ subscribePaymentStatus(id: string, callback: (status: PaymentStatus) => void): Subscription;
28
+ };
29
+ export declare const paymentManager: {
30
+ subscribeBalance(callback: (balance: PaymentBalance) => void): Subscription;
31
+ topUp(amount: bigint, source: TopUpSource): Promise<void>;
32
+ requestPayment(amount: bigint, destination: Uint8Array): Promise<{
33
+ id: string;
34
+ }>;
35
+ subscribePaymentStatus(id: string, callback: (status: PaymentStatus) => void): Subscription;
36
+ };
@@ -0,0 +1,45 @@
1
+ import { createHostApi, enumValue } from '@novasamatech/host-api';
2
+ import { resultToPromise, unwrapVersionedResult } from './helpers.js';
3
+ import { sandboxTransport } from './sandboxTransport.js';
4
+ export const createPaymentManager = (transport = sandboxTransport) => {
5
+ const hostApi = createHostApi(transport);
6
+ const version = 'v1';
7
+ return {
8
+ subscribeBalance(callback) {
9
+ return hostApi.paymentBalanceSubscribe(enumValue(version, undefined), payload => {
10
+ if (payload.tag === version) {
11
+ callback(payload.value);
12
+ }
13
+ });
14
+ },
15
+ topUp(amount, source) {
16
+ const sourceCodec = source.type === 'productAccount'
17
+ ? {
18
+ tag: 'ProductAccount',
19
+ value: [source.dotNsIdentifier, source.derivationIndex],
20
+ }
21
+ : { tag: 'PrivateKey', value: source.key };
22
+ return resultToPromise(unwrapVersionedResult(version, hostApi.paymentTopUp(enumValue(version, { amount, source: sourceCodec }))));
23
+ },
24
+ requestPayment(amount, destination) {
25
+ return resultToPromise(unwrapVersionedResult(version, hostApi.paymentRequest(enumValue(version, { amount, destination }))));
26
+ },
27
+ subscribePaymentStatus(id, callback) {
28
+ return hostApi.paymentStatusSubscribe(enumValue(version, id), payload => {
29
+ if (payload.tag === version) {
30
+ const raw = payload.value;
31
+ if (raw.tag === 'Processing') {
32
+ callback({ type: 'processing' });
33
+ }
34
+ else if (raw.tag === 'Completed') {
35
+ callback({ type: 'completed' });
36
+ }
37
+ else if (raw.tag === 'Failed') {
38
+ callback({ type: 'failed', reason: raw.value });
39
+ }
40
+ }
41
+ });
42
+ },
43
+ };
44
+ };
45
+ export const paymentManager = createPaymentManager();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/product-sdk",
3
3
  "type": "module",
4
- "version": "0.6.16",
4
+ "version": "0.6.18",
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-api/substrate-bindings": "^0.17.0",
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.6.16"
32
+ "@novasamatech/host-api": "0.6.18"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"