Skip to content

Commit

Permalink
fix transactions for native token
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Malochka committed Dec 19, 2024
1 parent 3027042 commit 2b4f5d6
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:app/feature/wallet/wallet.dart';
import 'package:app/generated/generated.dart';
import 'package:app/utils/utils.dart';
import 'package:app/widgets/transaction_icon.dart';
import 'package:flutter/material.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:nekoton_repository/nekoton_repository.dart';
Expand All @@ -12,7 +13,8 @@ class TokenWalletTransactionWidget extends StatelessWidget {
const TokenWalletTransactionWidget({
required this.transaction,
required this.transactionValue,
required this.displayDate,
required this.isFirst,
required this.isLast,
required this.transactionFee,
required this.price,
required this.rootTokenContract,
Expand All @@ -32,14 +34,15 @@ class TokenWalletTransactionWidget extends StatelessWidget {
/// If date of this transaction must be displayed.
/// This is external decision that could use comparing this transaction and
/// prev one.
final bool displayDate;
final bool isFirst;
final bool isLast;
final Fixed price;
final Address rootTokenContract;

@override
Widget build(BuildContext context) {
final theme = context.themeStyleV2;
final date = displayDate ? _headerDate(theme) : null;
final date = isFirst ? _headerDate(theme) : null;

final body = PressScaleWidget(
onPressed: () => Navigator.of(context, rootNavigator: true).push(
Expand All @@ -52,18 +55,20 @@ class TokenWalletTransactionWidget extends StatelessWidget {
),
),
),
child: Material(
shape: const SquircleShapeBorder(cornerRadius: DimensRadiusV2.radius16),
color: theme.colors.background2,
child: Container(
decoration: BoxDecoration(
color: theme.colors.background1,
borderRadius: BorderRadius.vertical(
top: Radius.circular(isFirst ? DimensRadiusV2.radius16 : 0),
bottom: Radius.circular(isLast ? DimensRadiusV2.radius16 : 0),
),
),
child: _baseTransactionBody(theme),
),
);

return date == null
? Padding(
padding: const EdgeInsets.only(top: DimensSizeV2.d8),
child: body,
)
? body
: SeparatedColumn(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
Expand Down Expand Up @@ -114,26 +119,41 @@ class TokenWalletTransactionWidget extends StatelessWidget {
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
isIncoming
? LucideIcons.arrowDown
: LucideIcons.arrowUp,
color: isIncoming
? theme.colors.contentPositive
: theme.colors.content0,
size: DimensSizeV2.d16,
TransactionIcon(
isIncoming: isIncoming,
icon: isIncoming
? LucideIcons.arrowDownLeft
: LucideIcons.arrowUpRight,
),
const SizedBox(width: DimensSizeV2.d8),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
isIncoming ? 'Received' : 'Sent',
style: theme.textStyles.labelSmall,
AmountWidget.fromMoney(
amount: transactionValue,
includeSymbol: false,
sign: isIncoming
? LocaleKeys.plusSign.tr()
: LocaleKeys.minusSign.tr(),
style: theme.textStyles.labelXSmall.copyWith(
color: isIncoming
? theme.colors.contentPositive
: theme.colors.content0,
),
),
const SizedBox(height: DimensSizeV2.d4),
Text(
transaction.address.toEllipseString(),
isIncoming
? LocaleKeys.fromWord.tr(
args: [
transaction.address.toEllipseString(),
],
)
: LocaleKeys.toWord.tr(
args: [
transaction.address.toEllipseString(),
],
),
style: theme.textStyles.labelXSmall.copyWith(
color: theme.colors.content3,
),
Expand All @@ -149,19 +169,7 @@ class TokenWalletTransactionWidget extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
AmountWidget.fromMoney(
amount: transactionValue,
includeSymbol: false,
sign: isIncoming
? LocaleKeys.plusSign.tr()
: LocaleKeys.minusSign.tr(),
style: theme.textStyles.labelXSmall.copyWith(
color: isIncoming
? theme.colors.contentPositive
: theme.colors.content0,
),
),
const SizedBox(height: DimensSizeV2.d4),
const SizedBox(height: DimensSizeV2.d14),
Text(
transactionTimeFormatter.format(transaction.date),
style: theme.textStyles.labelXSmall.copyWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,24 @@ class TokenWalletTransactionsWidget extends StatelessWidget {
);
}

final trans = transactions[index];

final prev = index == 0 ? null : transactions[index - 1];
final displayDate =
final trans = transactions[index];
final next = index == transactions.length - 1
? null
: transactions[index + 1];
final isFirst =
prev == null || !prev.date.isSameDay(trans.date);
final isLast =
next == null || !next.date.isSameDay(trans.date);

final ticker = inject<NekotonRepository>()
.currentTransport
.nativeTokenTicker;

return TokenWalletTransactionWidget(
transaction: trans,
displayDate: displayDate,
isFirst: isFirst,
isLast: isLast,
transactionFee: Money.fromBigIntWithCurrency(
trans.fees,
Currencies()[ticker]!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TonWalletMultisigPendingTransactionWidget extends StatelessWidget {
],
),
),
icon: LucideIcons.timer,
icon: transaction.canConfirm ? LucideIcons.timer : LucideIcons.loader,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:app/feature/wallet/widgets/account_transactions_tab/widgets/ton_wallet_transaction_status_body.dart';
import 'package:app/generated/generated.dart';
import 'package:app/utils/utils.dart';
import 'package:app/widgets/transaction_icon.dart';
import 'package:flutter/material.dart';
import 'package:nekoton_repository/nekoton_repository.dart';
import 'package:ui_components_lib/ui_components_lib.dart';
Expand Down Expand Up @@ -223,53 +224,3 @@ class TonWalletTransactionWidget extends StatelessWidget {
}
}
}

class TransactionIcon extends StatelessWidget {
const TransactionIcon({
required this.status,
required this.isIncoming,
required this.icon,
super.key,
});

final TonWalletTransactionStatus status;
final bool isIncoming;
final IconData icon;

@override
Widget build(BuildContext context) {
final theme = context.themeStyleV2;
return Container(
height: DimensSizeV2.d40,
width: DimensSizeV2.d40,
decoration: BoxDecoration(
color: theme.colors.backgroundAlpha,
shape: BoxShape.circle,
),
child: Center(
child: Icon(
icon,
size: DimensSizeV2.d20,
color: _getColor(theme, status, isIncoming),
),
),
);
}

Color _getColor(
ThemeStyleV2 theme,
TonWalletTransactionStatus status,
bool isIncoming,
) {
if (status == TonWalletTransactionStatus.waitingConfirmation) {
return theme.colors.contentWarning;
} else if (status == TonWalletTransactionStatus.pending ||
status == TonWalletTransactionStatus.expired) {
return theme.colors.content0;
} else if (isIncoming) {
return theme.colors.contentPositive;
} else {
return theme.colors.content0;
}
}
}
55 changes: 55 additions & 0 deletions lib/widgets/transaction_icon.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'package:app/feature/wallet/widgets/account_transactions_tab/widgets/ton_wallet_transaction_status_body.dart';
import 'package:flutter/material.dart';
import 'package:ui_components_lib/v2/ui_components_lib_v2.dart';

class TransactionIcon extends StatelessWidget {
const TransactionIcon({
required this.isIncoming,
required this.icon,
this.status,
this.size,
super.key,
});

final TonWalletTransactionStatus? status;
final bool isIncoming;
final IconData icon;
final double? size;

@override
Widget build(BuildContext context) {
final theme = context.themeStyleV2;
return Container(
height: size ?? DimensSizeV2.d40,
width: size ?? DimensSizeV2.d40,
decoration: BoxDecoration(
color: theme.colors.backgroundAlpha,
shape: BoxShape.circle,
),
child: Center(
child: Icon(
icon,
size: DimensSizeV2.d20,
color: _getColor(theme, status, isIncoming),
),
),
);
}

Color _getColor(
ThemeStyleV2 theme,
TonWalletTransactionStatus? status,
bool isIncoming,
) {
if (status == TonWalletTransactionStatus.waitingConfirmation) {
return theme.colors.contentWarning;
} else if (status == TonWalletTransactionStatus.pending ||
status == TonWalletTransactionStatus.expired) {
return theme.colors.content0;
} else if (isIncoming) {
return theme.colors.contentPositive;
} else {
return theme.colors.content0;
}
}
}

0 comments on commit 2b4f5d6

Please sign in to comment.