Skip to content
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

Format transaction amount #744

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions app/lib/helpers/transaction_helpers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// ignore: depend_on_referenced_packages
import 'package:intl/intl.dart';

String formatAmount(String amount) {
double parsedAmount = double.parse(amount);

String formattedAmount = NumberFormat('#,##0.##').format(parsedAmount);

return formattedAmount;
}
3 changes: 2 additions & 1 deletion app/lib/screens/wallets/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:threebotlogin/helpers/globals.dart';
import 'package:threebotlogin/helpers/transaction_helpers.dart';
import 'package:threebotlogin/models/wallet.dart';
import 'package:threebotlogin/providers/wallets_provider.dart';
import 'package:threebotlogin/screens/scan_screen.dart';
Expand Down Expand Up @@ -256,7 +257,7 @@ class _WalletSendScreenState extends State<WalletSendScreen> {
const TextInputType.numberWithOptions(decimal: true),
controller: amountController,
decoration: InputDecoration(
labelText: 'Amount (Balance: $balance)',
labelText: 'Amount (Balance: ${formatAmount(balance)})',
hintText: '100',
suffixText: 'TFT',
errorText: amountError)),
Expand Down
7 changes: 4 additions & 3 deletions app/lib/screens/wallets/wallet_assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stellar_client/models/vesting_account.dart';
import 'package:threebotlogin/helpers/globals.dart';
import 'package:threebotlogin/helpers/transaction_helpers.dart';
import 'package:threebotlogin/models/wallet.dart';
import 'package:threebotlogin/providers/wallets_provider.dart';
import 'package:threebotlogin/screens/wallets/receive.dart';
Expand Down Expand Up @@ -77,7 +78,7 @@ class _WalletAssetsWidgetState extends State<WalletAssetsWidget> {
),
WalletBalanceTileWidget(
name: 'Stellar',
balance: vestedWallets![0].tft.toString(),
balance: formatAmount(vestedWallets![0].tft.toString()),
loading: false,
),
];
Expand Down Expand Up @@ -171,14 +172,14 @@ class _WalletAssetsWidgetState extends State<WalletAssetsWidget> {
if (double.parse(widget.wallet.stellarBalance) >= 0)
WalletBalanceTileWidget(
name: 'Stellar',
balance: widget.wallet.stellarBalance,
balance: formatAmount(widget.wallet.stellarBalance),
loading: stellarBalaceLoading,
),
const SizedBox(height: 10),
if (double.parse(widget.wallet.tfchainBalance) >= 0)
WalletBalanceTileWidget(
name: 'TFChain',
balance: widget.wallet.tfchainBalance,
balance: formatAmount(widget.wallet.tfchainBalance),
loading: tfchainBalaceLoading,
),
const SizedBox(
Expand Down
4 changes: 2 additions & 2 deletions app/lib/widgets/wallets/transaction.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:stellar_client/models/transaction.dart';
import 'package:threebotlogin/helpers/transaction_helpers.dart';
import 'package:threebotlogin/screens/wallets/transaction_details.dart';
import 'package:threebotlogin/widgets/wallets/arrow_inward.dart';

Expand Down Expand Up @@ -54,8 +55,7 @@ class TransactionWidget extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
'TFT ${double.parse(transaction.amount).toStringAsFixed(2)}',
child: Text('TFT ${formatAmount(transaction.amount)}',
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
Expand Down
3 changes: 2 additions & 1 deletion app/lib/widgets/wallets/transaction_details.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:stellar_client/models/transaction.dart';
import 'package:threebotlogin/helpers/transaction_helpers.dart';

class TransactionDetails extends StatelessWidget {
final PaymentTransaction transaction;
Expand Down Expand Up @@ -75,7 +76,7 @@ class TransactionDetails extends StatelessWidget {
const Divider(),
buildDetailRow('Type', transaction.type.name),
const Divider(),
buildDetailRow('Amount', transaction.amount),
buildDetailRow('Amount', formatAmount(transaction.amount)),
const Divider(),
buildDetailRow('Asset', transaction.asset),
const Divider(),
Expand Down
5 changes: 3 additions & 2 deletions app/lib/widgets/wallets/wallet_card.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:threebotlogin/helpers/globals.dart';
import 'package:threebotlogin/helpers/logger.dart';
import 'package:threebotlogin/helpers/transaction_helpers.dart';
import 'package:threebotlogin/models/wallet.dart';
import 'package:threebotlogin/screens/wallets/wallet_details.dart';
import 'package:threebotlogin/services/stellar_service.dart' as StellarService;
Expand Down Expand Up @@ -107,7 +108,7 @@ class _WalletCardWidgetState extends State<WalletCardWidget> {
),
const Spacer(),
Text(
'${widget.wallet.stellarBalance} TFT',
'${formatAmount(widget.wallet.stellarBalance)} TFT',
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: Theme.of(context).colorScheme.onSecondaryContainer,
),
Expand All @@ -132,7 +133,7 @@ class _WalletCardWidgetState extends State<WalletCardWidget> {
),
const Spacer(),
Text(
'${widget.wallet.tfchainBalance} TFT',
'${formatAmount(widget.wallet.tfchainBalance)} TFT',
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: Theme.of(context).colorScheme.onSecondaryContainer,
),
Expand Down
Loading