fix: Prevent failed keys fetch from disabling display of mnemonic

This commit is contained in:
julian 2024-12-12 16:54:55 -06:00
parent 9c64ed6316
commit c56038cadf
3 changed files with 26 additions and 115 deletions

View file

@ -156,11 +156,13 @@ class _CNWalletKeysState extends State<CNWalletKeys> {
SizedBox(
height: Util.isDesktop ? 12 : 16,
),
QR(
data: _current(_currentDropDownValue),
size:
Util.isDesktop ? 256 : MediaQuery.of(context).size.width / 1.5,
),
if (_current(_currentDropDownValue) != "ERROR")
QR(
data: _current(_currentDropDownValue),
size: Util.isDesktop
? 256
: MediaQuery.of(context).size.width / 1.5,
),
SizedBox(
height: Util.isDesktop ? 12 : 16,
),

View file

@ -313,108 +313,7 @@ class _UnlockWalletKeysDesktopState
child: PrimaryButton(
label: "Continue",
enabled: continueEnabled,
onPressed: continueEnabled
? () async {
unawaited(
showDialog(
context: context,
builder: (context) => const Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
LoadingIndicator(
width: 200,
height: 200,
),
],
),
),
);
await Future<void>.delayed(
const Duration(seconds: 1),
);
final verified = await ref
.read(storageCryptoHandlerProvider)
.verifyPassphrase(passwordController.text);
if (verified) {
if (context.mounted) {
Navigator.of(context, rootNavigator: true)
.pop();
}
({String keys, String config})? frostData;
List<String>? words;
final wallet =
ref.read(pWallets).getWallet(widget.walletId);
// TODO: [prio=low] handle wallets that don't have a mnemonic
// All wallets currently are mnemonic based
if (wallet is! MnemonicInterface) {
if (wallet is BitcoinFrostWallet) {
frostData = (
keys: (await wallet.getSerializedKeys())!,
config: (await wallet.getMultisigConfig())!,
);
} else {
throw Exception("FIXME ~= see todo in code");
}
} else {
if (wallet is ViewOnlyOptionInterface &&
(wallet as ViewOnlyOptionInterface)
.isViewOnly) {
// TODO: is something needed here?
} else {
words = await wallet.getMnemonicAsWords();
}
}
KeyDataInterface? keyData;
if (wallet is ViewOnlyOptionInterface &&
wallet.isViewOnly) {
keyData = await wallet.getViewOnlyWalletData();
} else if (wallet is ExtendedKeysInterface) {
keyData = await wallet.getXPrivs();
} else if (wallet is LibMoneroWallet) {
keyData = await wallet.getKeys();
}
if (context.mounted) {
await Navigator.of(context)
.pushReplacementNamed(
WalletKeysDesktopPopup.routeName,
arguments: (
mnemonic: words ?? [],
walletId: widget.walletId,
frostData: frostData,
keyData: keyData,
),
);
}
} else {
if (context.mounted) {
Navigator.of(context, rootNavigator: true)
.pop();
}
await Future<void>.delayed(
const Duration(milliseconds: 300),
);
if (context.mounted) {
unawaited(
showFloatingFlushBar(
type: FlushBarType.warning,
message: "Invalid passphrase!",
context: context,
),
);
}
}
}
: null,
onPressed: continueEnabled ? enterPassphrase : null,
),
),
],

View file

@ -298,14 +298,24 @@ abstract class LibMoneroWallet<T extends CryptonoteCurrency>
if (base == null || (oldInfo != null && oldInfo.name != walletId)) {
return null;
}
return CWKeyData(
walletId: walletId,
publicViewKey: base.getPublicViewKey(),
privateViewKey: base.getPrivateViewKey(),
publicSpendKey: base.getPublicSpendKey(),
privateSpendKey: base.getPrivateSpendKey(),
);
try {
return CWKeyData(
walletId: walletId,
publicViewKey: base.getPublicViewKey(),
privateViewKey: base.getPrivateViewKey(),
publicSpendKey: base.getPublicSpendKey(),
privateSpendKey: base.getPrivateSpendKey(),
);
} catch (e, s) {
Logging.instance.log("getKeys failed: $e\n$s", level: LogLevel.Fatal);
return CWKeyData(
walletId: walletId,
publicViewKey: "ERROR",
privateViewKey: "ERROR",
publicSpendKey: "ERROR",
privateSpendKey: "ERROR",
);
}
}
Future<(String, String)>