diff --git a/lib/coins/abstract.dart b/lib/coins/abstract.dart index 2843d8b..38f181e 100644 --- a/lib/coins/abstract.dart +++ b/lib/coins/abstract.dart @@ -23,9 +23,9 @@ typedef ProgressCallback = int Function({String? title, String? description}); enum Coins { monero, unknown } -class Coin { +abstract class Coin { Coins get type => Coins.unknown; - CoinStrings get strings => CoinStrings(); + CoinStrings get strings => throw UnimplementedError(); bool get isEnabled => false; @@ -49,10 +49,10 @@ class Coin { throw UnimplementedError(); } -class CoinWalletInfo { +abstract class CoinWalletInfo { String get walletName => throw UnimplementedError(); Coins get type => coin.type; - Coin get coin => Coin(); + Coin get coin => throw UnimplementedError(); void openUI(BuildContext context) => throw UnimplementedError(); Future checkWalletPassword(String password) async => @@ -86,7 +86,7 @@ class CoinWalletInfo { Future renameWallet(String newName) => throw UnimplementedError(); } -class CoinStrings { +abstract class CoinStrings { String get nameLowercase => "coin"; String get nameCapitalized => "Coin"; String get nameUppercase => "COIN"; @@ -116,7 +116,7 @@ class WalletSeedDetail { class CoinWallet { CoinWallet(); - Coin coin = Coin(); + Coin get coin => throw UnimplementedError(); Future handleUR(BuildContext context, URQRData ur) => throw UnimplementedError(); bool get hasAccountSupport => false; diff --git a/lib/coins/monero/coin.dart b/lib/coins/monero/coin.dart index 5b72d73..bee3653 100644 --- a/lib/coins/monero/coin.dart +++ b/lib/coins/monero/coin.dart @@ -175,6 +175,8 @@ class Monero implements Coin { details: "unable to create wallet, recoveryWallet failed.", ); } + monero.Wallet_store(newWptr); + monero.Wallet_store(newWptr); progressCallback?.call(description: "Wallet created"); } @@ -204,6 +206,8 @@ class Monero implements Coin { details: "unable to create wallet, recoveryWallet failed.", ); } + monero.Wallet_store(newWptr); + monero.Wallet_store(newWptr); progressCallback?.call(description: "Wallet created"); } diff --git a/lib/coins/monero/wallet.dart b/lib/coins/monero/wallet.dart index 0d395ac..d1b246b 100644 --- a/lib/coins/monero/wallet.dart +++ b/lib/coins/monero/wallet.dart @@ -174,8 +174,8 @@ class MoneroWallet implements CoinWallet { @override String get seed => - nullIfEmpty(polyseed ?? "") ?? - nullIfEmpty(polyseedDart ?? "") ?? + (polyseed ?? "").nullIfEmpty() ?? + (polyseedDart ?? "").nullIfEmpty() ?? legacySeed; String? get polyseed => diff --git a/lib/utils/null_if_empty.dart b/lib/utils/null_if_empty.dart index cceaf00..c2c1ed3 100644 --- a/lib/utils/null_if_empty.dart +++ b/lib/utils/null_if_empty.dart @@ -1,4 +1,6 @@ -String? nullIfEmpty(String str) { - if (str.isEmpty) return null; - return str; +extension NullIfEmpty on String { + String? nullIfEmpty() { + if (isEmpty) return null; + return this; + } } diff --git a/lib/view_model/create_wallet_view_model.dart b/lib/view_model/create_wallet_view_model.dart index 0b6f184..ffe9ee3 100644 --- a/lib/view_model/create_wallet_view_model.dart +++ b/lib/view_model/create_wallet_view_model.dart @@ -232,13 +232,13 @@ class CreateWalletViewModel extends ViewModel { final cw = await selectedCoin!.createNewWallet( await walletName.value, await walletPassword.value, - primaryAddress: nullIfEmpty(await walletAddress.value), + primaryAddress: (await walletAddress.value).nullIfEmpty(), createWallet: (currentForm == _createForm), - seed: nullIfEmpty(await seed.value), + seed: (await seed.value).nullIfEmpty(), restoreHeight: int.tryParse(await restoreHeight.value), - viewKey: nullIfEmpty(await secretViewKey.value), - spendKey: nullIfEmpty(await secretSpendKey.value), - seedOffsetOrEncryption: nullIfEmpty(await seedOffset.value), + viewKey: (await secretViewKey.value).nullIfEmpty(), + spendKey: (await secretSpendKey.value).nullIfEmpty(), + seedOffsetOrEncryption: (await seedOffset.value).nullIfEmpty(), ); final List pages = [ diff --git a/lib/view_model/wallet_details_view_model.dart b/lib/view_model/wallet_details_view_model.dart deleted file mode 100644 index 083ac78..0000000 --- a/lib/view_model/wallet_details_view_model.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:cupcake/coins/abstract.dart'; -import 'package:cupcake/coins/list.dart'; -import 'package:cupcake/view_model/abstract.dart'; - -class HomeScreenViewModel extends ViewModel { - HomeScreenViewModel(); - - @override - String get screenName => L.wallet_details; - - Future> get wallets async { - List wallets = []; - for (var coin in walletCoins) { - final toAdd = await coin.coinWallets; - if (toAdd.isNotEmpty) { - wallets.addAll(toAdd); - } - } - return wallets; - } - - Future get showLandingInfo async => (await wallets).isEmpty; -} diff --git a/lib/views/receive.dart b/lib/views/receive.dart index ef6c0ef..e10ceb0 100644 --- a/lib/views/receive.dart +++ b/lib/views/receive.dart @@ -33,45 +33,45 @@ class Receive extends AbstractView { Padding( padding: const EdgeInsets.only(top: 8, left: 48, right: 48, bottom: 32), - child: Container( - padding: const EdgeInsets.all(10.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30.0), - color: Colors.white, - ), - child: QrImageView( - data: "monero:${viewModel.address}", - foregroundColor: Colors.black, + child: Container( + padding: const EdgeInsets.all(10.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(30.0), + color: Colors.white, + ), + child: QrImageView( + data: "monero:${viewModel.address}", + foregroundColor: Colors.black, + ), ), ), - ), Container( padding: const EdgeInsets.all(25.0), decoration: BoxDecoration( borderRadius: BorderRadius.circular(30.0), - color: Color.fromRGBO(35, 44, 79, 1), + color: const Color.fromRGBO(35, 44, 79, 1), ), - child: InkWell( - onTap: () { - Clipboard.setData( - ClipboardData( - text: viewModel.address, + child: InkWell( + onTap: () { + Clipboard.setData( + ClipboardData( + text: viewModel.address, + ), + ); + }, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 0), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Expanded( + child: SelectableText( + viewModel.address, + style: const TextStyle(color: Colors.white), + )), + const Icon(Icons.copy, color: Colors.grey), + ], ), - ); - }, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 0), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Expanded( - child: SelectableText( - viewModel.address, - style: const TextStyle(color: Colors.white), - )), - const Icon(Icons.copy, color: Colors.grey), - ], - ), ), ), ), diff --git a/lib/views/urqr.dart b/lib/views/urqr.dart index c6ed133..0b7e43e 100644 --- a/lib/views/urqr.dart +++ b/lib/views/urqr.dart @@ -105,19 +105,19 @@ class _URQRState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Center( - child: Container( - padding: const EdgeInsets.all(17.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30.0), - color: Colors.white, - ), - child: QrImageView( - foregroundColor: Colors.black, - data: widget.frames[frame % widget.frames.length], - version: -1, - size: 275, + child: Container( + padding: const EdgeInsets.all(17.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(30.0), + color: Colors.white, + ), + child: QrImageView( + foregroundColor: Colors.black, + data: widget.frames[frame % widget.frames.length], + version: -1, + size: 275, + ), ), - ), ), ], ); diff --git a/lib/views/wallet_home.dart b/lib/views/wallet_home.dart index 5f5116b..678ef0c 100644 --- a/lib/views/wallet_home.dart +++ b/lib/views/wallet_home.dart @@ -118,8 +118,8 @@ class WalletHome extends AbstractView { child: ElevatedButton.icon( onPressed: () => Receive.pushStatic(context, viewModel.wallet), - icon: - const Icon(Icons.call_received, size: 35, color: Colors.white), + icon: const Icon(Icons.call_received, + size: 35, color: Colors.white), label: Text( L.receive, style: const TextStyle(color: Colors.white, fontSize: 18), diff --git a/pubspec.lock b/pubspec.lock index a12bb3a..0166f59 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -988,10 +988,10 @@ packages: dependency: transitive description: name: vm_service - sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.4" + version: "14.2.5" watcher: dependency: transitive description: