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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-05-09 23:59:26 +00:00
|
|
|
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';
|
2024-11-21 15:40:40 +00:00
|
|
|
|
2024-05-23 00:37:06 +00:00
|
|
|
import '../../../models/isar/models/blockchain_data/v2/transaction_v2.dart';
|
|
|
|
import '../../../models/isar/models/isar_models.dart';
|
|
|
|
import '../../../models/isar/stack_theme.dart';
|
|
|
|
import '../../../providers/global/wallets_provider.dart';
|
|
|
|
import '../../../themes/theme_providers.dart';
|
|
|
|
import '../../../utilities/assets.dart';
|
|
|
|
import '../../../wallets/crypto_currency/crypto_currency.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2023-04-27 13:22:08 +00:00
|
|
|
class TxIcon extends ConsumerWidget {
|
2023-01-12 04:26:38 +00:00
|
|
|
const TxIcon({
|
2024-05-15 21:20:45 +00:00
|
|
|
super.key,
|
2023-01-10 23:53:09 +00:00
|
|
|
required this.transaction,
|
|
|
|
required this.currentHeight,
|
|
|
|
required this.coin,
|
2024-05-15 21:20:45 +00:00
|
|
|
});
|
2023-01-10 23:53:09 +00:00
|
|
|
|
2023-10-19 21:36:47 +00:00
|
|
|
final Object transaction;
|
2023-01-10 23:53:09 +00:00
|
|
|
final int currentHeight;
|
2024-05-15 21:20:45 +00:00
|
|
|
final CryptoCurrency coin;
|
2023-01-10 23:53:09 +00:00
|
|
|
|
|
|
|
static const Size size = Size(32, 32);
|
|
|
|
|
|
|
|
String _getAssetName(
|
2023-10-19 21:36:47 +00:00
|
|
|
bool isCancelled,
|
|
|
|
bool isReceived,
|
|
|
|
bool isPending,
|
|
|
|
TransactionSubType subType,
|
2023-12-29 16:30:37 +00:00
|
|
|
TransactionType type,
|
2023-10-19 21:36:47 +00:00
|
|
|
IThemeAssets assets,
|
|
|
|
) {
|
|
|
|
if (subType == TransactionSubType.cashFusion) {
|
2023-10-20 16:38:47 +00:00
|
|
|
return Assets.svg.txCashFusion;
|
2023-10-19 21:36:47 +00:00
|
|
|
}
|
|
|
|
|
2023-12-29 16:30:37 +00:00
|
|
|
if ((!isReceived && subType == TransactionSubType.mint) ||
|
|
|
|
(subType == TransactionSubType.sparkMint &&
|
|
|
|
type == TransactionType.sentToSelf)) {
|
2023-12-16 16:19:50 +00:00
|
|
|
if (isCancelled) {
|
|
|
|
return Assets.svg.anonymizeFailed;
|
|
|
|
}
|
|
|
|
if (isPending) {
|
|
|
|
return Assets.svg.anonymizePending;
|
|
|
|
}
|
|
|
|
return Assets.svg.anonymize;
|
|
|
|
}
|
|
|
|
|
2023-01-10 23:53:09 +00:00
|
|
|
if (isReceived) {
|
|
|
|
if (isCancelled) {
|
2023-09-20 18:19:39 +00:00
|
|
|
return assets.receiveCancelled;
|
2023-01-10 23:53:09 +00:00
|
|
|
}
|
|
|
|
if (isPending) {
|
2023-04-27 22:56:17 +00:00
|
|
|
return assets.receivePending;
|
2023-01-10 23:53:09 +00:00
|
|
|
}
|
2023-04-27 22:56:17 +00:00
|
|
|
return assets.receive;
|
2023-01-10 23:53:09 +00:00
|
|
|
} else {
|
|
|
|
if (isCancelled) {
|
2023-04-27 22:56:17 +00:00
|
|
|
return assets.sendCancelled;
|
2023-01-10 23:53:09 +00:00
|
|
|
}
|
|
|
|
if (isPending) {
|
2023-04-27 22:56:17 +00:00
|
|
|
return assets.sendPending;
|
2023-01-10 23:53:09 +00:00
|
|
|
}
|
2023-04-27 22:56:17 +00:00
|
|
|
return assets.send;
|
2023-01-10 23:53:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-04-27 13:22:08 +00:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-10-19 21:36:47 +00:00
|
|
|
final bool txIsReceived;
|
|
|
|
final String assetName;
|
2023-01-10 23:53:09 +00:00
|
|
|
|
2023-10-19 21:36:47 +00:00
|
|
|
if (transaction is Transaction) {
|
|
|
|
final tx = transaction as Transaction;
|
|
|
|
txIsReceived = tx.type == TransactionType.incoming;
|
|
|
|
assetName = _getAssetName(
|
|
|
|
tx.isCancelled,
|
|
|
|
txIsReceived,
|
|
|
|
!tx.isConfirmed(
|
|
|
|
currentHeight,
|
2023-11-08 22:09:28 +00:00
|
|
|
ref.watch(pWallets).getWallet(tx.walletId).cryptoCurrency.minConfirms,
|
2023-10-19 21:36:47 +00:00
|
|
|
),
|
|
|
|
tx.subType,
|
2023-12-29 16:30:37 +00:00
|
|
|
tx.type,
|
2023-10-19 21:36:47 +00:00
|
|
|
ref.watch(themeAssetsProvider),
|
|
|
|
);
|
|
|
|
} else if (transaction is TransactionV2) {
|
|
|
|
final tx = transaction as TransactionV2;
|
|
|
|
txIsReceived = tx.type == TransactionType.incoming;
|
|
|
|
assetName = _getAssetName(
|
|
|
|
false,
|
|
|
|
txIsReceived,
|
|
|
|
!tx.isConfirmed(
|
|
|
|
currentHeight,
|
2023-11-08 22:09:28 +00:00
|
|
|
ref.watch(pWallets).getWallet(tx.walletId).cryptoCurrency.minConfirms,
|
2024-11-21 15:40:40 +00:00
|
|
|
ref
|
|
|
|
.watch(pWallets)
|
|
|
|
.getWallet(tx.walletId)
|
|
|
|
.cryptoCurrency
|
|
|
|
.minCoinbaseConfirms,
|
2023-10-19 21:36:47 +00:00
|
|
|
),
|
|
|
|
tx.subType,
|
2023-12-29 16:30:37 +00:00
|
|
|
tx.type,
|
2023-10-19 21:36:47 +00:00
|
|
|
ref.watch(themeAssetsProvider),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
throw ArgumentError(
|
|
|
|
"Unknown transaction type ${transaction.runtimeType}",
|
|
|
|
);
|
|
|
|
}
|
2023-05-09 23:59:26 +00:00
|
|
|
|
2023-01-10 23:53:09 +00:00
|
|
|
return SizedBox(
|
|
|
|
width: size.width,
|
|
|
|
height: size.height,
|
|
|
|
child: Center(
|
2023-10-19 21:36:47 +00:00
|
|
|
// 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(
|
2023-05-09 23:59:26 +00:00
|
|
|
assetName,
|
2023-10-19 21:36:47 +00:00
|
|
|
),
|
|
|
|
width: size.width,
|
|
|
|
height: size.height,
|
|
|
|
),
|
|
|
|
),
|
2023-01-10 23:53:09 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|