@metamask-previews/assets-controller 20.2.3-preview-2ad7fb9 → 20.2.3-preview-55295a2
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 +0 -19
- package/README.md +0 -6
- package/dist/AssetsController.d.ts +2 -11
- package/dist/AssetsController.d.ts.map +1 -1
- package/dist/AssetsController.js +7 -55
- package/dist/AssetsController.js.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.ts +3 -20
- package/dist/data-sources/AccountsApiDataSource.d.ts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.js +4 -66
- package/dist/data-sources/AccountsApiDataSource.js.map +1 -1
- package/dist/index.d.ts +1 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +0 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -3
- package/dist/accounts-api-balances-service/accounts-api-balances-service-method-action-types.d.ts +0 -22
- package/dist/accounts-api-balances-service/accounts-api-balances-service-method-action-types.d.ts.map +0 -1
- package/dist/accounts-api-balances-service/accounts-api-balances-service-method-action-types.js +0 -6
- package/dist/accounts-api-balances-service/accounts-api-balances-service-method-action-types.js.map +0 -1
- package/dist/accounts-api-balances-service/accounts-api-balances-service.d.ts +0 -140
- package/dist/accounts-api-balances-service/accounts-api-balances-service.d.ts.map +0 -1
- package/dist/accounts-api-balances-service/accounts-api-balances-service.js +0 -280
- package/dist/accounts-api-balances-service/accounts-api-balances-service.js.map +0 -1
- package/dist/accounts-api-balances-service/structs.d.ts +0 -208
- package/dist/accounts-api-balances-service/structs.d.ts.map +0 -1
- package/dist/accounts-api-balances-service/structs.js +0 -92
- package/dist/accounts-api-balances-service/structs.js.map +0 -1
- package/dist/assetsFetchTracker.d.ts +0 -31
- package/dist/assetsFetchTracker.d.ts.map +0 -1
- package/dist/assetsFetchTracker.js +0 -85
- package/dist/assetsFetchTracker.js.map +0 -1
- package/dist/selectors/fetchStatus.d.ts +0 -36
- package/dist/selectors/fetchStatus.d.ts.map +0 -1
- package/dist/selectors/fetchStatus.js +0 -44
- package/dist/selectors/fetchStatus.js.map +0 -1
|
@@ -1,31 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,85 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assetsFetchTracker.js","sourceRoot":"","sources":["../src/assetsFetchTracker.ts"],"names":[],"mappings":"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","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,36 +0,0 @@
|
|
|
1
|
-
import type { AssetsControllerState } from '../AssetsController.js';
|
|
2
|
-
import type { AccountId, AssetsFetchPhase, ChainId } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Check whether an account is currently fetching assets in either phase.
|
|
5
|
-
*
|
|
6
|
-
* True when the `fast` or the `background` phase is `fetching`. There is a
|
|
7
|
-
* brief moment between the fast phase ending and the background phase
|
|
8
|
-
* beginning when both phases are idle, so consumers should not treat that gap
|
|
9
|
-
* as "finished".
|
|
10
|
-
*
|
|
11
|
-
* @param state - AssetsController state slice.
|
|
12
|
-
* @param accountId - The account id (`InternalAccount.id`).
|
|
13
|
-
* @returns True while either fetch phase is running for the account.
|
|
14
|
-
*/
|
|
15
|
-
export declare function isAccountFetching(state: Pick<AssetsControllerState, 'assetsFetchStatus'>, accountId: AccountId): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Get the per chain fetch errors of an account, separately for each phase.
|
|
18
|
-
*
|
|
19
|
-
* The phases are not merged on purpose: the fast phase can report a chain as
|
|
20
|
-
* failed, then the background phase retries it and may recover it, while the
|
|
21
|
-
* fast phase errors stay set. A merged union would show false errors.
|
|
22
|
-
* To get the effective errors, note that the background phase retries chains
|
|
23
|
-
* that failed in the fast phase, so once the background phase is idle after a
|
|
24
|
-
* fast completion, `background.errors` supersedes `fast.errors` for the chains
|
|
25
|
-
* it retried.
|
|
26
|
-
*
|
|
27
|
-
* Known limitation: overlapping forced fetches on the same account report the
|
|
28
|
-
* result of the last one to finish (earlier errors are dropped).
|
|
29
|
-
*
|
|
30
|
-
* @param state - AssetsController state slice.
|
|
31
|
-
* @param accountId - The account id (`InternalAccount.id`).
|
|
32
|
-
* @returns The errors keyed by chain id for each phase, with both phases
|
|
33
|
-
* `{}` when the account is unknown.
|
|
34
|
-
*/
|
|
35
|
-
export declare function getAccountFetchErrors(state: Pick<AssetsControllerState, 'assetsFetchStatus'>, accountId: AccountId): Record<AssetsFetchPhase, Record<ChainId, string>>;
|
|
36
|
-
//# sourceMappingURL=fetchStatus.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchStatus.d.ts","sourceRoot":"","sources":["../../src/selectors/fetchStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,mBAAmB,CAAC,EACvD,SAAS,EAAE,SAAS,GACnB,OAAO,CAMT;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,mBAAmB,CAAC,EACvD,SAAS,EAAE,SAAS,GACnB,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAMnD"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check whether an account is currently fetching assets in either phase.
|
|
3
|
-
*
|
|
4
|
-
* True when the `fast` or the `background` phase is `fetching`. There is a
|
|
5
|
-
* brief moment between the fast phase ending and the background phase
|
|
6
|
-
* beginning when both phases are idle, so consumers should not treat that gap
|
|
7
|
-
* as "finished".
|
|
8
|
-
*
|
|
9
|
-
* @param state - AssetsController state slice.
|
|
10
|
-
* @param accountId - The account id (`InternalAccount.id`).
|
|
11
|
-
* @returns True while either fetch phase is running for the account.
|
|
12
|
-
*/
|
|
13
|
-
export function isAccountFetching(state, accountId) {
|
|
14
|
-
const status = state.assetsFetchStatus?.[accountId];
|
|
15
|
-
return (status?.fast.fetchStatus === 'fetching' ||
|
|
16
|
-
status?.background.fetchStatus === 'fetching');
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Get the per chain fetch errors of an account, separately for each phase.
|
|
20
|
-
*
|
|
21
|
-
* The phases are not merged on purpose: the fast phase can report a chain as
|
|
22
|
-
* failed, then the background phase retries it and may recover it, while the
|
|
23
|
-
* fast phase errors stay set. A merged union would show false errors.
|
|
24
|
-
* To get the effective errors, note that the background phase retries chains
|
|
25
|
-
* that failed in the fast phase, so once the background phase is idle after a
|
|
26
|
-
* fast completion, `background.errors` supersedes `fast.errors` for the chains
|
|
27
|
-
* it retried.
|
|
28
|
-
*
|
|
29
|
-
* Known limitation: overlapping forced fetches on the same account report the
|
|
30
|
-
* result of the last one to finish (earlier errors are dropped).
|
|
31
|
-
*
|
|
32
|
-
* @param state - AssetsController state slice.
|
|
33
|
-
* @param accountId - The account id (`InternalAccount.id`).
|
|
34
|
-
* @returns The errors keyed by chain id for each phase, with both phases
|
|
35
|
-
* `{}` when the account is unknown.
|
|
36
|
-
*/
|
|
37
|
-
export function getAccountFetchErrors(state, accountId) {
|
|
38
|
-
const status = state.assetsFetchStatus?.[accountId];
|
|
39
|
-
return {
|
|
40
|
-
fast: status?.fast.errors ?? {},
|
|
41
|
-
background: status?.background.errors ?? {},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=fetchStatus.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchStatus.js","sourceRoot":"","sources":["../../src/selectors/fetchStatus.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAuD,EACvD,SAAoB;IAEpB,MAAM,MAAM,GAAG,KAAK,CAAC,iBAAiB,EAAE,CAAC,SAAS,CAAC,CAAC;IACpD,OAAO,CACL,MAAM,EAAE,IAAI,CAAC,WAAW,KAAK,UAAU;QACvC,MAAM,EAAE,UAAU,CAAC,WAAW,KAAK,UAAU,CAC9C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAuD,EACvD,SAAoB;IAEpB,MAAM,MAAM,GAAG,KAAK,CAAC,iBAAiB,EAAE,CAAC,SAAS,CAAC,CAAC;IACpD,OAAO;QACL,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,EAAE;QAC/B,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,IAAI,EAAE;KAC5C,CAAC;AACJ,CAAC","sourcesContent":["import type { AssetsControllerState } from '../AssetsController.js';\nimport type { AccountId, AssetsFetchPhase, ChainId } from '../types.js';\n\n/**\n * Check whether an account is currently fetching assets in either phase.\n *\n * True when the `fast` or the `background` phase is `fetching`. There is a\n * brief moment between the fast phase ending and the background phase\n * beginning when both phases are idle, so consumers should not treat that gap\n * as \"finished\".\n *\n * @param state - AssetsController state slice.\n * @param accountId - The account id (`InternalAccount.id`).\n * @returns True while either fetch phase is running for the account.\n */\nexport function isAccountFetching(\n state: Pick<AssetsControllerState, 'assetsFetchStatus'>,\n accountId: AccountId,\n): boolean {\n const status = state.assetsFetchStatus?.[accountId];\n return (\n status?.fast.fetchStatus === 'fetching' ||\n status?.background.fetchStatus === 'fetching'\n );\n}\n\n/**\n * Get the per chain fetch errors of an account, separately for each phase.\n *\n * The phases are not merged on purpose: the fast phase can report a chain as\n * failed, then the background phase retries it and may recover it, while the\n * fast phase errors stay set. A merged union would show false errors.\n * To get the effective errors, note that the background phase retries chains\n * that failed in the fast phase, so once the background phase is idle after a\n * fast completion, `background.errors` supersedes `fast.errors` for the chains\n * it retried.\n *\n * Known limitation: overlapping forced fetches on the same account report the\n * result of the last one to finish (earlier errors are dropped).\n *\n * @param state - AssetsController state slice.\n * @param accountId - The account id (`InternalAccount.id`).\n * @returns The errors keyed by chain id for each phase, with both phases\n * `{}` when the account is unknown.\n */\nexport function getAccountFetchErrors(\n state: Pick<AssetsControllerState, 'assetsFetchStatus'>,\n accountId: AccountId,\n): Record<AssetsFetchPhase, Record<ChainId, string>> {\n const status = state.assetsFetchStatus?.[accountId];\n return {\n fast: status?.fast.errors ?? {},\n background: status?.background.errors ?? {},\n };\n}\n"]}
|