Merge branch 'main' into CW-621-Open-external-sites-in-default-browser

This commit is contained in:
Serhii
2024-07-05 12:23:56 +03:00
466 changed files with 30584 additions and 11999 deletions
@@ -41,6 +41,7 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store {
case WalletType.tron:
return true;
case WalletType.monero:
case WalletType.wownero:
case WalletType.none:
case WalletType.bitcoin:
case WalletType.litecoin:
@@ -51,7 +52,7 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store {
}
}
bool get hasSeedTypeOption => type == WalletType.monero;
bool get hasSeedTypeOption => type == WalletType.monero || type == WalletType.wownero;
@computed
bool get addCustomNode => _addCustomNode;
@@ -150,6 +150,7 @@ abstract class AnonInvoicePageViewModelBase with Store {
await sharedPreferences.setString(PreferencesKey.clearnetDonationLink, result.clearnetUrl);
await sharedPreferences.setString(PreferencesKey.onionDonationLink, result.onionUrl);
await sharedPreferences.setString(PreferencesKey.donationLinkWalletName, _wallet.name);
state = ExecutedSuccessfullyState(payload: result);
}
@@ -163,10 +164,13 @@ abstract class AnonInvoicePageViewModelBase with Store {
maximum = limit.max != null ? limit.max! / 4 : null;
}
@computed
String get currentWalletName => _wallet.name;
@action
void reset() {
selectedCurrency = walletTypeToCryptoCurrency(_wallet.type);
cryptoCurrency = walletTypeToCryptoCurrency(_wallet.type);
cryptoCurrency = walletTypeToCryptoCurrency(_wallet.type);
receipientEmail = '';
receipientName = '';
description = '';
@@ -177,7 +181,10 @@ abstract class AnonInvoicePageViewModelBase with Store {
Future<void> _getPreviousDonationLink() async {
if (pageOption == ReceivePageOption.anonPayDonationLink) {
final donationLink = sharedPreferences.getString(PreferencesKey.clearnetDonationLink);
if (donationLink != null) {
final donationLinkWalletName =
sharedPreferences.getString(PreferencesKey.donationLinkWalletName);
if (donationLink != null && currentWalletName == donationLinkWalletName) {
final url = Uri.parse(donationLink);
url.queryParameters.forEach((key, value) {
if (key == 'name') receipientName = value;
+4 -2
View File
@@ -4,6 +4,8 @@ import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/core/secure_storage.dart';
import 'package:cake_wallet/entities/secret_store_key.dart';
import 'package:cake_wallet/store/secret_store.dart';
import 'package:cw_core/root_dir.dart';
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:intl/intl.dart';
import 'package:cake_wallet/wallet_type_utils.dart';
@@ -72,7 +74,7 @@ abstract class BackupViewModelBase with Store {
}
Future<String> saveBackupFileLocally(BackupExportFile backup) async {
final appDir = await getApplicationDocumentsDirectory();
final appDir = await getAppDir();
final path = '${appDir.path}/${backup.name}';
final backupFile = File(path);
await backupFile.writeAsBytes(backup.content);
@@ -80,7 +82,7 @@ abstract class BackupViewModelBase with Store {
}
Future<void> removeBackupFileLocally(BackupExportFile backup) async {
final appDir = await getApplicationDocumentsDirectory();
final appDir = await getAppDir();
final path = '${appDir.path}/${backup.name}';
final backupFile = File(path);
await backupFile.delete();
@@ -0,0 +1,20 @@
import 'package:cake_wallet/cake_pay/cake_pay_service.dart';
import 'package:mobx/mobx.dart';
part 'cake_pay_account_view_model.g.dart';
class CakePayAccountViewModel = CakePayAccountViewModelBase with _$CakePayAccountViewModel;
abstract class CakePayAccountViewModelBase with Store {
CakePayAccountViewModelBase({required this.cakePayService}) : email = '' {
cakePayService.getUserEmail().then((email) => this.email = email ?? '');
}
final CakePayService cakePayService;
@observable
String email;
@action
Future<void> logout() async => cakePayService.logout(email);
}
@@ -0,0 +1,51 @@
import 'package:cake_wallet/cake_pay/cake_pay_states.dart';
import 'package:cake_wallet/cake_pay/cake_pay_service.dart';
import 'package:mobx/mobx.dart';
part 'cake_pay_auth_view_model.g.dart';
class CakePayAuthViewModel = CakePayAuthViewModelBase with _$CakePayAuthViewModel;
abstract class CakePayAuthViewModelBase with Store {
CakePayAuthViewModelBase({required this.cakePayService})
: userVerificationState = CakePayUserVerificationStateInitial(),
otpState = CakePayOtpSendDisabled(),
email = '',
otp = '';
final CakePayService cakePayService;
@observable
CakePayUserVerificationState userVerificationState;
@observable
CakePayOtpState otpState;
@observable
String email;
@observable
String otp;
@action
Future<void> verifyEmail(String code) async {
try {
otpState = CakePayOtpValidating();
await cakePayService.verifyEmail(code);
otpState = CakePayOtpSuccess();
} catch (_) {
otpState = CakePayOtpFailure(error: 'Invalid OTP. Try again');
}
}
@action
Future<void> logIn(String email) async {
try {
userVerificationState = CakePayUserVerificationStateLoading();
await cakePayService.logIn(email);
userVerificationState = CakePayUserVerificationStateSuccess();
} catch (e) {
userVerificationState = CakePayUserVerificationStateFailure(error: e.toString());
}
}
}
@@ -0,0 +1,48 @@
import 'package:cake_wallet/cake_pay/cake_pay_card.dart';
import 'package:cake_wallet/cake_pay/cake_pay_vendor.dart';
import 'package:mobx/mobx.dart';
part 'cake_pay_buy_card_view_model.g.dart';
class CakePayBuyCardViewModel = CakePayBuyCardViewModelBase with _$CakePayBuyCardViewModel;
abstract class CakePayBuyCardViewModelBase with Store {
CakePayBuyCardViewModelBase({required this.vendor})
: amount = vendor.card!.denominations.isNotEmpty
? double.parse(vendor.card!.denominations.first)
: 0,
quantity = 1,
min = double.parse(vendor.card!.minValue ?? '0'),
max = double.parse(vendor.card!.maxValue ?? '0'),
card = vendor.card!;
final CakePayVendor vendor;
final CakePayCard card;
final double min;
final double max;
bool get isDenominationSelected => card.denominations.isNotEmpty;
@observable
double amount;
@observable
int quantity;
@computed
bool get isEnablePurchase =>
(amount >= min && amount <= max) || (isDenominationSelected && quantity > 0);
@computed
double get totalAmount => amount * quantity;
@action
void onQuantityChanged(int? input) => quantity = input ?? 1;
@action
void onAmountChanged(String input) {
if (input.isEmpty) return;
amount = double.parse(input.replaceAll(',', '.'));
}
}
@@ -0,0 +1,221 @@
import 'package:cake_wallet/cake_pay/cake_pay_service.dart';
import 'package:cake_wallet/cake_pay/cake_pay_states.dart';
import 'package:cake_wallet/cake_pay/cake_pay_vendor.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/view_model/dashboard/dropdown_filter_item.dart';
import 'package:cake_wallet/view_model/dashboard/filter_item.dart';
import 'package:mobx/mobx.dart';
part 'cake_pay_cards_list_view_model.g.dart';
class CakePayCardsListViewModel = CakePayCardsListViewModelBase with _$CakePayCardsListViewModel;
abstract class CakePayCardsListViewModelBase with Store {
CakePayCardsListViewModelBase({
required this.cakePayService,
}) : cardState = CakePayCardsStateNoCards(),
cakePayVendors = [],
availableCountries = [],
page = 1,
selectedCountry = 'USA',
displayPrepaidCards = true,
displayGiftCards = true,
displayDenominationsCards = true,
displayCustomValueCards = true,
scrollOffsetFromTop = 0.0,
vendorsState = InitialCakePayVendorLoadingState(),
createCardState = CakePayCreateCardState(),
searchString = '',
CakePayVendorList = <CakePayVendor>[] {
initialization();
}
void initialization() async {
await getCountries();
selectedCountry = availableCountries.first;
getVendors();
}
final CakePayService cakePayService;
List<CakePayVendor> CakePayVendorList;
Map<String, List<FilterItem>> get createFilterItems => {
S.current.filter_by: [
FilterItem(
value: () => displayPrepaidCards,
caption: S.current.prepaid_cards,
onChanged: togglePrepaidCards),
FilterItem(
value: () => displayGiftCards,
caption: S.current.gift_cards,
onChanged: toggleGiftCards),
],
S.current.value_type: [
FilterItem(
value: () => displayDenominationsCards,
caption: S.current.denominations,
onChanged: toggleDenominationsCards),
FilterItem(
value: () => displayCustomValueCards,
caption: S.current.custom_value,
onChanged: toggleCustomValueCards),
],
S.current.countries: [
DropdownFilterItem(
items: availableCountries,
caption: '',
selectedItem: selectedCountry,
onItemSelected: (String value) => setSelectedCountry(value),
),
]
};
String searchString;
int page;
late String _initialSelectedCountry;
late bool _initialDisplayPrepaidCards;
late bool _initialDisplayGiftCards;
late bool _initialDisplayDenominationsCards;
late bool _initialDisplayCustomValueCards;
@observable
double scrollOffsetFromTop;
@observable
CakePayCreateCardState createCardState;
@observable
CakePayCardsState cardState;
@observable
CakePayVendorState vendorsState;
@observable
bool hasMoreDataToFetch = true;
@observable
bool isLoadingNextPage = false;
@observable
List<CakePayVendor> cakePayVendors;
@observable
List<String> availableCountries;
@observable
bool displayPrepaidCards;
@observable
bool displayGiftCards;
@observable
bool displayDenominationsCards;
@observable
bool displayCustomValueCards;
@observable
String selectedCountry;
bool get hasFiltersChanged =>
selectedCountry != _initialSelectedCountry ||
displayPrepaidCards != _initialDisplayPrepaidCards ||
displayGiftCards != _initialDisplayGiftCards ||
displayDenominationsCards != _initialDisplayDenominationsCards ||
displayCustomValueCards != _initialDisplayCustomValueCards;
Future<void> getCountries() async {
availableCountries = await cakePayService.getCountries();
}
@action
Future<void> getVendors({
String? text,
int? currentPage,
}) async {
vendorsState = CakePayVendorLoadingState();
searchString = text ?? '';
var newVendors = await cakePayService.getVendors(
country: selectedCountry,
page: currentPage ?? page,
search: searchString,
giftCards: displayGiftCards,
prepaidCards: displayPrepaidCards,
custom: displayCustomValueCards,
onDemand: displayDenominationsCards);
cakePayVendors = CakePayVendorList = newVendors;
vendorsState = CakePayVendorLoadedState();
}
@action
Future<void> fetchNextPage() async {
if (vendorsState is CakePayVendorLoadingState || !hasMoreDataToFetch || isLoadingNextPage)
return;
isLoadingNextPage = true;
page++;
try {
var newVendors = await cakePayService.getVendors(
country: selectedCountry,
page: page,
search: searchString,
giftCards: displayGiftCards,
prepaidCards: displayPrepaidCards,
custom: displayCustomValueCards,
onDemand: displayDenominationsCards);
cakePayVendors.addAll(newVendors);
} catch (error) {
if (error.toString().contains('detail":"Invalid page."')) {
hasMoreDataToFetch = false;
}
} finally {
isLoadingNextPage = false;
}
}
Future<bool> isCakePayUserAuthenticated() async {
return await cakePayService.isLogged();
}
void resetLoadingNextPageState() {
hasMoreDataToFetch = true;
page = 1;
}
void storeInitialFilterStates() {
_initialSelectedCountry = selectedCountry;
_initialDisplayPrepaidCards = displayPrepaidCards;
_initialDisplayGiftCards = displayGiftCards;
_initialDisplayDenominationsCards = displayDenominationsCards;
_initialDisplayCustomValueCards = displayCustomValueCards;
}
@action
void setSelectedCountry(String country) => selectedCountry = country;
@action
void togglePrepaidCards() => displayPrepaidCards = !displayPrepaidCards;
@action
void toggleGiftCards() => displayGiftCards = !displayGiftCards;
@action
void toggleDenominationsCards() => displayDenominationsCards = !displayDenominationsCards;
@action
void toggleCustomValueCards() => displayCustomValueCards = !displayCustomValueCards;
void setScrollOffsetFromTop(double scrollOffset) {
scrollOffsetFromTop = scrollOffset;
}
}
@@ -0,0 +1,162 @@
import 'dart:async';
import 'package:cake_wallet/cake_pay/cake_pay_card.dart';
import 'package:cake_wallet/cake_pay/cake_pay_order.dart';
import 'package:cake_wallet/cake_pay/cake_pay_payment_credantials.dart';
import 'package:cake_wallet/cake_pay/cake_pay_service.dart';
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/view_model/send/send_view_model.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
part 'cake_pay_purchase_view_model.g.dart';
class CakePayPurchaseViewModel = CakePayPurchaseViewModelBase with _$CakePayPurchaseViewModel;
abstract class CakePayPurchaseViewModelBase with Store {
CakePayPurchaseViewModelBase({
required this.cakePayService,
required this.paymentCredential,
required this.card,
required this.sendViewModel,
}) : walletType = sendViewModel.walletType;
final WalletType walletType;
final PaymentCredential paymentCredential;
final CakePayCard card;
final SendViewModel sendViewModel;
final CakePayService cakePayService;
CakePayOrder? order;
Timer? _timer;
DateTime? expirationTime;
Duration? remainingTime;
String? get userName => paymentCredential.userName;
double get amount => paymentCredential.amount;
int get quantity => paymentCredential.quantity;
double get totalAmount => paymentCredential.totalAmount;
String get fiatCurrency => paymentCredential.fiatCurrency;
CryptoPaymentData? get cryptoPaymentData {
if (order == null) return null;
if (WalletType.monero == walletType) {
return order!.paymentData.xmr;
}
if (WalletType.bitcoin == walletType) {
final paymentUrls = order!.paymentData.btc.paymentUrls!.bip21;
final uri = Uri.parse(paymentUrls!);
final address = uri.path;
final price = uri.queryParameters['amount'];
return CryptoPaymentData(
address: address,
price: price ?? '0',
);
}
return null;
}
@observable
bool isOrderExpired = false;
@observable
String formattedRemainingTime = '';
@action
Future<void> createOrder() async {
if (walletType != WalletType.bitcoin && walletType != WalletType.monero) {
sendViewModel.state = FailureState('Unsupported wallet type, please use Bitcoin or Monero.');
}
try {
order = await cakePayService.createOrder(
cardId: card.id,
price: paymentCredential.amount.toString(),
quantity: paymentCredential.quantity);
await confirmSending();
expirationTime = order!.paymentData.expirationTime;
updateRemainingTime();
_startExpirationTimer();
} catch (e) {
sendViewModel.state = FailureState(
sendViewModel.translateErrorMessage(e, walletType, sendViewModel.wallet.currency));
}
}
@action
Future<void> confirmSending() async {
final cryptoPaymentData = this.cryptoPaymentData;
try {
if (order == null || cryptoPaymentData == null) return;
sendViewModel.clearOutputs();
final output = sendViewModel.outputs.first;
output.address = cryptoPaymentData.address;
output.setCryptoAmount(cryptoPaymentData.price);
await sendViewModel.createTransaction();
} catch (e) {
throw e;
}
}
@action
void updateRemainingTime() {
if (expirationTime == null) {
formattedRemainingTime = '';
return;
}
remainingTime = expirationTime!.difference(DateTime.now());
isOrderExpired = remainingTime!.isNegative;
if (isOrderExpired) {
disposeExpirationTimer();
sendViewModel.state = FailureState('Order has expired.');
} else {
formattedRemainingTime = formatDuration(remainingTime!);
}
}
void _startExpirationTimer() {
_timer?.cancel();
_timer = Timer.periodic(Duration(seconds: 1), (_) {
updateRemainingTime();
});
}
String formatDuration(Duration duration) {
final hours = duration.inHours;
final minutes = duration.inMinutes.remainder(60);
final seconds = duration.inSeconds.remainder(60);
return '${hours.toString().padLeft(2, '0')}:${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}';
}
void disposeExpirationTimer() {
_timer?.cancel();
remainingTime = null;
formattedRemainingTime = '';
expirationTime = null;
}
void dispose() {
disposeExpirationTimer();
}
}
@@ -39,7 +39,7 @@ abstract class ContactListViewModelBase with Store {
));
}
});
} else if (info.addresses?.isNotEmpty == true) {
} else if (info.addresses?.isNotEmpty == true && info.addresses!.length > 1) {
info.addresses!.forEach((address, label) {
if (label.isEmpty) {
return;
@@ -125,6 +125,7 @@ abstract class BalanceViewModelBase with Store {
String get availableBalanceLabel {
switch (wallet.type) {
case WalletType.monero:
case WalletType.wownero:
case WalletType.haven:
case WalletType.ethereum:
case WalletType.polygon:
@@ -142,6 +143,7 @@ abstract class BalanceViewModelBase with Store {
String get additionalBalanceLabel {
switch (wallet.type) {
case WalletType.monero:
case WalletType.wownero:
case WalletType.haven:
case WalletType.ethereum:
case WalletType.polygon:
@@ -1,4 +1,4 @@
import 'package:cake_wallet/ionia/ionia_service.dart';
import 'package:cake_wallet/cake_pay/cake_pay_service.dart';
import 'package:mobx/mobx.dart';
part 'cake_features_view_model.g.dart';
@@ -6,11 +6,11 @@ part 'cake_features_view_model.g.dart';
class CakeFeaturesViewModel = CakeFeaturesViewModelBase with _$CakeFeaturesViewModel;
abstract class CakeFeaturesViewModelBase with Store {
final IoniaService _ioniaService;
final CakePayService _cakePayService;
CakeFeaturesViewModelBase(this._ioniaService);
CakeFeaturesViewModelBase(this._cakePayService);
Future<bool> isIoniaUserAuthenticated() async {
return await _ioniaService.isLogined();
return await _cakePayService.isLogged();
}
}
@@ -303,6 +303,7 @@ abstract class DashboardViewModelBase with Store {
bool get hasRescan =>
wallet.type == WalletType.bitcoin ||
wallet.type == WalletType.monero ||
wallet.type == WalletType.wownero ||
wallet.type == WalletType.haven;
@computed
@@ -532,6 +533,11 @@ abstract class DashboardViewModelBase with Store {
@action
void setSyncAll(bool value) => settingsStore.currentSyncAll = value;
Future<List<String>> checkForHavenWallets() async {
final walletInfoSource = await CakeHive.openBox<WalletInfo>(WalletInfo.boxName);
return walletInfoSource.values.where((element) => element.type == WalletType.haven).map((e) => e.name).toList();
}
Future<List<String>> checkAffectedWallets() async {
try {
// await load file
@@ -0,0 +1,19 @@
import 'package:cake_wallet/view_model/dashboard/filter_item.dart';
class DropdownFilterItem extends FilterItem {
DropdownFilterItem({
required this.items,
required this.caption,
required this.selectedItem,
required this.onItemSelected,
}) : super(
value: () => false,
caption: caption,
onChanged: (_) {},
);
final List<String> items;
final String caption;
final String selectedItem;
final Function(String) onItemSelected;
}
@@ -0,0 +1,68 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:cake_wallet/themes/extensions/picker_theme.dart';
import 'package:flutter/material.dart';
class DropdownFilterList extends StatefulWidget {
DropdownFilterList({
Key? key,
required this.items,
this.itemPrefix,
this.textStyle,
required this.caption,
required this.selectedItem,
required this.onItemSelected,
}) : super(key: key);
final List<String> items;
final String? itemPrefix;
final TextStyle? textStyle;
final String caption;
final String selectedItem;
final Function(String) onItemSelected;
@override
_DropdownFilterListState createState() => _DropdownFilterListState();
}
class _DropdownFilterListState extends State<DropdownFilterList> {
String? selectedValue;
@override
void initState() {
super.initState();
selectedValue = widget.selectedItem;
}
@override
Widget build(BuildContext context) {
return DropdownButtonHideUnderline(
child: Container(
child: DropdownButton<String>(
isExpanded: true,
icon: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(Icons.arrow_drop_down, color: Theme.of(context).extension<PickerTheme>()!.searchIconColor),
],
),
),
dropdownColor: Theme.of(context).extension<PickerTheme>()!.searchBackgroundFillColor,
borderRadius: BorderRadius.circular(10),
items: widget.items
.map((item) => DropdownMenuItem<String>(
alignment: Alignment.bottomCenter,
value: item,
child: AutoSizeText('${widget.itemPrefix ?? ''} $item', style: widget.textStyle),
))
.toList(),
value: selectedValue,
onChanged: (newValue) {
setState(() => selectedValue = newValue);
widget.onItemSelected(newValue!);
},
),
),
);
}
}
@@ -144,10 +144,12 @@ abstract class HomeSettingsViewModelBase with Store {
if (_balanceViewModel.wallet.type == WalletType.ethereum) {
ethereum!.addErc20Token(_balanceViewModel.wallet, token as Erc20Token);
if (!value) ethereum!.removeTokenTransactionsInHistory(_balanceViewModel.wallet, token);
}
if (_balanceViewModel.wallet.type == WalletType.polygon) {
polygon!.addErc20Token(_balanceViewModel.wallet, token as Erc20Token);
if (!value) polygon!.removeTokenTransactionsInHistory(_balanceViewModel.wallet, token);
}
if (_balanceViewModel.wallet.type == WalletType.solana) {
@@ -7,6 +7,7 @@ import 'package:cake_wallet/polygon/polygon.dart';
import 'package:cake_wallet/reactions/wallet_connect.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/wownero/wownero.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/transaction_info.dart';
@@ -55,8 +56,14 @@ class TransactionListItem extends ActionListItem with Keyable {
}
String get formattedPendingStatus {
if (transaction.confirmations >= 0 && transaction.confirmations < 10) {
return ' (${transaction.confirmations}/10)';
if (balanceViewModel.wallet.type == WalletType.monero || balanceViewModel.wallet.type == WalletType.haven) {
if (transaction.confirmations >= 0 && transaction.confirmations < 10) {
return ' (${transaction.confirmations}/10)';
}
} else if (balanceViewModel.wallet.type == WalletType.wownero) {
if (transaction.confirmations >= 0 && transaction.confirmations < 3) {
return ' (${transaction.confirmations}/3)';
}
}
return '';
}
@@ -64,6 +71,7 @@ class TransactionListItem extends ActionListItem with Keyable {
String get formattedStatus {
if (transaction.direction == TransactionDirection.incoming) {
if (balanceViewModel.wallet.type == WalletType.monero ||
balanceViewModel.wallet.type == WalletType.wownero ||
balanceViewModel.wallet.type == WalletType.haven) {
return formattedPendingStatus;
}
@@ -95,7 +103,7 @@ class TransactionListItem extends ActionListItem with Keyable {
} catch (e) {
return null;
}
return null;
}
@@ -108,6 +116,11 @@ class TransactionListItem extends ActionListItem with Keyable {
cryptoAmount: monero!.formatterMoneroAmountToDouble(amount: transaction.amount),
price: price);
break;
case WalletType.wownero:
amount = calculateFiatAmountRaw(
cryptoAmount: wownero!.formatterWowneroAmountToDouble(amount: transaction.amount),
price: price);
break;
case WalletType.bitcoin:
case WalletType.litecoin:
case WalletType.bitcoinCash:
@@ -287,6 +287,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
bool get isLowFee {
switch (wallet.type) {
case WalletType.monero:
case WalletType.wownero:
case WalletType.haven:
return transactionPriority == monero!.getMoneroTransactionPrioritySlow();
case WalletType.bitcoin:
@@ -670,6 +671,10 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
depositCurrency = CryptoCurrency.nano;
receiveCurrency = CryptoCurrency.xmr;
break;
case WalletType.banano:
depositCurrency = CryptoCurrency.banano;
receiveCurrency = CryptoCurrency.xmr;
break;
case WalletType.polygon:
depositCurrency = CryptoCurrency.maticpoly;
receiveCurrency = CryptoCurrency.xmr;
@@ -682,7 +687,11 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
depositCurrency = CryptoCurrency.trx;
receiveCurrency = CryptoCurrency.xmr;
break;
default:
case WalletType.wownero:
depositCurrency = CryptoCurrency.wow;
receiveCurrency = CryptoCurrency.xmr;
break;
case WalletType.none:
break;
}
}
@@ -755,6 +764,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
switch (wallet.type) {
case WalletType.monero:
case WalletType.haven:
case WalletType.wownero:
_settingsStore.priority[wallet.type] = monero!.getMoneroTransactionPriorityAutomatic();
break;
case WalletType.bitcoin:
@@ -1,50 +0,0 @@
import 'package:cake_wallet/ionia/ionia_create_state.dart';
import 'package:cake_wallet/ionia/ionia_service.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
part 'ionia_account_view_model.g.dart';
class IoniaAccountViewModel = IoniaAccountViewModelBase with _$IoniaAccountViewModel;
abstract class IoniaAccountViewModelBase with Store {
IoniaAccountViewModelBase({required this.ioniaService})
: email = '',
giftCards = [],
merchantState = InitialIoniaMerchantLoadingState() {
ioniaService.getUserEmail().then((email) => this.email = email);
updateUserGiftCards();
}
final IoniaService ioniaService;
@observable
String email;
@observable
List<IoniaGiftCard> giftCards;
@observable
IoniaMerchantState merchantState;
@computed
int get countOfMerch => giftCards.where((giftCard) => !giftCard.isEmpty).length;
@computed
List<IoniaGiftCard> get activeMechs => giftCards.where((giftCard) => !giftCard.isEmpty).toList();
@computed
List<IoniaGiftCard> get redeemedMerchs => giftCards.where((giftCard) => giftCard.isEmpty).toList();
@action
void logout() {
ioniaService.logout();
}
@action
Future<void> updateUserGiftCards() async {
merchantState = IoniaLoadingMerchantState();
giftCards = await ioniaService.getCurrentUserGiftCardSummaries();
merchantState = IoniaLoadedMerchantState();
}
}
@@ -1,69 +0,0 @@
import 'package:cake_wallet/ionia/ionia_create_state.dart';
import 'package:cake_wallet/ionia/ionia_service.dart';
import 'package:mobx/mobx.dart';
part 'ionia_auth_view_model.g.dart';
class IoniaAuthViewModel = IoniaAuthViewModelBase with _$IoniaAuthViewModel;
abstract class IoniaAuthViewModelBase with Store {
IoniaAuthViewModelBase({required this.ioniaService}):
createUserState = IoniaInitialCreateState(),
signInState = IoniaInitialCreateState(),
otpState = IoniaOtpSendDisabled(),
email = '',
otp = '';
final IoniaService ioniaService;
@observable
IoniaCreateAccountState createUserState;
@observable
IoniaCreateAccountState signInState;
@observable
IoniaOtpState otpState;
@observable
String email;
@observable
String otp;
@action
Future<void> verifyEmail(String code) async {
try {
otpState = IoniaOtpValidating();
await ioniaService.verifyEmail(code);
otpState = IoniaOtpSuccess();
} catch (_) {
otpState = IoniaOtpFailure(error: 'Invalid OTP. Try again');
}
}
@action
Future<void> createUser(String email) async {
try {
createUserState = IoniaCreateStateLoading();
await ioniaService.createUser(email);
createUserState = IoniaCreateStateSuccess();
} catch (e) {
createUserState = IoniaCreateStateFailure(error: e.toString());
}
}
@action
Future<void> signIn(String email) async {
try {
signInState = IoniaCreateStateLoading();
await ioniaService.signIn(email);
signInState = IoniaCreateStateSuccess();
} catch (e) {
signInState = IoniaCreateStateFailure(error: e.toString());
}
}
}
@@ -1,30 +0,0 @@
import 'package:cake_wallet/ionia/ionia_merchant.dart';
import 'package:mobx/mobx.dart';
part 'ionia_buy_card_view_model.g.dart';
class IoniaBuyCardViewModel = IoniaBuyCardViewModelBase with _$IoniaBuyCardViewModel;
abstract class IoniaBuyCardViewModelBase with Store {
IoniaBuyCardViewModelBase({required this.ioniaMerchant})
: isEnablePurchase = false,
amount = 0;
final IoniaMerchant ioniaMerchant;
@observable
double amount;
@observable
bool isEnablePurchase;
@action
void onAmountChanged(String input) {
if (input.isEmpty) return;
amount = double.parse(input.replaceAll(',', '.'));
final min = ioniaMerchant.minimumCardPurchase;
final max = ioniaMerchant.maximumCardPurchase;
isEnablePurchase = amount >= min && amount <= max;
}
}
@@ -1,51 +0,0 @@
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
import 'package:cake_wallet/ionia/ionia_service.dart';
import 'package:mobx/mobx.dart';
part 'ionia_custom_redeem_view_model.g.dart';
class IoniaCustomRedeemViewModel = IoniaCustomRedeemViewModelBase with _$IoniaCustomRedeemViewModel;
abstract class IoniaCustomRedeemViewModelBase with Store {
IoniaCustomRedeemViewModelBase({
required this.giftCard,
required this.ioniaService,
}) : amount = 0,
redeemState = InitialExecutionState();
final IoniaGiftCard giftCard;
final IoniaService ioniaService;
@observable
ExecutionState redeemState;
@observable
double amount;
@computed
double get remaining =>
amount <= giftCard.remainingAmount ? giftCard.remainingAmount - amount : 0;
@computed
String get formattedRemaining => remaining.toStringAsFixed(2);
@computed
bool get disableRedeem => amount > giftCard.remainingAmount;
@action
void updateAmount(String text) {
amount = double.tryParse(text.replaceAll(',', '.')) ?? 0;
}
@action
Future<void> addCustomRedeem() async {
try {
redeemState = IsExecutingState();
await ioniaService.redeem(giftCardId: giftCard.id, amount: amount);
redeemState = ExecutedSuccessfullyState();
} catch (e) {
redeemState = FailureState(e.toString());
}
}
}
@@ -1,34 +0,0 @@
import 'package:cake_wallet/ionia/ionia_merchant.dart';
import 'package:cake_wallet/ionia/ionia_tip.dart';
import 'package:mobx/mobx.dart';
part 'ionia_custom_tip_view_model.g.dart';
class IoniaCustomTipViewModel = IoniaCustomTipViewModelBase with _$IoniaCustomTipViewModel;
abstract class IoniaCustomTipViewModelBase with Store {
IoniaCustomTipViewModelBase({
required this.amount,
required this.tip,
required this.ioniaMerchant})
: customTip = tip,
percentage = 0;
final IoniaMerchant ioniaMerchant;
final double amount;
final IoniaTip tip;
@observable
IoniaTip customTip;
@observable
double percentage;
@action
void onTipChanged(String value){
final _amount = value.isEmpty ? 0 : double.parse(value.replaceAll(',', '.'));
percentage = _amount/amount * 100;
customTip = IoniaTip(percentage: percentage, originalAmount: amount);
}
}
@@ -1,54 +0,0 @@
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/ionia/ionia_service.dart';
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
import 'package:mobx/mobx.dart';
import 'package:device_display_brightness/device_display_brightness.dart';
part 'ionia_gift_card_details_view_model.g.dart';
class IoniaGiftCardDetailsViewModel = IoniaGiftCardDetailsViewModelBase
with _$IoniaGiftCardDetailsViewModel;
abstract class IoniaGiftCardDetailsViewModelBase with Store {
IoniaGiftCardDetailsViewModelBase({required this.ioniaService, required this.giftCard})
: redeemState = InitialExecutionState(),
remainingAmount = giftCard.remainingAmount,
brightness = 0;
final IoniaService ioniaService;
double brightness;
@observable
IoniaGiftCard giftCard;
@observable
double remainingAmount;
@observable
ExecutionState redeemState;
@action
Future<void> redeem() async {
giftCard.remainingAmount = remainingAmount;
try {
redeemState = IsExecutingState();
await ioniaService.redeem(giftCardId: giftCard.id, amount: giftCard.remainingAmount);
giftCard = await ioniaService.getGiftCard(id: giftCard.id);
redeemState = ExecutedSuccessfullyState();
} catch (e) {
redeemState = FailureState(e.toString());
}
}
@action
Future<void> refeshCard() async {
giftCard = await ioniaService.getGiftCard(id: giftCard.id);
remainingAmount = giftCard.remainingAmount;
}
void increaseBrightness() async {
brightness = await DeviceDisplayBrightness.getBrightness();
await DeviceDisplayBrightness.setBrightness(1.0);
}
}
@@ -1,139 +0,0 @@
import 'package:cake_wallet/ionia/ionia_category.dart';
import 'package:cake_wallet/ionia/ionia_service.dart';
import 'package:cake_wallet/ionia/ionia_create_state.dart';
import 'package:cake_wallet/ionia/ionia_merchant.dart';
import 'package:mobx/mobx.dart';
part 'ionia_gift_cards_list_view_model.g.dart';
class IoniaGiftCardsListViewModel = IoniaGiftCardsListViewModelBase with _$IoniaGiftCardsListViewModel;
abstract class IoniaGiftCardsListViewModelBase with Store {
IoniaGiftCardsListViewModelBase({
required this.ioniaService,
}) :
cardState = IoniaNoCardState(),
ioniaMerchants = [],
ioniaCategories = IoniaCategory.allCategories,
selectedIndices = ObservableList<IoniaCategory>.of([IoniaCategory.all]),
scrollOffsetFromTop = 0.0,
merchantState = InitialIoniaMerchantLoadingState(),
createCardState = IoniaCreateCardState(),
searchString = '',
ioniaMerchantList = <IoniaMerchant>[] {
}
final IoniaService ioniaService;
List<IoniaMerchant> ioniaMerchantList;
String searchString;
@observable
double scrollOffsetFromTop;
@observable
IoniaCreateCardState createCardState;
@observable
IoniaFetchCardState cardState;
@observable
IoniaMerchantState merchantState;
@observable
List<IoniaMerchant> ioniaMerchants;
@observable
List<IoniaCategory> ioniaCategories;
@observable
ObservableList<IoniaCategory> selectedIndices;
@action
Future<void> createCard() async {
try {
createCardState = IoniaCreateCardLoading();
await ioniaService.createCard();
createCardState = IoniaCreateCardSuccess();
} catch (e) {
createCardState = IoniaCreateCardFailure(error: e.toString());
}
}
@action
void searchMerchant(String text) {
if (text.isEmpty) {
ioniaMerchants = ioniaMerchantList;
return;
}
searchString = text;
ioniaService.getMerchantsByFilter(search: searchString).then((value) {
ioniaMerchants = value;
});
}
Future<void> _getCard() async {
cardState = IoniaFetchingCard();
try {
final card = await ioniaService.getCard();
cardState = IoniaCardSuccess(card: card);
} catch (_) {
cardState = IoniaFetchCardFailure();
}
}
void getMerchants() {
merchantState = IoniaLoadingMerchantState();
ioniaService.getMerchantsByFilter(categories: selectedIndices).then((value) {
value.sort((a, b) => a.legalName.toLowerCase().compareTo(b.legalName.toLowerCase()));
ioniaMerchants = ioniaMerchantList = value;
merchantState = IoniaLoadedMerchantState();
});
}
@action
void setSelectedFilter(IoniaCategory category) {
if (category == IoniaCategory.all) {
selectedIndices.clear();
selectedIndices.add(category);
return;
}
if (category != IoniaCategory.all) {
selectedIndices.remove(IoniaCategory.all);
}
if (selectedIndices.contains(category)) {
selectedIndices.remove(category);
if (selectedIndices.isEmpty) {
selectedIndices.add(IoniaCategory.all);
}
return;
}
selectedIndices.add(category);
}
@action
void onSearchFilter(String text) {
if (text.isEmpty) {
ioniaCategories = IoniaCategory.allCategories;
} else {
ioniaCategories = IoniaCategory.allCategories
.where((e) => e.title.toLowerCase().contains(text.toLowerCase()),)
.toList();
}
}
@action
void resetIoniaCategories() {
ioniaCategories = IoniaCategory.allCategories;
}
void setScrollOffsetFromTop(double scrollOffset) {
scrollOffsetFromTop = scrollOffset;
}
}
@@ -1,62 +0,0 @@
import 'dart:async';
import 'package:cake_wallet/anypay/any_pay_chain.dart';
import 'package:mobx/mobx.dart';
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/ionia/ionia_service.dart';
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
import 'package:cake_wallet/anypay/any_pay_payment_committed_info.dart';
import 'package:cake_wallet/ionia/ionia_any_pay_payment_info.dart';
part 'ionia_payment_status_view_model.g.dart';
class IoniaPaymentStatusViewModel = IoniaPaymentStatusViewModelBase with _$IoniaPaymentStatusViewModel;
abstract class IoniaPaymentStatusViewModelBase with Store {
IoniaPaymentStatusViewModelBase(
this.ioniaService, {
required this.paymentInfo,
required this.committedInfo})
: error = '' {
_timer = Timer.periodic(updateTime, (timer) async {
await updatePaymentStatus();
if (giftCard != null) {
timer?.cancel();
}
});
}
static const updateTime = Duration(seconds: 3);
final IoniaService ioniaService;
final IoniaAnyPayPaymentInfo paymentInfo;
final AnyPayPaymentCommittedInfo committedInfo;
@observable
IoniaGiftCard? giftCard;
@observable
String error;
Timer? get timer => _timer;
bool get payingByBitcoin => paymentInfo.anyPayPayment.chain == AnyPayChain.btc;
Timer? _timer;
@action
Future<void> updatePaymentStatus() async {
try {
final giftCardId = await ioniaService.getPaymentStatus(
orderId: paymentInfo.ioniaOrder.id,
paymentId: paymentInfo.ioniaOrder.paymentId);
if (giftCardId != null) {
giftCard = await ioniaService.getGiftCard(id: giftCardId);
}
} catch (e) {
error = e.toString();
}
}
}
@@ -1,104 +0,0 @@
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/anypay/any_pay_payment.dart';
import 'package:cake_wallet/anypay/any_pay_payment_committed_info.dart';
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/ionia/ionia_anypay.dart';
import 'package:cake_wallet/ionia/ionia_merchant.dart';
import 'package:cake_wallet/ionia/ionia_tip.dart';
import 'package:cake_wallet/ionia/ionia_any_pay_payment_info.dart';
import 'package:cake_wallet/view_model/send/send_view_model.dart';
part 'ionia_purchase_merch_view_model.g.dart';
class IoniaMerchPurchaseViewModel = IoniaMerchPurchaseViewModelBase with _$IoniaMerchPurchaseViewModel;
abstract class IoniaMerchPurchaseViewModelBase with Store {
IoniaMerchPurchaseViewModelBase({
required this.ioniaAnyPayService,
required this.amount,
required this.ioniaMerchant,
required this.sendViewModel,
}) : tipAmount = 0.0,
percentage = 0.0,
invoiceCreationState = InitialExecutionState(),
invoiceCommittingState = InitialExecutionState(),
tips = <IoniaTip>[
IoniaTip(percentage: 0, originalAmount: amount),
IoniaTip(percentage: 15, originalAmount: amount),
IoniaTip(percentage: 18, originalAmount: amount),
IoniaTip(percentage: 20, originalAmount: amount),
IoniaTip(percentage: 0, originalAmount: amount, isCustom: true),
] {
selectedTip = tips.first;
}
final double amount;
List<IoniaTip> tips;
@observable
IoniaTip? selectedTip;
final IoniaMerchant ioniaMerchant;
final SendViewModel sendViewModel;
final IoniaAnyPay ioniaAnyPayService;
IoniaAnyPayPaymentInfo? paymentInfo;
AnyPayPayment? get invoice => paymentInfo?.anyPayPayment;
AnyPayPaymentCommittedInfo? committedInfo;
@observable
ExecutionState invoiceCreationState;
@observable
ExecutionState invoiceCommittingState;
@observable
double percentage;
@computed
double get giftCardAmount => double.parse((amount + tipAmount).toStringAsFixed(2));
@computed
double get billAmount => double.parse((giftCardAmount * (1 - (ioniaMerchant.discount / 100))).toStringAsFixed(2));
@observable
double tipAmount;
@action
void addTip(IoniaTip tip) {
tipAmount = tip.additionalAmount;
selectedTip = tip;
}
@action
Future<void> createInvoice() async {
try {
invoiceCreationState = IsExecutingState();
paymentInfo = await ioniaAnyPayService.purchase(merchId: ioniaMerchant.id.toString(), amount: giftCardAmount);
invoiceCreationState = ExecutedSuccessfullyState();
} catch (e) {
invoiceCreationState = FailureState(e.toString());
}
}
@action
Future<void> commitPaymentInvoice() async {
try {
if (invoice == null) {
throw Exception('Invoice is created. Invoince is null');
}
invoiceCommittingState = IsExecutingState();
committedInfo = await ioniaAnyPayService.commitInvoice(invoice!);
invoiceCommittingState = ExecutedSuccessfullyState(payload: committedInfo!);
} catch (e) {
invoiceCommittingState = FailureState(e.toString());
}
}
}
@@ -80,6 +80,7 @@ abstract class NodeCreateOrEditViewModelBase with Store {
return true;
case WalletType.none:
case WalletType.monero:
case WalletType.wownero:
case WalletType.haven:
case WalletType.litecoin:
case WalletType.bitcoinCash:
@@ -85,6 +85,9 @@ abstract class NodeListViewModelBase with Store {
case WalletType.tron:
node = getTronDefaultNode(nodes: _nodeSource)!;
break;
case WalletType.wownero:
node = getWowneroDefaultNode(nodes: _nodeSource);
break;
default:
throw Exception('Unexpected wallet type: ${_appStore.wallet!.type}');
}
+18 -1
View File
@@ -7,6 +7,7 @@ import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/view_model/restore/restore_mode.dart';
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
import 'package:cake_wallet/wownero/wownero.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/monero/monero.dart';
@@ -48,7 +49,7 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
@observable
String address;
bool get hasRestorationHeight => type == WalletType.monero;
bool get hasRestorationHeight => type == WalletType.monero || type == WalletType.wownero;
@override
WalletCredentials getCredentialsFromRestoredWallet(
@@ -74,6 +75,15 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
viewKey: restoreWallet.viewKey ?? '',
spendKey: restoreWallet.spendKey ?? '',
height: restoreWallet.height ?? 0);
case WalletType.wownero:
return wownero!.createWowneroRestoreWalletFromKeysCredentials(
name: name,
password: password,
language: 'English',
address: restoreWallet.address ?? '',
viewKey: restoreWallet.viewKey ?? '',
spendKey: restoreWallet.spendKey ?? '',
height: restoreWallet.height ?? 0);
case WalletType.bitcoin:
case WalletType.litecoin:
return bitcoin!.createBitcoinRestoreWalletFromWIFCredentials(
@@ -137,6 +147,13 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
case WalletType.tron:
return tron!.createTronRestoreWalletFromSeedCredentials(
name: name, mnemonic: restoreWallet.mnemonicSeed ?? '', password: password);
case WalletType.wownero:
return wownero!.createWowneroRestoreWalletFromSeedCredentials(
name: name,
height: restoreWallet.height ?? 0,
mnemonic: restoreWallet.mnemonicSeed ?? '',
password: password,
);
default:
throw Exception('Unexpected type: ${type.toString()}');
}
@@ -36,6 +36,9 @@ class WalletRestoreFromQRCode {
'tron': WalletType.tron,
'tron-wallet': WalletType.tron,
'tron_wallet': WalletType.tron,
'wownero': WalletType.wownero,
'wownero-wallet': WalletType.wownero,
'wownero_wallet': WalletType.wownero,
};
static bool _containsAssetSpecifier(String code) => _extractWalletType(code) != null;
@@ -57,7 +60,9 @@ class WalletRestoreFromQRCode {
RegExp _getPattern(int wordCount) =>
RegExp(r'(?<=\W|^)((?:\w+\s+){' + (wordCount - 1).toString() + r'}\w+)(?=\W|$)');
List<int> patternCounts = walletType == WalletType.monero ? [25, 16, 14, 13] : [24, 18, 12];
List<int> patternCounts = walletType == WalletType.monero || walletType == WalletType.wownero
? [25, 16, 14, 13]
: [24, 18, 12];
for (final count in patternCounts) {
final pattern = _getPattern(count);
@@ -132,7 +137,8 @@ class WalletRestoreFromQRCode {
final seedValue = credentials['seed'] as String;
final words = SeedValidator.getWordList(type: type, language: 'english');
if (type == WalletType.monero && Polyseed.isValidSeed(seedValue)) {
if ((type == WalletType.monero || type == WalletType.wownero) &&
Polyseed.isValidSeed(seedValue)) {
return WalletRestoreMode.seed;
}
+11
View File
@@ -9,6 +9,7 @@ import 'package:cake_wallet/reactions/wallet_connect.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/src/screens/send/widgets/extract_address_from_parsed.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/wownero/wownero.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
@@ -100,6 +101,9 @@ abstract class OutputBase with Store {
case WalletType.polygon:
_amount = polygon!.formatterPolygonParseAmount(_cryptoAmount);
break;
case WalletType.wownero:
_amount = wownero!.formatterWowneroParseAmount(amount: _cryptoAmount);
break;
default:
break;
}
@@ -154,6 +158,10 @@ abstract class OutputBase with Store {
return monero!.formatterMoneroAmountToDouble(amount: fee);
}
if (_wallet.type == WalletType.wownero) {
return wownero!.formatterWowneroAmountToDouble(amount: fee);
}
if (_wallet.type == WalletType.haven) {
return haven!.formatterMoneroAmountToDouble(amount: fee);
}
@@ -287,6 +295,9 @@ abstract class OutputBase with Store {
case WalletType.tron:
maximumFractionDigits = 12;
break;
case WalletType.wownero:
maximumFractionDigits = 11;
break;
default:
break;
}
+6
View File
@@ -16,6 +16,7 @@ import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart';
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
import 'package:cake_wallet/view_model/hardware_wallet/ledger_view_model.dart';
import 'package:cake_wallet/wownero/wownero.dart';
import 'package:cw_core/exceptions.dart';
import 'package:cw_core/transaction_priority.dart';
import 'package:cake_wallet/view_model/send/output.dart';
@@ -244,6 +245,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
wallet.type == WalletType.bitcoin ||
wallet.type == WalletType.litecoin ||
wallet.type == WalletType.monero ||
wallet.type == WalletType.wownero ||
wallet.type == WalletType.bitcoinCash;
@computed
@@ -478,6 +480,10 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
return monero!
.createMoneroTransactionCreationCredentials(outputs: outputs, priority: priority!);
case WalletType.wownero:
return wownero!
.createWowneroTransactionCreationCredentials(outputs: outputs, priority: priority!);
case WalletType.haven:
return haven!.createHavenTransactionCreationCredentials(
outputs: outputs, priority: priority!, assetType: selectedCryptoCurrency.title);
@@ -1,8 +1,11 @@
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/entities/provider_types.dart';
import 'package:cake_wallet/entities/priority_for_wallet_type.dart';
import 'package:cake_wallet/entities/provider_types.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/utils/package_info.dart';
// import 'package:package_info/package_info.dart';
import 'package:collection/collection.dart';
import 'package:cw_core/balance.dart';
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/transaction_info.dart';
@@ -10,19 +13,18 @@ import 'package:cw_core/transaction_priority.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
import 'package:package_info/package_info.dart';
import 'package:collection/collection.dart';
part 'other_settings_view_model.g.dart';
class OtherSettingsViewModel = OtherSettingsViewModelBase with _$OtherSettingsViewModel;
class OtherSettingsViewModel = OtherSettingsViewModelBase
with _$OtherSettingsViewModel;
abstract class OtherSettingsViewModelBase with Store {
OtherSettingsViewModelBase(this._settingsStore, this._wallet)
: walletType = _wallet.type,
currentVersion = '' {
PackageInfo.fromPlatform()
.then((PackageInfo packageInfo) => currentVersion = packageInfo.version);
PackageInfo.fromPlatform().then(
(PackageInfo packageInfo) => currentVersion = packageInfo.version);
final priority = _settingsStore.priority[_wallet.type];
final priorities = priorityForWalletType(_wallet.type);
@@ -33,7 +35,8 @@ abstract class OtherSettingsViewModelBase with Store {
}
final WalletType walletType;
final WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> _wallet;
final WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
TransactionInfo> _wallet;
@observable
String currentVersion;
@@ -61,10 +64,12 @@ abstract class OtherSettingsViewModelBase with Store {
_wallet.type == WalletType.tron);
@computed
bool get isEnabledBuyAction => !_settingsStore.disableBuy && _wallet.type != WalletType.haven;
bool get isEnabledBuyAction =>
!_settingsStore.disableBuy && _wallet.type != WalletType.haven;
@computed
bool get isEnabledSellAction => !_settingsStore.disableSell && _wallet.type != WalletType.haven;
bool get isEnabledSellAction =>
!_settingsStore.disableSell && _wallet.type != WalletType.haven;
List<ProviderType> get availableBuyProvidersTypes {
return ProvidersHelper.getAvailableBuyProviderTypes(walletType);
@@ -74,12 +79,12 @@ abstract class OtherSettingsViewModelBase with Store {
ProvidersHelper.getAvailableSellProviderTypes(walletType);
ProviderType get buyProviderType =>
_settingsStore.defaultBuyProviders[walletType] ?? ProviderType.askEachTime;
_settingsStore.defaultBuyProviders[walletType] ??
ProviderType.askEachTime;
ProviderType get sellProviderType =>
_settingsStore.defaultSellProviders[walletType] ?? ProviderType.askEachTime;
_settingsStore.defaultSellProviders[walletType] ??
ProviderType.askEachTime;
String getDisplayPriority(dynamic priority) {
final _priority = priority as TransactionPriority;
@@ -101,7 +106,8 @@ abstract class OtherSettingsViewModelBase with Store {
_wallet.type == WalletType.litecoin ||
_wallet.type == WalletType.bitcoinCash) {
final rate = bitcoin!.getFeeRate(_wallet, _priority);
return bitcoin!.bitcoinTransactionPriorityWithLabel(_priority, rate, customRate: customValue);
return bitcoin!.bitcoinTransactionPriorityWithLabel(_priority, rate,
customRate: customValue);
}
return priority.toString();
@@ -124,7 +130,8 @@ abstract class OtherSettingsViewModelBase with Store {
void onDisplayPrioritySelected(TransactionPriority priority) =>
_settingsStore.priority[walletType] = priority;
void onDisplayBitcoinPrioritySelected(TransactionPriority priority, double customValue) {
void onDisplayBitcoinPrioritySelected(
TransactionPriority priority, double customValue) {
if (_wallet.type == WalletType.bitcoin) {
_settingsStore.customBitcoinFeeRate = customValue.round();
}
@@ -132,12 +139,13 @@ abstract class OtherSettingsViewModelBase with Store {
}
@computed
double get customBitcoinFeeRate => _settingsStore.customBitcoinFeeRate.toDouble();
double get customBitcoinFeeRate =>
_settingsStore.customBitcoinFeeRate.toDouble();
int? get customPriorityItemIndex {
final priorities = priorityForWalletType(walletType);
final customItem = priorities
.firstWhereOrNull((element) => element == bitcoin!.getBitcoinTransactionPriorityCustom());
final customItem = priorities.firstWhereOrNull(
(element) => element == bitcoin!.getBitcoinTransactionPriorityCustom());
return customItem != null ? priorities.indexOf(customItem) : null;
}
@@ -41,6 +41,7 @@ abstract class PrivacySettingsViewModelBase with Store {
bool get isAutoGenerateSubaddressesVisible =>
_wallet.type == WalletType.monero ||
_wallet.type == WalletType.wownero ||
_wallet.type == WalletType.bitcoin ||
_wallet.type == WalletType.litecoin ||
_wallet.type == WalletType.bitcoinCash;
@@ -1,4 +1,5 @@
import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/wownero/wownero.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/wallet_type.dart';
@@ -75,6 +76,9 @@ abstract class TransactionDetailsViewModelBase with Store {
case WalletType.tron:
_addTronListItems(tx, dateFormat);
break;
case WalletType.wownero:
_addWowneroListItems(tx, dateFormat);
break;
default:
break;
}
@@ -167,7 +171,9 @@ abstract class TransactionDetailsViewModelBase with Store {
return 'https://solscan.io/tx/${txId}';
case WalletType.tron:
return 'https://tronscan.org/#/transaction/${txId}';
default:
case WalletType.wownero:
return 'https://explore.wownero.com/tx/${txId}';
case WalletType.none:
return '';
}
}
@@ -195,7 +201,9 @@ abstract class TransactionDetailsViewModelBase with Store {
return S.current.view_transaction_on + 'solscan.io';
case WalletType.tron:
return S.current.view_transaction_on + 'tronscan.org';
default:
case WalletType.wownero:
return S.current.view_transaction_on + 'Wownero.com';
case WalletType.none:
return '';
}
}
@@ -440,4 +448,44 @@ abstract class TransactionDetailsViewModelBase with Store {
String get pendingTransactionFeeFiatAmountFormatted => sendViewModel.isFiatDisabled
? ''
: sendViewModel.pendingTransactionFeeFiatAmount + ' ' + sendViewModel.fiat.title;
void _addWowneroListItems(TransactionInfo tx, DateFormat dateFormat) {
final key = tx.additionalInfo['key'] as String?;
final accountIndex = tx.additionalInfo['accountIndex'] as int;
final addressIndex = tx.additionalInfo['addressIndex'] as int;
final feeFormatted = tx.feeFormatted();
final _items = [
StandartListItem(title: S.current.transaction_details_transaction_id, value: tx.id),
StandartListItem(
title: S.current.transaction_details_date, value: dateFormat.format(tx.date)),
StandartListItem(title: S.current.transaction_details_height, value: '${tx.height}'),
StandartListItem(title: S.current.transaction_details_amount, value: tx.amountFormatted()),
if (feeFormatted != null)
StandartListItem(title: S.current.transaction_details_fee, value: feeFormatted),
if (key?.isNotEmpty ?? false) StandartListItem(title: S.current.transaction_key, value: key!),
];
if (tx.direction == TransactionDirection.incoming) {
try {
final address = wownero!.getTransactionAddress(wallet, accountIndex, addressIndex);
final label = wownero!.getSubaddressLabel(wallet, accountIndex, addressIndex);
if (address.isNotEmpty) {
isRecipientAddressShown = true;
_items.add(StandartListItem(
title: S.current.transaction_details_recipient_address,
value: address,
));
}
if (label.isNotEmpty) {
_items.add(StandartListItem(title: S.current.address_label, value: label));
}
} catch (e) {
print(e.toString());
}
}
items.addAll(_items);
}
}
@@ -2,6 +2,7 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/utils/exception_handler.dart';
import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_item.dart';
import 'package:cake_wallet/wownero/wownero.dart';
import 'package:cw_core/unspent_coins_info.dart';
import 'package:cw_core/unspent_transaction_output.dart';
import 'package:cw_core/wallet_base.dart';
@@ -62,6 +63,8 @@ abstract class UnspentCoinsListViewModelBase with Store {
String formatAmountToString(int fullBalance) {
if (wallet.type == WalletType.monero)
return monero!.formatterMoneroAmountToString(amount: fullBalance);
if (wallet.type == WalletType.wownero)
return wownero!.formatterWowneroAmountToString(amount: fullBalance);
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type))
return bitcoin!.formatterBitcoinAmountToString(amount: fullBalance);
return '';
@@ -71,6 +74,9 @@ abstract class UnspentCoinsListViewModelBase with Store {
if (wallet.type == WalletType.monero) {
await monero!.updateUnspents(wallet);
}
if (wallet.type == WalletType.wownero) {
await wownero!.updateUnspents(wallet);
}
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type)) {
await bitcoin!.updateUnspents(wallet);
}
@@ -80,6 +86,7 @@ abstract class UnspentCoinsListViewModelBase with Store {
List<Unspent> _getUnspents() {
if (wallet.type == WalletType.monero) return monero!.getUnspents(wallet);
if (wallet.type == WalletType.wownero) return wownero!.getUnspents(wallet);
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type))
return bitcoin!.getUnspents(wallet);
return List.empty();
@@ -17,6 +17,7 @@ import 'package:cake_wallet/utils/list_item.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_account_list_header.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_header.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_item.dart';
import 'package:cake_wallet/wownero/wownero.dart';
import 'package:cw_core/amount_converter.dart';
import 'package:cw_core/currency.dart';
import 'package:cw_core/wallet_type.dart';
@@ -191,6 +192,22 @@ class TronURI extends PaymentURI {
}
}
class WowneroURI extends PaymentURI {
WowneroURI({required String amount, required String address})
: super(amount: amount, address: address);
@override
String toString() {
var base = 'wownero:' + address;
if (amount.isNotEmpty) {
base += '?tx_amount=${amount.replaceAll(',', '.')}';
}
return base;
}
}
abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewModel with Store {
WalletAddressListViewModelBase({
required AppStore appStore,
@@ -293,6 +310,10 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
return TronURI(amount: amount, address: address.address);
}
if (wallet.type == WalletType.wownero) {
return WowneroURI(amount: amount, address: address.address);
}
throw Exception('Unexpected type: ${type.toString()}');
}
@@ -409,6 +430,20 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
addressList.add(WalletAddressListItem(isPrimary: true, name: null, address: primaryAddress));
}
if (wallet.type == WalletType.wownero) {
final primaryAddress = wownero!.getSubaddressList(wallet).subaddresses.first;
final addressItems = wownero!.getSubaddressList(wallet).subaddresses.map((subaddress) {
final isPrimary = subaddress == primaryAddress;
return WalletAddressListItem(
id: subaddress.id,
isPrimary: isPrimary,
name: subaddress.label,
address: subaddress.address);
});
addressList.addAll(addressItems);
}
if (searchText.isNotEmpty) {
return ObservableList.of(addressList.where((item) {
if (item is WalletAddressListItem) {
+10 -5
View File
@@ -1,3 +1,4 @@
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/core/wallet_creation_service.dart';
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/entities/background_tasks.dart';
@@ -12,6 +13,7 @@ import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/entities/generate_name.dart';
import 'package:polyseed/polyseed.dart';
part 'wallet_creation_vm.g.dart';
@@ -41,6 +43,10 @@ abstract class WalletCreationVMBase with Store {
final Box<WalletInfo> _walletInfoSource;
final AppStore _appStore;
bool isPolyseed(String seed) =>
(type == WalletType.monero || type == WalletType.wownero) &&
(Polyseed.isValidSeed(seed) || (seed.split(" ").length == 14));
bool nameExists(String name) => walletCreationService.exists(name);
bool typeExists(WalletType type) => walletCreationService.typeExists(type);
@@ -85,7 +91,9 @@ abstract class WalletCreationVMBase with Store {
getIt.get<BackgroundTasks>().registerSyncTask();
_appStore.authenticationStore.allowed();
state = ExecutedSuccessfullyState();
} catch (e) {
} catch (e, s) {
print("@@@@@@@@");
print(s);
state = FailureState(e.toString());
}
}
@@ -98,10 +106,7 @@ abstract class WalletCreationVMBase with Store {
);
case WalletType.bitcoin:
case WalletType.litecoin:
return DerivationInfo(
derivationType: DerivationType.electrum,
derivationPath: "m/0'",
);
return bitcoin!.getElectrumDerivations()[DerivationType.electrum]!.first;
default:
return null;
}
+125 -40
View File
@@ -1,16 +1,17 @@
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/haven/haven.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/reactions/wallet_connect.dart';
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/wownero/wownero.dart';
import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/haven/haven.dart';
import 'package:cw_monero/api/wallet.dart' as monero_wallet;
import 'package:cw_core/wallet_type.dart';
import 'package:cw_monero/monero_wallet.dart';
import 'package:cw_wownero/wownero_wallet.dart';
import 'package:mobx/mobx.dart';
import 'package:polyseed/polyseed.dart';
part 'wallet_keys_view_model.g.dart';
@@ -33,13 +34,17 @@ abstract class WalletKeysViewModelBase with Store {
_populateItems();
});
if (_appStore.wallet!.type == WalletType.monero || _appStore.wallet!.type == WalletType.haven) {
if (_appStore.wallet!.type == WalletType.monero ||
_appStore.wallet!.type == WalletType.haven ||
_appStore.wallet!.type == WalletType.wownero) {
final accountTransactions = _getWalletTransactions(_appStore.wallet!);
if (accountTransactions.isNotEmpty) {
final incomingAccountTransactions =
accountTransactions.where((tx) => tx.direction == TransactionDirection.incoming);
final incomingAccountTransactions = accountTransactions
.where((tx) => tx.direction == TransactionDirection.incoming);
if (incomingAccountTransactions.isNotEmpty) {
incomingAccountTransactions.toList().sort((a, b) => a.date.compareTo(b.date));
incomingAccountTransactions
.toList()
.sort((a, b) => a.date.compareTo(b.date));
_restoreHeightByTransactions = _getRestoreHeightByTransactions(
_appStore.wallet!.type, incomingAccountTransactions.first.date);
}
@@ -65,23 +70,38 @@ abstract class WalletKeysViewModelBase with Store {
items.addAll([
if (keys['publicSpendKey'] != null)
StandartListItem(title: S.current.spend_key_public, value: keys['publicSpendKey']!),
StandartListItem(
title: S.current.spend_key_public,
value: keys['publicSpendKey']!),
if (keys['privateSpendKey'] != null)
StandartListItem(title: S.current.spend_key_private, value: keys['privateSpendKey']!),
StandartListItem(
title: S.current.spend_key_private,
value: keys['privateSpendKey']!),
if (keys['publicViewKey'] != null)
StandartListItem(title: S.current.view_key_public, value: keys['publicViewKey']!),
StandartListItem(
title: S.current.view_key_public, value: keys['publicViewKey']!),
if (keys['privateViewKey'] != null)
StandartListItem(title: S.current.view_key_private, value: keys['privateViewKey']!),
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
StandartListItem(
title: S.current.view_key_private,
value: keys['privateViewKey']!),
StandartListItem(
title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
]);
if (_appStore.wallet?.seed != null && Polyseed.isValidSeed(_appStore.wallet!.seed!)) {
if (_appStore.wallet?.seed != null &&
Polyseed.isValidSeed(_appStore.wallet!.seed!)) {
final lang = PolyseedLang.getByPhrase(_appStore.wallet!.seed!);
final legacyLang = _getLegacySeedLang(lang);
final legacySeed =
Polyseed.decode(_appStore.wallet!.seed!, lang, PolyseedCoin.POLYSEED_MONERO)
.toLegacySeed(legacyLang);
items.add(StandartListItem(title: S.current.wallet_seed_legacy, value: legacySeed));
items.add(StandartListItem(
title: S.current.wallet_seed_legacy,
value: (_appStore.wallet as MoneroWalletBase)
.seedLegacy(lang.nameEnglish)));
}
final restoreHeight = monero!.getRestoreHeight(_appStore.wallet!);
if (restoreHeight != null) {
items.add(StandartListItem(
title: S.current.wallet_recovery_height,
value: restoreHeight.toString()));
}
}
@@ -90,17 +110,58 @@ abstract class WalletKeysViewModelBase with Store {
items.addAll([
if (keys['publicSpendKey'] != null)
StandartListItem(title: S.current.spend_key_public, value: keys['publicSpendKey']!),
StandartListItem(
title: S.current.spend_key_public,
value: keys['publicSpendKey']!),
if (keys['privateSpendKey'] != null)
StandartListItem(title: S.current.spend_key_private, value: keys['privateSpendKey']!),
StandartListItem(
title: S.current.spend_key_private,
value: keys['privateSpendKey']!),
if (keys['publicViewKey'] != null)
StandartListItem(title: S.current.view_key_public, value: keys['publicViewKey']!),
StandartListItem(
title: S.current.view_key_public, value: keys['publicViewKey']!),
if (keys['privateViewKey'] != null)
StandartListItem(title: S.current.view_key_private, value: keys['privateViewKey']!),
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
StandartListItem(
title: S.current.view_key_private,
value: keys['privateViewKey']!),
StandartListItem(
title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
]);
}
if (_appStore.wallet!.type == WalletType.wownero) {
final keys = wownero!.getKeys(_appStore.wallet!);
items.addAll([
if (keys['publicSpendKey'] != null)
StandartListItem(
title: S.current.spend_key_public,
value: keys['publicSpendKey']!),
if (keys['privateSpendKey'] != null)
StandartListItem(
title: S.current.spend_key_private,
value: keys['privateSpendKey']!),
if (keys['publicViewKey'] != null)
StandartListItem(
title: S.current.view_key_public, value: keys['publicViewKey']!),
if (keys['privateViewKey'] != null)
StandartListItem(
title: S.current.view_key_private,
value: keys['privateViewKey']!),
StandartListItem(
title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
]);
if (_appStore.wallet?.seed != null &&
Polyseed.isValidSeed(_appStore.wallet!.seed!)) {
final lang = PolyseedLang.getByPhrase(_appStore.wallet!.seed!);
items.add(StandartListItem(
title: S.current.wallet_seed_legacy,
value: (_appStore.wallet as WowneroWalletBase)
.seedLegacy(lang.nameEnglish)));
}
}
if (_appStore.wallet!.type == WalletType.bitcoin ||
_appStore.wallet!.type == WalletType.litecoin ||
_appStore.wallet!.type == WalletType.bitcoinCash) {
@@ -113,7 +174,8 @@ abstract class WalletKeysViewModelBase with Store {
// StandartListItem(title: S.current.private_key, value: keys['privateKey']!),
// if (keys['publicKey'] != null)
// StandartListItem(title: S.current.public_key, value: keys['publicKey']!),
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
StandartListItem(
title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
]);
}
@@ -122,24 +184,32 @@ abstract class WalletKeysViewModelBase with Store {
_appStore.wallet!.type == WalletType.tron) {
items.addAll([
if (_appStore.wallet!.privateKey != null)
StandartListItem(title: S.current.private_key, value: _appStore.wallet!.privateKey!),
StandartListItem(
title: S.current.private_key,
value: _appStore.wallet!.privateKey!),
if (_appStore.wallet!.seed != null)
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
StandartListItem(
title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
]);
}
bool nanoBased =
_appStore.wallet!.type == WalletType.nano || _appStore.wallet!.type == WalletType.banano;
bool nanoBased = _appStore.wallet!.type == WalletType.nano ||
_appStore.wallet!.type == WalletType.banano;
if (nanoBased) {
// we always have the hex version of the seed and private key:
items.addAll([
if (_appStore.wallet!.seed != null)
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
StandartListItem(
title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
if (_appStore.wallet!.hexSeed != null)
StandartListItem(title: S.current.seed_hex_form, value: _appStore.wallet!.hexSeed!),
StandartListItem(
title: S.current.seed_hex_form,
value: _appStore.wallet!.hexSeed!),
if (_appStore.wallet!.privateKey != null)
StandartListItem(title: S.current.private_key, value: _appStore.wallet!.privateKey!),
StandartListItem(
title: S.current.private_key,
value: _appStore.wallet!.privateKey!),
]);
}
}
@@ -149,7 +219,10 @@ abstract class WalletKeysViewModelBase with Store {
return await haven!.getCurrentHeight();
}
if (_appStore.wallet!.type == WalletType.monero) {
return monero_wallet.getCurrentHeight();
return await monero!.getCurrentHeight();
}
if (_appStore.wallet!.type == WalletType.wownero) {
return await wownero!.getCurrentHeight();
}
return null;
}
@@ -178,8 +251,10 @@ abstract class WalletKeysViewModelBase with Store {
return 'solana-wallet';
case WalletType.tron:
return 'tron-wallet';
case WalletType.wownero:
return 'wownero-wallet';
default:
throw Exception('Unexpected wallet type: ${_appStore.wallet!.toString()}');
throw Exception('Unexpected wallet type: ${_appStore.wallet!.type.toString()}');
}
}
@@ -200,7 +275,8 @@ abstract class WalletKeysViewModelBase with Store {
if (_appStore.wallet!.seed != null) 'seed': _appStore.wallet!.seed!,
if (_appStore.wallet!.seed == null && _appStore.wallet!.hexSeed != null)
'hexSeed': _appStore.wallet!.hexSeed!,
if (_appStore.wallet!.seed == null && _appStore.wallet!.privateKey != null)
if (_appStore.wallet!.seed == null &&
_appStore.wallet!.privateKey != null)
'private_key': _appStore.wallet!.privateKey!,
if (restoreHeightResult != null) ...{'height': restoreHeightResult}
};
@@ -216,6 +292,12 @@ abstract class WalletKeysViewModelBase with Store {
return monero!.getTransactionHistory(wallet).transactions.values.toList();
} else if (wallet.type == WalletType.haven) {
return haven!.getTransactionHistory(wallet).transactions.values.toList();
} else if (wallet.type == WalletType.wownero) {
return wownero!
.getTransactionHistory(wallet)
.transactions
.values
.toList();
}
return [];
}
@@ -225,11 +307,14 @@ abstract class WalletKeysViewModelBase with Store {
return monero!.getHeightByDate(date: date);
} else if (type == WalletType.haven) {
return haven!.getHeightByDate(date: date);
} else if (type == WalletType.wownero) {
return wownero!.getHeightByDate(date: date);
}
return 0;
}
String getRoundedRestoreHeight(int height) => ((height / 1000).floor() * 1000).toString();
String getRoundedRestoreHeight(int height) =>
((height / 1000).floor() * 1000).toString();
LegacySeedLang _getLegacySeedLang(PolyseedLang lang) {
switch (lang.nameEnglish) {
+10 -3
View File
@@ -2,6 +2,7 @@ import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/wownero/wownero.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/monero/monero.dart';
@@ -35,11 +36,13 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
@observable
String selectedMnemonicLanguage;
bool get hasLanguageSelector => type == WalletType.monero || type == WalletType.haven;
bool get hasLanguageSelector =>
type == WalletType.monero || type == WalletType.haven || type == WalletType.wownero;
int get seedPhraseWordsLength {
switch (type) {
case WalletType.monero:
case WalletType.wownero:
if (advancedPrivacySettingsViewModel.isPolySeed) {
return 16;
}
@@ -55,7 +58,7 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
}
}
bool get hasSeedType => type == WalletType.monero;
bool get hasSeedType => type == WalletType.monero || type == WalletType.wownero;
@override
WalletCredentials getCredentials(dynamic _options) {
@@ -76,6 +79,7 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
case WalletType.bitcoinCash:
return bitcoinCash!.createBitcoinCashNewWalletCredentials(name: name);
case WalletType.nano:
case WalletType.banano:
return nano!.createNanoNewWalletCredentials(name: name);
case WalletType.polygon:
return polygon!.createPolygonNewWalletCredentials(name: name);
@@ -83,7 +87,10 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
return solana!.createSolanaNewWalletCredentials(name: name);
case WalletType.tron:
return tron!.createTronNewWalletCredentials(name: name);
default:
case WalletType.wownero:
return wownero!.createWowneroNewWalletCredentials(
name: name, language: options!.first as String, isPolyseed: options.last as bool);
case WalletType.none:
throw Exception('Unexpected type: ${type.toString()}');
}
}
+32 -8
View File
@@ -2,7 +2,7 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/nano/nano.dart';
import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cw_core/nano_account_info_response.dart';
import 'package:cake_wallet/wownero/wownero.dart';
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
import 'package:cake_wallet/polygon/polygon.dart';
import 'package:cake_wallet/solana/solana.dart';
@@ -29,8 +29,10 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
WalletRestoreViewModelBase(AppStore appStore, WalletCreationService walletCreationService,
Box<WalletInfo> walletInfoSource,
{required WalletType type})
: hasSeedLanguageSelector = type == WalletType.monero || type == WalletType.haven,
hasBlockchainHeightLanguageSelector = type == WalletType.monero || type == WalletType.haven,
: hasSeedLanguageSelector =
type == WalletType.monero || type == WalletType.haven || type == WalletType.wownero,
hasBlockchainHeightLanguageSelector =
type == WalletType.monero || type == WalletType.haven || type == WalletType.wownero,
hasRestoreFromPrivateKey = type == WalletType.ethereum ||
type == WalletType.polygon ||
type == WalletType.nano ||
@@ -42,18 +44,22 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: true) {
switch (type) {
case WalletType.monero:
case WalletType.haven:
case WalletType.ethereum:
case WalletType.polygon:
availableModes = WalletRestoreMode.values;
break;
case WalletType.nano:
case WalletType.banano:
case WalletType.solana:
case WalletType.tron:
case WalletType.wownero:
case WalletType.haven:
case WalletType.ethereum:
case WalletType.polygon:
availableModes = [WalletRestoreMode.seed, WalletRestoreMode.keys];
break;
default:
case WalletType.bitcoin:
case WalletType.litecoin:
case WalletType.bitcoinCash:
case WalletType.none:
availableModes = [WalletRestoreMode.seed];
break;
}
@@ -112,6 +118,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
return bitcoinCash!.createBitcoinCashRestoreWalletFromSeedCredentials(
name: name, mnemonic: seed, password: password);
case WalletType.nano:
case WalletType.banano:
return nano!.createNanoRestoreWalletFromSeedCredentials(
name: name,
mnemonic: seed,
@@ -136,7 +143,14 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
mnemonic: seed,
password: password,
);
default:
case WalletType.wownero:
return wownero!.createWowneroRestoreWalletFromSeedCredentials(
name: name,
mnemonic: seed,
password: password,
height: height,
);
case WalletType.none:
break;
}
}
@@ -200,6 +214,16 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
password: password,
privateKey: options['private_key'] as String,
);
case WalletType.wownero:
return wownero!.createWowneroRestoreWalletFromKeysCredentials(
name: name,
height: height,
spendKey: spendKey!,
viewKey: viewKey!,
address: address!,
password: password,
language: 'English',
);
default:
break;
}