@talismn/balances 0.0.0-pr660-20230327112515 → 0.0.0-pr660-20230328111733
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 +6 -6
- package/dist/declarations/src/TalismanBalancesDatabase.d.ts +6 -0
- package/dist/declarations/src/helpers.d.ts +5 -1
- package/dist/declarations/src/types/balancetypes.d.ts +3 -1
- package/dist/talismn-balances.cjs.dev.js +26 -3
- package/dist/talismn-balances.cjs.prod.js +26 -3
- package/dist/talismn-balances.esm.js +25 -4
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# @talismn/balances
|
2
2
|
|
3
|
-
## 0.0.0-pr660-
|
3
|
+
## 0.0.0-pr660-20230328111733
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
@@ -12,11 +12,11 @@
|
|
12
12
|
- Updated dependencies [fa4d115f]
|
13
13
|
- Updated dependencies [79f6ccf6]
|
14
14
|
- Updated dependencies [c24dc1fb]
|
15
|
-
- @talismn/chain-connector@0.0.0-pr660-
|
16
|
-
- @talismn/util@0.0.0-pr660-
|
17
|
-
- @talismn/token-rates@0.0.0-pr660-
|
18
|
-
- @talismn/chaindata-provider@0.0.0-pr660-
|
19
|
-
- @talismn/chain-connector-evm@0.0.0-pr660-
|
15
|
+
- @talismn/chain-connector@0.0.0-pr660-20230328111733
|
16
|
+
- @talismn/util@0.0.0-pr660-20230328111733
|
17
|
+
- @talismn/token-rates@0.0.0-pr660-20230328111733
|
18
|
+
- @talismn/chaindata-provider@0.0.0-pr660-20230328111733
|
19
|
+
- @talismn/chain-connector-evm@0.0.0-pr660-20230328111733
|
20
20
|
|
21
21
|
## 0.3.3
|
22
22
|
|
@@ -1,7 +1,13 @@
|
|
1
1
|
import { Dexie } from "dexie";
|
2
2
|
import { BalanceJson } from "./types";
|
3
|
+
type BalancesDbMeta = {
|
4
|
+
id: string;
|
5
|
+
value: string;
|
6
|
+
};
|
3
7
|
export declare class TalismanBalancesDatabase extends Dexie {
|
4
8
|
balances: Dexie.Table<BalanceJson, string>;
|
9
|
+
meta: Dexie.Table<BalancesDbMeta, string>;
|
5
10
|
constructor();
|
6
11
|
}
|
7
12
|
export declare const db: TalismanBalancesDatabase;
|
13
|
+
export {};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { Registry } from "@polkadot/types-codec/types";
|
2
2
|
import { ChainId } from "@talismn/chaindata-provider";
|
3
3
|
import { BalanceModule, DefaultChainMeta, DefaultModuleConfig, DefaultTransferParams, ExtendableChainMeta, ExtendableModuleConfig, ExtendableTokenType, ExtendableTransferParams } from "./BalanceModule";
|
4
|
-
import { AddressesByToken, Balance, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
|
4
|
+
import { AddressesByToken, Balance, BalanceJson, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
|
5
5
|
/**
|
6
6
|
* Wraps a BalanceModule's fetch/subscribe methods with a single `balances` method.
|
7
7
|
* This `balances` method will subscribe if a callback parameter is provided, or otherwise fetch.
|
@@ -12,6 +12,10 @@ export declare const createTypeRegistryCache: () => {
|
|
12
12
|
getOrCreateTypeRegistry: (chainId: ChainId, metadataRpc?: `0x${string}`) => Registry;
|
13
13
|
};
|
14
14
|
export declare const filterMirrorTokens: (balance: Balance, i: number, balances: Balance[]) => boolean;
|
15
|
+
/**
|
16
|
+
* Sets all balance statuses from `live-${string}` to either `live` or `cached`
|
17
|
+
*/
|
18
|
+
export declare const deriveStatuses: (latestSubscriptionId: string | undefined, balances: BalanceJson[]) => BalanceJson[];
|
15
19
|
/**
|
16
20
|
* Used by a variety of balance modules to help encode and decode substrate state calls.
|
17
21
|
*/
|
@@ -23,7 +23,9 @@ export type BalanceTypes = {
|
|
23
23
|
export type BalanceJson = BalanceTypes[keyof BalanceTypes] extends never ? IBalance : BalanceTypes[keyof BalanceTypes];
|
24
24
|
/** A collection of `BalanceJson` objects */
|
25
25
|
export type BalanceJsonList = Record<string, BalanceJson>;
|
26
|
-
export type
|
26
|
+
export type BalanceStatusLive = `live-${string}`;
|
27
|
+
export declare const BalanceStatusLive: (subscriptionId: string) => BalanceStatusLive;
|
28
|
+
export type BalanceStatus = BalanceStatusLive | "live" | "cache" | "stale";
|
27
29
|
/** `IBalance` is a common interface which all balance types must implement. */
|
28
30
|
export type IBalance = {
|
29
31
|
/** The module that this balance was retrieved by */
|
@@ -49,14 +49,15 @@ class TalismanBalancesDatabase extends dexie.Dexie {
|
|
49
49
|
super("TalismanBalances");
|
50
50
|
|
51
51
|
// https://dexie.org/docs/Tutorial/Design#database-versioning
|
52
|
-
this.version(
|
52
|
+
this.version(2).stores({
|
53
53
|
// You only need to specify properties that you wish to index.
|
54
54
|
// The object store will allow any properties on your stored objects but you can only query them by indexed properties
|
55
55
|
// https://dexie.org/docs/API-Reference#declare-database
|
56
56
|
//
|
57
57
|
// Never index properties containing images, movies or large (huge) strings. Store them in IndexedDB, yes! but just don’t index them!
|
58
58
|
// https://dexie.org/docs/Version/Version.stores()#warning
|
59
|
-
balances: "id, source, status, address, tokenId"
|
59
|
+
balances: "id, source, status, address, tokenId",
|
60
|
+
meta: "id"
|
60
61
|
});
|
61
62
|
|
62
63
|
// this.on("ready", async () => {})
|
@@ -67,7 +68,7 @@ const db = new TalismanBalancesDatabase();
|
|
67
68
|
|
68
69
|
var packageJson = {
|
69
70
|
name: "@talismn/balances",
|
70
|
-
version: "0.0.0-pr660-
|
71
|
+
version: "0.0.0-pr660-20230328111733",
|
71
72
|
author: "Talisman",
|
72
73
|
homepage: "https://talisman.xyz",
|
73
74
|
license: "UNLICENSED",
|
@@ -162,6 +163,25 @@ const filterMirrorTokens = (balance, i, balances) => {
|
|
162
163
|
return !mirrorOf || !balances.find(b => b.tokenId === mirrorOf);
|
163
164
|
};
|
164
165
|
|
166
|
+
/**
|
167
|
+
* Sets all balance statuses from `live-${string}` to either `live` or `cached`
|
168
|
+
*/
|
169
|
+
const deriveStatuses = (latestSubscriptionId, balances) => balances.map(balance => {
|
170
|
+
if (balance.status === "live" || balance.status === "cache" || balance.status === "stale") return balance;
|
171
|
+
if (!latestSubscriptionId) return {
|
172
|
+
...balance,
|
173
|
+
status: "cache"
|
174
|
+
};
|
175
|
+
if (balance.status.slice("live-".length) !== latestSubscriptionId) return {
|
176
|
+
...balance,
|
177
|
+
status: "cache"
|
178
|
+
};
|
179
|
+
return {
|
180
|
+
...balance,
|
181
|
+
status: "live"
|
182
|
+
};
|
183
|
+
});
|
184
|
+
|
165
185
|
/**
|
166
186
|
* Used by a variety of balance modules to help encode and decode substrate state calls.
|
167
187
|
*/
|
@@ -243,6 +263,7 @@ class StorageHelper {
|
|
243
263
|
}
|
244
264
|
}
|
245
265
|
|
266
|
+
const BalanceStatusLive = subscriptionId => `live-${subscriptionId}`;
|
246
267
|
function excludeFromTransferableAmount(locks) {
|
247
268
|
if (typeof locks === "string") return BigInt(locks);
|
248
269
|
if (!Array.isArray(locks)) locks = [locks];
|
@@ -672,6 +693,7 @@ class SumBalancesFormatter {
|
|
672
693
|
|
673
694
|
exports.Balance = Balance;
|
674
695
|
exports.BalanceFormatter = BalanceFormatter;
|
696
|
+
exports.BalanceStatusLive = BalanceStatusLive;
|
675
697
|
exports.Balances = Balances;
|
676
698
|
exports.DefaultBalanceModule = DefaultBalanceModule;
|
677
699
|
exports.FiatSumBalancesFormatter = FiatSumBalancesFormatter;
|
@@ -681,6 +703,7 @@ exports.TalismanBalancesDatabase = TalismanBalancesDatabase;
|
|
681
703
|
exports.balances = balances;
|
682
704
|
exports.createTypeRegistryCache = createTypeRegistryCache;
|
683
705
|
exports.db = db;
|
706
|
+
exports.deriveStatuses = deriveStatuses;
|
684
707
|
exports.excludeFromFeePayableLocks = excludeFromFeePayableLocks;
|
685
708
|
exports.excludeFromTransferableAmount = excludeFromTransferableAmount;
|
686
709
|
exports.filterMirrorTokens = filterMirrorTokens;
|
@@ -49,14 +49,15 @@ class TalismanBalancesDatabase extends dexie.Dexie {
|
|
49
49
|
super("TalismanBalances");
|
50
50
|
|
51
51
|
// https://dexie.org/docs/Tutorial/Design#database-versioning
|
52
|
-
this.version(
|
52
|
+
this.version(2).stores({
|
53
53
|
// You only need to specify properties that you wish to index.
|
54
54
|
// The object store will allow any properties on your stored objects but you can only query them by indexed properties
|
55
55
|
// https://dexie.org/docs/API-Reference#declare-database
|
56
56
|
//
|
57
57
|
// Never index properties containing images, movies or large (huge) strings. Store them in IndexedDB, yes! but just don’t index them!
|
58
58
|
// https://dexie.org/docs/Version/Version.stores()#warning
|
59
|
-
balances: "id, source, status, address, tokenId"
|
59
|
+
balances: "id, source, status, address, tokenId",
|
60
|
+
meta: "id"
|
60
61
|
});
|
61
62
|
|
62
63
|
// this.on("ready", async () => {})
|
@@ -67,7 +68,7 @@ const db = new TalismanBalancesDatabase();
|
|
67
68
|
|
68
69
|
var packageJson = {
|
69
70
|
name: "@talismn/balances",
|
70
|
-
version: "0.0.0-pr660-
|
71
|
+
version: "0.0.0-pr660-20230328111733",
|
71
72
|
author: "Talisman",
|
72
73
|
homepage: "https://talisman.xyz",
|
73
74
|
license: "UNLICENSED",
|
@@ -162,6 +163,25 @@ const filterMirrorTokens = (balance, i, balances) => {
|
|
162
163
|
return !mirrorOf || !balances.find(b => b.tokenId === mirrorOf);
|
163
164
|
};
|
164
165
|
|
166
|
+
/**
|
167
|
+
* Sets all balance statuses from `live-${string}` to either `live` or `cached`
|
168
|
+
*/
|
169
|
+
const deriveStatuses = (latestSubscriptionId, balances) => balances.map(balance => {
|
170
|
+
if (balance.status === "live" || balance.status === "cache" || balance.status === "stale") return balance;
|
171
|
+
if (!latestSubscriptionId) return {
|
172
|
+
...balance,
|
173
|
+
status: "cache"
|
174
|
+
};
|
175
|
+
if (balance.status.slice("live-".length) !== latestSubscriptionId) return {
|
176
|
+
...balance,
|
177
|
+
status: "cache"
|
178
|
+
};
|
179
|
+
return {
|
180
|
+
...balance,
|
181
|
+
status: "live"
|
182
|
+
};
|
183
|
+
});
|
184
|
+
|
165
185
|
/**
|
166
186
|
* Used by a variety of balance modules to help encode and decode substrate state calls.
|
167
187
|
*/
|
@@ -243,6 +263,7 @@ class StorageHelper {
|
|
243
263
|
}
|
244
264
|
}
|
245
265
|
|
266
|
+
const BalanceStatusLive = subscriptionId => `live-${subscriptionId}`;
|
246
267
|
function excludeFromTransferableAmount(locks) {
|
247
268
|
if (typeof locks === "string") return BigInt(locks);
|
248
269
|
if (!Array.isArray(locks)) locks = [locks];
|
@@ -672,6 +693,7 @@ class SumBalancesFormatter {
|
|
672
693
|
|
673
694
|
exports.Balance = Balance;
|
674
695
|
exports.BalanceFormatter = BalanceFormatter;
|
696
|
+
exports.BalanceStatusLive = BalanceStatusLive;
|
675
697
|
exports.Balances = Balances;
|
676
698
|
exports.DefaultBalanceModule = DefaultBalanceModule;
|
677
699
|
exports.FiatSumBalancesFormatter = FiatSumBalancesFormatter;
|
@@ -681,6 +703,7 @@ exports.TalismanBalancesDatabase = TalismanBalancesDatabase;
|
|
681
703
|
exports.balances = balances;
|
682
704
|
exports.createTypeRegistryCache = createTypeRegistryCache;
|
683
705
|
exports.db = db;
|
706
|
+
exports.deriveStatuses = deriveStatuses;
|
684
707
|
exports.excludeFromFeePayableLocks = excludeFromFeePayableLocks;
|
685
708
|
exports.excludeFromTransferableAmount = excludeFromTransferableAmount;
|
686
709
|
exports.filterMirrorTokens = filterMirrorTokens;
|
@@ -41,14 +41,15 @@ class TalismanBalancesDatabase extends Dexie {
|
|
41
41
|
super("TalismanBalances");
|
42
42
|
|
43
43
|
// https://dexie.org/docs/Tutorial/Design#database-versioning
|
44
|
-
this.version(
|
44
|
+
this.version(2).stores({
|
45
45
|
// You only need to specify properties that you wish to index.
|
46
46
|
// The object store will allow any properties on your stored objects but you can only query them by indexed properties
|
47
47
|
// https://dexie.org/docs/API-Reference#declare-database
|
48
48
|
//
|
49
49
|
// Never index properties containing images, movies or large (huge) strings. Store them in IndexedDB, yes! but just don’t index them!
|
50
50
|
// https://dexie.org/docs/Version/Version.stores()#warning
|
51
|
-
balances: "id, source, status, address, tokenId"
|
51
|
+
balances: "id, source, status, address, tokenId",
|
52
|
+
meta: "id"
|
52
53
|
});
|
53
54
|
|
54
55
|
// this.on("ready", async () => {})
|
@@ -59,7 +60,7 @@ const db = new TalismanBalancesDatabase();
|
|
59
60
|
|
60
61
|
var packageJson = {
|
61
62
|
name: "@talismn/balances",
|
62
|
-
version: "0.0.0-pr660-
|
63
|
+
version: "0.0.0-pr660-20230328111733",
|
63
64
|
author: "Talisman",
|
64
65
|
homepage: "https://talisman.xyz",
|
65
66
|
license: "UNLICENSED",
|
@@ -154,6 +155,25 @@ const filterMirrorTokens = (balance, i, balances) => {
|
|
154
155
|
return !mirrorOf || !balances.find(b => b.tokenId === mirrorOf);
|
155
156
|
};
|
156
157
|
|
158
|
+
/**
|
159
|
+
* Sets all balance statuses from `live-${string}` to either `live` or `cached`
|
160
|
+
*/
|
161
|
+
const deriveStatuses = (latestSubscriptionId, balances) => balances.map(balance => {
|
162
|
+
if (balance.status === "live" || balance.status === "cache" || balance.status === "stale") return balance;
|
163
|
+
if (!latestSubscriptionId) return {
|
164
|
+
...balance,
|
165
|
+
status: "cache"
|
166
|
+
};
|
167
|
+
if (balance.status.slice("live-".length) !== latestSubscriptionId) return {
|
168
|
+
...balance,
|
169
|
+
status: "cache"
|
170
|
+
};
|
171
|
+
return {
|
172
|
+
...balance,
|
173
|
+
status: "live"
|
174
|
+
};
|
175
|
+
});
|
176
|
+
|
157
177
|
/**
|
158
178
|
* Used by a variety of balance modules to help encode and decode substrate state calls.
|
159
179
|
*/
|
@@ -235,6 +255,7 @@ class StorageHelper {
|
|
235
255
|
}
|
236
256
|
}
|
237
257
|
|
258
|
+
const BalanceStatusLive = subscriptionId => `live-${subscriptionId}`;
|
238
259
|
function excludeFromTransferableAmount(locks) {
|
239
260
|
if (typeof locks === "string") return BigInt(locks);
|
240
261
|
if (!Array.isArray(locks)) locks = [locks];
|
@@ -662,4 +683,4 @@ class SumBalancesFormatter {
|
|
662
683
|
}
|
663
684
|
}
|
664
685
|
|
665
|
-
export { Balance, BalanceFormatter, Balances, DefaultBalanceModule, FiatSumBalancesFormatter, StorageHelper, SumBalancesFormatter, TalismanBalancesDatabase, balances, createTypeRegistryCache, db, excludeFromFeePayableLocks, excludeFromTransferableAmount, filterMirrorTokens, includeInTotalExtraAmount };
|
686
|
+
export { Balance, BalanceFormatter, BalanceStatusLive, Balances, DefaultBalanceModule, FiatSumBalancesFormatter, StorageHelper, SumBalancesFormatter, TalismanBalancesDatabase, balances, createTypeRegistryCache, db, deriveStatuses, excludeFromFeePayableLocks, excludeFromTransferableAmount, filterMirrorTokens, includeInTotalExtraAmount };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/balances",
|
3
|
-
"version": "0.0.0-pr660-
|
3
|
+
"version": "0.0.0-pr660-20230328111733",
|
4
4
|
"author": "Talisman",
|
5
5
|
"homepage": "https://talisman.xyz",
|
6
6
|
"license": "UNLICENSED",
|
@@ -27,11 +27,11 @@
|
|
27
27
|
"clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
|
28
28
|
},
|
29
29
|
"dependencies": {
|
30
|
-
"@talismn/chain-connector": "^0.0.0-pr660-
|
31
|
-
"@talismn/chain-connector-evm": "^0.0.0-pr660-
|
32
|
-
"@talismn/chaindata-provider": "^0.0.0-pr660-
|
33
|
-
"@talismn/token-rates": "^0.0.0-pr660-
|
34
|
-
"@talismn/util": "^0.0.0-pr660-
|
30
|
+
"@talismn/chain-connector": "^0.0.0-pr660-20230328111733",
|
31
|
+
"@talismn/chain-connector-evm": "^0.0.0-pr660-20230328111733",
|
32
|
+
"@talismn/chaindata-provider": "^0.0.0-pr660-20230328111733",
|
33
|
+
"@talismn/token-rates": "^0.0.0-pr660-20230328111733",
|
34
|
+
"@talismn/util": "^0.0.0-pr660-20230328111733",
|
35
35
|
"anylogger": "^1.0.11",
|
36
36
|
"dexie": "^3.2.3"
|
37
37
|
},
|