@autonomys/auto-utils 0.1.3-alpha.0 → 0.1.3

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
@@ -1,4 +1,4 @@
1
- import { ApiPromise } from '@polkadot/api';
1
+ import type { ApiPromise } from './types/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>;
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":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAQhE,eAAO,MAAM,QAAQ,WAAkB,YAAY,KAAG,QAAQ,UAAU,CASvE,CAAA;AAED,eAAO,MAAM,cAAc,UAAiB,WAAW,KAAG,QAAQ,UAAU,CAS3E,CAAA;AAED,eAAO,MAAM,UAAU,QAAa,QAAQ,IAAI,CAO/C,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAa,QAAQ,IAAI,CAOrD,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) {
@@ -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,3 +1,4 @@
1
+ export * from './api';
1
2
  export * from './network';
2
3
  export * from './wallet';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -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,OAAO,CAAA;AACrB,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);
@@ -15,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
15
  };
17
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api"), exports);
18
18
  __exportStar(require("./network"), exports);
19
19
  __exportStar(require("./wallet"), exports);
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.0",
3
+ "version": "0.1.3",
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": "438f0fefdd77e291689a8a1233e28bc8792d5503"
39
+ "gitHead": "457844c0907bafa6079549968fba6c3a299618ff"
40
40
  }