refactor(spl): don't create separate Amount objs
What changed, and why it matters
This commit is a small code cleanup in the Stack Wallet app. It changes how zero token balances are created so that only one zero-value object is reused instead of making four separate ones. There is no visible security problem or user-facing behavior change.
No security action needed. Treat as routine code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors two Dart methods, getCachedBalance(), in token wallet info models. Previously each Balance field was initialized with Amount.zeroWith(fractionDigits: tokenFractionDigits), creating distinct Amount instances. The change creates a single Amount(rawValue: BigInt.zero, fractionDigits: tokenFractionDigits) and assigns the same reference to all four Balance fields. This is a stylistic/micro-optimization refactor. No logic, validation, or trust boundary changes are present in the diff.
Changed components
lib/wallets/isar/models/token_wallet_info.dartlib/wallets/isar/models/wallet_solana_token_info.dartInspect captured patch +16 / −8
diff --git a/lib/wallets/isar/models/token_wallet_info.dart b/lib/wallets/isar/models/token_wallet_info.dart
index 842d04b..767c5a2 100644
--- a/lib/wallets/isar/models/token_wallet_info.dart
+++ b/lib/wallets/isar/models/token_wallet_info.dart
@@ -38,11 +38,15 @@ class TokenWalletInfo implements IsarId {
// token balance cache
Balance getCachedBalance() {
if (cachedBalanceJsonString == null) {
+ final amount = Amount(
+ rawValue: BigInt.zero,
+ fractionDigits: tokenFractionDigits,
+ );
return Balance(
- total: Amount.zeroWith(fractionDigits: tokenFractionDigits),
- spendable: Amount.zeroWith(fractionDigits: tokenFractionDigits),
- blockedTotal: Amount.zeroWith(fractionDigits: tokenFractionDigits),
- pendingSpendable: Amount.zeroWith(fractionDigits: tokenFractionDigits),
+ total: amount,
+ spendable: amount,
+ blockedTotal: amount,
+ pendingSpendable: amount,
);
}
return Balance.fromJson(cachedBalanceJsonString!, tokenFractionDigits);
diff --git a/lib/wallets/isar/models/wallet_solana_token_info.dart b/lib/wallets/isar/models/wallet_solana_token_info.dart
index a80e989..16d45b1 100644
--- a/lib/wallets/isar/models/wallet_solana_token_info.dart
+++ b/lib/wallets/isar/models/wallet_solana_token_info.dart
@@ -47,11 +47,15 @@ class WalletSolanaTokenInfo implements IsarId {
// Token balance cache.
Balance getCachedBalance() {
if (cachedBalanceJsonString == null) {
+ final amount = Amount(
+ rawValue: BigInt.zero,
+ fractionDigits: tokenFractionDigits,
+ );
return Balance(
- total: Amount.zeroWith(fractionDigits: tokenFractionDigits),
- spendable: Amount.zeroWith(fractionDigits: tokenFractionDigits),
- blockedTotal: Amount.zeroWith(fractionDigits: tokenFractionDigits),
- pendingSpendable: Amount.zeroWith(fractionDigits: tokenFractionDigits),
+ total: amount,
+ spendable: amount,
+ blockedTotal: amount,
+ pendingSpendable: amount,
);
}
return Balance.fromJson(cachedBalanceJsonString!, tokenFractionDigits);
Why this scored 11/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.