prevent trade.from saving as null + fallback when it does (#3346)

This commit is contained in:
malik1004x
2026-06-25 13:05:05 +03:00
committed by GitHub
parent d3a1464775
commit eaa8338a52
5 changed files with 28 additions and 16 deletions
@@ -280,8 +280,8 @@ class NearIntentsExchangeProvider extends ExchangeProvider {
final trade = Trade(
id: depositAddress,
// Using deposit address as trade ID
from: from,
to: to,
from: request.fromCurrency,
to: request.toCurrency,
provider: description,
providerName: title,
state: TradeState.created,
@@ -101,9 +101,6 @@ class HistorySection extends StatelessWidget {
final trade = item.trade;
final tradeFrom = trade.from;
final tradeTo = trade.to;
if (tradeFrom == null || tradeTo == null) {
return const SizedBox.shrink();
}
return GestureDetector(
onTap: () => Navigator.of(context)
@@ -15,13 +15,13 @@ class HistoryTradeTile extends StatelessWidget {
required this.roundedTop,
required this.roundedBottom,
required this.bottomSeparator,
required this.from,
required this.to,
this.from,
this.to,
required this.swapState,
required this.provider});
final CryptoCurrency from;
final CryptoCurrency to;
final CryptoCurrency? from;
final CryptoCurrency? to;
final ExchangeProviderDescription provider;
final String date;
final String amount;
@@ -32,6 +32,11 @@ class HistoryTradeTile extends StatelessWidget {
final TradeState swapState;
Widget _getLeadingStack(BuildContext context) {
if (from == null || to == null) {
return SizedBox(width: 50, height: 50);
}
double currencyIconSize = 22.0;
return SizedBox(
@@ -40,7 +45,7 @@ class HistoryTradeTile extends StatelessWidget {
child: Stack(
children: [
CakeImageWidget(
imageUrl: _getIconPath(from), width: currencyIconSize, height: currencyIconSize),
imageUrl: _getIconPath(from!), width: currencyIconSize, height: currencyIconSize),
Positioned(
top: currencyIconSize / 2,
left: currencyIconSize / 2,
@@ -50,7 +55,7 @@ class HistoryTradeTile extends StatelessWidget {
Border.all(width: 2, color: Theme.of(context).colorScheme.surfaceContainer),
shape: BoxShape.circle),
child: CakeImageWidget(
imageUrl: _getIconPath(to),
imageUrl: _getIconPath(to!),
width: currencyIconSize,
height: currencyIconSize,
),
@@ -85,8 +90,8 @@ class HistoryTradeTile extends StatelessWidget {
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontWeight: FontWeight.w500)),
Text(from.title, style: TextStyle(color: Theme.of(context).colorScheme.onSurfaceVariant)),
if (fromChainIcon.isNotEmpty)
if(from?.title != null) Text(from!.title, style: TextStyle(color: Theme.of(context).colorScheme.onSurfaceVariant)),
if (fromChainIcon?.isNotEmpty ?? false)
CakeImageWidget(
imageUrl: fromChainIcon,
width: 12,
@@ -106,10 +111,11 @@ class HistoryTradeTile extends StatelessWidget {
receiveAmount.withMaxDecimals(8),
style: TextStyle(fontWeight: FontWeight.w500),
),
if(to!=null)
Text(
to.title,
to!.title,
),
if (toChainIcon.isNotEmpty) CakeImageWidget(imageUrl: toChainIcon, width: 12, height: 12)
if (toChainIcon?.isNotEmpty ?? false) CakeImageWidget(imageUrl: toChainIcon, width: 12, height: 12)
],
),
leadingIcon: _getLeadingStack(context),
@@ -137,7 +143,8 @@ class HistoryTradeTile extends StatelessWidget {
return "";
}
String _getChainIcon(CryptoCurrency currency) {
String? _getChainIcon(CryptoCurrency? currency) {
if(currency == null) return null;
try {
if (currency.title.isNotEmpty) {
final parsedCurrency = CryptoCurrency.safeParseCurrencyFromString(currency.title, tag: currency.tag);
@@ -9,6 +9,7 @@ import 'package:cw_core/root_dir.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:path/path.dart' as path;
class DevMoneroWalletCacheDebugPage extends StatelessWidget {
@@ -263,6 +264,7 @@ class _JsonExplorerState extends State<JsonExplorer> {
),
)
: ListView.builder(
controller: ModalScrollController.of(context),
itemCount: _filteredItems.length,
itemBuilder: (context, index) {
final item = _filteredItems[index];
@@ -1242,6 +1242,12 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
trade.walletId = wallet.id;
trade.chainId = wallet.chainId;
trade.fromWalletAddress = wallet.walletAddresses.address;
if(trade.from == null) {
trade.from = depositCurrency;
}
if(trade.to == null) {
trade.to = receiveCurrency;
}
final canCreateTrade = await isCanCreateTrade(trade);
if (!canCreateTrade.result) {