@metamask-previews/assets-controller 20.3.1-preview-701acab40 → 20.4.0-preview-d8f16be
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 -1
- package/dist/AssetsController.d.ts +2 -1
- package/dist/AssetsController.d.ts.map +1 -1
- package/dist/AssetsController.js +33 -4
- package/dist/AssetsController.js.map +1 -1
- package/dist/data-sources/RpcDataSource.d.ts.map +1 -1
- package/dist/data-sources/RpcDataSource.js +16 -8
- package/dist/data-sources/RpcDataSource.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/selectors/loading.d.ts +48 -0
- package/dist/selectors/loading.d.ts.map +1 -1
- package/dist/selectors/loading.js +105 -16
- package/dist/selectors/loading.js.map +1 -1
- package/dist/syncAusUserAssets.d.ts +12 -0
- package/dist/syncAusUserAssets.d.ts.map +1 -0
- package/dist/syncAusUserAssets.js +128 -0
- package/dist/syncAusUserAssets.js.map +1 -0
- package/dist/trackAssetsLoading.d.ts +25 -0
- package/dist/trackAssetsLoading.d.ts.map +1 -1
- package/dist/trackAssetsLoading.js +71 -6
- package/dist/trackAssetsLoading.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +5 -4
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,eAAe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,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE3E,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,sCAAsC,EACtC,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,sBAAsB,EACtB,yBAAyB,EACzB,kCAAkC,EAClC,kCAAkC,EAClC,WAAW,EACX,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,EACrC,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,iCAAiC,EACjC,sCAAsC,EACtC,4BAA4B,EAC5B,uBAAuB,EACvB,mDAAmD,EACnD,yCAAyC,EACzC,0BAA0B,EAC1B,+BAA+B,EAC/B,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GACd,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -24,5 +24,5 @@ export { CustomAssetGraduationMiddleware, RpcFallbackMiddleware, } from './middl
|
|
|
24
24
|
export { normalizeAssetId, formatExchangeRatesForBridge, formatStateForTransactionPay, } from './utils/index.js';
|
|
25
25
|
// Selectors
|
|
26
26
|
export { calculateBalanceForAllWallets, calculateBalanceChangeForAccountGroup, getAggregatedBalanceForAccount, getGroupIdForAccount, getInternalAccountsForGroup, } from './selectors/balance.js';
|
|
27
|
-
export { getAccountGroupLoadingStatus, getAccountLoadingStatus, getIsAssetsLoadingForSelectedAccountGroup, isAccountGroupLoading, isAccountLoading, } from './selectors/loading.js';
|
|
27
|
+
export { getAccountBackgroundLoadingStatus, getAccountGroupBackgroundLoadingStatus, getAccountGroupLoadingStatus, getAccountLoadingStatus, getIsAssetsBackgroundLoadingForSelectedAccountGroup, getIsAssetsLoadingForSelectedAccountGroup, isAccountBackgroundLoading, isAccountGroupBackgroundLoading, isAccountGroupLoading, isAccountLoading, } from './selectors/loading.js';
|
|
28
28
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,eAAe,CAAC;AAGvB,4CAA4C;AAC5C,OAAO,EACL,gCAAgC,EAChC,iCAAiC,EACjC,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EACtB,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,mCAAmC,CAAC;AAwF3C,sCAAsC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAO7D,6BAA6B;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAQhE,qBAAqB;AACrB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAS7E,gFAAgF;AAChF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB;AACrB,YAAY;AACZ,kBAAkB;AAClB,oBAAoB;AACpB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AAOjC,0BAA0B;AAC1B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAQ3E,cAAc;AACd,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAMhC,YAAY;AACZ,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,kBAAkB,CAAC;AAU1B,YAAY;AACZ,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,EACrC,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,yCAAyC,EACzC,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC","sourcesContent":["// Main controller export\nexport {\n AssetsController,\n getDefaultAssetsControllerState,\n} from './AssetsController.js';\nexport { AssetsDataSourceError } from './errors.js';\nexport {\n DEFAULT_TRACKED_ASSETS_BY_CHAIN,\n CHAINS_WITH_DEFAULT_TRACKED_ASSETS,\n DEFAULT_ASSET_METADATA,\n buildDefaultAssetsInfo,\n getDefaultTrackedAssetsForChain,\n getDefaultAssetMetadata,\n} from './defaults.js';\nexport type { PendingTokenMetadata } from './AssetsController.js';\n\n// Snaps → AssetsController assets migration\nexport {\n SNAPS_ASSETS_MIGRATION_FLAG_KEYS,\n SNAPS_ASSETS_MIGRATION_NAMESPACES,\n SnapsAssetsMigrationStage,\n getSnapsAssetsMigrationNamespace,\n isMigrationStageActive,\n isSnapsAssetsMigrationNamespace,\n parseSnapsAssetsMigrationStage,\n} from './utils/snaps-assets-migration.js';\nexport type { SnapsAssetsMigrationNamespace } from './utils/snaps-assets-migration.js';\n\n// State and messenger types\nexport type {\n AssetsControllerState,\n AssetsControllerMessenger,\n AssetsControllerOptions,\n AssetsControllerGetStateAction,\n AssetsControllerActions,\n AssetsControllerStateChangeEvent,\n AssetsControllerBalanceChangedEvent,\n AssetsControllerPriceChangedEvent,\n AssetsControllerEvents,\n} from './AssetsController.js';\nexport type {\n AssetsControllerGetAssetsAction,\n AssetsControllerGetAssetsBalanceAction,\n AssetsControllerGetAssetMetadataAction,\n AssetsControllerGetAccountAssetByIDAction,\n AssetsControllerGetAccountAssetsByIDsAction,\n AssetsControllerGetAccountAssetsByScopeAction,\n AssetsControllerGetAssetsPriceAction,\n AssetsControllerSyncAssetsPricesAction,\n AssetsControllerAddCustomAssetAction,\n AssetsControllerRemoveCustomAssetAction,\n AssetsControllerGetCustomAssetsAction,\n AssetsControllerHideAssetAction,\n AssetsControllerUnhideAssetAction,\n AssetsControllerGetExchangeRatesForBridgeAction,\n AssetsControllerGetStateForTransactionPayAction,\n AssetsControllerSetSelectedCurrencyAction,\n} from './AssetsController-method-action-types.js';\n\n// Core types\nexport type {\n // CAIP types\n Caip19AssetId,\n AccountId,\n ChainId,\n // Asset types\n AssetType,\n TokenStandard,\n // Contract data types\n TokenFees,\n HoneypotStatus,\n StorageSlots,\n LocalizedDescription,\n // Metadata types\n BaseAssetMetadata,\n FungibleAssetMetadata,\n ERC721AssetMetadata,\n ERC1155AssetMetadata,\n AssetMetadata,\n // Price types\n BaseAssetPrice,\n FungibleAssetPrice,\n NFTAssetPrice,\n AssetPrice,\n // Balance types\n FungibleAssetBalance,\n ERC721AssetBalance,\n ERC1155AssetBalance,\n AssetBalance,\n // Data source types\n AccountWithSupportedChains,\n DataType,\n DataRequest,\n DataResponse,\n AssetsUpdateMode,\n AssetsLoadingStatus,\n // Middleware types\n Context,\n NextFunction,\n Middleware,\n AssetsDataSource,\n FetchContext,\n FetchNextFunction,\n FetchMiddleware,\n SubscriptionResponse,\n // Combined asset type\n Asset,\n // Event types\n BalanceChangeEvent,\n PriceChangeEvent,\n MetadataChangeEvent,\n} from './types.js';\n\n// Data sources - base class and types\nexport { AbstractDataSource } from './data-sources/index.js';\n\nexport type {\n DataSourceState,\n SubscriptionRequest,\n} from './data-sources/index.js';\n\n// Data sources - AccountsApi\nexport { AccountsApiDataSource } from './data-sources/index.js';\n\nexport type {\n AccountsApiDataSourceConfig,\n AccountsApiDataSourceOptions,\n AccountsApiDataSourceState,\n} from './data-sources/index.js';\n\n// Data sources - RPC\nexport { RpcDataSource, createRpcDataSource } from './data-sources/index.js';\n\nexport type {\n RpcDataSourceConfig,\n RpcDataSourceOptions,\n RpcDataSourceState,\n ChainStatus,\n} from './data-sources/index.js';\n\n// Data sources - Unified Snap Data Source (dynamically discovers keyring snaps)\nexport {\n SnapDataSource,\n createSnapDataSource,\n SNAP_DATA_SOURCE_NAME,\n // Constants\n KEYRING_PERMISSION,\n // Utility functions\n getChainIdsCaveat,\n extractChainFromAssetId,\n} from './data-sources/index.js';\n\nexport type {\n SnapDataSourceState,\n SnapDataSourceOptions,\n} from './data-sources/index.js';\n\n// Enrichment data sources\nexport { TokenDataSource, PriceDataSource } from './data-sources/index.js';\n\nexport type {\n TokenDataSourceOptions,\n PriceDataSourceConfig,\n PriceDataSourceOptions,\n} from './data-sources/index.js';\n\n// Middlewares\nexport {\n CustomAssetGraduationMiddleware,\n RpcFallbackMiddleware,\n} from './middlewares/index.js';\nexport type {\n CustomAssetGraduationMiddlewareOptions,\n RpcFallbackMiddlewareOptions,\n} from './middlewares/index.js';\n\n// Utilities\nexport {\n normalizeAssetId,\n formatExchangeRatesForBridge,\n formatStateForTransactionPay,\n} from './utils/index.js';\nexport type {\n AccountForLegacyFormat,\n BridgeExchangeRatesFormat,\n FormatExchangeRatesForBridgeParams,\n FormatStateForTransactionPayParams,\n LegacyToken,\n TransactionPayLegacyFormat,\n} from './utils/index.js';\n\n// Selectors\nexport {\n calculateBalanceForAllWallets,\n calculateBalanceChangeForAccountGroup,\n getAggregatedBalanceForAccount,\n getGroupIdForAccount,\n getInternalAccountsForGroup,\n} from './selectors/balance.js';\n\nexport {\n getAccountGroupLoadingStatus,\n getAccountLoadingStatus,\n getIsAssetsLoadingForSelectedAccountGroup,\n isAccountGroupLoading,\n isAccountLoading,\n} from './selectors/loading.js';\n\nexport type {\n AccountGroupBalance,\n AccountsById,\n AggregatedBalanceEntry,\n AggregatedBalanceForAccount,\n AllWalletsBalance,\n BalanceChangePeriod,\n BalanceChangeResult,\n EnabledNetworkMap,\n WalletBalance,\n} from './selectors/balance.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,eAAe,CAAC;AAGvB,4CAA4C;AAC5C,OAAO,EACL,gCAAgC,EAChC,iCAAiC,EACjC,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EACtB,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,mCAAmC,CAAC;AAwF3C,sCAAsC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAO7D,6BAA6B;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAQhE,qBAAqB;AACrB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAS7E,gFAAgF;AAChF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB;AACrB,YAAY;AACZ,kBAAkB;AAClB,oBAAoB;AACpB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AAOjC,0BAA0B;AAC1B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAQ3E,cAAc;AACd,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAMhC,YAAY;AACZ,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,kBAAkB,CAAC;AAU1B,YAAY;AACZ,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,EACrC,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,iCAAiC,EACjC,sCAAsC,EACtC,4BAA4B,EAC5B,uBAAuB,EACvB,mDAAmD,EACnD,yCAAyC,EACzC,0BAA0B,EAC1B,+BAA+B,EAC/B,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC","sourcesContent":["// Main controller export\nexport {\n AssetsController,\n getDefaultAssetsControllerState,\n} from './AssetsController.js';\nexport { AssetsDataSourceError } from './errors.js';\nexport {\n DEFAULT_TRACKED_ASSETS_BY_CHAIN,\n CHAINS_WITH_DEFAULT_TRACKED_ASSETS,\n DEFAULT_ASSET_METADATA,\n buildDefaultAssetsInfo,\n getDefaultTrackedAssetsForChain,\n getDefaultAssetMetadata,\n} from './defaults.js';\nexport type { PendingTokenMetadata } from './AssetsController.js';\n\n// Snaps → AssetsController assets migration\nexport {\n SNAPS_ASSETS_MIGRATION_FLAG_KEYS,\n SNAPS_ASSETS_MIGRATION_NAMESPACES,\n SnapsAssetsMigrationStage,\n getSnapsAssetsMigrationNamespace,\n isMigrationStageActive,\n isSnapsAssetsMigrationNamespace,\n parseSnapsAssetsMigrationStage,\n} from './utils/snaps-assets-migration.js';\nexport type { SnapsAssetsMigrationNamespace } from './utils/snaps-assets-migration.js';\n\n// State and messenger types\nexport type {\n AssetsControllerState,\n AssetsControllerMessenger,\n AssetsControllerOptions,\n AssetsControllerGetStateAction,\n AssetsControllerActions,\n AssetsControllerStateChangeEvent,\n AssetsControllerBalanceChangedEvent,\n AssetsControllerPriceChangedEvent,\n AssetsControllerEvents,\n} from './AssetsController.js';\nexport type {\n AssetsControllerGetAssetsAction,\n AssetsControllerGetAssetsBalanceAction,\n AssetsControllerGetAssetMetadataAction,\n AssetsControllerGetAccountAssetByIDAction,\n AssetsControllerGetAccountAssetsByIDsAction,\n AssetsControllerGetAccountAssetsByScopeAction,\n AssetsControllerGetAssetsPriceAction,\n AssetsControllerSyncAssetsPricesAction,\n AssetsControllerAddCustomAssetAction,\n AssetsControllerRemoveCustomAssetAction,\n AssetsControllerGetCustomAssetsAction,\n AssetsControllerHideAssetAction,\n AssetsControllerUnhideAssetAction,\n AssetsControllerGetExchangeRatesForBridgeAction,\n AssetsControllerGetStateForTransactionPayAction,\n AssetsControllerSetSelectedCurrencyAction,\n} from './AssetsController-method-action-types.js';\n\n// Core types\nexport type {\n // CAIP types\n Caip19AssetId,\n AccountId,\n ChainId,\n // Asset types\n AssetType,\n TokenStandard,\n // Contract data types\n TokenFees,\n HoneypotStatus,\n StorageSlots,\n LocalizedDescription,\n // Metadata types\n BaseAssetMetadata,\n FungibleAssetMetadata,\n ERC721AssetMetadata,\n ERC1155AssetMetadata,\n AssetMetadata,\n // Price types\n BaseAssetPrice,\n FungibleAssetPrice,\n NFTAssetPrice,\n AssetPrice,\n // Balance types\n FungibleAssetBalance,\n ERC721AssetBalance,\n ERC1155AssetBalance,\n AssetBalance,\n // Data source types\n AccountWithSupportedChains,\n DataType,\n DataRequest,\n DataResponse,\n AssetsUpdateMode,\n AssetsLoadingStatus,\n // Middleware types\n Context,\n NextFunction,\n Middleware,\n AssetsDataSource,\n FetchContext,\n FetchNextFunction,\n FetchMiddleware,\n SubscriptionResponse,\n // Combined asset type\n Asset,\n // Event types\n BalanceChangeEvent,\n PriceChangeEvent,\n MetadataChangeEvent,\n} from './types.js';\n\n// Data sources - base class and types\nexport { AbstractDataSource } from './data-sources/index.js';\n\nexport type {\n DataSourceState,\n SubscriptionRequest,\n} from './data-sources/index.js';\n\n// Data sources - AccountsApi\nexport { AccountsApiDataSource } from './data-sources/index.js';\n\nexport type {\n AccountsApiDataSourceConfig,\n AccountsApiDataSourceOptions,\n AccountsApiDataSourceState,\n} from './data-sources/index.js';\n\n// Data sources - RPC\nexport { RpcDataSource, createRpcDataSource } from './data-sources/index.js';\n\nexport type {\n RpcDataSourceConfig,\n RpcDataSourceOptions,\n RpcDataSourceState,\n ChainStatus,\n} from './data-sources/index.js';\n\n// Data sources - Unified Snap Data Source (dynamically discovers keyring snaps)\nexport {\n SnapDataSource,\n createSnapDataSource,\n SNAP_DATA_SOURCE_NAME,\n // Constants\n KEYRING_PERMISSION,\n // Utility functions\n getChainIdsCaveat,\n extractChainFromAssetId,\n} from './data-sources/index.js';\n\nexport type {\n SnapDataSourceState,\n SnapDataSourceOptions,\n} from './data-sources/index.js';\n\n// Enrichment data sources\nexport { TokenDataSource, PriceDataSource } from './data-sources/index.js';\n\nexport type {\n TokenDataSourceOptions,\n PriceDataSourceConfig,\n PriceDataSourceOptions,\n} from './data-sources/index.js';\n\n// Middlewares\nexport {\n CustomAssetGraduationMiddleware,\n RpcFallbackMiddleware,\n} from './middlewares/index.js';\nexport type {\n CustomAssetGraduationMiddlewareOptions,\n RpcFallbackMiddlewareOptions,\n} from './middlewares/index.js';\n\n// Utilities\nexport {\n normalizeAssetId,\n formatExchangeRatesForBridge,\n formatStateForTransactionPay,\n} from './utils/index.js';\nexport type {\n AccountForLegacyFormat,\n BridgeExchangeRatesFormat,\n FormatExchangeRatesForBridgeParams,\n FormatStateForTransactionPayParams,\n LegacyToken,\n TransactionPayLegacyFormat,\n} from './utils/index.js';\n\n// Selectors\nexport {\n calculateBalanceForAllWallets,\n calculateBalanceChangeForAccountGroup,\n getAggregatedBalanceForAccount,\n getGroupIdForAccount,\n getInternalAccountsForGroup,\n} from './selectors/balance.js';\n\nexport {\n getAccountBackgroundLoadingStatus,\n getAccountGroupBackgroundLoadingStatus,\n getAccountGroupLoadingStatus,\n getAccountLoadingStatus,\n getIsAssetsBackgroundLoadingForSelectedAccountGroup,\n getIsAssetsLoadingForSelectedAccountGroup,\n isAccountBackgroundLoading,\n isAccountGroupBackgroundLoading,\n isAccountGroupLoading,\n isAccountLoading,\n} from './selectors/loading.js';\n\nexport type {\n AccountGroupBalance,\n AccountsById,\n AggregatedBalanceEntry,\n AggregatedBalanceForAccount,\n AllWalletsBalance,\n BalanceChangePeriod,\n BalanceChangeResult,\n EnabledNetworkMap,\n WalletBalance,\n} from './selectors/balance.js';\n"]}
|
|
@@ -45,4 +45,52 @@ export declare function isAccountGroupLoading(state: Pick<AssetsControllerState,
|
|
|
45
45
|
* @returns True while any account in the selected account group is loading.
|
|
46
46
|
*/
|
|
47
47
|
export declare function getIsAssetsLoadingForSelectedAccountGroup(state: Pick<AssetsControllerState, 'assetsLoadingStatus'>, accountTreeState: AccountTreeControllerState): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get the background (Snap + RPC) loading status for a single account.
|
|
50
|
+
*
|
|
51
|
+
* @param state - AssetsController state slice.
|
|
52
|
+
* @param accountId - The account id (`InternalAccount.id`).
|
|
53
|
+
* @returns `'loading'` while a background fetch for the account is in
|
|
54
|
+
* flight, `'loaded'` once every background fetch has settled, or `undefined`
|
|
55
|
+
* if no background fetch was triggered.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getAccountBackgroundLoadingStatus(state: Pick<AssetsControllerState, 'assetsBackgroundLoadingStatus'>, accountId: AccountId): AssetsLoadingStatus | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Check whether a background fetch for an account is currently in flight.
|
|
60
|
+
*
|
|
61
|
+
* @param state - AssetsController state slice.
|
|
62
|
+
* @param accountId - The account id (`InternalAccount.id`).
|
|
63
|
+
* @returns True while a background fetch for the account is in flight.
|
|
64
|
+
*/
|
|
65
|
+
export declare function isAccountBackgroundLoading(state: Pick<AssetsControllerState, 'assetsBackgroundLoadingStatus'>, accountId: AccountId): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Get the background loading statuses for every account in an account group.
|
|
68
|
+
*
|
|
69
|
+
* @param state - AssetsController state slice.
|
|
70
|
+
* @param accountTreeState - AccountTreeController state slice.
|
|
71
|
+
* @param groupId - The account group id.
|
|
72
|
+
* @returns A record containing an entry for each account in the group that
|
|
73
|
+
* has a background loading status, keyed by account id.
|
|
74
|
+
*/
|
|
75
|
+
export declare function getAccountGroupBackgroundLoadingStatus(state: Pick<AssetsControllerState, 'assetsBackgroundLoadingStatus'>, accountTreeState: AccountTreeControllerState, groupId: string): Record<AccountId, AssetsLoadingStatus>;
|
|
76
|
+
/**
|
|
77
|
+
* Check whether any account in an account group has a background fetch in
|
|
78
|
+
* flight.
|
|
79
|
+
*
|
|
80
|
+
* @param state - AssetsController state slice.
|
|
81
|
+
* @param accountTreeState - AccountTreeController state slice.
|
|
82
|
+
* @param groupId - The account group id.
|
|
83
|
+
* @returns True while at least one account in the group is background
|
|
84
|
+
* loading.
|
|
85
|
+
*/
|
|
86
|
+
export declare function isAccountGroupBackgroundLoading(state: Pick<AssetsControllerState, 'assetsBackgroundLoadingStatus'>, accountTreeState: AccountTreeControllerState, groupId: string): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Check whether the selected account group has a background fetch in flight.
|
|
89
|
+
*
|
|
90
|
+
* @param state - AssetsController state slice.
|
|
91
|
+
* @param accountTreeState - AccountTreeController state slice.
|
|
92
|
+
* @returns True while any account in the selected account group is
|
|
93
|
+
* background loading.
|
|
94
|
+
*/
|
|
95
|
+
export declare function getIsAssetsBackgroundLoadingForSelectedAccountGroup(state: Pick<AssetsControllerState, 'assetsBackgroundLoadingStatus'>, accountTreeState: AccountTreeControllerState): boolean;
|
|
48
96
|
//# sourceMappingURL=loading.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loading.d.ts","sourceRoot":"","sources":["../../src/selectors/loading.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAEpF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,EA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CAAC,EACnE,SAAS,EAAE,SAAS,GACnB,mBAAmB,GAAG,SAAS,CAEjC;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,+BAA+B,CAAC,EACnE,SAAS,EAAE,SAAS,GACnB,OAAO,CAET;AAED;;;;;;;;GAQG;AACH,wBAAgB,sCAAsC,CACpD,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,+BAA+B,CAAC,EACnE,gBAAgB,EAAE,0BAA0B,EAC5C,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAMxC;AAED;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,+BAA+B,CAAC,EACnE,gBAAgB,EAAE,0BAA0B,EAC5C,OAAO,EAAE,MAAM,GACd,OAAO,CAMT;AAED;;;;;;;GAOG;AACH,wBAAgB,mDAAmD,CACjE,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,+BAA+B,CAAC,EACnE,gBAAgB,EAAE,0BAA0B,GAC3C,OAAO,CAKT"}
|
|
@@ -1,4 +1,48 @@
|
|
|
1
1
|
import { getAccountIdsForGroup } from './balance.js';
|
|
2
|
+
/**
|
|
3
|
+
* Collect the statuses for every account in an account group.
|
|
4
|
+
*
|
|
5
|
+
* @param statuses - The per-account statuses to read from.
|
|
6
|
+
* @param accountTreeState - AccountTreeController state slice.
|
|
7
|
+
* @param groupId - The account group id.
|
|
8
|
+
* @returns A record with an entry for each account in the group that has a
|
|
9
|
+
* status, keyed by account id.
|
|
10
|
+
*/
|
|
11
|
+
function collectGroupStatuses(statuses, accountTreeState, groupId) {
|
|
12
|
+
const result = {};
|
|
13
|
+
for (const accountId of getAccountIdsForGroup(accountTreeState, groupId)) {
|
|
14
|
+
const status = statuses?.[accountId];
|
|
15
|
+
if (status !== undefined) {
|
|
16
|
+
result[accountId] = status;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check whether any account in an account group is `'loading'`.
|
|
23
|
+
*
|
|
24
|
+
* @param statuses - The per-account statuses to read from.
|
|
25
|
+
* @param accountTreeState - AccountTreeController state slice.
|
|
26
|
+
* @param groupId - The account group id.
|
|
27
|
+
* @returns True while at least one account in the group is loading.
|
|
28
|
+
*/
|
|
29
|
+
function isAnyGroupAccountLoading(statuses, accountTreeState, groupId) {
|
|
30
|
+
return getAccountIdsForGroup(accountTreeState, groupId).some((accountId) => statuses?.[accountId] === 'loading');
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check whether any account in the selected account group is `'loading'`.
|
|
34
|
+
*
|
|
35
|
+
* @param statuses - The per-account statuses to read from.
|
|
36
|
+
* @param accountTreeState - AccountTreeController state slice.
|
|
37
|
+
* @returns True while any account in the selected account group is loading.
|
|
38
|
+
*/
|
|
39
|
+
function isSelectedGroupLoading(statuses, accountTreeState) {
|
|
40
|
+
const groupId = accountTreeState.selectedAccountGroup;
|
|
41
|
+
if (!groupId) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return isAnyGroupAccountLoading(statuses, accountTreeState, groupId);
|
|
45
|
+
}
|
|
2
46
|
/**
|
|
3
47
|
* Get the loading status for a single account.
|
|
4
48
|
*
|
|
@@ -30,15 +74,7 @@ export function isAccountLoading(state, accountId) {
|
|
|
30
74
|
* has a loading status, keyed by account id.
|
|
31
75
|
*/
|
|
32
76
|
export function getAccountGroupLoadingStatus(state, accountTreeState, groupId) {
|
|
33
|
-
|
|
34
|
-
const result = {};
|
|
35
|
-
for (const accountId of getAccountIdsForGroup(accountTreeState, groupId)) {
|
|
36
|
-
const status = loadingStatus?.[accountId];
|
|
37
|
-
if (status !== undefined) {
|
|
38
|
-
result[accountId] = status;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
77
|
+
return collectGroupStatuses(state.assetsLoadingStatus, accountTreeState, groupId);
|
|
42
78
|
}
|
|
43
79
|
/**
|
|
44
80
|
* Check whether any account in an account group is currently loading.
|
|
@@ -49,8 +85,7 @@ export function getAccountGroupLoadingStatus(state, accountTreeState, groupId) {
|
|
|
49
85
|
* @returns True while at least one account in the group is loading.
|
|
50
86
|
*/
|
|
51
87
|
export function isAccountGroupLoading(state, accountTreeState, groupId) {
|
|
52
|
-
|
|
53
|
-
return getAccountIdsForGroup(accountTreeState, groupId).some((accountId) => loadingStatus?.[accountId] === 'loading');
|
|
88
|
+
return isAnyGroupAccountLoading(state.assetsLoadingStatus, accountTreeState, groupId);
|
|
54
89
|
}
|
|
55
90
|
/**
|
|
56
91
|
* Check whether the selected account group is currently loading its assets.
|
|
@@ -60,10 +95,64 @@ export function isAccountGroupLoading(state, accountTreeState, groupId) {
|
|
|
60
95
|
* @returns True while any account in the selected account group is loading.
|
|
61
96
|
*/
|
|
62
97
|
export function getIsAssetsLoadingForSelectedAccountGroup(state, accountTreeState) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
98
|
+
return isSelectedGroupLoading(state.assetsLoadingStatus, accountTreeState);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the background (Snap + RPC) loading status for a single account.
|
|
102
|
+
*
|
|
103
|
+
* @param state - AssetsController state slice.
|
|
104
|
+
* @param accountId - The account id (`InternalAccount.id`).
|
|
105
|
+
* @returns `'loading'` while a background fetch for the account is in
|
|
106
|
+
* flight, `'loaded'` once every background fetch has settled, or `undefined`
|
|
107
|
+
* if no background fetch was triggered.
|
|
108
|
+
*/
|
|
109
|
+
export function getAccountBackgroundLoadingStatus(state, accountId) {
|
|
110
|
+
return state.assetsBackgroundLoadingStatus?.[accountId];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Check whether a background fetch for an account is currently in flight.
|
|
114
|
+
*
|
|
115
|
+
* @param state - AssetsController state slice.
|
|
116
|
+
* @param accountId - The account id (`InternalAccount.id`).
|
|
117
|
+
* @returns True while a background fetch for the account is in flight.
|
|
118
|
+
*/
|
|
119
|
+
export function isAccountBackgroundLoading(state, accountId) {
|
|
120
|
+
return getAccountBackgroundLoadingStatus(state, accountId) === 'loading';
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get the background loading statuses for every account in an account group.
|
|
124
|
+
*
|
|
125
|
+
* @param state - AssetsController state slice.
|
|
126
|
+
* @param accountTreeState - AccountTreeController state slice.
|
|
127
|
+
* @param groupId - The account group id.
|
|
128
|
+
* @returns A record containing an entry for each account in the group that
|
|
129
|
+
* has a background loading status, keyed by account id.
|
|
130
|
+
*/
|
|
131
|
+
export function getAccountGroupBackgroundLoadingStatus(state, accountTreeState, groupId) {
|
|
132
|
+
return collectGroupStatuses(state.assetsBackgroundLoadingStatus, accountTreeState, groupId);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Check whether any account in an account group has a background fetch in
|
|
136
|
+
* flight.
|
|
137
|
+
*
|
|
138
|
+
* @param state - AssetsController state slice.
|
|
139
|
+
* @param accountTreeState - AccountTreeController state slice.
|
|
140
|
+
* @param groupId - The account group id.
|
|
141
|
+
* @returns True while at least one account in the group is background
|
|
142
|
+
* loading.
|
|
143
|
+
*/
|
|
144
|
+
export function isAccountGroupBackgroundLoading(state, accountTreeState, groupId) {
|
|
145
|
+
return isAnyGroupAccountLoading(state.assetsBackgroundLoadingStatus, accountTreeState, groupId);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Check whether the selected account group has a background fetch in flight.
|
|
149
|
+
*
|
|
150
|
+
* @param state - AssetsController state slice.
|
|
151
|
+
* @param accountTreeState - AccountTreeController state slice.
|
|
152
|
+
* @returns True while any account in the selected account group is
|
|
153
|
+
* background loading.
|
|
154
|
+
*/
|
|
155
|
+
export function getIsAssetsBackgroundLoadingForSelectedAccountGroup(state, accountTreeState) {
|
|
156
|
+
return isSelectedGroupLoading(state.assetsBackgroundLoadingStatus, accountTreeState);
|
|
68
157
|
}
|
|
69
158
|
//# sourceMappingURL=loading.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loading.js","sourceRoot":"","sources":["../../src/selectors/loading.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,KAAyD,EACzD,SAAoB;IAEpB,OAAO,KAAK,CAAC,mBAAmB,EAAE,CAAC,SAAS,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAyD,EACzD,SAAoB;IAEpB,OAAO,uBAAuB,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,SAAS,CAAC;AACjE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,4BAA4B,CAC1C,KAAyD,EACzD,gBAA4C,EAC5C,OAAe;IAEf,MAAM,aAAa,GAAG,KAAK,CAAC,mBAAmB,CAAC;IAChD,MAAM,MAAM,GAA2C,EAAE,CAAC;IAC1D,KAAK,MAAM,SAAS,IAAI,qBAAqB,CAAC,gBAAgB,EAAE,OAAO,CAAC,EAAE,CAAC;QACzE,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAyD,EACzD,gBAA4C,EAC5C,OAAe;IAEf,MAAM,aAAa,GAAG,KAAK,CAAC,mBAAmB,CAAC;IAChD,OAAO,qBAAqB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC,IAAI,CAC1D,CAAC,SAAS,EAAE,EAAE,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC,KAAK,SAAS,CACxD,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yCAAyC,CACvD,KAAyD,EACzD,gBAA4C;IAE5C,MAAM,OAAO,GAAG,gBAAgB,CAAC,oBAAoB,CAAC;IACtD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import type { AccountTreeControllerState } from '@metamask/account-tree-controller';\n\nimport type { AssetsControllerState } from '../AssetsController.js';\nimport type { AccountId, AssetsLoadingStatus } from '../types.js';\nimport { getAccountIdsForGroup } from './balance.js';\n\n/**\n * Get the loading status for a single account.\n *\n * @param state - AssetsController state slice.\n * @param accountId - The account id (`InternalAccount.id`).\n * @returns `'loading'` while the account's assets are loading, `'loaded'`\n * after its fetch has settled, or `undefined` if no fetch was triggered.\n */\nexport function getAccountLoadingStatus(\n state: Pick<AssetsControllerState, 'assetsLoadingStatus'>,\n accountId: AccountId,\n): AssetsLoadingStatus | undefined {\n return state.assetsLoadingStatus?.[accountId];\n}\n\n/**\n * Check whether an account's assets are currently loading.\n *\n * @param state - AssetsController state slice.\n * @param accountId - The account id (`InternalAccount.id`).\n * @returns True while the account's assets are loading.\n */\nexport function isAccountLoading(\n state: Pick<AssetsControllerState, 'assetsLoadingStatus'>,\n accountId: AccountId,\n): boolean {\n return getAccountLoadingStatus(state, accountId) === 'loading';\n}\n\n/**\n * Get the loading statuses for every account in an account group.\n *\n * @param state - AssetsController state slice.\n * @param accountTreeState - AccountTreeController state slice.\n * @param groupId - The account group id.\n * @returns A record containing an entry for each account in the group that\n * has a loading status, keyed by account id.\n */\nexport function getAccountGroupLoadingStatus(\n state: Pick<AssetsControllerState, 'assetsLoadingStatus'>,\n accountTreeState: AccountTreeControllerState,\n groupId: string,\n): Record<AccountId, AssetsLoadingStatus> {\n const loadingStatus = state.assetsLoadingStatus;\n const result: Record<AccountId, AssetsLoadingStatus> = {};\n for (const accountId of getAccountIdsForGroup(accountTreeState, groupId)) {\n const status = loadingStatus?.[accountId];\n if (status !== undefined) {\n result[accountId] = status;\n }\n }\n return result;\n}\n\n/**\n * Check whether any account in an account group is currently loading.\n *\n * @param state - AssetsController state slice.\n * @param accountTreeState - AccountTreeController state slice.\n * @param groupId - The account group id.\n * @returns True while at least one account in the group is loading.\n */\nexport function isAccountGroupLoading(\n state: Pick<AssetsControllerState, 'assetsLoadingStatus'>,\n accountTreeState: AccountTreeControllerState,\n groupId: string,\n): boolean {\n const loadingStatus = state.assetsLoadingStatus;\n return getAccountIdsForGroup(accountTreeState, groupId).some(\n (accountId) => loadingStatus?.[accountId] === 'loading',\n );\n}\n\n/**\n * Check whether the selected account group is currently loading its assets.\n *\n * @param state - AssetsController state slice.\n * @param accountTreeState - AccountTreeController state slice.\n * @returns True while any account in the selected account group is loading.\n */\nexport function getIsAssetsLoadingForSelectedAccountGroup(\n state: Pick<AssetsControllerState, 'assetsLoadingStatus'>,\n accountTreeState: AccountTreeControllerState,\n): boolean {\n const groupId = accountTreeState.selectedAccountGroup;\n if (!groupId) {\n return false;\n }\n return isAccountGroupLoading(state, accountTreeState, groupId);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"loading.js","sourceRoot":"","sources":["../../src/selectors/loading.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;;;;;GAQG;AACH,SAAS,oBAAoB,CAC3B,QAA4D,EAC5D,gBAA4C,EAC5C,OAAe;IAEf,MAAM,MAAM,GAA2C,EAAE,CAAC;IAC1D,KAAK,MAAM,SAAS,IAAI,qBAAqB,CAAC,gBAAgB,EAAE,OAAO,CAAC,EAAE,CAAC;QACzE,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC,SAAS,CAAC,CAAC;QACrC,IAAI,MAA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,wBAAwB,CAC7B,KAAK,CAAC,mBAAmB,EACzB,gBAAgB,EAChB,OAAO,CACR,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yCAAyC,CACvD,KAAyD,EACzD,gBAA4C;IAE5C,OAAO,sBAAsB,CAAC,KAAK,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iCAAiC,CAC/C,KAAmE,EACnE,SAAoB;IAEpB,OAAO,KAAK,CAAC,6BAA6B,EAAE,CAAC,SAAS,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,KAAmE,EACnE,SAAoB;IAEpB,OAAO,iCAAiC,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,SAAS,CAAC;AAC3E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sCAAsC,CACpD,KAAmE,EACnE,gBAA4C,EAC5C,OAAe;IAEf,OAAO,oBAAoB,CACzB,KAAK,CAAC,6BAA6B,EACnC,gBAAgB,EAChB,OAAO,CACR,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,+BAA+B,CAC7C,KAAmE,EACnE,gBAA4C,EAC5C,OAAe;IAEf,OAAO,wBAAwB,CAC7B,KAAK,CAAC,6BAA6B,EACnC,gBAAgB,EAChB,OAAO,CACR,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mDAAmD,CACjE,KAAmE,EACnE,gBAA4C;IAE5C,OAAO,sBAAsB,CAC3B,KAAK,CAAC,6BAA6B,EACnC,gBAAgB,CACjB,CAAC;AACJ,CAAC","sourcesContent":["import type { AccountTreeControllerState } from '@metamask/account-tree-controller';\n\nimport type { AssetsControllerState } from '../AssetsController.js';\nimport type { AccountId, AssetsLoadingStatus } from '../types.js';\nimport { getAccountIdsForGroup } from './balance.js';\n\n/**\n * Collect the statuses for every account in an account group.\n *\n * @param statuses - The per-account statuses to read from.\n * @param accountTreeState - AccountTreeController state slice.\n * @param groupId - The account group id.\n * @returns A record with an entry for each account in the group that has a\n * status, keyed by account id.\n */\nfunction collectGroupStatuses(\n statuses: Record<AccountId, AssetsLoadingStatus> | undefined,\n accountTreeState: AccountTreeControllerState,\n groupId: string,\n): Record<AccountId, AssetsLoadingStatus> {\n const result: Record<AccountId, AssetsLoadingStatus> = {};\n for (const accountId of getAccountIdsForGroup(accountTreeState, groupId)) {\n const status = statuses?.[accountId];\n if (status !== undefined) {\n result[accountId] = status;\n }\n }\n return result;\n}\n\n/**\n * Check whether any account in an account group is `'loading'`.\n *\n * @param statuses - The per-account statuses to read from.\n * @param accountTreeState - AccountTreeController state slice.\n * @param groupId - The account group id.\n * @returns True while at least one account in the group is loading.\n */\nfunction isAnyGroupAccountLoading(\n statuses: Record<AccountId, AssetsLoadingStatus> | undefined,\n accountTreeState: AccountTreeControllerState,\n groupId: string,\n): boolean {\n return getAccountIdsForGroup(accountTreeState, groupId).some(\n (accountId) => statuses?.[accountId] === 'loading',\n );\n}\n\n/**\n * Check whether any account in the selected account group is `'loading'`.\n *\n * @param statuses - The per-account statuses to read from.\n * @param accountTreeState - AccountTreeController state slice.\n * @returns True while any account in the selected account group is loading.\n */\nfunction isSelectedGroupLoading(\n statuses: Record<AccountId, AssetsLoadingStatus> | undefined,\n accountTreeState: AccountTreeControllerState,\n): boolean {\n const groupId = accountTreeState.selectedAccountGroup;\n if (!groupId) {\n return false;\n }\n return isAnyGroupAccountLoading(statuses, accountTreeState, groupId);\n}\n\n/**\n * Get the loading status for a single account.\n *\n * @param state - AssetsController state slice.\n * @param accountId - The account id (`InternalAccount.id`).\n * @returns `'loading'` while the account's assets are loading, `'loaded'`\n * after its fetch has settled, or `undefined` if no fetch was triggered.\n */\nexport function getAccountLoadingStatus(\n state: Pick<AssetsControllerState, 'assetsLoadingStatus'>,\n accountId: AccountId,\n): AssetsLoadingStatus | undefined {\n return state.assetsLoadingStatus?.[accountId];\n}\n\n/**\n * Check whether an account's assets are currently loading.\n *\n * @param state - AssetsController state slice.\n * @param accountId - The account id (`InternalAccount.id`).\n * @returns True while the account's assets are loading.\n */\nexport function isAccountLoading(\n state: Pick<AssetsControllerState, 'assetsLoadingStatus'>,\n accountId: AccountId,\n): boolean {\n return getAccountLoadingStatus(state, accountId) === 'loading';\n}\n\n/**\n * Get the loading statuses for every account in an account group.\n *\n * @param state - AssetsController state slice.\n * @param accountTreeState - AccountTreeController state slice.\n * @param groupId - The account group id.\n * @returns A record containing an entry for each account in the group that\n * has a loading status, keyed by account id.\n */\nexport function getAccountGroupLoadingStatus(\n state: Pick<AssetsControllerState, 'assetsLoadingStatus'>,\n accountTreeState: AccountTreeControllerState,\n groupId: string,\n): Record<AccountId, AssetsLoadingStatus> {\n return collectGroupStatuses(\n state.assetsLoadingStatus,\n accountTreeState,\n groupId,\n );\n}\n\n/**\n * Check whether any account in an account group is currently loading.\n *\n * @param state - AssetsController state slice.\n * @param accountTreeState - AccountTreeController state slice.\n * @param groupId - The account group id.\n * @returns True while at least one account in the group is loading.\n */\nexport function isAccountGroupLoading(\n state: Pick<AssetsControllerState, 'assetsLoadingStatus'>,\n accountTreeState: AccountTreeControllerState,\n groupId: string,\n): boolean {\n return isAnyGroupAccountLoading(\n state.assetsLoadingStatus,\n accountTreeState,\n groupId,\n );\n}\n\n/**\n * Check whether the selected account group is currently loading its assets.\n *\n * @param state - AssetsController state slice.\n * @param accountTreeState - AccountTreeController state slice.\n * @returns True while any account in the selected account group is loading.\n */\nexport function getIsAssetsLoadingForSelectedAccountGroup(\n state: Pick<AssetsControllerState, 'assetsLoadingStatus'>,\n accountTreeState: AccountTreeControllerState,\n): boolean {\n return isSelectedGroupLoading(state.assetsLoadingStatus, accountTreeState);\n}\n\n/**\n * Get the background (Snap + RPC) loading status for a single account.\n *\n * @param state - AssetsController state slice.\n * @param accountId - The account id (`InternalAccount.id`).\n * @returns `'loading'` while a background fetch for the account is in\n * flight, `'loaded'` once every background fetch has settled, or `undefined`\n * if no background fetch was triggered.\n */\nexport function getAccountBackgroundLoadingStatus(\n state: Pick<AssetsControllerState, 'assetsBackgroundLoadingStatus'>,\n accountId: AccountId,\n): AssetsLoadingStatus | undefined {\n return state.assetsBackgroundLoadingStatus?.[accountId];\n}\n\n/**\n * Check whether a background fetch for an account is currently in flight.\n *\n * @param state - AssetsController state slice.\n * @param accountId - The account id (`InternalAccount.id`).\n * @returns True while a background fetch for the account is in flight.\n */\nexport function isAccountBackgroundLoading(\n state: Pick<AssetsControllerState, 'assetsBackgroundLoadingStatus'>,\n accountId: AccountId,\n): boolean {\n return getAccountBackgroundLoadingStatus(state, accountId) === 'loading';\n}\n\n/**\n * Get the background loading statuses for every account in an account group.\n *\n * @param state - AssetsController state slice.\n * @param accountTreeState - AccountTreeController state slice.\n * @param groupId - The account group id.\n * @returns A record containing an entry for each account in the group that\n * has a background loading status, keyed by account id.\n */\nexport function getAccountGroupBackgroundLoadingStatus(\n state: Pick<AssetsControllerState, 'assetsBackgroundLoadingStatus'>,\n accountTreeState: AccountTreeControllerState,\n groupId: string,\n): Record<AccountId, AssetsLoadingStatus> {\n return collectGroupStatuses(\n state.assetsBackgroundLoadingStatus,\n accountTreeState,\n groupId,\n );\n}\n\n/**\n * Check whether any account in an account group has a background fetch in\n * flight.\n *\n * @param state - AssetsController state slice.\n * @param accountTreeState - AccountTreeController state slice.\n * @param groupId - The account group id.\n * @returns True while at least one account in the group is background\n * loading.\n */\nexport function isAccountGroupBackgroundLoading(\n state: Pick<AssetsControllerState, 'assetsBackgroundLoadingStatus'>,\n accountTreeState: AccountTreeControllerState,\n groupId: string,\n): boolean {\n return isAnyGroupAccountLoading(\n state.assetsBackgroundLoadingStatus,\n accountTreeState,\n groupId,\n );\n}\n\n/**\n * Check whether the selected account group has a background fetch in flight.\n *\n * @param state - AssetsController state slice.\n * @param accountTreeState - AccountTreeController state slice.\n * @returns True while any account in the selected account group is\n * background loading.\n */\nexport function getIsAssetsBackgroundLoadingForSelectedAccountGroup(\n state: Pick<AssetsControllerState, 'assetsBackgroundLoadingStatus'>,\n accountTreeState: AccountTreeControllerState,\n): boolean {\n return isSelectedGroupLoading(\n state.assetsBackgroundLoadingStatus,\n accountTreeState,\n );\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method decorator that mirrors a custom-token state change to AUS user
|
|
3
|
+
* storage as the decorated method returns, fire-and-forget.
|
|
4
|
+
*
|
|
5
|
+
* @param target - The decorated custom-token method.
|
|
6
|
+
* @param context - The decorator context.
|
|
7
|
+
* @returns The wrapped method.
|
|
8
|
+
* @throws If applied to a method that is not configured in
|
|
9
|
+
* {@link AUS_SYNC_METHODS} (fails at class-definition time).
|
|
10
|
+
*/
|
|
11
|
+
export declare function syncAusUserAssets<This, Args extends unknown[], Return>(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>): (this: This, ...args: Args) => Return;
|
|
12
|
+
//# sourceMappingURL=syncAusUserAssets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncAusUserAssets.d.ts","sourceRoot":"","sources":["../src/syncAusUserAssets.ts"],"names":[],"mappings":"AA0KA;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,SAAS,OAAO,EAAE,EAAE,MAAM,EACpE,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,EAC7C,OAAO,EAAE,2BAA2B,CAClC,IAAI,EACJ,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CACtC,GACA,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAiBvC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { projectLogger, createModuleLogger } from './logger.js';
|
|
2
|
+
import { normalizeAssetId } from './utils/index.js';
|
|
3
|
+
const log = createModuleLogger(projectLogger, 'syncAusUserAssets');
|
|
4
|
+
/**
|
|
5
|
+
* The decorated methods and the AUS user-assets behavior each one mirrors.
|
|
6
|
+
*/
|
|
7
|
+
const AUS_SYNC_METHODS = {
|
|
8
|
+
addCustomAsset: {
|
|
9
|
+
kind: 'merge',
|
|
10
|
+
action: 'AuthenticatedUserStorageService:importTokens',
|
|
11
|
+
assetIdArgIndex: 1,
|
|
12
|
+
},
|
|
13
|
+
removeCustomAsset: {
|
|
14
|
+
kind: 'strip',
|
|
15
|
+
stripFrom: 'importedAssets',
|
|
16
|
+
assetIdArgIndex: 1,
|
|
17
|
+
},
|
|
18
|
+
hideAsset: {
|
|
19
|
+
kind: 'merge',
|
|
20
|
+
action: 'AuthenticatedUserStorageService:hideTokens',
|
|
21
|
+
assetIdArgIndex: 0,
|
|
22
|
+
},
|
|
23
|
+
unhideAsset: {
|
|
24
|
+
kind: 'strip',
|
|
25
|
+
stripFrom: 'hiddenAssets',
|
|
26
|
+
assetIdArgIndex: 0,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The tail of each controller instance's pending AUS sync queue.
|
|
31
|
+
*/
|
|
32
|
+
const ausSyncQueues = new WeakMap();
|
|
33
|
+
/**
|
|
34
|
+
* Mirror a custom-token action to AUS user assets.
|
|
35
|
+
*
|
|
36
|
+
* @param caller - The controller whose messenger to call AUS actions on.
|
|
37
|
+
* @param config - The AUS behavior configured for the invoked method.
|
|
38
|
+
* @param assetId - The CAIP-19 asset ID the method was invoked with.
|
|
39
|
+
*/
|
|
40
|
+
async function syncUserAssetsToAus(caller, config, assetId) {
|
|
41
|
+
const normalizedAssetId = normalizeAssetId(assetId);
|
|
42
|
+
if (config.kind === 'merge') {
|
|
43
|
+
await caller.messenger.call(config.action, [normalizedAssetId]);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const blob = await caller.messenger.call('AuthenticatedUserStorageService:getUserAssets');
|
|
47
|
+
// No stored blob means there is nothing to strip.
|
|
48
|
+
if (blob === null) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// Already absent means there is nothing to write (avoids version churn).
|
|
52
|
+
if (!blob[config.stripFrom].includes(normalizedAssetId)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const nextBlob = {
|
|
56
|
+
...blob,
|
|
57
|
+
[config.stripFrom]: blob[config.stripFrom].filter((id) => id !== normalizedAssetId),
|
|
58
|
+
};
|
|
59
|
+
await caller.messenger.call('AuthenticatedUserStorageService:setUserAssets', nextBlob);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Report a failed AUS sync. Never throws, so it can never block or roll back
|
|
63
|
+
* the local state change that already happened.
|
|
64
|
+
*
|
|
65
|
+
* @param caller - The controller whose messenger reports the error.
|
|
66
|
+
* @param assetId - The CAIP-19 asset ID the method was invoked with.
|
|
67
|
+
* @param error - The error the sync failed with.
|
|
68
|
+
*/
|
|
69
|
+
function reportAusSyncError(caller, assetId, error) {
|
|
70
|
+
log('Failed to sync user assets to AUS', { assetId, error });
|
|
71
|
+
try {
|
|
72
|
+
caller.messenger.captureException?.(new Error('Failed to sync user assets to AUS', { cause: error }));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// Never let telemetry throw.
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Fire the AUS sync, reporting any failure instead of propagating it so it
|
|
80
|
+
* can never block or roll back the local state change that already happened.
|
|
81
|
+
*
|
|
82
|
+
* @param caller - The controller whose messenger to call AUS actions on.
|
|
83
|
+
* @param config - The AUS behavior configured for the invoked method.
|
|
84
|
+
* @param assetId - The CAIP-19 asset ID the method was invoked with.
|
|
85
|
+
*/
|
|
86
|
+
function fireAusSync(caller, config, assetId) {
|
|
87
|
+
const run = async () => syncUserAssetsToAus(caller, config, assetId).catch((error) => reportAusSyncError(caller, assetId, error));
|
|
88
|
+
// Serialize syncs per controller instance: each one is a read-modify-write
|
|
89
|
+
// of the whole AUS blob, so a sync must not read until the previous write
|
|
90
|
+
// has landed (and invalidated the service's cached read). When idle, start
|
|
91
|
+
// right away; `run` never rejects, so one failure cannot stall the queue.
|
|
92
|
+
const previous = ausSyncQueues.get(caller);
|
|
93
|
+
const next = previous ? previous.then(run) : run();
|
|
94
|
+
ausSyncQueues.set(caller, next);
|
|
95
|
+
// Drop the queue once it drains, so an idle caller starts synchronously.
|
|
96
|
+
next
|
|
97
|
+
.then(() => {
|
|
98
|
+
if (ausSyncQueues.get(caller) === next) {
|
|
99
|
+
ausSyncQueues.delete(caller);
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
.catch(() => undefined);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Method decorator that mirrors a custom-token state change to AUS user
|
|
106
|
+
* storage as the decorated method returns, fire-and-forget.
|
|
107
|
+
*
|
|
108
|
+
* @param target - The decorated custom-token method.
|
|
109
|
+
* @param context - The decorator context.
|
|
110
|
+
* @returns The wrapped method.
|
|
111
|
+
* @throws If applied to a method that is not configured in
|
|
112
|
+
* {@link AUS_SYNC_METHODS} (fails at class-definition time).
|
|
113
|
+
*/
|
|
114
|
+
export function syncAusUserAssets(target, context) {
|
|
115
|
+
const config = AUS_SYNC_METHODS[context.name];
|
|
116
|
+
if (!config) {
|
|
117
|
+
throw new Error(`@syncAusUserAssets applied to unconfigured method '${String(context.name)}'`);
|
|
118
|
+
}
|
|
119
|
+
return function (...args) {
|
|
120
|
+
const caller = this;
|
|
121
|
+
const result = target.call(this, ...args);
|
|
122
|
+
// The local mutation is applied by the time the method returns, so fire
|
|
123
|
+
// the mirror now rather than when post-mutation work settles.
|
|
124
|
+
fireAusSync(caller, config, args[config.assetIdArgIndex]);
|
|
125
|
+
return result;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=syncAusUserAssets.js.map
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,GAAG,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;IACnD,aAAa,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAChC,yEAAyE;IACzE,IAAI;SACD,IAAI,CAAC,GAAG,EAAE;QACT,IAAI,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;YACvC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC,CAAC;SACD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAA6C,EAC7C,OAGC;IAED,MAAM,MAAM,GACV,gBAAgB,CAAC,OAAO,CAAC,IAAqC,CAAC,CAAC;IAClE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,sDAAsD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAC9E,CAAC;IACJ,CAAC;IAED,OAAO,UAAsB,GAAG,IAAU;QACxC,MAAM,MAAM,GAAG,IAAgC,CAAC;QAChD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QAC1C,wEAAwE;QACxE,8DAA8D;QAC9D,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,eAAe,CAAkB,CAAC,CAAC;QAC3E,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n AuthenticatedUserStorageServiceHideTokensAction,\n AuthenticatedUserStorageServiceImportTokensAction,\n UserAssetsBlob,\n} from '@metamask/authenticated-user-storage';\n\nimport type { AssetsControllerMessenger } from './AssetsController.js';\nimport { projectLogger, createModuleLogger } from './logger.js';\nimport type { Caip19AssetId } from './types.js';\nimport { normalizeAssetId } from './utils/index.js';\n\nconst log = createModuleLogger(projectLogger, 'syncAusUserAssets');\n\n/** The list of a user-assets blob an asset can be stripped from. */\ntype StripFromList = 'importedAssets' | 'hiddenAssets';\n\n/** Merge configuration: a single high-level AUS SDK operation. */\ntype MergeConfig = {\n kind: 'merge';\n action:\n | AuthenticatedUserStorageServiceImportTokensAction['type']\n | AuthenticatedUserStorageServiceHideTokensAction['type'];\n assetIdArgIndex: number;\n};\n\n/** Strip configuration: remove from one blob list, leaving the other untouched. */\ntype StripConfig = {\n kind: 'strip';\n stripFrom: StripFromList;\n assetIdArgIndex: number;\n};\n\ntype AusSyncConfig = MergeConfig | StripConfig;\n\n/** The controller surface the AUS sync needs (`messenger` is protected). */\ntype AusSyncCaller = {\n messenger: Pick<AssetsControllerMessenger, 'call' | 'captureException'>;\n};\n\n/**\n * The decorated methods and the AUS user-assets behavior each one mirrors.\n */\nconst AUS_SYNC_METHODS = {\n addCustomAsset: {\n kind: 'merge',\n action: 'AuthenticatedUserStorageService:importTokens',\n assetIdArgIndex: 1,\n },\n removeCustomAsset: {\n kind: 'strip',\n stripFrom: 'importedAssets',\n assetIdArgIndex: 1,\n },\n hideAsset: {\n kind: 'merge',\n action: 'AuthenticatedUserStorageService:hideTokens',\n assetIdArgIndex: 0,\n },\n unhideAsset: {\n kind: 'strip',\n stripFrom: 'hiddenAssets',\n assetIdArgIndex: 0,\n },\n} as const satisfies Record<string, AusSyncConfig>;\n\n/**\n * The tail of each controller instance's pending AUS sync queue.\n */\nconst ausSyncQueues = new WeakMap<AusSyncCaller, Promise<void>>();\n\n/**\n * Mirror a custom-token action to AUS user assets.\n *\n * @param caller - The controller whose messenger to call AUS actions on.\n * @param config - The AUS behavior configured for the invoked method.\n * @param assetId - The CAIP-19 asset ID the method was invoked with.\n */\nasync function syncUserAssetsToAus(\n caller: AusSyncCaller,\n config: AusSyncConfig,\n assetId: Caip19AssetId,\n): Promise<void> {\n const normalizedAssetId = normalizeAssetId(assetId);\n\n if (config.kind === 'merge') {\n await caller.messenger.call(config.action, [normalizedAssetId]);\n return;\n }\n\n const blob = await caller.messenger.call(\n 'AuthenticatedUserStorageService:getUserAssets',\n );\n // No stored blob means there is nothing to strip.\n if (blob === null) {\n return;\n }\n // Already absent means there is nothing to write (avoids version churn).\n if (!blob[config.stripFrom].includes(normalizedAssetId)) {\n return;\n }\n const nextBlob: UserAssetsBlob = {\n ...blob,\n [config.stripFrom]: blob[config.stripFrom].filter(\n (id) => id !== normalizedAssetId,\n ),\n };\n await caller.messenger.call(\n 'AuthenticatedUserStorageService:setUserAssets',\n nextBlob,\n );\n}\n\n/**\n * Report a failed AUS sync. Never throws, so it can never block or roll back\n * the local state change that already happened.\n *\n * @param caller - The controller whose messenger reports the error.\n * @param assetId - The CAIP-19 asset ID the method was invoked with.\n * @param error - The error the sync failed with.\n */\nfunction reportAusSyncError(\n caller: AusSyncCaller,\n assetId: Caip19AssetId,\n error: unknown,\n): void {\n log('Failed to sync user assets to AUS', { assetId, error });\n try {\n caller.messenger.captureException?.(\n new Error('Failed to sync user assets to AUS', { cause: error }),\n );\n } catch {\n // Never let telemetry throw.\n }\n}\n\n/**\n * Fire the AUS sync, reporting any failure instead of propagating it so it\n * can never block or roll back the local state change that already happened.\n *\n * @param caller - The controller whose messenger to call AUS actions on.\n * @param config - The AUS behavior configured for the invoked method.\n * @param assetId - The CAIP-19 asset ID the method was invoked with.\n */\nfunction fireAusSync(\n caller: AusSyncCaller,\n config: AusSyncConfig,\n assetId: Caip19AssetId,\n): void {\n const run = async (): Promise<void> =>\n syncUserAssetsToAus(caller, config, assetId).catch((error: unknown) =>\n reportAusSyncError(caller, assetId, error),\n );\n\n // Serialize syncs per controller instance: each one is a read-modify-write\n // of the whole AUS blob, so a sync must not read until the previous write\n // has landed (and invalidated the service's cached read). When idle, start\n // right away; `run` never rejects, so one failure cannot stall the queue.\n const previous = ausSyncQueues.get(caller);\n const next = previous ? previous.then(run) : run();\n ausSyncQueues.set(caller, next);\n // Drop the queue once it drains, so an idle caller starts synchronously.\n next\n .then(() => {\n if (ausSyncQueues.get(caller) === next) {\n ausSyncQueues.delete(caller);\n }\n })\n .catch(() => undefined);\n}\n\n/**\n * Method decorator that mirrors a custom-token state change to AUS user\n * storage as the decorated method returns, fire-and-forget.\n *\n * @param target - The decorated custom-token method.\n * @param context - The decorator context.\n * @returns The wrapped method.\n * @throws If applied to a method that is not configured in\n * {@link AUS_SYNC_METHODS} (fails at class-definition time).\n */\nexport function syncAusUserAssets<This, Args extends unknown[], Return>(\n target: (this: This, ...args: Args) => Return,\n context: ClassMethodDecoratorContext<\n This,\n (this: This, ...args: Args) => Return\n >,\n): (this: This, ...args: Args) => Return {\n const config =\n AUS_SYNC_METHODS[context.name as keyof typeof AUS_SYNC_METHODS];\n if (!config) {\n throw new Error(\n `@syncAusUserAssets applied to unconfigured method '${String(context.name)}'`,\n );\n }\n\n return function (this: This, ...args: Args): Return {\n const caller = this as unknown as AusSyncCaller;\n const result = target.call(this, ...args);\n // The local mutation is applied by the time the method returns, so fire\n // the mirror now rather than when post-mutation work settles.\n fireAusSync(caller, config, args[config.assetIdArgIndex] as Caip19AssetId);\n return result;\n };\n}\n"]}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import type { InternalAccount } from '@metamask/keyring-internal-api';
|
|
2
|
+
import type { AssetsControllerState } from './AssetsController.js';
|
|
3
|
+
type AssetsLoadingStatusKey = 'assetsLoadingStatus' | 'assetsBackgroundLoadingStatus';
|
|
4
|
+
type AssetsLoadingState = Pick<AssetsControllerState, AssetsLoadingStatusKey>;
|
|
5
|
+
/**
|
|
6
|
+
* The controller surface the loading tracker needs. `update` is spelled out
|
|
7
|
+
* here because it is protected on the controller and so cannot be picked.
|
|
8
|
+
*/
|
|
9
|
+
export type AssetsLoadingStateUpdater = {
|
|
10
|
+
state: AssetsLoadingState;
|
|
11
|
+
update: (callback: (state: AssetsLoadingState) => void) => void;
|
|
12
|
+
};
|
|
2
13
|
/**
|
|
3
14
|
* Method decorator that tracks a per-account first-load status around the
|
|
4
15
|
* decorated fetch method: accounts whose assets have never been fetched are
|
|
@@ -15,4 +26,18 @@ import type { InternalAccount } from '@metamask/keyring-internal-api';
|
|
|
15
26
|
export declare function trackAssetsLoading<This, Args extends [InternalAccount[], {
|
|
16
27
|
forceUpdate?: boolean;
|
|
17
28
|
}?, ...unknown[]], Return>(target: (this: This, ...args: Args) => Promise<Return>, _context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Promise<Return>>): (this: This, ...args: Args) => Promise<Return>;
|
|
29
|
+
/**
|
|
30
|
+
* Track the per-account background loading status around a background fetch.
|
|
31
|
+
* Unlike {@link trackAssetsLoading}, every call is tracked: the accounts are
|
|
32
|
+
* marked `'loading'` before the fetch starts and settle to `'loaded'` once
|
|
33
|
+
* every overlapping background fetch for that account has completed, whether
|
|
34
|
+
* it succeeded or failed.
|
|
35
|
+
*
|
|
36
|
+
* @param controller - The controller whose state should be updated.
|
|
37
|
+
* @param accounts - The accounts the background fetch covers.
|
|
38
|
+
* @param runFetch - Starts the background fetch.
|
|
39
|
+
* @returns The result of the background fetch.
|
|
40
|
+
*/
|
|
41
|
+
export declare function trackBackgroundAssetsLoading<Result>(controller: AssetsLoadingStateUpdater, accounts: InternalAccount[], runFetch: () => Promise<Result>): Promise<Result>;
|
|
42
|
+
export {};
|
|
18
43
|
//# sourceMappingURL=trackAssetsLoading.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trackAssetsLoading.d.ts","sourceRoot":"","sources":["../src/trackAssetsLoading.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"trackAssetsLoading.d.ts","sourceRoot":"","sources":["../src/trackAssetsLoading.ts"],"names":[],"mappings":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logger.js';
|
|
2
|
+
const log = createModuleLogger(projectLogger, 'trackAssetsLoading');
|
|
3
|
+
/**
|
|
4
|
+
* In-flight background fetch counts per account, keyed by controller, so an
|
|
5
|
+
* account only settles once every overlapping background fetch has finished.
|
|
6
|
+
*/
|
|
7
|
+
const inFlightBackgroundFetches = new WeakMap();
|
|
1
8
|
/**
|
|
2
9
|
* Set the loading status of the given accounts.
|
|
3
10
|
*
|
|
4
11
|
* @param controller - The controller whose state should be updated.
|
|
12
|
+
* @param key - The loading status state property to update.
|
|
5
13
|
* @param accounts - The accounts to set the status for.
|
|
6
14
|
* @param status - The loading status to set.
|
|
7
15
|
*/
|
|
8
|
-
function setAssetsLoadingStatus(controller, accounts, status) {
|
|
16
|
+
function setAssetsLoadingStatus(controller, key, accounts, status) {
|
|
9
17
|
if (accounts.length === 0) {
|
|
10
18
|
return;
|
|
11
19
|
}
|
|
12
20
|
controller.update((state) => {
|
|
13
|
-
state
|
|
21
|
+
state[key] ??= {};
|
|
14
22
|
for (const account of accounts) {
|
|
15
|
-
state
|
|
23
|
+
state[key][account.id] = status;
|
|
16
24
|
}
|
|
17
25
|
});
|
|
26
|
+
log(`${key} updated`, {
|
|
27
|
+
status,
|
|
28
|
+
accountIds: accounts.map((account) => account.id),
|
|
29
|
+
[key]: controller.state[key],
|
|
30
|
+
});
|
|
18
31
|
}
|
|
19
32
|
/**
|
|
20
33
|
* Method decorator that tracks a per-account first-load status around the
|
|
@@ -36,14 +49,66 @@ export function trackAssetsLoading(target, _context) {
|
|
|
36
49
|
return target.call(this, ...args);
|
|
37
50
|
}
|
|
38
51
|
const controller = this;
|
|
39
|
-
const firstLoadAccounts =
|
|
40
|
-
|
|
52
|
+
const firstLoadAccounts = [];
|
|
53
|
+
const settledAccountIds = [];
|
|
54
|
+
for (const account of accounts) {
|
|
55
|
+
if (controller.state.assetsLoadingStatus?.[account.id] === undefined) {
|
|
56
|
+
firstLoadAccounts.push(account);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
settledAccountIds.push(account.id);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (settledAccountIds.length > 0) {
|
|
63
|
+
log('Skipping assetsLoadingStatus for settled accounts', {
|
|
64
|
+
accountIds: settledAccountIds,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
setAssetsLoadingStatus(controller, 'assetsLoadingStatus', firstLoadAccounts, 'loading');
|
|
41
68
|
try {
|
|
42
69
|
return await target.call(this, ...args);
|
|
43
70
|
}
|
|
44
71
|
finally {
|
|
45
|
-
setAssetsLoadingStatus(controller, firstLoadAccounts, 'loaded');
|
|
72
|
+
setAssetsLoadingStatus(controller, 'assetsLoadingStatus', firstLoadAccounts, 'loaded');
|
|
46
73
|
}
|
|
47
74
|
};
|
|
48
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Track the per-account background loading status around a background fetch.
|
|
78
|
+
* Unlike {@link trackAssetsLoading}, every call is tracked: the accounts are
|
|
79
|
+
* marked `'loading'` before the fetch starts and settle to `'loaded'` once
|
|
80
|
+
* every overlapping background fetch for that account has completed, whether
|
|
81
|
+
* it succeeded or failed.
|
|
82
|
+
*
|
|
83
|
+
* @param controller - The controller whose state should be updated.
|
|
84
|
+
* @param accounts - The accounts the background fetch covers.
|
|
85
|
+
* @param runFetch - Starts the background fetch.
|
|
86
|
+
* @returns The result of the background fetch.
|
|
87
|
+
*/
|
|
88
|
+
export async function trackBackgroundAssetsLoading(controller, accounts, runFetch) {
|
|
89
|
+
let counts = inFlightBackgroundFetches.get(controller);
|
|
90
|
+
if (!counts) {
|
|
91
|
+
counts = new Map();
|
|
92
|
+
inFlightBackgroundFetches.set(controller, counts);
|
|
93
|
+
}
|
|
94
|
+
for (const account of accounts) {
|
|
95
|
+
counts.set(account.id, (counts.get(account.id) ?? 0) + 1);
|
|
96
|
+
}
|
|
97
|
+
setAssetsLoadingStatus(controller, 'assetsBackgroundLoadingStatus', accounts, 'loading');
|
|
98
|
+
try {
|
|
99
|
+
return await runFetch();
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
const settledAccounts = accounts.filter((account) => {
|
|
103
|
+
const remaining = (counts.get(account.id) ?? 1) - 1;
|
|
104
|
+
if (remaining > 0) {
|
|
105
|
+
counts.set(account.id, remaining);
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
counts.delete(account.id);
|
|
109
|
+
return true;
|
|
110
|
+
});
|
|
111
|
+
setAssetsLoadingStatus(controller, 'assetsBackgroundLoadingStatus', settledAccounts, 'loaded');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
49
114
|
//# sourceMappingURL=trackAssetsLoading.js.map
|