From ea5c8bfcdd3bd8e7bfb97cfc67e395fc86056c5d Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Tue, 15 Apr 2025 14:22:36 +0200 Subject: [PATCH 1/2] Show all avaiable chains in dropdowns and disable necessary --- .../wallets/swap_transaction_widget.dart | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/app/lib/widgets/wallets/swap_transaction_widget.dart b/app/lib/widgets/wallets/swap_transaction_widget.dart index fb3a20a2..b0f6f98d 100644 --- a/app/lib/widgets/wallets/swap_transaction_widget.dart +++ b/app/lib/widgets/wallets/swap_transaction_widget.dart @@ -60,8 +60,8 @@ class _SwapTransactionWidgetState extends State { setState(() { leftSelectedChain = newChain; if (newChain == Chains.TFChain.name) { - currentOperation = BridgeOperation.Withdraw; - _handleRightChainChange(Chains.Stellar.name); + currentOperation = BridgeOperation.Withdraw; + _handleRightChainChange(Chains.Stellar.name); } else { currentOperation = BridgeOperation.Deposit; } @@ -97,17 +97,18 @@ class _SwapTransactionWidgetState extends State { _buildChainInfo( context, selectedChain: leftSelectedChain, - excludeChains: [Chains.Solana.name, rightSelectedChain], + excludeChains: [rightSelectedChain], onChainChanged: _handleLeftChainChange, + disabledChains: [Chains.Solana.name], ), _buildSwapButton(context, disableSwap), _buildChainInfo( context, selectedChain: rightSelectedChain, - excludeChains: [ - leftSelectedChain, - if (leftSelectedChain == Chains.TFChain.name) Chains.Solana.name - ], + excludeChains: [leftSelectedChain], + disabledChains: leftSelectedChain == Chains.TFChain.name + ? [Chains.Solana.name] + : [], onChainChanged: _handleRightChainChange, isLeft: false, ), @@ -122,6 +123,7 @@ class _SwapTransactionWidgetState extends State { required List excludeChains, required ValueChanged onChainChanged, bool isLeft = true, + List disabledChains = const [], }) { return Flexible( flex: 1, @@ -137,6 +139,7 @@ class _SwapTransactionWidgetState extends State { onChanged: onChainChanged, colorScheme: Theme.of(context).colorScheme, textTheme: Theme.of(context).textTheme, + disabledChains: disabledChains, ), ), ], @@ -174,6 +177,7 @@ class _SwapTransactionWidgetState extends State { class ChainDropdown extends StatelessWidget { final String selectedChain; final List excludeChains; + final List disabledChains; final ValueChanged onChanged; final ColorScheme colorScheme; final TextTheme textTheme; @@ -185,6 +189,7 @@ class ChainDropdown extends StatelessWidget { required this.onChanged, required this.colorScheme, required this.textTheme, + this.disabledChains = const [], }); @override @@ -198,16 +203,24 @@ class ChainDropdown extends StatelessWidget { child: DropdownButton( value: selectedChain, items: chains.map((c) { + final isDisabled = disabledChains.contains(c); return DropdownMenuItem( - value: c, - child: _ChainItem(chain: c, colorScheme: colorScheme), + value: isDisabled ? null : c, + enabled: !isDisabled, + child: _ChainItem( + chain: c, + colorScheme: colorScheme, + isDisabled: isDisabled, + ), ); }).toList(), selectedItemBuilder: (context) => chains.map((c) { + final isDisabled = disabledChains.contains(c); return _ChainItem( chain: c, colorScheme: colorScheme, isSelected: true, + isDisabled: isDisabled, ); }).toList(), onChanged: (v) => v != null ? onChanged(v) : null, @@ -220,22 +233,28 @@ class _ChainItem extends StatelessWidget { final String chain; final ColorScheme colorScheme; final bool isSelected; + final bool isDisabled; const _ChainItem({ required this.chain, required this.colorScheme, this.isSelected = false, + this.isDisabled = false, }); @override Widget build(BuildContext context) { + final color = isDisabled + ? colorScheme.onSurface.withOpacity(0.4) + : colorScheme.onSurface; + return Row( children: [ Image.asset( _getChainIcon(chain), width: isSelected ? 30 : 20, height: isSelected ? 30 : 20, - color: colorScheme.onSurface, + color: color, ), const SizedBox(width: 8), Column( @@ -246,14 +265,14 @@ class _ChainItem extends StatelessWidget { style: TextStyle( fontWeight: FontWeight.bold, fontSize: isSelected ? 14 : 12, - color: colorScheme.onSurface, + color: color, ), ), Text( chain, style: TextStyle( fontSize: isSelected ? 12 : 10, - color: colorScheme.onSurface, + color: color, ), ), ], @@ -263,12 +282,11 @@ class _ChainItem extends StatelessWidget { } String _getChainIcon(String chain) { - Map chainIcons = { - Chains.Stellar.name: 'assets/stellar.png', - Chains.Solana.name: 'assets/solana.png', - Chains.TFChain.name: 'assets/tf_chain.png', - }; - - return chainIcons[chain] ?? 'assets/tf_chain.png'; + return { + Chains.Stellar.name: 'assets/stellar.png', + Chains.Solana.name: 'assets/solana.png', + Chains.TFChain.name: 'assets/tf_chain.png', + }[chain] ?? + 'assets/tf_chain.png'; } } From 3e3fbbdb32e92d11b1391b6f94ce4cf5c6ebd3de Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Tue, 15 Apr 2025 14:39:39 +0200 Subject: [PATCH 2/2] Edit from disabled chains --- app/lib/widgets/wallets/swap_transaction_widget.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/lib/widgets/wallets/swap_transaction_widget.dart b/app/lib/widgets/wallets/swap_transaction_widget.dart index b0f6f98d..7b7400fc 100644 --- a/app/lib/widgets/wallets/swap_transaction_widget.dart +++ b/app/lib/widgets/wallets/swap_transaction_widget.dart @@ -99,7 +99,9 @@ class _SwapTransactionWidgetState extends State { selectedChain: leftSelectedChain, excludeChains: [rightSelectedChain], onChainChanged: _handleLeftChainChange, - disabledChains: [Chains.Solana.name], + disabledChains: rightSelectedChain == Chains.Solana.name + ? [Chains.TFChain.name, Chains.Solana.name] + : [Chains.Solana.name], ), _buildSwapButton(context, disableSwap), _buildChainInfo(