stack_wallet/lib/pages/wallet_view/sub_widgets/tx_icon.dart

103 lines
2.7 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
import 'dart:io';
2022-08-26 08:11:35 +00:00
import 'package:flutter/cupertino.dart';
2023-04-27 22:56:17 +00:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
2022-08-26 08:11:35 +00:00
import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart';
2023-05-09 16:24:11 +00:00
import 'package:stackwallet/models/isar/stack_theme.dart';
import 'package:stackwallet/themes/theme_providers.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
2022-08-26 08:11:35 +00:00
class TxIcon extends ConsumerWidget {
const TxIcon({
Key? key,
required this.transaction,
required this.currentHeight,
required this.coin,
}) : super(key: key);
final Transaction transaction;
final int currentHeight;
final Coin coin;
static const Size size = Size(32, 32);
String _getAssetName(
2023-05-18 18:52:48 +00:00
bool isCancelled, bool isReceived, bool isPending, IThemeAssets assets) {
if (!isReceived && transaction.subType == TransactionSubType.mint) {
if (isCancelled) {
return Assets.svg.anonymizeFailed;
}
if (isPending) {
return Assets.svg.anonymizePending;
}
return Assets.svg.anonymize;
}
if (isReceived) {
if (isCancelled) {
return assets.receiveCancelled;
}
if (isPending) {
2023-04-27 22:56:17 +00:00
return assets.receivePending;
}
2023-04-27 22:56:17 +00:00
return assets.receive;
} else {
if (isCancelled) {
2023-04-27 22:56:17 +00:00
return assets.sendCancelled;
}
if (isPending) {
2023-04-27 22:56:17 +00:00
return assets.sendPending;
}
2023-04-27 22:56:17 +00:00
return assets.send;
}
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final txIsReceived = transaction.type == TransactionType.incoming;
final assetName = _getAssetName(
transaction.isCancelled,
txIsReceived,
!transaction.isConfirmed(
currentHeight,
coin.requiredConfirmations,
),
2023-05-18 18:52:48 +00:00
ref.watch(themeAssetsProvider),
);
return SizedBox(
width: size.width,
height: size.height,
child: Center(
// if it starts with "assets" we assume its local
// TODO: a more thorough check
child: assetName.startsWith("assets")
? SvgPicture.asset(
assetName,
width: size.width,
height: size.height,
)
: SvgPicture.file(
File(
assetName,
),
width: size.width,
height: size.height,
)),
);
}
}