feat: add balance metadata for snap datasource [DO NOT MERGE]#9564
feat: add balance metadata for snap datasource [DO NOT MERGE]#9564stanleyyconsensys wants to merge 1 commit into
Conversation
| [assetId: string]: { | ||
| amount: string; | ||
| unit: string; | ||
| metadata?: Record<string, Json>; |
There was a problem hiding this comment.
add metadata into snap balance update event payload type
There was a problem hiding this comment.
Do we want type enforced payloads?
E.g. a typed descriminated union?
There was a problem hiding this comment.
Or maybe we can enforce a schema for runtime validation & parsing?
There was a problem hiding this comment.
i think in future
some snap may still using SNAP path to sync data, those data will not able to predict
adding validation may also adding a complexity on how snap ship data to controller
and it require bump up to controller when the data sharp change..., so i will suggest leave it as this (should align with keyring API)
| accountAssets ??= {}; | ||
| accountAssets[assetId as Caip19AssetId] = { | ||
| amount: balance.amount, | ||
| ...(balance.metadata ? { metadata: balance.metadata } : {}), |
There was a problem hiding this comment.
when persist balance data via event, we persist metadata together if any
type AssetBalance already ready to store metadata
|
|
||
| // Step 2: Get balances for those specific assets | ||
| const balances: Record<CaipAssetType, Balance> = | ||
| const balances: Record<CaipAssetType, Balance & { metadata?: Json }> = |
There was a problem hiding this comment.
mock keyring type
| if (accountBalances) { | ||
| (accountBalances as Record<string, unknown>)[assetId] = { | ||
| amount: balance.amount, | ||
| ...(balance.metadata ? { metadata: balance.metadata } : {}), |
There was a problem hiding this comment.
when persist balance data via keyring API get balance, we persist metadata together if any
Prithpal-Sooriya
left a comment
There was a problem hiding this comment.
Nice mock impl!
Explanation
References
Checklist
Note
Low Risk
Additive, optional fields on balance mapping with no auth or persistence changes; behavior unchanged when metadata is absent.
Overview
Snap balance metadata is threaded through
SnapDataSourceso optional fields from the keyring are not dropped when balances reach the assets pipeline.The
AccountsController:accountBalancesUpdatedpayload type gains optionalmetadataon each balance entry. When handling that event,#handleSnapBalancesUpdatedcopiesmetadataonto eachAssetBalancewhen present. The same optional field is read fromgetAccountBalancesduringfetchand included in mergedassetsBalanceresponses.Reviewed by Cursor Bugbot for commit 2dd2694. Bugbot is set up for automated code reviews on this repo. Configure here.