diff --git a/lib/chart.dart b/lib/chart.dart index c6fd4f4..4974495 100644 --- a/lib/chart.dart +++ b/lib/chart.dart @@ -42,14 +42,15 @@ class HorizontalBarChart extends StatelessWidget { Widget build(BuildContext context) { final palette = getPalette(Theme.of(context).primaryColor, values.length); - final sum = max(values.fold(0, ((acc, v) => acc + v)), 1); + final sum = values.fold(0, ((acc, v) => acc + v)); final stacks = values.asMap().entries.map((e) { final i = e.key; final color = palette[i]; final v = NumberFormat.compact().format(values[i]); + final flex = max((values[i] / sum * 100).round(), 1); return Flexible(child: Container(child: Center(child: Text(v, textAlign: TextAlign.center, style: TextStyle(color: Colors.white))), - color: color, height: height), flex: min((values[i] / sum * 100).round(), 1)); + color: color, height: height), flex: flex); }).toList(); return IntrinsicHeight( diff --git a/lib/dualmoneyinput.dart b/lib/dualmoneyinput.dart index ec93fd6..49a3457 100644 --- a/lib/dualmoneyinput.dart +++ b/lib/dualmoneyinput.dart @@ -5,12 +5,12 @@ import 'generated/l10n.dart'; import 'main.dart'; class DualMoneyInputWidget extends StatefulWidget { - final Widget? child; final int? spendable; final int? initialValue; - final bool useMillis; + final bool max; - DualMoneyInputWidget({Key? key, this.child, this.initialValue, this.spendable, this.useMillis = true}): super(key: key); + DualMoneyInputWidget({Key? key, this.initialValue, this.spendable, + this.max = false}): super(key: key); @override DualMoneyInputState createState() => DualMoneyInputState(); @@ -18,19 +18,20 @@ class DualMoneyInputWidget extends StatefulWidget { class DualMoneyInputState extends State { static final zero = decimalFormat(0, 3); - var useMillis = true; var inputInCoin = true; var coinAmountController = TextEditingController(text: zero); var fiatAmountController = TextEditingController(text: zero); var amount = 0; + var useMax = false; ReactionDisposer? priceAutorunDispose; + bool get useMillis => settings.useMillis && !useMax; + @override void initState() { super.initState(); final initialValue = widget.initialValue ?? 0; - useMillis = widget.useMillis; final amount = amountToString(initialValue, precision(useMillis)); coinAmountController.text = amount; _updateFiatAmount(); @@ -49,7 +50,6 @@ class DualMoneyInputState extends State { @override Widget build(BuildContext context) { final s = S.of(context); - final child = widget.child; return Column(children: [ Row(children: [ Expanded( @@ -70,7 +70,7 @@ class DualMoneyInputState extends State { onChanged: (_) => _updateFiatAmount(), onSaved: _onAmount, )), - if (child != null) child, + if (widget.max) TextButton(child: Text(s.max), onPressed: _onMax), ]), Row(children: [ Expanded( @@ -95,23 +95,26 @@ class DualMoneyInputState extends State { void clear() { setState(() { - useMillis = true; + useMax = false; coinAmountController.text = zero; fiatAmountController.text = zero; }); } - void setMillis(bool useMillis) { + void setAmount(int amount) { setState(() { - this.useMillis = useMillis; + coinAmountController.text = amountToString(amount, MAX_PRECISION); + _updateFiatAmount(); }); } - void setAmount(int amount) { + void _onMax() { setState(() { - useMillis = false; - coinAmountController.text = amountToString(amount, MAX_PRECISION); - _updateFiatAmount(); + final s = widget.spendable; + if (s != null) { + useMax = true; + setAmount(s); + } }); } diff --git a/lib/pools.dart b/lib/pools.dart index 29b0281..d070071 100644 --- a/lib/pools.dart +++ b/lib/pools.dart @@ -66,7 +66,7 @@ class PoolsState extends State { }); } ), - DualMoneyInputWidget(key: _amountKey, initialValue: 0, spendable: _spendable, useMillis: settings.useMillis), + DualMoneyInputWidget(key: _amountKey, initialValue: 0, spendable: _spendable, max: true), Text(s.maxSpendableAmount(amountToString(_spendable, MAX_PRECISION), active.coinDef.ticker)), Padding(padding: EdgeInsets.symmetric(vertical: 8.0)), TextFormField( @@ -95,9 +95,9 @@ class PoolsState extends State { int get _spendable { final b = active.poolBalances; switch (_fromPool) { - case 0: return b.transparent; - case 1: return b.sapling; - case 2: return b.orchard; + case 0: return b.transparent - DEFAULT_FEE; + case 1: return b.sapling - DEFAULT_FEE; + case 2: return b.orchard - DEFAULT_FEE; } return 0; } diff --git a/lib/send.dart b/lib/send.dart index 31777b7..d047451 100644 --- a/lib/send.dart +++ b/lib/send.dart @@ -43,7 +43,6 @@ class SendState extends State { final _memoController = TextEditingController(); final _subjectController = TextEditingController(); var _memoInitialized = false; - bool _max = false; ReactionDisposer? _newBlockAutorunDispose; final _fee = DEFAULT_FEE; var _usedBalance = 0; @@ -159,10 +158,8 @@ class SendState extends State { ]), DualMoneyInputWidget( key: _amountKey, - child: - TextButton(child: Text(s.max), onPressed: _onMax), + max: true, initialValue: _initialAmount, - useMillis: settings.useMillis && !_max, spendable: spendable), if (!simpleMode) BalanceTable(_sBalance, _tBalance, _excludedBalance, _underConfirmedBalance, change, _usedBalance, _fee), @@ -217,13 +214,6 @@ class SendState extends State { return null; } - void _onMax() { - setState(() { - _max = true; - amountInput?.setAmount(spendable); - }); - } - void _onScan() async { final code = await scanCode(context); if (code != null) { @@ -318,20 +308,21 @@ class BalanceTable extends StatelessWidget { @override Widget build(BuildContext context) { final theme = Theme.of(context); + final s = S.of(context); return Container( decoration: BoxDecoration( border: Border.all(color: theme.dividerColor, width: 1), borderRadius: BorderRadius.circular(8)), child: Column(crossAxisAlignment: CrossAxisAlignment.center, children: [ - BalanceRow(Text(S.of(context).totalBalance), totalBalance), - BalanceRow(Text(S.of(context).underConfirmed), -underConfirmed), - BalanceRow(Text(S.of(context).excludedNotes), -excludedBalance), - BalanceRow(Text(S.of(context).spendableBalance), spendable, - style: TextStyle(color: Theme.of(context).primaryColor)), + BalanceRow(Text(s.totalBalance), totalBalance), + BalanceRow(Text(s.underConfirmed), -underConfirmed), + BalanceRow(Text(s.excludedNotes), -excludedBalance), + BalanceRow(Text(s.spendableBalance), spendable, + style: TextStyle(color: theme.primaryColor)), ])); } - get totalBalance => sBalance + tBalance + change - used - fee; + get totalBalance => sBalance + tBalance + change - used; get underConfirmed => -underConfirmedBalance - change; diff --git a/pubspec.yaml b/pubspec.yaml index 42ebc0c..5f10e34 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.2.16+310 +version: 1.2.17+311 environment: sdk: ">=2.12.0 <3.0.0"