@metamask-previews/assets-controller 20.2.3-preview-4dd847ca3 → 20.2.3-preview-2ad7fb9
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 +19 -0
- package/README.md +6 -0
- package/dist/AssetsController.d.ts +11 -2
- package/dist/AssetsController.d.ts.map +1 -1
- package/dist/AssetsController.js +55 -7
- package/dist/AssetsController.js.map +1 -1
- package/dist/accounts-api-balances-service/accounts-api-balances-service-method-action-types.d.ts +22 -0
- package/dist/accounts-api-balances-service/accounts-api-balances-service-method-action-types.d.ts.map +1 -0
- package/dist/accounts-api-balances-service/accounts-api-balances-service-method-action-types.js +6 -0
- package/dist/accounts-api-balances-service/accounts-api-balances-service-method-action-types.js.map +1 -0
- package/dist/accounts-api-balances-service/accounts-api-balances-service.d.ts +140 -0
- package/dist/accounts-api-balances-service/accounts-api-balances-service.d.ts.map +1 -0
- package/dist/accounts-api-balances-service/accounts-api-balances-service.js +280 -0
- package/dist/accounts-api-balances-service/accounts-api-balances-service.js.map +1 -0
- package/dist/accounts-api-balances-service/structs.d.ts +208 -0
- package/dist/accounts-api-balances-service/structs.d.ts.map +1 -0
- package/dist/accounts-api-balances-service/structs.js +92 -0
- package/dist/accounts-api-balances-service/structs.js.map +1 -0
- package/dist/assetsFetchTracker.d.ts +31 -0
- package/dist/assetsFetchTracker.d.ts.map +1 -0
- package/dist/assetsFetchTracker.js +85 -0
- package/dist/assetsFetchTracker.js.map +1 -0
- package/dist/data-sources/AccountsApiDataSource.d.ts +20 -3
- package/dist/data-sources/AccountsApiDataSource.d.ts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.js +66 -4
- package/dist/data-sources/AccountsApiDataSource.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/selectors/fetchStatus.d.ts +36 -0
- package/dist/selectors/fetchStatus.d.ts.map +1 -0
- package/dist/selectors/fetchStatus.js +44 -0
- package/dist/selectors/fetchStatus.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import type { Infer } from '@metamask/superstruct';
|
|
2
|
+
/** Accounts API v5 multi account balances response. */
|
|
3
|
+
export declare const V5BalancesResponseStruct: import("@metamask/superstruct").Struct<{
|
|
4
|
+
count: number;
|
|
5
|
+
unprocessedNetworks: string[];
|
|
6
|
+
balances: {
|
|
7
|
+
object?: string | null | undefined;
|
|
8
|
+
symbol?: string | null | undefined;
|
|
9
|
+
name?: string | null | undefined;
|
|
10
|
+
type?: string | null | undefined;
|
|
11
|
+
decimals?: number | null | undefined;
|
|
12
|
+
assetId: string;
|
|
13
|
+
balance: string;
|
|
14
|
+
accountId: string;
|
|
15
|
+
metadata?: {
|
|
16
|
+
limit?: string | undefined;
|
|
17
|
+
authorized?: boolean | undefined;
|
|
18
|
+
sponsored?: boolean | undefined;
|
|
19
|
+
spendableBalance?: string | undefined;
|
|
20
|
+
minimumReserveBalance?: string | undefined;
|
|
21
|
+
} | null | undefined;
|
|
22
|
+
}[];
|
|
23
|
+
}, {
|
|
24
|
+
count: import("@metamask/superstruct").Struct<number, null>;
|
|
25
|
+
unprocessedNetworks: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
|
|
26
|
+
balances: import("@metamask/superstruct").Struct<{
|
|
27
|
+
object?: string | null | undefined;
|
|
28
|
+
symbol?: string | null | undefined;
|
|
29
|
+
name?: string | null | undefined;
|
|
30
|
+
type?: string | null | undefined;
|
|
31
|
+
decimals?: number | null | undefined;
|
|
32
|
+
assetId: string;
|
|
33
|
+
balance: string;
|
|
34
|
+
accountId: string;
|
|
35
|
+
metadata?: {
|
|
36
|
+
limit?: string | undefined;
|
|
37
|
+
authorized?: boolean | undefined;
|
|
38
|
+
sponsored?: boolean | undefined;
|
|
39
|
+
spendableBalance?: string | undefined;
|
|
40
|
+
minimumReserveBalance?: string | undefined;
|
|
41
|
+
} | null | undefined;
|
|
42
|
+
}[], import("@metamask/superstruct").Struct<{
|
|
43
|
+
object?: string | null | undefined;
|
|
44
|
+
symbol?: string | null | undefined;
|
|
45
|
+
name?: string | null | undefined;
|
|
46
|
+
type?: string | null | undefined;
|
|
47
|
+
decimals?: number | null | undefined;
|
|
48
|
+
assetId: string;
|
|
49
|
+
balance: string;
|
|
50
|
+
accountId: string;
|
|
51
|
+
metadata?: {
|
|
52
|
+
limit?: string | undefined;
|
|
53
|
+
authorized?: boolean | undefined;
|
|
54
|
+
sponsored?: boolean | undefined;
|
|
55
|
+
spendableBalance?: string | undefined;
|
|
56
|
+
minimumReserveBalance?: string | undefined;
|
|
57
|
+
} | null | undefined;
|
|
58
|
+
}, {
|
|
59
|
+
object: import("@metamask/superstruct").Struct<string | null | undefined, null>;
|
|
60
|
+
symbol: import("@metamask/superstruct").Struct<string | null | undefined, null>;
|
|
61
|
+
name: import("@metamask/superstruct").Struct<string | null | undefined, null>;
|
|
62
|
+
type: import("@metamask/superstruct").Struct<string | null | undefined, null>;
|
|
63
|
+
decimals: import("@metamask/superstruct").Struct<number | null | undefined, null>;
|
|
64
|
+
assetId: import("@metamask/superstruct").Struct<string, null>;
|
|
65
|
+
balance: import("@metamask/superstruct").Struct<string, null>;
|
|
66
|
+
accountId: import("@metamask/superstruct").Struct<string, null>;
|
|
67
|
+
metadata: import("@metamask/superstruct").Struct<{
|
|
68
|
+
limit?: string | undefined;
|
|
69
|
+
authorized?: boolean | undefined;
|
|
70
|
+
sponsored?: boolean | undefined;
|
|
71
|
+
spendableBalance?: string | undefined;
|
|
72
|
+
minimumReserveBalance?: string | undefined;
|
|
73
|
+
} | null | undefined, {
|
|
74
|
+
limit: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
75
|
+
authorized: import("@metamask/superstruct").Struct<boolean | undefined, null>;
|
|
76
|
+
sponsored: import("@metamask/superstruct").Struct<boolean | undefined, null>;
|
|
77
|
+
spendableBalance: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
78
|
+
minimumReserveBalance: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
79
|
+
}>;
|
|
80
|
+
}>>;
|
|
81
|
+
}>;
|
|
82
|
+
/** Accounts API v6 multi account balances response. */
|
|
83
|
+
export declare const V6BalancesResponseStruct: import("@metamask/superstruct").Struct<{
|
|
84
|
+
unprocessedNetworks: string[];
|
|
85
|
+
unprocessedIncludeAssetIds: string[];
|
|
86
|
+
balances: {
|
|
87
|
+
accountId: string;
|
|
88
|
+
object: string;
|
|
89
|
+
type?: string | null | undefined;
|
|
90
|
+
assetId: string;
|
|
91
|
+
name?: string | null | undefined;
|
|
92
|
+
symbol?: string | null | undefined;
|
|
93
|
+
decimals?: number | null | undefined;
|
|
94
|
+
balance: string;
|
|
95
|
+
price?: string | null | undefined;
|
|
96
|
+
labels?: string[] | null | undefined;
|
|
97
|
+
canonicalHead?: string | null | undefined;
|
|
98
|
+
metadata?: {
|
|
99
|
+
limit?: string | undefined;
|
|
100
|
+
authorized?: boolean | undefined;
|
|
101
|
+
sponsored?: boolean | undefined;
|
|
102
|
+
spendableBalance?: string | undefined;
|
|
103
|
+
minimumReserveBalance?: string | undefined;
|
|
104
|
+
} | {
|
|
105
|
+
protocolId: string;
|
|
106
|
+
productName: string;
|
|
107
|
+
description: string;
|
|
108
|
+
protocolUrl: string;
|
|
109
|
+
protocolIconUrl?: string | undefined;
|
|
110
|
+
positionType: "deposit" | "investment" | "loan" | "locked" | "reward" | "staked" | "wallet";
|
|
111
|
+
poolAddress: string;
|
|
112
|
+
groupId: string;
|
|
113
|
+
} | null | undefined;
|
|
114
|
+
}[];
|
|
115
|
+
processingDefiPositions?: string[] | null | undefined;
|
|
116
|
+
}, {
|
|
117
|
+
unprocessedNetworks: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
|
|
118
|
+
unprocessedIncludeAssetIds: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
|
|
119
|
+
balances: import("@metamask/superstruct").Struct<{
|
|
120
|
+
accountId: string;
|
|
121
|
+
object: string;
|
|
122
|
+
type?: string | null | undefined;
|
|
123
|
+
assetId: string;
|
|
124
|
+
name?: string | null | undefined;
|
|
125
|
+
symbol?: string | null | undefined;
|
|
126
|
+
decimals?: number | null | undefined;
|
|
127
|
+
balance: string;
|
|
128
|
+
price?: string | null | undefined;
|
|
129
|
+
labels?: string[] | null | undefined;
|
|
130
|
+
canonicalHead?: string | null | undefined;
|
|
131
|
+
metadata?: {
|
|
132
|
+
limit?: string | undefined;
|
|
133
|
+
authorized?: boolean | undefined;
|
|
134
|
+
sponsored?: boolean | undefined;
|
|
135
|
+
spendableBalance?: string | undefined;
|
|
136
|
+
minimumReserveBalance?: string | undefined;
|
|
137
|
+
} | {
|
|
138
|
+
protocolId: string;
|
|
139
|
+
productName: string;
|
|
140
|
+
description: string;
|
|
141
|
+
protocolUrl: string;
|
|
142
|
+
protocolIconUrl?: string | undefined;
|
|
143
|
+
positionType: "deposit" | "investment" | "loan" | "locked" | "reward" | "staked" | "wallet";
|
|
144
|
+
poolAddress: string;
|
|
145
|
+
groupId: string;
|
|
146
|
+
} | null | undefined;
|
|
147
|
+
}[], import("@metamask/superstruct").Struct<{
|
|
148
|
+
accountId: string;
|
|
149
|
+
object: string;
|
|
150
|
+
type?: string | null | undefined;
|
|
151
|
+
assetId: string;
|
|
152
|
+
name?: string | null | undefined;
|
|
153
|
+
symbol?: string | null | undefined;
|
|
154
|
+
decimals?: number | null | undefined;
|
|
155
|
+
balance: string;
|
|
156
|
+
price?: string | null | undefined;
|
|
157
|
+
labels?: string[] | null | undefined;
|
|
158
|
+
canonicalHead?: string | null | undefined;
|
|
159
|
+
metadata?: {
|
|
160
|
+
limit?: string | undefined;
|
|
161
|
+
authorized?: boolean | undefined;
|
|
162
|
+
sponsored?: boolean | undefined;
|
|
163
|
+
spendableBalance?: string | undefined;
|
|
164
|
+
minimumReserveBalance?: string | undefined;
|
|
165
|
+
} | {
|
|
166
|
+
protocolId: string;
|
|
167
|
+
productName: string;
|
|
168
|
+
description: string;
|
|
169
|
+
protocolUrl: string;
|
|
170
|
+
protocolIconUrl?: string | undefined;
|
|
171
|
+
positionType: "deposit" | "investment" | "loan" | "locked" | "reward" | "staked" | "wallet";
|
|
172
|
+
poolAddress: string;
|
|
173
|
+
groupId: string;
|
|
174
|
+
} | null | undefined;
|
|
175
|
+
}, {
|
|
176
|
+
accountId: import("@metamask/superstruct").Struct<string, null>;
|
|
177
|
+
object: import("@metamask/superstruct").Struct<string, null>;
|
|
178
|
+
type: import("@metamask/superstruct").Struct<string | null | undefined, null>;
|
|
179
|
+
assetId: import("@metamask/superstruct").Struct<string, null>;
|
|
180
|
+
name: import("@metamask/superstruct").Struct<string | null | undefined, null>;
|
|
181
|
+
symbol: import("@metamask/superstruct").Struct<string | null | undefined, null>;
|
|
182
|
+
decimals: import("@metamask/superstruct").Struct<number | null | undefined, null>;
|
|
183
|
+
balance: import("@metamask/superstruct").Struct<string, null>;
|
|
184
|
+
price: import("@metamask/superstruct").Struct<string | null | undefined, null>;
|
|
185
|
+
labels: import("@metamask/superstruct").Struct<string[] | null | undefined, import("@metamask/superstruct").Struct<string, null>>;
|
|
186
|
+
canonicalHead: import("@metamask/superstruct").Struct<string | null | undefined, null>;
|
|
187
|
+
metadata: import("@metamask/superstruct").Struct<{
|
|
188
|
+
limit?: string | undefined;
|
|
189
|
+
authorized?: boolean | undefined;
|
|
190
|
+
sponsored?: boolean | undefined;
|
|
191
|
+
spendableBalance?: string | undefined;
|
|
192
|
+
minimumReserveBalance?: string | undefined;
|
|
193
|
+
} | {
|
|
194
|
+
protocolId: string;
|
|
195
|
+
productName: string;
|
|
196
|
+
description: string;
|
|
197
|
+
protocolUrl: string;
|
|
198
|
+
protocolIconUrl?: string | undefined;
|
|
199
|
+
positionType: "deposit" | "investment" | "loan" | "locked" | "reward" | "staked" | "wallet";
|
|
200
|
+
poolAddress: string;
|
|
201
|
+
groupId: string;
|
|
202
|
+
} | null | undefined, null>;
|
|
203
|
+
}>>;
|
|
204
|
+
processingDefiPositions: import("@metamask/superstruct").Struct<string[] | null | undefined, import("@metamask/superstruct").Struct<string, null>>;
|
|
205
|
+
}>;
|
|
206
|
+
/** A validated v5 or v6 balances response. */
|
|
207
|
+
export type BalancesResponse = Infer<typeof V5BalancesResponseStruct> | Infer<typeof V6BalancesResponseStruct>;
|
|
208
|
+
//# sourceMappingURL=structs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structs.d.ts","sourceRoot":"","sources":["../../src/accounts-api-balances-service/structs.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAuFnD,uDAAuD;AACvD,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAInC,CAAC;AAEH,uDAAuD;AACvD,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKnC,CAAC;AAEH,8CAA8C;AAC9C,MAAM,MAAM,gBAAgB,GACxB,KAAK,CAAC,OAAO,wBAAwB,CAAC,GACtC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { array, boolean, enums, nullable, number, optional, string, type, union, } from '@metamask/superstruct';
|
|
2
|
+
/**
|
|
3
|
+
* Stellar specific token metadata (trustline and native reserve fields).
|
|
4
|
+
* All fields are optional and unknown fields are allowed.
|
|
5
|
+
*/
|
|
6
|
+
const TokenBalanceMetadataStruct = type({
|
|
7
|
+
limit: optional(string()),
|
|
8
|
+
authorized: optional(boolean()),
|
|
9
|
+
sponsored: optional(boolean()),
|
|
10
|
+
spendableBalance: optional(string()),
|
|
11
|
+
minimumReserveBalance: optional(string()),
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* DeFi protocol metadata attached to `object: defi` rows (v6 only).
|
|
15
|
+
*/
|
|
16
|
+
const DefiBalanceMetadataStruct = type({
|
|
17
|
+
protocolId: string(),
|
|
18
|
+
productName: string(),
|
|
19
|
+
description: string(),
|
|
20
|
+
protocolUrl: string(),
|
|
21
|
+
protocolIconUrl: optional(string()),
|
|
22
|
+
positionType: enums([
|
|
23
|
+
'deposit',
|
|
24
|
+
'loan',
|
|
25
|
+
'locked',
|
|
26
|
+
'staked',
|
|
27
|
+
'reward',
|
|
28
|
+
'wallet',
|
|
29
|
+
'investment',
|
|
30
|
+
]),
|
|
31
|
+
poolAddress: string(),
|
|
32
|
+
groupId: string(),
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* A string field the data source does not read. It is kept loose (optional
|
|
36
|
+
* and nullable) so an API change to it never rejects a whole response.
|
|
37
|
+
*/
|
|
38
|
+
const LooseStringStruct = optional(nullable(string()));
|
|
39
|
+
/**
|
|
40
|
+
* A number field the data source does not read, kept loose for the same
|
|
41
|
+
* reason as {@link LooseStringStruct}.
|
|
42
|
+
*/
|
|
43
|
+
const LooseNumberStruct = optional(nullable(number()));
|
|
44
|
+
/**
|
|
45
|
+
* A v5 balance row. Only `accountId`, `assetId`, `balance` and `metadata` are
|
|
46
|
+
* read by the data source, every other field is loose.
|
|
47
|
+
*/
|
|
48
|
+
const V5BalanceItemStruct = type({
|
|
49
|
+
object: LooseStringStruct,
|
|
50
|
+
symbol: LooseStringStruct,
|
|
51
|
+
name: LooseStringStruct,
|
|
52
|
+
type: LooseStringStruct,
|
|
53
|
+
decimals: LooseNumberStruct,
|
|
54
|
+
assetId: string(),
|
|
55
|
+
balance: string(),
|
|
56
|
+
accountId: string(),
|
|
57
|
+
metadata: optional(nullable(TokenBalanceMetadataStruct)),
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* A v6 balance row. Only `accountId`, `assetId`, `balance`, `object` and
|
|
61
|
+
* `metadata` are read by the data source, every other field is loose.
|
|
62
|
+
* `object` is a plain string so unknown row kinds are skipped by the data
|
|
63
|
+
* source instead of rejecting the response.
|
|
64
|
+
*/
|
|
65
|
+
const V6BalanceItemStruct = type({
|
|
66
|
+
accountId: string(),
|
|
67
|
+
object: string(),
|
|
68
|
+
type: LooseStringStruct,
|
|
69
|
+
assetId: string(),
|
|
70
|
+
name: LooseStringStruct,
|
|
71
|
+
symbol: LooseStringStruct,
|
|
72
|
+
decimals: LooseNumberStruct,
|
|
73
|
+
balance: string(),
|
|
74
|
+
price: LooseStringStruct,
|
|
75
|
+
labels: optional(nullable(array(string()))),
|
|
76
|
+
canonicalHead: LooseStringStruct,
|
|
77
|
+
metadata: optional(nullable(union([DefiBalanceMetadataStruct, TokenBalanceMetadataStruct]))),
|
|
78
|
+
});
|
|
79
|
+
/** Accounts API v5 multi account balances response. */
|
|
80
|
+
export const V5BalancesResponseStruct = type({
|
|
81
|
+
count: number(),
|
|
82
|
+
unprocessedNetworks: array(string()),
|
|
83
|
+
balances: array(V5BalanceItemStruct),
|
|
84
|
+
});
|
|
85
|
+
/** Accounts API v6 multi account balances response. */
|
|
86
|
+
export const V6BalancesResponseStruct = type({
|
|
87
|
+
unprocessedNetworks: array(string()),
|
|
88
|
+
unprocessedIncludeAssetIds: array(string()),
|
|
89
|
+
balances: array(V6BalanceItemStruct),
|
|
90
|
+
processingDefiPositions: optional(nullable(array(string()))),
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=structs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structs.js","sourceRoot":"","sources":["../../src/accounts-api-balances-service/structs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,E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CAAC,CAAC,CAAC;CAC7D,CAAC,CAAC","sourcesContent":["import {\n array,\n boolean,\n enums,\n nullable,\n number,\n optional,\n string,\n type,\n union,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\n\n/**\n * Stellar specific token metadata (trustline and native reserve fields).\n * All fields are optional and unknown fields are allowed.\n */\nconst TokenBalanceMetadataStruct = type({\n limit: optional(string()),\n authorized: optional(boolean()),\n sponsored: optional(boolean()),\n spendableBalance: optional(string()),\n minimumReserveBalance: optional(string()),\n});\n\n/**\n * DeFi protocol metadata attached to `object: defi` rows (v6 only).\n */\nconst DefiBalanceMetadataStruct = type({\n protocolId: string(),\n productName: string(),\n description: string(),\n protocolUrl: string(),\n protocolIconUrl: optional(string()),\n positionType: enums([\n 'deposit',\n 'loan',\n 'locked',\n 'staked',\n 'reward',\n 'wallet',\n 'investment',\n ]),\n poolAddress: string(),\n groupId: string(),\n});\n\n/**\n * A string field the data source does not read. It is kept loose (optional\n * and nullable) so an API change to it never rejects a whole response.\n */\nconst LooseStringStruct = optional(nullable(string()));\n\n/**\n * A number field the data source does not read, kept loose for the same\n * reason as {@link LooseStringStruct}.\n */\nconst LooseNumberStruct = optional(nullable(number()));\n\n/**\n * A v5 balance row. Only `accountId`, `assetId`, `balance` and `metadata` are\n * read by the data source, every other field is loose.\n */\nconst V5BalanceItemStruct = type({\n object: LooseStringStruct,\n symbol: LooseStringStruct,\n name: LooseStringStruct,\n type: LooseStringStruct,\n decimals: LooseNumberStruct,\n assetId: string(),\n balance: string(),\n accountId: string(),\n metadata: optional(nullable(TokenBalanceMetadataStruct)),\n});\n\n/**\n * A v6 balance row. Only `accountId`, `assetId`, `balance`, `object` and\n * `metadata` are read by the data source, every other field is loose.\n * `object` is a plain string so unknown row kinds are skipped by the data\n * source instead of rejecting the response.\n */\nconst V6BalanceItemStruct = type({\n accountId: string(),\n object: string(),\n type: LooseStringStruct,\n assetId: string(),\n name: LooseStringStruct,\n symbol: LooseStringStruct,\n decimals: LooseNumberStruct,\n balance: string(),\n price: LooseStringStruct,\n labels: optional(nullable(array(string()))),\n canonicalHead: LooseStringStruct,\n metadata: optional(\n nullable(union([DefiBalanceMetadataStruct, TokenBalanceMetadataStruct])),\n ),\n});\n\n/** Accounts API v5 multi account balances response. */\nexport const V5BalancesResponseStruct = type({\n count: number(),\n unprocessedNetworks: array(string()),\n balances: array(V5BalanceItemStruct),\n});\n\n/** Accounts API v6 multi account balances response. */\nexport const V6BalancesResponseStruct = type({\n unprocessedNetworks: array(string()),\n unprocessedIncludeAssetIds: array(string()),\n balances: array(V6BalanceItemStruct),\n processingDefiPositions: optional(nullable(array(string()))),\n});\n\n/** A validated v5 or v6 balances response. */\nexport type BalancesResponse =\n | Infer<typeof V5BalancesResponseStruct>\n | Infer<typeof V6BalancesResponseStruct>;\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AccountId, AssetsFetchPhase, AssetsFetchStatus, ChainId } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Applies a recipe to the controller state. Matches the shape of the
|
|
4
|
+
* controller's protected `update` method.
|
|
5
|
+
*/
|
|
6
|
+
export type AssetsFetchUpdate = (recipe: (state: {
|
|
7
|
+
assetsFetchStatus?: Record<AccountId, AssetsFetchStatus>;
|
|
8
|
+
}) => void) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Tracks in flight fetches per account and phase, and writes the resulting
|
|
11
|
+
* fetch status through the injected `update` callback.
|
|
12
|
+
*/
|
|
13
|
+
export declare class AssetsFetchTracker {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* @param update - Callback used to write state.
|
|
17
|
+
* @param now - Clock used for `updatedAt`.
|
|
18
|
+
*/
|
|
19
|
+
constructor(update: AssetsFetchUpdate, now?: () => number);
|
|
20
|
+
/**
|
|
21
|
+
* Mark a fetch as started for the given accounts and phase.
|
|
22
|
+
*
|
|
23
|
+
* @param accountIds - The accounts being fetched.
|
|
24
|
+
* @param phase - The fetch phase.
|
|
25
|
+
* @returns An idempotent `end` function to call when the fetch finishes.
|
|
26
|
+
*/
|
|
27
|
+
begin(accountIds: AccountId[], phase: AssetsFetchPhase): (result?: {
|
|
28
|
+
errors?: Record<ChainId, string>;
|
|
29
|
+
}) => void;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=assetsFetchTracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetsFetchTracker.d.ts","sourceRoot":"","sources":["../src/assetsFetchTracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAEhB,iBAAiB,EACjB,OAAO,EACR,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,MAAM,EAAE,CAAC,KAAK,EAAE;IACd,iBAAiB,CAAC,EAAE,MAAM,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;CAC1D,KAAK,IAAI,KACP,IAAI,CAAC;AAEV;;;GAGG;AACH,qBAAa,kBAAkB;;IAO7B;;;OAGG;IACH,YAAY,MAAM,EAAE,iBAAiB,EAAE,GAAG,GAAE,MAAM,MAAiB,EAGlE;IAED;;;;;;OAMG;IACH,KAAK,CACH,UAAU,EAAE,SAAS,EAAE,EACvB,KAAK,EAAE,gBAAgB,GACtB,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;KAAE,KAAK,IAAI,CAsDzD;CAkBF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracks in flight fetches per account and phase, and writes the resulting
|
|
3
|
+
* fetch status through the injected `update` callback.
|
|
4
|
+
*/
|
|
5
|
+
export class AssetsFetchTracker {
|
|
6
|
+
#update;
|
|
7
|
+
#now;
|
|
8
|
+
#counts = new Map();
|
|
9
|
+
/**
|
|
10
|
+
* @param update - Callback used to write state.
|
|
11
|
+
* @param now - Clock used for `updatedAt`.
|
|
12
|
+
*/
|
|
13
|
+
constructor(update, now = Date.now) {
|
|
14
|
+
this.#update = update;
|
|
15
|
+
this.#now = now;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Mark a fetch as started for the given accounts and phase.
|
|
19
|
+
*
|
|
20
|
+
* @param accountIds - The accounts being fetched.
|
|
21
|
+
* @param phase - The fetch phase.
|
|
22
|
+
* @returns An idempotent `end` function to call when the fetch finishes.
|
|
23
|
+
*/
|
|
24
|
+
begin(accountIds, phase) {
|
|
25
|
+
if (accountIds.length === 0) {
|
|
26
|
+
return () => undefined;
|
|
27
|
+
}
|
|
28
|
+
const ids = [...accountIds];
|
|
29
|
+
const started = ids.filter((accountId) => !this.#counts.has(`${accountId}:${phase}`));
|
|
30
|
+
// Write before counting so a failed write leaves no stale count behind.
|
|
31
|
+
if (started.length > 0) {
|
|
32
|
+
this.#write(started, phase, (status) => {
|
|
33
|
+
status.fetchStatus = 'fetching';
|
|
34
|
+
status.errors = {};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
for (const accountId of ids) {
|
|
38
|
+
const key = `${accountId}:${phase}`;
|
|
39
|
+
this.#counts.set(key, (this.#counts.get(key) ?? 0) + 1);
|
|
40
|
+
}
|
|
41
|
+
let ended = false;
|
|
42
|
+
return (result) => {
|
|
43
|
+
if (ended) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
ended = true;
|
|
47
|
+
const errors = result?.errors ?? {};
|
|
48
|
+
const finished = [];
|
|
49
|
+
for (const accountId of ids) {
|
|
50
|
+
const key = `${accountId}:${phase}`;
|
|
51
|
+
const count = (this.#counts.get(key) ?? 1) - 1;
|
|
52
|
+
if (count <= 0) {
|
|
53
|
+
this.#counts.delete(key);
|
|
54
|
+
finished.push(accountId);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.#counts.set(key, count);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (finished.length > 0) {
|
|
61
|
+
const hasErrors = Object.keys(errors).length > 0;
|
|
62
|
+
this.#write(finished, phase, (status) => {
|
|
63
|
+
status.fetchStatus = 'idle';
|
|
64
|
+
status.errors = { ...errors };
|
|
65
|
+
if (!hasErrors) {
|
|
66
|
+
status.updatedAt = this.#now();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
#write(accountIds, phase, mutate) {
|
|
73
|
+
this.#update((state) => {
|
|
74
|
+
state.assetsFetchStatus ??= {};
|
|
75
|
+
for (const accountId of accountIds) {
|
|
76
|
+
state.assetsFetchStatus[accountId] ??= {
|
|
77
|
+
fast: { fetchStatus: 'idle', errors: {}, updatedAt: null },
|
|
78
|
+
background: { fetchStatus: 'idle', errors: {}, updatedAt: null },
|
|
79
|
+
};
|
|
80
|
+
mutate(state.assetsFetchStatus[accountId][phase]);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=assetsFetchTracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetsFetchTracker.js","sourceRoot":"","sources":["../src/assetsFetchTracker.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACpB,OAAO,CAAoB;IAE3B,IAAI,CAAe;IAEnB,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE7C;;;OAGG;IACH,YAAY,MAAyB,EAAE,GAAG,GAAiB,IAAI,CAAC,GAAG;QACjE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CACH,UAAuB,EACvB,KAAuB;QAEvB,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,OAAO,GAAS,EAAE,CAAC,SAAS,CAAC;QAC/B,C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,EAAE,IAAI,EAAE;iBACjE,CAAC;gBACF,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YACpD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n AccountId,\n AssetsFetchPhase,\n AssetsFetchPhaseStatus,\n AssetsFetchStatus,\n ChainId,\n} from './types.js';\n\n/**\n * Applies a recipe to the controller state. Matches the shape of the\n * controller's protected `update` method.\n */\nexport type AssetsFetchUpdate = (\n recipe: (state: {\n assetsFetchStatus?: Record<AccountId, AssetsFetchStatus>;\n }) => void,\n) => void;\n\n/**\n * Tracks in flight fetches per account and phase, and writes the resulting\n * fetch status through the injected `update` callback.\n */\nexport class AssetsFetchTracker {\n readonly #update: AssetsFetchUpdate;\n\n readonly #now: () => number;\n\n readonly #counts = new Map<string, number>();\n\n /**\n * @param update - Callback used to write state.\n * @param now - Clock used for `updatedAt`.\n */\n constructor(update: AssetsFetchUpdate, now: () => number = Date.now) {\n this.#update = update;\n this.#now = now;\n }\n\n /**\n * Mark a fetch as started for the given accounts and phase.\n *\n * @param accountIds - The accounts being fetched.\n * @param phase - The fetch phase.\n * @returns An idempotent `end` function to call when the fetch finishes.\n */\n begin(\n accountIds: AccountId[],\n phase: AssetsFetchPhase,\n ): (result?: { errors?: Record<ChainId, string> }) => void {\n if (accountIds.length === 0) {\n return (): void => undefined;\n }\n\n const ids = [...accountIds];\n const started = ids.filter(\n (accountId) => !this.#counts.has(`${accountId}:${phase}`),\n );\n\n // Write before counting so a failed write leaves no stale count behind.\n if (started.length > 0) {\n this.#write(started, phase, (status) => {\n status.fetchStatus = 'fetching';\n status.errors = {};\n });\n }\n\n for (const accountId of ids) {\n const key = `${accountId}:${phase}`;\n this.#counts.set(key, (this.#counts.get(key) ?? 0) + 1);\n }\n\n let ended = false;\n return (result): void => {\n if (ended) {\n return;\n }\n ended = true;\n\n const errors = result?.errors ?? {};\n const finished: AccountId[] = [];\n for (const accountId of ids) {\n const key = `${accountId}:${phase}`;\n const count = (this.#counts.get(key) ?? 1) - 1;\n if (count <= 0) {\n this.#counts.delete(key);\n finished.push(accountId);\n } else {\n this.#counts.set(key, count);\n }\n }\n\n if (finished.length > 0) {\n const hasErrors = Object.keys(errors).length > 0;\n this.#write(finished, phase, (status) => {\n status.fetchStatus = 'idle';\n status.errors = { ...errors };\n if (!hasErrors) {\n status.updatedAt = this.#now();\n }\n });\n }\n };\n }\n\n #write(\n accountIds: AccountId[],\n phase: AssetsFetchPhase,\n mutate: (status: AssetsFetchPhaseStatus) => void,\n ): void {\n this.#update((state) => {\n state.assetsFetchStatus ??= {};\n for (const accountId of accountIds) {\n state.assetsFetchStatus[accountId] ??= {\n fast: { fetchStatus: 'idle', errors: {}, updatedAt: null },\n background: { fetchStatus: 'idle', errors: {}, updatedAt: null },\n };\n mutate(state.assetsFetchStatus[accountId][phase]);\n }\n });\n }\n}\n"]}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import type { QueryStateChangeHandler } from '@metamask/base-data-service';
|
|
1
2
|
import { ApiPlatformClient } from '@metamask/core-backend';
|
|
2
3
|
import type { RemoteFeatureFlagControllerGetStateAction, RemoteFeatureFlagControllerStateChangeEvent } from '@metamask/remote-feature-flag-controller';
|
|
4
|
+
import type { AccountsApiBalancesServiceFetchBalancesAction } from '../accounts-api-balances-service/accounts-api-balances-service-method-action-types.js';
|
|
3
5
|
import type { AssetsControllerMessenger } from '../AssetsController.js';
|
|
4
6
|
import type { ChainId, DataRequest, DataResponse, Middleware, AssetsControllerState } from '../types.js';
|
|
5
7
|
import type { GetAssetVisibility } from '../utils/assetVisibility.js';
|
|
6
8
|
import type { DataSourceState, SubscriptionRequest } from './AbstractDataSource.js';
|
|
7
9
|
import { AbstractDataSource } from './AbstractDataSource.js';
|
|
8
10
|
declare const CONTROLLER_NAME = "AccountsApiDataSource";
|
|
9
|
-
export type AccountsApiDataSourceAllowedActions = RemoteFeatureFlagControllerGetStateAction;
|
|
11
|
+
export type AccountsApiDataSourceAllowedActions = RemoteFeatureFlagControllerGetStateAction | AccountsApiBalancesServiceFetchBalancesAction;
|
|
10
12
|
export type AccountsApiDataSourceAllowedEvents = RemoteFeatureFlagControllerStateChangeEvent;
|
|
11
13
|
export type AccountsApiDataSourceState = DataSourceState;
|
|
12
14
|
/** Optional configuration for AccountsApiDataSource. */
|
|
@@ -25,6 +27,12 @@ export type AccountsApiDataSourceConfig = {
|
|
|
25
27
|
* middleware hands them off to the next data source (e.g. RPC fallback).
|
|
26
28
|
*/
|
|
27
29
|
fetchTimeoutMs?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Called with the state of the balances query as it changes, when balances
|
|
32
|
+
* are fetched through `AccountsApiBalancesService` (see
|
|
33
|
+
* `useAccountsApiBalancesService`). Forwarded as `onQueryStateChange`.
|
|
34
|
+
*/
|
|
35
|
+
onBalancesQueryStateChange?: QueryStateChangeHandler;
|
|
28
36
|
};
|
|
29
37
|
export type AccountsApiDataSourceOptions = AccountsApiDataSourceConfig & {
|
|
30
38
|
/**
|
|
@@ -49,6 +57,13 @@ export type AccountsApiDataSourceOptions = AccountsApiDataSourceConfig & {
|
|
|
49
57
|
getAssetsState: () => AssetsControllerState;
|
|
50
58
|
/** Returns shared visible/hidden assets for an account/chain scope. */
|
|
51
59
|
getAssetVisibility: GetAssetVisibility;
|
|
60
|
+
/**
|
|
61
|
+
* When true, v5 and v6 balances are fetched through the
|
|
62
|
+
* `AccountsApiBalancesService:fetchBalances` messenger action instead of
|
|
63
|
+
* `queryApiClient`. Only turn it on once that action is registered and
|
|
64
|
+
* delegated to the messenger. Defaults to `false`.
|
|
65
|
+
*/
|
|
66
|
+
useAccountsApiBalancesService?: boolean;
|
|
52
67
|
state?: Partial<AccountsApiDataSourceState>;
|
|
53
68
|
};
|
|
54
69
|
/**
|
|
@@ -63,8 +78,10 @@ export declare function filterResponseToKnownAssets(response: DataResponse, asse
|
|
|
63
78
|
/**
|
|
64
79
|
* Data source for fetching balances from the MetaMask Accounts API.
|
|
65
80
|
*
|
|
66
|
-
* Uses ApiPlatformClient (queryApiClient) for
|
|
67
|
-
*
|
|
81
|
+
* Uses ApiPlatformClient (queryApiClient) for API calls. When
|
|
82
|
+
* `useAccountsApiBalancesService` is on, balances go through the
|
|
83
|
+
* `AccountsApiBalancesService:fetchBalances` messenger action instead.
|
|
84
|
+
* Reports active chains via onActiveChainsUpdated callback.
|
|
68
85
|
*/
|
|
69
86
|
export declare class AccountsApiDataSource extends AbstractDataSource<typeof CONTROLLER_NAME, AccountsApiDataSourceState> {
|
|
70
87
|
#private;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountsApiDataSource.d.ts","sourceRoot":"","sources":["../../src/data-sources/AccountsApiDataSource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AccountsApiDataSource.d.ts","sourceRoot":"","sources":["../../src/data-sources/AccountsApiDataSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EACV,yCAAyC,EACzC,2CAA2C,EAC5C,MAAM,0CAA0C,CAAC;AASlD,OAAO,KAAK,EAAE,6CAA6C,EAAE,MAAM,uFAAuF,CAAC;AAE3J,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAExE,OAAO,KAAK,EACV,OAAO,EAGP,WAAW,EACX,YAAY,EACZ,UAAU,EACV,qBAAqB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAOtE,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAO7D,QAAA,MAAM,eAAe,0BAA0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AO,EAAE,4BAA4B,EAqChD;IAiED;;;;;;OAMG;IACH,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEnC;IA0BK,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAMvD;IAojBD;;;;;;;;;;OAUG;IACH,IAAI,gBAAgB,IAAI,UAAU,CAMjC;IAiHK,SAAS,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+FvE;IAMD,OAAO,IAAI,IAAI,CAMd;CACF"}
|
|
@@ -106,8 +106,10 @@ export function filterResponseToKnownAssets(response, assetsState) {
|
|
|
106
106
|
/**
|
|
107
107
|
* Data source for fetching balances from the MetaMask Accounts API.
|
|
108
108
|
*
|
|
109
|
-
* Uses ApiPlatformClient (queryApiClient) for
|
|
110
|
-
*
|
|
109
|
+
* Uses ApiPlatformClient (queryApiClient) for API calls. When
|
|
110
|
+
* `useAccountsApiBalancesService` is on, balances go through the
|
|
111
|
+
* `AccountsApiBalancesService:fetchBalances` messenger action instead.
|
|
112
|
+
* Reports active chains via onActiveChainsUpdated callback.
|
|
111
113
|
*/
|
|
112
114
|
export class AccountsApiDataSource extends AbstractDataSource {
|
|
113
115
|
#onActiveChainsUpdated;
|
|
@@ -123,6 +125,11 @@ export class AccountsApiDataSource extends AbstractDataSource {
|
|
|
123
125
|
#getAssetVisibility;
|
|
124
126
|
/** ApiPlatformClient for cached API calls */
|
|
125
127
|
#apiClient;
|
|
128
|
+
/** Whether balances go through `AccountsApiBalancesService`. */
|
|
129
|
+
#useBalancesService;
|
|
130
|
+
#onBalancesQueryStateChange;
|
|
131
|
+
/** Whether the missing service action warning was already reported. */
|
|
132
|
+
#hasReportedMissingBalancesService = false;
|
|
126
133
|
/** Chains refresh timer */
|
|
127
134
|
#chainsRefreshTimer = null;
|
|
128
135
|
constructor(options) {
|
|
@@ -141,6 +148,8 @@ export class AccountsApiDataSource extends AbstractDataSource {
|
|
|
141
148
|
this.#getAssetsState = options.getAssetsState;
|
|
142
149
|
this.#getAssetVisibility = options.getAssetVisibility;
|
|
143
150
|
this.#apiClient = options.queryApiClient;
|
|
151
|
+
this.#useBalancesService = options.useAccountsApiBalancesService ?? false;
|
|
152
|
+
this.#onBalancesQueryStateChange = options.onBalancesQueryStateChange;
|
|
144
153
|
// The Snaps → AssetsController migration flags gate which migration networks
|
|
145
154
|
// (Solana, Stellar, Tron) are surfaced as active chains (see
|
|
146
155
|
// `#shouldSupportChain`). Mirror core-backend's AccountActivityService and
|
|
@@ -422,7 +431,9 @@ export class AccountsApiDataSource extends AbstractDataSource {
|
|
|
422
431
|
* @returns Unprocessed networks and processed asset balances by account.
|
|
423
432
|
*/
|
|
424
433
|
async #fetchV5Balances(accountIds, fetchOptions, request) {
|
|
425
|
-
const apiResponse = await fetchWithTimeout(() => this.#
|
|
434
|
+
const apiResponse = await fetchWithTimeout(async () => this.#useBalancesService
|
|
435
|
+
? (await this.#fetchBalancesFromService({ version: 'v5', accountIds }, fetchOptions))
|
|
436
|
+
: this.#apiClient.accounts.fetchV5MultiAccountBalances(accountIds, undefined, fetchOptions), this.#fetchTimeoutMs);
|
|
426
437
|
const { assetsBalance } = this.#processV5Balances(apiResponse.balances, request);
|
|
427
438
|
return {
|
|
428
439
|
unprocessedNetworks: apiResponse.unprocessedNetworks,
|
|
@@ -449,7 +460,9 @@ export class AccountsApiDataSource extends AbstractDataSource {
|
|
|
449
460
|
...(excludeAssetIds && { excludeAssetIds }),
|
|
450
461
|
}
|
|
451
462
|
: undefined;
|
|
452
|
-
const apiResponse = await fetchWithTimeout(() => this.#
|
|
463
|
+
const apiResponse = await fetchWithTimeout(async () => this.#useBalancesService
|
|
464
|
+
? (await this.#fetchBalancesFromService({ version: 'v6', accountIds, ...params }, fetchOptions))
|
|
465
|
+
: this.#apiClient.accounts.fetchV6MultiAccountBalances(accountIds, params, fetchOptions), this.#fetchTimeoutMs);
|
|
453
466
|
const { assetsBalance } = this.#processV6Balances(apiResponse.balances, request);
|
|
454
467
|
return {
|
|
455
468
|
unprocessedNetworks: apiResponse.unprocessedNetworks,
|
|
@@ -457,6 +470,55 @@ export class AccountsApiDataSource extends AbstractDataSource {
|
|
|
457
470
|
assetsBalance,
|
|
458
471
|
};
|
|
459
472
|
}
|
|
473
|
+
/**
|
|
474
|
+
* Fetch balances through `AccountsApiBalancesService:fetchBalances`. Any
|
|
475
|
+
* forced fetch (`forceUpdate` or `bypassServerCache` on the request) skips
|
|
476
|
+
* the service cache, and `bypassServerCache` also skips the API's own cache,
|
|
477
|
+
* mirroring the `ApiPlatformClient` fetch options.
|
|
478
|
+
*
|
|
479
|
+
* The service validates the fields the balance processors read, so its
|
|
480
|
+
* response can be handed to them as is.
|
|
481
|
+
*
|
|
482
|
+
* @param params - The endpoint version, account IDs and, for v6, the
|
|
483
|
+
* include and exclude asset IDs.
|
|
484
|
+
* @param fetchOptions - Cache/fetch options built from the request.
|
|
485
|
+
* @returns The balances response.
|
|
486
|
+
*/
|
|
487
|
+
async #fetchBalancesFromService(params, fetchOptions) {
|
|
488
|
+
try {
|
|
489
|
+
return await this.#messenger.call('AccountsApiBalancesService:fetchBalances', {
|
|
490
|
+
...params,
|
|
491
|
+
forceUpdate: fetchOptions !== undefined,
|
|
492
|
+
bypassServerCache: fetchOptions?.bypassServerCache === true,
|
|
493
|
+
...(this.#onBalancesQueryStateChange
|
|
494
|
+
? { onQueryStateChange: this.#onBalancesQueryStateChange }
|
|
495
|
+
: {}),
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
catch (error) {
|
|
499
|
+
this.#reportMissingBalancesService(error);
|
|
500
|
+
throw error;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Log once per instance when `useAccountsApiBalancesService` is on but the
|
|
505
|
+
* `AccountsApiBalancesService:fetchBalances` action is not delegated or not
|
|
506
|
+
* registered. This data source has no injected exception reporter, so it
|
|
507
|
+
* uses the module debug logger.
|
|
508
|
+
*
|
|
509
|
+
* @param error - The error thrown by the messenger call.
|
|
510
|
+
*/
|
|
511
|
+
#reportMissingBalancesService(error) {
|
|
512
|
+
if (this.#hasReportedMissingBalancesService) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
516
|
+
if (message.includes('has not been delegated') ||
|
|
517
|
+
message.includes('has not been registered')) {
|
|
518
|
+
this.#hasReportedMissingBalancesService = true;
|
|
519
|
+
log('useAccountsApiBalancesService is enabled but AccountsApiBalancesService:fetchBalances is not delegated or registered', { error });
|
|
520
|
+
}
|
|
521
|
+
}
|
|
460
522
|
/**
|
|
461
523
|
* Build a lookup of lowercased account address to the request's account ID.
|
|
462
524
|
*
|