Skip to content

Commit

Permalink
currency - units - lbtc lsats ui
Browse files Browse the repository at this point in the history
  • Loading branch information
mocodesmo committed Apr 18, 2024
1 parent 3aeac89 commit 4caa061
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 32 deletions.
2 changes: 2 additions & 0 deletions lib/_model/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Wallet with _$Wallet {
// Address? getLastAddress() =>
// baseWalletType == BaseWalletType.Bitcoin ? lastGeneratedAddress : lastGeneratedLiqAddress;

bool isLiquid() => baseWalletType == BaseWalletType.Liquid;

Wallet setLastAddress(Address address) {
return copyWith(lastGeneratedAddress: address);
}
Expand Down
17 changes: 10 additions & 7 deletions lib/currency/bloc/currency_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,28 @@ class CurrencyState with _$CurrencyState {
String getAmountInUnits(
int amount, {
bool? isSats,
bool isLiquid = false,
bool removeText = false,
bool hideZero = false,
bool removeEndZeros = false,
}) {
String amt = '';
final btcStr = isLiquid ? 'L-BTC' : 'BTC';
final satsStr = isLiquid ? 'L-sats' : 'sats';
if (isSats ?? unitsInSats)
amt = satsFormatting(amount.toString()) + ' sats';
amt = satsFormatting(amount.toString()) + ' $satsStr';
else {
String b = '';
if (!removeEndZeros)
b = (amount / 100000000).toStringAsFixed(8);
else
b = (amount / 100000000).toStringAsFixed(8);
amt = b + ' BTC';
amt = b + ' $btcStr';
}

if (removeText) {
amt = amt.replaceAll(' sats', '');
amt = amt.replaceAll(' BTC', '');
amt = amt.replaceAll(' $satsStr', '');
amt = amt.replaceAll(' $btcStr', '');
}

if (hideZero && amount == 0) amt = '';
Expand All @@ -83,9 +86,9 @@ class CurrencyState with _$CurrencyState {
return amt;
}

String getUnitString() {
if (unitsInSats) return 'sats';
return 'BTC';
String getUnitString({bool isLiquid = false}) {
if (unitsInSats) return isLiquid ? 'L-sats' : 'sats';
return isLiquid ? 'L-BTC' : 'BTC';
}

int getSatsAmount(String amount, bool? unitsInSatss) {
Expand Down
3 changes: 2 additions & 1 deletion lib/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ class CardItem extends StatelessWidget {

final balance =
context.select((CurrencyCubit x) => x.state.getAmountInUnits(sats, removeText: true));
final unit = context.select((CurrencyCubit x) => x.state.getUnitString());
final unit =
context.select((CurrencyCubit x) => x.state.getUnitString(isLiquid: wallet.isLiquid()));

final fiatCurrency = context.select((CurrencyCubit x) => x.state.defaultFiatCurrency);

Expand Down
15 changes: 11 additions & 4 deletions lib/home/transactions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ class HomeTxItem2 extends StatelessWidget {
x.state.getAmountInUnits(tx.getAmount(sentAsTotal: true), removeText: true),
);

final units = context.select((CurrencyCubit x) => x.state.getUnitString());
final units = context.select(
(CurrencyCubit x) => x.state.getUnitString(isLiquid: tx.wallet?.isLiquid() ?? false),
);

final darkMode =
context.select((Lighting x) => x.state.currentTheme(context) == ThemeMode.dark);
Expand All @@ -222,7 +224,7 @@ class HomeTxItem2 extends StatelessWidget {

final amt = '${isReceive ? '' : ''}${amount.replaceAll("-", "")}';

final wallet = tx.wallet;
final wallet = tx.wallet!;

return InkWell(
onTap: () {
Expand Down Expand Up @@ -276,7 +278,7 @@ class HomeTxItem2 extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
if (wallet != null) ...[
...[
WalletTag(wallet: wallet),
const Gap(2),
],
Expand Down Expand Up @@ -318,7 +320,12 @@ class _SwapTxHomeListItem extends StatelessWidget {
if (swap == null) return const SizedBox.shrink();

final amt = swap.outAmount;
final amount = context.select((CurrencyCubit x) => x.state.getAmountInUnits(amt));
final amount = context.select(
(CurrencyCubit x) => x.state.getAmountInUnits(
amt,
isLiquid: transaction.wallet?.isLiquid() ?? false,
),
);
final isReceive = !swap.isSubmarine;

// final invoice = swap.invoice;
Expand Down
14 changes: 7 additions & 7 deletions lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:bb_mobile/home/transactions.dart';
import 'package:bb_mobile/import/page.dart';
import 'package:bb_mobile/locator.dart';
import 'package:bb_mobile/receive/receive_page.dart';
import 'package:bb_mobile/seeds/seeds_page.dart';
// import 'package:bb_mobile/seeds/seeds_page.dart';
import 'package:bb_mobile/send/send_page.dart';
import 'package:bb_mobile/settings/broadcast.dart';
import 'package:bb_mobile/settings/settings_page.dart';
Expand Down Expand Up @@ -63,12 +63,12 @@ final GoRouter router = GoRouter(
return const ImportWalletPage();
},
),
GoRoute(
path: '/seed-view',
builder: (context, state) {
return const SeedViewPage();
},
),
// GoRoute(
// path: '/seed-view',
// builder: (context, state) {
// return const SeedViewPage();
// },
// ),
GoRoute(
path: '/create-wallet-main',
builder: (context, state) {
Expand Down
2 changes: 1 addition & 1 deletion lib/transaction/transaction_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class _TxDetails extends StatelessWidget {
(CurrencyCubit cubit) => cubit.state.getAmountInUnits(fees, removeText: true),
);
final units = context.select(
(CurrencyCubit cubit) => cubit.state.getUnitString(),
(CurrencyCubit cubit) => cubit.state.getUnitString(isLiquid: tx.wallet?.isLiquid() ?? false),
);
final status = tx.timestamp == 0 ? 'Pending' : 'Confirmed';
final time = tx.timestamp == 0 ? 'Waiting for confirmations' : timeago.format(tx.getDateTime());
Expand Down
3 changes: 2 additions & 1 deletion lib/wallet/wallet_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class WalletCardDetails extends StatelessWidget {

final balance =
context.select((CurrencyCubit x) => x.state.getAmountInUnits(sats, removeText: true));
final unit = context.select((CurrencyCubit x) => x.state.getUnitString());
final unit =
context.select((CurrencyCubit x) => x.state.getUnitString(isLiquid: wallet.isLiquid()));

final fiatCurrency = context.select((CurrencyCubit x) => x.state.defaultFiatCurrency);

Expand Down
14 changes: 10 additions & 4 deletions lib/wallet/wallet_txs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,18 @@ class HomeTxItem extends StatelessWidget {
Widget build(BuildContext context) {
final label = tx.label ?? '';

final amount = context
.select((CurrencyCubit x) => x.state.getAmountInUnits(tx.getAmount(sentAsTotal: true)));
final amount = context.select(
(CurrencyCubit x) => x.state.getAmountInUnits(
tx.getAmount(
sentAsTotal: true,
),
isLiquid: tx.wallet?.isLiquid() ?? false,
),
);

final isReceive = tx.isReceived();

final amt = '${isReceive ? '' : ''}${amount.replaceAll("-", "")}';
// final amt = '${isReceive ? '' : ''}${amount.replaceAll("-", "")}';

return InkWell(
onTap: () {
Expand All @@ -133,7 +139,7 @@ class HomeTxItem extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
BBText.titleLarge(amt),
BBText.titleLarge(amount),
if (label.isNotEmpty) ...[
const Gap(4),
BBText.bodySmall(label),
Expand Down
14 changes: 7 additions & 7 deletions lib/wallet_settings/wallet_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,11 @@ class Balances extends StatelessWidget {

@override
Widget build(BuildContext context) {
final amtSent = context.select(
(WalletBloc cubit) => cubit.state.wallet!.totalSent(),
);
final wallet = context.select((WalletBloc cubit) => cubit.state.wallet!);

final amtReceived = context.select(
(WalletBloc cubit) => cubit.state.wallet!.totalReceived(),
);
final amtSent = wallet.totalSent();

final amtReceived = wallet.totalReceived();

final inAmt = context.select(
(CurrencyCubit x) => x.state.getAmountInUnits(amtReceived, removeText: true),
Expand All @@ -307,7 +305,9 @@ class Balances extends StatelessWidget {
(CurrencyCubit x) => x.state.getAmountInUnits(amtSent, removeText: true),
);

final units = context.select((CurrencyCubit x) => x.state.getUnitString());
final units = context.select(
(CurrencyCubit x) => x.state.getUnitString(isLiquid: wallet.isLiquid()),
);

return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
Expand Down

0 comments on commit 4caa061

Please sign in to comment.