-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2173 from get10101/feat/currency-switch
feat(webapp): add currency toggle to navbar to display balances in Sats/Btc or USD
- Loading branch information
Showing
7 changed files
with
180 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
enum Currency { usd, btc, sats } | ||
|
||
extension CurrencyExtension on Currency { | ||
String get name { | ||
switch (this) { | ||
case Currency.sats: | ||
return 'Sats'; | ||
case Currency.btc: | ||
return 'BTC'; | ||
case Currency.usd: | ||
return 'USD'; | ||
default: | ||
throw Exception('Unknown currency'); | ||
} | ||
} | ||
} | ||
|
||
class CurrencyChangeNotifier extends ChangeNotifier { | ||
Currency _currency; | ||
|
||
CurrencyChangeNotifier(this._currency); | ||
|
||
Currency get currency => _currency; | ||
|
||
set currency(Currency value) { | ||
_currency = value; | ||
notifyListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:bitcoin_icons/bitcoin_icons.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | ||
import 'package:get_10101/common/currency_change_notifier.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class CurrencySelectionScreen extends StatelessWidget { | ||
const CurrencySelectionScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
CurrencyChangeNotifier changeNotifier = context.watch<CurrencyChangeNotifier>(); | ||
final Currency currency = changeNotifier.currency; | ||
|
||
return SegmentedButton<Currency>( | ||
style: SegmentedButton.styleFrom( | ||
backgroundColor: Colors.grey[100], | ||
), | ||
segments: <ButtonSegment<Currency>>[ | ||
ButtonSegment<Currency>( | ||
value: Currency.sats, | ||
label: Text(Currency.sats.name), | ||
icon: const Icon(BitcoinIcons.satoshi_v2)), | ||
ButtonSegment<Currency>( | ||
value: Currency.btc, | ||
label: Text(Currency.btc.name), | ||
icon: const Icon(BitcoinIcons.bitcoin)), | ||
ButtonSegment<Currency>( | ||
value: Currency.usd, | ||
label: Text(Currency.usd.name), | ||
icon: const Icon(FontAwesomeIcons.dollarSign), | ||
), | ||
], | ||
selected: <Currency>{currency}, | ||
onSelectionChanged: (Set<Currency> newSelection) { | ||
changeNotifier.currency = newSelection.first; | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters