-
Notifications
You must be signed in to change notification settings - Fork 5
Redesign home screen #447
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
Redesign home screen #447
Changes from all commits
3155dab
6c5b673
89192a4
f734185
c57b838
e005f88
cb71838
f1cba5b
6642684
01d2e21
4b51e4c
9bd0554
a9f2870
aeb7e29
836d97c
6af5a54
7effe0f
60e7353
53238bf
71a1999
9601a80
4cb2b5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| Copyright (c) 2023 Vercel, in collaboration with basement.studio | ||
|
|
||
| This Font Software is licensed under the SIL Open Font License, Version 1.1. | ||
| This license is copied below, and is also available with a FAQ at: | ||
| http://scripts.sil.org/OFL | ||
|
|
||
| ----------------------------------------------------------- | ||
| SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 | ||
| ----------------------------------------------------------- | ||
|
|
||
| PREAMBLE | ||
| The goals of the Open Font License (OFL) are to stimulate worldwide | ||
| development of collaborative font projects, to support the font creation | ||
| efforts of academic and linguistic communities, and to provide a free and | ||
| open framework in which fonts may be shared and improved in partnership | ||
| with others. | ||
|
|
||
| The OFL allows the licensed fonts to be used, studied, modified and | ||
| redistributed freely as long as they are not sold by themselves. The | ||
| fonts, including any derivative works, can be bundled, embedded, | ||
| redistributed and/or sold with any software provided that any reserved | ||
| names are not used by derivative works. The fonts and derivatives, | ||
| however, cannot be released under any other type of license. The | ||
| requirement for fonts to remain under this license does not apply | ||
| to any document created using the fonts or their derivatives. | ||
|
|
||
| DEFINITIONS | ||
| "Font Software" refers to the set of files released by the Copyright | ||
| Holder(s) under this license and clearly marked as such. This may | ||
| include source files, build scripts and documentation. | ||
|
|
||
| "Reserved Font Name" refers to any names specified as such after the | ||
| copyright statement(s). | ||
|
|
||
| "Original Version" refers to the collection of Font Software components as | ||
| distributed by the Copyright Holder(s). | ||
|
|
||
| "Modified Version" refers to any derivative made by adding to, deleting, | ||
| or substituting -- in part or in whole -- any of the components of the | ||
| Original Version, by changing formats or by porting the Font Software to a | ||
| new environment. | ||
|
|
||
| "Author" refers to any designer, engineer, programmer, technical | ||
| writer or other person who contributed to the Font Software. | ||
|
|
||
| PERMISSION AND CONDITIONS | ||
| Permission is hereby granted, free of charge, to any person obtaining | ||
| a copy of the Font Software, to use, study, copy, merge, embed, modify, | ||
| redistribute, and sell modified and unmodified copies of the Font | ||
| Software, subject to the following conditions: | ||
|
|
||
| 1) Neither the Font Software nor any of its individual components, | ||
| in Original or Modified Versions, may be sold by itself. | ||
|
|
||
| 2) Original or Modified Versions of the Font Software may be bundled, | ||
| redistributed and/or sold with any software, provided that each copy | ||
| contains the above copyright notice and this license. These can be | ||
| included either as stand-alone text files, human-readable headers or | ||
| in the appropriate machine-readable metadata fields within text or | ||
| binary files as long as those fields can be easily viewed by the user. | ||
|
|
||
| 3) No Modified Version of the Font Software may use the Reserved Font | ||
| Name(s) unless explicit written permission is granted by the corresponding | ||
| Copyright Holder. This restriction only applies to the primary font name as | ||
| presented to the users. | ||
|
|
||
| 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font | ||
| Software shall not be used to promote, endorse or advertise any | ||
| Modified Version, except to acknowledge the contribution(s) of the | ||
| Copyright Holder(s) and the Author(s) or with their explicit written | ||
| permission. | ||
|
|
||
| 5) The Font Software, modified or unmodified, in part or in whole, | ||
| must be distributed entirely under this license, and must not be | ||
| distributed under any other license. The requirement for fonts to | ||
| remain under this license does not apply to any document created | ||
| using the Font Software. | ||
|
|
||
| TERMINATION | ||
| This license becomes null and void if any of the above conditions are | ||
| not met. | ||
|
|
||
| DISCLAIMER | ||
| THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF | ||
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | ||
| OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE | ||
| COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL | ||
| DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM | ||
| OTHER DEALINGS IN THE FONT SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /// Fiat currencies the app can convert QUAN amounts into. | ||
| /// | ||
| /// QUAN itself is not listed here — it is always the native side. | ||
| /// Adding a new currency only requires a new enum case here and a matching | ||
| /// rate in [ExchangeRateService]. No widget or provider changes are needed. | ||
| enum FiatCurrency { | ||
| usd(code: 'USD', symbol: '\$', symbolPosition: SymbolPosition.prefix), | ||
| myr(code: 'MYR', symbol: 'RM', symbolPosition: SymbolPosition.prefix), | ||
| idr(code: 'IDR', symbol: 'Rp', symbolPosition: SymbolPosition.prefix), | ||
| jpy(code: 'JPY', symbol: '¥', symbolPosition: SymbolPosition.prefix), | ||
| eur(code: 'EUR', symbol: '€', symbolPosition: SymbolPosition.prefix), | ||
| gbp(code: 'GBP', symbol: '£', symbolPosition: SymbolPosition.prefix); | ||
|
|
||
| const FiatCurrency({required this.code, required this.symbol, required this.symbolPosition}); | ||
|
|
||
| /// ISO 4217 code, e.g. "USD", "IDR". Used for persistence and display. | ||
| final String code; | ||
|
|
||
| /// The display symbol, e.g. "$", "Rp", "¥". | ||
| final String symbol; | ||
|
|
||
| final SymbolPosition symbolPosition; | ||
|
|
||
| /// Wraps a pre-formatted numeric [amount] string with this currency's symbol. | ||
| /// | ||
| /// Example: | ||
| /// FiatCurrency.usd.format('1,250.00') → '$1,250.00' | ||
| /// FiatCurrency.idr.format('1,250') → 'Rp1,250' | ||
| String format(String amount) => switch (symbolPosition) { | ||
| SymbolPosition.prefix => '$symbol$amount', | ||
| SymbolPosition.suffix => '$amount $symbol', | ||
| }; | ||
|
|
||
| /// Same as [format] but prepends a `+` or `-` sign. Used for transaction | ||
| /// list items where direction matters. | ||
| /// | ||
| /// Example: | ||
| /// FiatCurrency.usd.formatSigned('1,250.00', isSend: true) → '-$1,250.00' | ||
| /// FiatCurrency.usd.formatSigned('1,250.00', isSend: false) → '+$1,250.00' | ||
| String formatSigned(String amount, {required bool isSend}) { | ||
| final sign = isSend ? '-' : '+'; | ||
| return switch (symbolPosition) { | ||
| SymbolPosition.prefix => '$sign$symbol$amount', | ||
| SymbolPosition.suffix => '$sign$amount $symbol', | ||
| }; | ||
| } | ||
|
|
||
| /// Looks up a [FiatCurrency] by its [code], returning [fallback] if not found. | ||
| static FiatCurrency fromCode(String code, {FiatCurrency fallback = FiatCurrency.usd}) { | ||
| return FiatCurrency.values.firstWhere((c) => c.code == code, orElse: () => fallback); | ||
| } | ||
| } | ||
|
|
||
| enum SymbolPosition { prefix, suffix } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| import 'package:decimal/decimal.dart'; | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:quantus_sdk/quantus_sdk.dart'; | ||
| import 'package:resonance_network_wallet/models/fiat_currency.dart'; | ||
| import 'package:resonance_network_wallet/providers/wallet_providers.dart'; | ||
| import 'package:resonance_network_wallet/services/exchange_rate_service.dart'; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Exchange rate service provider | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| final exchangeRateServiceProvider = Provider<ExchangeRateService>((ref) { | ||
| return ExchangeRateService(); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Selected fiat currency provider | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| /// Persists and exposes the user's chosen fiat currency for conversions. | ||
| /// Defaults to [FiatCurrency.usd] when no preference has been saved. | ||
| /// | ||
| /// To change the active fiat currency (e.g. from a settings screen): | ||
| /// ref.read(selectedFiatCurrencyProvider.notifier).select(FiatCurrency.idr); | ||
| final selectedFiatCurrencyProvider = StateNotifierProvider<SelectedFiatCurrencyNotifier, FiatCurrency>((ref) { | ||
| final settings = ref.watch(settingsServiceProvider); | ||
| return SelectedFiatCurrencyNotifier(settings); | ||
| }); | ||
|
|
||
| class SelectedFiatCurrencyNotifier extends StateNotifier<FiatCurrency> { | ||
| final SettingsService _settings; | ||
|
|
||
| SelectedFiatCurrencyNotifier(this._settings) : super(_load(_settings)); | ||
|
|
||
| /// Persists and applies [currency] as the active fiat currency. | ||
| Future<void> select(FiatCurrency currency) async { | ||
| await _settings.setSelectedFiatCurrency(currency.code); | ||
| state = currency; | ||
| } | ||
|
|
||
| static FiatCurrency _load(SettingsService settings) { | ||
| final code = settings.getSelectedFiatCurrency(); | ||
| if (code == null) return FiatCurrency.usd; | ||
| return FiatCurrency.fromCode(code); | ||
| } | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Currency flip provider | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| /// Whether fiat is shown as the primary (large) display and QUAN secondary. | ||
| /// | ||
| /// false → primary = QUAN, secondary = fiat (default) | ||
| /// true → primary = fiat, secondary = QUAN | ||
| /// | ||
| /// To toggle from the swap button: | ||
| /// ref.read(isCurrencyFlippedProvider.notifier).toggle(); | ||
| final isCurrencyFlippedProvider = StateNotifierProvider<IsCurrencyFlippedNotifier, bool>((ref) { | ||
| final settings = ref.watch(settingsServiceProvider); | ||
| return IsCurrencyFlippedNotifier(settings); | ||
| }); | ||
|
|
||
| class IsCurrencyFlippedNotifier extends StateNotifier<bool> { | ||
| final SettingsService _settings; | ||
|
|
||
| IsCurrencyFlippedNotifier(this._settings) : super(_settings.isCurrencyFlipped()); | ||
|
|
||
| Future<void> toggle() async { | ||
| final next = !state; | ||
| await _settings.setCurrencyFlipped(next); | ||
| state = next; | ||
| } | ||
|
|
||
| Future<void> setFlipped(bool value) async { | ||
| await _settings.setCurrencyFlipped(value); | ||
| state = value; | ||
| } | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Display state | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| /// The fully-resolved display state for the active account's balance. | ||
| /// | ||
| /// Widgets render [primaryAmount] and [secondaryAmount] directly. | ||
| /// No conversion math belongs in widgets. | ||
| class CurrencyDisplayState { | ||
| final String primaryAmount; | ||
| final String secondaryAmount; | ||
| final bool isFlipped; | ||
| final FiatCurrency selectedFiat; | ||
|
|
||
| const CurrencyDisplayState({ | ||
| required this.primaryAmount, | ||
| required this.secondaryAmount, | ||
| required this.isFlipped, | ||
| required this.selectedFiat, | ||
| }); | ||
|
|
||
| CurrencyDisplayState copyWith({ | ||
| String? primaryAmount, | ||
| String? secondaryAmount, | ||
| bool? isFlipped, | ||
| FiatCurrency? selectedFiat, | ||
| }) => CurrencyDisplayState( | ||
| primaryAmount: primaryAmount ?? this.primaryAmount, | ||
| secondaryAmount: secondaryAmount ?? this.secondaryAmount, | ||
| isFlipped: isFlipped ?? this.isFlipped, | ||
| selectedFiat: selectedFiat ?? this.selectedFiat, | ||
| ); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Balance display provider | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| final _hiddenAmountText = '- - - - -'; | ||
|
|
||
| /// Combines balance, hidden state, flip state, selected fiat, and exchange | ||
| /// rate into [CurrencyDisplayState] ready for widgets to render. | ||
| final currencyDisplayProvider = Provider<AsyncValue<CurrencyDisplayState>>((ref) { | ||
| final balanceAsync = ref.watch(balanceProvider); | ||
| final isHidden = ref.watch(isBalanceHiddenProvider); | ||
| final isFlipped = ref.watch(isCurrencyFlippedProvider); | ||
| final selectedFiat = ref.watch(selectedFiatCurrencyProvider); | ||
| final fmt = ref.watch(numberFormattingServiceProvider); | ||
| final xRate = ref.watch(exchangeRateServiceProvider); | ||
|
|
||
| return balanceAsync.when( | ||
| loading: () => const AsyncValue.loading(), | ||
| error: (err, stack) => AsyncValue.error(err, stack), | ||
| data: (balance) { | ||
| final quanFormatted = fmt.formatBalance(balance, addSymbol: isFlipped); | ||
| final fiatFormatted = selectedFiat.format(_toFiatNumeric(balance, selectedFiat, xRate)); | ||
|
|
||
| CurrencyDisplayState data = CurrencyDisplayState( | ||
| primaryAmount: isFlipped ? fiatFormatted : quanFormatted, | ||
| secondaryAmount: isFlipped ? quanFormatted : fiatFormatted, | ||
| isFlipped: isFlipped, | ||
| selectedFiat: selectedFiat, | ||
| ); | ||
|
|
||
| if (isHidden) { | ||
| data = data.copyWith(primaryAmount: _hiddenAmountText, secondaryAmount: _hiddenAmountText); | ||
| } | ||
|
|
||
| return AsyncValue.data(data); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Per-amount formatter (for transaction items) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| /// Formats a single transaction [amount] (raw BigInt) as a signed string | ||
| /// respecting the current hidden state, flip state, and selected fiat. | ||
| /// | ||
| /// Usage: | ||
| /// final formatted = ref.watch(txAmountFormatterProvider)(amount, isSend: true); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure we ever want to show transaction items as fiat currency?!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works the same purpose as the blance toggling between fiat and quan. I think it's reasonable to display it as fiat when they toggle the balance, it make it easier for some people to know how much they send or spend in fiat term. It is also how the design in figma. |
||
| final txAmountFormatterProvider = Provider<String Function(BigInt, {required bool isSend})>((ref) { | ||
| final isHidden = ref.watch(isBalanceHiddenProvider); | ||
| final isFlipped = ref.watch(isCurrencyFlippedProvider); | ||
| final selectedFiat = ref.watch(selectedFiatCurrencyProvider); | ||
| final fmt = ref.watch(numberFormattingServiceProvider); | ||
| final xRate = ref.watch(exchangeRateServiceProvider); | ||
|
|
||
| return (BigInt amount, {required bool isSend}) { | ||
| if (isHidden) return _hiddenAmountText; | ||
|
|
||
| if (isFlipped) { | ||
| final numeric = _toFiatNumeric(amount, selectedFiat, xRate); | ||
| return selectedFiat.formatSigned(numeric, isSend: isSend); | ||
| } | ||
|
|
||
| final sign = isSend ? '-' : '+'; | ||
| return '$sign${fmt.formatBalance(amount)} ${AppConstants.tokenSymbol}'; | ||
| }; | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Internal helpers | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| String _toFiatNumeric(BigInt rawBalance, FiatCurrency fiat, ExchangeRateService xRate) { | ||
| final scaleFactor = BigInt.from(10).pow(AppConstants.decimals); | ||
| final quantity = (Decimal.fromBigInt(rawBalance) / Decimal.fromBigInt(scaleFactor)).toDecimal(); | ||
| final fiatValue = xRate.convert(quantity, fiat); | ||
|
|
||
| return fiatValue.toStringAsFixed(2); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.