wownero
M 4 years ago
parent b17e7744c6
commit 5c4e1b4d01

@ -351,13 +351,11 @@ extern "C"
uint64_t get_full_balance(uint32_t account_index) uint64_t get_full_balance(uint32_t account_index)
{ {
// return 0;
return get_current_wallet()->balance(account_index); return get_current_wallet()->balance(account_index);
} }
uint64_t get_unlocked_balance(uint32_t account_index) uint64_t get_unlocked_balance(uint32_t account_index)
{ {
// return 0;
return get_current_wallet()->unlockedBalance(account_index); return get_current_wallet()->unlockedBalance(account_index);
} }

@ -29,47 +29,59 @@ import 'package:cake_wallet/src/screens/root/root.dart';
final navigatorKey = GlobalKey<NavigatorState>(); final navigatorKey = GlobalKey<NavigatorState>();
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); try {
WidgetsFlutterBinding.ensureInitialized();
final appDir = await getApplicationDocumentsDirectory(); final appDir = await getApplicationDocumentsDirectory();
Hive.init(appDir.path); Hive.init(appDir.path);
Hive.registerAdapter(ContactAdapter()); Hive.registerAdapter(ContactAdapter());
Hive.registerAdapter(NodeAdapter()); Hive.registerAdapter(NodeAdapter());
Hive.registerAdapter(TransactionDescriptionAdapter()); Hive.registerAdapter(TransactionDescriptionAdapter());
Hive.registerAdapter(TradeAdapter()); Hive.registerAdapter(TradeAdapter());
Hive.registerAdapter(WalletInfoAdapter()); Hive.registerAdapter(WalletInfoAdapter());
Hive.registerAdapter(WalletTypeAdapter()); Hive.registerAdapter(WalletTypeAdapter());
Hive.registerAdapter(TemplateAdapter()); Hive.registerAdapter(TemplateAdapter());
Hive.registerAdapter(ExchangeTemplateAdapter()); Hive.registerAdapter(ExchangeTemplateAdapter());
final secureStorage = FlutterSecureStorage();
final secureStorage = FlutterSecureStorage(); final transactionDescriptionsBoxKey = await getEncryptionKey(
final transactionDescriptionsBoxKey = await getEncryptionKey( secureStorage: secureStorage, forKey: TransactionDescription.boxKey);
secureStorage: secureStorage, forKey: TransactionDescription.boxKey); final tradesBoxKey = await getEncryptionKey(
final tradesBoxKey = await getEncryptionKey( secureStorage: secureStorage, forKey: Trade.boxKey);
secureStorage: secureStorage, forKey: Trade.boxKey); final contacts = await Hive.openBox<Contact>(Contact.boxName);
final contacts = await Hive.openBox<Contact>(Contact.boxName); final nodes = await Hive.openBox<Node>(Node.boxName);
final nodes = await Hive.openBox<Node>(Node.boxName); final transactionDescriptions = await Hive.openBox<TransactionDescription>(
final transactionDescriptions = await Hive.openBox<TransactionDescription>( TransactionDescription.boxName,
TransactionDescription.boxName, encryptionKey: transactionDescriptionsBoxKey);
encryptionKey: transactionDescriptionsBoxKey); final trades =
final trades = await Hive.openBox<Trade>(Trade.boxName, encryptionKey: tradesBoxKey);
await Hive.openBox<Trade>(Trade.boxName, encryptionKey: tradesBoxKey); final walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
final walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName); final templates = await Hive.openBox<Template>(Template.boxName);
final templates = await Hive.openBox<Template>(Template.boxName); final exchangeTemplates =
final exchangeTemplates = await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName);
await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName); await initialSetup(
await initialSetup( sharedPreferences: await SharedPreferences.getInstance(),
sharedPreferences: await SharedPreferences.getInstance(), nodes: nodes,
nodes: nodes, walletInfoSource: walletInfoSource,
walletInfoSource: walletInfoSource, contactSource: contacts,
contactSource: contacts, tradesSource: trades,
tradesSource: trades, // fiatConvertationService: fiatConvertationService,
// fiatConvertationService: fiatConvertationService, templates: templates,
templates: templates, exchangeTemplates: exchangeTemplates,
exchangeTemplates: exchangeTemplates, transactionDescriptions: transactionDescriptions,
transactionDescriptions: transactionDescriptions, initialMigrationVersion: 4);
initialMigrationVersion: 4); runApp(App());
runApp(App()); } catch (e) {
runApp(MaterialApp(
debugShowCheckedModeBanner: true,
home: Scaffold(
body: Container(
margin:
EdgeInsets.only(top: 50, left: 20, right: 20, bottom: 20),
child: Text(
'Error:\n${e.toString()}',
style: TextStyle(fontSize: 22),
)))));
}
} }
Future<void> initialSetup( Future<void> initialSetup(

@ -7,9 +7,11 @@ final moneroAmountFormat = NumberFormat()
..maximumFractionDigits = moneroAmountLength ..maximumFractionDigits = moneroAmountLength
..minimumFractionDigits = 1; ..minimumFractionDigits = 1;
String moneroAmountToString({int amount}) => String moneroAmountToString({int amount}) => moneroAmountFormat
moneroAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider)); .format(cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider));
double moneroAmountToDouble({int amount}) => cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider); double moneroAmountToDouble({int amount}) =>
cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider);
int moneroParseAmount({String amount}) => moneroAmountFormat.parse(amount).toInt(); int moneroParseAmount({String amount}) =>
(double.parse(amount) * moneroAmountDivider).toInt();

@ -0,0 +1,8 @@
class MoneroTransactionCreationException implements Exception {
MoneroTransactionCreationException(this.message);
final String message;
@override
String toString() => message;
}

@ -1,3 +1,7 @@
import 'dart:async';
import 'package:cake_wallet/monero/monero_amount_format.dart';
import 'package:cake_wallet/monero/monero_transaction_creation_exception.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:cw_monero/wallet.dart'; import 'package:cw_monero/wallet.dart';
@ -170,6 +174,19 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
@override @override
Future<PendingTransaction> createTransaction(Object credentials) async { Future<PendingTransaction> createTransaction(Object credentials) async {
final _credentials = credentials as MoneroTransactionCreationCredentials; final _credentials = credentials as MoneroTransactionCreationCredentials;
final amount = moneroParseAmount(amount: _credentials.amount);
final unlockedBalance =
monero_wallet.getUnlockedBalance(accountIndex: account.id);
if (unlockedBalance < amount) {
throw MoneroTransactionCreationException(
'Incorrect unlocked balance. Unlocked: $unlockedBalance. Transaction amount: ${_credentials.amount}.');
}
if (!(syncStatus is SyncedSyncStatus)) {
throw MoneroTransactionCreationException('The wallet is not synced.');
}
final pendingTransactionDescription = final pendingTransactionDescription =
await transaction_history.createTransaction( await transaction_history.createTransaction(
address: _credentials.address, address: _credentials.address,

Loading…
Cancel
Save