Skip to content

Show all chains in bridge #999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 39 additions & 19 deletions app/lib/widgets/wallets/swap_transaction_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class _SwapTransactionWidgetState extends State<SwapTransactionWidget> {
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;
}
Expand Down Expand Up @@ -97,17 +97,20 @@ class _SwapTransactionWidgetState extends State<SwapTransactionWidget> {
_buildChainInfo(
context,
selectedChain: leftSelectedChain,
excludeChains: [Chains.Solana.name, rightSelectedChain],
excludeChains: [rightSelectedChain],
onChainChanged: _handleLeftChainChange,
disabledChains: rightSelectedChain == Chains.Solana.name
? [Chains.TFChain.name, Chains.Solana.name]
: [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,
),
Expand All @@ -122,6 +125,7 @@ class _SwapTransactionWidgetState extends State<SwapTransactionWidget> {
required List<String> excludeChains,
required ValueChanged<String> onChainChanged,
bool isLeft = true,
List<String> disabledChains = const [],
}) {
return Flexible(
flex: 1,
Expand All @@ -137,6 +141,7 @@ class _SwapTransactionWidgetState extends State<SwapTransactionWidget> {
onChanged: onChainChanged,
colorScheme: Theme.of(context).colorScheme,
textTheme: Theme.of(context).textTheme,
disabledChains: disabledChains,
),
),
],
Expand Down Expand Up @@ -174,6 +179,7 @@ class _SwapTransactionWidgetState extends State<SwapTransactionWidget> {
class ChainDropdown extends StatelessWidget {
final String selectedChain;
final List<String> excludeChains;
final List<String> disabledChains;
final ValueChanged<String> onChanged;
final ColorScheme colorScheme;
final TextTheme textTheme;
Expand All @@ -185,6 +191,7 @@ class ChainDropdown extends StatelessWidget {
required this.onChanged,
required this.colorScheme,
required this.textTheme,
this.disabledChains = const [],
});

@override
Expand All @@ -198,16 +205,24 @@ class ChainDropdown extends StatelessWidget {
child: DropdownButton<String>(
value: selectedChain,
items: chains.map((c) {
final isDisabled = disabledChains.contains(c);
return DropdownMenuItem<String>(
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,
Expand All @@ -220,22 +235,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(
Expand All @@ -246,14 +267,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,
),
),
],
Expand All @@ -263,12 +284,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';
}
}