From 269ad06f148a49cb88dcc0eb55683655f26b0fac Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 14 Nov 2023 09:57:48 -0600 Subject: [PATCH] couple small fixes --- lib/wallets/isar/models/wallet_info.dart | 23 +------------- lib/wallets/wallet/wallet.dart | 40 ++++++++++-------------- 2 files changed, 17 insertions(+), 46 deletions(-) diff --git a/lib/wallets/isar/models/wallet_info.dart b/lib/wallets/isar/models/wallet_info.dart index bf03fa112..dffb9fe74 100644 --- a/lib/wallets/isar/models/wallet_info.dart +++ b/lib/wallets/isar/models/wallet_info.dart @@ -266,32 +266,11 @@ class WalletInfo implements IsarId { int restoreHeight = 0, String? walletIdOverride, }) { - // TODO: make Coin aware of these - // ex. - // walletType = coin.walletType; - // mainAddressType = coin.mainAddressType; - - final AddressType mainAddressType; - switch (coin) { - case Coin.bitcoin: - case Coin.bitcoinTestNet: - mainAddressType = AddressType.p2wpkh; - break; - - case Coin.bitcoincash: - case Coin.bitcoincashTestnet: - mainAddressType = AddressType.p2pkh; - break; - - default: - throw UnimplementedError(); - } - return WalletInfo( coinName: coin.name, walletId: walletIdOverride ?? const Uuid().v1(), name: name, - mainAddressType: mainAddressType, + mainAddressType: coin.primaryAddressType, restoreHeight: restoreHeight, ); } diff --git a/lib/wallets/wallet/wallet.dart b/lib/wallets/wallet/wallet.dart index 65fec0f73..b6ea839f6 100644 --- a/lib/wallets/wallet/wallet.dart +++ b/lib/wallets/wallet/wallet.dart @@ -32,10 +32,8 @@ import 'package:stackwallet/wallets/wallet/impl/bitcoincash_wallet.dart'; import 'package:stackwallet/wallets/wallet/impl/ecash_wallet.dart'; import 'package:stackwallet/wallets/wallet/impl/epiccash_wallet.dart'; import 'package:stackwallet/wallets/wallet/impl/wownero_wallet.dart'; -import 'package:stackwallet/wallets/wallet/intermediate/bip39_hd_wallet.dart'; -import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart'; -import 'package:stackwallet/wallets/wallet/intermediate/cryptonote_wallet.dart'; import 'package:stackwallet/wallets/wallet/mixins/electrumx_mixin.dart'; +import 'package:stackwallet/wallets/wallet/mixins/mnemonic_based_wallet.dart'; import 'package:stackwallet/wallets/wallet/mixins/multi_address.dart'; import 'package:stackwallet/wallets/wallet/private_key_based_wallet.dart'; @@ -135,28 +133,22 @@ abstract class Wallet { prefs: prefs, ); - switch (wallet.runtimeType) { - case Bip39Wallet: - case Bip39HDWallet: - await secureStorageInterface.write( - key: mnemonicKey(walletId: walletInfo.walletId), - value: mnemonic!, - ); - await secureStorageInterface.write( - key: mnemonicPassphraseKey(walletId: walletInfo.walletId), - value: mnemonicPassphrase!, - ); - break; + if (wallet is MnemonicBasedWallet) { + await secureStorageInterface.write( + key: mnemonicKey(walletId: walletInfo.walletId), + value: mnemonic!, + ); + await secureStorageInterface.write( + key: mnemonicPassphraseKey(walletId: walletInfo.walletId), + value: mnemonicPassphrase!, + ); + } - case CryptonoteWallet: - break; - - case PrivateKeyBasedWallet: - await secureStorageInterface.write( - key: privateKeyKey(walletId: walletInfo.walletId), - value: privateKey!, - ); - break; + if (wallet is PrivateKeyBasedWallet) { + await secureStorageInterface.write( + key: privateKeyKey(walletId: walletInfo.walletId), + value: privateKey!, + ); } // Store in db after wallet creation