@autonomys/auto-utils 0.1.3-alpha.1 → 0.1.4

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/api.d.ts CHANGED
@@ -2,6 +2,5 @@ import { ApiPromise } from '@polkadot/api';
2
2
  import type { DomainInput, NetworkInput } from './types/network';
3
3
  export declare const activate: (input?: NetworkInput) => Promise<ApiPromise>;
4
4
  export declare const activateDomain: (input: DomainInput) => Promise<ApiPromise>;
5
- export declare const disconnect: () => Promise<void>;
6
- export declare const disconnectDomain: () => Promise<void>;
5
+ export declare const disconnect: (api: ApiPromise) => Promise<void>;
7
6
  //# sourceMappingURL=api.d.ts.map
package/dist/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAc,MAAM,eAAe,CAAA;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAQhE,eAAO,MAAM,QAAQ,WAAkB,YAAY,wBASlD,CAAA;AAED,eAAO,MAAM,cAAc,UAAiB,WAAW,wBAStD,CAAA;AAED,eAAO,MAAM,UAAU,qBAOtB,CAAA;AAED,eAAO,MAAM,gBAAgB,qBAO5B,CAAA"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,eAAe,CAAA;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAEhE,eAAO,MAAM,QAAQ,WAAkB,YAAY,KAAG,QAAQ,UAAU,CAUvE,CAAA;AAED,eAAO,MAAM,cAAc,UAAiB,WAAW,KAAG,QAAQ,UAAU,CAU3E,CAAA;AAED,eAAO,MAAM,UAAU,QAAe,UAAU,KAAG,QAAQ,IAAI,CAG9D,CAAA"}
package/dist/api.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // file: src/api.ts
3
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -10,48 +9,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
9
  });
11
10
  };
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.disconnectDomain = exports.disconnect = exports.activateDomain = exports.activate = void 0;
12
+ exports.disconnect = exports.activateDomain = exports.activate = void 0;
14
13
  const api_1 = require("@polkadot/api");
15
14
  const network_1 = require("./network");
16
- let provider = null;
17
- let apiInstance = null;
18
- let domainProvider = null;
19
- let apiDomainInstance = null;
20
15
  const activate = (input) => __awaiter(void 0, void 0, void 0, function* () {
21
16
  // Get the first rpc urls for the network
22
17
  const rpcUrl = (0, network_1.getNetworkRpcUrls)(input);
23
18
  // Create the provider
24
- provider = new api_1.WsProvider(rpcUrl[0]);
19
+ const provider = new api_1.WsProvider(rpcUrl[0]);
25
20
  // Create the API instance
26
- apiInstance = yield api_1.ApiPromise.create({ provider });
27
- return apiInstance;
21
+ const api = yield api_1.ApiPromise.create({ provider });
22
+ yield api.isReady;
23
+ return api;
28
24
  });
29
25
  exports.activate = activate;
30
26
  const activateDomain = (input) => __awaiter(void 0, void 0, void 0, function* () {
31
27
  // Get the first rpc urls for the network
32
28
  const rpcUrl = (0, network_1.getNetworkDomainRpcUrls)(input);
33
29
  // Create the provider
34
- domainProvider = new api_1.WsProvider(rpcUrl[0]);
30
+ const provider = new api_1.WsProvider(rpcUrl[0]);
35
31
  // Create the API instance
36
- apiDomainInstance = yield api_1.ApiPromise.create({ provider: domainProvider });
37
- return apiDomainInstance;
32
+ const api = yield api_1.ApiPromise.create({ provider });
33
+ yield api.isReady;
34
+ return api;
38
35
  });
39
36
  exports.activateDomain = activateDomain;
40
- const disconnect = () => __awaiter(void 0, void 0, void 0, function* () {
41
- // Disconnect the API instance and the provider if they exist
42
- if (apiInstance) {
43
- yield apiInstance.disconnect();
44
- apiInstance = null;
45
- provider = null;
46
- }
37
+ const disconnect = (api) => __awaiter(void 0, void 0, void 0, function* () {
38
+ // Disconnect the API instance and the provider
39
+ yield api.disconnect();
47
40
  });
48
41
  exports.disconnect = disconnect;
49
- const disconnectDomain = () => __awaiter(void 0, void 0, void 0, function* () {
50
- // Disconnect the API instance and the provider if they exist
51
- if (apiDomainInstance) {
52
- yield apiDomainInstance.disconnect();
53
- apiDomainInstance = null;
54
- domainProvider = null;
55
- }
56
- });
57
- exports.disconnectDomain = disconnectDomain;
@@ -1,3 +1,4 @@
1
1
  export * from './network';
2
+ export * from './token';
2
3
  export * from './wallet';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./network"), exports);
19
+ __exportStar(require("./token"), exports);
19
20
  __exportStar(require("./wallet"), exports);
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_TOKEN_DECIMALS = 18;
2
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/constants/token.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,KAAK,CAAA"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_TOKEN_DECIMALS = void 0;
4
+ exports.DEFAULT_TOKEN_DECIMALS = 18;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './api';
2
2
  export * from './crypto';
3
3
  export * from './network';
4
+ export * from './number';
4
5
  export * from './read';
5
6
  export * from './save';
6
7
  export * from './wallet';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AAExB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AAExB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./api"), exports);
19
19
  __exportStar(require("./crypto"), exports);
20
20
  __exportStar(require("./network"), exports);
21
+ __exportStar(require("./number"), exports);
21
22
  __exportStar(require("./read"), exports);
22
23
  __exportStar(require("./save"), exports);
23
24
  __exportStar(require("./wallet"), exports);
@@ -0,0 +1,3 @@
1
+ export declare const parseTokenAmount: (amount: string | bigint, decimals?: number) => number | bigint;
2
+ export declare const formatTokenAmount: (amount: number | bigint, decimals?: number) => number | bigint;
3
+ //# sourceMappingURL=number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,WACnB,MAAM,GAAG,MAAM,aACb,MAAM,oBAIjB,CAAA;AAED,eAAO,MAAM,iBAAiB,WACpB,MAAM,GAAG,MAAM,aACb,MAAM,oBAIjB,CAAA"}
package/dist/number.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatTokenAmount = exports.parseTokenAmount = void 0;
4
+ const token_1 = require("./constants/token");
5
+ const parseTokenAmount = (amount, decimals = token_1.DEFAULT_TOKEN_DECIMALS) => {
6
+ if (typeof amount === 'bigint')
7
+ return amount / BigInt(Math.pow(10, decimals));
8
+ return parseFloat(amount) / Math.pow(10, decimals);
9
+ };
10
+ exports.parseTokenAmount = parseTokenAmount;
11
+ const formatTokenAmount = (amount, decimals = token_1.DEFAULT_TOKEN_DECIMALS) => {
12
+ if (typeof amount === 'bigint')
13
+ return amount * BigInt(Math.pow(10, decimals));
14
+ return amount * Math.pow(10, decimals);
15
+ };
16
+ exports.formatTokenAmount = formatTokenAmount;
@@ -0,0 +1,3 @@
1
+ import type { ApiPromise as PolkadotApiPromise } from '@polkadot/api';
2
+ export type ApiPromise = PolkadotApiPromise;
3
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAErE,MAAM,MAAM,UAAU,GAAG,kBAAkB,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA"}
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // file: src/types/index.ts
3
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
3
  if (k2 === undefined) k2 = k;
5
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
package/dist/wallet.js CHANGED
@@ -62,7 +62,12 @@ const activateWallet = (input) => __awaiter(void 0, void 0, void 0, function* ()
62
62
  ? yield (0, api_2.activate)(input)
63
63
  : yield (0, api_2.activateDomain)(input);
64
64
  const accounts = [];
65
- if (typeof window !== 'undefined') {
65
+ if (input.mnemonic || input.uri) {
66
+ // Attach the wallet in a node environment
67
+ const account = yield (0, exports.setupWallet)(input);
68
+ accounts.push(account);
69
+ }
70
+ else if (typeof window !== 'undefined') {
66
71
  const { web3Enable, web3Accounts } = yield Promise.resolve().then(() => __importStar(require('@polkadot/extension-dapp')));
67
72
  // Enable Polkadot.js extension in the browser
68
73
  yield web3Enable(input.appName || 'Auto');
@@ -72,11 +77,6 @@ const activateWallet = (input) => __awaiter(void 0, void 0, void 0, function* ()
72
77
  if (allAccounts.length === 0)
73
78
  console.warn('No accounts found in the Polkadot.js extension');
74
79
  }
75
- else if (input.mnemonic || input.uri) {
76
- // Attach the wallet in a node environment
77
- const account = yield (0, exports.setupWallet)(input);
78
- accounts.push(account);
79
- }
80
80
  else
81
81
  throw new Error('No wallet provided');
82
82
  return { api, accounts };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autonomys/auto-utils",
3
- "version": "0.1.3-alpha.1",
3
+ "version": "0.1.4",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -36,5 +36,5 @@
36
36
  "browser": {
37
37
  "fs": false
38
38
  },
39
- "gitHead": "040b7e1835cbdc80a897e37f03579901dbb50243"
39
+ "gitHead": "bf1aacdebad697135f8cbcf4a359e7c2a9188e24"
40
40
  }