improve transaction list performance (#3082)

* improve transaction list performance

* fix "no transactions" placeholder positioning

* format
This commit is contained in:
malik1004x
2026-03-14 14:31:50 +01:00
committed by GitHub
parent 9e88d4bf96
commit 2de86c80a8
11 changed files with 186 additions and 111 deletions
+9 -6
View File
@@ -144,18 +144,21 @@ class _NewHomePageState extends State<NewHomePage> {
);
},
),
],
),
),
Observer(
builder: (_) => AssetsHistorySection(
nftViewModel: widget.nftViewModel,
dashboardViewModel: widget.dashboardViewModel,
),
),
SizedBox(height: 80.0)
],
),
),]
),
Container(
SliverToBoxAdapter(
child: SizedBox(height: 80.0),
)
]),
Container(
height: (MediaQuery.of(context).padding.top),
decoration: BoxDecoration(
gradient: LinearGradient(
@@ -68,8 +68,8 @@ class _AssetsHistorySectionState extends State<AssetsHistorySection> {
@override
Widget build(BuildContext context) {
return Column(
children: [
return SliverMainAxisGroup(
slivers: [
// if(tabs.length>1)
AssetsTopBar(
dashboardViewModel: widget.dashboardViewModel,
@@ -15,45 +15,47 @@ class AssetsSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 64.0),
child: Observer(
builder: (context) {
final hasMweb = dashboardViewModel.hasMweb && dashboardViewModel.mwebEnabled;
return ListView.builder(
shrinkWrap: true,
padding: EdgeInsets.zero,
physics: NeverScrollableScrollPhysics(),
itemCount: dashboardViewModel.balanceViewModel.formattedBalances.length + (hasMweb ? 1 : 0),
itemBuilder: (context, index) {
return Observer(builder: (context) {
if (hasMweb) {
return SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(bottom: 64.0),
child: Observer(
builder: (context) {
final hasMweb = dashboardViewModel.hasMweb && dashboardViewModel.mwebEnabled;
return ListView.builder(
shrinkWrap: true,
padding: EdgeInsets.zero,
physics: NeverScrollableScrollPhysics(),
itemCount: dashboardViewModel.balanceViewModel.formattedBalances.length + (hasMweb ? 1 : 0),
itemBuilder: (context, index) {
return Observer(builder: (context) {
if (hasMweb) {
return AssetTile(
showSwap: dashboardViewModel.isEnabledSwapAction,
balance: dashboardViewModel.balanceViewModel.formattedBalances.first,
showSecondary: index > 0 ? true : false,
wallet: dashboardViewModel.wallet,
chainIconPath: index > 0 ? dashboardViewModel.wallet.currency.chainIconPath! : "",
trailingText: index > 0 ? "MWEB" : null,
modalMode: index > 0
? AssetDetailsModalModes.ltcPrivate
: AssetDetailsModalModes.ltcTransparent,
title: index > 0 ? "Litecoin Private" : null,
);
}
final balance = dashboardViewModel.balanceViewModel.formattedBalances.elementAt(index);
return AssetTile(
showSwap: dashboardViewModel.isEnabledSwapAction,
balance: dashboardViewModel.balanceViewModel.formattedBalances.first,
showSecondary: index > 0 ? true : false,
balance: balance,
wallet: dashboardViewModel.wallet,
chainIconPath: index > 0 ? dashboardViewModel.wallet.currency.chainIconPath! : "",
trailingText: index > 0 ? "MWEB" : null,
modalMode: index > 0
? AssetDetailsModalModes.ltcPrivate
: AssetDetailsModalModes.ltcTransparent,
title: index > 0 ? "Litecoin Private" : null,
chainIconPath: _getChainIconPath(),
);
}
final balance = dashboardViewModel.balanceViewModel.formattedBalances.elementAt(index);
return AssetTile(
showSwap: dashboardViewModel.isEnabledSwapAction,
balance: balance,
wallet: dashboardViewModel.wallet,
chainIconPath: _getChainIconPath(),
);
});
},
);
}
});
},
);
}
),
),
);
}
@@ -26,10 +26,10 @@ class AssetsTopBar extends StatelessWidget {
final settingsButtonText = _getSettingsButtonText();
final hasTokenSettingsButton = settingsButtonText != null;
return Padding(
padding: const EdgeInsets.only(top: 12.0, bottom: 12.0, left: 12.0, right: 18.0),
child: Row(
return SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(top: 12.0, bottom: 12.0, left: 12.0, right: 18.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
@@ -82,9 +82,9 @@ class AssetsTopBar extends StatelessWidget {
),
),
),
),
],
),
],
),
),
);
}
@@ -27,26 +27,29 @@ class HistorySection extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Observer(
builder: (_) => (dashboardViewModel.items.isEmpty &&
dashboardViewModel.status is! SyncingSyncStatus)
? Padding(
padding: EdgeInsets.only(top: 24),
child: Text(S.of(context).transactions_will_appear_here,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
color: Theme.of(context).colorScheme.onSurfaceVariant)))
: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: dashboardViewModel.items.length,
itemBuilder: (context, index) => Observer(builder: (_) {
final prevItem = index == 0 ? null : dashboardViewModel.items[index - 1];
final item = dashboardViewModel.items[index];
return SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
sliver: Observer(
builder: (_) => (dashboardViewModel.items.isEmpty &&
dashboardViewModel.status is! SyncingSyncStatus)
? SliverPadding(
padding: EdgeInsets.only(top: 24),
sliver: SliverToBoxAdapter(
child: Center(
child: Text(S.of(context).transactions_will_appear_here,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
color: Theme.of(context).colorScheme.onSurfaceVariant)),
),
),
)
: SliverList(
delegate: SliverChildBuilderDelegate(
childCount: dashboardViewModel.items.length,
(context, index) => Observer(builder: (_) {
final prevItem = index == 0 ? null : dashboardViewModel.items[index - 1];
final item = dashboardViewModel.items[index];
final nextItem = index == dashboardViewModel.items.length - 1
? null
: dashboardViewModel.items[index + 1];
@@ -163,6 +166,6 @@ class HistorySection extends StatelessWidget {
}),
),
),
);
));
}
}
@@ -63,7 +63,7 @@ class HistoryTile extends StatelessWidget {
return Stack(
children: [
CakeImageWidget(imageUrl:
"assets/images/lightning-icon.svg",
"assets/new-ui/lightning-icon.svg",
width: 34,
height: 34,
),
@@ -31,38 +31,40 @@ class _NFTListingPageState extends State<NFTListingPage> {
@override
Widget build(BuildContext context) {
return Observer(
builder: (context) {
return Column(
children: [
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
child: PrimaryButton(
text: S.current.import,
color: Theme.of(context).colorScheme.surfaceContainer,
textColor: Theme.of(context).colorScheme.onSecondaryContainer,
onPressed: () => Navigator.pushNamed(
context,
Routes.importNFTPage,
arguments: widget.nftViewModel,
),
),
),
if (widget.nftViewModel.isLoading)
Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).colorScheme.surfaceContainerHighest,
valueColor: AlwaysStoppedAnimation<Color>(
Theme.of(context).colorScheme.primary,
return SliverToBoxAdapter(
child: Observer(
builder: (context) {
return Column(
children: [
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
child: PrimaryButton(
text: S.current.import,
color: Theme.of(context).colorScheme.surfaceContainer,
textColor: Theme.of(context).colorScheme.onSecondaryContainer,
onPressed: () => Navigator.pushNamed(
context,
Routes.importNFTPage,
arguments: widget.nftViewModel,
),
),
)
else
NFTListWidget(nftViewModel: widget.nftViewModel)
],
);
},
),
if (widget.nftViewModel.isLoading)
Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).colorScheme.surfaceContainerHighest,
valueColor: AlwaysStoppedAnimation<Color>(
Theme.of(context).colorScheme.primary,
),
),
)
else
NFTListWidget(nftViewModel: widget.nftViewModel)
],
);
},
),
);
}
}
@@ -327,7 +327,7 @@ abstract class DashboardViewModelBase with Store {
} catch (_) {}
}
return length * confirmations;
}, _transactionDisposerCallback);
}, _transactionDisposerCallback, delay: 300);
if (hasSilentPayments) {
silentPaymentsScanningActive = bitcoin!.getScanningActive(wallet);
@@ -481,13 +481,23 @@ abstract class DashboardViewModelBase with Store {
}
// printV("Transaction disposer callback (relevantTxs: ${relevantTxs.length} current: ${transactions.length})");
transactions.clear();
transactions.addAll(relevantTxs.map((tx) => TransactionListItem(
transaction: tx,
balanceViewModel: balanceViewModel,
appStore: appStore,
key: ValueKey('${wallet.type.name}_transaction_history_item_${tx.id}_key'),
)));
final newTransactions = relevantTxs
.map((tx) => TransactionListItem(
transaction: tx,
balanceViewModel: balanceViewModel,
appStore: appStore,
key: ValueKey('${wallet.type.name}_transaction_history_item_${tx.id}_key'),
))
.where((item) => !transactions.contains(item));
transactions.addAll(newTransactions);
// transactions.clear();
// transactions.addAll(relevantTxs.map((tx) => TransactionListItem(
// transaction: tx,
// balanceViewModel: balanceViewModel,
// appStore: appStore,
// key: ValueKey('${wallet.type.name}_transaction_history_item_${tx.id}_key'),
// )));
} finally {
_isTransactionDisposerCallbackRunning = false;
}
@@ -1252,7 +1262,7 @@ abstract class DashboardViewModelBase with Store {
} catch (_) {}
}
return length * confirmations;
}, _transactionDisposerCallback);
}, _transactionDisposerCallback, delay: 300);
}
@action
@@ -289,4 +289,12 @@ class TransactionListItem extends ActionListItem with Keyable {
@override
DateTime get date => transaction.date;
@override
bool operator ==(Object other) {
if (other is TransactionListItem) {
return other.transaction.txHash == transaction.txHash;
}
return false;
}
}