@metamask/snap-networks-utils 1.0.0 → 2.0.0
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 +63 -1
- package/README.md +4 -10
- package/dist/index.cjs +102 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +51 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +32 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/assets/AssetsProvider.cjs +36 -18
- package/dist/providers/assets/AssetsProvider.cjs.map +1 -1
- package/dist/providers/assets/AssetsProvider.d.cts +30 -2
- package/dist/providers/assets/AssetsProvider.d.cts.map +1 -1
- package/dist/providers/assets/AssetsProvider.d.mts +30 -2
- package/dist/providers/assets/AssetsProvider.d.mts.map +1 -1
- package/dist/providers/assets/AssetsProvider.mjs +36 -18
- package/dist/providers/assets/AssetsProvider.mjs.map +1 -1
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.cjs +4 -17
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.cjs.map +1 -1
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.mjs +4 -17
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.mjs.map +1 -1
- package/dist/services/analytics/AnalyticsService.cjs +225 -0
- package/dist/services/analytics/AnalyticsService.cjs.map +1 -0
- package/dist/services/analytics/AnalyticsService.d.cts +175 -0
- package/dist/services/analytics/AnalyticsService.d.cts.map +1 -0
- package/dist/services/analytics/AnalyticsService.d.mts +175 -0
- package/dist/services/analytics/AnalyticsService.d.mts.map +1 -0
- package/dist/services/analytics/AnalyticsService.mjs +221 -0
- package/dist/services/analytics/AnalyticsService.mjs.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.cjs +23 -0
- package/dist/ui/ActionHeader/ActionHeader.cjs.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.d.cts +27 -0
- package/dist/ui/ActionHeader/ActionHeader.d.cts.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.d.mts +27 -0
- package/dist/ui/ActionHeader/ActionHeader.d.mts.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.mjs +19 -0
- package/dist/ui/ActionHeader/ActionHeader.mjs.map +1 -0
- package/dist/ui/Asset/Asset.cjs +68 -0
- package/dist/ui/Asset/Asset.cjs.map +1 -0
- package/dist/ui/Asset/Asset.d.cts +83 -0
- package/dist/ui/Asset/Asset.d.cts.map +1 -0
- package/dist/ui/Asset/Asset.d.mts +83 -0
- package/dist/ui/Asset/Asset.d.mts.map +1 -0
- package/dist/ui/Asset/Asset.mjs +60 -0
- package/dist/ui/Asset/Asset.mjs.map +1 -0
- package/dist/ui/Asset/question-mark.svg +3 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.cjs +57 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.cjs.map +1 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.cts +50 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.cts.map +1 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.mts +50 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.mts.map +1 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.mjs +53 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.mjs.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.cjs +72 -0
- package/dist/ui/TransactionAlert/TransactionAlert.cjs.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.cts +58 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.cts.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.mts +58 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.mts.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.mjs +68 -0
- package/dist/ui/TransactionAlert/TransactionAlert.mjs.map +1 -0
- package/dist/utils/async/async.cjs +95 -0
- package/dist/utils/async/async.cjs.map +1 -0
- package/dist/utils/async/async.d.cts +51 -0
- package/dist/utils/async/async.d.cts.map +1 -0
- package/dist/utils/async/async.d.mts +51 -0
- package/dist/utils/async/async.d.mts.map +1 -0
- package/dist/utils/async/async.mjs +88 -0
- package/dist/utils/async/async.mjs.map +1 -0
- package/dist/utils/buildUrl/buildUrl.cjs +54 -0
- package/dist/utils/buildUrl/buildUrl.cjs.map +1 -0
- package/dist/utils/buildUrl/buildUrl.d.cts +15 -0
- package/dist/utils/buildUrl/buildUrl.d.cts.map +1 -0
- package/dist/utils/buildUrl/buildUrl.d.mts +15 -0
- package/dist/utils/buildUrl/buildUrl.d.mts.map +1 -0
- package/dist/utils/buildUrl/buildUrl.mjs +51 -0
- package/dist/utils/buildUrl/buildUrl.mjs.map +1 -0
- package/dist/utils/cache/InMemoryCache.cjs +134 -0
- package/dist/utils/cache/InMemoryCache.cjs.map +1 -0
- package/dist/utils/cache/InMemoryCache.d.cts +29 -0
- package/dist/utils/cache/InMemoryCache.d.cts.map +1 -0
- package/dist/utils/cache/InMemoryCache.d.mts +29 -0
- package/dist/utils/cache/InMemoryCache.d.mts.map +1 -0
- package/dist/utils/cache/InMemoryCache.mjs +130 -0
- package/dist/utils/cache/InMemoryCache.mjs.map +1 -0
- package/dist/utils/cache/StateCache.cjs +193 -0
- package/dist/utils/cache/StateCache.cjs.map +1 -0
- package/dist/utils/cache/StateCache.d.cts +96 -0
- package/dist/utils/cache/StateCache.d.cts.map +1 -0
- package/dist/utils/cache/StateCache.d.mts +96 -0
- package/dist/utils/cache/StateCache.d.mts.map +1 -0
- package/dist/utils/cache/StateCache.mjs +189 -0
- package/dist/utils/cache/StateCache.mjs.map +1 -0
- package/dist/utils/cache/types.cjs +3 -0
- package/dist/utils/cache/types.cjs.map +1 -0
- package/dist/utils/cache/types.d.cts +99 -0
- package/dist/utils/cache/types.d.cts.map +1 -0
- package/dist/utils/cache/types.d.mts +99 -0
- package/dist/utils/cache/types.d.mts.map +1 -0
- package/dist/utils/cache/types.mjs +2 -0
- package/dist/utils/cache/types.mjs.map +1 -0
- package/dist/utils/cache/useCache.cjs +82 -0
- package/dist/utils/cache/useCache.cjs.map +1 -0
- package/dist/utils/cache/useCache.d.cts +57 -0
- package/dist/utils/cache/useCache.d.cts.map +1 -0
- package/dist/utils/cache/useCache.d.mts +57 -0
- package/dist/utils/cache/useCache.d.mts.map +1 -0
- package/dist/utils/cache/useCache.mjs +78 -0
- package/dist/utils/cache/useCache.mjs.map +1 -0
- package/dist/utils/cache/useCacheUntil.cjs +80 -0
- package/dist/utils/cache/useCacheUntil.cjs.map +1 -0
- package/dist/utils/cache/useCacheUntil.d.cts +54 -0
- package/dist/utils/cache/useCacheUntil.d.cts.map +1 -0
- package/dist/utils/cache/useCacheUntil.d.mts +54 -0
- package/dist/utils/cache/useCacheUntil.d.mts.map +1 -0
- package/dist/utils/cache/useCacheUntil.mjs +76 -0
- package/dist/utils/cache/useCacheUntil.mjs.map +1 -0
- package/dist/utils/config/BaseConfigProvider.cjs +62 -0
- package/dist/utils/config/BaseConfigProvider.cjs.map +1 -0
- package/dist/utils/config/BaseConfigProvider.d.cts +54 -0
- package/dist/utils/config/BaseConfigProvider.d.cts.map +1 -0
- package/dist/utils/config/BaseConfigProvider.d.mts +54 -0
- package/dist/utils/config/BaseConfigProvider.d.mts.map +1 -0
- package/dist/utils/config/BaseConfigProvider.mjs +58 -0
- package/dist/utils/config/BaseConfigProvider.mjs.map +1 -0
- package/dist/utils/config/envStructs.cjs +69 -0
- package/dist/utils/config/envStructs.cjs.map +1 -0
- package/dist/utils/config/envStructs.d.cts +57 -0
- package/dist/utils/config/envStructs.d.cts.map +1 -0
- package/dist/utils/config/envStructs.d.mts +57 -0
- package/dist/utils/config/envStructs.d.mts.map +1 -0
- package/dist/utils/config/envStructs.mjs +61 -0
- package/dist/utils/config/envStructs.mjs.map +1 -0
- package/dist/utils/config/environmentStruct.cjs +19 -0
- package/dist/utils/config/environmentStruct.cjs.map +1 -0
- package/dist/utils/config/environmentStruct.d.cts +20 -0
- package/dist/utils/config/environmentStruct.d.cts.map +1 -0
- package/dist/utils/config/environmentStruct.d.mts +20 -0
- package/dist/utils/config/environmentStruct.d.mts.map +1 -0
- package/dist/utils/config/environmentStruct.mjs +16 -0
- package/dist/utils/config/environmentStruct.mjs.map +1 -0
- package/dist/utils/config/logLevelStruct.cjs +14 -0
- package/dist/utils/config/logLevelStruct.cjs.map +1 -0
- package/dist/utils/config/logLevelStruct.d.cts +17 -0
- package/dist/utils/config/logLevelStruct.d.cts.map +1 -0
- package/dist/utils/config/logLevelStruct.d.mts +17 -0
- package/dist/utils/config/logLevelStruct.d.mts.map +1 -0
- package/dist/utils/config/logLevelStruct.mjs +11 -0
- package/dist/utils/config/logLevelStruct.mjs.map +1 -0
- package/dist/utils/config/parseEnv.cjs +30 -0
- package/dist/utils/config/parseEnv.cjs.map +1 -0
- package/dist/utils/config/parseEnv.d.cts +19 -0
- package/dist/utils/config/parseEnv.d.cts.map +1 -0
- package/dist/utils/config/parseEnv.d.mts +19 -0
- package/dist/utils/config/parseEnv.d.mts.map +1 -0
- package/dist/utils/config/parseEnv.mjs +26 -0
- package/dist/utils/config/parseEnv.mjs.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.cjs +28 -0
- package/dist/utils/dedupe/InFlightCoalescer.cjs.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.cts +12 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.cts.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.mts +12 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.mts.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.mjs +24 -0
- package/dist/utils/dedupe/InFlightCoalescer.mjs.map +1 -0
- package/dist/utils/errors/errors.cjs +44 -0
- package/dist/utils/errors/errors.cjs.map +1 -0
- package/dist/utils/errors/errors.d.cts +37 -0
- package/dist/utils/errors/errors.d.cts.map +1 -0
- package/dist/utils/errors/errors.d.mts +37 -0
- package/dist/utils/errors/errors.d.mts.map +1 -0
- package/dist/utils/errors/errors.mjs +40 -0
- package/dist/utils/errors/errors.mjs.map +1 -0
- package/dist/utils/errors/index.cjs +18 -0
- package/dist/utils/errors/index.cjs.map +1 -0
- package/dist/utils/errors/index.d.cts +10 -0
- package/dist/utils/errors/index.d.cts.map +1 -0
- package/dist/utils/errors/index.d.mts +10 -0
- package/dist/utils/errors/index.d.mts.map +1 -0
- package/dist/utils/errors/index.mjs +6 -0
- package/dist/utils/errors/index.mjs.map +1 -0
- package/dist/utils/errors/snapRpcError.cjs +33 -0
- package/dist/utils/errors/snapRpcError.cjs.map +1 -0
- package/dist/utils/errors/snapRpcError.d.cts +11 -0
- package/dist/utils/errors/snapRpcError.d.cts.map +1 -0
- package/dist/utils/errors/snapRpcError.d.mts +11 -0
- package/dist/utils/errors/snapRpcError.d.mts.map +1 -0
- package/dist/utils/errors/snapRpcError.mjs +30 -0
- package/dist/utils/errors/snapRpcError.mjs.map +1 -0
- package/dist/utils/errors/stringifyReason.cjs +36 -0
- package/dist/utils/errors/stringifyReason.cjs.map +1 -0
- package/dist/utils/errors/stringifyReason.d.cts +15 -0
- package/dist/utils/errors/stringifyReason.d.cts.map +1 -0
- package/dist/utils/errors/stringifyReason.d.mts +15 -0
- package/dist/utils/errors/stringifyReason.d.mts.map +1 -0
- package/dist/utils/errors/stringifyReason.mjs +33 -0
- package/dist/utils/errors/stringifyReason.mjs.map +1 -0
- package/dist/utils/errors/syncError.cjs +98 -0
- package/dist/utils/errors/syncError.cjs.map +1 -0
- package/dist/utils/errors/syncError.d.cts +60 -0
- package/dist/utils/errors/syncError.d.cts.map +1 -0
- package/dist/utils/errors/syncError.d.mts +60 -0
- package/dist/utils/errors/syncError.d.mts.map +1 -0
- package/dist/utils/errors/syncError.mjs +92 -0
- package/dist/utils/errors/syncError.mjs.map +1 -0
- package/dist/utils/errors/trackError.cjs +76 -0
- package/dist/utils/errors/trackError.cjs.map +1 -0
- package/dist/utils/errors/trackError.d.cts +64 -0
- package/dist/utils/errors/trackError.d.cts.map +1 -0
- package/dist/utils/errors/trackError.d.mts +64 -0
- package/dist/utils/errors/trackError.d.mts.map +1 -0
- package/dist/utils/errors/trackError.mjs +72 -0
- package/dist/utils/errors/trackError.mjs.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.cjs +57 -0
- package/dist/utils/handlers/wrapSnapHandlers.cjs.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.cts +74 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.cts.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.mts +74 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.mts.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.mjs +53 -0
- package/dist/utils/handlers/wrapSnapHandlers.mjs.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.cjs +25 -0
- package/dist/utils/keyringAccount/keyringAccount.cjs.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.d.cts +29 -0
- package/dist/utils/keyringAccount/keyringAccount.d.cts.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.d.mts +29 -0
- package/dist/utils/keyringAccount/keyringAccount.d.mts.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.mjs +22 -0
- package/dist/utils/keyringAccount/keyringAccount.mjs.map +1 -0
- package/dist/utils/logger/Logger.cjs +140 -0
- package/dist/utils/logger/Logger.cjs.map +1 -0
- package/dist/utils/logger/Logger.d.cts +118 -0
- package/dist/utils/logger/Logger.d.cts.map +1 -0
- package/dist/utils/logger/Logger.d.mts +118 -0
- package/dist/utils/logger/Logger.d.mts.map +1 -0
- package/dist/utils/logger/Logger.mjs +136 -0
- package/dist/utils/logger/Logger.mjs.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.cjs +26 -0
- package/dist/utils/logger/__mocks__/Logger.cjs.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.d.cts +3 -0
- package/dist/utils/logger/__mocks__/Logger.d.cts.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.d.mts +3 -0
- package/dist/utils/logger/__mocks__/Logger.d.mts.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.mjs +23 -0
- package/dist/utils/logger/__mocks__/Logger.mjs.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.cjs +30 -0
- package/dist/utils/originPermissions/createOriginPermissions.cjs.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.cts +24 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.cts.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.mts +24 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.mts.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.mjs +26 -0
- package/dist/utils/originPermissions/createOriginPermissions.mjs.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.cjs +23 -0
- package/dist/utils/originPermissions/validateOrigin.cjs.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.d.cts +10 -0
- package/dist/utils/originPermissions/validateOrigin.d.cts.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.d.mts +10 -0
- package/dist/utils/originPermissions/validateOrigin.d.mts.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.mjs +19 -0
- package/dist/utils/originPermissions/validateOrigin.mjs.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.cjs +89 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.cjs.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.cts +143 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.cts.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.mts +143 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.mts.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.mjs +85 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.mjs.map +1 -0
- package/dist/utils/safeMerge/safeMerge.cjs +26 -0
- package/dist/utils/safeMerge/safeMerge.cjs.map +1 -0
- package/dist/utils/safeMerge/safeMerge.d.cts +17 -0
- package/dist/utils/safeMerge/safeMerge.d.cts.map +1 -0
- package/dist/utils/safeMerge/safeMerge.d.mts +17 -0
- package/dist/utils/safeMerge/safeMerge.d.mts.map +1 -0
- package/dist/utils/safeMerge/safeMerge.mjs +22 -0
- package/dist/utils/safeMerge/safeMerge.mjs.map +1 -0
- package/dist/utils/sanitize/sanitize.cjs +42 -0
- package/dist/utils/sanitize/sanitize.cjs.map +1 -0
- package/dist/utils/sanitize/sanitize.d.cts +15 -0
- package/dist/utils/sanitize/sanitize.d.cts.map +1 -0
- package/dist/utils/sanitize/sanitize.d.mts +15 -0
- package/dist/utils/sanitize/sanitize.d.mts.map +1 -0
- package/dist/utils/sanitize/sanitize.mjs +38 -0
- package/dist/utils/sanitize/sanitize.mjs.map +1 -0
- package/dist/utils/serialization/serialization.cjs +73 -0
- package/dist/utils/serialization/serialization.cjs.map +1 -0
- package/dist/utils/serialization/serialization.d.cts +19 -0
- package/dist/utils/serialization/serialization.d.cts.map +1 -0
- package/dist/utils/serialization/serialization.d.mts +19 -0
- package/dist/utils/serialization/serialization.d.mts.map +1 -0
- package/dist/utils/serialization/serialization.mjs +69 -0
- package/dist/utils/serialization/serialization.mjs.map +1 -0
- package/dist/utils/serialization/types.cjs +3 -0
- package/dist/utils/serialization/types.cjs.map +1 -0
- package/dist/utils/serialization/types.d.cts +8 -0
- package/dist/utils/serialization/types.d.cts.map +1 -0
- package/dist/utils/serialization/types.d.mts +8 -0
- package/dist/utils/serialization/types.d.mts.map +1 -0
- package/dist/utils/serialization/types.mjs +2 -0
- package/dist/utils/serialization/types.mjs.map +1 -0
- package/dist/utils/state/IStateManager.cjs +3 -0
- package/dist/utils/state/IStateManager.cjs.map +1 -0
- package/dist/utils/state/IStateManager.d.cts +69 -0
- package/dist/utils/state/IStateManager.d.cts.map +1 -0
- package/dist/utils/state/IStateManager.d.mts +69 -0
- package/dist/utils/state/IStateManager.d.mts.map +1 -0
- package/dist/utils/state/IStateManager.mjs +2 -0
- package/dist/utils/state/IStateManager.mjs.map +1 -0
- package/dist/utils/state/InMemoryState.cjs +41 -0
- package/dist/utils/state/InMemoryState.cjs.map +1 -0
- package/dist/utils/state/InMemoryState.d.cts +18 -0
- package/dist/utils/state/InMemoryState.d.cts.map +1 -0
- package/dist/utils/state/InMemoryState.d.mts +18 -0
- package/dist/utils/state/InMemoryState.d.mts.map +1 -0
- package/dist/utils/state/InMemoryState.mjs +38 -0
- package/dist/utils/state/InMemoryState.mjs.map +1 -0
- package/dist/utils/state/State.cjs +159 -0
- package/dist/utils/state/State.cjs.map +1 -0
- package/dist/utils/state/State.d.cts +25 -0
- package/dist/utils/state/State.d.cts.map +1 -0
- package/dist/utils/state/State.d.mts +25 -0
- package/dist/utils/state/State.d.mts.map +1 -0
- package/dist/utils/state/State.mjs +156 -0
- package/dist/utils/state/State.mjs.map +1 -0
- package/dist/utils/transactionType/transactionType.cjs +32 -0
- package/dist/utils/transactionType/transactionType.cjs.map +1 -0
- package/dist/utils/transactionType/transactionType.d.cts +17 -0
- package/dist/utils/transactionType/transactionType.d.cts.map +1 -0
- package/dist/utils/transactionType/transactionType.d.mts +17 -0
- package/dist/utils/transactionType/transactionType.d.mts.map +1 -0
- package/dist/utils/transactionType/transactionType.mjs +28 -0
- package/dist/utils/transactionType/transactionType.mjs.map +1 -0
- package/dist/utils/urlStruct/urlStruct.cjs +96 -0
- package/dist/utils/urlStruct/urlStruct.cjs.map +1 -0
- package/dist/utils/urlStruct/urlStruct.d.cts +25 -0
- package/dist/utils/urlStruct/urlStruct.d.cts.map +1 -0
- package/dist/utils/urlStruct/urlStruct.d.mts +25 -0
- package/dist/utils/urlStruct/urlStruct.d.mts.map +1 -0
- package/dist/utils/urlStruct/urlStruct.mjs +93 -0
- package/dist/utils/urlStruct/urlStruct.mjs.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.cjs +12 -0
- package/dist/utils/uuidStruct/uuidStruct.cjs.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.d.cts +8 -0
- package/dist/utils/uuidStruct/uuidStruct.d.cts.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.d.mts +8 -0
- package/dist/utils/uuidStruct/uuidStruct.d.mts.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.mjs +9 -0
- package/dist/utils/uuidStruct/uuidStruct.mjs.map +1 -0
- package/package.json +33 -13
- package/dist/logger.cjs +0 -57
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts +0 -30
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -30
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs +0 -53
- package/dist/logger.mjs.map +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@metamask/snaps-sdk/jsx-runtime";
|
|
2
|
+
import { Box, Icon, Image, Section, Skeleton, Text as SnapText, Tooltip } from "@metamask/snaps-sdk/jsx";
|
|
3
|
+
const Header = ({ labels, }) => (_jsxs(Box, { direction: "horizontal", alignment: "start", children: [_jsx(SnapText, { fontWeight: "medium", children: labels.title }), _jsx(Tooltip, { content: labels.tooltip, children: _jsx(Icon, { name: "info" }) })] }));
|
|
4
|
+
const MessageSection = ({ labels, message, }) => (_jsxs(Section, { direction: "vertical", children: [_jsx(Header, { labels: labels }), _jsx(SnapText, { color: "alternative", children: message })] }));
|
|
5
|
+
const AssetRow = ({ asset, }) => {
|
|
6
|
+
const isOut = asset.type === 'out';
|
|
7
|
+
const isUnknownValue = asset.value === null;
|
|
8
|
+
let label;
|
|
9
|
+
if (isUnknownValue) {
|
|
10
|
+
label = `– ${asset.symbol}`;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
const sign = isOut ? '-' : '+';
|
|
14
|
+
label = `${sign}${asset.value} ${asset.symbol}`;
|
|
15
|
+
}
|
|
16
|
+
const successOrError = isOut ? 'error' : 'success';
|
|
17
|
+
return (_jsxs(Box, { direction: "vertical", crossAlignment: "end", children: [_jsxs(Box, { direction: "horizontal", alignment: "end", center: true, children: [asset.logo ? (_jsx(Image, { src: asset.logo, borderRadius: "full", height: 16, width: 16 })) : null, _jsx(SnapText, { color: isUnknownValue ? 'alternative' : successOrError, children: label })] }), asset.fiat ? _jsx(SnapText, { color: "muted", children: asset.fiat }) : null] }));
|
|
18
|
+
};
|
|
19
|
+
const AssetGroup = ({ title, assets, }) => assets.length > 0 ? (_jsxs(Box, { alignment: "space-between", direction: "horizontal", children: [_jsx(SnapText, { fontWeight: "medium", color: "alternative", children: title }), _jsx(Box, { direction: "vertical", alignment: "end", children: assets.map((asset, index) => (_jsx(Box, { children: _jsx(AssetRow, { asset: asset }) }, `${asset.type}-${asset.symbol}-${index}`))) })] })) : null;
|
|
20
|
+
/**
|
|
21
|
+
* Renders the estimated balance changes of a transaction, grouped into
|
|
22
|
+
* "send" and "receive" rows, with loading, error and empty states.
|
|
23
|
+
*
|
|
24
|
+
* The header is always rendered. The body depends on the props:
|
|
25
|
+
*
|
|
26
|
+
* 1. No assets and `isFetching` → loading skeleton (takes precedence over
|
|
27
|
+
* `isUnavailable`).
|
|
28
|
+
* 2. No assets and `isUnavailable` → "not available" message.
|
|
29
|
+
* 3. No assets otherwise → "no changes" message (an empty result means the
|
|
30
|
+
* transaction does not change any balance).
|
|
31
|
+
* 4. Assets present → "send" and/or "receive" groups; a group with no assets
|
|
32
|
+
* is omitted. `isFetching` and `isUnavailable` are ignored in this case, as
|
|
33
|
+
* rows seeded locally by the caller are final.
|
|
34
|
+
*
|
|
35
|
+
* @param props - The component props.
|
|
36
|
+
* @param props.assets - The display-ready asset changes.
|
|
37
|
+
* @param props.labels - The translated labels.
|
|
38
|
+
* @param props.isFetching - Whether the estimate is still being fetched.
|
|
39
|
+
* @param props.isUnavailable - Whether the estimate could not be produced.
|
|
40
|
+
* @returns The estimated changes section.
|
|
41
|
+
*/
|
|
42
|
+
export const EstimatedChanges = ({ assets, labels, isFetching, isUnavailable, }) => {
|
|
43
|
+
// Rows seeded locally by the caller are final, so they are never replaced by
|
|
44
|
+
// the loading/unavailable states.
|
|
45
|
+
if (assets.length === 0) {
|
|
46
|
+
if (isFetching) {
|
|
47
|
+
return (_jsxs(Section, { direction: "vertical", children: [_jsx(Header, { labels: labels }), _jsxs(Box, { alignment: "space-between", direction: "horizontal", children: [_jsx(Skeleton, { width: 60 }), _jsx(Skeleton, { width: 100 })] })] }));
|
|
48
|
+
}
|
|
49
|
+
return (_jsx(MessageSection, { labels: labels, message: isUnavailable ? labels.notAvailable : labels.noChanges }));
|
|
50
|
+
}
|
|
51
|
+
return (_jsxs(Section, { children: [_jsx(Header, { labels: labels }), _jsx(AssetGroup, { title: labels.send, assets: assets.filter((asset) => asset.type === 'out') }), _jsx(AssetGroup, { title: labels.receive, assets: assets.filter((asset) => asset.type === 'in') })] }));
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=EstimatedChanges.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EstimatedChanges.mjs","sourceRoot":"","sources":["../../../src/ui/EstimatedChanges/EstimatedChanges.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,GAAG,EACH,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,IAAI,IAAI,QAAQ,EAChB,OAAO,EACR,gCAAgC;AA8BjC,MAAM,MAAM,GAAG,CAAC,EACd,MAAM,GAGP,EAAsB,EAAE,CAAC,CACxB,MAAC,GAAG,IAAC,SAAS,EAAC,YAAY,EAAC,SAAS,EAAC,OAAO,aAC3C,KAAC,QAAQ,IAAC,UAAU,EAAC,QAAQ,YAAE,MAAM,CAAC,KAAK,GAAY,EACvD,KAAC,OAAO,IAAC,OAAO,EAAE,MAAM,CAAC,OAAO,YAC9B,KAAC,IAAI,IAAC,IAAI,EAAC,MAAM,GAAG,GACZ,IACN,CACP,CAAC;AAEF,MAAM,cAAc,GAAG,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SAAS,EAAC,eAAe,EAAC,SAAS,EAAC,YAAY,aACnD,KAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,GAAI,EACvB,KAAC,QAAQ,IAAC,KAAK,EAAE,GAAG,GAAI,IACpB,IACE,CACX,CAAC;QACJ,CAAC;QAED,OAAO,CACL,KAAC,cAAc,IACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,GAC/D,CACH,CAAC;IACJ,CAAC;IAED,OAAO,CACL,MAAC,OAAO,eACN,KAAC,MAAM,IAAC,MAAM,EAAE,MAAM,GAAI,EAC1B,KAAC,UAAU,IACT,KAAK,EAAE,MAAM,CAAC,IAAI,EAClB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,GACtD,EACF,KAAC,UAAU,IACT,KAAK,EAAE,MAAM,CAAC,OAAO,EACrB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,GACrD,IACM,CACX,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { ComponentOrElement } from '@metamask/snaps-sdk';\nimport {\n Box,\n Icon,\n Image,\n Section,\n Skeleton,\n Text as SnapText,\n Tooltip,\n} from '@metamask/snaps-sdk/jsx';\n\nexport type EstimatedChangesAsset = {\n type: 'in' | 'out';\n /** Display-ready amount, or `null` when the amount is unknown. */\n value: string | null;\n symbol: string;\n logo: string | null;\n /** Display-ready fiat value shown under the amount. */\n fiat?: string | null;\n};\n\nexport type EstimatedChangesLabels = {\n title: string;\n tooltip: string;\n send: string;\n receive: string;\n notAvailable: string;\n noChanges: string;\n};\n\nexport type EstimatedChangesProps = {\n assets: EstimatedChangesAsset[];\n labels: EstimatedChangesLabels;\n /** Whether the estimate is still being fetched. */\n isFetching: boolean;\n /** Whether the estimate could not be produced (e.g. fetch or simulation failure). */\n isUnavailable: boolean;\n};\n\nconst Header = ({\n labels,\n}: {\n labels: EstimatedChangesLabels;\n}): ComponentOrElement => (\n <Box direction=\"horizontal\" alignment=\"start\">\n <SnapText fontWeight=\"medium\">{labels.title}</SnapText>\n <Tooltip content={labels.tooltip}>\n <Icon name=\"info\" />\n </Tooltip>\n </Box>\n);\n\nconst MessageSection = ({\n labels,\n message,\n}: {\n labels: EstimatedChangesLabels;\n message: string;\n}): ComponentOrElement => (\n <Section direction=\"vertical\">\n <Header labels={labels} />\n <SnapText color=\"alternative\">{message}</SnapText>\n </Section>\n);\n\nconst AssetRow = ({\n asset,\n}: {\n asset: EstimatedChangesAsset;\n}): ComponentOrElement => {\n const isOut = asset.type === 'out';\n const isUnknownValue = asset.value === null;\n let label: string;\n if (isUnknownValue) {\n label = `– ${asset.symbol}`;\n } else {\n const sign = isOut ? '-' : '+';\n label = `${sign}${asset.value} ${asset.symbol}`;\n }\n const successOrError = isOut ? 'error' : 'success';\n\n return (\n <Box direction=\"vertical\" crossAlignment=\"end\">\n <Box direction=\"horizontal\" alignment=\"end\" center>\n {asset.logo ? (\n <Image src={asset.logo} borderRadius=\"full\" height={16} width={16} />\n ) : null}\n <SnapText color={isUnknownValue ? 'alternative' : successOrError}>\n {label}\n </SnapText>\n </Box>\n {asset.fiat ? <SnapText color=\"muted\">{asset.fiat}</SnapText> : null}\n </Box>\n );\n};\n\nconst AssetGroup = ({\n title,\n assets,\n}: {\n title: string;\n assets: EstimatedChangesAsset[];\n}): ComponentOrElement | null =>\n assets.length > 0 ? (\n <Box alignment=\"space-between\" direction=\"horizontal\">\n <SnapText fontWeight=\"medium\" color=\"alternative\">\n {title}\n </SnapText>\n <Box direction=\"vertical\" alignment=\"end\">\n {assets.map((asset, index) => (\n <Box key={`${asset.type}-${asset.symbol}-${index}`}>\n <AssetRow asset={asset} />\n </Box>\n ))}\n </Box>\n </Box>\n ) : null;\n\n/**\n * Renders the estimated balance changes of a transaction, grouped into\n * \"send\" and \"receive\" rows, with loading, error and empty states.\n *\n * The header is always rendered. The body depends on the props:\n *\n * 1. No assets and `isFetching` → loading skeleton (takes precedence over\n * `isUnavailable`).\n * 2. No assets and `isUnavailable` → \"not available\" message.\n * 3. No assets otherwise → \"no changes\" message (an empty result means the\n * transaction does not change any balance).\n * 4. Assets present → \"send\" and/or \"receive\" groups; a group with no assets\n * is omitted. `isFetching` and `isUnavailable` are ignored in this case, as\n * rows seeded locally by the caller are final.\n *\n * @param props - The component props.\n * @param props.assets - The display-ready asset changes.\n * @param props.labels - The translated labels.\n * @param props.isFetching - Whether the estimate is still being fetched.\n * @param props.isUnavailable - Whether the estimate could not be produced.\n * @returns The estimated changes section.\n */\nexport const EstimatedChanges = ({\n assets,\n labels,\n isFetching,\n isUnavailable,\n}: EstimatedChangesProps): ComponentOrElement => {\n // Rows seeded locally by the caller are final, so they are never replaced by\n // the loading/unavailable states.\n if (assets.length === 0) {\n if (isFetching) {\n return (\n <Section direction=\"vertical\">\n <Header labels={labels} />\n <Box alignment=\"space-between\" direction=\"horizontal\">\n <Skeleton width={60} />\n <Skeleton width={100} />\n </Box>\n </Section>\n );\n }\n\n return (\n <MessageSection\n labels={labels}\n message={isUnavailable ? labels.notAvailable : labels.noChanges}\n />\n );\n }\n\n return (\n <Section>\n <Header labels={labels} />\n <AssetGroup\n title={labels.send}\n assets={assets.filter((asset) => asset.type === 'out')}\n />\n <AssetGroup\n title={labels.receive}\n assets={assets.filter((asset) => asset.type === 'in')}\n />\n </Section>\n );\n};\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionAlert = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("@metamask/snaps-sdk/jsx-runtime");
|
|
5
|
+
const jsx_1 = require("@metamask/snaps-sdk/jsx");
|
|
6
|
+
const SECURITY_ALERTS_URL = 'https://support.metamask.io/configure/wallet/how-to-turn-on-security-alerts/';
|
|
7
|
+
const BLOCKAID_URL = 'https://www.blockaid.io';
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the security banner for a validation result.
|
|
10
|
+
*
|
|
11
|
+
* @param validation - The security validation result.
|
|
12
|
+
* @param labels - The translated labels.
|
|
13
|
+
* @returns The banner severity, title and message, or `null` when the
|
|
14
|
+
* validation does not warrant a banner.
|
|
15
|
+
*/
|
|
16
|
+
function getValidationAlert(validation, labels) {
|
|
17
|
+
const trimmedDescription = validation.description?.trim();
|
|
18
|
+
const description = trimmedDescription === '' ? undefined : trimmedDescription;
|
|
19
|
+
if (validation.type === 'Malicious') {
|
|
20
|
+
return {
|
|
21
|
+
severity: 'danger',
|
|
22
|
+
title: labels.maliciousTitle,
|
|
23
|
+
message: description ?? labels.maliciousMessage,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (validation.type === 'Warning') {
|
|
27
|
+
return {
|
|
28
|
+
severity: 'warning',
|
|
29
|
+
title: labels.warningTitle,
|
|
30
|
+
message: description ?? labels.warningMessage,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Renders the single top-of-screen transaction scan banner.
|
|
37
|
+
*
|
|
38
|
+
* Exactly one banner is rendered, picked in this order:
|
|
39
|
+
*
|
|
40
|
+
* 1. `isFetching` → "scan in progress" info banner.
|
|
41
|
+
* 2. `isFetchError` → "scan failed" danger banner.
|
|
42
|
+
* 3. `error` → warning banner with the error title and message.
|
|
43
|
+
* 4. `Malicious` or `Warning` validation → security banner with a link to the
|
|
44
|
+
* security alerts documentation and the Blockaid attribution.
|
|
45
|
+
* 5. Otherwise nothing.
|
|
46
|
+
*
|
|
47
|
+
* @param props - The component props.
|
|
48
|
+
* @param props.labels - The translated labels.
|
|
49
|
+
* @param props.isFetching - Whether the transaction scan is in flight.
|
|
50
|
+
* @param props.isFetchError - Whether the transaction scan request failed.
|
|
51
|
+
* @param props.error - The scan error to show.
|
|
52
|
+
* @param props.validation - The security validation to show.
|
|
53
|
+
* @returns The banner, or `null` when no alert applies.
|
|
54
|
+
*/
|
|
55
|
+
const TransactionAlert = ({ labels, isFetching, isFetchError, error, validation, }) => {
|
|
56
|
+
if (isFetching) {
|
|
57
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Banner, { title: labels.scanInProgressTitle, severity: "info", children: (0, jsx_runtime_1.jsx)(jsx_1.Text, { children: labels.scanInProgressMessage }) }));
|
|
58
|
+
}
|
|
59
|
+
if (isFetchError) {
|
|
60
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Banner, { title: labels.scanFailedTitle, severity: "danger", children: (0, jsx_runtime_1.jsx)(jsx_1.Text, { children: labels.scanFailedMessage }) }));
|
|
61
|
+
}
|
|
62
|
+
if (error) {
|
|
63
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Banner, { title: error.title, severity: "warning", children: (0, jsx_runtime_1.jsx)(jsx_1.Text, { children: error.message }) }));
|
|
64
|
+
}
|
|
65
|
+
const alert = validation ? getValidationAlert(validation, labels) : null;
|
|
66
|
+
if (!alert) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_1.Banner, { title: alert.title, severity: alert.severity, children: [(0, jsx_runtime_1.jsx)(jsx_1.Text, { children: alert.message }), (0, jsx_runtime_1.jsx)(jsx_1.Text, { size: "sm", children: (0, jsx_runtime_1.jsx)(jsx_1.Link, { href: SECURITY_ALERTS_URL, children: labels.learnMore }) }), (0, jsx_runtime_1.jsxs)(jsx_1.Text, { size: "sm", children: [(0, jsx_runtime_1.jsx)(jsx_1.Icon, { color: "primary", name: "security-tick" }), " ", labels.securityAdvisedBy, ' ', (0, jsx_runtime_1.jsx)(jsx_1.Link, { href: BLOCKAID_URL, children: "Blockaid" })] })] }));
|
|
70
|
+
};
|
|
71
|
+
exports.TransactionAlert = TransactionAlert;
|
|
72
|
+
//# sourceMappingURL=TransactionAlert.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactionAlert.cjs","sourceRoot":"","sources":["../../../src/ui/TransactionAlert/TransactionAlert.tsx"],"names":[],"mappings":";;;;AACA,iDAA+E;AA0C/E,MAAM,mBAAmB,GACvB,8EAA8E,CAAC;AAEjF,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAE/C;;;;;;;GAOG;AACH,SAAS,kBAAkB,CACzB,UAAsC,EACtC,MAA8B;IAM9B,MAAM,kBAAkB,GAAG,UAAU,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC;IAC1D,MAAM,WAAW,GACf,kBAAkB,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,kBAAkB,CAAC;IAE7D,IAAI,UAAU,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACpC,OAAO;YACL,QAAQ,EAAE,QAAQ;YAClB,KAAK,EAAE,MAAM,CAAC,cAAc;YAC5B,OAAO,EAAE,WAAW,IAAI,MAAM,CAAC,gBAAgB;SAChD,CAAC;IACJ,CAAC;IAED,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO;YACL,QAAQ,EAAE,SAAS;YACnB,KAAK,EAAE,MAAM,CAAC,YAAY;YAC1B,OAAO,EAAE,WAAW,IAAI,MAAM,CAAC,cAAc;SAC9C,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,gBAAgB,GAAG,CAAC,EAC/B,MAAM,EACN,UAAU,EACV,YAAY,EACZ,KAAK,EACL,UAAU,GACY,EAA6B,EAAE;IACrD,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CACL,uBAAC,YAAM,IAAC,KAAK,EAAE,MAAM,CAAC,mBAAmB,EAAE,QAAQ,EAAC,MAAM,YACxD,u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esContent":["import type { ComponentOrElement } from '@metamask/snaps-sdk';\nimport { Banner, Icon, Link, Text as SnapText } from '@metamask/snaps-sdk/jsx';\nimport type { BannerProps } from '@metamask/snaps-sdk/jsx';\n\nexport type TransactionAlertLabels = {\n scanInProgressTitle: string;\n scanInProgressMessage: string;\n scanFailedTitle: string;\n scanFailedMessage: string;\n maliciousTitle: string;\n maliciousMessage: string;\n warningTitle: string;\n warningMessage: string;\n learnMore: string;\n securityAdvisedBy: string;\n};\n\nexport type TransactionAlertError = {\n /** Translated banner title. */\n title: string;\n /** Translated, user-facing reason of the scan error. */\n message: string;\n};\n\nexport type TransactionAlertValidation = {\n /** Security validation result type, e.g. `Malicious`, `Warning` or `Benign`. */\n type: string | null;\n /** Provider description of the finding, used instead of the default message. */\n description?: string | null;\n};\n\nexport type TransactionAlertProps = {\n labels: TransactionAlertLabels;\n /** Whether the transaction scan is in flight. */\n isFetching: boolean;\n /** Whether the transaction scan request itself failed. */\n isFetchError: boolean;\n /** The scan error to show, or `null` when there is none (or it is disabled). */\n error: TransactionAlertError | null;\n /** The security validation to show, or `null` when there is none (or it is disabled). */\n validation: TransactionAlertValidation | null;\n};\n\nconst SECURITY_ALERTS_URL =\n 'https://support.metamask.io/configure/wallet/how-to-turn-on-security-alerts/';\n\nconst BLOCKAID_URL = 'https://www.blockaid.io';\n\n/**\n * Resolves the security banner for a validation result.\n *\n * @param validation - The security validation result.\n * @param labels - The translated labels.\n * @returns The banner severity, title and message, or `null` when the\n * validation does not warrant a banner.\n */\nfunction getValidationAlert(\n validation: TransactionAlertValidation,\n labels: TransactionAlertLabels,\n): {\n severity: BannerProps['severity'];\n title: string;\n message: string;\n} | null {\n const trimmedDescription = validation.description?.trim();\n const description =\n trimmedDescription === '' ? undefined : trimmedDescription;\n\n if (validation.type === 'Malicious') {\n return {\n severity: 'danger',\n title: labels.maliciousTitle,\n message: description ?? labels.maliciousMessage,\n };\n }\n\n if (validation.type === 'Warning') {\n return {\n severity: 'warning',\n title: labels.warningTitle,\n message: description ?? labels.warningMessage,\n };\n }\n\n return null;\n}\n\n/**\n * Renders the single top-of-screen transaction scan banner.\n *\n * Exactly one banner is rendered, picked in this order:\n *\n * 1. `isFetching` → \"scan in progress\" info banner.\n * 2. `isFetchError` → \"scan failed\" danger banner.\n * 3. `error` → warning banner with the error title and message.\n * 4. `Malicious` or `Warning` validation → security banner with a link to the\n * security alerts documentation and the Blockaid attribution.\n * 5. Otherwise nothing.\n *\n * @param props - The component props.\n * @param props.labels - The translated labels.\n * @param props.isFetching - Whether the transaction scan is in flight.\n * @param props.isFetchError - Whether the transaction scan request failed.\n * @param props.error - The scan error to show.\n * @param props.validation - The security validation to show.\n * @returns The banner, or `null` when no alert applies.\n */\nexport const TransactionAlert = ({\n labels,\n isFetching,\n isFetchError,\n error,\n validation,\n}: TransactionAlertProps): ComponentOrElement | null => {\n if (isFetching) {\n return (\n <Banner title={labels.scanInProgressTitle} severity=\"info\">\n <SnapText>{labels.scanInProgressMessage}</SnapText>\n </Banner>\n );\n }\n\n if (isFetchError) {\n return (\n <Banner title={labels.scanFailedTitle} severity=\"danger\">\n <SnapText>{labels.scanFailedMessage}</SnapText>\n </Banner>\n );\n }\n\n if (error) {\n return (\n <Banner title={error.title} severity=\"warning\">\n <SnapText>{error.message}</SnapText>\n </Banner>\n );\n }\n\n const alert = validation ? getValidationAlert(validation, labels) : null;\n\n if (!alert) {\n return null;\n }\n\n return (\n <Banner title={alert.title} severity={alert.severity}>\n <SnapText>{alert.message}</SnapText>\n <SnapText size=\"sm\">\n <Link href={SECURITY_ALERTS_URL}>{labels.learnMore}</Link>\n </SnapText>\n <SnapText size=\"sm\">\n <Icon color=\"primary\" name=\"security-tick\" /> {labels.securityAdvisedBy}{' '}\n <Link href={BLOCKAID_URL}>Blockaid</Link>\n </SnapText>\n </Banner>\n );\n};\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ComponentOrElement } from "@metamask/snaps-sdk";
|
|
2
|
+
export type TransactionAlertLabels = {
|
|
3
|
+
scanInProgressTitle: string;
|
|
4
|
+
scanInProgressMessage: string;
|
|
5
|
+
scanFailedTitle: string;
|
|
6
|
+
scanFailedMessage: string;
|
|
7
|
+
maliciousTitle: string;
|
|
8
|
+
maliciousMessage: string;
|
|
9
|
+
warningTitle: string;
|
|
10
|
+
warningMessage: string;
|
|
11
|
+
learnMore: string;
|
|
12
|
+
securityAdvisedBy: string;
|
|
13
|
+
};
|
|
14
|
+
export type TransactionAlertError = {
|
|
15
|
+
/** Translated banner title. */
|
|
16
|
+
title: string;
|
|
17
|
+
/** Translated, user-facing reason of the scan error. */
|
|
18
|
+
message: string;
|
|
19
|
+
};
|
|
20
|
+
export type TransactionAlertValidation = {
|
|
21
|
+
/** Security validation result type, e.g. `Malicious`, `Warning` or `Benign`. */
|
|
22
|
+
type: string | null;
|
|
23
|
+
/** Provider description of the finding, used instead of the default message. */
|
|
24
|
+
description?: string | null;
|
|
25
|
+
};
|
|
26
|
+
export type TransactionAlertProps = {
|
|
27
|
+
labels: TransactionAlertLabels;
|
|
28
|
+
/** Whether the transaction scan is in flight. */
|
|
29
|
+
isFetching: boolean;
|
|
30
|
+
/** Whether the transaction scan request itself failed. */
|
|
31
|
+
isFetchError: boolean;
|
|
32
|
+
/** The scan error to show, or `null` when there is none (or it is disabled). */
|
|
33
|
+
error: TransactionAlertError | null;
|
|
34
|
+
/** The security validation to show, or `null` when there is none (or it is disabled). */
|
|
35
|
+
validation: TransactionAlertValidation | null;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Renders the single top-of-screen transaction scan banner.
|
|
39
|
+
*
|
|
40
|
+
* Exactly one banner is rendered, picked in this order:
|
|
41
|
+
*
|
|
42
|
+
* 1. `isFetching` → "scan in progress" info banner.
|
|
43
|
+
* 2. `isFetchError` → "scan failed" danger banner.
|
|
44
|
+
* 3. `error` → warning banner with the error title and message.
|
|
45
|
+
* 4. `Malicious` or `Warning` validation → security banner with a link to the
|
|
46
|
+
* security alerts documentation and the Blockaid attribution.
|
|
47
|
+
* 5. Otherwise nothing.
|
|
48
|
+
*
|
|
49
|
+
* @param props - The component props.
|
|
50
|
+
* @param props.labels - The translated labels.
|
|
51
|
+
* @param props.isFetching - Whether the transaction scan is in flight.
|
|
52
|
+
* @param props.isFetchError - Whether the transaction scan request failed.
|
|
53
|
+
* @param props.error - The scan error to show.
|
|
54
|
+
* @param props.validation - The security validation to show.
|
|
55
|
+
* @returns The banner, or `null` when no alert applies.
|
|
56
|
+
*/
|
|
57
|
+
export declare const TransactionAlert: ({ labels, isFetching, isFetchError, error, validation, }: TransactionAlertProps) => ComponentOrElement | null;
|
|
58
|
+
//# sourceMappingURL=TransactionAlert.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactionAlert.d.cts","sourceRoot":"","sources":["../../../src/ui/TransactionAlert/TransactionAlert.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,4BAA4B;AAI9D,MAAM,MAAM,sBAAsB,GAAG;IACnC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,gFAAgF;IAChF,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,gFAAgF;IAChF,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,sBAAsB,CAAC;IAC/B,iDAAiD;IACjD,UAAU,EAAE,OAAO,CAAC;IACpB,0DAA0D;IAC1D,YAAY,EAAE,OAAO,CAAC;IACtB,gFAAgF;IAChF,KAAK,EAAE,qBAAqB,GAAG,IAAI,CAAC;IACpC,yFAAyF;IACzF,UAAU,EAAE,0BAA0B,GAAG,IAAI,CAAC;CAC/C,CAAC;AA8CF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,gBAAgB,GAAI,0DAM9B,qBAAqB,KAAG,kBAAkB,GAAG,IA2C/C,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ComponentOrElement } from "@metamask/snaps-sdk";
|
|
2
|
+
export type TransactionAlertLabels = {
|
|
3
|
+
scanInProgressTitle: string;
|
|
4
|
+
scanInProgressMessage: string;
|
|
5
|
+
scanFailedTitle: string;
|
|
6
|
+
scanFailedMessage: string;
|
|
7
|
+
maliciousTitle: string;
|
|
8
|
+
maliciousMessage: string;
|
|
9
|
+
warningTitle: string;
|
|
10
|
+
warningMessage: string;
|
|
11
|
+
learnMore: string;
|
|
12
|
+
securityAdvisedBy: string;
|
|
13
|
+
};
|
|
14
|
+
export type TransactionAlertError = {
|
|
15
|
+
/** Translated banner title. */
|
|
16
|
+
title: string;
|
|
17
|
+
/** Translated, user-facing reason of the scan error. */
|
|
18
|
+
message: string;
|
|
19
|
+
};
|
|
20
|
+
export type TransactionAlertValidation = {
|
|
21
|
+
/** Security validation result type, e.g. `Malicious`, `Warning` or `Benign`. */
|
|
22
|
+
type: string | null;
|
|
23
|
+
/** Provider description of the finding, used instead of the default message. */
|
|
24
|
+
description?: string | null;
|
|
25
|
+
};
|
|
26
|
+
export type TransactionAlertProps = {
|
|
27
|
+
labels: TransactionAlertLabels;
|
|
28
|
+
/** Whether the transaction scan is in flight. */
|
|
29
|
+
isFetching: boolean;
|
|
30
|
+
/** Whether the transaction scan request itself failed. */
|
|
31
|
+
isFetchError: boolean;
|
|
32
|
+
/** The scan error to show, or `null` when there is none (or it is disabled). */
|
|
33
|
+
error: TransactionAlertError | null;
|
|
34
|
+
/** The security validation to show, or `null` when there is none (or it is disabled). */
|
|
35
|
+
validation: TransactionAlertValidation | null;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Renders the single top-of-screen transaction scan banner.
|
|
39
|
+
*
|
|
40
|
+
* Exactly one banner is rendered, picked in this order:
|
|
41
|
+
*
|
|
42
|
+
* 1. `isFetching` → "scan in progress" info banner.
|
|
43
|
+
* 2. `isFetchError` → "scan failed" danger banner.
|
|
44
|
+
* 3. `error` → warning banner with the error title and message.
|
|
45
|
+
* 4. `Malicious` or `Warning` validation → security banner with a link to the
|
|
46
|
+
* security alerts documentation and the Blockaid attribution.
|
|
47
|
+
* 5. Otherwise nothing.
|
|
48
|
+
*
|
|
49
|
+
* @param props - The component props.
|
|
50
|
+
* @param props.labels - The translated labels.
|
|
51
|
+
* @param props.isFetching - Whether the transaction scan is in flight.
|
|
52
|
+
* @param props.isFetchError - Whether the transaction scan request failed.
|
|
53
|
+
* @param props.error - The scan error to show.
|
|
54
|
+
* @param props.validation - The security validation to show.
|
|
55
|
+
* @returns The banner, or `null` when no alert applies.
|
|
56
|
+
*/
|
|
57
|
+
export declare const TransactionAlert: ({ labels, isFetching, isFetchError, error, validation, }: TransactionAlertProps) => ComponentOrElement | null;
|
|
58
|
+
//# sourceMappingURL=TransactionAlert.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactionAlert.d.mts","sourceRoot":"","sources":["../../../src/ui/TransactionAlert/TransactionAlert.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,4BAA4B;AAI9D,MAAM,MAAM,sBAAsB,GAAG;IACnC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,gFAAgF;IAChF,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,gFAAgF;IAChF,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,sBAAsB,CAAC;IAC/B,iDAAiD;IACjD,UAAU,EAAE,OAAO,CAAC;IACpB,0DAA0D;IAC1D,YAAY,EAAE,OAAO,CAAC;IACtB,gFAAgF;IAChF,KAAK,EAAE,qBAAqB,GAAG,IAAI,CAAC;IACpC,yFAAyF;IACzF,UAAU,EAAE,0BAA0B,GAAG,IAAI,CAAC;CAC/C,CAAC;AA8CF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,gBAAgB,GAAI,0DAM9B,qBAAqB,KAAG,kBAAkB,GAAG,IA2C/C,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@metamask/snaps-sdk/jsx-runtime";
|
|
2
|
+
import { Banner, Icon, Link, Text as SnapText } from "@metamask/snaps-sdk/jsx";
|
|
3
|
+
const SECURITY_ALERTS_URL = 'https://support.metamask.io/configure/wallet/how-to-turn-on-security-alerts/';
|
|
4
|
+
const BLOCKAID_URL = 'https://www.blockaid.io';
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the security banner for a validation result.
|
|
7
|
+
*
|
|
8
|
+
* @param validation - The security validation result.
|
|
9
|
+
* @param labels - The translated labels.
|
|
10
|
+
* @returns The banner severity, title and message, or `null` when the
|
|
11
|
+
* validation does not warrant a banner.
|
|
12
|
+
*/
|
|
13
|
+
function getValidationAlert(validation, labels) {
|
|
14
|
+
const trimmedDescription = validation.description?.trim();
|
|
15
|
+
const description = trimmedDescription === '' ? undefined : trimmedDescription;
|
|
16
|
+
if (validation.type === 'Malicious') {
|
|
17
|
+
return {
|
|
18
|
+
severity: 'danger',
|
|
19
|
+
title: labels.maliciousTitle,
|
|
20
|
+
message: description ?? labels.maliciousMessage,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (validation.type === 'Warning') {
|
|
24
|
+
return {
|
|
25
|
+
severity: 'warning',
|
|
26
|
+
title: labels.warningTitle,
|
|
27
|
+
message: description ?? labels.warningMessage,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Renders the single top-of-screen transaction scan banner.
|
|
34
|
+
*
|
|
35
|
+
* Exactly one banner is rendered, picked in this order:
|
|
36
|
+
*
|
|
37
|
+
* 1. `isFetching` → "scan in progress" info banner.
|
|
38
|
+
* 2. `isFetchError` → "scan failed" danger banner.
|
|
39
|
+
* 3. `error` → warning banner with the error title and message.
|
|
40
|
+
* 4. `Malicious` or `Warning` validation → security banner with a link to the
|
|
41
|
+
* security alerts documentation and the Blockaid attribution.
|
|
42
|
+
* 5. Otherwise nothing.
|
|
43
|
+
*
|
|
44
|
+
* @param props - The component props.
|
|
45
|
+
* @param props.labels - The translated labels.
|
|
46
|
+
* @param props.isFetching - Whether the transaction scan is in flight.
|
|
47
|
+
* @param props.isFetchError - Whether the transaction scan request failed.
|
|
48
|
+
* @param props.error - The scan error to show.
|
|
49
|
+
* @param props.validation - The security validation to show.
|
|
50
|
+
* @returns The banner, or `null` when no alert applies.
|
|
51
|
+
*/
|
|
52
|
+
export const TransactionAlert = ({ labels, isFetching, isFetchError, error, validation, }) => {
|
|
53
|
+
if (isFetching) {
|
|
54
|
+
return (_jsx(Banner, { title: labels.scanInProgressTitle, severity: "info", children: _jsx(SnapText, { children: labels.scanInProgressMessage }) }));
|
|
55
|
+
}
|
|
56
|
+
if (isFetchError) {
|
|
57
|
+
return (_jsx(Banner, { title: labels.scanFailedTitle, severity: "danger", children: _jsx(SnapText, { children: labels.scanFailedMessage }) }));
|
|
58
|
+
}
|
|
59
|
+
if (error) {
|
|
60
|
+
return (_jsx(Banner, { title: error.title, severity: "warning", children: _jsx(SnapText, { children: error.message }) }));
|
|
61
|
+
}
|
|
62
|
+
const alert = validation ? getValidationAlert(validation, labels) : null;
|
|
63
|
+
if (!alert) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return (_jsxs(Banner, { title: alert.title, severity: alert.severity, children: [_jsx(SnapText, { children: alert.message }), _jsx(SnapText, { size: "sm", children: _jsx(Link, { href: SECURITY_ALERTS_URL, children: labels.learnMore }) }), _jsxs(SnapText, { size: "sm", children: [_jsx(Icon, { color: "primary", name: "security-tick" }), " ", labels.securityAdvisedBy, ' ', _jsx(Link, { href: BLOCKAID_URL, children: "Blockaid" })] })] }));
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=TransactionAlert.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactionAlert.mjs","sourceRoot":"","sources":["../../../src/ui/TransactionAlert/TransactionAlert.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,IAAI,QAAQ,EAAE,gCAAgC;AA0C/E,MAAM,mBAAmB,GACvB,8EAA8E,CAAC;AAEjF,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAE/C;;;;;;;GA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EAAE,CAAC;QACV,OAAO,CACL,KAAC,MAAM,IAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAC,SAAS,YAC5C,KAAC,QAAQ,cAAE,KAAK,CAAC,OAAO,GAAY,GAC7B,CACV,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEzE,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,MAAC,MAAM,IAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,aAClD,KAAC,QAAQ,cAAE,KAAK,CAAC,OAAO,GAAY,EACpC,KAAC,QAAQ,IAAC,IAAI,EAAC,IAAI,YACjB,KAAC,IAAI,IAAC,IAAI,EAAE,mBAAmB,YAAG,MAAM,CAAC,SAAS,GAAQ,GACjD,EACX,MAAC,QAAQ,IAAC,IAAI,EAAC,IAAI,aACjB,KAAC,IAAI,IAAC,KAAK,EAAC,SAAS,EAAC,IAAI,EAAC,eAAe,GAAG,OAAE,MAAM,CAAC,iBAAiB,EAAE,GAAG,EAC5E,KAAC,IAAI,IAAC,IAAI,EAAE,YAAY,yBAAiB,IAChC,IACJ,CACV,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { ComponentOrElement } from '@metamask/snaps-sdk';\nimport { Banner, Icon, Link, Text as SnapText } from '@metamask/snaps-sdk/jsx';\nimport type { BannerProps } from '@metamask/snaps-sdk/jsx';\n\nexport type TransactionAlertLabels = {\n scanInProgressTitle: string;\n scanInProgressMessage: string;\n scanFailedTitle: string;\n scanFailedMessage: string;\n maliciousTitle: string;\n maliciousMessage: string;\n warningTitle: string;\n warningMessage: string;\n learnMore: string;\n securityAdvisedBy: string;\n};\n\nexport type TransactionAlertError = {\n /** Translated banner title. */\n title: string;\n /** Translated, user-facing reason of the scan error. */\n message: string;\n};\n\nexport type TransactionAlertValidation = {\n /** Security validation result type, e.g. `Malicious`, `Warning` or `Benign`. */\n type: string | null;\n /** Provider description of the finding, used instead of the default message. */\n description?: string | null;\n};\n\nexport type TransactionAlertProps = {\n labels: TransactionAlertLabels;\n /** Whether the transaction scan is in flight. */\n isFetching: boolean;\n /** Whether the transaction scan request itself failed. */\n isFetchError: boolean;\n /** The scan error to show, or `null` when there is none (or it is disabled). */\n error: TransactionAlertError | null;\n /** The security validation to show, or `null` when there is none (or it is disabled). */\n validation: TransactionAlertValidation | null;\n};\n\nconst SECURITY_ALERTS_URL =\n 'https://support.metamask.io/configure/wallet/how-to-turn-on-security-alerts/';\n\nconst BLOCKAID_URL = 'https://www.blockaid.io';\n\n/**\n * Resolves the security banner for a validation result.\n *\n * @param validation - The security validation result.\n * @param labels - The translated labels.\n * @returns The banner severity, title and message, or `null` when the\n * validation does not warrant a banner.\n */\nfunction getValidationAlert(\n validation: TransactionAlertValidation,\n labels: TransactionAlertLabels,\n): {\n severity: BannerProps['severity'];\n title: string;\n message: string;\n} | null {\n const trimmedDescription = validation.description?.trim();\n const description =\n trimmedDescription === '' ? undefined : trimmedDescription;\n\n if (validation.type === 'Malicious') {\n return {\n severity: 'danger',\n title: labels.maliciousTitle,\n message: description ?? labels.maliciousMessage,\n };\n }\n\n if (validation.type === 'Warning') {\n return {\n severity: 'warning',\n title: labels.warningTitle,\n message: description ?? labels.warningMessage,\n };\n }\n\n return null;\n}\n\n/**\n * Renders the single top-of-screen transaction scan banner.\n *\n * Exactly one banner is rendered, picked in this order:\n *\n * 1. `isFetching` → \"scan in progress\" info banner.\n * 2. `isFetchError` → \"scan failed\" danger banner.\n * 3. `error` → warning banner with the error title and message.\n * 4. `Malicious` or `Warning` validation → security banner with a link to the\n * security alerts documentation and the Blockaid attribution.\n * 5. Otherwise nothing.\n *\n * @param props - The component props.\n * @param props.labels - The translated labels.\n * @param props.isFetching - Whether the transaction scan is in flight.\n * @param props.isFetchError - Whether the transaction scan request failed.\n * @param props.error - The scan error to show.\n * @param props.validation - The security validation to show.\n * @returns The banner, or `null` when no alert applies.\n */\nexport const TransactionAlert = ({\n labels,\n isFetching,\n isFetchError,\n error,\n validation,\n}: TransactionAlertProps): ComponentOrElement | null => {\n if (isFetching) {\n return (\n <Banner title={labels.scanInProgressTitle} severity=\"info\">\n <SnapText>{labels.scanInProgressMessage}</SnapText>\n </Banner>\n );\n }\n\n if (isFetchError) {\n return (\n <Banner title={labels.scanFailedTitle} severity=\"danger\">\n <SnapText>{labels.scanFailedMessage}</SnapText>\n </Banner>\n );\n }\n\n if (error) {\n return (\n <Banner title={error.title} severity=\"warning\">\n <SnapText>{error.message}</SnapText>\n </Banner>\n );\n }\n\n const alert = validation ? getValidationAlert(validation, labels) : null;\n\n if (!alert) {\n return null;\n }\n\n return (\n <Banner title={alert.title} severity={alert.severity}>\n <SnapText>{alert.message}</SnapText>\n <SnapText size=\"sm\">\n <Link href={SECURITY_ALERTS_URL}>{labels.learnMore}</Link>\n </SnapText>\n <SnapText size=\"sm\">\n <Icon color=\"primary\" name=\"security-tick\" /> {labels.securityAdvisedBy}{' '}\n <Link href={BLOCKAID_URL}>Blockaid</Link>\n </SnapText>\n </Banner>\n );\n};\n"]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chunks = chunks;
|
|
4
|
+
exports.batchesAll = batchesAll;
|
|
5
|
+
exports.batchesAllSettled = batchesAllSettled;
|
|
6
|
+
exports.batchesAllSettledWithChunks = batchesAllSettledWithChunks;
|
|
7
|
+
exports.batchesAllWithChunks = batchesAllWithChunks;
|
|
8
|
+
/**
|
|
9
|
+
* Splits items into chunks of a given size.
|
|
10
|
+
*
|
|
11
|
+
* @param items - Input items; order is preserved in the returned chunks.
|
|
12
|
+
* @param chunkSize - Size of each chunk (must be ≥ 1).
|
|
13
|
+
* @returns An array of chunks, each containing `chunkSize` items.
|
|
14
|
+
*/
|
|
15
|
+
function chunks(items, chunkSize) {
|
|
16
|
+
if (chunkSize < 1) {
|
|
17
|
+
throw new RangeError('chunkSize must be at least 1');
|
|
18
|
+
}
|
|
19
|
+
const itemsChunks = [];
|
|
20
|
+
for (let index = 0; index < items.length; index += chunkSize) {
|
|
21
|
+
itemsChunks.push(items.slice(index, index + chunkSize));
|
|
22
|
+
}
|
|
23
|
+
return itemsChunks;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Runs async work on items in fixed-size waves, using {@link Promise.all} per wave.
|
|
27
|
+
* The next wave starts only after the current wave completes; any rejection fails the whole call.
|
|
28
|
+
*
|
|
29
|
+
* @param items - Input items; order is preserved in the returned results.
|
|
30
|
+
* @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
|
|
31
|
+
* @param mapper - Async function for each item; receives the global index in `items`.
|
|
32
|
+
* @returns One result per item, in the same order as `items`.
|
|
33
|
+
*/
|
|
34
|
+
async function batchesAll(items, batchSize, mapper) {
|
|
35
|
+
if (batchSize < 1) {
|
|
36
|
+
throw new RangeError('batchSize must be at least 1');
|
|
37
|
+
}
|
|
38
|
+
const results = [];
|
|
39
|
+
for (let index = 0; index < items.length; index += batchSize) {
|
|
40
|
+
const batch = items.slice(index, index + batchSize);
|
|
41
|
+
const batchResults = await Promise.all(batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)));
|
|
42
|
+
results.push(...batchResults);
|
|
43
|
+
}
|
|
44
|
+
return results;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Runs async work on items in fixed-size waves, using {@link Promise.allSettled} per wave.
|
|
48
|
+
* The next wave starts only after the current one settles, limiting concurrency to `batchSize`.
|
|
49
|
+
*
|
|
50
|
+
* @param items - Input items; order is preserved in the returned results.
|
|
51
|
+
* @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
|
|
52
|
+
* @param mapper - Async function for each item; receives the global index in `items`.
|
|
53
|
+
* @returns One settled result per item, in the same order as `items`.
|
|
54
|
+
*/
|
|
55
|
+
async function batchesAllSettled(items, batchSize, mapper) {
|
|
56
|
+
if (batchSize < 1) {
|
|
57
|
+
throw new RangeError('batchSize must be at least 1');
|
|
58
|
+
}
|
|
59
|
+
const results = [];
|
|
60
|
+
for (let index = 0; index < items.length; index += batchSize) {
|
|
61
|
+
const batch = items.slice(index, index + batchSize);
|
|
62
|
+
const settled = await Promise.allSettled(batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)));
|
|
63
|
+
results.push(...settled);
|
|
64
|
+
}
|
|
65
|
+
return results;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAllSettled} on those chunks.
|
|
69
|
+
* Each mapper call receives one chunk; settled results are in chunk order (same order as {@link chunks}).
|
|
70
|
+
*
|
|
71
|
+
* @param items - Flat input items.
|
|
72
|
+
* @param chunkSize - Items per chunk (must be ≥ 1).
|
|
73
|
+
* @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
|
|
74
|
+
* @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
|
|
75
|
+
* @returns One settled result per chunk.
|
|
76
|
+
*/
|
|
77
|
+
async function batchesAllSettledWithChunks(items, chunkSize, batchSize, mapper) {
|
|
78
|
+
const itemChunks = chunks(items, chunkSize);
|
|
79
|
+
return batchesAllSettled(itemChunks, batchSize, async (chunk, chunkIndex) => mapper(chunk, chunkIndex));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAll} on those chunks.
|
|
83
|
+
* Each mapper call receives one chunk; results are in chunk order (same order as {@link chunks}).
|
|
84
|
+
*
|
|
85
|
+
* @param items - Flat input items.
|
|
86
|
+
* @param chunkSize - Items per chunk (must be ≥ 1).
|
|
87
|
+
* @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
|
|
88
|
+
* @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
|
|
89
|
+
* @returns One result per chunk.
|
|
90
|
+
*/
|
|
91
|
+
async function batchesAllWithChunks(items, chunkSize, batchSize, mapper) {
|
|
92
|
+
const itemChunks = chunks(items, chunkSize);
|
|
93
|
+
return batchesAll(itemChunks, batchSize, async (chunk, chunkIndex) => mapper(chunk, chunkIndex));
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=async.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.cjs","sourceRoot":"","sources":["../../../src/utils/async/async.ts"],"names":[],"mappings":";;AAOA,wBAaC;AAWD,gCAoBC;AAWD,8CAoBC;AAYD,kEAUC;AAYD,oDAUC;AA9HD;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,KAAuB,EACvB,SAAiB;IAEjB,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,UAAU,CAAC,8BAA8B,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,WAAW,GAAc,EAAE,CAAC;IAClC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,SAAS,EAAE,CAAC;QAC7D,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,UAAU,CAC9B,KAAuB,EACvB,SAAiB,EACjB,MAAwD;IAExD,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,UAAU,CAAC,8BAA8B,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,OAAO,GAAc,EAAE,CAAC;IAE9B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EA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AAgE;IAEhE,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC5C,OAAO,iBAAiB,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CAC1E,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,oBAAoB,CACxC,KAAuB,EACvB,SAAiB,EACjB,SAAiB,EACjB,MAAgE;IAEhE,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC5C,OAAO,UAAU,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CACnE,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAC1B,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Splits items into chunks of a given size.\n *\n * @param items - Input items; order is preserved in the returned chunks.\n * @param chunkSize - Size of each chunk (must be ≥ 1).\n * @returns An array of chunks, each containing `chunkSize` items.\n */\nexport function chunks<TItem>(\n items: readonly TItem[],\n chunkSize: number,\n): TItem[][] {\n if (chunkSize < 1) {\n throw new RangeError('chunkSize must be at least 1');\n }\n\n const itemsChunks: TItem[][] = [];\n for (let index = 0; index < items.length; index += chunkSize) {\n itemsChunks.push(items.slice(index, index + chunkSize));\n }\n return itemsChunks;\n}\n\n/**\n * Runs async work on items in fixed-size waves, using {@link Promise.all} per wave.\n * The next wave starts only after the current wave completes; any rejection fails the whole call.\n *\n * @param items - Input items; order is preserved in the returned results.\n * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).\n * @param mapper - Async function for each item; receives the global index in `items`.\n * @returns One result per item, in the same order as `items`.\n */\nexport async function batchesAll<TItem, TResult>(\n items: readonly TItem[],\n batchSize: number,\n mapper: (item: TItem, index: number) => Promise<TResult>,\n): Promise<TResult[]> {\n if (batchSize < 1) {\n throw new RangeError('batchSize must be at least 1');\n }\n\n const results: TResult[] = [];\n\n for (let index = 0; index < items.length; index += batchSize) {\n const batch = items.slice(index, index + batchSize);\n const batchResults = await Promise.all(\n batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)),\n );\n results.push(...batchResults);\n }\n\n return results;\n}\n\n/**\n * Runs async work on items in fixed-size waves, using {@link Promise.allSettled} per wave.\n * The next wave starts only after the current one settles, limiting concurrency to `batchSize`.\n *\n * @param items - Input items; order is preserved in the returned results.\n * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).\n * @param mapper - Async function for each item; receives the global index in `items`.\n * @returns One settled result per item, in the same order as `items`.\n */\nexport async function batchesAllSettled<TItem, TResult>(\n items: readonly TItem[],\n batchSize: number,\n mapper: (item: TItem, index: number) => Promise<TResult>,\n): Promise<PromiseSettledResult<TResult>[]> {\n if (batchSize < 1) {\n throw new RangeError('batchSize must be at least 1');\n }\n\n const results: PromiseSettledResult<TResult>[] = [];\n\n for (let index = 0; index < items.length; index += batchSize) {\n const batch = items.slice(index, index + batchSize);\n const settled = await Promise.allSettled(\n batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)),\n );\n results.push(...settled);\n }\n\n return results;\n}\n\n/**\n * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAllSettled} on those chunks.\n * Each mapper call receives one chunk; settled results are in chunk order (same order as {@link chunks}).\n *\n * @param items - Flat input items.\n * @param chunkSize - Items per chunk (must be ≥ 1).\n * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).\n * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).\n * @returns One settled result per chunk.\n */\nexport async function batchesAllSettledWithChunks<TItem, TResult>(\n items: readonly TItem[],\n chunkSize: number,\n batchSize: number,\n mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>,\n): Promise<PromiseSettledResult<TResult>[]> {\n const itemChunks = chunks(items, chunkSize);\n return batchesAllSettled(itemChunks, batchSize, async (chunk, chunkIndex) =>\n mapper(chunk, chunkIndex),\n );\n}\n\n/**\n * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAll} on those chunks.\n * Each mapper call receives one chunk; results are in chunk order (same order as {@link chunks}).\n *\n * @param items - Flat input items.\n * @param chunkSize - Items per chunk (must be ≥ 1).\n * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).\n * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).\n * @returns One result per chunk.\n */\nexport async function batchesAllWithChunks<TItem, TResult>(\n items: readonly TItem[],\n chunkSize: number,\n batchSize: number,\n mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>,\n): Promise<TResult[]> {\n const itemChunks = chunks(items, chunkSize);\n return batchesAll(itemChunks, batchSize, async (chunk, chunkIndex) =>\n mapper(chunk, chunkIndex),\n );\n}\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits items into chunks of a given size.
|
|
3
|
+
*
|
|
4
|
+
* @param items - Input items; order is preserved in the returned chunks.
|
|
5
|
+
* @param chunkSize - Size of each chunk (must be ≥ 1).
|
|
6
|
+
* @returns An array of chunks, each containing `chunkSize` items.
|
|
7
|
+
*/
|
|
8
|
+
export declare function chunks<TItem>(items: readonly TItem[], chunkSize: number): TItem[][];
|
|
9
|
+
/**
|
|
10
|
+
* Runs async work on items in fixed-size waves, using {@link Promise.all} per wave.
|
|
11
|
+
* The next wave starts only after the current wave completes; any rejection fails the whole call.
|
|
12
|
+
*
|
|
13
|
+
* @param items - Input items; order is preserved in the returned results.
|
|
14
|
+
* @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
|
|
15
|
+
* @param mapper - Async function for each item; receives the global index in `items`.
|
|
16
|
+
* @returns One result per item, in the same order as `items`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function batchesAll<TItem, TResult>(items: readonly TItem[], batchSize: number, mapper: (item: TItem, index: number) => Promise<TResult>): Promise<TResult[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Runs async work on items in fixed-size waves, using {@link Promise.allSettled} per wave.
|
|
21
|
+
* The next wave starts only after the current one settles, limiting concurrency to `batchSize`.
|
|
22
|
+
*
|
|
23
|
+
* @param items - Input items; order is preserved in the returned results.
|
|
24
|
+
* @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
|
|
25
|
+
* @param mapper - Async function for each item; receives the global index in `items`.
|
|
26
|
+
* @returns One settled result per item, in the same order as `items`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function batchesAllSettled<TItem, TResult>(items: readonly TItem[], batchSize: number, mapper: (item: TItem, index: number) => Promise<TResult>): Promise<PromiseSettledResult<TResult>[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAllSettled} on those chunks.
|
|
31
|
+
* Each mapper call receives one chunk; settled results are in chunk order (same order as {@link chunks}).
|
|
32
|
+
*
|
|
33
|
+
* @param items - Flat input items.
|
|
34
|
+
* @param chunkSize - Items per chunk (must be ≥ 1).
|
|
35
|
+
* @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
|
|
36
|
+
* @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
|
|
37
|
+
* @returns One settled result per chunk.
|
|
38
|
+
*/
|
|
39
|
+
export declare function batchesAllSettledWithChunks<TItem, TResult>(items: readonly TItem[], chunkSize: number, batchSize: number, mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>): Promise<PromiseSettledResult<TResult>[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAll} on those chunks.
|
|
42
|
+
* Each mapper call receives one chunk; results are in chunk order (same order as {@link chunks}).
|
|
43
|
+
*
|
|
44
|
+
* @param items - Flat input items.
|
|
45
|
+
* @param chunkSize - Items per chunk (must be ≥ 1).
|
|
46
|
+
* @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
|
|
47
|
+
* @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
|
|
48
|
+
* @returns One result per chunk.
|
|
49
|
+
*/
|
|
50
|
+
export declare function batchesAllWithChunks<TItem, TResult>(items: readonly TItem[], chunkSize: number, batchSize: number, mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>): Promise<TResult[]>;
|
|
51
|
+
//# sourceMappingURL=async.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.d.cts","sourceRoot":"","sources":["../../../src/utils/async/async.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAC1B,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,GAChB,KAAK,EAAE,EAAE,CAUX;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,OAAO,EAC7C,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GACvD,OAAO,CAAC,OAAO,EAAE,CAAC,CAgBpB;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EACpD,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GACvD,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAgB1C;AAED;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAC9D,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAC/D,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAK1C;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EACvD,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAC/D,OAAO,CAAC,OAAO,EAAE,CAAC,CAKpB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits items into chunks of a given size.
|
|
3
|
+
*
|
|
4
|
+
* @param items - Input items; order is preserved in the returned chunks.
|
|
5
|
+
* @param chunkSize - Size of each chunk (must be ≥ 1).
|
|
6
|
+
* @returns An array of chunks, each containing `chunkSize` items.
|
|
7
|
+
*/
|
|
8
|
+
export declare function chunks<TItem>(items: readonly TItem[], chunkSize: number): TItem[][];
|
|
9
|
+
/**
|
|
10
|
+
* Runs async work on items in fixed-size waves, using {@link Promise.all} per wave.
|
|
11
|
+
* The next wave starts only after the current wave completes; any rejection fails the whole call.
|
|
12
|
+
*
|
|
13
|
+
* @param items - Input items; order is preserved in the returned results.
|
|
14
|
+
* @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
|
|
15
|
+
* @param mapper - Async function for each item; receives the global index in `items`.
|
|
16
|
+
* @returns One result per item, in the same order as `items`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function batchesAll<TItem, TResult>(items: readonly TItem[], batchSize: number, mapper: (item: TItem, index: number) => Promise<TResult>): Promise<TResult[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Runs async work on items in fixed-size waves, using {@link Promise.allSettled} per wave.
|
|
21
|
+
* The next wave starts only after the current one settles, limiting concurrency to `batchSize`.
|
|
22
|
+
*
|
|
23
|
+
* @param items - Input items; order is preserved in the returned results.
|
|
24
|
+
* @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
|
|
25
|
+
* @param mapper - Async function for each item; receives the global index in `items`.
|
|
26
|
+
* @returns One settled result per item, in the same order as `items`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function batchesAllSettled<TItem, TResult>(items: readonly TItem[], batchSize: number, mapper: (item: TItem, index: number) => Promise<TResult>): Promise<PromiseSettledResult<TResult>[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAllSettled} on those chunks.
|
|
31
|
+
* Each mapper call receives one chunk; settled results are in chunk order (same order as {@link chunks}).
|
|
32
|
+
*
|
|
33
|
+
* @param items - Flat input items.
|
|
34
|
+
* @param chunkSize - Items per chunk (must be ≥ 1).
|
|
35
|
+
* @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
|
|
36
|
+
* @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
|
|
37
|
+
* @returns One settled result per chunk.
|
|
38
|
+
*/
|
|
39
|
+
export declare function batchesAllSettledWithChunks<TItem, TResult>(items: readonly TItem[], chunkSize: number, batchSize: number, mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>): Promise<PromiseSettledResult<TResult>[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAll} on those chunks.
|
|
42
|
+
* Each mapper call receives one chunk; results are in chunk order (same order as {@link chunks}).
|
|
43
|
+
*
|
|
44
|
+
* @param items - Flat input items.
|
|
45
|
+
* @param chunkSize - Items per chunk (must be ≥ 1).
|
|
46
|
+
* @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
|
|
47
|
+
* @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
|
|
48
|
+
* @returns One result per chunk.
|
|
49
|
+
*/
|
|
50
|
+
export declare function batchesAllWithChunks<TItem, TResult>(items: readonly TItem[], chunkSize: number, batchSize: number, mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>): Promise<TResult[]>;
|
|
51
|
+
//# sourceMappingURL=async.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.d.mts","sourceRoot":"","sources":["../../../src/utils/async/async.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAC1B,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,GAChB,KAAK,EAAE,EAAE,CAUX;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,OAAO,EAC7C,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GACvD,OAAO,CAAC,OAAO,EAAE,CAAC,CAgBpB;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EACpD,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GACvD,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAgB1C;AAED;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAC9D,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAC/D,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAK1C;AAED;;;;;;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