@talismn/balances 0.1.17 → 0.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @talismn/balances
2
2
 
3
+ ## 0.1.18
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: a variety of improvements from the wallet integration
8
+ - Updated dependencies
9
+ - @talismn/chain-connector@0.1.10
10
+ - @talismn/chain-connector-evm@0.1.10
11
+ - @talismn/chaindata-provider@0.1.10
12
+ - @talismn/token-rates@0.1.10
13
+ - @talismn/util@0.1.4
14
+
3
15
  ## 0.1.17
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,7 @@
1
+ import { Dexie } from "dexie";
2
+ import { BalanceJson } from "./types";
3
+ export declare class TalismanBalancesDatabase extends Dexie {
4
+ balances: Dexie.Table<BalanceJson, string>;
5
+ constructor();
6
+ }
7
+ export declare const db: TalismanBalancesDatabase;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.db = exports.TalismanBalancesDatabase = void 0;
4
+ const dexie_1 = require("dexie");
5
+ class TalismanBalancesDatabase extends dexie_1.Dexie {
6
+ constructor() {
7
+ super("TalismanBalances");
8
+ // https://dexie.org/docs/Tutorial/Design#database-versioning
9
+ this.version(1).stores({
10
+ // You only need to specify properties that you wish to index.
11
+ // The object store will allow any properties on your stored objects but you can only query them by indexed properties
12
+ // https://dexie.org/docs/API-Reference#declare-database
13
+ //
14
+ // Never index properties containing images, movies or large (huge) strings. Store them in IndexedDB, yes! but just don’t index them!
15
+ // https://dexie.org/docs/Version/Version.stores()#warning
16
+ balances: "id, source, status, address, tokenId",
17
+ });
18
+ // this.on("ready", async () => {})
19
+ }
20
+ }
21
+ exports.TalismanBalancesDatabase = TalismanBalancesDatabase;
22
+ exports.db = new TalismanBalancesDatabase();
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./BalanceModule";
2
+ export * from "./TalismanBalancesDatabase";
2
3
  export * from "./helpers";
3
4
  export * from "./types";
package/dist/index.js CHANGED
@@ -26,5 +26,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
28
  __exportStar(require("./BalanceModule"), exports);
29
+ __exportStar(require("./TalismanBalancesDatabase"), exports);
29
30
  __exportStar(require("./helpers"), exports);
30
31
  __exportStar(require("./types"), exports);
package/dist/log.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const _default: import("anylogger").Logger<import("anylogger").BaseLevels>;
2
+ export default _default;
package/dist/log.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const anylogger_1 = __importDefault(require("anylogger"));
7
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8
+ const { name } = require("../package.json");
9
+ // import { name } from "../package.json"
10
+ exports.default = (0, anylogger_1.default)(name);
@@ -122,6 +122,7 @@ export declare class Balance {
122
122
  get tokenId(): string;
123
123
  get token(): import("@talismn/chaindata-provider").IToken | null;
124
124
  get decimals(): number | null;
125
+ get rates(): TokenRates | null;
125
126
  /**
126
127
  * The total balance of this token.
127
128
  * Includes the free and the reserved amount.
@@ -143,7 +144,7 @@ export declare class Balance {
143
144
  }
144
145
  export declare class BalanceFormatter {
145
146
  #private;
146
- constructor(planck: string | bigint, decimals?: number, fiatRatios?: TokenRates);
147
+ constructor(planck: string | bigint | undefined, decimals?: number | undefined, fiatRatios?: TokenRates);
147
148
  toJSON: () => string;
148
149
  get planck(): bigint;
149
150
  get tokens(): string;
@@ -25,6 +25,7 @@ exports.SumBalancesFormatter = exports.FiatSumBalancesFormatter = exports.Balanc
25
25
  const util_1 = require("@talismn/util");
26
26
  const memoize_1 = __importDefault(require("lodash/memoize"));
27
27
  const typescript_memoize_1 = require("typescript-memoize");
28
+ const log_1 = __importDefault(require("../log"));
28
29
  const balancetypes_1 = require("./balancetypes");
29
30
  /**
30
31
  * A collection of balances.
@@ -45,7 +46,17 @@ class Balances {
45
46
  /**
46
47
  * Calling toJSON on a collection of balances will return the underlying BalanceJsonList.
47
48
  */
48
- this.toJSON = () => Object.fromEntries(Object.entries(__classPrivateFieldGet(this, _Balances_balances, "f")).map(([id, balance]) => [id, balance.toJSON()]));
49
+ this.toJSON = () => Object.fromEntries(Object.entries(__classPrivateFieldGet(this, _Balances_balances, "f"))
50
+ .map(([id, balance]) => {
51
+ try {
52
+ return [id, balance.toJSON()];
53
+ }
54
+ catch (error) {
55
+ log_1.default.error("Failed to convert balance to JSON", error, { id, balance });
56
+ return null;
57
+ }
58
+ })
59
+ .filter(Array.isArray));
49
60
  /**
50
61
  * Allows the collection to be iterated over.
51
62
  *
@@ -286,6 +297,10 @@ class Balance {
286
297
  var _b;
287
298
  return ((_b = this.token) === null || _b === void 0 ? void 0 : _b.decimals) || null;
288
299
  }
300
+ get rates() {
301
+ var _b;
302
+ return (((_b = __classPrivateFieldGet(this, _Balance_db, "f")) === null || _b === void 0 ? void 0 : _b.tokenRates) && __classPrivateFieldGet(this, _Balance_db, "f").tokenRates[this.tokenId]) || null;
303
+ }
289
304
  /**
290
305
  * The total balance of this token.
291
306
  * Includes the free and the reserved amount.
@@ -384,7 +399,7 @@ class BalanceFormatter {
384
399
  _BalanceFormatter_decimals.set(this, void 0);
385
400
  _BalanceFormatter_fiatRatios.set(this, void 0);
386
401
  this.toJSON = () => __classPrivateFieldGet(this, _BalanceFormatter_planck, "f");
387
- __classPrivateFieldSet(this, _BalanceFormatter_planck, typeof planck === "bigint" ? planck.toString() : planck, "f");
402
+ __classPrivateFieldSet(this, _BalanceFormatter_planck, typeof planck === "bigint" ? planck.toString() : planck !== null && planck !== void 0 ? planck : "0", "f");
388
403
  __classPrivateFieldSet(this, _BalanceFormatter_decimals, decimals || 0, "f");
389
404
  __classPrivateFieldSet(this, _BalanceFormatter_fiatRatios, fiatRatios || null, "f");
390
405
  this.fiat = (0, memoize_1.default)(this.fiat);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/balances",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "UNLICENSED",
@@ -31,11 +31,11 @@
31
31
  "clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
32
32
  },
33
33
  "dependencies": {
34
- "@talismn/chain-connector": "^0.1.9",
35
- "@talismn/chain-connector-evm": "^0.1.9",
36
- "@talismn/chaindata-provider": "^0.1.9",
37
- "@talismn/token-rates": "^0.1.9",
38
- "@talismn/util": "^0.1.3",
34
+ "@talismn/chain-connector": "^0.1.10",
35
+ "@talismn/chain-connector-evm": "^0.1.10",
36
+ "@talismn/chaindata-provider": "^0.1.10",
37
+ "@talismn/token-rates": "^0.1.10",
38
+ "@talismn/util": "^0.1.4",
39
39
  "lodash": "^4.17.21",
40
40
  "typescript-memoize": "^1.1.0"
41
41
  },