@xelis/sdk 0.6.0 → 0.6.1

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/README.md CHANGED
@@ -15,8 +15,12 @@ Import library and start working :).
15
15
  Use Daemon HTTP RPC connection.
16
16
 
17
17
  ```js
18
+ // ESM
18
19
  import { TESTNET_NODE_RPC } from '@xelis/sdk/config'
19
20
  import DaemonRPC from '@xelis/sdk/daemon/rpc'
21
+ // CommonJS
22
+ // const { TESTNET_NODE_RPC } = require('@xelis/sdk/config')
23
+ // const { RPC: DaemonRPC } = require('@xelis/sdk/daemon/rpc')
20
24
 
21
25
  const main = async () => {
22
26
  const daemon = new DaemonRPC(TESTNET_NODE_RPC)
@@ -30,8 +34,12 @@ main()
30
34
  Use Daemon WebSocket RPC connection.
31
35
 
32
36
  ```js
37
+ // ESM
33
38
  import { TESTNET_NODE_WS } from '@xelis/sdk/config'
34
39
  import DaemonWS from '@xelis/sdk/daemon/websocket'
40
+ // CommonJS
41
+ // const { TESTNET_NODE_RPC } = require('@xelis/sdk/config')
42
+ // const { WS: DaemonWS } = require('@xelis/sdk/daemon/websocket')
35
43
 
36
44
  const main = async () => {
37
45
  const daemon = new DaemonWS()
@@ -46,8 +54,12 @@ main()
46
54
  Use Wallet WebSocket RPC connection.
47
55
 
48
56
  ```js
57
+ // ESM
49
58
  import { LOCAL_WALLET_WS } from '@xelis/sdk/config'
50
59
  import DaemonWS from '@xelis/sdk/wallet/websocket'
60
+ // CommonJS
61
+ // const { LOCAL_WALLET_WS } = require('@xelis/sdk/config')
62
+ // const { WS: WalletWS } = require('@xelis/sdk/wallet/websocket')
51
63
 
52
64
  const main = async () => {
53
65
  const wallet = new WalletWS(`test`, `test`) // username, password
@@ -62,8 +74,12 @@ main()
62
74
  Use XSWD protocol.
63
75
 
64
76
  ```js
77
+ // ESM
65
78
  import { LOCAL_XSWD_WS } from '@xelis/sdk/config'
66
79
  import XSWD from '@xelis/sdk/xswd/websocket'
80
+ // CommonJS
81
+ // const { LOCAL_XSWD_WS } = require('@xelis/sdk/config')
82
+ // const { WS: XSWD } = require('@xelis/sdk/xswd/websocket')
67
83
 
68
84
  const main = async () => {
69
85
  const xswd = new XSWD()
package/daemon/rpc.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Balance, Block, TopoHeightRangeParams, GetInfoResult, HeightRangeParams, GetBalanceResult, P2PStatusResult, Transaction, GetBalanceParams, GetBalanceAtTopoHeightParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceResult, GetNonceParams, GetAccountHistoryParams, AccounHistory, Peer, DevFee, DiskSize, HasBalanceParams, HasBalanceResult, AssetData, IsTxExecutedInBlockParams, GetAssetParams } from './types';
2
2
  import { RPC as BaseRPC } from '../lib/rpc';
3
- declare class RPC extends BaseRPC {
3
+ export declare class RPC extends BaseRPC {
4
4
  getVersion(): Promise<import("../lib/types").RPCResponse<string>>;
5
5
  getInfo(): Promise<import("../lib/types").RPCResponse<GetInfoResult>>;
6
6
  getHeight(): Promise<import("../lib/types").RPCResponse<number>>;
package/daemon/rpc.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RPCMethod } from './types';
2
2
  import { RPC as BaseRPC } from '../lib/rpc';
3
- class RPC extends BaseRPC {
3
+ export class RPC extends BaseRPC {
4
4
  getVersion() {
5
5
  return this.post(RPCMethod.GetVersion);
6
6
  }
@@ -54,7 +54,7 @@ export declare class DaemonMethods {
54
54
  getSizeOnDisk(): Promise<DiskSize>;
55
55
  isTxExecutedInBlock(params: IsTxExecutedInBlockParams): Promise<boolean>;
56
56
  }
57
- declare class WS extends BaseWS {
57
+ export declare class WS extends BaseWS {
58
58
  methods: DaemonMethods;
59
59
  constructor();
60
60
  }
@@ -150,7 +150,7 @@ export class DaemonMethods {
150
150
  return this.dataCall(RPCMethod.IsTxExecutedInBlock, params);
151
151
  }
152
152
  }
153
- class WS extends BaseWS {
153
+ export class WS extends BaseWS {
154
154
  constructor() {
155
155
  super();
156
156
  this.methods = new DaemonMethods(this);
package/lib/websocket.js CHANGED
@@ -5,7 +5,7 @@ export class WS {
5
5
  this.connectionTries = 0;
6
6
  this.methodIdIncrement = 0;
7
7
  this.endpoint = "";
8
- this.timeout = 3000;
8
+ this.timeout = 15000; // default to 15s
9
9
  this.events = {};
10
10
  this.unsubscribeSuspense = 1000;
11
11
  this.maxConnectionTries = 3;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.0",
2
+ "version": "0.6.1",
3
3
  "name": "@xelis/sdk",
4
4
  "description": "Xelis software development kit for JS",
5
5
  "repository": {
package/react/daemon.d.ts CHANGED
@@ -10,6 +10,7 @@ interface NodeSocket {
10
10
  }
11
11
  interface NodeSocketProviderProps {
12
12
  endpoint: string;
13
+ timeout?: number;
13
14
  }
14
15
  export declare const NodeSocketProvider: (props: PropsWithChildren<NodeSocketProviderProps>) => React.JSX.Element;
15
16
  interface NodeSocketSubscribeProps<T> {
package/react/daemon.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import React, { createContext, useContext, useEffect, useState } from 'react';
2
2
  import to from 'await-to-js';
3
3
  import DaemonWS from '../daemon/websocket';
4
- const daemon = new DaemonWS();
5
4
  export const INITIATING = -1;
5
+ const daemon = new DaemonWS();
6
6
  const Context = createContext({
7
7
  err: undefined,
8
8
  daemon,
9
9
  readyState: INITIATING
10
10
  });
11
11
  export const NodeSocketProvider = (props) => {
12
- const { children, endpoint } = props;
12
+ const { children, endpoint, timeout } = props;
13
13
  const [readyState, setReadyState] = useState(INITIATING);
14
14
  const [err, setErr] = useState();
15
15
  useEffect(() => {
@@ -21,6 +21,11 @@ export const NodeSocketProvider = (props) => {
21
21
  };
22
22
  connect();
23
23
  }, [endpoint]);
24
+ useEffect(() => {
25
+ if (!timeout)
26
+ return;
27
+ daemon.timeout = timeout;
28
+ }, [timeout]);
24
29
  useEffect(() => {
25
30
  if (!daemon.socket)
26
31
  return;
package/wallet/rpc.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Transaction, GetAssetParams } from '../daemon/types';
2
2
  import { GetAddressParams, SplitAddressParams, SplitAddressResult, BuildTransactionParams, BuildTransactionResult, ListTransactionParams } from './types';
3
3
  import { RPC as BaseRPC } from '../lib/rpc';
4
4
  import { RPCResponse } from '../lib/types';
5
- declare class RPC extends BaseRPC {
5
+ export declare class RPC extends BaseRPC {
6
6
  auth: string;
7
7
  constructor(endpoint: string, username: string, password: string);
8
8
  post<T>(method: string, params?: any): Promise<RPCResponse<T>>;
package/wallet/rpc.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Base64 } from 'js-base64';
2
2
  import { RPCMethod } from './types';
3
3
  import { RPC as BaseRPC } from '../lib/rpc';
4
- class RPC extends BaseRPC {
4
+ export class RPC extends BaseRPC {
5
5
  constructor(endpoint, username, password) {
6
6
  super(endpoint);
7
7
  const authValue = Base64.encode(`${username}:${password}`);
@@ -21,7 +21,7 @@ export declare class WalletMethods {
21
21
  listTransactions(params?: ListTransactionParams): Promise<Transaction[]>;
22
22
  isOnline(): Promise<boolean>;
23
23
  }
24
- declare class WS extends BaseWS {
24
+ export declare class WS extends BaseWS {
25
25
  methods: WalletMethods;
26
26
  constructor(username: string, password: string);
27
27
  }
@@ -51,7 +51,7 @@ export class WalletMethods {
51
51
  return this.dataCall(RPCMethod.IsOnline);
52
52
  }
53
53
  }
54
- class WS extends BaseWS {
54
+ export class WS extends BaseWS {
55
55
  constructor(username, password) {
56
56
  super({ auth: `${username}:${password}` });
57
57
  this.methods = new WalletMethods(this);
@@ -2,7 +2,7 @@ import { WS as BaseWS } from '../lib/websocket';
2
2
  import { ApplicationData } from '../wallet/types';
3
3
  import { DaemonMethods } from '../daemon/websocket';
4
4
  import { WalletMethods } from '../wallet/websocket';
5
- declare class WS extends BaseWS {
5
+ export declare class WS extends BaseWS {
6
6
  daemon: DaemonMethods;
7
7
  wallet: WalletMethods;
8
8
  constructor();
package/xswd/websocket.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { WS as BaseWS } from '../lib/websocket';
2
2
  import { DaemonMethods } from '../daemon/websocket';
3
3
  import { WalletMethods } from '../wallet/websocket';
4
- class WS extends BaseWS {
4
+ export class WS extends BaseWS {
5
5
  constructor() {
6
6
  super();
7
7
  this.timeout = 0;