* hv
* Change build version
This commit is contained in:
mkyq
2022-03-30 17:57:04 +02:00
committed by GitHub
parent e7e419bc83
commit 01150ef2a7
213 changed files with 23972 additions and 672 deletions
+131 -41
View File
@@ -15,6 +15,21 @@ import 'package:mobx/mobx.dart';
part 'balance_view_model.g.dart';
class BalanceRecord {
const BalanceRecord({this.availableBalance,
this.additionalBalance,
this.fiatAvailableBalance,
this.fiatAdditionalBalance,
this.asset,
this.formattedAssetTitle});
final String fiatAdditionalBalance;
final String fiatAvailableBalance;
final String additionalBalance;
final String availableBalance;
final CryptoCurrency asset;
final String formattedAssetTitle;
}
class BalanceViewModel = BalanceViewModelBase with _$BalanceViewModel;
abstract class BalanceViewModelBase with Store {
@@ -24,16 +39,7 @@ abstract class BalanceViewModelBase with Store {
@required this.fiatConvertationStore}) {
isReversing = false;
wallet ??= appStore.wallet;
balance = wallet.balance;
reaction((_) => appStore.wallet, _onWalletChange);
_onCurrentWalletChangeReaction =
reaction<void>((_) => wallet.balance, (dynamic balance) {
if (balance is Balance) {
this.balance = balance;
}
});
}
final AppStore appStore;
@@ -45,9 +51,6 @@ abstract class BalanceViewModelBase with Store {
@observable
bool isReversing;
@observable
Balance balance;
@observable
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>
wallet;
@@ -58,47 +61,56 @@ abstract class BalanceViewModelBase with Store {
@computed
BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode;
@computed
@computed
String get asset {
switch(appStore.wallet.currency){
case CryptoCurrency.btc:
return 'Bitcoin Assets';
case CryptoCurrency.xmr:
return 'Monero Assets';
case CryptoCurrency.ltc:
return 'Litecoin Assets';
final typeFormatted = walletTypeToString(appStore.wallet.type);
switch(wallet.type) {
case WalletType.haven:
return '$typeFormatted Assets';
default:
return '';
return typeFormatted;
}
}
@computed
BalanceDisplayMode get displayMode => isReversing
? savedDisplayMode == BalanceDisplayMode.hiddenBalance
? BalanceDisplayMode.displayableBalance
: savedDisplayMode
: savedDisplayMode;
BalanceDisplayMode get displayMode {
if (isReversing) {
if (savedDisplayMode == BalanceDisplayMode.hiddenBalance) {
return BalanceDisplayMode.displayableBalance;
} else {
return BalanceDisplayMode.hiddenBalance;
}
}
return savedDisplayMode;
}
@computed
String get availableBalanceLabel {
if (wallet.type == WalletType.monero) {
return S.current.xmr_available_balance;
switch(wallet.type) {
case WalletType.monero:
case WalletType.haven:
return S.current.xmr_available_balance;
default:
return S.current.confirmed;
}
return S.current.confirmed;
}
@computed
String get additionalBalanceLabel {
if (wallet.type == WalletType.monero) {
return S.current.xmr_full_balance;
switch(wallet.type) {
case WalletType.monero:
case WalletType.haven:
return S.current.xmr_full_balance;
default:
return S.current.unconfirmed;
}
return S.current.unconfirmed;
}
@computed
bool get hasMultiBalance => appStore.wallet.type == WalletType.haven;
@computed
String get availableBalance {
final walletBalance = _walletBalance;
@@ -152,7 +164,73 @@ abstract class BalanceViewModelBase with Store {
}
@computed
Balance get _walletBalance => wallet.balance;
Map<CryptoCurrency, BalanceRecord> get balances {
return wallet.balance.map((key, value) {
if (displayMode == BalanceDisplayMode.hiddenBalance) {
return MapEntry(key, BalanceRecord(
availableBalance: '---',
additionalBalance: '---',
fiatAdditionalBalance: '---',
fiatAvailableBalance: '---',
asset: key,
formattedAssetTitle: _formatterAsset(key)));
}
final fiatCurrency = settingsStore.fiatCurrency;
final additionalFiatBalance = fiatCurrency.toString()
+ ' '
+ _getFiatBalance(
price: fiatConvertationStore.prices[key],
cryptoAmount: value.formattedAdditionalBalance);
final availableFiatBalance = fiatCurrency.toString()
+ ' '
+ _getFiatBalance(
price: fiatConvertationStore.prices[key],
cryptoAmount: value.formattedAvailableBalance);
return MapEntry(key, BalanceRecord(
availableBalance: value.formattedAvailableBalance,
additionalBalance: value.formattedAdditionalBalance,
fiatAdditionalBalance: additionalFiatBalance,
fiatAvailableBalance: availableFiatBalance,
asset: key,
formattedAssetTitle: _formatterAsset(key)));
});
}
@computed
List<BalanceRecord> get formattedBalances {
final balance = balances.values.toList();
balance.sort((BalanceRecord a, BalanceRecord b) {
if (b.asset == CryptoCurrency.xhv) {
return 1;
}
if (b.asset == CryptoCurrency.xusd) {
if (a.asset == CryptoCurrency.xhv) {
return -1;
}
return 1;
}
if (b.asset == CryptoCurrency.xbtc) {
return 1;
}
if (b.asset == CryptoCurrency.xeur) {
return 1;
}
return 0;
});
return balance;
}
@computed
Balance get _walletBalance => wallet.balance[wallet.currency];
@computed
CryptoCurrency get currency => appStore.wallet.currency;
@@ -164,11 +242,8 @@ abstract class BalanceViewModelBase with Store {
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
TransactionInfo>
wallet) {
this.wallet = wallet;
balance = wallet.balance;
this.wallet = wallet;
_onCurrentWalletChangeReaction?.reaction?.dispose();
_onCurrentWalletChangeReaction = reaction<Balance>(
(_) => wallet.balance, (Balance balance) => this.balance = balance);
}
String _getFiatBalance({double price, String cryptoAmount}) {
@@ -178,5 +253,20 @@ abstract class BalanceViewModelBase with Store {
return calculateFiatAmount(price: price, cryptoAmount: cryptoAmount);
}
String _formatterAsset(CryptoCurrency asset) {
switch (wallet.type) {
case WalletType.haven:
final assetStringified = asset.toString();
if (asset != CryptoCurrency.xhv && assetStringified[0].toUpperCase() == 'X') {
return assetStringified.replaceFirst('X', 'x');
}
return asset.toString();
default:
return asset.toString();
}
}
}
@@ -1,3 +1,4 @@
import 'package:cake_wallet/wallet_type_utils.dart';
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/balance.dart';
import 'package:cake_wallet/buy/order.dart';
@@ -78,6 +79,8 @@ abstract class DashboardViewModelBase with Store {
isShowFirstYatIntroduction = false;
isShowSecondYatIntroduction = false;
isShowThirdYatIntroduction = false;
updateActions();
final _wallet = wallet;
if (_wallet.type == WalletType.monero) {
@@ -229,6 +232,24 @@ abstract class DashboardViewModelBase with Store {
void furtherShowYatPopup(bool shouldShow) =>
settingsStore.shouldShowYatPopup = shouldShow;
@observable
bool isEnabledExchangeAction;
@observable
bool hasExchangeAction;
@observable
bool isEnabledBuyAction;
@observable
bool hasBuyAction;
@observable
bool isEnabledSellAction;
@observable
bool hasSellAction;
ReactionDisposer _onMoneroAccountChangeReaction;
ReactionDisposer _onMoneroBalanceChangeReaction;
@@ -251,6 +272,7 @@ abstract class DashboardViewModelBase with Store {
name = wallet.name;
isOutdatedElectrumWallet =
wallet.type == WalletType.bitcoin && wallet.seed.split(' ').length < 24;
updateActions();
if (wallet.type == WalletType.monero) {
subname = monero.getCurrentAccount(wallet)?.label;
@@ -313,4 +335,16 @@ abstract class DashboardViewModelBase with Store {
balanceViewModel: balanceViewModel,
settingsStore: appStore.settingsStore)));
}
void updateActions() {
isEnabledExchangeAction = wallet.type != WalletType.haven;
hasExchangeAction = !isHaven;
isEnabledBuyAction = wallet.type != WalletType.haven
&& wallet.type != WalletType.monero;
hasBuyAction = !isMoneroOnly && !isHaven;
isEnabledSellAction = wallet.type != WalletType.haven
&& wallet.type != WalletType.monero
&& wallet.type != WalletType.litecoin;
hasSellAction = !isMoneroOnly && !isHaven;
}
}
@@ -1,15 +1,18 @@
import 'package:cake_wallet/entities/balance_display_mode.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/utils/mobx.dart';
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/haven/haven.dart';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
import 'package:cw_core/keyable.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cw_haven/haven_transaction_info.dart';
class TransactionListItem extends ActionListItem with Keyable {
TransactionListItem(
@@ -35,21 +38,33 @@ class TransactionListItem extends ActionListItem with Keyable {
}
String get formattedFiatAmount {
if (balanceViewModel.wallet.type == WalletType.monero) {
final amount = calculateFiatAmountRaw(
var amount = '';
switch(balanceViewModel.wallet.type) {
case WalletType.monero:
amount = calculateFiatAmountRaw(
cryptoAmount: monero.formatterMoneroAmountToDouble(amount: transaction.amount),
price: price);
transaction.changeFiatAmount(amount);
}
if (balanceViewModel.wallet.type == WalletType.bitcoin
|| balanceViewModel.wallet.type == WalletType.litecoin) {
final amount = calculateFiatAmountRaw(
break;
case WalletType.bitcoin:
case WalletType.litecoin:
amount = calculateFiatAmountRaw(
cryptoAmount: bitcoin.formatterBitcoinAmountToDouble(amount: transaction.amount),
price: price);
transaction.changeFiatAmount(amount);
break;
case WalletType.haven:
final tx = transaction as HavenTransactionInfo;
final asset = CryptoCurrency.fromString(tx.assetType);
final price = balanceViewModel.fiatConvertationStore.prices[asset];
amount = calculateFiatAmountRaw(
cryptoAmount: haven.formatterMoneroAmountToDouble(amount: transaction.amount),
price: price);
break;
default:
break;
}
transaction.changeFiatAmount(amount);
return displayMode == BalanceDisplayMode.hiddenBalance
? '---'
: fiatCurrency.title + ' ' + transaction.fiatAmount();
@@ -338,7 +338,7 @@ abstract class ExchangeViewModelBase with Store {
@action
void calculateDepositAllAmount() {
if (wallet.type == WalletType.bitcoin) {
final availableBalance = wallet.balance.available;
final availableBalance = wallet.balance[wallet.currency].available;
final priority = _settingsStore.priority[wallet.type];
final fee = wallet.calculateEstimatedFee(priority, null);
@@ -1,8 +1,10 @@
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/haven/haven.dart';
import 'package:cake_wallet/view_model/monero_account_list/account_list_item.dart';
part 'monero_account_edit_or_create_view_model.g.dart';
@@ -11,7 +13,7 @@ class MoneroAccountEditOrCreateViewModel = MoneroAccountEditOrCreateViewModelBas
with _$MoneroAccountEditOrCreateViewModel;
abstract class MoneroAccountEditOrCreateViewModelBase with Store {
MoneroAccountEditOrCreateViewModelBase(this._moneroAccountList,
MoneroAccountEditOrCreateViewModelBase(this._moneroAccountList, this._havenAccountList,
{@required WalletBase wallet, AccountListItem accountListItem})
: state = InitialExecutionState(),
isEdit = accountListItem != null,
@@ -28,10 +30,21 @@ abstract class MoneroAccountEditOrCreateViewModelBase with Store {
String label;
final MoneroAccountList _moneroAccountList;
final HavenAccountList _havenAccountList;
final AccountListItem _accountListItem;
final WalletBase _wallet;
Future<void> save() async {
if (_wallet.type == WalletType.monero) {
await saveMonero();
}
if (_wallet.type == WalletType.haven) {
await saveHaven();
}
}
Future<void> saveMonero() async {
try {
state = IsExecutingState();
@@ -52,4 +65,30 @@ abstract class MoneroAccountEditOrCreateViewModelBase with Store {
state = FailureState(e.toString());
}
}
Future<void> saveHaven() async {
if (!(_wallet.type == WalletType.haven)) {
return;
}
try {
state = IsExecutingState();
if (_accountListItem != null) {
await _havenAccountList.setLabelAccount(
_wallet,
accountIndex: _accountListItem.id,
label: label);
} else {
await _havenAccountList.addAccount(
_wallet,
label: label);
}
await _wallet.save();
state = ExecutedSuccessfullyState();
} catch (e) {
state = FailureState(e.toString());
}
}
}
@@ -1,7 +1,9 @@
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cake_wallet/view_model/monero_account_list/account_list_item.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/haven/haven.dart';
part 'monero_account_list_view_model.g.dart';
@@ -20,20 +22,43 @@ abstract class MoneroAccountListViewModelBase with Store {
}
@computed
List<AccountListItem> get accounts => monero
.getAccountList(_wallet)
.accounts.map((acc) => AccountListItem(
label: acc.label,
id: acc.id,
isSelected: acc.id == monero.getCurrentAccount(_wallet).id))
.toList();
List<AccountListItem> get accounts {
if (_wallet.type == WalletType.haven) {
return haven
.getAccountList(_wallet)
.accounts.map((acc) => AccountListItem(
label: acc.label,
id: acc.id,
isSelected: acc.id == haven.getCurrentAccount(_wallet).id))
.toList();
}
if (_wallet.type == WalletType.monero) {
return monero
.getAccountList(_wallet)
.accounts.map((acc) => AccountListItem(
label: acc.label,
id: acc.id,
isSelected: acc.id == monero.getCurrentAccount(_wallet).id))
.toList();
}
}
final WalletBase _wallet;
void select(AccountListItem item) =>
void select(AccountListItem item) {
if (_wallet.type == WalletType.monero) {
monero.setCurrentAccount(
_wallet,
Account(
id: item.id,
label: item.label));
item.id,
item.label);
}
if (_wallet.type == WalletType.haven) {
haven.setCurrentAccount(
_wallet,
item.id,
item.label);
}
}
}
@@ -41,7 +41,8 @@ abstract class NodeCreateOrEditViewModelBase with Store {
bool get isReady =>
(address?.isNotEmpty ?? false) && (port?.isNotEmpty ?? false);
bool get hasAuthCredentials => _wallet.type == WalletType.monero;
bool get hasAuthCredentials => _wallet.type == WalletType.monero ||
_wallet.type == WalletType.haven;
String get uri {
var uri = address;
+18 -5
View File
@@ -2,7 +2,9 @@ import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
import 'package:cake_wallet/entities/parse_address_from_domain.dart';
import 'package:cake_wallet/entities/parsed_address.dart';
import 'package:cake_wallet/haven/haven.dart';
import 'package:cake_wallet/src/screens/send/widgets/extract_address_from_parsed.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:mobx/mobx.dart';
@@ -22,7 +24,7 @@ const String cryptoNumberPattern = '0.0';
class Output = OutputBase with _$Output;
abstract class OutputBase with Store {
OutputBase(this._wallet, this._settingsStore, this._fiatConversationStore)
OutputBase(this._wallet, this._settingsStore, this._fiatConversationStore, this.cryptoCurrencyHandler)
: _cryptoNumberFormat = NumberFormat(cryptoNumberPattern) {
reset();
_setCryptoNumMaximumFractionDigits();
@@ -77,6 +79,9 @@ abstract class OutputBase with Store {
_amount =
bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount);
break;
case WalletType.haven:
_amount = haven.formatterMoneroParseAmount(amount: _cryptoAmount);
break;
default:
break;
}
@@ -106,6 +111,10 @@ abstract class OutputBase with Store {
if (_wallet.type == WalletType.monero) {
return monero.formatterMoneroAmountToDouble(amount: fee);
}
if (_wallet.type == WalletType.haven) {
return haven.formatterMoneroAmountToDouble(amount: fee);
}
} catch (e) {
print(e.toString());
}
@@ -117,7 +126,7 @@ abstract class OutputBase with Store {
String get estimatedFeeFiatAmount {
try {
final fiat = calculateFiatAmountRaw(
price: _fiatConversationStore.prices[_wallet.currency],
price: _fiatConversationStore.prices[cryptoCurrencyHandler()],
cryptoAmount: estimatedFee);
return fiat;
} catch (_) {
@@ -126,6 +135,7 @@ abstract class OutputBase with Store {
}
WalletType get walletType => _wallet.type;
final CryptoCurrency Function() cryptoCurrencyHandler;
final WalletBase _wallet;
final SettingsStore _settingsStore;
final FiatConversionStore _fiatConversationStore;
@@ -169,7 +179,7 @@ abstract class OutputBase with Store {
void _updateFiatAmount() {
try {
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[_wallet.currency],
price: _fiatConversationStore.prices[cryptoCurrencyHandler()],
cryptoAmount: cryptoAmount.replaceAll(',', '.'));
if (fiatAmount != fiat) {
fiatAmount = fiat;
@@ -183,7 +193,7 @@ abstract class OutputBase with Store {
void _updateCryptoAmount() {
try {
final crypto = double.parse(fiatAmount.replaceAll(',', '.')) /
_fiatConversationStore.prices[_wallet.currency];
_fiatConversationStore.prices[cryptoCurrencyHandler()];
final cryptoAmountTmp = _cryptoNumberFormat.format(crypto);
if (cryptoAmount != cryptoAmountTmp) {
@@ -207,6 +217,9 @@ abstract class OutputBase with Store {
case WalletType.litecoin:
maximumFractionDigits = 8;
break;
case WalletType.haven:
maximumFractionDigits = 12;
break;
default:
break;
}
@@ -216,7 +229,7 @@ abstract class OutputBase with Store {
Future<void> fetchParsedAddress(BuildContext context) async {
final domain = address;
final ticker = _wallet.currency.title.toLowerCase();
final ticker = cryptoCurrencyHandler().title.toLowerCase();
parsedAddress = await getIt.get<AddressResolver>().resolve(domain, ticker);
extractedAddress = await extractAddressFromParsed(context, parsedAddress);
note = parsedAddress.description;
@@ -21,7 +21,7 @@ abstract class SendTemplateViewModelBase with Store {
SendTemplateViewModelBase(this._wallet, this._settingsStore,
this._sendTemplateStore, this._fiatConversationStore) {
output = Output(_wallet, _settingsStore, _fiatConversationStore);
output = Output(_wallet, _settingsStore, _fiatConversationStore, () => currency);
}
Output output;
+24 -11
View File
@@ -24,6 +24,7 @@ import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
import 'package:cake_wallet/entities/parsed_address.dart';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/haven/haven.dart';
part 'send_view_model.g.dart';
@@ -39,13 +40,15 @@ abstract class SendViewModelBase with Store {
: state = InitialExecutionState() {
final priority = _settingsStore.priority[_wallet.type];
final priorities = priorityForWalletType(_wallet.type);
selectedCryptoCurrency = _wallet.currency;
currencies = _wallet.balance.keys.toList();
if (!priorityForWalletType(_wallet.type).contains(priority)) {
_settingsStore.priority[_wallet.type] = priorities.first;
}
outputs = ObservableList<Output>()
..add(Output(_wallet, _settingsStore, _fiatConversationStore));
..add(Output(_wallet, _settingsStore, _fiatConversationStore, () => selectedCryptoCurrency));
}
@observable
@@ -55,7 +58,7 @@ abstract class SendViewModelBase with Store {
@action
void addOutput() {
outputs.add(Output(_wallet, _settingsStore, _fiatConversationStore));
outputs.add(Output(_wallet, _settingsStore, _fiatConversationStore, () => selectedCryptoCurrency));
}
@action
@@ -79,7 +82,7 @@ abstract class SendViewModelBase with Store {
try {
if (pendingTransaction != null) {
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[_wallet.currency],
price: _fiatConversationStore.prices[selectedCryptoCurrency],
cryptoAmount: pendingTransaction.amountFormatted);
return fiat;
} else {
@@ -95,7 +98,7 @@ abstract class SendViewModelBase with Store {
try {
if (pendingTransaction != null) {
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[_wallet.currency],
price: _fiatConversationStore.prices[selectedCryptoCurrency],
cryptoAmount: pendingTransaction.feeFormatted);
return fiat;
} else {
@@ -117,7 +120,7 @@ abstract class SendViewModelBase with Store {
Validator get allAmountValidator => AllAmountValidator();
Validator get addressValidator => AddressValidator(type: _wallet.currency);
Validator get addressValidator => AddressValidator(type: selectedCryptoCurrency);
Validator get textValidator => TextValidator();
@@ -125,12 +128,7 @@ abstract class SendViewModelBase with Store {
PendingTransaction pendingTransaction;
@computed
String get balance {
if(_settingsStore.balanceDisplayMode == BalanceDisplayMode.hiddenBalance){
return '---';
}
return _wallet.balance.formattedAvailableBalance ?? '0.0' ;
}
String get balance => _wallet.balance[selectedCryptoCurrency].formattedAvailableBalance ?? '0.0';
@computed
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
@@ -144,11 +142,21 @@ abstract class SendViewModelBase with Store {
bool get isElectrumWallet =>
_wallet.type == WalletType.bitcoin || _wallet.type == WalletType.litecoin;
@observable
CryptoCurrency selectedCryptoCurrency;
List<CryptoCurrency> currencies;
bool get hasMultiRecipient => _wallet.type != WalletType.haven;
bool get hasYat => outputs.any((out) =>
out.isParsedAddress &&
out.parsedAddress.parseFrom == ParseFrom.yatRecord);
WalletType get walletType => _wallet.type;
bool get hasCurrecyChanger => walletType == WalletType.haven;
final WalletBase _wallet;
final SettingsStore _settingsStore;
final SendTemplateViewModel sendTemplateViewModel;
@@ -221,6 +229,11 @@ abstract class SendViewModelBase with Store {
return monero.createMoneroTransactionCreationCredentials(
outputs: outputs, priority: priority);
case WalletType.haven:
final priority = _settingsStore.priority[_wallet.type];
return haven.createHavenTransactionCreationCredentials(
outputs: outputs, priority: priority, assetType: selectedCryptoCurrency.title);
default:
return null;
}
@@ -14,6 +14,7 @@ import 'package:cake_wallet/entities/balance_display_mode.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cw_core/node.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/haven/haven.dart';
import 'package:cake_wallet/entities/action_list_display_mode.dart';
import 'package:cake_wallet/view_model/settings/version_list_item.dart';
import 'package:cake_wallet/view_model/settings/picker_list_item.dart';
@@ -29,6 +30,7 @@ import 'package:cw_core/transaction_priority.dart';
import 'package:cake_wallet/themes/theme_base.dart';
import 'package:cake_wallet/themes/theme_list.dart';
import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart';
import 'package:cake_wallet/wallet_type_utils.dart';
part 'settings_view_model.g.dart';
@@ -42,6 +44,8 @@ List<TransactionPriority> priorityForWalletType(WalletType type) {
return bitcoin.getTransactionPriorities();
case WalletType.litecoin:
return bitcoin.getLitecoinTransactionPriorities();
case WalletType.haven:
return haven.getTransactionPriorities();
default:
return [];
}
@@ -101,12 +105,13 @@ abstract class SettingsViewModelBase with Store {
selectedItem: () => balanceDisplayMode,
onItemSelected: (BalanceDisplayMode mode) =>
_settingsStore.balanceDisplayMode = mode),
PickerListItem(
title: S.current.settings_currency,
items: FiatCurrency.all,
selectedItem: () => fiatCurrency,
onItemSelected: (FiatCurrency currency) =>
setFiatCurrency(currency)),
if (!isHaven)
PickerListItem(
title: S.current.settings_currency,
items: FiatCurrency.all,
selectedItem: () => fiatCurrency,
onItemSelected: (FiatCurrency currency) =>
setFiatCurrency(currency)),
PickerListItem(
title: S.current.settings_fee_priority,
items: priorityForWalletType(wallet.type),
@@ -14,6 +14,7 @@ import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/haven/haven.dart';
part 'transaction_details_view_model.g.dart';
@@ -100,6 +101,23 @@ abstract class TransactionDetailsViewModelBase with Store {
items.addAll(_items);
}
if (wallet.type == WalletType.haven) {
items.addAll([
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()),
StandartListItem(
title: S.current.transaction_details_fee, value: tx.feeFormatted()),
]);
}
if (showRecipientAddress && !isRecipientAddressShown) {
final recipientAddress = transactionDescriptionBox.values
.firstWhere((val) => val.id == transactionInfo.id, orElse: () => null)
@@ -154,6 +172,8 @@ abstract class TransactionDetailsViewModelBase with Store {
return 'https://www.blockchain.com/btc/tx/${txId}';
case WalletType.litecoin:
return 'https://blockchair.com/litecoin/transaction/${txId}';
case WalletType.haven:
return 'https://explorer.havenprotocol.org/search?value=${txId}';
default:
return '';
}
@@ -167,6 +187,8 @@ abstract class TransactionDetailsViewModelBase with Store {
return 'View Transaction on Blockchain.com';
case WalletType.litecoin:
return 'View Transaction on Blockchair.com';
case WalletType.haven:
return 'View Transaction on explorer.havenprotocol.org';
default:
return '';
}
@@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/haven/haven.dart';
import 'package:cw_core/wallet_type.dart';
part 'wallet_address_edit_or_create_view_model.g.dart';
@@ -78,6 +79,16 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store {
label: label);
await wallet.save();
}
if (wallet.type == WalletType.haven) {
await haven
.getSubaddressList(wallet)
.addSubaddress(
wallet,
accountIndex: haven.getCurrentAccount(wallet).id,
label: label);
await wallet.save();
}
}
Future<void> _update() async {
@@ -98,5 +109,16 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store {
label: label);
await wallet.save();
}
if (wallet.type == WalletType.haven) {
await haven
.getSubaddressList(wallet)
.setLabelSubaddress(
wallet,
accountIndex: haven.getCurrentAccount(wallet).id,
addressIndex: _item.id as int,
label: label);
await wallet.save();
}
}
}
@@ -15,6 +15,7 @@ import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'dart:async';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/haven/haven.dart';
part 'wallet_address_list_view_model.g.dart';
@@ -44,6 +45,22 @@ class MoneroURI extends PaymentURI {
}
}
class HavenURI extends PaymentURI {
HavenURI({String amount, String address})
: super(amount: amount, address: address);
@override
String toString() {
var base = 'haven:' + address;
if (amount?.isNotEmpty ?? false) {
base += '?tx_amount=${amount.replaceAll(',', '.')}';
}
return base;
}
}
class BitcoinURI extends PaymentURI {
BitcoinURI({String amount, String address})
: super(amount: amount, address: address);
@@ -83,30 +100,7 @@ abstract class WalletAddressListViewModelBase with Store {
}) {
_appStore = appStore;
_wallet = _appStore.wallet;
emoji = '';
hasAccounts = _wallet?.type == WalletType.monero;
reaction((_) => _wallet.walletAddresses.address, (String address) {
if (address == _wallet.walletInfo.yatLastUsedAddress) {
emoji = yatStore.emoji;
} else {
emoji = '';
}
});
//reaction((_) => yatStore.emoji, (String emojiId) => this.emoji = emojiId);
//_onLastUsedYatAddressSubscription =
// _wallet.walletInfo.yatLastUsedAddressStream.listen((String yatAddress) {
// if (yatAddress == _wallet.walletAddresses.address) {
// emoji = yatStore.emoji;
// } else {
// emoji = '';
// }
//});
if (_wallet.walletAddresses.address == _wallet.walletInfo.yatLastUsedAddress) {
emoji = yatStore.emoji;
}
hasAccounts = _wallet?.type == WalletType.monero || _wallet?.type == WalletType.haven;
_onWalletChangeReaction = reaction((_) => _appStore.wallet, (WalletBase<
Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>
@@ -133,6 +127,10 @@ abstract class WalletAddressListViewModelBase with Store {
return MoneroURI(amount: amount, address: address.address);
}
if (_wallet.type == WalletType.haven) {
return HavenURI(amount: amount, address: address.address);
}
if (_wallet.type == WalletType.bitcoin) {
return BitcoinURI(amount: amount, address: address.address);
}
@@ -170,6 +168,23 @@ abstract class WalletAddressListViewModelBase with Store {
addressList.addAll(addressItems);
}
if (wallet.type == WalletType.haven) {
final primaryAddress = haven.getSubaddressList(wallet).subaddresses.first;
final addressItems = haven
.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 (wallet.type == WalletType.bitcoin) {
final primaryAddress = bitcoin.getAddress(wallet);
final bitcoinAddresses = bitcoin.getAddresses(wallet).map((addr) {
@@ -195,14 +210,15 @@ abstract class WalletAddressListViewModelBase with Store {
return monero.getCurrentAccount(wallet).label;
}
if (wallet.type == WalletType.haven) {
return haven.getCurrentAccount(wallet).label;
}
return null;
}
@computed
bool get hasAddressList => _wallet.type == WalletType.monero;
@observable
String emoji;
bool get hasAddressList => _wallet.type == WalletType.monero || _wallet.type == WalletType.haven;
@observable
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>
@@ -216,9 +232,6 @@ abstract class WalletAddressListViewModelBase with Store {
ReactionDisposer _onWalletChangeReaction;
StreamSubscription<String> _onLastUsedYatAddressSubscription;
StreamSubscription<String> _onEmojiIdChangeSubscription;
@action
void setAddress(WalletAddressListItem address) =>
_wallet.walletAddresses.address = address.address;
@@ -226,7 +239,7 @@ abstract class WalletAddressListViewModelBase with Store {
void _init() {
_baseItems = [];
if (_wallet.type == WalletType.monero) {
if (_wallet.type == WalletType.monero || _wallet.type == WalletType.haven) {
_baseItems.add(WalletAccountListHeader());
}
@@ -5,6 +5,7 @@ import 'package:cw_core/wallet_base.dart';
import 'package:cake_wallet/bitcoin/bitcoin.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';
part 'wallet_keys_view_model.g.dart';
@@ -29,6 +30,22 @@ abstract class WalletKeysViewModelBase with Store {
]);
}
if (wallet.type == WalletType.haven) {
final keys = haven.getKeys(wallet);
items.addAll([
StandartListItem(
title: S.current.spend_key_public, value: keys['publicSpendKey']),
StandartListItem(
title: S.current.spend_key_private, value: keys['privateSpendKey']),
StandartListItem(
title: S.current.view_key_public, value: keys['publicViewKey']),
StandartListItem(
title: S.current.view_key_private, value: keys['privateViewKey']),
StandartListItem(title: S.current.wallet_seed, value: wallet.seed),
]);
}
if (wallet.type == WalletType.bitcoin || wallet.type == WalletType.litecoin) {
final keys = bitcoin.getWalletKeys(wallet);
@@ -16,7 +16,7 @@ class WalletListViewModel = WalletListViewModelBase with _$WalletListViewModel;
abstract class WalletListViewModelBase with Store {
WalletListViewModelBase(this._walletInfoSource, this._appStore,
this._keyService, this.walletNewVM) {
this._keyService) {
wallets = ObservableList<WalletListItem>();
_updateList();
}
@@ -27,7 +27,6 @@ abstract class WalletListViewModelBase with Store {
final AppStore _appStore;
final Box<WalletInfo> _walletInfoSource;
final KeyService _keyService;
final WalletNewVM walletNewVM;
WalletType get currentWalletType => _appStore.wallet.type;
+5 -1
View File
@@ -10,6 +10,7 @@ import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/view_model/wallet_creation_vm.dart';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/haven/haven.dart';
part 'wallet_new_vm.g.dart';
@@ -25,7 +26,7 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
@observable
String selectedMnemonicLanguage;
bool get hasLanguageSelector => type == WalletType.monero;
bool get hasLanguageSelector => type == WalletType.monero || type == WalletType.haven;
final WalletCreationService _walletCreationService;
@@ -39,6 +40,9 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
return bitcoin.createBitcoinNewWalletCredentials(name: name);
case WalletType.litecoin:
return bitcoin.createBitcoinNewWalletCredentials(name: name);
case WalletType.haven:
return haven.createHavenNewWalletCredentials(
name: name, language: options as String);
default:
return null;
}
+32 -12
View File
@@ -12,6 +12,7 @@ import 'package:cw_core/wallet_type.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cake_wallet/view_model/wallet_creation_vm.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/haven/haven.dart';
part 'wallet_restore_view_model.g.dart';
@@ -24,11 +25,11 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
WalletRestoreViewModelBase(AppStore appStore, this._walletCreationService,
Box<WalletInfo> walletInfoSource,
{@required WalletType type})
: availableModes = type == WalletType.monero
: availableModes = (type == WalletType.monero || type == WalletType.haven)
? WalletRestoreMode.values
: [WalletRestoreMode.seed],
hasSeedLanguageSelector = type == WalletType.monero,
hasBlockchainHeightLanguageSelector = type == WalletType.monero,
hasSeedLanguageSelector = type == WalletType.monero || type == WalletType.haven,
hasBlockchainHeightLanguageSelector = type == WalletType.monero || type == WalletType.haven,
super(appStore, walletInfoSource, type: type, isRecovery: true) {
isButtonEnabled =
!hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector;
@@ -64,7 +65,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
case WalletType.monero:
return monero.createMoneroRestoreWalletFromSeedCredentials(
name: name,
height: height,
height: height ?? 0,
mnemonic: seed,
password: password);
case WalletType.bitcoin:
@@ -77,6 +78,12 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
name: name,
mnemonic: seed,
password: password);
case WalletType.haven:
return haven.createHavenRestoreWalletFromSeedCredentials(
name: name,
height: height ?? 0,
mnemonic: seed,
password: password);
default:
break;
}
@@ -87,14 +94,27 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
final spendKey = options['spendKey'] as String;
final address = options['address'] as String;
return monero.createMoneroRestoreWalletFromKeysCredentials(
name: name,
height: height,
spendKey: spendKey,
viewKey: viewKey,
address: address,
password: password,
language: 'English');
if (type == WalletType.monero) {
return monero.createMoneroRestoreWalletFromKeysCredentials(
name: name,
height: height,
spendKey: spendKey,
viewKey: viewKey,
address: address,
password: password,
language: 'English');
}
if (type == WalletType.haven) {
return haven.createHavenRestoreWalletFromKeysCredentials(
name: name,
height: height,
spendKey: spendKey,
viewKey: viewKey,
address: address,
password: password,
language: 'English');
}
}
return null;