Skip to content

Commit a6494a0

Browse files
committed
feat: xpub restore from bitcoin URI QR
1 parent ad4bc38 commit a6494a0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/view_model/restore/restore_wallet.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class RestoredWallet {
3535

3636
factory RestoredWallet.fromKey(Map<String, dynamic> json) {
3737
try {
38-
final codeParsed = jsonDecode(json['raw_qr'].toString());
38+
final codeParsed = jsonDecode(json['raw_qr'].toString());
3939
if (codeParsed["version"] == 0) {
4040
json['address'] = codeParsed["primaryAddress"];
4141
json['view_key'] = codeParsed["privateViewKey"];
@@ -44,14 +44,15 @@ class RestoredWallet {
4444
} catch (e) {
4545
// fine, we don't care, it is only for monero anyway
4646
}
47+
json['view_key'] ??= json['xpub'];
4748
final height = json['height'] as String?;
4849
return RestoredWallet(
4950
restoreMode: json['mode'] as WalletRestoreMode,
5051
type: json['type'] as WalletType,
5152
address: json['address'] as String?,
5253
spendKey: json['spend_key'] as String?,
5354
viewKey: json['view_key'] as String?,
54-
height: height != null ? int.tryParse(height)??0 : 0,
55+
height: height != null ? int.tryParse(height) ?? 0 : 0,
5556
privateKey: json['private_key'] as String?,
5657
);
5758
}

lib/view_model/restore/wallet_restore_from_qr_code.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ class WalletRestoreFromQRCode {
155155
throw Exception('Unexpected restore mode: tx_payment_id is invalid');
156156
}
157157

158+
if (credentials.containsKey("xpub")) {
159+
return WalletRestoreMode.keys;
160+
}
161+
158162
if (credentials['seed'] != null) {
159163
final seedValue = credentials['seed'] as String;
160164
final words = SeedValidator.getWordList(type: type, language: 'english');

0 commit comments

Comments
 (0)