mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +00:00
rough epic cash refactor
This commit is contained in:
parent
f43ae8788d
commit
cb7e63ba3b
10 changed files with 1309 additions and 1507 deletions
|
@ -57,6 +57,14 @@ class TransactionV2 {
|
|||
required this.otherData,
|
||||
});
|
||||
|
||||
bool get isEpiccashTransaction =>
|
||||
_getFromOtherData(key: "isEpiccashTransaction") == true;
|
||||
int? get numberOfMessages =>
|
||||
_getFromOtherData(key: "numberOfMessages") as int?;
|
||||
String? get slateId => _getFromOtherData(key: "slateId") as String?;
|
||||
String? get onChainNote => _getFromOtherData(key: "onChainNote") as String?;
|
||||
bool get isCancelled => _getFromOtherData(key: "isCancelled") == true;
|
||||
|
||||
int getConfirmations(int currentChainHeight) {
|
||||
if (height == null || height! <= 0) return 0;
|
||||
return max(0, currentChainHeight - (height! - 1));
|
||||
|
@ -146,35 +154,35 @@ class TransactionV2 {
|
|||
}
|
||||
}
|
||||
|
||||
// if (coin == Coin.epicCash) {
|
||||
// if (_transaction.isCancelled) {
|
||||
// return "Cancelled";
|
||||
// } else if (type == TransactionType.incoming) {
|
||||
// if (isConfirmed(height, minConfirms)) {
|
||||
// return "Received";
|
||||
// } else {
|
||||
// if (_transaction.numberOfMessages == 1) {
|
||||
// return "Receiving (waiting for sender)";
|
||||
// } else if ((_transaction.numberOfMessages ?? 0) > 1) {
|
||||
// return "Receiving (waiting for confirmations)"; // TODO test if the sender still has to open again after the receiver has 2 messages present, ie. sender->receiver->sender->node (yes) vs. sender->receiver->node (no)
|
||||
// } else {
|
||||
// return "Receiving";
|
||||
// }
|
||||
// }
|
||||
// } else if (type == TransactionType.outgoing) {
|
||||
// if (isConfirmed(height, minConfirms)) {
|
||||
// return "Sent (confirmed)";
|
||||
// } else {
|
||||
// if (_transaction.numberOfMessages == 1) {
|
||||
// return "Sending (waiting for receiver)";
|
||||
// } else if ((_transaction.numberOfMessages ?? 0) > 1) {
|
||||
// return "Sending (waiting for confirmations)";
|
||||
// } else {
|
||||
// return "Sending";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (isEpiccashTransaction) {
|
||||
if (isCancelled) {
|
||||
return "Cancelled";
|
||||
} else if (type == TransactionType.incoming) {
|
||||
if (isConfirmed(currentChainHeight, minConfirms)) {
|
||||
return "Received";
|
||||
} else {
|
||||
if (numberOfMessages == 1) {
|
||||
return "Receiving (waiting for sender)";
|
||||
} else if ((numberOfMessages ?? 0) > 1) {
|
||||
return "Receiving (waiting for confirmations)"; // TODO test if the sender still has to open again after the receiver has 2 messages present, ie. sender->receiver->sender->node (yes) vs. sender->receiver->node (no)
|
||||
} else {
|
||||
return "Receiving";
|
||||
}
|
||||
}
|
||||
} else if (type == TransactionType.outgoing) {
|
||||
if (isConfirmed(currentChainHeight, minConfirms)) {
|
||||
return "Sent (confirmed)";
|
||||
} else {
|
||||
if (numberOfMessages == 1) {
|
||||
return "Sending (waiting for receiver)";
|
||||
} else if ((numberOfMessages ?? 0) > 1) {
|
||||
return "Sending (waiting for confirmations)";
|
||||
} else {
|
||||
return "Sending";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == TransactionType.incoming) {
|
||||
// if (_transaction.isMinting) {
|
||||
|
@ -198,6 +206,14 @@ class TransactionV2 {
|
|||
}
|
||||
}
|
||||
|
||||
dynamic _getFromOtherData({required dynamic key}) {
|
||||
if (otherData == null) {
|
||||
return null;
|
||||
}
|
||||
final map = jsonDecode(otherData!);
|
||||
return map[key];
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TransactionV2(\n'
|
||||
|
|
|
@ -30,7 +30,6 @@ import 'package:stackwallet/pages/settings_views/wallet_settings_view/wallet_set
|
|||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||
import 'package:stackwallet/providers/ui/transaction_filter_provider.dart';
|
||||
import 'package:stackwallet/route_generator.dart';
|
||||
import 'package:stackwallet/services/coins/epiccash/epiccash_wallet.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/node_connection_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
|
@ -40,6 +39,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|||
import 'package:stackwallet/utilities/show_loading.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
import 'package:stackwallet/wallets/wallet/impl/epiccash_wallet.dart';
|
||||
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/mnemonic_interface.dart';
|
||||
import 'package:stackwallet/widgets/background.dart';
|
||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||
|
@ -470,11 +470,11 @@ class _EpiBoxInfoFormState extends ConsumerState<EpicBoxInfoForm> {
|
|||
final hostController = TextEditingController();
|
||||
final portController = TextEditingController();
|
||||
|
||||
late EpicCashWallet wallet;
|
||||
late EpiccashWallet wallet;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
wallet = ref.read(pWallets).getWallet(widget.walletId) as EpicCashWallet;
|
||||
wallet = ref.read(pWallets).getWallet(widget.walletId) as EpiccashWallet;
|
||||
|
||||
wallet.getEpicBoxConfig().then((EpicBoxConfigModel epicBoxConfig) {
|
||||
hostController.text = epicBoxConfig.host;
|
||||
|
|
|
@ -26,7 +26,6 @@ import 'package:stackwallet/pages/wallet_view/wallet_view.dart';
|
|||
import 'package:stackwallet/providers/db/main_db_provider.dart';
|
||||
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/services/coins/epiccash/epiccash_wallet.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
|
@ -39,6 +38,7 @@ import 'package:stackwallet/utilities/logger.dart';
|
|||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
|
||||
import 'package:stackwallet/wallets/wallet/impl/epiccash_wallet.dart';
|
||||
import 'package:stackwallet/widgets/background.dart';
|
||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||
|
@ -1592,7 +1592,7 @@ class _TransactionDetailsViewState
|
|||
onPressed: () async {
|
||||
final wallet = ref.read(pWallets).getWallet(walletId);
|
||||
|
||||
if (wallet is EpicCashWallet) {
|
||||
if (wallet is EpiccashWallet) {
|
||||
final String? id = _transaction.slateId;
|
||||
if (id == null) {
|
||||
unawaited(showFloatingFlushBar(
|
||||
|
@ -1610,8 +1610,8 @@ class _TransactionDetailsViewState
|
|||
const CancellingTransactionProgressDialog(),
|
||||
));
|
||||
|
||||
final result = await (wallet as EpicCashWallet)
|
||||
.cancelPendingTransactionAndPost(id);
|
||||
final result =
|
||||
await wallet.cancelPendingTransactionAndPost(id);
|
||||
if (mounted) {
|
||||
// pop progress dialog
|
||||
Navigator.of(context).pop();
|
||||
|
|
|
@ -19,7 +19,9 @@ import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart'
|
|||
import 'package:stackwallet/models/isar/models/blockchain_data/v2/transaction_v2.dart';
|
||||
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
||||
import 'package:stackwallet/pages/wallet_view/sub_widgets/tx_icon.dart';
|
||||
import 'package:stackwallet/pages/wallet_view/transaction_views/dialogs/cancelling_transaction_progress_dialog.dart';
|
||||
import 'package:stackwallet/pages/wallet_view/transaction_views/edit_note_view.dart';
|
||||
import 'package:stackwallet/pages/wallet_view/wallet_view.dart';
|
||||
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
|
@ -34,6 +36,7 @@ import 'package:stackwallet/utilities/logger.dart';
|
|||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
|
||||
import 'package:stackwallet/wallets/wallet/impl/epiccash_wallet.dart';
|
||||
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
|
||||
import 'package:stackwallet/widgets/background.dart';
|
||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||
|
@ -1448,7 +1451,68 @@ class _TransactionV2DetailsViewState
|
|||
// ],
|
||||
// ),
|
||||
// ),
|
||||
|
||||
if (coin == Coin.epicCash)
|
||||
isDesktop
|
||||
? const _Divider()
|
||||
: const SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
if (coin == Coin.epicCash)
|
||||
RoundedWhiteContainer(
|
||||
padding: isDesktop
|
||||
? const EdgeInsets.all(16)
|
||||
: const EdgeInsets.all(12),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Slate ID",
|
||||
style: isDesktop
|
||||
? STextStyles
|
||||
.desktopTextExtraExtraSmall(
|
||||
context)
|
||||
: STextStyles.itemSubtitle(
|
||||
context),
|
||||
),
|
||||
// Flexible(
|
||||
// child: FittedBox(
|
||||
// fit: BoxFit.scaleDown,
|
||||
// child:
|
||||
SelectableText(
|
||||
_transaction.slateId ?? "Unknown",
|
||||
style: isDesktop
|
||||
? STextStyles
|
||||
.desktopTextExtraExtraSmall(
|
||||
context)
|
||||
.copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textDark,
|
||||
)
|
||||
: STextStyles.itemSubtitle12(
|
||||
context),
|
||||
),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
if (isDesktop)
|
||||
const SizedBox(
|
||||
width: 12,
|
||||
),
|
||||
if (isDesktop)
|
||||
IconCopyButton(
|
||||
data: _transaction.slateId ?? "Unknown",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!isDesktop)
|
||||
const SizedBox(
|
||||
height: 12,
|
||||
|
@ -1463,6 +1527,98 @@ class _TransactionV2DetailsViewState
|
|||
],
|
||||
),
|
||||
),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||
floatingActionButton: (coin == Coin.epicCash &&
|
||||
_transaction.getConfirmations(currentHeight) < 1 &&
|
||||
_transaction.isCancelled == false)
|
||||
? ConditionalParent(
|
||||
condition: isDesktop,
|
||||
builder: (child) => Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 32,
|
||||
vertical: 16,
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
child: SizedBox(
|
||||
width: MediaQuery.of(context).size.width - 32,
|
||||
child: TextButton(
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.all<Color>(
|
||||
Theme.of(context).extension<StackColors>()!.textError,
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
final wallet = ref.read(pWallets).getWallet(walletId);
|
||||
|
||||
if (wallet is EpiccashWallet) {
|
||||
final String? id = _transaction.slateId;
|
||||
if (id == null) {
|
||||
unawaited(showFloatingFlushBar(
|
||||
type: FlushBarType.warning,
|
||||
message: "Could not find Epic transaction ID",
|
||||
context: context,
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
unawaited(
|
||||
showDialog<void>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (_) =>
|
||||
const CancellingTransactionProgressDialog(),
|
||||
),
|
||||
);
|
||||
|
||||
final result =
|
||||
await wallet.cancelPendingTransactionAndPost(id);
|
||||
if (mounted) {
|
||||
// pop progress dialog
|
||||
Navigator.of(context).pop();
|
||||
|
||||
if (result.isEmpty) {
|
||||
await showDialog<dynamic>(
|
||||
context: context,
|
||||
builder: (_) => StackOkDialog(
|
||||
title: "Transaction cancelled",
|
||||
onOkPressed: (_) {
|
||||
wallet.refresh();
|
||||
Navigator.of(context).popUntil(
|
||||
ModalRoute.withName(
|
||||
WalletView.routeName,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
await showDialog<dynamic>(
|
||||
context: context,
|
||||
builder: (_) => StackOkDialog(
|
||||
title: "Failed to cancel transaction",
|
||||
message: result,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unawaited(showFloatingFlushBar(
|
||||
type: FlushBarType.warning,
|
||||
message: "ERROR: Wallet type is not Epic Cash",
|
||||
context: context,
|
||||
));
|
||||
return;
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
"Cancel Transaction",
|
||||
style: STextStyles.button(context),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import 'package:stackwallet/models/balance.dart';
|
|||
import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models;
|
||||
import 'package:stackwallet/models/node_model.dart';
|
||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||
import 'package:stackwallet/services/coins/epiccash/epiccash_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/ethereum/ethereum_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/namecoin/namecoin_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/particl/particl_wallet.dart';
|
||||
|
@ -101,13 +100,7 @@ abstract class CoinServiceAPI {
|
|||
throw UnimplementedError("moved");
|
||||
|
||||
case Coin.epicCash:
|
||||
return EpicCashWallet(
|
||||
walletId: walletId,
|
||||
walletName: walletName,
|
||||
coin: coin,
|
||||
secureStore: secureStorageInterface,
|
||||
// tracker: tracker,
|
||||
);
|
||||
throw UnimplementedError("moved");
|
||||
|
||||
case Coin.ethereum:
|
||||
return EthereumWallet(
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -13,7 +13,6 @@ import 'package:flutter_libmonero/wownero/wownero.dart';
|
|||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/db/hive/db.dart';
|
||||
import 'package:stackwallet/db/isar/main_db.dart';
|
||||
import 'package:stackwallet/services/coins/epiccash/epiccash_wallet.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/services/notifications_service.dart';
|
||||
import 'package:stackwallet/services/trade_sent_from_stack_service.dart';
|
||||
|
@ -24,6 +23,7 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
|||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
|
||||
import 'package:stackwallet/wallets/wallet/impl/epiccash_wallet.dart';
|
||||
import 'package:stackwallet/wallets/wallet/wallet.dart';
|
||||
|
||||
class Wallets {
|
||||
|
|
|
@ -15,12 +15,12 @@ import 'package:flutter_libmonero/monero/monero.dart';
|
|||
import 'package:flutter_libmonero/wownero/wownero.dart';
|
||||
import 'package:stackwallet/db/hive/db.dart';
|
||||
import 'package:stackwallet/db/isar/main_db.dart';
|
||||
import 'package:stackwallet/services/coins/epiccash/epiccash_wallet.dart';
|
||||
import 'package:stackwallet/services/notifications_service.dart';
|
||||
import 'package:stackwallet/services/trade_sent_from_stack_service.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/wallets/wallet/impl/epiccash_wallet.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class WalletInfo {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,6 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
|
||||
|
||||
|
@ -23,6 +24,18 @@ extension EpiccashWalletInfoExtension on WalletInfo {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateExtraEpiccashWalletInfo({
|
||||
required ExtraEpiccashWalletInfo epicData,
|
||||
required Isar isar,
|
||||
}) async {
|
||||
await updateOtherData(
|
||||
newEntries: {
|
||||
WalletInfoKeys.epiccashData: jsonEncode(epicData.toMap()),
|
||||
},
|
||||
isar: isar,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Holds data previously stored in hive
|
||||
|
|
Loading…
Reference in a new issue