The personal finance app for everyone (by everyone)
Ruby
feat(mobile): add SureCard primitive and migrate account cards (#2370)
ghost56000d783479
diff --git a/app/models/coinstats_item/importer.rb b/app/models/coinstats_item/importer.rbindex b8fec52094..220b69d2a2 100644--- a/app/models/coinstats_item/importer.rb+++ b/app/models/coinstats_item/importer.rb@@ -145,8 +145,13 @@ class CoinstatsItem::Importerreturn [] if wallets.empty?Rails.logger.info "CoinstatsItem::Importer - Fetching balances for #{wallets.size} wallet(s) via bulk endpoint"- # Build comma-separated string in format "blockchain:address"- wallets_param = wallets.map { |w| "#{w[:blockchain]}:#{w[:address]}" }.join(",")+ # Build comma-separated string in format "blockchain:address". Sort for a+ # deterministic batch order so the request is stable regardless of the+ # account query order (otherwise the bulk-endpoint param varies run to run).+ wallets_param = wallets+ .sort_by { |w| "#{w[:blockchain]}:#{w[:address]}".downcase }+ .map { |w| "#{w[:blockchain]}:#{w[:address]}" }+ .join(",")response = coinstats_provider.get_wallet_balances(wallets_param)response.success? ? response.data : FETCH_FAILEDrescue => e@@ -192,8 +197,13 @@ class CoinstatsItem::Importerreturn [] if wallets.empty?Rails.logger.info "CoinstatsItem::Importer - Fetching transactions for #{wallets.size} wallet(s) via bulk endpoint"- # Build comma-separated string in format "blockchain:address"- wallets_param = wallets.map { |w| "#{w[:blockchain]}:#{w[:address]}" }.join(",")+ # Build comma-separated string in format "blockchain:address". Sort for a+ # deterministic batch order so the request is stable regardless of the+ # account query order (otherwise the bulk-endpoint param varies run to run).+ wallets_param = wallets+ .sort_by { |w| "#{w[:blockchain]}:#{w[:address]}".downcase }+ .map { |w| "#{w[:blockchain]}:#{w[:address]}" }+ .join(",")response = coinstats_provider.get_wallet_transactions(wallets_param)response.success? ? response.data : FETCH_FAILEDrescue => ediff --git a/mobile/lib/widgets/account_card.dart b/mobile/lib/widgets/account_card.dartindex cc070ab757..bb8e131373 100644--- a/mobile/lib/widgets/account_card.dart+++ b/mobile/lib/widgets/account_card.dart@@ -1,7 +1,9 @@import 'package:flutter/material.dart';import '../models/account.dart';import '../theme/sure_colors.dart';+import '../theme/sure_tokens.dart';import 'money_text.dart';+import 'sure_card.dart';import 'sure_icon.dart';class AccountCard extends StatelessWidget {@@ -43,7 +45,7 @@ class AccountCard extends StatelessWidget {Color _getAccountColor(BuildContext context) {final colorScheme = Theme.of(context).colorScheme;-+if (account.isAsset) {return SureColors.of(context).palette.success;} else if (account.isLiability) {@@ -57,82 +59,76 @@ class AccountCard extends StatelessWidget {final colorScheme = Theme.of(context).colorScheme;final accountColor = _getAccountColor(context);- final cardContent = Card(+ final cardContent = SureCard(margin: const EdgeInsets.only(bottom: 12),- child: InkWell(- onTap: onTap,- borderRadius: BorderRadius.circular(12),- child: Padding(- padding: const EdgeInsets.all(16),- child: Row(- children: [- // Account icon- Container(- width: 48,- height: 48,- decoration: BoxDecoration(- color: accountColor.withValues(alpha: 0.1),- borderRadius: BorderRadius.circular(12),+ onTap: onTap,+ child: Row(+ children: [+ // Account icon+ Container(+ width: 48,+ height: 48,+ decoration: BoxDecoration(+ color: accountColor.withValues(alpha: 0.1),+ borderRadius: BorderRadius.circular(12),+ ),+ child: SureIcon(+ _getAccountIconName(),+ color: accountColor,+ size: SureIconSize.lg,+ ),+ ),+ const SizedBox(width: 16),++ // Account info+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ account.name,+ style: Theme.of(context).textTheme.titleMedium?.copyWith(+ fontWeight: FontWeight.w500,+ ),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,),- child: SureIcon(- _getAccountIconName(),- color: accountColor,- size: SureIconSize.lg,+ const SizedBox(height: 4),+ Text(+ account.displayAccountType,+ style: Theme.of(context).textTheme.bodySmall?.copyWith(+ color: colorScheme.onSurfaceVariant,+ ),),- ),- const SizedBox(width: 16),+ ],+ ),+ ),- // Account info- Expanded(- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Text(- account.name,- style: Theme.of(context).textTheme.titleMedium?.copyWith(- fontWeight: FontWeight.w500,- ),- maxLines: 1,- overflow: TextOverflow.ellipsis,- ),- const SizedBox(height: 4),- Text(- account.displayAccountType,- style: Theme.of(context).textTheme.bodySmall?.copyWith(- color: colorScheme.onSurfaceVariant,- ),- ),- ],+ // Balance+ Column(+ crossAxisAlignment: CrossAxisAlignment.end,+ children: [+ Text(+ account.balance,+ style: SureMoney.tabular(+ Theme.of(context).textTheme.titleMedium?.copyWith(+ fontWeight: FontWeight.w500,+ color: account.isLiability+ ? SureColors.of(context).palette.destructive+ : null,+ ),),),-- // Balance- Column(- crossAxisAlignment: CrossAxisAlignment.end,- children: [- Text(- account.balance,- style: SureMoney.tabular(- Theme.of(context).textTheme.titleMedium?.copyWith(- fontWeight: FontWeight.w500,- color: account.isLiability- ? SureColors.of(context).palette.destructive- : null,- ),- ),- ),- const SizedBox(height: 4),- Text(- account.currency,- style: Theme.of(context).textTheme.bodySmall?.copyWith(- color: colorScheme.onSurfaceVariant,- ),- ),- ],+ const SizedBox(height: 4),+ Text(+ account.currency,+ style: Theme.of(context).textTheme.bodySmall?.copyWith(+ color: colorScheme.onSurfaceVariant,+ ),),],),- ),+ ],),);@@ -152,7 +148,7 @@ class AccountCard extends StatelessWidget {padding: const EdgeInsets.only(right: 20),decoration: BoxDecoration(color: Colors.blue,- borderRadius: BorderRadius.circular(12),+ borderRadius: BorderRadius.circular(SureTokens.radiusLg),),child: const Column(mainAxisAlignment: MainAxisAlignment.center,diff --git a/mobile/lib/widgets/sure_card.dart b/mobile/lib/widgets/sure_card.dartnew file mode 100644index 0000000000..80e4e08b1a--- /dev/null+++ b/mobile/lib/widgets/sure_card.dart@@ -0,0 +1,66 @@+import 'package:flutter/material.dart';++import '../theme/sure_colors.dart';+import '../theme/sure_tokens.dart';++/// Sure design-system card — a tokenized content surface mirroring the web card+/// chrome (`bg-container` + a hairline border + rounded corners + the subtle DS+/// shadow). Use it instead of a Material [Card] so the chrome stays in lockstep+/// with `sure.tokens.json` and reads correctly in light and dark.+///+/// Colors resolve from the active [SureColors] palette (brightness-aware). When+/// [onTap] is provided the whole card is tappable, with a flat ink response+/// clipped to the card's radius.+class SureCard extends StatelessWidget {+ const SureCard({+ super.key,+ required this.child,+ this.padding = const EdgeInsets.all(16),+ this.margin,+ this.onTap,+ this.elevated = true,+ });++ final Widget child;++ /// Inner padding around [child].+ final EdgeInsetsGeometry padding;++ /// Outer spacing around the card (e.g. separation in a list).+ final EdgeInsetsGeometry? margin;++ /// When non-null, the card is tappable.+ final VoidCallback? onTap;++ /// Apply the subtle DS card shadow. Set false for cards sitting on an inset+ /// surface, where the border alone provides enough separation.+ final bool elevated;++ @override+ Widget build(BuildContext context) {+ final palette = SureColors.of(context).palette;+ final radius = BorderRadius.circular(SureTokens.radiusLg);++ Widget content = Padding(padding: padding, child: child);+ if (onTap != null) {+ // Material(transparency) gives InkWell a surface to paint on without+ // covering the card's tokenized background or border.+ content = Material(+ type: MaterialType.transparency,+ child: InkWell(onTap: onTap, borderRadius: radius, child: content),+ );+ }++ return Container(+ margin: margin,+ clipBehavior: Clip.antiAlias,+ decoration: BoxDecoration(+ color: palette.container,+ borderRadius: radius,+ border: Border.all(color: palette.borderSecondary),+ boxShadow: elevated ? palette.shadowXs : null,+ ),+ child: content,+ );+ }+}diff --git a/mobile/test/widgets/sure_card_test.dart b/mobile/test/widgets/sure_card_test.dartnew file mode 100644index 0000000000..7df369e746--- /dev/null+++ b/mobile/test/widgets/sure_card_test.dart@@ -0,0 +1,69 @@+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:sure_mobile/theme/sure_theme.dart';+import 'package:sure_mobile/theme/sure_tokens.dart';+import 'package:sure_mobile/widgets/sure_card.dart';++void main() {+ Future<void> pump(WidgetTester tester, Widget child,+ {Brightness brightness = Brightness.light}) {+ return tester.pumpWidget(+ MaterialApp(+ theme:+ brightness == Brightness.light ? SureTheme.light : SureTheme.dark,+ home: Scaffold(body: child),+ ),+ );+ }++ BoxDecoration decorationOf(WidgetTester tester) => tester+ .widget<Container>(+ find+ .descendant(of: find.byType(SureCard), matching: find.byType(Container))+ .first,+ )+ .decoration as BoxDecoration;++ // Brightness-aware by contract — assert the chrome resolves the right palette+ // in both themes so a token regression in either mode is caught.+ for (final (brightness, tokens) in [+ (Brightness.light, SureTokens.light),+ (Brightness.dark, SureTokens.dark),+ ]) {+ testWidgets('paints the Sure card chrome from tokens (${brightness.name})',+ (tester) async {+ await pump(tester, const SureCard(child: Text('Body')),+ brightness: brightness);++ final deco = decorationOf(tester);+ expect(deco.color, tokens.container);+ expect((deco.border as Border).top.color, tokens.borderSecondary);+ expect(deco.borderRadius, BorderRadius.circular(SureTokens.radiusLg));+ expect(deco.boxShadow, tokens.shadowXs);+ expect(find.text('Body'), findsOneWidget);+ });+ }++ testWidgets('elevated: false drops the shadow', (tester) async {+ await pump(tester, const SureCard(elevated: false, child: Text('Body')));+ expect(decorationOf(tester).boxShadow, isNull);+ });++ testWidgets('onTap fires and is clipped to the card (InkWell present)',+ (tester) async {+ var taps = 0;+ await pump(+ tester,+ SureCard(onTap: () => taps++, child: const Text('Tap me')),+ );+ final inkWell = tester.widget<InkWell>(find.byType(InkWell));+ expect(inkWell.borderRadius, BorderRadius.circular(SureTokens.radiusLg));+ await tester.tap(find.text('Tap me'));+ expect(taps, 1);+ });++ testWidgets('is non-interactive without onTap (no InkWell)', (tester) async {+ await pump(tester, const SureCard(child: Text('Body')));+ expect(find.byType(InkWell), findsNothing);+ });+}diff --git a/test/models/coinstats_item/importer_test.rb b/test/models/coinstats_item/importer_test.rbindex a07a7526e2..8f5e235f5b 100644--- a/test/models/coinstats_item/importer_test.rb+++ b/test/models/coinstats_item/importer_test.rb@@ -458,7 +458,7 @@ class CoinstatsItem::ImporterTest < ActiveSupport::TestCase]@mock_provider.expects(:get_wallet_balances)- .with("ethereum:0xworking,ethereum:0xfailing")+ .with("ethereum:0xfailing,ethereum:0xworking").returns(success_response(bulk_response))@mock_provider.expects(:extract_wallet_balance)@@ -475,7 +475,7 @@ class CoinstatsItem::ImporterTest < ActiveSupport::TestCase]@mock_provider.expects(:get_wallet_transactions)- .with("ethereum:0xworking,ethereum:0xfailing")+ .with("ethereum:0xfailing,ethereum:0xworking").returns(success_response(bulk_transactions_response))@mock_provider.expects(:extract_wallet_transactions)@@ -551,7 +551,7 @@ class CoinstatsItem::ImporterTest < ActiveSupport::TestCase]@mock_provider.expects(:get_wallet_balances)- .with("ethereum:0xworking,dogecoin:Ddoge123")+ .with("dogecoin:Ddoge123,ethereum:0xworking").returns(success_response(bulk_response))@mock_provider.expects(:extract_wallet_balance)@@ -568,7 +568,7 @@ class CoinstatsItem::ImporterTest < ActiveSupport::TestCase]@mock_provider.expects(:get_wallet_transactions)- .with("ethereum:0xworking,dogecoin:Ddoge123")+ .with("dogecoin:Ddoge123,ethereum:0xworking").returns(success_response(bulk_transactions_response))@mock_provider.expects(:extract_wallet_transactions)@@ -650,12 +650,12 @@ class CoinstatsItem::ImporterTest < ActiveSupport::TestCaseAccountProvider.create!(account: account2, provider: coinstats_account2)@mock_provider.expects(:get_wallet_balances)- .with("ethereum:0xeth123,dogecoin:Ddoge456")+ .with("dogecoin:Ddoge456,ethereum:0xeth123").raises(Provider::Coinstats::Error.new("CoinStats timeout"))bulk_transactions_response = []@mock_provider.expects(:get_wallet_transactions)- .with("ethereum:0xeth123,dogecoin:Ddoge456")+ .with("dogecoin:Ddoge456,ethereum:0xeth123").returns(success_response(bulk_transactions_response))assert_difference "DebugLogEntry.count", 3 do@@ -729,7 +729,7 @@ class CoinstatsItem::ImporterTest < ActiveSupport::TestCase]@mock_provider.expects(:get_wallet_balances)- .with("ethereum:0xeth123,bitcoin:bc1qbtc456")+ .with("bitcoin:bc1qbtc456,ethereum:0xeth123").returns(success_response(bulk_response))@mock_provider.expects(:extract_wallet_balance)@@ -756,7 +756,7 @@ class CoinstatsItem::ImporterTest < ActiveSupport::TestCase]@mock_provider.expects(:get_wallet_transactions)- .with("ethereum:0xeth123,bitcoin:bc1qbtc456")+ .with("bitcoin:bc1qbtc456,ethereum:0xeth123").returns(success_response(bulk_transactions_response))@mock_provider.expects(:extract_wallet_transactions)